diff options
-rw-r--r-- | hdv/redfish/test/mock_server.json | 732 | ||||
-rw-r--r-- | hdv/redfish/test/sample_test_cases.yml | 9 | ||||
-rw-r--r-- | hdv/redfish/test/test_hdv_redfish.py | 102 |
3 files changed, 821 insertions, 22 deletions
diff --git a/hdv/redfish/test/mock_server.json b/hdv/redfish/test/mock_server.json index acf7e9a..f36633a 100644 --- a/hdv/redfish/test/mock_server.json +++ b/hdv/redfish/test/mock_server.json @@ -46,5 +46,735 @@ "Members@odata.count": 3, "Name": "Processors Collection" } - } + }, + "/redfish/v1/Chassis/{chassis_id}": [ + { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Chassis/1U", + "@odata.type": "#Chassis.v1_11_0.Chassis", + "AssetTag": "Chicago-45Z-2381", + "ChassisType": "RackMount", + "DepthMm": 711, + "HeightMm": 44.45, + "Id": "1U", + "IndicatorLED": "Lit", + "Links": { + "ComputerSystems": [ + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2" + } + ], + "ManagedBy": [ + { + "@odata.id": "/redfish/v1/Managers/BMC" + } + ], + "ManagersInChassis": [ + { + "@odata.id": "/redfish/v1/Managers/BMC" + } + ] + }, + "Location": { + "Placement": { + "Rack": "WEB43", + "RackOffset": 12, + "RackOffsetUnits": "EIA_310", + "Row": "North" + }, + "PostalAddress": { + "City": "Portland", + "Country": "US", + "HouseNumber": 1100, + "Name": "DMTF", + "PostalCode": "97204", + "Street": "1001 SW 5th Avenue", + "Territory": "OR" + } + }, + "Manufacturer": "Contoso", + "Oem": { + "Mainboard":{ + "BoardName": "RS33M2C9S" + } + }, + "Model": "3500RX", + "Name": "Computer System Chassis", + "PartNumber": "224071-J23", + "Power": { + "@odata.id": "/redfish/v1/Chassis/1U/Power" + }, + "PowerState": "On", + "SKU": "8675309", + "SerialNumber": "437XR1138R2", + "Status": { + "Health": "OK", + "State": "Enabled" + }, + "Thermal": { + "@odata.id": "/redfish/v1/Chassis/1U/Thermal" + }, + "WeightKg": 15.31, + "WidthMm": 431.8 + } + } + ], + "/redfish/v1/Chassis/1U": { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Chassis/1U", + "@odata.type": "#Chassis.v1_11_0.Chassis", + "AssetTag": "Chicago-45Z-2381", + "ChassisType": "RackMount", + "DepthMm": 711, + "HeightMm": 44.45, + "Id": "1U", + "IndicatorLED": "Lit", + "Links": { + "ComputerSystems": [ + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2" + } + ], + "ManagedBy": [ + { + "@odata.id": "/redfish/v1/Managers/BMC" + } + ], + "ManagersInChassis": [ + { + "@odata.id": "/redfish/v1/Managers/BMC" + } + ] + }, + "Location": { + "Placement": { + "Rack": "WEB43", + "RackOffset": 12, + "RackOffsetUnits": "EIA_310", + "Row": "North" + }, + "PostalAddress": { + "City": "Portland", + "Country": "US", + "HouseNumber": 1100, + "Name": "DMTF", + "PostalCode": "97204", + "Street": "1001 SW 5th Avenue", + "Territory": "OR" + } + }, + "Manufacturer": "Contoso", + "Oem": { + "Mainboard":{ + "BoardName": "RS33M2C9S" + } + }, + "Model": "3500RX", + "Name": "Computer System Chassis", + "PartNumber": "224071-J23", + "Power": { + "@odata.id": "/redfish/v1/Chassis/1U/Power" + }, + "PowerState": "On", + "SKU": "8675309", + "SerialNumber": "437XR1138R2", + "Status": { + "Health": "OK", + "State": "Enabled" + }, + "Thermal": { + "@odata.id": "/redfish/v1/Chassis/1U/Thermal" + }, + "WeightKg": 15.31, + "WidthMm": 431.8 + } + }, + "/redfish/v1/Systems/437XR1138R2": { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2", + "@odata.type": "#ComputerSystem.v1_10_0.ComputerSystem", + "Actions": { + "#ComputerSystem.Reset": { + "ResetType@Redfish.AllowableValues": [ + "On", + "ForceOff", + "GracefulShutdown", + "GracefulRestart", + "ForceRestart", + "Nmi", + "ForceOn", + "PushPowerButton" + ], + "target": "/redfish/v1/Systems/437XR1138R2/Actions/ComputerSystem.Reset" + }, + "Oem": { + "#Contoso.Reset": { + "target": "/redfish/v1/Systems/437XR1138R2/Oem/Contoso/Actions/Contoso.Reset" + } + } + }, + "AssetTag": "CM_cc@1234", + "Bios": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Bios" + }, + "BiosVersion": "P79 v1.45 (12/06/2017)", + "Boot": { + "BootSourceOverrideEnabled": "Once", + "BootSourceOverrideMode": "UEFI", + "BootSourceOverrideTarget": "Pxe", + "BootSourceOverrideTarget@Redfish.AllowableValues": [ + "None", + "Pxe", + "Cd", + "Usb", + "Hdd", + "BiosSetup", + "Utilities", + "Diags", + "SDCard", + "UefiTarget" + ], + "UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01" + }, + "Description": "Web Front End node", + "EthernetInterfaces": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/EthernetInterfaces" + }, + "HostName": "web483", + "HostingRoles": [ + "ApplicationServer" + ], + "Id": "437XR1138R2", + "IndicatorLED": "Off", + "Links": { + "Chassis": [ + { + "@odata.id": "/redfish/v1/Chassis/1U" + } + ], + "ManagedBy": [ + { + "@odata.id": "/redfish/v1/Managers/BMC" + } + ] + }, + "LogServices": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/LogServices" + }, + "Manufacturer": "Contoso", + "Memory": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Memory" + }, + "MemorySummary": { + "MemoryMirroring": "None", + "Status": { + "Health": "OK", + "HealthRollup": "OK", + "State": "Enabled" + }, + "TotalSystemMemoryGiB": 96, + "TotalSystemPersistentMemoryGiB": 0 + }, + "Model": "3500", + "Name": "WebFrontEnd483", + "Oem": { + "Chipwise": { + "@odata.type": "#Chipwise.ComputerSystem", + "Style": "Executive" + }, + "Contoso": { + "@odata.type": "#Contoso.ComputerSystem", + "ProductionLocation": { + "Country": "USA", + "FacilityName": "PacWest Production Facility" + } + } + }, + "PartNumber": "224071-J23", + "PowerState": "On", + "ProcessorSummary": { + "Count": 2, + "Model": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series", + "Status": { + "Health": "OK", + "HealthRollup": "OK", + "State": "Enabled" + } + }, + "Processors": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors" + }, + "SKU": "8675309", + "SerialNumber": "437XR1138R2", + "SimpleStorage": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/SimpleStorage" + }, + "Status": { + "Health": "OK", + "HealthRollup": "OK", + "State": "Enabled" + }, + "SubModel": "RX", + "SystemType": "Physical", + "TrustedModules": [ + { + "FirmwareVersion": "1.13b", + "InterfaceType": "TPM1_2", + "Status": { + "Health": "OK", + "State": "Enabled" + } + } + ], + "UUID": "38947555-7742-3448-3784-823347823834" + } + }, + "/redfish/v1/Systems/{system_id}": [ + { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2", + "@odata.type": "#ComputerSystem.v1_10_0.ComputerSystem", + "Actions": { + "#ComputerSystem.Reset": { + "ResetType@Redfish.AllowableValues": [ + "On", + "ForceOff", + "GracefulShutdown", + "GracefulRestart", + "ForceRestart", + "Nmi", + "ForceOn", + "PushPowerButton" + ], + "target": "/redfish/v1/Systems/437XR1138R2/Actions/ComputerSystem.Reset" + }, + "Oem": { + "#Contoso.Reset": { + "target": "/redfish/v1/Systems/437XR1138R2/Oem/Contoso/Actions/Contoso.Reset" + } + } + }, + "AssetTag": "CM_cc@1234", + "Bios": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Bios" + }, + "BiosVersion": "P79 v1.45 (12/06/2017)", + "Boot": { + "BootSourceOverrideEnabled": "Once", + "BootSourceOverrideMode": "UEFI", + "BootSourceOverrideTarget": "Pxe", + "BootSourceOverrideTarget@Redfish.AllowableValues": [ + "None", + "Pxe", + "Cd", + "Usb", + "Hdd", + "BiosSetup", + "Utilities", + "Diags", + "SDCard", + "UefiTarget" + ], + "UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01" + }, + "Description": "Web Front End node", + "EthernetInterfaces": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/EthernetInterfaces" + }, + "HostName": "web483", + "HostingRoles": [ + "ApplicationServer" + ], + "Id": "437XR1138R2", + "IndicatorLED": "Off", + "Links": { + "Chassis": [ + { + "@odata.id": "/redfish/v1/Chassis/1U" + } + ], + "ManagedBy": [ + { + "@odata.id": "/redfish/v1/Managers/BMC" + } + ] + }, + "LogServices": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/LogServices" + }, + "Manufacturer": "Contoso", + "Memory": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Memory" + }, + "MemorySummary": { + "MemoryMirroring": "None", + "Status": { + "Health": "OK", + "HealthRollup": "OK", + "State": "Enabled" + }, + "TotalSystemMemoryGiB": 96, + "TotalSystemPersistentMemoryGiB": 0 + }, + "Model": "3500", + "Name": "WebFrontEnd483", + "Oem": { + "Chipwise": { + "@odata.type": "#Chipwise.ComputerSystem", + "Style": "Executive" + }, + "Contoso": { + "@odata.type": "#Contoso.ComputerSystem", + "ProductionLocation": { + "Country": "USA", + "FacilityName": "PacWest Production Facility" + } + } + }, + "PartNumber": "224071-J23", + "PowerState": "On", + "ProcessorSummary": { + "Count": 2, + "Model": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series", + "Status": { + "Health": "OK", + "HealthRollup": "OK", + "State": "Enabled" + } + }, + "Processors": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors" + }, + "SKU": "8675309", + "SerialNumber": "437XR1138R2", + "SimpleStorage": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/SimpleStorage" + }, + "Status": { + "Health": "OK", + "HealthRollup": "OK", + "State": "Enabled" + }, + "SubModel": "RX", + "SystemType": "Physical", + "TrustedModules": [ + { + "FirmwareVersion": "1.13b", + "InterfaceType": "TPM1_2", + "Status": { + "Health": "OK", + "State": "Enabled" + } + } + ], + "UUID": "38947555-7742-3448-3784-823347823834" + } + } + ], + "/redfish/v1/Systems/437XR1138R2/Processors": { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors", + "@odata.type": "#ProcessorCollection.ProcessorCollection", + "Members": [ + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU1" + }, + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU2" + }, + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1" + } + ], + "Members@odata.count": 3, + "Name": "Processors Collection" + } + }, + "/redfish/v1/Systems/{system_id}/Processors": [ + { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors", + "@odata.type": "#ProcessorCollection.ProcessorCollection", + "Members": [ + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU1" + }, + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU2" + }, + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1" + } + ], + "Members@odata.count": 3, + "Name": "Processors Collection" + } + } + ], + "/redfish/v1/Systems/437XR1138R2/Processors/CPU1": { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU1", + "@odata.type": "#Processor.v1_7_0.Processor", + "Id": "CPU1", + "InstructionSet": "x86-64", + "Manufacturer": "Intel(R) Corporation", + "MaxSpeedMHz": 3700, + "Model": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series", + "Name": "Processor", + "ProcessorArchitecture": "x86", + "ProcessorId": { + "EffectiveFamily": "0x42", + "EffectiveModel": "0x61", + "IdentificationRegisters": "0x34AC34DC8901274A", + "MicrocodeInfo": "0x429943", + "Step": "0x1", + "VendorId": "GenuineIntel" + }, + "ProcessorType": "CPU", + "Socket": "CPU 1", + "Status": { + "Health": "OK", + "State": "Enabled" + }, + "TotalCores": 8, + "TotalThreads": 16 + } + }, + "/redfish/v1/Systems/437XR1138R2/Processors/CPU2": { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU2", + "@odata.type": "#Processor.v1_7_0.Processor", + "Id": "CPU2", + "Name": "Processor", + "ProcessorType": "CPU", + "Socket": "CPU 2", + "Status": { + "State": "Absent" + } + } + }, + "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1": { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1", + "@odata.type": "#Processor.v1_7_0.Processor", + "AccelerationFunctions": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1/AccelerationFunctions" + }, + "Actions": { + "#Processor.Reset": { + "target": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1/Actions/Processor.Reset" + } + }, + "FPGA": { + "ExternalInterfaces": [ + { + "Ethernet": { + "MaxLanes": 4, + "MaxSpeedMbps": 10240 + }, + "InterfaceType": "Ethernet" + } + ], + "FirmwareId": "0x6400002fc614bb9", + "FirmwareManufacturer": "Intel(R) Corporation", + "FirmwareVersion": "Blue v.1.00.86", + "FpgaType": "Discrete", + "HostInterface": { + "InterfaceType": "PCIe", + "PCIe": { + "MaxLanes": 8, + "MaxPCIeType": "Gen4" + } + }, + "Model": "Stratix10", + "Oem": {}, + "PCIeVirtualFunctions": 1, + "ProgrammableFromHost": true, + "ReconfigurationSlots": [ + { + "AccelerationFunction": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1/AccelerationFunctions/Compression" + }, + "ProgrammableFromHost": true, + "SlotId": "AFU0", + "UUID": "00000000-0000-0000-0000-000000000000" + } + ] + }, + "Id": "FPGA1", + "InstructionSet": "OEM", + "Links": { + "ConnectedProcessors": [ + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU1" + } + ], + "Endpoints": [] + }, + "Manufacturer": "Intel(R) Corporation", + "MaxTDPWatts": 150, + "Metrics": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1/ProcessorMetrics" + }, + "Model": "Stratix 10", + "Name": "FPGA", + "Oem": {}, + "ProcessorArchitecture": "OEM", + "ProcessorMemory": [ + { + "CapacityMiB": 512, + "IntegratedMemory": true, + "MemoryType": "HBM2", + "SpeedMHz": 1066 + } + ], + "ProcessorType": "FPGA", + "Status": { + "Health": "OK", + "State": "Enabled" + }, + "TDPWatts": 120, + "UUID": "00000000-0000-0000-0000-000000000000" + } + }, + "/redfish/v1/Systems/{system_id}/Processors/{cpu_id}": [ + { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU1", + "@odata.type": "#Processor.v1_7_0.Processor", + "Id": "CPU1", + "InstructionSet": "x86-64", + "Manufacturer": "Intel(R) Corporation", + "MaxSpeedMHz": 3700, + "Model": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series", + "Name": "Processor", + "ProcessorArchitecture": "x86", + "ProcessorId": { + "EffectiveFamily": "0x42", + "EffectiveModel": "0x61", + "IdentificationRegisters": "0x34AC34DC8901274A", + "MicrocodeInfo": "0x429943", + "Step": "0x1", + "VendorId": "GenuineIntel" + }, + "ProcessorType": "CPU", + "Socket": "CPU 1", + "Status": { + "Health": "OK", + "State": "Enabled" + }, + "TotalCores": 8, + "TotalThreads": 16 + } + }, + { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU2", + "@odata.type": "#Processor.v1_7_0.Processor", + "Id": "CPU2", + "Name": "Processor", + "ProcessorType": "CPU", + "Socket": "CPU 2", + "Status": { + "State": "Absent" + } + } + }, + { + "return_code": 200, + "return_value": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1", + "@odata.type": "#Processor.v1_7_0.Processor", + "AccelerationFunctions": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1/AccelerationFunctions" + }, + "Actions": { + "#Processor.Reset": { + "target": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1/Actions/Processor.Reset" + } + }, + "FPGA": { + "ExternalInterfaces": [ + { + "Ethernet": { + "MaxLanes": 4, + "MaxSpeedMbps": 10240 + }, + "InterfaceType": "Ethernet" + } + ], + "FirmwareId": "0x6400002fc614bb9", + "FirmwareManufacturer": "Intel(R) Corporation", + "FirmwareVersion": "Blue v.1.00.86", + "FpgaType": "Discrete", + "HostInterface": { + "InterfaceType": "PCIe", + "PCIe": { + "MaxLanes": 8, + "MaxPCIeType": "Gen4" + } + }, + "Model": "Stratix10", + "Oem": {}, + "PCIeVirtualFunctions": 1, + "ProgrammableFromHost": true, + "ReconfigurationSlots": [ + { + "AccelerationFunction": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1/AccelerationFunctions/Compression" + }, + "ProgrammableFromHost": true, + "SlotId": "AFU0", + "UUID": "00000000-0000-0000-0000-000000000000" + } + ] + }, + "Id": "FPGA1", + "InstructionSet": "OEM", + "Links": { + "ConnectedProcessors": [ + { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/CPU1" + } + ], + "Endpoints": [] + }, + "Manufacturer": "Intel(R) Corporation", + "MaxTDPWatts": 150, + "Metrics": { + "@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1/ProcessorMetrics" + }, + "Model": "Stratix 10", + "Name": "FPGA", + "Oem": {}, + "ProcessorArchitecture": "OEM", + "ProcessorMemory": [ + { + "CapacityMiB": 512, + "IntegratedMemory": true, + "MemoryType": "HBM2", + "SpeedMHz": 1066 + } + ], + "ProcessorType": "FPGA", + "Status": { + "Health": "OK", + "State": "Enabled" + }, + "TDPWatts": 120, + "UUID": "00000000-0000-0000-0000-000000000000" + } + } + ] }
\ No newline at end of file diff --git a/hdv/redfish/test/sample_test_cases.yml b/hdv/redfish/test/sample_test_cases.yml index 8a732b2..9b47ad0 100644 --- a/hdv/redfish/test/sample_test_cases.yml +++ b/hdv/redfish/test/sample_test_cases.yml @@ -34,7 +34,7 @@ enabled: true expected_code: 200 expected_result: - Members@odata.count: 2 + Members@odata.count: 3 group: compoment management header: null method: GET @@ -51,14 +51,7 @@ count: 2 Manufacturer: "Intel(R) Corporation" MaxSpeedMHz: 2300 - Model: "Intel(R) Xeon(R) Gold 5218N CPU @ 2.30GHz" ProcessorArchitecture: ["x86", "IA-64", "ARM", "MIPS", "OEM"] - Socket: [1, 2] - Status: - Health: OK - State: Enabled - TotalCores: 16 - TotalThreads: 32 group: compoment management header: null method: GET diff --git a/hdv/redfish/test/test_hdv_redfish.py b/hdv/redfish/test/test_hdv_redfish.py index e230b69..078f2b7 100644 --- a/hdv/redfish/test/test_hdv_redfish.py +++ b/hdv/redfish/test/test_hdv_redfish.py @@ -3,19 +3,20 @@ import yaml import pytest import hdv.redfish.log_utils from hdv.redfish.http_handler import UrllibHttpHandler -from hdv.redfish.hdv_redfish import create_real_url +from hdv.redfish.hdv_redfish import create_real_url, execute_final_url, parse_test_result, parse_data sample_case = {} - -with open('test/sample_test_cases.yml', 'r') as sample_test_file: +mock_server = {} +with open("test/sample_test_cases.yml", "r") as sample_test_file: sample_case = yaml.load(sample_test_file.read(), Loader=yaml.FullLoader) +with open("test/mock_server.json", "r") as mock_server_file: + mock_server = json.load(mock_server_file) + + @pytest.fixture(autouse=True) def mock_response(monkeypatch): - with open('test/mock_server.json', 'r') as mock_server_file: - mock_server = json.load(mock_server_file) - def mock_get(*args, **kwargs): return mock_server[args[0]] @@ -26,16 +27,91 @@ def mock_response(monkeypatch): (sample_case[0], ["/redfish/v1/Systems/437XR1138R2"]), (sample_case[1], ["/redfish/v1/Chassis/1U"]), (sample_case[2], ["/redfish/v1/Systems/437XR1138R2/Processors"]), - (sample_case[3], ['/redfish/v1/Systems/437XR1138R2/Processors/CPU1', - '/redfish/v1/Systems/437XR1138R2/Processors/CPU2', - '/redfish/v1/Systems/437XR1138R2/Processors/FPGA1']) + (sample_case[3], ["/redfish/v1/Systems/437XR1138R2/Processors/CPU1", + "/redfish/v1/Systems/437XR1138R2/Processors/CPU2", + "/redfish/v1/Systems/437XR1138R2/Processors/FPGA1"]) ]) def test_create_real_url(sampleCase, expected_list): - - url, key_flag_dict = sampleCase['url'], sampleCase['key_flag_dict'] + url, key_flag_dict = sampleCase["url"], sampleCase["key_flag_dict"] bmc_ip = "" depends_id = {} http_handler = UrllibHttpHandler() url_list = create_real_url(url, depends_id, None, key_flag_dict, http_handler, bmc_ip) - #checking if url_list and expected_list have same elements, regarless of order - assert expected_list == url_list
\ No newline at end of file + + assert expected_list == url_list + + +@pytest.mark.parametrize("sampleCase", sample_case) +def test_execute_final_url(sampleCase): + method, url, req_body, key_flag_dict \ + = sampleCase["method"], sampleCase["url"], sampleCase["request_body"], sampleCase["key_flag_dict"] + bmc_ip = "" + depends_id = {} + http_handler = UrllibHttpHandler() + config_file = {} + rsp_list = execute_final_url(config_file, depends_id, + http_handler, method, url, req_body, key_flag_dict, bmc_ip) + assert mock_server[url] == rsp_list + + +@pytest.mark.parametrize("sampleCase, expected_return_value_list", [ + (sample_case[0], [{'return_code': 'Success', 'AssetTag': 'Success'}]), + (sample_case[1], [{'return_code': 'Success', "Oem": {"Mainboard":{"BoardName": "Success"}}}]), + (sample_case[2], [{'return_code': 'Success', "Members@odata.count": "Success" }]), + (sample_case[3], [{'return_code': 'Success', 'Manufacturer': 'Success', "MaxSpeedMHz": "Failure, expect value: 2300, return value: 3700", "ProcessorArchitecture": "Success"}, + {'return_code': 'Success', 'Manufacturer': "Failure, expect value: Intel(R) Corporation, return value: Can't find key Manufacturer in return value", "MaxSpeedMHz": "Failure, expect value: 2300, return value: Can't find key MaxSpeedMHz in return value", "ProcessorArchitecture": "Failure, expect value: ['x86', 'IA-64', 'ARM', 'MIPS', 'OEM'], return value: Can't find key ProcessorArchitecture in return value"}, + {'return_code': 'Success', 'Manufacturer': 'Success', "MaxSpeedMHz": "Failure, expect value: 2300, return value: Can't find key MaxSpeedMHz in return value", "ProcessorArchitecture": "Success"}]) +]) +def test_parse_result(sampleCase, expected_return_value_list): + final_rst={} + method, url, req_body, expected_code, expected_value, tc_name, key_flag_dict \ + = sampleCase["method"], sampleCase["url"], sampleCase["request_body"], \ + sampleCase["expected_code"], sampleCase["expected_result"], sampleCase["case_name"], sampleCase["key_flag_dict"] + bmc_ip = "" + depends_id = {} + http_handler = UrllibHttpHandler() + config_file = {} + rsp_list = execute_final_url(config_file, depends_id, + http_handler, method, url, req_body, key_flag_dict, bmc_ip) + + return_value_list, return_code_list, final_rst, flag = \ + parse_test_result(expected_value, expected_code, rsp_list, final_rst) + + assert return_code_list == [200] * len(return_code_list) + + assert return_value_list == expected_return_value_list + + +@pytest.mark.parametrize("sampleCase, expected_act_pairs_list", [ + (sample_case[0], [{'AssetTag': ("CM_cc@1234", "CM_cc@1234")}]), + (sample_case[1], [{'Oem': {'Mainboard': {'BoardName': ('RS33M2C9S', 'RS33M2C9S')}}}]), + (sample_case[2], [{'Members@odata.count': (3, 3)}]), + (sample_case[3], [{'Manufacturer': ('Intel(R) Corporation', 'Intel(R) Corporation'), 'MaxSpeedMHz': (2300, 3700), 'ProcessorArchitecture': (['x86', 'IA-64', 'ARM', 'MIPS', 'OEM'], 'x86')}, + {'Manufacturer': ('Intel(R) Corporation', "Can't find key Manufacturer in return value"), 'MaxSpeedMHz': (2300, "Can't find key MaxSpeedMHz in return value"), 'ProcessorArchitecture': (['x86', 'IA-64', 'ARM', 'MIPS', 'OEM'], "Can't find key ProcessorArchitecture in return value")}, + {'Manufacturer': ('Intel(R) Corporation', 'Intel(R) Corporation'), 'MaxSpeedMHz': (2300, "Can't find key MaxSpeedMHz in return value"), 'ProcessorArchitecture': (['x86', 'IA-64', 'ARM', 'MIPS', 'OEM'], 'OEM')}]) +]) +def test_parse_data(sampleCase, expected_act_pairs_list): + method, url, req_body, expected_code, expected_value, tc_name, key_flag_dict \ + = sampleCase["method"], sampleCase["url"], sampleCase["request_body"], \ + sampleCase["expected_code"], sampleCase["expected_result"], sampleCase["case_name"], sampleCase["key_flag_dict"] + bmc_ip = "" + depends_id = {} + http_handler = UrllibHttpHandler() + config_file = {} + rsp_list = execute_final_url(config_file, depends_id, + http_handler, method, url, req_body, key_flag_dict, bmc_ip) + + for i in range (0,len(rsp_list)): + rsp = rsp_list[i] + return_value = rsp["return_value"] + expected_act_pairs = expected_act_pairs_list[i] + exp_act_pairs = {} + for key, value in expected_value.items(): + if key in return_value: + exp_act_pairs[key] = parse_data(value, return_value[key]) + elif key == 'count': + pass + else: + exp_act_pairs[key] = \ + (value, "Can't find key {} in return value".format(key)) + assert exp_act_pairs == expected_act_pairs
\ No newline at end of file |