summaryrefslogtreecommitdiff
path: root/proliantutils/tests/redfish/test_redfish.py
diff options
context:
space:
mode:
Diffstat (limited to 'proliantutils/tests/redfish/test_redfish.py')
-rw-r--r--proliantutils/tests/redfish/test_redfish.py50
1 files changed, 27 insertions, 23 deletions
diff --git a/proliantutils/tests/redfish/test_redfish.py b/proliantutils/tests/redfish/test_redfish.py
index df26572..0df709b 100644
--- a/proliantutils/tests/redfish/test_redfish.py
+++ b/proliantutils/tests/redfish/test_redfish.py
@@ -16,61 +16,65 @@
16import json 16import json
17 17
18import mock 18import mock
19import sushy
19import testtools 20import testtools
20 21
21from proliantutils import exception 22from proliantutils import exception
22from proliantutils.redfish import redfish 23from proliantutils.redfish import redfish
23from proliantutils import rest
24 24
25 25
26class RedfishOperationsTestCase(testtools.TestCase): 26class RedfishOperationsTestCase(testtools.TestCase):
27 27
28 @mock.patch.object(rest, 'RestConnectorBase', autospec=True) 28 @mock.patch.object(sushy, 'Sushy', autospec=True)
29 def setUp(self, rest_connector_mock): 29 def setUp(self, sushy_mock):
30 super(RedfishOperationsTestCase, self).setUp() 30 super(RedfishOperationsTestCase, self).setUp()
31 self.conn = mock.MagicMock() 31 self.sushy = mock.MagicMock()
32 rest_connector_mock.return_value = self.conn 32 sushy_mock.return_value = self.sushy
33 with open('proliantutils/tests/redfish/' 33 with open('proliantutils/tests/redfish/'
34 'json_samples/root.json', 'r') as f: 34 'json_samples/root.json', 'r') as f:
35 self.conn._rest_get.return_value = 200, None, json.loads(f.read()) 35 self.sushy.json = json.loads(f.read())
36 36
37 self.rf_client = redfish.RedfishOperations( 37 self.rf_client = redfish.RedfishOperations(
38 '1.2.3.4', username='foo', password='bar') 38 '1.2.3.4', username='foo', password='bar')
39 rest_connector_mock.assert_called_once_with( 39 sushy_mock.assert_called_once_with(
40 '1.2.3.4', 'foo', 'bar', None, None) 40 'https://1.2.3.4', 'foo', 'bar', '/redfish/v1/', False)
41 41
42 def test__fetch_root_resources(self): 42 @mock.patch.object(sushy, 'Sushy', autospec=True)
43 rf_client = self.rf_client 43 def test_sushy_init_fail(self, sushy_mock):
44 rf_client._fetch_root_resources() 44 sushy_mock.side_effect = sushy.exceptions.SushyError
45 self.assertEqual('HPE RESTful Root Service', 45 self.assertRaisesRegex(
46 rf_client._root_resp.get('Name')) 46 exception.IloConnectionError,
47 self.assertEqual('1.0.0', rf_client._root_resp.get('RedfishVersion')) 47 'The Redfish controller at "https://1.2.3.4" has thrown error',
48 self.assertEqual('7704b47b-2fbe-5920-99a5-b766dd84cc28', 48 redfish.RedfishOperations,
49 rf_client._root_resp.get('UUID')) 49 '1.2.3.4', username='foo', password='bar')
50 for resource in ['Systems', 'Managers', 'Chassis']:
51 self.assertTrue(resource in rf_client._root_resp)
52 50
53 def test__get_system_collection_path(self): 51 def test__get_system_collection_path(self):
54 self.assertEqual('/redfish/v1/Systems/', 52 self.assertEqual('/redfish/v1/Systems/',
55 self.rf_client._get_system_collection_path()) 53 self.rf_client._get_system_collection_path())
56 54
57 def test__get_system_collection_path_missing_systems_attr(self): 55 def test__get_system_collection_path_missing_systems_attr(self):
58 self.rf_client._root_resp.pop('Systems') 56 self.rf_client._sushy.json.pop('Systems')
59 self.assertRaisesRegex( 57 self.assertRaisesRegex(
60 exception.MissingAttributeError, 58 exception.MissingAttributeError,
61 'The attribute Systems is missing', 59 'The attribute Systems is missing',
62 self.rf_client._get_system_collection_path) 60 self.rf_client._get_system_collection_path)
63 61
62 def test__get_sushy_system_fail(self):
63 self.rf_client._sushy.get_system.side_effect = (
64 sushy.exceptions.SushyError)
65 self.assertRaisesRegex(
66 exception.IloError,
67 'The Redfish System "apple" was not found.',
68 self.rf_client._get_sushy_system, 'apple')
69
64 def test_get_product_name(self): 70 def test_get_product_name(self):
65 with open('proliantutils/tests/redfish/' 71 with open('proliantutils/tests/redfish/'
66 'json_samples/system.json', 'r') as f: 72 'json_samples/system.json', 'r') as f:
67 self.conn._rest_get.return_value = 200, None, json.loads(f.read()) 73 self.sushy.get_system().json = json.loads(f.read())
68 product_name = self.rf_client.get_product_name() 74 product_name = self.rf_client.get_product_name()
69 self.assertEqual('ProLiant DL180 Gen10', product_name) 75 self.assertEqual('ProLiant DL180 Gen10', product_name)
70 76
71 def test_get_host_power_status(self): 77 def test_get_host_power_status(self):
72 with open('proliantutils/tests/redfish/' 78 self.sushy.get_system().power_state = sushy.SYSTEM_POWER_STATE_ON
73 'json_samples/system.json', 'r') as f:
74 self.conn._rest_get.return_value = 200, None, json.loads(f.read())
75 power_state = self.rf_client.get_host_power_status() 79 power_state = self.rf_client.get_host_power_status()
76 self.assertEqual('ON', power_state) 80 self.assertEqual('ON', power_state)