summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-08 10:51:32 +0000
committerGerrit Code Review <review@openstack.org>2017-06-08 10:51:32 +0000
commit840f7d72f7ffbefabfa1414467b1eae798782f16 (patch)
tree1c1537b2cf6e2b811857ba8bad2ed8e7a19baf03
parent7e3a0e45598d2b507dc87768cb3d91fe93b8dfb6 (diff)
parent3ff2a0582ff259b3dabb319dd4f25760b29add67 (diff)
Merge "Add HPE extensions support to redfish connection lib"
-rw-r--r--proliantutils/redfish/main.py35
-rw-r--r--proliantutils/redfish/redfish.py3
-rw-r--r--proliantutils/redfish/resources/__init__.py0
-rw-r--r--proliantutils/redfish/resources/system/__init__.py0
-rw-r--r--proliantutils/redfish/resources/system/system.py25
-rw-r--r--proliantutils/tests/redfish/test_main.py40
-rw-r--r--proliantutils/tests/redfish/test_redfish.py5
7 files changed, 105 insertions, 3 deletions
diff --git a/proliantutils/redfish/main.py b/proliantutils/redfish/main.py
new file mode 100644
index 0000000..b670345
--- /dev/null
+++ b/proliantutils/redfish/main.py
@@ -0,0 +1,35 @@
1# Copyright 2017 Hewlett Packard Enterprise Development LP
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15__author__ = 'HPE'
16
17from proliantutils.redfish.resources.system import system
18import sushy
19
20
21class HPESushy(sushy.Sushy):
22 """Class that extends base Sushy class
23
24 This class extends the Sushy class to override certain methods
25 required to customize the functionality of different resources
26 """
27
28 def get_system(self, identity):
29 """Given the identity return a HPESystem object
30
31 :param identity: The identity of the System resource
32 :returns: The System object
33 """
34 return system.HPESystem(self._conn, identity,
35 redfish_version=self.redfish_version)
diff --git a/proliantutils/redfish/redfish.py b/proliantutils/redfish/redfish.py
index 808e26e..90a05e1 100644
--- a/proliantutils/redfish/redfish.py
+++ b/proliantutils/redfish/redfish.py
@@ -20,6 +20,7 @@ import sushy
20from proliantutils import exception 20from proliantutils import exception
21from proliantutils.ilo import operations 21from proliantutils.ilo import operations
22from proliantutils import log 22from proliantutils import log
23from proliantutils.redfish import main
23 24
24 25
25""" 26"""
@@ -86,7 +87,7 @@ class RedfishOperations(operations.IloOperations):
86 self._root_prefix = root_prefix 87 self._root_prefix = root_prefix
87 88
88 try: 89 try:
89 self._sushy = sushy.Sushy( 90 self._sushy = main.HPESushy(
90 address, username=username, password=password, 91 address, username=username, password=password,
91 root_prefix=root_prefix, verify=verify) 92 root_prefix=root_prefix, verify=verify)
92 except sushy.exceptions.SushyError as e: 93 except sushy.exceptions.SushyError as e:
diff --git a/proliantutils/redfish/resources/__init__.py b/proliantutils/redfish/resources/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/proliantutils/redfish/resources/__init__.py
diff --git a/proliantutils/redfish/resources/system/__init__.py b/proliantutils/redfish/resources/system/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/proliantutils/redfish/resources/system/__init__.py
diff --git a/proliantutils/redfish/resources/system/system.py b/proliantutils/redfish/resources/system/system.py
new file mode 100644
index 0000000..c477dd1
--- /dev/null
+++ b/proliantutils/redfish/resources/system/system.py
@@ -0,0 +1,25 @@
1# Copyright 2017 Hewlett Packard Enterprise Development LP
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15__author__ = 'HPE'
16
17from sushy.resources.system import system
18
19
20class HPESystem(system.System):
21 """Class that extends the functionality of System resource class
22
23 This class extends the functionality of System resource class
24 from sushy
25 """
diff --git a/proliantutils/tests/redfish/test_main.py b/proliantutils/tests/redfish/test_main.py
new file mode 100644
index 0000000..779d2a5
--- /dev/null
+++ b/proliantutils/tests/redfish/test_main.py
@@ -0,0 +1,40 @@
1# Copyright 2017 Hewlett Packard Enterprise Development LP
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import mock
17from sushy import connector
18import testtools
19
20from proliantutils.redfish import main
21from proliantutils.redfish.resources.system import system
22
23
24class HPESushyTestCase(testtools.TestCase):
25
26 @mock.patch.object(connector, 'Connector', autospec=True)
27 def setUp(self, connector_mock):
28 super(HPESushyTestCase, self).setUp()
29 self.hpe_sushy = main.HPESushy('https://1.2.3.4',
30 username='foo',
31 password='bar')
32
33 @mock.patch.object(system, 'HPESystem', autospec=True)
34 def test_get_system(self, mock_system):
35 sys_inst = self.hpe_sushy.get_system('1234')
36 self.assertTrue(isinstance(sys_inst,
37 system.HPESystem.__class__))
38 mock_system.assert_called_once_with(self.hpe_sushy._conn,
39 '1234',
40 self.hpe_sushy.redfish_version)
diff --git a/proliantutils/tests/redfish/test_redfish.py b/proliantutils/tests/redfish/test_redfish.py
index 3cd32e7..7fb5884 100644
--- a/proliantutils/tests/redfish/test_redfish.py
+++ b/proliantutils/tests/redfish/test_redfish.py
@@ -20,12 +20,13 @@ import sushy
20import testtools 20import testtools
21 21
22from proliantutils import exception 22from proliantutils import exception
23from proliantutils.redfish import main
23from proliantutils.redfish import redfish 24from proliantutils.redfish import redfish
24 25
25 26
26class RedfishOperationsTestCase(testtools.TestCase): 27class RedfishOperationsTestCase(testtools.TestCase):
27 28
28 @mock.patch.object(sushy, 'Sushy', autospec=True) 29 @mock.patch.object(main, 'HPESushy', autospec=True)
29 def setUp(self, sushy_mock): 30 def setUp(self, sushy_mock):
30 super(RedfishOperationsTestCase, self).setUp() 31 super(RedfishOperationsTestCase, self).setUp()
31 self.sushy = mock.MagicMock() 32 self.sushy = mock.MagicMock()
@@ -39,7 +40,7 @@ class RedfishOperationsTestCase(testtools.TestCase):
39 sushy_mock.assert_called_once_with( 40 sushy_mock.assert_called_once_with(
40 'https://1.2.3.4', 'foo', 'bar', '/redfish/v1/', False) 41 'https://1.2.3.4', 'foo', 'bar', '/redfish/v1/', False)
41 42
42 @mock.patch.object(sushy, 'Sushy', autospec=True) 43 @mock.patch.object(main, 'HPESushy', autospec=True)
43 def test_sushy_init_fail(self, sushy_mock): 44 def test_sushy_init_fail(self, sushy_mock):
44 sushy_mock.side_effect = sushy.exceptions.SushyError 45 sushy_mock.side_effect = sushy.exceptions.SushyError
45 self.assertRaisesRegex( 46 self.assertRaisesRegex(