From d94bab35afb3a3ee4f1ab2af5054ef80288bd07c Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Fri, 23 Jan 2026 17:42:49 +0000 Subject: [PATCH 01/10] Extend HW Discovery to report vPRO support --- .../apparmor.d/opt.edge-node.bin.hd-agent | 1 + .../config/sudoers.d/hd-agent | 2 +- .../internal/device/device.go | 45 ++++++++ .../internal/device/device_test.go | 102 ++++++++++++++++++ .../test/data/mock_amtinfo.json | 15 +++ 5 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 hardware-discovery-agent/internal/device/device.go create mode 100644 hardware-discovery-agent/internal/device/device_test.go create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo.json diff --git a/hardware-discovery-agent/config/apparmor.d/opt.edge-node.bin.hd-agent b/hardware-discovery-agent/config/apparmor.d/opt.edge-node.bin.hd-agent index 77c556df..2b57c7f5 100644 --- a/hardware-discovery-agent/config/apparmor.d/opt.edge-node.bin.hd-agent +++ b/hardware-discovery-agent/config/apparmor.d/opt.edge-node.bin.hd-agent @@ -289,6 +289,7 @@ profile hda_sudo { /run/systemd/resolve/stub-resolv.conf r, /usr/bin/ipmitool rPx -> hda_ipmitool, /usr/bin/lshw rPx -> hda_lshw, + /usr/bin/rpc ix /usr/bin/sudo mr, /usr/libexec/sudo/libsudo_util.so.* mr, /usr/sbin/dmidecode rPx -> hda_dmidecode, diff --git a/hardware-discovery-agent/config/sudoers.d/hd-agent b/hardware-discovery-agent/config/sudoers.d/hd-agent index a3492bab..5d7ee359 100644 --- a/hardware-discovery-agent/config/sudoers.d/hd-agent +++ b/hardware-discovery-agent/config/sudoers.d/hd-agent @@ -1 +1 @@ -hd-agent ALL=(root) NOPASSWD:/usr/sbin/dmidecode,/usr/bin/ipmitool,/usr/bin/lshw,/usr/sbin/lshw +hd-agent ALL=(root) NOPASSWD:/usr/sbin/dmidecode,/usr/bin/ipmitool,/usr/bin/lshw,/usr/sbin/lshw,/usr/bin/rpc diff --git a/hardware-discovery-agent/internal/device/device.go b/hardware-discovery-agent/internal/device/device.go new file mode 100644 index 00000000..3026a1a0 --- /dev/null +++ b/hardware-discovery-agent/internal/device/device.go @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: (C) 2026 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 + +package device + +import ( + "encoding/json" + "fmt" + + "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/utils" +) + +type RASInfo struct { + NetworkStatus string `json:"networkStatus"` + RemoteStatus string `json:"remoteStatus"` + RemoteTrigger string `json:"remoteTrigger"` + MPSHostname string `json:"mpsHostname"` +} + +type AMTInfo struct { + Version string `json:"version"` + BuildNumber string `json:"buildNumber"` + Sku string `json:"sku"` + Features string `json:"features"` + Uuid string `json:"uuid"` + ControlMode string `json:"controlMode"` + DNSSuffix string `json:"dnsSuffix"` + RAS RASInfo `json:"ras"` +} + +func GetDeviceInfo(executor utils.CmdExecutor) (AMTInfo, error) { + var amtInfo AMTInfo + dataBytes, err := utils.ReadFromCommand(executor, "sudo", "rpc", "amtinfo", "-json") + if err != nil { + return amtInfo, fmt.Errorf("failed to read data from command; error: %w", err) + } + + err = json.Unmarshal(dataBytes, &amtInfo) + if err != nil { + return amtInfo, fmt.Errorf("failed to parse data from command; error: %w", err) + } + + return amtInfo, nil +} diff --git a/hardware-discovery-agent/internal/device/device_test.go b/hardware-discovery-agent/internal/device/device_test.go new file mode 100644 index 00000000..56108bd2 --- /dev/null +++ b/hardware-discovery-agent/internal/device/device_test.go @@ -0,0 +1,102 @@ +// SPDX-FileCopyrightText: (C) 2026 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 + +package device_test + +import ( + "fmt" + "os" + "os/exec" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/device" +) + +func Test_GetDeviceInfo(t *testing.T) { + res, err := device.GetDeviceInfo(testSuccess) + expected := device.AMTInfo{ + Version: "16.1.27", + BuildNumber: "2176", + Sku: "16392", + Features: "AMT Pro Corporate", + Uuid: "1234abcd-ef56-7890-abcd-123456ef7890", + ControlMode: "activated in client control mode", + DNSSuffix: "test.com", + RAS: device.RASInfo{ + NetworkStatus: "direct", + RemoteStatus: "not connected", + RemoteTrigger: "user initiated", + MPSHostname: "", + }, + } + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoFailed(t *testing.T) { + res, err := device.GetDeviceInfo(testFailure) + var expected device.AMTInfo + assert.Error(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoFailedUnmarshal(t *testing.T) { + res, err := device.GetDeviceInfo(testFailureUnmarshal) + var expected device.AMTInfo + assert.Error(t, err) + assert.Equal(t, expected, res) +} + +func testSuccess(command string, args ...string) *exec.Cmd { + cs := []string{"-test.run=TestSuccess", "--", command} + cs = append(cs, args...) + cmd := exec.Command(os.Args[0], cs...) + cmd.Env = []string{"GO_TEST_PROCESS=1"} + return cmd +} + +func testFailure(command string, args ...string) *exec.Cmd { + cs := []string{"-test.run=TestFailure", "--", command} + cs = append(cs, args...) + cmd := exec.Command(os.Args[0], cs...) + cmd.Env = []string{"GO_TEST_PROCESS=1"} + return cmd +} + +func testFailureUnmarshal(command string, args ...string) *exec.Cmd { + cs := []string{"-test.run=TestFailureUnmarshal", "--", command} + cs = append(cs, args...) + cmd := exec.Command(os.Args[0], cs...) + cmd.Env = []string{"GO_TEST_PROCESS=1"} + return cmd +} + +func TestSuccess(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestFailure(_ *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + fmt.Fprintf(os.Stderr, "failed to execute command") + os.Exit(1) +} + +func TestFailureUnmarshal(_ *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + fmt.Fprintf(os.Stdout, "%v", string("not a json")) + os.Exit(0) +} diff --git a/hardware-discovery-agent/test/data/mock_amtinfo.json b/hardware-discovery-agent/test/data/mock_amtinfo.json new file mode 100644 index 00000000..4d06390a --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo.json @@ -0,0 +1,15 @@ +{ + "version": "16.1.27", + "buildNumber": "2176", + "sku": "16392", + "features": "AMT Pro Corporate", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + } +} \ No newline at end of file From 1685b712fafe5684538e35d9fe25885be7f31076 Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Mon, 26 Jan 2026 12:32:11 +0000 Subject: [PATCH 02/10] Add device info call to comms package and update unit tests --- .../internal/comms/comms.go | 6 +++ .../internal/comms/comms_test.go | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/hardware-discovery-agent/internal/comms/comms.go b/hardware-discovery-agent/internal/comms/comms.go index 406baf8c..51953c6e 100644 --- a/hardware-discovery-agent/internal/comms/comms.go +++ b/hardware-discovery-agent/internal/comms/comms.go @@ -16,6 +16,7 @@ import ( "google.golang.org/grpc/credentials" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/cpu" + "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/device" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/disk" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/gpu" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/logger" @@ -357,5 +358,10 @@ func GenerateSystemInfoRequest(executor utils.CmdExecutor) *proto.SystemInfo { log.Errorf("unable to get usb description : %v", err) } + _, err = device.GetDeviceInfo(executor) + if err != nil { + log.Errorf("unable to get device description : %v", err) + } + return parseSystemInfo(sn, productName, bmcAddr, osInfo, biosInfo, cpu, storage, gpu, mem, networkList, bmType, usbList) } diff --git a/hardware-discovery-agent/internal/comms/comms_test.go b/hardware-discovery-agent/internal/comms/comms_test.go index 344966cb..97378469 100644 --- a/hardware-discovery-agent/internal/comms/comms_test.go +++ b/hardware-discovery-agent/internal/comms/comms_test.go @@ -594,6 +594,24 @@ func TestGenerateUpdateDeviceRequestSuccessUsbInfoOnly(t *testing.T) { assert.Equal(t, expected, json) } +func TestGenerateUpdateDeviceRequestSuccessDeviceInfoOnly(t *testing.T) { + json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassedDeviceOnly) + osKern := proto.OsKernel{} + osRelease := proto.OsRelease{} + osInfo := &proto.OsInfo{ + Kernel: &osKern, + Release: &osRelease, + } + cpu := &proto.SystemCPU{} + storage := []*proto.SystemDisk{} + gpu := []*proto.SystemGPU{} + networks := []*proto.SystemNetwork{} + usbInfo := []*proto.SystemUSB{} + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + require.NotNil(t, json) + assert.Equal(t, expected, json) +} + func testCmd(testFunc string, command string, args ...string) *exec.Cmd { cs := []string{fmt.Sprintf("-test.run=%s", testFunc), "--", command} cs = append(cs, args...) @@ -644,6 +662,8 @@ func testCmdExecutorCommandPassed(command string, args ...string) *exec.Cmd { return testCmd("TestGenerateUpdateDeviceRequestCommandGpuDetails", command, args...) } else if strings.Contains(args[0], "ipmitool") { return testCmd("TestGenerateUpdateDeviceRequestCommandIpmiDetails", command, args...) + } else if strings.Contains(args[0], "rpc") { + return testCmd("TestGenerateUpdateDeviceRequestCommandDeviceDetails", command, args...) } else { if strings.Contains(args[2], "bios-version") { return testCmd("TestGenerateUpdateDeviceRequestCommandBiosVersion", command, args...) @@ -760,6 +780,18 @@ func testCmdExecutorCommandPassedUsbOnly(command string, args ...string) *exec.C } } +func testCmdExecutorCommandPassedDeviceOnly(command string, args ...string) *exec.Cmd { + if strings.Contains(command, "sudo") { + if strings.Contains(args[0], "rpc") { + return testCmd("TestGenerateUpdateDeviceRequestCommandDeviceDetails", command, args...) + } else { + return testCmd("TestGenerateUpdateDeviceRequestCommandFailed", command, args...) + } + } else { + return testCmd("TestGenerateUpdateDeviceRequestCommandFailed", command, args...) + } +} + func testCmdExecutorCommandFailed(command string, args ...string) *exec.Cmd { cs := []string{"-test.run=TestGenerateUpdateDeviceRequestCommandFailed", "--", command} cs = append(cs, args...) @@ -788,6 +820,16 @@ func TestGenerateUpdateDeviceRequestCommandCoreDetails(t *testing.T) { os.Exit(0) } +func TestGenerateUpdateDeviceRequestCommandDeviceDetails(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + func TestGenerateUpdateDeviceRequestCommandDiskDetails(t *testing.T) { if os.Getenv("GO_TEST_PROCESS") != "1" { return From eac727f36709e03f0acf4954d3dfad575ad00c4c Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Mon, 26 Jan 2026 14:29:02 +0000 Subject: [PATCH 03/10] Add additional comms tests --- .../internal/comms/comms_test.go | 82 ++++++++++++++++--- 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/hardware-discovery-agent/internal/comms/comms_test.go b/hardware-discovery-agent/internal/comms/comms_test.go index 97378469..dc1bc50b 100644 --- a/hardware-discovery-agent/internal/comms/comms_test.go +++ b/hardware-discovery-agent/internal/comms/comms_test.go @@ -426,6 +426,18 @@ func getUsbInfo() []*proto.SystemUSB { return usbInfo } +func TestGenerateUpdateDeviceRequestSuccessAllInfo(t *testing.T) { + network.ReadFile = mockedReadFile + network.ReadDir = mockedReadDir + network.Readlink = mockedReadlink + network.CollectEthtoolData = mockedCollectEthtoolData + network.Stat = mockedStat + json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassed) + expected := expectedSystemInfoResult("12A34B5", "Test Product", "192.168.1.50", getOsInfo(), getBiosInfo(), getCpuInfo(), getStorageInfo(), getGpuInfo(), 17179869184, getNetworkInfo(), proto.BmInfo_IPMI, getUsbInfo()) + require.NotNil(t, json) + assert.Equal(t, expected, json) +} + func TestGenerateUpdateDeviceRequestErr(t *testing.T) { json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandFailed) osKern := proto.OsKernel{} @@ -444,20 +456,25 @@ func TestGenerateUpdateDeviceRequestErr(t *testing.T) { assert.Equal(t, expected, json) } -func TestGenerateUpdateDeviceRequestSuccessAllInfo(t *testing.T) { - network.ReadFile = mockedReadFile - network.ReadDir = mockedReadDir - network.Readlink = mockedReadlink - network.CollectEthtoolData = mockedCollectEthtoolData - network.Stat = mockedStat - json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassed) - expected := expectedSystemInfoResult("12A34B5", "Test Product", "192.168.1.50", getOsInfo(), getBiosInfo(), getCpuInfo(), getStorageInfo(), getGpuInfo(), 17179869184, getNetworkInfo(), proto.BmInfo_IPMI, getUsbInfo()) +func TestGenerateUpdateDeviceRequestSuccessStorageOnly(t *testing.T) { + json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassedStorageOnly) + osKern := proto.OsKernel{} + osRelease := proto.OsRelease{} + osInfo := &proto.OsInfo{ + Kernel: &osKern, + Release: &osRelease, + } + cpu := &proto.SystemCPU{} + gpu := []*proto.SystemGPU{} + networks := []*proto.SystemNetwork{} + usbInfo := []*proto.SystemUSB{} + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, getStorageInfo(), gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) require.NotNil(t, json) assert.Equal(t, expected, json) } -func TestGenerateUpdateDeviceRequestSuccessStorageOnly(t *testing.T) { - json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassedStorageOnly) +func TestGeneraeUpdateDeviceRequestSuccessSerialNumberOnly(t *testing.T) { + json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassedSerialNumberOnly) osKern := proto.OsKernel{} osRelease := proto.OsRelease{} osInfo := &proto.OsInfo{ @@ -465,10 +482,29 @@ func TestGenerateUpdateDeviceRequestSuccessStorageOnly(t *testing.T) { Release: &osRelease, } cpu := &proto.SystemCPU{} + storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, getStorageInfo(), gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("12A34B5", "", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + require.NotNil(t, json) + assert.Equal(t, expected, json) +} + +func TestGenerateUpdateDeviceRequestSuccessProductNameOnly(t *testing.T) { + json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassedProductNameOnly) + osKern := proto.OsKernel{} + osRelease := proto.OsRelease{} + osInfo := &proto.OsInfo{ + Kernel: &osKern, + Release: &osRelease, + } + cpu := &proto.SystemCPU{} + storage := []*proto.SystemDisk{} + gpu := []*proto.SystemGPU{} + networks := []*proto.SystemNetwork{} + usbInfo := []*proto.SystemUSB{} + expected := expectedSystemInfoResult("", "Test Product", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -690,6 +726,30 @@ func testCmdExecutorCommandPassedStorageOnly(command string, args ...string) *ex } } +func testCmdExecutorCommandPassedSerialNumberOnly(command string, args ...string) *exec.Cmd { + if strings.Contains(command, "sudo") && strings.Contains(args[0], "dmidecode") { + if strings.Contains(args[2], "system-serial-number") { + return testCmd("TestGenerateUpdateDeviceRequestCommandSystemSerialNumber", command, args...) + } else { + return testCmd("TestGenerateUpdateDeviceRequestCommandFailed", command, args...) + } + } else { + return testCmd("TestGenerateUpdateDeviceRequestCommandFailed", command, args...) + } +} + +func testCmdExecutorCommandPassedProductNameOnly(command string, args ...string) *exec.Cmd { + if strings.Contains(command, "sudo") && strings.Contains(args[0], "dmidecode") { + if strings.Contains(args[2], "system-product-name") { + return testCmd("TestGenerateUpdateDeviceRequestCommandSystemProductName", command, args...) + } else { + return testCmd("TestGenerateUpdateDeviceRequestCommandFailed", command, args...) + } + } else { + return testCmd("TestGenerateUpdateDeviceRequestCommandFailed", command, args...) + } +} + func testCmdExecutorCommandPassedOsOnly(command string, args ...string) *exec.Cmd { if strings.Contains(command, "uname") { if strings.Contains(args[0], "-r") { From 71bd7407497f6f01a03aa6e02934a0800cfc7f6d Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Mon, 26 Jan 2026 18:02:16 +0000 Subject: [PATCH 04/10] Add fallback check for device ID and additional unit tests --- .../internal/device/device.go | 27 +- .../internal/device/device_test.go | 382 ++++++++++++++++-- .../test/data/mock_amtinfo.json | 29 +- .../data/mock_amtinfo_missingbuildnum.json | 35 ++ .../data/mock_amtinfo_missingcontrolmode.json | 35 ++ .../data/mock_amtinfo_missingdnssuffix.json | 35 ++ .../data/mock_amtinfo_missingfeature.json | 35 ++ .../data/mock_amtinfo_missinghostname.json | 35 ++ .../mock_amtinfo_missingnetworkstatus.json | 35 ++ .../data/mock_amtinfo_missingopstate.json | 35 ++ .../data/mock_amtinfo_missingrasinfo.json | 30 ++ .../mock_amtinfo_missingremotestatus.json | 35 ++ .../mock_amtinfo_missingremotetrigger.json | 35 ++ .../test/data/mock_amtinfo_missingsku.json | 35 ++ .../test/data/mock_amtinfo_missinguuid.json | 35 ++ .../data/mock_amtinfo_missingversion.json | 35 ++ 16 files changed, 851 insertions(+), 37 deletions(-) create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingbuildnum.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingcontrolmode.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingdnssuffix.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingfeature.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missinghostname.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingnetworkstatus.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingopstate.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingrasinfo.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingremotestatus.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingremotetrigger.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingsku.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missinguuid.json create mode 100644 hardware-discovery-agent/test/data/mock_amtinfo_missingversion.json diff --git a/hardware-discovery-agent/internal/device/device.go b/hardware-discovery-agent/internal/device/device.go index 3026a1a0..22ae6bde 100644 --- a/hardware-discovery-agent/internal/device/device.go +++ b/hardware-discovery-agent/internal/device/device.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" + "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/system" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/utils" ) @@ -19,14 +20,16 @@ type RASInfo struct { } type AMTInfo struct { - Version string `json:"version"` - BuildNumber string `json:"buildNumber"` - Sku string `json:"sku"` - Features string `json:"features"` - Uuid string `json:"uuid"` - ControlMode string `json:"controlMode"` - DNSSuffix string `json:"dnsSuffix"` - RAS RASInfo `json:"ras"` + Version string `json:"amt"` + Hostname string `json:"hostnameOS"` + OperationalState string `json:"operationalState"` + BuildNumber string `json:"buildNumber"` + Sku string `json:"sku"` + Features string `json:"features"` + Uuid string `json:"uuid"` + ControlMode string `json:"controlMode"` + DNSSuffix string `json:"dnsSuffix"` + RAS RASInfo `json:"ras"` } func GetDeviceInfo(executor utils.CmdExecutor) (AMTInfo, error) { @@ -41,5 +44,13 @@ func GetDeviceInfo(executor utils.CmdExecutor) (AMTInfo, error) { return amtInfo, fmt.Errorf("failed to parse data from command; error: %w", err) } + if amtInfo.Uuid == "" { + systemId, err := system.GetSystemUUID(executor) + if err != nil { + return AMTInfo{}, fmt.Errorf("failed to retrieve system uuid; error: %w", err) + } + amtInfo.Uuid = systemId + } + return amtInfo, nil } diff --git a/hardware-discovery-agent/internal/device/device_test.go b/hardware-discovery-agent/internal/device/device_test.go index 56108bd2..2674efc2 100644 --- a/hardware-discovery-agent/internal/device/device_test.go +++ b/hardware-discovery-agent/internal/device/device_test.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "os/exec" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -16,23 +17,45 @@ import ( "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/device" ) -func Test_GetDeviceInfo(t *testing.T) { - res, err := device.GetDeviceInfo(testSuccess) - expected := device.AMTInfo{ - Version: "16.1.27", - BuildNumber: "2176", - Sku: "16392", - Features: "AMT Pro Corporate", - Uuid: "1234abcd-ef56-7890-abcd-123456ef7890", - ControlMode: "activated in client control mode", - DNSSuffix: "test.com", +var testVersion = "16.1.27" +var testHostname = "testhost" +var testOperationalState = "enabled" +var testBuildNumber = "2176" +var testSku = "16392" +var testFeatures = "AMT Pro Corporate" +var testUuid = "1234abcd-ef56-7890-abcd-123456ef7890" +var testControlMode = "activated in client control mode" +var testDnsSuffix = "test.com" +var testNetworkStatus = "direct" +var testRemoteStatus = "not connected" +var testRemoteTrigger = "user initiated" + +func getExpectedResult(version string, hostname string, opState string, buildNum string, sku string, + features string, uuid string, controlMode string, dnsSuffix string, networkStatus string, + remoteStatus string, remoteTrigger string) device.AMTInfo { + return device.AMTInfo{ + Version: version, + Hostname: hostname, + OperationalState: opState, + BuildNumber: buildNum, + Sku: sku, + Features: features, + Uuid: uuid, + ControlMode: controlMode, + DNSSuffix: dnsSuffix, RAS: device.RASInfo{ - NetworkStatus: "direct", - RemoteStatus: "not connected", - RemoteTrigger: "user initiated", + NetworkStatus: networkStatus, + RemoteStatus: remoteStatus, + RemoteTrigger: remoteTrigger, MPSHostname: "", }, } +} + +func Test_GetDeviceInfo(t *testing.T) { + res, err := device.GetDeviceInfo(testSuccess) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, + testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } @@ -44,6 +67,13 @@ func Test_GetDeviceInfoFailed(t *testing.T) { assert.Equal(t, expected, res) } +func Test_GetDeviceInfoSystemUuidFailed(t *testing.T) { + res, err := device.GetDeviceInfo(testFailureSystemUuid) + var expected device.AMTInfo + assert.Error(t, err) + assert.Equal(t, expected, res) +} + func Test_GetDeviceInfoFailedUnmarshal(t *testing.T) { res, err := device.GetDeviceInfo(testFailureUnmarshal) var expected device.AMTInfo @@ -51,28 +81,192 @@ func Test_GetDeviceInfoFailedUnmarshal(t *testing.T) { assert.Equal(t, expected, res) } -func testSuccess(command string, args ...string) *exec.Cmd { - cs := []string{"-test.run=TestSuccess", "--", command} +func Test_GetDeviceInfoMissingVersionNumber(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingVersionNumber) + expected := getExpectedResult("", testHostname, testOperationalState, testBuildNumber, testSku, testFeatures, + testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingHostname(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingHostname) + expected := getExpectedResult(testVersion, "", testOperationalState, testBuildNumber, testSku, testFeatures, + testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingOperationalState(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingOperationalState) + expected := getExpectedResult(testVersion, testHostname, "", testBuildNumber, testSku, testFeatures, testUuid, + testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingBuildNumber(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingBuildNumber) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, "", testSku, testFeatures, testUuid, + testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingSku(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingSku) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, "", testFeatures, + testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingFeatures(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingFeatures) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, "", + testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingUuid(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingUuid) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, + testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingControlMode(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingControlMode) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, + testFeatures, testUuid, "", testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingDnsSuffix(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingDnsSuffix) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, + testFeatures, testUuid, testControlMode, "", testNetworkStatus, testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingRasInfo(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingRasInfo) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, + testFeatures, testUuid, testControlMode, testDnsSuffix, "", "", "") + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingNetworkStatus(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingNetworkStatus) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, + testFeatures, testUuid, testControlMode, testDnsSuffix, "", testRemoteStatus, testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingRemoteStatus(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingRemoteStatus) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, + testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, "", testRemoteTrigger) + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func Test_GetDeviceInfoMissingRemoteTrigger(t *testing.T) { + res, err := device.GetDeviceInfo(testMissingRemoteTrigger) + expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, + testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, "") + assert.NoError(t, err) + assert.Equal(t, expected, res) +} + +func testCmd(testFunc string, command string, args ...string) *exec.Cmd { + cs := []string{fmt.Sprintf("-test.run=%s", testFunc), "--", command} cs = append(cs, args...) cmd := exec.Command(os.Args[0], cs...) cmd.Env = []string{"GO_TEST_PROCESS=1"} return cmd } +func testSuccess(command string, args ...string) *exec.Cmd { + return testCmd("TestSuccess", command, args...) +} + func testFailure(command string, args ...string) *exec.Cmd { - cs := []string{"-test.run=TestFailure", "--", command} - cs = append(cs, args...) - cmd := exec.Command(os.Args[0], cs...) - cmd.Env = []string{"GO_TEST_PROCESS=1"} - return cmd + return testCmd("TestFailure", command, args...) +} + +func testFailureSystemUuid(command string, args ...string) *exec.Cmd { + if strings.Contains(args[0], "rpc") { + return testCmd("TestMissingUuid", command, args...) + } else { + return testCmd("TestFailure", command, args...) + } } func testFailureUnmarshal(command string, args ...string) *exec.Cmd { - cs := []string{"-test.run=TestFailureUnmarshal", "--", command} - cs = append(cs, args...) - cmd := exec.Command(os.Args[0], cs...) - cmd.Env = []string{"GO_TEST_PROCESS=1"} - return cmd + return testCmd("TestFailureUnmarshal", command, args...) +} + +func testMissingVersionNumber(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingVersionNumber", command, args...) +} + +func testMissingHostname(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingHostname", command, args...) +} + +func testMissingOperationalState(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingOperationalState", command, args...) +} + +func testMissingBuildNumber(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingBuildNumber", command, args...) +} + +func testMissingSku(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingSku", command, args...) +} + +func testMissingFeatures(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingFeatures", command, args...) +} + +func testMissingUuid(command string, args ...string) *exec.Cmd { + if strings.Contains(args[0], "rpc") { + return testCmd("TestMissingUuid", command, args...) + } else { + return testCmd("TestSystemUuid", command, args...) + } +} + +func testMissingControlMode(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingControlMode", command, args...) +} + +func testMissingDnsSuffix(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingDnsSuffix", command, args...) +} + +func testMissingRasInfo(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingRasInfo", command, args...) +} + +func testMissingNetworkStatus(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingNetworkStatus", command, args...) +} + +func testMissingRemoteStatus(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingRemoteStatus", command, args...) +} + +func testMissingRemoteTrigger(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingRemoteTrigger", command, args...) } func TestSuccess(t *testing.T) { @@ -100,3 +294,141 @@ func TestFailureUnmarshal(_ *testing.T) { fmt.Fprintf(os.Stdout, "%v", string("not a json")) os.Exit(0) } + +func TestMissingVersionNumber(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingversion.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingHostname(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missinghostname.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingOperationalState(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingopstate.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingBuildNumber(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingbuildnum.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingSku(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingsku.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingFeatures(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingfeature.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingUuid(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missinguuid.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestSystemUuid(_ *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + fmt.Fprintf(os.Stdout, "%v", testUuid) + os.Exit(0) +} + +func TestMissingControlMode(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingcontrolmode.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingDnsSuffix(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingdnssuffix.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingRasInfo(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingrasinfo.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingNetworkStatus(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingnetworkstatus.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingRemoteStatus(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingremotestatus.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} + +func TestMissingRemoteTrigger(t *testing.T) { + if os.Getenv("GO_TEST_PROCESS") != "1" { + return + } + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingremotetrigger.json") + require.NoError(t, err) + fmt.Fprintf(os.Stdout, "%v", string(testData)) + os.Exit(0) +} diff --git a/hardware-discovery-agent/test/data/mock_amtinfo.json b/hardware-discovery-agent/test/data/mock_amtinfo.json index 4d06390a..5724ca75 100644 --- a/hardware-discovery-agent/test/data/mock_amtinfo.json +++ b/hardware-discovery-agent/test/data/mock_amtinfo.json @@ -1,15 +1,36 @@ { - "version": "16.1.27", + "amt": "16.1.27", "buildNumber": "2176", - "sku": "16392", - "features": "AMT Pro Corporate", - "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", "controlMode": "activated in client control mode", "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", "ras": { "networkStatus": "direct", "remoteStatus": "not connected", "remoteTrigger": "user initiated", "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" } } \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingbuildnum.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingbuildnum.json new file mode 100644 index 00000000..0b8138a4 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingbuildnum.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingcontrolmode.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingcontrolmode.json new file mode 100644 index 00000000..e38d101f --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingcontrolmode.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingdnssuffix.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingdnssuffix.json new file mode 100644 index 00000000..ce7b0426 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingdnssuffix.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingfeature.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingfeature.json new file mode 100644 index 00000000..148c1380 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingfeature.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missinghostname.json b/hardware-discovery-agent/test/data/mock_amtinfo_missinghostname.json new file mode 100644 index 00000000..3649eab8 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missinghostname.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingnetworkstatus.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingnetworkstatus.json new file mode 100644 index 00000000..82213266 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingnetworkstatus.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingopstate.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingopstate.json new file mode 100644 index 00000000..36047d9b --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingopstate.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingrasinfo.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingrasinfo.json new file mode 100644 index 00000000..d8027ae2 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingrasinfo.json @@ -0,0 +1,30 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingremotestatus.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingremotestatus.json new file mode 100644 index 00000000..1bd8eea7 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingremotestatus.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingremotetrigger.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingremotetrigger.json new file mode 100644 index 00000000..241cc07c --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingremotetrigger.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingsku.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingsku.json new file mode 100644 index 00000000..520be320 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingsku.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missinguuid.json b/hardware-discovery-agent/test/data/mock_amtinfo_missinguuid.json new file mode 100644 index 00000000..d2aaf5d8 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missinguuid.json @@ -0,0 +1,35 @@ +{ + "amt": "16.1.27", + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missingversion.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingversion.json new file mode 100644 index 00000000..02248dc9 --- /dev/null +++ b/hardware-discovery-agent/test/data/mock_amtinfo_missingversion.json @@ -0,0 +1,35 @@ +{ + "buildNumber": "2176", + "controlMode": "activated in client control mode", + "dnsSuffix": "test.com", + "dnsSuffixOS": "localhost", + "features": "AMT Pro Corporate", + "hostnameOS": "testhost", + "operationalState": "enabled", + "ras": { + "networkStatus": "direct", + "remoteStatus": "not connected", + "remoteTrigger": "user initiated", + "mpsHostname": "" + }, + "sku": "16392", + "uuid": "1234abcd-ef56-7890-abcd-123456ef7890", + "wiredAdapter": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "1a:b2:3c:d4:5e:f6" + }, + "wirelessAddress": { + "isEnable": false, + "linkStatus": "down", + "dhcpEnabled": false, + "dhcpMode": "passive", + "ipAddress": "0.0.0.0", + "osIpAddress": "0.0.0.0", + "macAddress": "a1:2b:c3:4d:e5:6f" + } +} \ No newline at end of file From 194e9033c6aca9b4d540910df53e7a3607083800 Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Wed, 28 Jan 2026 12:19:00 +0000 Subject: [PATCH 05/10] Fix apparmor typo --- .../config/apparmor.d/opt.edge-node.bin.hd-agent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware-discovery-agent/config/apparmor.d/opt.edge-node.bin.hd-agent b/hardware-discovery-agent/config/apparmor.d/opt.edge-node.bin.hd-agent index 2b57c7f5..52fa3211 100644 --- a/hardware-discovery-agent/config/apparmor.d/opt.edge-node.bin.hd-agent +++ b/hardware-discovery-agent/config/apparmor.d/opt.edge-node.bin.hd-agent @@ -289,7 +289,7 @@ profile hda_sudo { /run/systemd/resolve/stub-resolv.conf r, /usr/bin/ipmitool rPx -> hda_ipmitool, /usr/bin/lshw rPx -> hda_lshw, - /usr/bin/rpc ix + /usr/bin/rpc ix, /usr/bin/sudo mr, /usr/libexec/sudo/libsudo_util.so.* mr, /usr/sbin/dmidecode rPx -> hda_dmidecode, From 2c6a03551d4a484ea07841309b19a16a0dcba938 Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Wed, 28 Jan 2026 12:19:35 +0000 Subject: [PATCH 06/10] Update license headers --- hardware-discovery-agent/internal/comms/comms.go | 2 +- hardware-discovery-agent/internal/comms/comms_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware-discovery-agent/internal/comms/comms.go b/hardware-discovery-agent/internal/comms/comms.go index 51953c6e..74839844 100644 --- a/hardware-discovery-agent/internal/comms/comms.go +++ b/hardware-discovery-agent/internal/comms/comms.go @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: (C) 2025 Intel Corporation +// SPDX-FileCopyrightText: (C) 2026 Intel Corporation // SPDX-License-Identifier: Apache-2.0 package comms diff --git a/hardware-discovery-agent/internal/comms/comms_test.go b/hardware-discovery-agent/internal/comms/comms_test.go index dc1bc50b..2b10e3be 100644 --- a/hardware-discovery-agent/internal/comms/comms_test.go +++ b/hardware-discovery-agent/internal/comms/comms_test.go @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: (C) 2025 Intel Corporation +// SPDX-FileCopyrightText: (C) 2026 Intel Corporation // SPDX-License-Identifier: Apache-2.0 package comms_test From 7d84d8a4e9e6628ef6ed34b2f400ef5aadea9607 Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Tue, 24 Feb 2026 16:17:37 +0000 Subject: [PATCH 07/10] Rename local structure --- .../internal/device/device.go | 20 +++++++++---------- .../internal/device/device_test.go | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hardware-discovery-agent/internal/device/device.go b/hardware-discovery-agent/internal/device/device.go index 22ae6bde..75a6a6bd 100644 --- a/hardware-discovery-agent/internal/device/device.go +++ b/hardware-discovery-agent/internal/device/device.go @@ -19,7 +19,7 @@ type RASInfo struct { MPSHostname string `json:"mpsHostname"` } -type AMTInfo struct { +type DeviceInfo struct { Version string `json:"amt"` Hostname string `json:"hostnameOS"` OperationalState string `json:"operationalState"` @@ -32,25 +32,25 @@ type AMTInfo struct { RAS RASInfo `json:"ras"` } -func GetDeviceInfo(executor utils.CmdExecutor) (AMTInfo, error) { - var amtInfo AMTInfo +func GetDeviceInfo(executor utils.CmdExecutor) (DeviceInfo, error) { + var deviceInfo DeviceInfo dataBytes, err := utils.ReadFromCommand(executor, "sudo", "rpc", "amtinfo", "-json") if err != nil { - return amtInfo, fmt.Errorf("failed to read data from command; error: %w", err) + return deviceInfo, fmt.Errorf("failed to read data from command; error: %w", err) } - err = json.Unmarshal(dataBytes, &amtInfo) + err = json.Unmarshal(dataBytes, &deviceInfo) if err != nil { - return amtInfo, fmt.Errorf("failed to parse data from command; error: %w", err) + return deviceInfo, fmt.Errorf("failed to parse data from command; error: %w", err) } - if amtInfo.Uuid == "" { + if deviceInfo.Uuid == "" { systemId, err := system.GetSystemUUID(executor) if err != nil { - return AMTInfo{}, fmt.Errorf("failed to retrieve system uuid; error: %w", err) + return DeviceInfo{}, fmt.Errorf("failed to retrieve system uuid; error: %w", err) } - amtInfo.Uuid = systemId + deviceInfo.Uuid = systemId } - return amtInfo, nil + return deviceInfo, nil } diff --git a/hardware-discovery-agent/internal/device/device_test.go b/hardware-discovery-agent/internal/device/device_test.go index 2674efc2..faceaf58 100644 --- a/hardware-discovery-agent/internal/device/device_test.go +++ b/hardware-discovery-agent/internal/device/device_test.go @@ -32,8 +32,8 @@ var testRemoteTrigger = "user initiated" func getExpectedResult(version string, hostname string, opState string, buildNum string, sku string, features string, uuid string, controlMode string, dnsSuffix string, networkStatus string, - remoteStatus string, remoteTrigger string) device.AMTInfo { - return device.AMTInfo{ + remoteStatus string, remoteTrigger string) device.DeviceInfo { + return device.DeviceInfo{ Version: version, Hostname: hostname, OperationalState: opState, @@ -62,21 +62,21 @@ func Test_GetDeviceInfo(t *testing.T) { func Test_GetDeviceInfoFailed(t *testing.T) { res, err := device.GetDeviceInfo(testFailure) - var expected device.AMTInfo + var expected device.DeviceInfo assert.Error(t, err) assert.Equal(t, expected, res) } func Test_GetDeviceInfoSystemUuidFailed(t *testing.T) { res, err := device.GetDeviceInfo(testFailureSystemUuid) - var expected device.AMTInfo + var expected device.DeviceInfo assert.Error(t, err) assert.Equal(t, expected, res) } func Test_GetDeviceInfoFailedUnmarshal(t *testing.T) { res, err := device.GetDeviceInfo(testFailureUnmarshal) - var expected device.AMTInfo + var expected device.DeviceInfo assert.Error(t, err) assert.Equal(t, expected, res) } From 3a6e3dae0a48d9f42773f8e46d963ae1304cc4e9 Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Tue, 24 Feb 2026 17:48:56 +0000 Subject: [PATCH 08/10] Update SystemInfo generation to include new DeviceInfo struct --- hardware-discovery-agent/go.mod | 8 +-- hardware-discovery-agent/go.sum | 6 ++ .../internal/comms/comms.go | 43 ++++++++++++- .../internal/comms/comms_test.go | 62 +++++++++++-------- .../internal/device/device.go | 30 ++++----- .../internal/device/device_test.go | 57 ++++++++++------- 6 files changed, 135 insertions(+), 71 deletions(-) diff --git a/hardware-discovery-agent/go.mod b/hardware-discovery-agent/go.mod index c62c9c8e..b17c0084 100644 --- a/hardware-discovery-agent/go.mod +++ b/hardware-discovery-agent/go.mod @@ -1,18 +1,18 @@ module github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent -go 1.25.5 +go 1.25.7 require ( github.com/cenkalti/backoff v2.2.1+incompatible github.com/cenkalti/backoff/v4 v4.3.0 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.3 github.com/open-edge-platform/edge-node-agents/common v1.10.0 - github.com/open-edge-platform/infra-managers/host v1.24.1 + github.com/open-edge-platform/infra-managers/host v1.25.3-0.20260224153806-441992a7dc4b github.com/safchain/ethtool v0.7.0 github.com/sirupsen/logrus v1.9.4 github.com/stretchr/testify v1.11.1 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.65.0 - google.golang.org/grpc v1.78.0 + google.golang.org/grpc v1.80.0-dev gopkg.in/yaml.v3 v3.0.1 ) @@ -23,7 +23,7 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/ebitengine/purego v0.9.1 // indirect - github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect + github.com/envoyproxy/protoc-gen-validate v1.3.0 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect diff --git a/hardware-discovery-agent/go.sum b/hardware-discovery-agent/go.sum index 21973694..15c40006 100644 --- a/hardware-discovery-agent/go.sum +++ b/hardware-discovery-agent/go.sum @@ -16,6 +16,8 @@ github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8= github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU= +github.com/envoyproxy/protoc-gen-validate v1.3.0 h1:TvGH1wof4H33rezVKWSpqKz5NXWg5VPuZ0uONDT6eb4= +github.com/envoyproxy/protoc-gen-validate v1.3.0/go.mod h1:HvYl7zwPa5mffgyeTUHA9zHIH36nmrm7oCbo4YKoSWA= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -46,6 +48,8 @@ github.com/open-edge-platform/edge-node-agents/common v1.10.0 h1:+e43e4yPjtTJLlV github.com/open-edge-platform/edge-node-agents/common v1.10.0/go.mod h1:kFEVak/irwkcHaaUdeimwfVNB7HdAwdMvsg56m5hnY8= github.com/open-edge-platform/infra-managers/host v1.24.1 h1:maFaMENysk2THSjws3OUHNzhKhzaaMzKQ6ZX7wLK0mI= github.com/open-edge-platform/infra-managers/host v1.24.1/go.mod h1:HCZqBlFbO/JGKg4i797wujirxPOX5AtC6SdrWxThGSY= +github.com/open-edge-platform/infra-managers/host v1.25.3-0.20260224153806-441992a7dc4b h1:/v86SnswpTRx/OzS200YpL2ZXXUiKorUHM2T4dlV9NA= +github.com/open-edge-platform/infra-managers/host v1.25.3-0.20260224153806-441992a7dc4b/go.mod h1:WweXot60IvWxW5aB9VrZSfQhwyat07q8rq233dd4cSw= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= @@ -109,6 +113,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc= google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U= +google.golang.org/grpc v1.80.0-dev h1:n93B3+tPiXo01iQAJ2dniKR8veelXd9upFkDNvweUAM= +google.golang.org/grpc v1.80.0-dev/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/hardware-discovery-agent/internal/comms/comms.go b/hardware-discovery-agent/internal/comms/comms.go index 74839844..a3638e8b 100644 --- a/hardware-discovery-agent/internal/comms/comms.go +++ b/hardware-discovery-agent/internal/comms/comms.go @@ -127,7 +127,8 @@ func ConnectToEdgeInfrastructureManager(serverAddr string, tlsConfig *tls.Config } func parseSystemInfo(serialNumber string, productName string, bmcAddr string, osInfo *system.Os, biosInfo *system.Bios, cpu *cpu.CPU, - storage []*disk.Disk, gpu []*gpu.Gpu, mem uint64, networks []*network.Network, bmType proto.BmInfo_BmType, usbInfo []*usb.Usb) *proto.SystemInfo { + storage []*disk.Disk, gpu []*gpu.Gpu, mem uint64, networks []*network.Network, bmType proto.BmInfo_BmType, usbInfo []*usb.Usb, + device *device.DeviceInfo) *proto.SystemInfo { gpuList := []*proto.SystemGPU{} for _, gpuDetails := range gpu { @@ -276,6 +277,41 @@ func parseSystemInfo(serialNumber string, productName string, bmcAddr string, os } } + deviceInfo := proto.DeviceInfo{} + if device != nil { + if device.RAS != nil { + deviceInfo = proto.DeviceInfo{ + Version: device.Version, + Hostname: device.Hostname, + OperationalState: device.OperationalState, + BuildNumber: device.BuildNumber, + Sku: device.Sku, + Features: device.Features, + DeviceGuid: device.Uuid, + ControlMode: device.ControlMode, + DnsSuffix: device.DNSSuffix, + RasInfo: &proto.RASInfo{ + NetworkStatus: device.RAS.NetworkStatus, + RemoteStatus: device.RAS.RemoteStatus, + RemoteTrigger: device.RAS.RemoteTrigger, + MpsHostname: device.RAS.MPSHostname, + }, + } + } else { + deviceInfo = proto.DeviceInfo{ + Version: device.Version, + Hostname: device.Hostname, + OperationalState: device.OperationalState, + BuildNumber: device.BuildNumber, + Sku: device.Sku, + Features: device.Features, + DeviceGuid: device.Uuid, + ControlMode: device.ControlMode, + DnsSuffix: device.DNSSuffix, + } + } + } + systemInfo := &proto.SystemInfo{ HwInfo: &proto.HWInfo{ SerialNum: serialNumber, @@ -302,6 +338,7 @@ func parseSystemInfo(serialNumber string, productName string, bmcAddr string, os ReleaseDate: biosInfo.RelDate, Vendor: biosInfo.Vendor, }, + DeviceInfo: &deviceInfo, } return systemInfo @@ -358,10 +395,10 @@ func GenerateSystemInfoRequest(executor utils.CmdExecutor) *proto.SystemInfo { log.Errorf("unable to get usb description : %v", err) } - _, err = device.GetDeviceInfo(executor) + deviceInfo, err := device.GetDeviceInfo(executor) if err != nil { log.Errorf("unable to get device description : %v", err) } - return parseSystemInfo(sn, productName, bmcAddr, osInfo, biosInfo, cpu, storage, gpu, mem, networkList, bmType, usbList) + return parseSystemInfo(sn, productName, bmcAddr, osInfo, biosInfo, cpu, storage, gpu, mem, networkList, bmType, usbList, deviceInfo) } diff --git a/hardware-discovery-agent/internal/comms/comms_test.go b/hardware-discovery-agent/internal/comms/comms_test.go index 2b10e3be..26223484 100644 --- a/hardware-discovery-agent/internal/comms/comms_test.go +++ b/hardware-discovery-agent/internal/comms/comms_test.go @@ -208,7 +208,7 @@ func TestFailedSystemInfoUpdate(t *testing.T) { } func expectedSystemInfoResult(sn string, productName string, bmcAddr string, osInfo *proto.OsInfo, biosInfo *proto.BiosInfo, cpu *proto.SystemCPU, storage []*proto.SystemDisk, - gpu []*proto.SystemGPU, mem uint64, networks []*proto.SystemNetwork, bmType proto.BmInfo_BmType, usbInfo []*proto.SystemUSB) *proto.SystemInfo { + gpu []*proto.SystemGPU, mem uint64, networks []*proto.SystemNetwork, bmType proto.BmInfo_BmType, usbInfo []*proto.SystemUSB, deviceInfo *proto.DeviceInfo) *proto.SystemInfo { return &proto.SystemInfo{ HwInfo: &proto.HWInfo{ @@ -228,7 +228,8 @@ func expectedSystemInfoResult(sn string, productName string, bmcAddr string, osI BmIp: bmcAddr, }, }, - BiosInfo: biosInfo, + BiosInfo: biosInfo, + DeviceInfo: deviceInfo, } } @@ -426,6 +427,26 @@ func getUsbInfo() []*proto.SystemUSB { return usbInfo } +func getDeviceInfo() *proto.DeviceInfo { + return &proto.DeviceInfo{ + Version: "16.1.27", + Hostname: "testhost", + OperationalState: "enabled", + BuildNumber: "2176", + Sku: "16392", + Features: "AMT Pro Corporate", + DeviceGuid: "1234abcd-ef56-7890-abcd-123456ef7890", + ControlMode: "activated in client control mode", + DnsSuffix: "test.com", + RasInfo: &proto.RASInfo{ + NetworkStatus: "direct", + RemoteStatus: "not connected", + RemoteTrigger: "user initiated", + MpsHostname: "", + }, + } +} + func TestGenerateUpdateDeviceRequestSuccessAllInfo(t *testing.T) { network.ReadFile = mockedReadFile network.ReadDir = mockedReadDir @@ -433,7 +454,7 @@ func TestGenerateUpdateDeviceRequestSuccessAllInfo(t *testing.T) { network.CollectEthtoolData = mockedCollectEthtoolData network.Stat = mockedStat json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassed) - expected := expectedSystemInfoResult("12A34B5", "Test Product", "192.168.1.50", getOsInfo(), getBiosInfo(), getCpuInfo(), getStorageInfo(), getGpuInfo(), 17179869184, getNetworkInfo(), proto.BmInfo_IPMI, getUsbInfo()) + expected := expectedSystemInfoResult("12A34B5", "Test Product", "192.168.1.50", getOsInfo(), getBiosInfo(), getCpuInfo(), getStorageInfo(), getGpuInfo(), 17179869184, getNetworkInfo(), proto.BmInfo_IPMI, getUsbInfo(), getDeviceInfo()) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -446,12 +467,11 @@ func TestGenerateUpdateDeviceRequestErr(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -464,11 +484,10 @@ func TestGenerateUpdateDeviceRequestSuccessStorageOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, getStorageInfo(), gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, getStorageInfo(), gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -481,12 +500,11 @@ func TestGeneraeUpdateDeviceRequestSuccessSerialNumberOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("12A34B5", "", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("12A34B5", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -499,24 +517,22 @@ func TestGenerateUpdateDeviceRequestSuccessProductNameOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "Test Product", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "Test Product", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } func TestGenerateUpdateDeviceRequestSuccessOsOnly(t *testing.T) { json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassedOsOnly) - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", getOsInfo(), &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "", "", getOsInfo(), &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -529,12 +545,11 @@ func TestGenerateUpdateDeviceRequestSuccessBiosOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, getBiosInfo(), cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "", "", osInfo, getBiosInfo(), &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -551,7 +566,7 @@ func TestGenerateUpdateDeviceRequestSuccessCpuOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, getCpuInfo(), storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, getCpuInfo(), storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -564,11 +579,10 @@ func TestGenerateUpdateDeviceRequestSuccessGpuOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, storage, getGpuInfo(), uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, getGpuInfo(), uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -581,12 +595,11 @@ func TestGenerateUpdateDeviceRequestSuccessMemoryOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, 17179869184, networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, 17179869184, networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -604,11 +617,10 @@ func TestGenerateUpdateDeviceRequestSuccessNetworkOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "192.168.1.50", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), getNetworkInfo(), proto.BmInfo_IPMI, usbInfo) + expected := expectedSystemInfoResult("", "", "192.168.1.50", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), getNetworkInfo(), proto.BmInfo_IPMI, usbInfo, &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -621,11 +633,10 @@ func TestGenerateUpdateDeviceRequestSuccessUsbInfoOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, getUsbInfo()) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, getUsbInfo(), &proto.DeviceInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -638,12 +649,11 @@ func TestGenerateUpdateDeviceRequestSuccessDeviceInfoOnly(t *testing.T) { Kernel: &osKern, Release: &osRelease, } - cpu := &proto.SystemCPU{} storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, cpu, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, getDeviceInfo()) require.NotNil(t, json) assert.Equal(t, expected, json) } diff --git a/hardware-discovery-agent/internal/device/device.go b/hardware-discovery-agent/internal/device/device.go index 75a6a6bd..eedb8f4c 100644 --- a/hardware-discovery-agent/internal/device/device.go +++ b/hardware-discovery-agent/internal/device/device.go @@ -20,37 +20,37 @@ type RASInfo struct { } type DeviceInfo struct { - Version string `json:"amt"` - Hostname string `json:"hostnameOS"` - OperationalState string `json:"operationalState"` - BuildNumber string `json:"buildNumber"` - Sku string `json:"sku"` - Features string `json:"features"` - Uuid string `json:"uuid"` - ControlMode string `json:"controlMode"` - DNSSuffix string `json:"dnsSuffix"` - RAS RASInfo `json:"ras"` + Version string `json:"amt"` + Hostname string `json:"hostnameOS"` + OperationalState string `json:"operationalState"` + BuildNumber string `json:"buildNumber"` + Sku string `json:"sku"` + Features string `json:"features"` + Uuid string `json:"uuid"` + ControlMode string `json:"controlMode"` + DNSSuffix string `json:"dnsSuffix"` + RAS *RASInfo `json:"ras"` } -func GetDeviceInfo(executor utils.CmdExecutor) (DeviceInfo, error) { +func GetDeviceInfo(executor utils.CmdExecutor) (*DeviceInfo, error) { var deviceInfo DeviceInfo dataBytes, err := utils.ReadFromCommand(executor, "sudo", "rpc", "amtinfo", "-json") if err != nil { - return deviceInfo, fmt.Errorf("failed to read data from command; error: %w", err) + return &DeviceInfo{}, fmt.Errorf("failed to read data from command; error: %w", err) } err = json.Unmarshal(dataBytes, &deviceInfo) if err != nil { - return deviceInfo, fmt.Errorf("failed to parse data from command; error: %w", err) + return &DeviceInfo{}, fmt.Errorf("failed to parse data from command; error: %w", err) } if deviceInfo.Uuid == "" { systemId, err := system.GetSystemUUID(executor) if err != nil { - return DeviceInfo{}, fmt.Errorf("failed to retrieve system uuid; error: %w", err) + return &DeviceInfo{}, fmt.Errorf("failed to retrieve system uuid; error: %w", err) } deviceInfo.Uuid = systemId } - return deviceInfo, nil + return &deviceInfo, nil } diff --git a/hardware-discovery-agent/internal/device/device_test.go b/hardware-discovery-agent/internal/device/device_test.go index faceaf58..3111094e 100644 --- a/hardware-discovery-agent/internal/device/device_test.go +++ b/hardware-discovery-agent/internal/device/device_test.go @@ -32,23 +32,37 @@ var testRemoteTrigger = "user initiated" func getExpectedResult(version string, hostname string, opState string, buildNum string, sku string, features string, uuid string, controlMode string, dnsSuffix string, networkStatus string, - remoteStatus string, remoteTrigger string) device.DeviceInfo { - return device.DeviceInfo{ - Version: version, - Hostname: hostname, - OperationalState: opState, - BuildNumber: buildNum, - Sku: sku, - Features: features, - Uuid: uuid, - ControlMode: controlMode, - DNSSuffix: dnsSuffix, - RAS: device.RASInfo{ - NetworkStatus: networkStatus, - RemoteStatus: remoteStatus, - RemoteTrigger: remoteTrigger, - MPSHostname: "", - }, + remoteStatus string, remoteTrigger string) *device.DeviceInfo { + if networkStatus == "" && remoteStatus == "" && remoteTrigger == "" { + return &device.DeviceInfo{ + Version: version, + Hostname: hostname, + OperationalState: opState, + BuildNumber: buildNum, + Sku: sku, + Features: features, + Uuid: uuid, + ControlMode: controlMode, + DNSSuffix: dnsSuffix, + } + } else { + return &device.DeviceInfo{ + Version: version, + Hostname: hostname, + OperationalState: opState, + BuildNumber: buildNum, + Sku: sku, + Features: features, + Uuid: uuid, + ControlMode: controlMode, + DNSSuffix: dnsSuffix, + RAS: &device.RASInfo{ + NetworkStatus: networkStatus, + RemoteStatus: remoteStatus, + RemoteTrigger: remoteTrigger, + MPSHostname: "", + }, + } } } @@ -62,23 +76,20 @@ func Test_GetDeviceInfo(t *testing.T) { func Test_GetDeviceInfoFailed(t *testing.T) { res, err := device.GetDeviceInfo(testFailure) - var expected device.DeviceInfo assert.Error(t, err) - assert.Equal(t, expected, res) + assert.Equal(t, &device.DeviceInfo{}, res) } func Test_GetDeviceInfoSystemUuidFailed(t *testing.T) { res, err := device.GetDeviceInfo(testFailureSystemUuid) - var expected device.DeviceInfo assert.Error(t, err) - assert.Equal(t, expected, res) + assert.Equal(t, &device.DeviceInfo{}, res) } func Test_GetDeviceInfoFailedUnmarshal(t *testing.T) { res, err := device.GetDeviceInfo(testFailureUnmarshal) - var expected device.DeviceInfo assert.Error(t, err) - assert.Equal(t, expected, res) + assert.Equal(t, &device.DeviceInfo{}, res) } func Test_GetDeviceInfoMissingVersionNumber(t *testing.T) { From 782f44001cd311f5862f40a5f83b09029dbe8374 Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Wed, 18 Mar 2026 16:18:58 +0000 Subject: [PATCH 09/10] Fix branch merge commit --- hardware-discovery-agent/go.mod | 17 +------------- hardware-discovery-agent/go.sum | 39 ++------------------------------- 2 files changed, 3 insertions(+), 53 deletions(-) diff --git a/hardware-discovery-agent/go.mod b/hardware-discovery-agent/go.mod index 22e9445b..3d636476 100644 --- a/hardware-discovery-agent/go.mod +++ b/hardware-discovery-agent/go.mod @@ -6,23 +6,13 @@ require ( github.com/cenkalti/backoff v2.2.1+incompatible github.com/cenkalti/backoff/v4 v4.3.0 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.3 -<<<<<<< vpro-support-reporting - github.com/open-edge-platform/edge-node-agents/common v1.10.0 - github.com/open-edge-platform/infra-managers/host v1.25.3-0.20260224153806-441992a7dc4b - github.com/safchain/ethtool v0.7.0 - github.com/sirupsen/logrus v1.9.4 - github.com/stretchr/testify v1.11.1 - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.65.0 - google.golang.org/grpc v1.80.0-dev -======= github.com/open-edge-platform/edge-node-agents/common v1.10.1 - github.com/open-edge-platform/infra-managers/host v1.25.4 + github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260318161218-8db11f57899b github.com/safchain/ethtool v0.7.0 github.com/sirupsen/logrus v1.9.4 github.com/stretchr/testify v1.11.1 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0 google.golang.org/grpc v1.81.0-dev ->>>>>>> main gopkg.in/yaml.v3 v3.0.1 ) @@ -32,13 +22,8 @@ require ( github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect -<<<<<<< vpro-support-reporting - github.com/ebitengine/purego v0.9.1 // indirect - github.com/envoyproxy/protoc-gen-validate v1.3.0 // indirect -======= github.com/ebitengine/purego v0.10.0 // indirect github.com/envoyproxy/protoc-gen-validate v1.3.3 // indirect ->>>>>>> main github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect diff --git a/hardware-discovery-agent/go.sum b/hardware-discovery-agent/go.sum index 092ff10a..cdd961d1 100644 --- a/hardware-discovery-agent/go.sum +++ b/hardware-discovery-agent/go.sum @@ -12,19 +12,10 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -<<<<<<< vpro-support-reporting -github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s0A= -github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= -github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8= -github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU= -github.com/envoyproxy/protoc-gen-validate v1.3.0 h1:TvGH1wof4H33rezVKWSpqKz5NXWg5VPuZ0uONDT6eb4= -github.com/envoyproxy/protoc-gen-validate v1.3.0/go.mod h1:HvYl7zwPa5mffgyeTUHA9zHIH36nmrm7oCbo4YKoSWA= -======= github.com/ebitengine/purego v0.10.0 h1:QIw4xfpWT6GWTzaW5XEKy3HXoqrJGx1ijYHzTF0/ISU= github.com/ebitengine/purego v0.10.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/envoyproxy/protoc-gen-validate v1.3.3 h1:MVQghNeW+LZcmXe7SY1V36Z+WFMDjpqGAGacLe2T0ds= github.com/envoyproxy/protoc-gen-validate v1.3.3/go.mod h1:TsndJ/ngyIdQRhMcVVGDDHINPLWB7C82oDArY51KfB0= ->>>>>>> main github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -49,23 +40,14 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -<<<<<<< vpro-support-reporting -github.com/lufia/plan9stats v0.0.0-20251013123823-9fd1530e3ec3 h1:PwQumkgq4/acIiZhtifTV5OUqqiP82UAl0h87xj/l9k= -github.com/lufia/plan9stats v0.0.0-20251013123823-9fd1530e3ec3/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg= -github.com/open-edge-platform/edge-node-agents/common v1.10.0 h1:+e43e4yPjtTJLlVnRcqpPhdbwgZG0ow/M35RVebIwGA= -github.com/open-edge-platform/edge-node-agents/common v1.10.0/go.mod h1:kFEVak/irwkcHaaUdeimwfVNB7HdAwdMvsg56m5hnY8= -github.com/open-edge-platform/infra-managers/host v1.24.1 h1:maFaMENysk2THSjws3OUHNzhKhzaaMzKQ6ZX7wLK0mI= -github.com/open-edge-platform/infra-managers/host v1.24.1/go.mod h1:HCZqBlFbO/JGKg4i797wujirxPOX5AtC6SdrWxThGSY= -github.com/open-edge-platform/infra-managers/host v1.25.3-0.20260224153806-441992a7dc4b h1:/v86SnswpTRx/OzS200YpL2ZXXUiKorUHM2T4dlV9NA= -github.com/open-edge-platform/infra-managers/host v1.25.3-0.20260224153806-441992a7dc4b/go.mod h1:WweXot60IvWxW5aB9VrZSfQhwyat07q8rq233dd4cSw= -======= github.com/lufia/plan9stats v0.0.0-20260216142805-b3301c5f2a88 h1:PTw+yKnXcOFCR6+8hHTyWBeQ/P4Nb7dd4/0ohEcWQuM= github.com/lufia/plan9stats v0.0.0-20260216142805-b3301c5f2a88/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg= github.com/open-edge-platform/edge-node-agents/common v1.10.1 h1:o25PgbWvAMSmtWWsD72LYncvQp6qSoYvAM5OzutaQX4= github.com/open-edge-platform/edge-node-agents/common v1.10.1/go.mod h1:AsVGM6J0GfIzHYEZav6eWpNGcz/PzIyVGg6fxr4C2rg= github.com/open-edge-platform/infra-managers/host v1.25.4 h1:5Ulfpasc3y8F5TwpSZYMQAA58SkIwWItKHrd/lai3gE= github.com/open-edge-platform/infra-managers/host v1.25.4/go.mod h1:1aEoXXhxW9OIBIK71u+SHg9vn60pemsyLZIzAkBZU9o= ->>>>>>> main +github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260318161218-8db11f57899b h1:tBqLy/6CuoJBEN+4G8HTITPEeyPwexNSKDQQl9f7pbc= +github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260318161218-8db11f57899b/go.mod h1:wh8qa1GjMTMVM78275y4lZR9iJEZZRnoWDldkVk4ygU= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= @@ -117,22 +99,6 @@ golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7 golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -<<<<<<< vpro-support-reporting -golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= -golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= -golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= -gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= -gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= -google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 h1:merA0rdPeUV3YIIfHHcH4qBkiQAc1nfCKSI7lB4cV2M= -google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409/go.mod h1:fl8J1IvUjCilwZzQowmw2b7HQB2eAuYBabMXzWurF+I= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 h1:H86B94AW+VfJWDqFeEbBPhEtHzJwJfTbgE2lZa54ZAQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= -google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc= -google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U= -google.golang.org/grpc v1.80.0-dev h1:n93B3+tPiXo01iQAJ2dniKR8veelXd9upFkDNvweUAM= -google.golang.org/grpc v1.80.0-dev/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ= -======= golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= @@ -145,7 +111,6 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= google.golang.org/grpc v1.81.0-dev h1:uzUVIOArPG2WIWvAqK9vE6Eriyon0hELME7Z2LulcHQ= google.golang.org/grpc v1.81.0-dev/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= ->>>>>>> main google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 524846ed259ddeca4f13fc2437a14470663e1f40 Mon Sep 17 00:00:00 2001 From: Christopher Nolan Date: Fri, 27 Mar 2026 17:19:30 +0000 Subject: [PATCH 10/10] Rename device folder to amt and update to latest host manager branch changes --- hardware-discovery-agent/go.mod | 2 +- hardware-discovery-agent/go.sum | 2 + .../internal/{device/device.go => amt/amt.go} | 25 ++-- .../device_test.go => amt/amt_test.go} | 129 +++++++++--------- .../internal/comms/comms.go | 66 ++++----- .../internal/comms/comms_test.go | 50 +++---- ...on => mock_amtinfo_missingdevicename.json} | 0 7 files changed, 137 insertions(+), 137 deletions(-) rename hardware-discovery-agent/internal/{device/device.go => amt/amt.go} (66%) rename hardware-discovery-agent/internal/{device/device_test.go => amt/amt_test.go} (72%) rename hardware-discovery-agent/test/data/{mock_amtinfo_missinghostname.json => mock_amtinfo_missingdevicename.json} (100%) diff --git a/hardware-discovery-agent/go.mod b/hardware-discovery-agent/go.mod index 3d636476..2e7bbeca 100644 --- a/hardware-discovery-agent/go.mod +++ b/hardware-discovery-agent/go.mod @@ -7,7 +7,7 @@ require ( github.com/cenkalti/backoff/v4 v4.3.0 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.3 github.com/open-edge-platform/edge-node-agents/common v1.10.1 - github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260318161218-8db11f57899b + github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260327130440-6e311d484d46 github.com/safchain/ethtool v0.7.0 github.com/sirupsen/logrus v1.9.4 github.com/stretchr/testify v1.11.1 diff --git a/hardware-discovery-agent/go.sum b/hardware-discovery-agent/go.sum index cdd961d1..bbbea78a 100644 --- a/hardware-discovery-agent/go.sum +++ b/hardware-discovery-agent/go.sum @@ -48,6 +48,8 @@ github.com/open-edge-platform/infra-managers/host v1.25.4 h1:5Ulfpasc3y8F5TwpSZY github.com/open-edge-platform/infra-managers/host v1.25.4/go.mod h1:1aEoXXhxW9OIBIK71u+SHg9vn60pemsyLZIzAkBZU9o= github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260318161218-8db11f57899b h1:tBqLy/6CuoJBEN+4G8HTITPEeyPwexNSKDQQl9f7pbc= github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260318161218-8db11f57899b/go.mod h1:wh8qa1GjMTMVM78275y4lZR9iJEZZRnoWDldkVk4ygU= +github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260327130440-6e311d484d46 h1:j9eFqADXZerzCcxLy7bLa6n9soqMkt7i4xh8Pja3bdU= +github.com/open-edge-platform/infra-managers/host v1.25.5-0.20260327130440-6e311d484d46/go.mod h1:BjQEDPZRaGLaS/DSAvx9JbUyFuGDUJ91hc9VM1xG06c= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= diff --git a/hardware-discovery-agent/internal/device/device.go b/hardware-discovery-agent/internal/amt/amt.go similarity index 66% rename from hardware-discovery-agent/internal/device/device.go rename to hardware-discovery-agent/internal/amt/amt.go index eedb8f4c..f2f10fdc 100644 --- a/hardware-discovery-agent/internal/device/device.go +++ b/hardware-discovery-agent/internal/amt/amt.go @@ -1,8 +1,7 @@ // SPDX-FileCopyrightText: (C) 2026 Intel Corporation -// // SPDX-License-Identifier: Apache-2.0 -package device +package amt import ( "encoding/json" @@ -19,9 +18,9 @@ type RASInfo struct { MPSHostname string `json:"mpsHostname"` } -type DeviceInfo struct { +type AmtInfo struct { Version string `json:"amt"` - Hostname string `json:"hostnameOS"` + DeviceName string `json:"hostnameOS"` OperationalState string `json:"operationalState"` BuildNumber string `json:"buildNumber"` Sku string `json:"sku"` @@ -32,25 +31,25 @@ type DeviceInfo struct { RAS *RASInfo `json:"ras"` } -func GetDeviceInfo(executor utils.CmdExecutor) (*DeviceInfo, error) { - var deviceInfo DeviceInfo +func GetAmtInfo(executor utils.CmdExecutor) (*AmtInfo, error) { + var amtInfo AmtInfo dataBytes, err := utils.ReadFromCommand(executor, "sudo", "rpc", "amtinfo", "-json") if err != nil { - return &DeviceInfo{}, fmt.Errorf("failed to read data from command; error: %w", err) + return &AmtInfo{}, fmt.Errorf("failed to read data from command; error: %w", err) } - err = json.Unmarshal(dataBytes, &deviceInfo) + err = json.Unmarshal(dataBytes, &amtInfo) if err != nil { - return &DeviceInfo{}, fmt.Errorf("failed to parse data from command; error: %w", err) + return &AmtInfo{}, fmt.Errorf("failed to parse data from command; error: %w", err) } - if deviceInfo.Uuid == "" { + if amtInfo.Uuid == "" { systemId, err := system.GetSystemUUID(executor) if err != nil { - return &DeviceInfo{}, fmt.Errorf("failed to retrieve system uuid; error: %w", err) + return &AmtInfo{}, fmt.Errorf("failed to retrieve system uuid; error: %w", err) } - deviceInfo.Uuid = systemId + amtInfo.Uuid = systemId } - return &deviceInfo, nil + return &amtInfo, nil } diff --git a/hardware-discovery-agent/internal/device/device_test.go b/hardware-discovery-agent/internal/amt/amt_test.go similarity index 72% rename from hardware-discovery-agent/internal/device/device_test.go rename to hardware-discovery-agent/internal/amt/amt_test.go index 3111094e..2c7b9080 100644 --- a/hardware-discovery-agent/internal/device/device_test.go +++ b/hardware-discovery-agent/internal/amt/amt_test.go @@ -1,8 +1,7 @@ // SPDX-FileCopyrightText: (C) 2026 Intel Corporation -// // SPDX-License-Identifier: Apache-2.0 -package device_test +package amt_test import ( "fmt" @@ -14,11 +13,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/device" + "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/amt" ) var testVersion = "16.1.27" -var testHostname = "testhost" +var testDeviceName = "testhost" var testOperationalState = "enabled" var testBuildNumber = "2176" var testSku = "16392" @@ -30,13 +29,13 @@ var testNetworkStatus = "direct" var testRemoteStatus = "not connected" var testRemoteTrigger = "user initiated" -func getExpectedResult(version string, hostname string, opState string, buildNum string, sku string, +func getExpectedResult(version string, deviceName string, opState string, buildNum string, sku string, features string, uuid string, controlMode string, dnsSuffix string, networkStatus string, - remoteStatus string, remoteTrigger string) *device.DeviceInfo { + remoteStatus string, remoteTrigger string) *amt.AmtInfo { if networkStatus == "" && remoteStatus == "" && remoteTrigger == "" { - return &device.DeviceInfo{ + return &amt.AmtInfo{ Version: version, - Hostname: hostname, + DeviceName: deviceName, OperationalState: opState, BuildNumber: buildNum, Sku: sku, @@ -46,9 +45,9 @@ func getExpectedResult(version string, hostname string, opState string, buildNum DNSSuffix: dnsSuffix, } } else { - return &device.DeviceInfo{ + return &amt.AmtInfo{ Version: version, - Hostname: hostname, + DeviceName: deviceName, OperationalState: opState, BuildNumber: buildNum, Sku: sku, @@ -56,7 +55,7 @@ func getExpectedResult(version string, hostname string, opState string, buildNum Uuid: uuid, ControlMode: controlMode, DNSSuffix: dnsSuffix, - RAS: &device.RASInfo{ + RAS: &amt.RASInfo{ NetworkStatus: networkStatus, RemoteStatus: remoteStatus, RemoteTrigger: remoteTrigger, @@ -66,131 +65,131 @@ func getExpectedResult(version string, hostname string, opState string, buildNum } } -func Test_GetDeviceInfo(t *testing.T) { - res, err := device.GetDeviceInfo(testSuccess) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, +func Test_GetAmtInfo(t *testing.T) { + res, err := amt.GetAmtInfo(testSuccess) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoFailed(t *testing.T) { - res, err := device.GetDeviceInfo(testFailure) +func Test_GetAmtInfoFailed(t *testing.T) { + res, err := amt.GetAmtInfo(testFailure) assert.Error(t, err) - assert.Equal(t, &device.DeviceInfo{}, res) + assert.Equal(t, &amt.AmtInfo{}, res) } -func Test_GetDeviceInfoSystemUuidFailed(t *testing.T) { - res, err := device.GetDeviceInfo(testFailureSystemUuid) +func Test_GetAmtInfoSystemUuidFailed(t *testing.T) { + res, err := amt.GetAmtInfo(testFailureSystemUuid) assert.Error(t, err) - assert.Equal(t, &device.DeviceInfo{}, res) + assert.Equal(t, &amt.AmtInfo{}, res) } -func Test_GetDeviceInfoFailedUnmarshal(t *testing.T) { - res, err := device.GetDeviceInfo(testFailureUnmarshal) +func Test_GetAmtInfoFailedUnmarshal(t *testing.T) { + res, err := amt.GetAmtInfo(testFailureUnmarshal) assert.Error(t, err) - assert.Equal(t, &device.DeviceInfo{}, res) + assert.Equal(t, &amt.AmtInfo{}, res) } -func Test_GetDeviceInfoMissingVersionNumber(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingVersionNumber) - expected := getExpectedResult("", testHostname, testOperationalState, testBuildNumber, testSku, testFeatures, +func Test_GetAmtInfoMissingVersionNumber(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingVersionNumber) + expected := getExpectedResult("", testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingHostname(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingHostname) +func Test_GetAmtInfoMissingDeviceName(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingDeviceName) expected := getExpectedResult(testVersion, "", testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingOperationalState(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingOperationalState) - expected := getExpectedResult(testVersion, testHostname, "", testBuildNumber, testSku, testFeatures, testUuid, +func Test_GetAmtInfoMissingOperationalState(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingOperationalState) + expected := getExpectedResult(testVersion, testDeviceName, "", testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingBuildNumber(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingBuildNumber) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, "", testSku, testFeatures, testUuid, +func Test_GetAmtInfoMissingBuildNumber(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingBuildNumber) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, "", testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingSku(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingSku) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, "", testFeatures, +func Test_GetAmtInfoMissingSku(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingSku) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, "", testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingFeatures(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingFeatures) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, "", +func Test_GetAmtInfoMissingFeatures(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingFeatures) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, "", testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingUuid(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingUuid) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, +func Test_GetAmtInfoMissingUuid(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingUuid) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingControlMode(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingControlMode) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, +func Test_GetAmtInfoMissingControlMode(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingControlMode) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, "", testDnsSuffix, testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingDnsSuffix(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingDnsSuffix) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, +func Test_GetAmtInfoMissingDnsSuffix(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingDnsSuffix) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, "", testNetworkStatus, testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingRasInfo(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingRasInfo) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, +func Test_GetAmtInfoMissingRasInfo(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingRasInfo) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, "", "", "") assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingNetworkStatus(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingNetworkStatus) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, +func Test_GetAmtInfoMissingNetworkStatus(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingNetworkStatus) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, "", testRemoteStatus, testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingRemoteStatus(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingRemoteStatus) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, +func Test_GetAmtInfoMissingRemoteStatus(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingRemoteStatus) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, "", testRemoteTrigger) assert.NoError(t, err) assert.Equal(t, expected, res) } -func Test_GetDeviceInfoMissingRemoteTrigger(t *testing.T) { - res, err := device.GetDeviceInfo(testMissingRemoteTrigger) - expected := getExpectedResult(testVersion, testHostname, testOperationalState, testBuildNumber, testSku, +func Test_GetAmtInfoMissingRemoteTrigger(t *testing.T) { + res, err := amt.GetAmtInfo(testMissingRemoteTrigger) + expected := getExpectedResult(testVersion, testDeviceName, testOperationalState, testBuildNumber, testSku, testFeatures, testUuid, testControlMode, testDnsSuffix, testNetworkStatus, testRemoteStatus, "") assert.NoError(t, err) assert.Equal(t, expected, res) @@ -228,8 +227,8 @@ func testMissingVersionNumber(command string, args ...string) *exec.Cmd { return testCmd("TestMissingVersionNumber", command, args...) } -func testMissingHostname(command string, args ...string) *exec.Cmd { - return testCmd("TestMissingHostname", command, args...) +func testMissingDeviceName(command string, args ...string) *exec.Cmd { + return testCmd("TestMissingDeviceName", command, args...) } func testMissingOperationalState(command string, args ...string) *exec.Cmd { @@ -316,11 +315,11 @@ func TestMissingVersionNumber(t *testing.T) { os.Exit(0) } -func TestMissingHostname(t *testing.T) { +func TestMissingDeviceName(t *testing.T) { if os.Getenv("GO_TEST_PROCESS") != "1" { return } - testData, err := os.ReadFile("../../test/data/mock_amtinfo_missinghostname.json") + testData, err := os.ReadFile("../../test/data/mock_amtinfo_missingdevicename.json") require.NoError(t, err) fmt.Fprintf(os.Stdout, "%v", string(testData)) os.Exit(0) diff --git a/hardware-discovery-agent/internal/comms/comms.go b/hardware-discovery-agent/internal/comms/comms.go index a3638e8b..7aa766be 100644 --- a/hardware-discovery-agent/internal/comms/comms.go +++ b/hardware-discovery-agent/internal/comms/comms.go @@ -15,8 +15,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/amt" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/cpu" - "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/device" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/disk" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/gpu" "github.com/open-edge-platform/edge-node-agents/hardware-discovery-agent/internal/logger" @@ -128,7 +128,7 @@ func ConnectToEdgeInfrastructureManager(serverAddr string, tlsConfig *tls.Config func parseSystemInfo(serialNumber string, productName string, bmcAddr string, osInfo *system.Os, biosInfo *system.Bios, cpu *cpu.CPU, storage []*disk.Disk, gpu []*gpu.Gpu, mem uint64, networks []*network.Network, bmType proto.BmInfo_BmType, usbInfo []*usb.Usb, - device *device.DeviceInfo) *proto.SystemInfo { + amt *amt.AmtInfo) *proto.SystemInfo { gpuList := []*proto.SystemGPU{} for _, gpuDetails := range gpu { @@ -277,37 +277,37 @@ func parseSystemInfo(serialNumber string, productName string, bmcAddr string, os } } - deviceInfo := proto.DeviceInfo{} - if device != nil { - if device.RAS != nil { - deviceInfo = proto.DeviceInfo{ - Version: device.Version, - Hostname: device.Hostname, - OperationalState: device.OperationalState, - BuildNumber: device.BuildNumber, - Sku: device.Sku, - Features: device.Features, - DeviceGuid: device.Uuid, - ControlMode: device.ControlMode, - DnsSuffix: device.DNSSuffix, + amtInfo := proto.AmtConfigInfo{} + if amt != nil { + if amt.RAS != nil { + amtInfo = proto.AmtConfigInfo{ + Version: amt.Version, + DeviceName: amt.DeviceName, + OperationalState: amt.OperationalState, + BuildNumber: amt.BuildNumber, + Sku: amt.Sku, + Features: amt.Features, + DeviceGuid: amt.Uuid, + ControlMode: amt.ControlMode, + DnsSuffix: amt.DNSSuffix, RasInfo: &proto.RASInfo{ - NetworkStatus: device.RAS.NetworkStatus, - RemoteStatus: device.RAS.RemoteStatus, - RemoteTrigger: device.RAS.RemoteTrigger, - MpsHostname: device.RAS.MPSHostname, + NetworkStatus: amt.RAS.NetworkStatus, + RemoteStatus: amt.RAS.RemoteStatus, + RemoteTrigger: amt.RAS.RemoteTrigger, + MpsHostname: amt.RAS.MPSHostname, }, } } else { - deviceInfo = proto.DeviceInfo{ - Version: device.Version, - Hostname: device.Hostname, - OperationalState: device.OperationalState, - BuildNumber: device.BuildNumber, - Sku: device.Sku, - Features: device.Features, - DeviceGuid: device.Uuid, - ControlMode: device.ControlMode, - DnsSuffix: device.DNSSuffix, + amtInfo = proto.AmtConfigInfo{ + Version: amt.Version, + DeviceName: amt.DeviceName, + OperationalState: amt.OperationalState, + BuildNumber: amt.BuildNumber, + Sku: amt.Sku, + Features: amt.Features, + DeviceGuid: amt.Uuid, + ControlMode: amt.ControlMode, + DnsSuffix: amt.DNSSuffix, } } } @@ -338,7 +338,7 @@ func parseSystemInfo(serialNumber string, productName string, bmcAddr string, os ReleaseDate: biosInfo.RelDate, Vendor: biosInfo.Vendor, }, - DeviceInfo: &deviceInfo, + AmtInfo: &amtInfo, } return systemInfo @@ -395,10 +395,10 @@ func GenerateSystemInfoRequest(executor utils.CmdExecutor) *proto.SystemInfo { log.Errorf("unable to get usb description : %v", err) } - deviceInfo, err := device.GetDeviceInfo(executor) + amtInfo, err := amt.GetAmtInfo(executor) if err != nil { - log.Errorf("unable to get device description : %v", err) + log.Errorf("unable to get amt description : %v", err) } - return parseSystemInfo(sn, productName, bmcAddr, osInfo, biosInfo, cpu, storage, gpu, mem, networkList, bmType, usbList, deviceInfo) + return parseSystemInfo(sn, productName, bmcAddr, osInfo, biosInfo, cpu, storage, gpu, mem, networkList, bmType, usbList, amtInfo) } diff --git a/hardware-discovery-agent/internal/comms/comms_test.go b/hardware-discovery-agent/internal/comms/comms_test.go index 26223484..994f0112 100644 --- a/hardware-discovery-agent/internal/comms/comms_test.go +++ b/hardware-discovery-agent/internal/comms/comms_test.go @@ -208,7 +208,7 @@ func TestFailedSystemInfoUpdate(t *testing.T) { } func expectedSystemInfoResult(sn string, productName string, bmcAddr string, osInfo *proto.OsInfo, biosInfo *proto.BiosInfo, cpu *proto.SystemCPU, storage []*proto.SystemDisk, - gpu []*proto.SystemGPU, mem uint64, networks []*proto.SystemNetwork, bmType proto.BmInfo_BmType, usbInfo []*proto.SystemUSB, deviceInfo *proto.DeviceInfo) *proto.SystemInfo { + gpu []*proto.SystemGPU, mem uint64, networks []*proto.SystemNetwork, bmType proto.BmInfo_BmType, usbInfo []*proto.SystemUSB, amtInfo *proto.AmtConfigInfo) *proto.SystemInfo { return &proto.SystemInfo{ HwInfo: &proto.HWInfo{ @@ -228,8 +228,8 @@ func expectedSystemInfoResult(sn string, productName string, bmcAddr string, osI BmIp: bmcAddr, }, }, - BiosInfo: biosInfo, - DeviceInfo: deviceInfo, + BiosInfo: biosInfo, + AmtInfo: amtInfo, } } @@ -427,10 +427,10 @@ func getUsbInfo() []*proto.SystemUSB { return usbInfo } -func getDeviceInfo() *proto.DeviceInfo { - return &proto.DeviceInfo{ +func getAmtInfo() *proto.AmtConfigInfo { + return &proto.AmtConfigInfo{ Version: "16.1.27", - Hostname: "testhost", + DeviceName: "testhost", OperationalState: "enabled", BuildNumber: "2176", Sku: "16392", @@ -454,7 +454,7 @@ func TestGenerateUpdateDeviceRequestSuccessAllInfo(t *testing.T) { network.CollectEthtoolData = mockedCollectEthtoolData network.Stat = mockedStat json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassed) - expected := expectedSystemInfoResult("12A34B5", "Test Product", "192.168.1.50", getOsInfo(), getBiosInfo(), getCpuInfo(), getStorageInfo(), getGpuInfo(), 17179869184, getNetworkInfo(), proto.BmInfo_IPMI, getUsbInfo(), getDeviceInfo()) + expected := expectedSystemInfoResult("12A34B5", "Test Product", "192.168.1.50", getOsInfo(), getBiosInfo(), getCpuInfo(), getStorageInfo(), getGpuInfo(), 17179869184, getNetworkInfo(), proto.BmInfo_IPMI, getUsbInfo(), getAmtInfo()) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -471,7 +471,7 @@ func TestGenerateUpdateDeviceRequestErr(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -487,7 +487,7 @@ func TestGenerateUpdateDeviceRequestSuccessStorageOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, getStorageInfo(), gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, getStorageInfo(), gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -504,7 +504,7 @@ func TestGeneraeUpdateDeviceRequestSuccessSerialNumberOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("12A34B5", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("12A34B5", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -521,7 +521,7 @@ func TestGenerateUpdateDeviceRequestSuccessProductNameOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "Test Product", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "Test Product", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -532,7 +532,7 @@ func TestGenerateUpdateDeviceRequestSuccessOsOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", getOsInfo(), &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "", getOsInfo(), &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -549,7 +549,7 @@ func TestGenerateUpdateDeviceRequestSuccessBiosOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, getBiosInfo(), &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "", osInfo, getBiosInfo(), &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -566,7 +566,7 @@ func TestGenerateUpdateDeviceRequestSuccessCpuOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, getCpuInfo(), storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, getCpuInfo(), storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -582,7 +582,7 @@ func TestGenerateUpdateDeviceRequestSuccessGpuOnly(t *testing.T) { storage := []*proto.SystemDisk{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, getGpuInfo(), uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, getGpuInfo(), uint64(0), networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -599,7 +599,7 @@ func TestGenerateUpdateDeviceRequestSuccessMemoryOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, 17179869184, networks, proto.BmInfo_NONE, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, 17179869184, networks, proto.BmInfo_NONE, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -620,7 +620,7 @@ func TestGenerateUpdateDeviceRequestSuccessNetworkOnly(t *testing.T) { storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "192.168.1.50", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), getNetworkInfo(), proto.BmInfo_IPMI, usbInfo, &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "192.168.1.50", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), getNetworkInfo(), proto.BmInfo_IPMI, usbInfo, &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -636,13 +636,13 @@ func TestGenerateUpdateDeviceRequestSuccessUsbInfoOnly(t *testing.T) { storage := []*proto.SystemDisk{} gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, getUsbInfo(), &proto.DeviceInfo{}) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, getUsbInfo(), &proto.AmtConfigInfo{}) require.NotNil(t, json) assert.Equal(t, expected, json) } -func TestGenerateUpdateDeviceRequestSuccessDeviceInfoOnly(t *testing.T) { - json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassedDeviceOnly) +func TestGenerateUpdateDeviceRequestSuccessAmtInfoOnly(t *testing.T) { + json := comms.GenerateSystemInfoRequest(testCmdExecutorCommandPassedAmtOnly) osKern := proto.OsKernel{} osRelease := proto.OsRelease{} osInfo := &proto.OsInfo{ @@ -653,7 +653,7 @@ func TestGenerateUpdateDeviceRequestSuccessDeviceInfoOnly(t *testing.T) { gpu := []*proto.SystemGPU{} networks := []*proto.SystemNetwork{} usbInfo := []*proto.SystemUSB{} - expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, getDeviceInfo()) + expected := expectedSystemInfoResult("", "", "", osInfo, &proto.BiosInfo{}, &proto.SystemCPU{}, storage, gpu, uint64(0), networks, proto.BmInfo_NONE, usbInfo, getAmtInfo()) require.NotNil(t, json) assert.Equal(t, expected, json) } @@ -709,7 +709,7 @@ func testCmdExecutorCommandPassed(command string, args ...string) *exec.Cmd { } else if strings.Contains(args[0], "ipmitool") { return testCmd("TestGenerateUpdateDeviceRequestCommandIpmiDetails", command, args...) } else if strings.Contains(args[0], "rpc") { - return testCmd("TestGenerateUpdateDeviceRequestCommandDeviceDetails", command, args...) + return testCmd("TestGenerateUpdateDeviceRequestCommandAmtDetails", command, args...) } else { if strings.Contains(args[2], "bios-version") { return testCmd("TestGenerateUpdateDeviceRequestCommandBiosVersion", command, args...) @@ -850,10 +850,10 @@ func testCmdExecutorCommandPassedUsbOnly(command string, args ...string) *exec.C } } -func testCmdExecutorCommandPassedDeviceOnly(command string, args ...string) *exec.Cmd { +func testCmdExecutorCommandPassedAmtOnly(command string, args ...string) *exec.Cmd { if strings.Contains(command, "sudo") { if strings.Contains(args[0], "rpc") { - return testCmd("TestGenerateUpdateDeviceRequestCommandDeviceDetails", command, args...) + return testCmd("TestGenerateUpdateDeviceRequestCommandAmtDetails", command, args...) } else { return testCmd("TestGenerateUpdateDeviceRequestCommandFailed", command, args...) } @@ -890,7 +890,7 @@ func TestGenerateUpdateDeviceRequestCommandCoreDetails(t *testing.T) { os.Exit(0) } -func TestGenerateUpdateDeviceRequestCommandDeviceDetails(t *testing.T) { +func TestGenerateUpdateDeviceRequestCommandAmtDetails(t *testing.T) { if os.Getenv("GO_TEST_PROCESS") != "1" { return } diff --git a/hardware-discovery-agent/test/data/mock_amtinfo_missinghostname.json b/hardware-discovery-agent/test/data/mock_amtinfo_missingdevicename.json similarity index 100% rename from hardware-discovery-agent/test/data/mock_amtinfo_missinghostname.json rename to hardware-discovery-agent/test/data/mock_amtinfo_missingdevicename.json