Skip to content

Commit a1d80ed

Browse files
committed
Implement basic structures and testing over ssh connection
Signed-off-by: Christopher Meis <christopher.meis@9elements.com>
1 parent a787c39 commit a1d80ed

File tree

16 files changed

+666
-84
lines changed

16 files changed

+666
-84
lines changed

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tasks:
1212
matrix:
1313
OS: ['linux']
1414
ARCH: ['amd64', 'arm', 'arm64']
15-
cmd: GOOS="{{.ITEM.OS}}" GOARCH="{{.ITEM.ARCH}}" go build -ldflags="-s -w" -o "bin/bmc-test-go-{{.ITEM.OS}}-{{.ITEM.ARCH}}-{{.SEMVER}}"
15+
cmd: GOOS="{{.ITEM.OS}}" GOARCH="{{.ITEM.ARCH}}" go build ./cmds/openbmc-tests -ldflags="-s -w" -o "bin/bmc-test-go-{{.ITEM.OS}}-{{.ITEM.ARCH}}-{{.SEMVER}}"
1616

1717
lint:
1818
desc: Run linters

cmds/openbmc-tests/cmdline.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
)
6+
7+
type flags struct {
8+
configPath string
9+
execEnv string
10+
user string
11+
password string
12+
ip string
13+
sshPort int
14+
}
15+
16+
func parseFlags() *flags {
17+
f := &flags{}
18+
flag.StringVar(&f.configPath, "config", "contrib/example_config.yaml", "Path to device specific test case configuration file")
19+
flag.StringVar(&f.execEnv, "execEnv", "remote", "Runtime locality switch. Default: remote")
20+
flag.StringVar(&f.user, "user", "root", "OpenBMC username for remote access. Default: 'root'")
21+
flag.StringVar(&f.password, "password", "0penBmc", "OpenBMC user password for remote access Default: '0penBmc'")
22+
flag.StringVar(&f.ip, "ip", "", "IP address to the remote BMC. Default: localhost")
23+
flag.IntVar(&f.sshPort, "port", 22, "Port to access the BMC via SSH. Default: 22")
24+
flag.Parse()
25+
return f
26+
}

cmds/openbmc-tests/main.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
3+
// Package main implements the core logic
4+
package main
5+
6+
import (
7+
"log"
8+
"os"
9+
10+
"github.com/9elements/bmc-test-go/pkg/bmc"
11+
"github.com/9elements/bmc-test-go/pkg/configuration"
12+
"github.com/9elements/bmc-test-go/pkg/tests"
13+
)
14+
15+
func run() error {
16+
flags := parseFlags()
17+
18+
cfg, err := configuration.LoadConfig(flags.configPath)
19+
if err != nil {
20+
log.Print(err)
21+
os.Exit(1)
22+
}
23+
24+
bmc, err := bmc.NewBMC(flags.execEnv, cfg)
25+
if err != nil {
26+
return err
27+
}
28+
29+
ipmiPre := &tests.IPMIPreconditions{}
30+
if err := ipmiPre.Run(bmc); err != nil {
31+
return err
32+
}
33+
34+
for _, test := range tests.IPMITests {
35+
if !test.Run(bmc, cfg, ipmiPre) {
36+
return err
37+
}
38+
}
39+
40+
return nil
41+
}
42+
43+
func main() {
44+
if err := run(); err != nil {
45+
log.Print(err)
46+
os.Exit(1)
47+
}
48+
}

contrib/example_config.yaml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
---
22
version: 0
33
name: ExampleServer
4-
requirements:
4+
bmc_ip: bmcIP
5+
bmc_user: root
6+
bmc_password: 0penBmc
7+
numHosts: 1
8+
hosts:
9+
- host1:
10+
ip: hostIP1
11+
user: hostUser1
12+
password: hostPassword1
13+
- host2:
14+
ip: hostIP2
15+
user: hostUser2
16+
password: hostPassword2
17+
testdata:
518
redfish:
619
general:
720
cpuvendor: "TestVendor"
@@ -22,7 +35,11 @@ requirements:
2235
vendor: TestDimmmVendor
2336
capacity: 1336
2437
fru:
25-
fruExpected:
26-
vendor: TestFruVendor
27-
name: TestFruName
28-
serial: TestSerial001
38+
- fruExpected:
39+
manufacturer: TestFruVendor
40+
name: TestFruName
41+
serial: TestSerial001
42+
- fruExpected:
43+
manufacturer: TestFruVendor
44+
name: TestFruName
45+
serial: TestSerial001

go.mod

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

3-
go 1.23
3+
go 1.24.0
4+
5+
toolchain go1.24.12
46

57
require gopkg.in/yaml.v3 v3.0.1
8+
9+
require (
10+
github.com/stmcginnis/gofish v0.20.0 // indirect
11+
golang.org/x/crypto v0.47.0 // indirect
12+
golang.org/x/sys v0.40.0 // indirect
13+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
github.com/stmcginnis/gofish v0.20.0 h1:hH2V2Qe898F2wWT1loApnkDUrXXiLKqbSlMaH3Y1n08=
2+
github.com/stmcginnis/gofish v0.20.0/go.mod h1:PzF5i8ecRG9A2ol8XT64npKUunyraJ+7t0kYMpQAtqU=
3+
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
4+
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
5+
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
6+
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
17
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
28
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
39
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

main.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

pkg/bmc/bmc.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package bmc
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/9elements/bmc-test-go/pkg/configuration"
7+
)
8+
9+
type BMC struct {
10+
con BMCConnection
11+
}
12+
13+
type ExecType string
14+
15+
var (
16+
localExec ExecType = "local"
17+
remoteExec ExecType = "remote"
18+
)
19+
20+
func NewBMC(execEnv string, cfg *configuration.Config) (*BMC, error) {
21+
switch execEnv {
22+
case "local":
23+
return &BMC{con: &LocalConn{}}, nil
24+
case "remote":
25+
remoteConn, err := NewRemoteConn(cfg.BMCIP, cfg.BMCUser, cfg.BMCPassword)
26+
if err != nil {
27+
return nil, err
28+
}
29+
return &BMC{con: remoteConn}, nil
30+
}
31+
return nil, fmt.Errorf("unknown connection type: %s", execEnv)
32+
}
33+
34+
func (b *BMC) ExecuteCommandLine(cmd string) ([]byte, error) {
35+
return b.con.ExecuteCmdline(cmd)
36+
}

pkg/bmc/interface.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package bmc
2+
3+
type BMCConnection interface {
4+
ExecuteCmdline(cmd string) ([]byte, error)
5+
}

pkg/bmc/localconn.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package bmc
2+
3+
import "os/exec"
4+
5+
type LocalConn struct{}
6+
7+
func (l *LocalConn) ExecuteCmdline(cmd string) ([]byte, error) {
8+
command := exec.Command(cmd)
9+
resp, err := command.Output()
10+
if err != nil {
11+
return []byte{}, err
12+
}
13+
return resp, nil
14+
}

0 commit comments

Comments
 (0)