summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebayan Ray <debayan.ray@gmail.com>2017-06-02 12:42:26 -0400
committerDebayan Ray <debayan.ray@gmail.com>2017-06-05 01:50:57 -0400
commit7e3a0e45598d2b507dc87768cb3d91fe93b8dfb6 (patch)
treec709b9dc78dd8688859c3ba98710687a545e8599
parent100c058a09cec405fe1ab9f012699f8f4d3e9519 (diff)
Redfish: Add system power operations
This patch adds system power operations in proliantutils via redfish way. These 2 methods are introduced on redfish ops: 1) reset_server 2) set_host_power Partial-Bug: 1691955 Change-Id: Ib8217cfe68c5ae5b647d5ece055251153054454d
Notes
Notes (review): Code-Review+2: Nisha Agarwal <agarwalnisha1980@gmail.com> Code-Review+2: Shivanand Tendulker <stendulker@gmail.com> Code-Review+2: vinay kumar muddu <vinay50muddu@yahoo.com> Workflow+1: vinay kumar muddu <vinay50muddu@yahoo.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 07 Jun 2017 06:57:21 +0000 Reviewed-on: https://review.openstack.org/470353 Project: openstack/proliantutils Branch: refs/heads/master
-rw-r--r--proliantutils/ilo/client.py2
-rw-r--r--proliantutils/redfish/redfish.py57
-rw-r--r--proliantutils/tests/redfish/test_redfish.py43
3 files changed, 102 insertions, 0 deletions
diff --git a/proliantutils/ilo/client.py b/proliantutils/ilo/client.py
index fcc5215..06ad50c 100644
--- a/proliantutils/ilo/client.py
+++ b/proliantutils/ilo/client.py
@@ -60,6 +60,8 @@ SUPPORTED_RIS_METHODS = [
60SUPPORTED_REDFISH_METHODS = [ 60SUPPORTED_REDFISH_METHODS = [
61 'get_product_name', 61 'get_product_name',
62 'get_host_power_status', 62 'get_host_power_status',
63 'set_host_power',
64 'reset_server',
63] 65]
64 66
65LOG = log.get_logger(__name__) 67LOG = log.get_logger(__name__)
diff --git a/proliantutils/redfish/redfish.py b/proliantutils/redfish/redfish.py
index 540b97b..808e26e 100644
--- a/proliantutils/redfish/redfish.py
+++ b/proliantutils/redfish/redfish.py
@@ -33,6 +33,11 @@ GET_POWER_STATE_MAP = {
33 sushy.SYSTEM_POWER_STATE_POWERING_OFF: 'OFF' 33 sushy.SYSTEM_POWER_STATE_POWERING_OFF: 'OFF'
34} 34}
35 35
36POWER_RESET_MAP = {
37 'ON': sushy.RESET_ON,
38 'OFF': sushy.RESET_FORCE_OFF,
39}
40
36PROLIANT_SYSTEM_ID = '1' 41PROLIANT_SYSTEM_ID = '1'
37 42
38LOG = log.get_logger(__name__) 43LOG = log.get_logger(__name__)
@@ -138,3 +143,55 @@ class RedfishOperations(operations.IloOperations):
138 # as we are dealing with iLO's here. 143 # as we are dealing with iLO's here.
139 sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID) 144 sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID)
140 return GET_POWER_STATE_MAP.get(sushy_system.power_state) 145 return GET_POWER_STATE_MAP.get(sushy_system.power_state)
146
147 def reset_server(self):
148 """Resets the server.
149
150 :raises: IloError, on an error from iLO.
151 """
152 # Assuming only one sushy_system present as part of collection,
153 # as we are dealing with iLO's here.
154 sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID)
155 try:
156 sushy_system.reset_system(sushy.RESET_FORCE_RESTART)
157 except sushy.exceptions.SushyError as e:
158 msg = (self._('The Redfish controller failed to reset server. '
159 'Error %(error)s') %
160 {'error': str(e)})
161 LOG.debug(msg)
162 raise exception.IloError(msg)
163
164 def set_host_power(self, target_value):
165 """Sets the power state of the system.
166
167 :param target_value: The target value to be set. Value can be:
168 'ON' or 'OFF'.
169 :raises: IloError, on an error from iLO.
170 :raises: InvalidInputError, if the target value is not
171 allowed.
172 """
173 if target_value not in POWER_RESET_MAP:
174 msg = ('The parameter "%(parameter)s" value "%(target_value)s" is '
175 'invalid. Valid values are: %(valid_power_values)s' %
176 {'parameter': 'target_value', 'target_value': target_value,
177 'valid_power_values': POWER_RESET_MAP.keys()})
178 raise exception.InvalidInputError(msg)
179
180 # Check current power status, do not act if it's in requested state.
181 current_power_status = self.get_host_power_status()
182 if current_power_status == target_value:
183 LOG.debug(self._("Node is already in '%(target_value)s' power "
184 "state."), {'target_value': target_value})
185 return
186
187 # Assuming only one system present as part of collection,
188 # as we are dealing with iLO's here.
189 sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID)
190 try:
191 sushy_system.reset_system(POWER_RESET_MAP[target_value])
192 except sushy.exceptions.SushyError as e:
193 msg = (self._('The Redfish controller failed to set power state '
194 'of server to %(target_value)s. Error %(error)s') %
195 {'target_value': target_value, 'error': str(e)})
196 LOG.debug(msg)
197 raise exception.IloError(msg)
diff --git a/proliantutils/tests/redfish/test_redfish.py b/proliantutils/tests/redfish/test_redfish.py
index 0df709b..3cd32e7 100644
--- a/proliantutils/tests/redfish/test_redfish.py
+++ b/proliantutils/tests/redfish/test_redfish.py
@@ -78,3 +78,46 @@ class RedfishOperationsTestCase(testtools.TestCase):
78 self.sushy.get_system().power_state = sushy.SYSTEM_POWER_STATE_ON 78 self.sushy.get_system().power_state = sushy.SYSTEM_POWER_STATE_ON
79 power_state = self.rf_client.get_host_power_status() 79 power_state = self.rf_client.get_host_power_status()
80 self.assertEqual('ON', power_state) 80 self.assertEqual('ON', power_state)
81
82 def test_reset_server(self):
83 self.rf_client.reset_server()
84 self.sushy.get_system().reset_system.assert_called_once_with(
85 sushy.RESET_FORCE_RESTART)
86
87 def test_reset_server_invalid_value(self):
88 self.sushy.get_system().reset_system.side_effect = (
89 sushy.exceptions.SushyError)
90 self.assertRaisesRegex(
91 exception.IloError,
92 'The Redfish controller failed to reset server.',
93 self.rf_client.reset_server)
94
95 @mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
96 def test_set_host_power_no_change(self, get_host_power_status_mock):
97 get_host_power_status_mock.return_value = 'ON'
98 self.rf_client.set_host_power('ON')
99 self.assertTrue(get_host_power_status_mock.called)
100 self.assertFalse(self.sushy.get_system().reset_system.called)
101
102 @mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
103 def test_set_host_power_failure(self, get_host_power_status_mock):
104 get_host_power_status_mock.return_value = 'OFF'
105 self.sushy.get_system().reset_system.side_effect = (
106 sushy.exceptions.SushyError)
107 self.assertRaisesRegex(
108 exception.IloError,
109 'The Redfish controller failed to set power state of server to ON',
110 self.rf_client.set_host_power, 'ON')
111
112 def test_set_host_power_invalid_input(self):
113 self.assertRaisesRegex(
114 exception.InvalidInputError,
115 'The parameter "target_value" value "Off" is invalid.',
116 self.rf_client.set_host_power, 'Off')
117
118 @mock.patch.object(redfish.RedfishOperations, 'get_host_power_status')
119 def test_set_host_power_change(self, get_host_power_status_mock):
120 get_host_power_status_mock.return_value = 'OFF'
121 self.rf_client.set_host_power('ON')
122 self.sushy.get_system().reset_system.assert_called_once_with(
123 sushy.RESET_ON)