-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for Redfish system. These unit tests employ `unittest.mock`, which is a Python 3 feature only.
- Loading branch information
Showing
2 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# coding: utf-8 | ||
# Unit tests for the Redfish API | ||
from unittest import mock, TestCase | ||
|
||
from wrapanapi.exceptions import InvalidValueException | ||
from wrapanapi.systems import RedfishSystem | ||
from wrapanapi.systems.redfish import RedfishChassis, RedfishRack, RedfishServer | ||
|
||
|
||
@mock.patch("redfish_client.connect") | ||
class TestRedfishSystemSetup: | ||
def test_connect_non_ssl(self, mock_connector): | ||
RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
mock_connector.assert_called_with("http://dummy:8000/", "user", "pass") | ||
|
||
def test_connect_ssl(self, mock_connector): | ||
RedfishSystem("dummy", "user", "pass", "SSL", "443") | ||
mock_connector.assert_called_with("https://dummy:443/", "user", "pass") | ||
|
||
|
||
@mock.patch("redfish_client.Root.login") | ||
@mock.patch("redfish_client.CachingConnector") | ||
class TestRedfishSystem(TestCase): | ||
def test_find_resource(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "id" | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
resource = rf.find("/redfish/v1/BlankResource") | ||
self.assertEqual(resource.raw, {"@odata.id": "id"}) | ||
|
||
def test_get_server(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "/redfish/v1/Systems/System-1-2-1-1", | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
rf_server = rf.get_server("/redfish/v1/Systems/System-1-2-1-1") | ||
self.assertEqual(type(rf_server), RedfishServer) | ||
|
||
def test_server_simple_properties(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "/redfish/v1/Systems/System-1-2-1-1", | ||
"Description": "A server", | ||
"Id": "System-1-2-1-1", | ||
"Manufacturer": "Dell Inc.", | ||
"Name": "System", | ||
"PowerState": "On", | ||
"SerialNumber": "945hjf0927mf", | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
rf_server = rf.get_server("/redfish/v1/Systems/System-1-2-1-1") | ||
self.assertEqual(rf_server.name, "Dell Inc. System (945hjf0927mf)") | ||
self.assertEqual(rf_server.description, "A server") | ||
self.assertEqual(rf_server.state, "On") | ||
self.assertEqual(rf_server._identifying_attrs, | ||
{"odata_id": "/redfish/v1/Systems/System-1-2-1-1"}) | ||
self.assertEqual(rf_server.uuid(), "System-1-2-1-1") | ||
|
||
def test_server_name_no_sn(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "/redfish/v1/Systems/System-1-2-1-1", | ||
"Id": "System-1-2-1-1", | ||
"Manufacturer": "Dell Inc.", | ||
"Name": "System", | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
rf_server = rf.get_server("/redfish/v1/Systems/System-1-2-1-1") | ||
self.assertEqual(rf_server.name, "Dell Inc. System") | ||
|
||
def test_get_chassis(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "/redfish/v1/Chassis/Sled-1-2-1", | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
rf_chassis = rf.get_chassis("/redfish/v1/Chassis/Sled-1-2-1") | ||
self.assertEqual(type(rf_chassis), RedfishChassis) | ||
|
||
def test_get_chassis_simple_properties(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "/redfish/v1/Chassis/Sled-1-2-1", | ||
"ChassisType": "Sled", | ||
"Description": "G5 Sled-Level Enclosure", | ||
"Id": "Sled-1-2-1", | ||
"IndicatorLED": "Blinking", | ||
"Manufacturer": "Dell", | ||
"Name": "G5_Sled", | ||
"SerialNumber": "5555A", | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
rf_chassis = rf.get_chassis("/redfish/v1/Chassis/Sled-1-2-1") | ||
self.assertEqual(rf_chassis.chassis_type, "Sled") | ||
self.assertEqual(rf_chassis.name, "Dell G5_Sled (5555A)") | ||
self.assertEqual(rf_chassis.description, "G5 Sled-Level Enclosure") | ||
self.assertEqual(rf_chassis.led_state, "Blinking") | ||
self.assertEqual(rf_chassis._identifying_attrs, | ||
{"odata_id": "/redfish/v1/Chassis/Sled-1-2-1"}) | ||
self.assertEqual(rf_chassis.uuid(), "Sled-1-2-1") | ||
|
||
def test_get_rack(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "/redfish/v1/Chassis/Rack-1", | ||
"ChassisType": "Rack", | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
rf_rack = rf.get_rack("/redfish/v1/Chassis/Rack-1") | ||
self.assertEqual(type(rf_rack), RedfishRack) | ||
|
||
def test_get_rack_bad(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "/redfish/v1/Chassis/Sled-1-2-1", | ||
"ChassisType": "Sled", | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
with self.assertRaises(InvalidValueException, | ||
msg="Chassis type Sled does not match that of a Rack"): | ||
rf.get_rack("/redfish/v1/Chassis/Sled-1-2-1") | ||
|
||
def test_get_rack_simple_properties(self, mock_connector, mock_root_login): | ||
mock_connector.return_value.get.return_value.status = 200 | ||
mock_connector.return_value.get.return_value.json = { | ||
"@odata.id": "/redfish/v1/Chassis/Rack-1", | ||
"ChassisType": "Rack", | ||
"Description": "Redfish Rack", | ||
"Id": "Rack-1", | ||
"Manufacturer": "Dell", | ||
"Name": "G5_Rack", | ||
"SerialNumber": "1ABC", | ||
} | ||
|
||
rf = RedfishSystem("dummy", "user", "pass", "Non-SSL", "8000") | ||
rf_rack = rf.get_rack("/redfish/v1/Chassis/Rack-1") | ||
self.assertEqual(rf_rack.chassis_type, "Rack") | ||
self.assertEqual(rf_rack.name, "Rack-1") | ||
self.assertEqual(rf_rack.description, "Redfish Rack") | ||
self.assertEqual(rf_rack.uuid(), "Rack-1") | ||
self.assertEqual(rf_rack._identifying_attrs, {"odata_id": | ||
"/redfish/v1/Chassis/Rack-1"}) |