Improve unit-tests
This patch is improving the unit-test coverage for the modules: connector.py, main.py and resources/system/system.py. The coverage is now in 95%. Change-Id: I6ddb67d52c0d11c611e54a53af2dafc312ee9400
This commit is contained in:
parent
bb9f4ada4f
commit
f760529c03
|
@ -45,6 +45,7 @@ class System(base.ResourceBase):
|
|||
identity = None
|
||||
"""The system identity string"""
|
||||
|
||||
# TODO(lucasagomes): Create mappings for the indicator_led
|
||||
indicator_led = None
|
||||
"""Whether the indicator LED is lit or off"""
|
||||
|
||||
|
@ -66,6 +67,7 @@ class System(base.ResourceBase):
|
|||
sku = None
|
||||
"""The system stock-keeping unit"""
|
||||
|
||||
# TODO(lucasagomes): Create mappings for the system_type
|
||||
system_type = None
|
||||
"""The system type"""
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"@odata.type": "#ServiceRoot.v1_0_2.ServiceRoot",
|
||||
"Id": "RootService",
|
||||
"Name": "Root Service",
|
||||
"RedfishVersion": "1.0.2",
|
||||
"UUID": "92384634-2938-2342-8820-489239905423",
|
||||
"Systems": {
|
||||
"@odata.id": "/redfish/v1/Systems"
|
||||
},
|
||||
"Chassis": {
|
||||
"@odata.id": "/redfish/v1/Chassis"
|
||||
},
|
||||
"Managers": {
|
||||
"@odata.id": "/redfish/v1/Managers"
|
||||
},
|
||||
"Tasks": {
|
||||
"@odata.id": "/redfish/v1/TaskService"
|
||||
},
|
||||
"SessionService": {
|
||||
"@odata.id": "/redfish/v1/SessionService"
|
||||
},
|
||||
"AccountService": {
|
||||
"@odata.id": "/redfish/v1/AccountService"
|
||||
},
|
||||
"EventService": {
|
||||
"@odata.id": "/redfish/v1/EventService"
|
||||
},
|
||||
"Links": {
|
||||
"Sessions": {
|
||||
"@odata.id": "/redfish/v1/SessionService/Sessions"
|
||||
}
|
||||
},
|
||||
"Oem": {},
|
||||
"@odata.context": "/redfish/v1/$metadata#ServiceRoot",
|
||||
"@odata.id": "/redfish/v1/",
|
||||
"@Redfish.Copyright": "Copyright 2014-2016 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright."
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
{
|
||||
"@odata.type": "#ComputerSystem.v1_1_0.ComputerSystem",
|
||||
"Id": "437XR1138R2",
|
||||
"Name": "WebFrontEnd483",
|
||||
"SystemType": "Physical",
|
||||
"AssetTag": "Chicago-45Z-2381",
|
||||
"Manufacturer": "Contoso",
|
||||
"Model": "3500RX",
|
||||
"SKU": "8675309",
|
||||
"SerialNumber": "437XR1138R2",
|
||||
"PartNumber": "224071-J23",
|
||||
"Description": "Web Front End node",
|
||||
"UUID": "38947555-7742-3448-3784-823347823834",
|
||||
"HostName": "web483",
|
||||
"Status": {
|
||||
"State": "Enabled",
|
||||
"Health": "OK",
|
||||
"HealthRollUp": "OK"
|
||||
},
|
||||
"IndicatorLED": "Off",
|
||||
"PowerState": "On",
|
||||
"Boot": {
|
||||
"BootSourceOverrideEnabled": "Once",
|
||||
"BootSourceOverrideTarget": "Pxe",
|
||||
"BootSourceOverrideTarget@Redfish.AllowableValues": [
|
||||
"None",
|
||||
"Pxe",
|
||||
"Cd",
|
||||
"Usb",
|
||||
"Hdd",
|
||||
"BiosSetup",
|
||||
"Utilities",
|
||||
"Diags",
|
||||
"SDCard",
|
||||
"UefiTarget"
|
||||
],
|
||||
"BootSourceOverrideMode": "UEFI",
|
||||
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"
|
||||
},
|
||||
"TrustedModules": [
|
||||
{
|
||||
"FirmwareVersion": "1.13b",
|
||||
"InterfaceType": "TPM1_2",
|
||||
"Status": {
|
||||
"State": "Enabled",
|
||||
"Health": "OK"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Oem": {
|
||||
"Contoso": {
|
||||
"@odata.type": "http://Contoso.com/Schema#Contoso.ComputerSystem",
|
||||
"ProductionLocation": {
|
||||
"FacilityName": "PacWest Production Facility",
|
||||
"Country": "USA"
|
||||
}
|
||||
},
|
||||
"Chipwise": {
|
||||
"@odata.type": "http://Chipwise.com/Schema#Chipwise.ComputerSystem",
|
||||
"Style": "Executive"
|
||||
}
|
||||
},
|
||||
"BiosVersion": "P79 v1.33 (02/28/2015)",
|
||||
"ProcessorSummary": {
|
||||
"Count": 2,
|
||||
"ProcessorFamily": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series",
|
||||
"Status": {
|
||||
"State": "Enabled",
|
||||
"Health": "OK",
|
||||
"HealthRollUp": "OK"
|
||||
}
|
||||
},
|
||||
"MemorySummary": {
|
||||
"TotalSystemMemoryGiB": 96,
|
||||
"Status": {
|
||||
"State": "Enabled",
|
||||
"Health": "OK",
|
||||
"HealthRollUp": "OK"
|
||||
}
|
||||
},
|
||||
"Bios": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS"
|
||||
},
|
||||
"Processors": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors"
|
||||
},
|
||||
"Memory": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Memory"
|
||||
},
|
||||
"EthernetInterfaces": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/EthernetInterfaces"
|
||||
},
|
||||
"SimpleStorage": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/SimpleStorage"
|
||||
},
|
||||
"LogServices": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/LogServices"
|
||||
},
|
||||
"Links": {
|
||||
"Chassis": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Chassis/1U"
|
||||
}
|
||||
],
|
||||
"ManagedBy": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Managers/BMC"
|
||||
}
|
||||
]
|
||||
},
|
||||
"Actions": {
|
||||
"#ComputerSystem.Reset": {
|
||||
"target": "/redfish/v1/Systems/437XR1138R2/Actions/ComputerSystem.Reset",
|
||||
"ResetType@Redfish.AllowableValues": [
|
||||
"On",
|
||||
"ForceOff",
|
||||
"GracefulShutdown",
|
||||
"GracefulRestart",
|
||||
"ForceRestart",
|
||||
"Nmi",
|
||||
"ForceOn",
|
||||
"PushPowerButton"
|
||||
]
|
||||
},
|
||||
"Oem": {
|
||||
"#Contoso.Reset": {
|
||||
"target": "/redfish/v1/Systems/437XR1138R2/Oem/Contoso/Actions/Contoso.Reset"
|
||||
}
|
||||
}
|
||||
},
|
||||
"@odata.context": "/redfish/v1/$metadata#ComputerSystem.ComputerSystem",
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2",
|
||||
"@Redfish.Copyright": "Copyright 2014-2016 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright."
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
|
||||
"Name": "Computer System Collection",
|
||||
"Members@odata.count": 1,
|
||||
"Members": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2"
|
||||
}
|
||||
],
|
||||
"@odata.context": "/redfish/v1/$metadata#Systems",
|
||||
"@odata.id": "/redfish/v1/Systems",
|
||||
"@Redfish.Copyright": "Copyright 2014-2016 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright."
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
# Copyright 2017 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
import mock
|
||||
|
||||
import sushy
|
||||
from sushy import exceptions
|
||||
from sushy.resources.system import system
|
||||
from sushy.tests.unit import base
|
||||
|
||||
|
||||
class SystemTestCase(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SystemTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('sushy/tests/unit/json_samples/system.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.sys_inst = system.System(self.conn, '437XR1138R2',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.sys_inst._parse_attributes()
|
||||
self.assertEqual('1.0.2', self.sys_inst.redfish_version)
|
||||
self.assertEqual('Chicago-45Z-2381', self.sys_inst.asset_tag)
|
||||
self.assertEqual('P79 v1.33 (02/28/2015)', self.sys_inst.bios_version)
|
||||
self.assertEqual('Web Front End node', self.sys_inst.description)
|
||||
self.assertEqual('web483', self.sys_inst.hostname)
|
||||
self.assertEqual('437XR1138R2', self.sys_inst.identity)
|
||||
self.assertEqual('Off', self.sys_inst.indicator_led)
|
||||
self.assertEqual('Contoso', self.sys_inst.manufacturer)
|
||||
self.assertEqual('WebFrontEnd483', self.sys_inst.name)
|
||||
self.assertEqual('224071-J23', self.sys_inst.part_number)
|
||||
self.assertEqual('437XR1138R2', self.sys_inst.serial_number)
|
||||
self.assertEqual('8675309', self.sys_inst.sku)
|
||||
self.assertEqual('Physical', self.sys_inst.system_type)
|
||||
self.assertEqual('38947555-7742-3448-3784-823347823834',
|
||||
self.sys_inst.uuid)
|
||||
self.assertEqual(sushy.SYSTEM_POWER_STATE_ON,
|
||||
self.sys_inst.power_state)
|
||||
|
||||
def test_get_allowed_reset_system_values(self):
|
||||
values = self.sys_inst.get_allowed_reset_system_values()
|
||||
expected = [sushy.RESET_GRACEFUL_SHUTDOWN,
|
||||
sushy.RESET_GRACEFUL_RESTART,
|
||||
sushy.RESET_FORCE_RESTART,
|
||||
sushy.RESET_FORCE_OFF,
|
||||
sushy.RESET_FORCE_ON,
|
||||
sushy.RESET_ON,
|
||||
sushy.RESET_NMI,
|
||||
sushy.RESET_PUSH_POWER_BUTTON]
|
||||
self.assertEqual(sorted(expected), sorted(values))
|
||||
|
||||
def test_reset_system(self):
|
||||
self.sys_inst.reset_system(sushy.RESET_FORCE_OFF)
|
||||
self.sys_inst._conn.post.assert_called_once_with(
|
||||
'Systems/437XR1138R2/Actions/ComputerSystem.Reset',
|
||||
data={'ResetType': 'ForceOff'})
|
||||
|
||||
def test_reset_system_invalid_value(self):
|
||||
self.assertRaises(exceptions.InvalidParameterValueError,
|
||||
self.sys_inst.reset_system, 'invalid-value')
|
||||
|
||||
def test_get_allowed_system_boot_source_values(self):
|
||||
values = self.sys_inst.get_allowed_system_boot_source_values()
|
||||
expected = [sushy.BOOT_SOURCE_TARGET_NONE,
|
||||
sushy.BOOT_SOURCE_TARGET_PXE,
|
||||
sushy.BOOT_SOURCE_TARGET_CD,
|
||||
sushy.BOOT_SOURCE_TARGET_USB,
|
||||
sushy.BOOT_SOURCE_TARGET_HDD,
|
||||
sushy.BOOT_SOURCE_TARGET_BIOS_SETUP,
|
||||
sushy.BOOT_SOURCE_TARGET_UTILITIES,
|
||||
sushy.BOOT_SOURCE_TARGET_DIAGS,
|
||||
sushy.BOOT_SOURCE_TARGET_SD_CARD,
|
||||
sushy.BOOT_SOURCE_TARGET_UEFI_TARGET]
|
||||
self.assertEqual(sorted(expected), sorted(values))
|
||||
|
||||
def test_set_system_boot_source(self):
|
||||
self.sys_inst.set_system_boot_source(
|
||||
sushy.BOOT_SOURCE_TARGET_PXE,
|
||||
enabled=sushy.BOOT_SOURCE_ENABLED_CONTINUOUS,
|
||||
mode=sushy.BOOT_SOURCE_MODE_UEFI)
|
||||
self.sys_inst._conn.patch.assert_called_once_with(
|
||||
'Systems/437XR1138R2',
|
||||
data={'Boot': {'BootSourceOverrideEnabled': 'Continuous',
|
||||
'BootSourceOverrideTarget': 'Pxe',
|
||||
'BootSourceOverrideMode': 'UEFI'}})
|
||||
|
||||
def test_set_system_boot_source_no_mode_specified(self):
|
||||
self.sys_inst.set_system_boot_source(
|
||||
sushy.BOOT_SOURCE_TARGET_HDD,
|
||||
enabled=sushy.BOOT_SOURCE_ENABLED_ONCE)
|
||||
self.sys_inst._conn.patch.assert_called_once_with(
|
||||
'Systems/437XR1138R2',
|
||||
data={'Boot': {'BootSourceOverrideEnabled': 'Once',
|
||||
'BootSourceOverrideTarget': 'Hdd'}})
|
||||
|
||||
def test_set_system_boot_source_invalid_target(self):
|
||||
self.assertRaises(exceptions.InvalidParameterValueError,
|
||||
self.sys_inst.set_system_boot_source,
|
||||
'invalid-target')
|
||||
|
||||
def test_set_system_boot_source_invalid_enabled(self):
|
||||
self.assertRaises(exceptions.InvalidParameterValueError,
|
||||
self.sys_inst.set_system_boot_source,
|
||||
sushy.BOOT_SOURCE_TARGET_HDD,
|
||||
enabled='invalid-enabled')
|
||||
|
||||
|
||||
class SystemCollectionTestCase(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SystemCollectionTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('sushy/tests/unit/json_samples/'
|
||||
'system_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
self.sys_col = system.SystemCollection(self.conn,
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.sys_col._parse_attributes()
|
||||
self.assertEqual('1.0.2', self.sys_col.redfish_version)
|
||||
self.assertEqual('Computer System Collection', self.sys_col.name)
|
||||
self.assertEqual(('437XR1138R2',), self.sys_col.members_identities)
|
||||
|
||||
@mock.patch.object(system, 'System', autospec=True)
|
||||
def test_get_member(self, mock_system):
|
||||
self.sys_col.get_member('437XR1138R2')
|
||||
mock_system.assert_called_once_with(
|
||||
self.sys_col._conn, '437XR1138R2',
|
||||
redfish_version=self.sys_col.redfish_version)
|
||||
|
||||
@mock.patch.object(system, 'System', autospec=True)
|
||||
def test_get_members(self, mock_system):
|
||||
members = self.sys_col.get_members()
|
||||
mock_system.assert_called_once_with(
|
||||
self.sys_col._conn, '437XR1138R2',
|
||||
redfish_version=self.sys_col.redfish_version)
|
||||
self.assertIsInstance(members, list)
|
||||
self.assertEqual(1, len(members))
|
|
@ -48,16 +48,23 @@ class ConnectorTestCase(base.TestCase):
|
|||
self.data, self.headers)
|
||||
|
||||
@mock.patch('sushy.connector.requests.Session', autospec=True)
|
||||
def test__op(self, mock_session):
|
||||
def _test_op(self, headers, expected_headers, mock_session):
|
||||
fake_session = mock.Mock()
|
||||
mock_session.return_value.__enter__.return_value = fake_session
|
||||
|
||||
self.conn._op('GET', path='fake/path', data=self.data,
|
||||
headers=self.headers)
|
||||
headers=headers)
|
||||
mock_session.assert_called_once_with()
|
||||
fake_session.request.assert_called_once_with(
|
||||
'GET', 'http://foo.bar:1234/redfish/v1/fake/path',
|
||||
data='{"fake": "data"}')
|
||||
expected_headers = {'Content-Type': 'application/json',
|
||||
'X-Fake': 'header'}
|
||||
self.assertEqual(expected_headers, fake_session.headers)
|
||||
|
||||
def test__op(self):
|
||||
expected_headers = self.headers.copy()
|
||||
expected_headers['Content-Type'] = 'application/json'
|
||||
self._test_op(self.headers, expected_headers)
|
||||
|
||||
def test__op_no_headers(self):
|
||||
expected_headers = {'Content-Type': 'application/json'}
|
||||
self._test_op(None, expected_headers)
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
# Copyright 2017 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
import mock
|
||||
|
||||
from sushy import connector
|
||||
from sushy import main
|
||||
from sushy.resources.system import system
|
||||
from sushy.tests.unit import base
|
||||
|
||||
|
||||
class MainTestCase(base.TestCase):
|
||||
|
||||
@mock.patch.object(connector, 'Connector', autospec=True)
|
||||
def setUp(self, mock_connector):
|
||||
super(MainTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
mock_connector.return_code = self.conn
|
||||
self.root = main.Sushy(
|
||||
'http://foo.bar:1234/redfish/v1', username='foo', password='bar',
|
||||
verify=True)
|
||||
mock_connector.assert_called_once_with(
|
||||
'http://foo.bar:1234/redfish/v1', 'foo', 'bar', True)
|
||||
|
||||
def test__parse_attributes(self):
|
||||
with open('sushy/tests/unit/json_samples/root.json', 'r') as f:
|
||||
self.root._json = json.loads(f.read())
|
||||
self.root._parse_attributes()
|
||||
self.assertEqual('RootService', self.root.identity)
|
||||
self.assertEqual('Root Service', self.root.name)
|
||||
self.assertEqual('1.0.2', self.root.redfish_version)
|
||||
self.assertEqual('92384634-2938-2342-8820-489239905423',
|
||||
self.root.uuid)
|
||||
|
||||
@mock.patch.object(system, 'SystemCollection', autospec=True)
|
||||
def test_get_system_collection(self, mock_system_collection):
|
||||
self.root.get_system_collection()
|
||||
mock_system_collection.assert_called_once_with(
|
||||
self.root._conn, redfish_version=self.root.redfish_version)
|
||||
|
||||
@mock.patch.object(system, 'System', autospec=True)
|
||||
def test_get_system(self, mock_system):
|
||||
self.root.get_system('fake-system-id')
|
||||
mock_system.assert_called_once_with(
|
||||
self.root._conn, 'fake-system-id',
|
||||
redfish_version=self.root.redfish_version)
|
Loading…
Reference in New Issue