Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions gnmi_server/platform_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package gnmi

import (
"crypto/tls"
"encoding/json"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -870,3 +871,169 @@ func TestGetShowPlatformSsdhealth(t *testing.T) {
})
}
}

func TestGetShowPlatformSyseeprom(t *testing.T) {
tests := []struct {
desc string
pathTarget string
textPbPath string
wantRetCode codes.Code
wantRespVal interface{}
valTest bool
testInit func() *gomonkey.Patches
}{
{
desc: "query SHOW platform syseeprom - full EEPROM data",
pathTarget: "SHOW",
textPbPath: `
elem: <name: "platform" >
elem: <name: "syseeprom" >
`,
wantRetCode: codes.OK,
wantRespVal: func() []byte {
expected := helpers.SysEepromInfo{
TlvInfoHeader: helpers.SysEepromHeader{
IdString: "TlvInfo",
Version: "1",
TotalLength: "169",
},
TlvList: []helpers.SysEepromTlv{
{Name: "Product Name", Code: "0x21", Length: "12", Value: "DCS-7060CX-32"},
{Name: "Part Number", Code: "0x22", Length: "14", Value: "FP-T3048-C32-R"},
{Name: "Serial Number", Code: "0x23", Length: "11", Value: "JPE20381234"},
{Name: "Base MAC Address", Code: "0x24", Length: "6", Value: "00:1C:73:01:23:45"},
{Name: "Manufacture Date", Code: "0x25", Length: "19", Value: "01/01/2024 00:00:00"},
{Name: "Device Version", Code: "0x26", Length: "1", Value: "2"},
{Name: "Label Revision", Code: "0x27", Length: "3", Value: "R01"},
{Name: "Platform Name", Code: "0x28", Length: "30", Value: "x86_64-mlnx_msn3700-r0"},
{Name: "ONIE Version", Code: "0x29", Length: "12", Value: "2024.02.01.0"},
{Name: "MAC Addresses", Code: "0x2A", Length: "2", Value: "256"},
{Name: "Manufacturer", Code: "0x2B", Length: "8", Value: "Mellanox"},
{Name: "Vendor Extension", Code: "0xFD", Length: "36", Value: "0x00 0x00 0x81 0x19 0x02 0x40 0x44 0x65"},
{Name: "Vendor Extension", Code: "0xFD", Length: "36", Value: "0x00 0x00 0x81 0x19 0x02 0x40 0x44 0x66"},
{Name: "CRC-32", Code: "0xFE", Length: "4", Value: "0xABCDEF01"},
},
ChecksumValid: true,
}
jsonData, _ := json.Marshal(expected)
return jsonData
}(),
valTest: true,
testInit: func() *gomonkey.Patches {
ResetDataSetsAndMappings(t)
AddDataSet(t, StateDbNum, "../testdata/SYSEEPROM.txt")
return gomonkey.ApplyFunc(sccommon.GetPlatform, func() string {
return "x86_64-mlnx_msn3700-r0"
})
},
},
{
desc: "query SHOW platform syseeprom - not initialized",
pathTarget: "SHOW",
textPbPath: `
elem: <name: "platform" >
elem: <name: "syseeprom" >
`,
wantRetCode: codes.NotFound,
valTest: false,
testInit: func() *gomonkey.Patches {
ResetDataSetsAndMappings(t)
AddDataSet(t, StateDbNum, "../testdata/SYSEEPROM_NOT_INITIALIZED.txt")
return gomonkey.ApplyFunc(sccommon.GetPlatform, func() string {
return "x86_64-mlnx_msn3700-r0"
})
},
},
{
desc: "query SHOW platform syseeprom - no data",
pathTarget: "SHOW",
textPbPath: `
elem: <name: "platform" >
elem: <name: "syseeprom" >
`,
wantRetCode: codes.NotFound,
valTest: false,
testInit: func() *gomonkey.Patches {
ResetDataSetsAndMappings(t)
return gomonkey.ApplyFunc(sccommon.GetPlatform, func() string {
return "x86_64-mlnx_msn3700-r0"
})
},
},
{
desc: "query SHOW platform syseeprom - KVM platform not supported",
pathTarget: "SHOW",
textPbPath: `
elem: <name: "platform" >
elem: <name: "syseeprom" >
`,
wantRetCode: codes.NotFound,
valTest: false,
testInit: func() *gomonkey.Patches {
ResetDataSetsAndMappings(t)
return gomonkey.ApplyFunc(sccommon.GetPlatform, func() string {
return "x86_64-kvm_x86_64-r0"
})
},
},
{
desc: "query SHOW platform syseeprom - Arista platform uses nsenter fallback",
pathTarget: "SHOW",
textPbPath: `
elem: <name: "platform" >
elem: <name: "syseeprom" >
`,
wantRetCode: codes.OK,
wantRespVal: func() []byte {
result := map[string]string{"eeprom_raw": "SKU: DCS-7060X6-64PE-B\nSerialNumber: HBG251204WB\nMAC: d8:06:f3:5a:a9:b1\nHwRev: 11.00"}
jsonData, _ := json.Marshal(result)
return jsonData
}(),
valTest: true,
testInit: func() *gomonkey.Patches {
ResetDataSetsAndMappings(t)
patches := gomonkey.ApplyFunc(sccommon.GetPlatform, func() string {
return "x86_64-arista_7050-r0"
})
eepromText := "SKU: DCS-7060X6-64PE-B\nSerialNumber: HBG251204WB\nMAC: d8:06:f3:5a:a9:b1\nHwRev: 11.00"
patches.ApplyFunc(sccommon.GetDataFromHostCommand, func(command string) (string, error) {
return eepromText, nil
})
return patches
},
},
}

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
var patches *gomonkey.Patches
if tt.testInit != nil {
patches = tt.testInit()
}
defer func() {
if patches != nil {
patches.Reset()
}
}()

s := createServer(t, ServerPort)
go runServer(t, s)
defer s.ForceStop()

tlsConfig := &tls.Config{InsecureSkipVerify: true}
opts := []grpc.DialOption{grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))}

conn, err := grpc.Dial(TargetAddr, opts...)
if err != nil {
t.Fatalf("Dialing to %q failed: %v", TargetAddr, err)
}
defer conn.Close()

gClient := pb.NewGNMIClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), QueryTimeout*time.Second)
defer cancel()

runTestGet(t, ctx, gClient, tt.pathTarget, tt.textPbPath, tt.wantRetCode, tt.wantRespVal, tt.valTest)
})
}
}
15 changes: 15 additions & 0 deletions show_client/common/platform_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ except ImportError as e:
s = SsdUtil('%s')
print(json.dumps({'model': str(s.get_model()), 'firmware': str(s.get_firmware()), 'serial': str(s.get_serial()), 'health': str(s.get_health()), 'temperature': str(s.get_temperature()), 'vendor_output': str(s.get_vendor_output())}))
`

// SysEepromPyScript is the Python script that invokes the sonic_platform API
// to retrieve system EEPROM info.
var SysEepromPyScript = `
import sys
try:
import sonic_platform
eeprom = sonic_platform.platform.Platform().get_chassis().get_eeprom()
except Exception:
eeprom = None
if not eeprom:
sys.exit(1)
sys_eeprom_data = eeprom.read_eeprom()
eeprom.decode_eeprom(sys_eeprom_data)
`
Loading
Loading