aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/tests/unit/benchmark')
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/energy/__init__.py0
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/energy/energy_sample_chassis_output.txt14
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/energy/energy_sample_power_metrics.txt300
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/energy/test_energy.py182
4 files changed, 496 insertions, 0 deletions
diff --git a/yardstick/tests/unit/benchmark/scenarios/energy/__init__.py b/yardstick/tests/unit/benchmark/scenarios/energy/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/energy/__init__.py
diff --git a/yardstick/tests/unit/benchmark/scenarios/energy/energy_sample_chassis_output.txt b/yardstick/tests/unit/benchmark/scenarios/energy/energy_sample_chassis_output.txt
new file mode 100644
index 0000000..9b3afd1
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/energy/energy_sample_chassis_output.txt
@@ -0,0 +1,14 @@
+{
+ "@odata.id": "/redfish/v1/Chassis",
+ "Name": "ChassisCollection",
+ "@odata.context": "/redfish/v1/$metadata#ChassisCollection.ChassisCollection",
+ "Members": [
+ {
+ "@odata.id": "/redfish/v1/Chassis/1"
+ }
+ ],
+ "@odata.type": "#ChassisCollection.ChassisCollection",
+ "@odata.etag": "\"af5a94479815eb5f87fe91ea08fde0ac\"",
+ "Members@odata.count": 1,
+ "Description": "A collection of Chassis resource instances."
+}
diff --git a/yardstick/tests/unit/benchmark/scenarios/energy/energy_sample_power_metrics.txt b/yardstick/tests/unit/benchmark/scenarios/energy/energy_sample_power_metrics.txt
new file mode 100644
index 0000000..343ed36
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/energy/energy_sample_power_metrics.txt
@@ -0,0 +1,300 @@
+{
+ "PowerControl@odata.count": 1,
+ "@odata.id": "/redfish/v1/Chassis/1/Power",
+ "Redundancy@odata.count": 1,
+ "@odata.context": "/redfish/v1/$metadata#Power.Power",
+ "Voltages": [
+ {
+ "MaxReadingRange": 14.28,
+ "RelatedItem": [
+ {
+ "@odata.id": "/redfish/v1/Systems/1"
+ },
+ {
+ "@odata.id": "/redfish/v1/Chassis/1"
+ }
+ ],
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/Voltages/0",
+ "Status": {
+ "State": "Enabled"
+ },
+ "SensorNumber": 140,
+ "Name": "SysBrd 12V",
+ "PhysicalContext": "VoltageRegulator",
+ "LowerThresholdCritical": 10.81,
+ "RelatedItem@odata.count": 2,
+ "MemberId": "0",
+ "MinReadingRange": null,
+ "ReadingVolts": 12.15,
+ "UpperThresholdCritical": 13.22
+ },
+ {
+ "MaxReadingRange": 3.95,
+ "RelatedItem": [
+ {
+ "@odata.id": "/redfish/v1/Systems/1"
+ },
+ {
+ "@odata.id": "/redfish/v1/Chassis/1"
+ }
+ ],
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/Voltages/1",
+ "Status": {
+ "State": "Enabled"
+ },
+ "SensorNumber": 141,
+ "Name": "SysBrd 3.3V",
+ "PhysicalContext": "VoltageRegulator",
+ "LowerThresholdCritical": 2.98,
+ "RelatedItem@odata.count": 2,
+ "MemberId": "1",
+ "MinReadingRange": null,
+ "UpperThresholdCritical": 3.63,
+ "ReadingVolts": 3.36
+ },
+ {
+ "MaxReadingRange": 5.97,
+ "RelatedItem": [
+ {
+ "@odata.id": "/redfish/v1/Systems/1"
+ },
+ {
+ "@odata.id": "/redfish/v1/Chassis/1"
+ }
+ ],
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/Voltages/2",
+ "Status": {
+ "State": "Enabled"
+ },
+ "SensorNumber": 142,
+ "Name": "SysBrd 5V",
+ "PhysicalContext": "VoltageRegulator",
+ "LowerThresholdCritical": 4.49,
+ "RelatedItem@odata.count": 2,
+ "MemberId": "2",
+ "MinReadingRange": null,
+ "UpperThresholdCritical": 5.5,
+ "ReadingVolts": 5.03
+ },
+ {
+ "MaxReadingRange": 3.32,
+ "RelatedItem": [
+ {
+ "@odata.id": "/redfish/v1/Systems/1"
+ },
+ {
+ "@odata.id": "/redfish/v1/Chassis/1"
+ }
+ ],
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/Voltages/3",
+ "Status": {
+ "State": "Enabled"
+ },
+ "SensorNumber": 3,
+ "Name": "CMOS Battery",
+ "PhysicalContext": "VoltageRegulator",
+ "LowerThresholdCritical": 2.25,
+ "RelatedItem@odata.count": 2,
+ "MemberId": "3",
+ "MinReadingRange": null,
+ "LowerThresholdNonCritical": 2.39,
+ "ReadingVolts": 3.12
+ }
+ ],
+ "Voltages@odata.count": 4,
+ "Redundancy": [
+ {
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/Redundancy/0",
+ "Status": {
+ "State": "Enabled",
+ "Health": "OK"
+ },
+ "Name": "PSU Redundancy",
+ "MinNumNeeded": 2,
+ "Oem": {
+ "Lenovo": {
+ "NonRedundantAvailablePower": 1100,
+ "@odata.type": "#LenovoRedundancy.v1_0_0.LenovoRedundancyProperties",
+ "PowerRedundancySettings": {
+ "EstimatedUsage": "58.55%",
+ "MaxPowerLimitWatts": 1100,
+ "PowerFailureLimit": 0,
+ "PowerRedundancyPolicy": "RedundantWithThrottling"
+ }
+ }
+ },
+ "RedundancyEnabled": true,
+ "RedundancySet": [
+ {
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/PowerSupplies/0"
+ },
+ {
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/PowerSupplies/1"
+ }
+ ],
+ "RedundancySet@odata.count": 2,
+ "MaxNumSupported": 2,
+ "Mode": "N+m",
+ "MemberId": "0"
+ }
+ ],
+ "Description": "Power Consumption and Power Limiting",
+ "Name": "Power",
+ "PowerSupplies@odata.count": 2,
+ "Oem": {
+ "Lenovo": {
+ "@odata.type": "#LenovoPower.v1_0_0.Capabilities",
+ "LocalPowerControlEnabled": true,
+ "PowerOnPermissionEnabled": true,
+ "PowerRestorePolicy": "Restore",
+ "WakeOnLANEnabled": true
+ }
+ },
+ "@odata.type": "#Power.v1_5_1.Power",
+ "Id": "Power",
+ "@odata.etag": "\"ad85a1403e07a433386e9907d00565cc\"",
+ "PowerControl": [
+ {
+ "PowerAllocatedWatts": 1100,
+ "RelatedItem": [
+ {
+ "@odata.id": "/redfish/v1/Chassis/1"
+ }
+ ],
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/PowerControl/0",
+ "Status": {
+ "HealthRollup": "Warning",
+ "State": "Enabled"
+ },
+ "PowerLimit": {
+ "LimitException": "NoAction",
+ "LimitInWatts": null
+ },
+ "Name": "Server Power Control",
+ "Oem": {
+ "Lenovo": {
+ "PowerUtilization": {
+ "MaxLimitInWatts": 1100,
+ "EnablePowerCapping": false,
+ "LimitMode": "AC",
+ "EnablePowerCapping@Redfish.Deprecated": "The property is deprecated. Please use LimitInWatts instead.",
+ "CapacityMinAC": 617,
+ "MinLimitInWatts": 0,
+ "GuaranteedInWatts": 617,
+ "CapacityMinDC": 578,
+ "CapacityMaxDC": 749,
+ "CapacityMaxAC": 802
+ },
+ "HistoryPowerMetric": {
+ "@odata.id": "/redfish/v1/Chassis/1/Power/PowerControl/0/Oem/Lenovo/HistoryPowerMetric"
+ },
+ "@odata.type": "#LenovoPower.v1_0_0.PowerControl"
+ }
+ },
+ "PowerAvailableWatts": 0,
+ "PowerMetrics": {
+ "IntervalInMin": 60,
+ "AverageConsumedWatts": 314.716675,
+ "MinConsumedWatts": 311,
+ "MaxConsumedWatts": 318
+ },
+ "RelatedItem@odata.count": 1,
+ "MemberId": "0",
+ "PowerRequestedWatts": 802,
+ "PowerConsumedWatts": 344,
+ "PowerCapacityWatts": 1100
+ }
+ ],
+ "PowerSupplies": [
+ {
+ "SerialNumber": "A4DB8BP11WJ",
+ "InputRanges": [
+ {
+ "InputType": null,
+ "OutputWattage": null,
+ "MinimumVoltage": null,
+ "MaximumVoltage": null
+ }
+ ],
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/PowerSupplies/0",
+ "RelatedItem@odata.count": 1,
+ "MemberId": "0",
+ "PartNumber": "SP57A02023",
+ "FirmwareVersion": "4.52",
+ "Status": {
+ "State": "Enabled",
+ "Health": "Warning"
+ },
+ "LineInputVoltage": null,
+ "Name": "PSU1",
+ "PowerSupplyType": "Unknown",
+ "LastPowerOutputWatts": 316,
+ "Oem": {
+ "Lenovo": {
+ "Location": {
+ "InfoFormat": "Slot X",
+ "Info": "Slot 1"
+ },
+ "HistoryPowerSupplyMetric": {
+ "@odata.id": "/redfish/v1/Chassis/1/Power/PowerSupplies/0/Oem/Lenovo/HistoryPowerSupplyMetric"
+ },
+ "@odata.type": "#LenovoPower.v1_0_0.PowerSupply"
+ }
+ },
+ "PowerCapacityWatts": null,
+ "Manufacturer": "ACBE",
+ "LineInputVoltageType": "Unknown",
+ "Model": "LENOVO-SP57A02023",
+ "RelatedItem": [
+ {
+ "@odata.id": "/redfish/v1/Chassis/1"
+ }
+ ]
+ },
+ {
+ "SerialNumber": "A4DB8BP12J7",
+ "InputRanges": [
+ {
+ "InputType": "AC",
+ "OutputWattage": 1100,
+ "MinimumVoltage": 200,
+ "MaximumVoltage": 240
+ }
+ ],
+ "@odata.id": "/redfish/v1/Chassis/1/Power#/PowerSupplies/1",
+ "RelatedItem@odata.count": 1,
+ "MemberId": "1",
+ "PartNumber": "SP57A02023",
+ "FirmwareVersion": "4.52",
+ "Status": {
+ "State": "Enabled",
+ "Health": "OK"
+ },
+ "LineInputVoltage": 220,
+ "Name": "PSU2",
+ "PowerSupplyType": "AC",
+ "LastPowerOutputWatts": 316,
+ "Oem": {
+ "Lenovo": {
+ "Location": {
+ "InfoFormat": "Slot X",
+ "Info": "Slot 2"
+ },
+ "HistoryPowerSupplyMetric": {
+ "@odata.id": "/redfish/v1/Chassis/1/Power/PowerSupplies/1/Oem/Lenovo/HistoryPowerSupplyMetric"
+ },
+ "@odata.type": "#LenovoPower.v1_0_0.PowerSupply"
+ }
+ },
+ "PowerCapacityWatts": 1100,
+ "Manufacturer": "ACBE",
+ "LineInputVoltageType": "ACMidLine",
+ "Model": "LENOVO-SP57A02023",
+ "RelatedItem": [
+ {
+ "@odata.id": "/redfish/v1/Chassis/1"
+ }
+ ]
+ }
+ ]
+}
diff --git a/yardstick/tests/unit/benchmark/scenarios/energy/test_energy.py b/yardstick/tests/unit/benchmark/scenarios/energy/test_energy.py
new file mode 100644
index 0000000..98daefe
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/energy/test_energy.py
@@ -0,0 +1,182 @@
+##############################################################################
+# Copyright (c) 2019 Lenovo Group Limited Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.energy.energy.Energy
+
+from __future__ import absolute_import
+import unittest
+import mock
+import os
+from yardstick.benchmark.scenarios.energy import energy
+
+
+class EnergyTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'target': {
+ 'ip': '172.16.0.137',
+ 'user': 'root',
+ 'password': 'passw0rd',
+ 'redfish_ip': '10.229.17.105',
+ 'redfish_user': 'USERID',
+ 'redfish_pwd': "PASSW0RD",
+ }
+ }
+ self.result = {}
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_setup_response_success(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 200
+ p.setup()
+ self.assertTrue(p.get_response)
+ self.assertTrue(p.setup_done)
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_setup_response_failed(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 404
+ p.setup()
+ self.assertFalse(p.get_response)
+ self.assertTrue(p.setup_done)
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_load_chassis_list_success(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ expect_result = self._read_file("energy_sample_chassis_output.txt")
+ expect_result = str(expect_result)
+ expect_result = expect_result.replace("'", '"')
+ mock_send_request.return_value.status_code = 200
+ mock_send_request.return_value.text = expect_result
+ self.result = p.load_chassis_list()
+ self.assertEqual(self.result, ["/redfish/v1/Chassis/1"])
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_load_chassis_response_fail(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 404
+ self.result = p.load_chassis_list()
+ self.assertEqual(self.result, [])
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_load_chassis_wrongtype_response(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 200
+ expect_result = {}
+ mock_send_request.return_value.text = expect_result
+ self.result = p.load_chassis_list()
+ self.assertEqual(self.result, [])
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_load_chassis_inproper_key(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 200
+ expect_result = '{"some_key": "some_value"}'
+ mock_send_request.return_value.text = expect_result
+ self.result = p.load_chassis_list()
+ self.assertEqual(self.result, [])
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_energy_getpower_success(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ expect_result = self._read_file("energy_sample_power_metrics.txt")
+ expect_result = str(expect_result)
+ expect_result = expect_result.replace("'", '"')
+ mock_send_request.return_value.status_code = 200
+ mock_send_request.return_value.text = expect_result
+ self.result = p.get_power("/redfish/v1/Chassis/1")
+ self.assertEqual(self.result, 344)
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_energy_getpower_response_fail(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 404
+ self.result = p.get_power("/redfish/v1/Chassis/1")
+ self.assertEqual(self.result, -1)
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_energy_getpower_wrongtype_response(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 200
+ expect_result = {}
+ mock_send_request.return_value.text = expect_result
+ self.result = p.get_power("/redfish/v1/Chassis/1")
+ self.assertEqual(self.result, -1)
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_energy_getpower_inproper_key(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 200
+ expect_result = '{"some_key": "some_value"}'
+ mock_send_request.return_value.text = expect_result
+ self.result = p.get_power("/redfish/v1/Chassis/1")
+ self.assertEqual(self.result, -1)
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_run_success(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 200
+ chassis_list = mock.Mock(return_value=["/redfish/v1/Chassis/1"])
+ p.load_chassis_list = chassis_list
+ power = mock.Mock(return_value=344)
+ p.get_power = power
+ p.run(self.result)
+ self.assertEqual(self.result, {"power": 344})
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_run_no_response(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 404
+ chassis_list = mock.Mock(return_value=["/redfish/v1/Chassis/1"])
+ p.load_chassis_list = chassis_list
+ p.run(self.result)
+ self.assertEqual(self.result, {"power": -1})
+
+ @mock.patch('yardstick.benchmark.scenarios.'
+ 'energy.energy.Energy._send_request')
+ def test_run_wrong_chassis(self, mock_send_request):
+ args = {}
+ p = energy.Energy(args, self.ctx)
+ mock_send_request.return_value.status_code = 200
+ chassis_list = mock.Mock(return_value=[])
+ p.load_chassis_list = chassis_list
+ p.run(self.result)
+ self.assertEqual(self.result, {"power": -1})
+
+ def _read_file(self, filename):
+ curr_path = os.path.dirname(os.path.abspath(__file__))
+ output = os.path.join(curr_path, filename)
+ with open(output) as f:
+ sample_output = f.read()
+ return sample_output