mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Updated tests
This commit is contained in:
parent
7b18615e5f
commit
dd7bb5ec77
2 changed files with 130 additions and 17 deletions
|
|
@ -8,10 +8,14 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"flag"
|
||||||
|
|
||||||
magellan "github.com/OpenCHAMI/magellan/internal"
|
magellan "github.com/OpenCHAMI/magellan/internal"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -29,33 +33,114 @@ var (
|
||||||
DisableProbing: false,
|
DisableProbing: false,
|
||||||
Verbose: false,
|
Verbose: false,
|
||||||
}
|
}
|
||||||
|
exePath = flag.String("exe", "./magellan", "path to 'magellan' binary executable")
|
||||||
|
emuPath = flag.String("emu", "./emulator/setup.sh", "path to emulator 'setup.sh' script")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func runEmulator() {}
|
||||||
|
|
||||||
func TestScanAndCollect(t *testing.T) {
|
func TestScanAndCollect(t *testing.T) {
|
||||||
// do a scan on the emulator cluster with probing disabled and check results
|
var (
|
||||||
results := magellan.ScanForAssets(scanParams)
|
err error
|
||||||
if len(results) <= 0 {
|
emuErr error
|
||||||
t.Fatal("expected to find at least one BMC node, but found none")
|
output []byte
|
||||||
}
|
tempDir = t.TempDir()
|
||||||
// do a scan on the emulator cluster with probing enabled
|
command string
|
||||||
results = magellan.ScanForAssets(scanParams)
|
)
|
||||||
if len(results) <= 0 {
|
|
||||||
t.Fatal("expected to find at least one BMC node, but found none")
|
// try and start the emulator in the background if arg passed
|
||||||
|
if *emuPath != "" {
|
||||||
|
t.Parallel()
|
||||||
|
t.Run("emulator", func(t *testing.T) {
|
||||||
|
_, emuErr = exec.Command("bash", "-c", *emuPath).CombinedOutput()
|
||||||
|
if emuErr != nil {
|
||||||
|
t.Fatalf("failed to start emulator: %v", emuErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// do a collect on the emulator cluster to collect Redfish info
|
// try and run a "scan" with the emulator
|
||||||
err := magellan.CollectInventory(&results, &magellan.CollectParams{})
|
command = fmt.Sprintf("%s scan --subnet 127.0.0.1 --subnet-mask 255.255.255.0 --cache %s", exePath, tempDir)
|
||||||
|
output, err = exec.Command("bash", "-c", command).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to collect inventory")
|
t.Fatalf("failed to run 'scan' command: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure that the expected output is not empty
|
||||||
|
if len(output) <= 0 {
|
||||||
|
t.Fatalf("expected the 'scan' output to not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
// try and run a "collect" with the emulator
|
||||||
|
command = fmt.Sprintf("%s collect --username root --password root_password --cache %s", exePath, tempDir)
|
||||||
|
output, err = exec.Command("bash", "-c", command).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to run 'collect' command: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure that the output is not empty
|
||||||
|
if len(output) <= 0 {
|
||||||
|
t.Fatalf("expected the 'collect' output to not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: check for at least one System/EthernetInterface that we know should exist
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCrawlCommand(t *testing.T) {
|
func TestCrawlCommand(t *testing.T) {
|
||||||
// TODO: add test to check the crawl command's behavior
|
var (
|
||||||
|
err error
|
||||||
|
emuErr error
|
||||||
|
output []byte
|
||||||
|
command string
|
||||||
|
)
|
||||||
|
|
||||||
|
// try and start the emulator in the background if arg passed
|
||||||
|
if *emuPath != "" {
|
||||||
|
t.Parallel()
|
||||||
|
t.Run("emulator", func(t *testing.T) {
|
||||||
|
_, emuErr = exec.Command("bash", "-c", *emuPath).CombinedOutput()
|
||||||
|
if emuErr != nil {
|
||||||
|
t.Fatalf("failed to start emulator: %v", emuErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// try and run a "collect" with the emulator
|
||||||
|
command = fmt.Sprintf("%s crawl --username root --password root_password -i", exePath)
|
||||||
|
output, err = exec.Command("bash", "-c", command).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to run 'crawl' command: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure that the output is not empty
|
||||||
|
if len(output) <= 0 {
|
||||||
|
t.Fatalf("expected the 'crawl' output to not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListCommand(t *testing.T) {
|
func TestListCommand(t *testing.T) {
|
||||||
// TODO: add test to check the list command's output
|
// TODO: need magellan binary to test command
|
||||||
|
var (
|
||||||
|
cmd *exec.Cmd
|
||||||
|
err error
|
||||||
|
output []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
// set up the test
|
||||||
|
|
||||||
|
// set up temporary directory
|
||||||
|
cmd = exec.Command("bash", "-c", fmt.Sprintf("%s list", *exePath))
|
||||||
|
output, err = cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to run 'list' command: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure that the output is not empty
|
||||||
|
if len(output) <= 0 {
|
||||||
|
t.Fatalf("expected the 'list' output to not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateCommand(t *testing.T) {
|
func TestUpdateCommand(t *testing.T) {
|
||||||
|
|
@ -70,4 +155,26 @@ func TestGofishFunctions(t *testing.T) {
|
||||||
|
|
||||||
func TestGenerateHosts(t *testing.T) {
|
func TestGenerateHosts(t *testing.T) {
|
||||||
// TODO: add test to generate hosts using a collection of subnets/masks
|
// TODO: add test to generate hosts using a collection of subnets/masks
|
||||||
|
t.Run("generate-hosts.1", func(t *testing.T) {
|
||||||
|
var (
|
||||||
|
subnet = "172.16.0.0"
|
||||||
|
subnetMask = &net.IPMask{255, 255, 255, 0}
|
||||||
|
ports = []int{443}
|
||||||
|
scheme = "https"
|
||||||
|
hosts = [][]string{}
|
||||||
|
)
|
||||||
|
hosts = magellan.GenerateHostsWithSubnet(subnet, subnetMask, ports, scheme)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("generate-hosts.2", func(t *testing.T) {
|
||||||
|
var (
|
||||||
|
subnet = "127.0.0.1"
|
||||||
|
subnetMask = &net.IPMask{255, 255, 255, 0}
|
||||||
|
ports = []int{443, 5000}
|
||||||
|
scheme = "https"
|
||||||
|
hosts = [][]string{}
|
||||||
|
)
|
||||||
|
hosts = magellan.GenerateHostsWithSubnet(subnet, subnetMask, ports, scheme)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,13 @@ func TestRedfishV1ServiceRootAvailability(t *testing.T) {
|
||||||
)
|
)
|
||||||
res, b, err := client.MakeRequest(nil, url, http.MethodGet, body, headers)
|
res, b, err := client.MakeRequest(nil, url, http.MethodGet, body, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to make request to BMC node: %w", err)
|
t.Fatalf("failed to make request to BMC node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = checkResponse(res, b)
|
err = checkResponse(res, b)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to check response for redfish service root: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,9 +71,12 @@ func TestRedfishV1Version(t *testing.T) {
|
||||||
|
|
||||||
res, b, err := client.MakeRequest(nil, url, http.MethodGet, body, headers)
|
res, b, err := client.MakeRequest(nil, url, http.MethodGet, body, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to make request to BMC node: %w", err)
|
t.Fatalf("failed to make request to BMC node: %v", err)
|
||||||
}
|
}
|
||||||
err = checkResponse(res, b)
|
err = checkResponse(res, b)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to check response for redfish version: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crawls a BMC node and checks that we're able to query certain properties
|
// Crawls a BMC node and checks that we're able to query certain properties
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue