def test__set_power_state_fail(self, mock_client_pywsman, mock_aw): mock_client = mock_client_pywsman.return_value mock_client.wsman_invoke.side_effect = exception.AMTFailure('x') self.assertRaises(exception.AMTFailure, amt_power._set_power_state, self.node, states.POWER_ON) self.assertTrue(mock_aw.called)
def test__power_status_fail(self, mock_gwc, mock_aw): mock_client = mock_gwc.return_value mock_client.wsman_get.side_effect = exception.AMTFailure('x') self.assertRaises(exception.AMTFailure, amt_power._power_status, self.node) self.assertTrue(mock_aw.called)
def wsman_invoke(self, options, resource_uri, method, data=None): """Invoke method on target server :param options: client options :param resource_uri: a URI to an XML schema :param method: invoke method :param data: a XmlDoc as invoke input :returns: XmlDoc object :raises: AMTFailure if get unexpected response. :raises: AMTConnectFailure if unable to connect to the server. """ if data is None: doc = self.client.invoke(options, resource_uri, method) else: doc = self.client.invoke(options, resource_uri, method, data) item = "ReturnValue" return_value = xml_find(doc, resource_uri, item).text if return_value != RET_SUCCESS: LOG.exception( _LE("Call to AMT with URI %(uri)s and " "method %(method)s failed: return value " "was %(value)s"), { 'uri': resource_uri, 'method': method, 'value': return_value }) raise exception.AMTFailure(cmd='wsman_invoke') return doc
def test__set_and_wait_exceed_iterations(self, mock_sps, mock_ps): target_state = states.POWER_ON mock_ps.side_effect = iter( [states.POWER_OFF, states.POWER_OFF, states.POWER_OFF]) mock_sps.return_value = exception.AMTFailure('x') with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: self.assertRaises(exception.PowerStateFailure, amt_power._set_and_wait, task, target_state) mock_sps.assert_called_with(task.node, states.POWER_ON) mock_ps.assert_called_with(task.node) self.assertEqual(3, mock_ps.call_count)
def wsman_get(self, resource_uri, options=None): """Get target server info :param options: client options :param resource_uri: a URI to an XML schema :returns: XmlDoc object :raises: AMTFailure if get unexpected response. :raises: AMTConnectFailure if unable to connect to the server. """ if options is None: options = pywsman.ClientOptions() doc = self.client.get(options, resource_uri) item = 'Fault' fault = xml_find(doc, _SOAP_ENVELOPE, item) if fault is not None: LOG.exception(_LE('Call to AMT with URI %(uri)s failed: ' 'got Fault %(fault)s'), {'uri': resource_uri, 'fault': fault.text}) raise exception.AMTFailure(cmd='wsman_get') return doc
def amtctrl(driver_info, command, special=''): """all interactions with the client object happen here. """ amt_client = Client(driver_info['address'], driver_info['password']) command_map = { 'on': amt_client.power_on_with_device(special), 'off': amt_client.power_off(), 'power_state': amt_client.power_status(), } try: response = command_map[command] except ConnectionError as e: # timeout (network is probably down) LOG.error(e) raise exception.AMTFailure(cmd=command) except KeyError: # command attempted that we don't have mapped raise NotImplementedError() else: return response