Skip to content

Commit 1e222a6

Browse files
committed
feat: add yaml file parsing
By adding this capability it will be possible to supply device specific expected information by a config file. Signed-off-by: Christopher Meis <christopher.meis@9elements.com>
1 parent d7dfacf commit 1e222a6

File tree

7 files changed

+104
-1
lines changed

7 files changed

+104
-1
lines changed

contrib/example_config.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
version: 0
3+
name: ExampleServer
4+
requirements:
5+
redfish:
6+
general:
7+
cpuvendor: "TestVendor"
8+
cpumodel: TestModel
9+
psucount: 0
10+
voltage:
11+
- TestString 1
12+
- TestString 2
13+
temperatures:
14+
- Test Temp 1
15+
- Test Temp 2
16+
fans:
17+
- Test Fans 1
18+
- Test Fans 2
19+
dimms:
20+
count: 0
21+
partNo: 0123
22+
vendor: TestDimmmVendor
23+
capacity: 1336
24+
fru:
25+
fruExpected:
26+
vendor: TestFruVendor
27+
name: TestFruName
28+
serial: TestSerial001

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/9elements/bmc-test-go
22

33
go 1.23
4+
5+
require gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,31 @@
44
package main
55

66
import (
7+
"flag"
78
"fmt"
9+
"os"
10+
11+
"github.com/9elements/bmc-test-go/pkg/configuration"
12+
"gopkg.in/yaml.v3"
813
)
914

1015
const bmcTestGoVersion = "v0.0.0"
1116

1217
func main() {
13-
fmt.Println(bmcTestGoVersion)
18+
configPath := flag.String("config", "contrib/example_config.yaml", "Path to device specific test case configuration file")
19+
flag.Parse()
20+
21+
file, err := os.ReadFile(*configPath)
22+
if err != nil {
23+
fmt.Println(err)
24+
os.Exit(1)
25+
}
26+
var cfg configuration.Device
27+
28+
if err = yaml.Unmarshal(file, &cfg); err != nil {
29+
fmt.Println(err)
30+
os.Exit(1)
31+
}
32+
33+
fmt.Printf("%+v", cfg)
1434
}

pkg/configuration/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package configuration
2+
3+
import "github.com/9elements/bmc-test-go/pkg/framework"
4+
5+
type Device struct {
6+
Version int
7+
Name string
8+
framework.Requirements `yaml:"requirements"`
9+
}

pkg/framework/framework.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package framework
2+
3+
var Test struct{}

pkg/framework/requirements.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package framework
2+
3+
type Requirements struct {
4+
Redfish RedfishExpected
5+
Fru FruContent
6+
}
7+
8+
type RedfishExpected struct {
9+
General GeneralInfo `yaml:"general"`
10+
Voltage []string
11+
Temperatures []string
12+
Fans []string
13+
Dimms DimmInfo `yaml:"dimms"`
14+
}
15+
16+
type FruExpected struct {
17+
Vendor string `yaml:"vendor"`
18+
Name string
19+
Serial string
20+
}
21+
22+
type FruContent struct {
23+
FruExpected `yaml:"fruExpected"`
24+
}
25+
26+
type DimmInfo struct {
27+
Count int
28+
PartNo int
29+
Vendor string
30+
Capacity int
31+
}
32+
33+
type GeneralInfo struct {
34+
CPUVendor string
35+
CPUModel string
36+
PSUCount int
37+
}

0 commit comments

Comments
 (0)