def agent_get_clean_steps(task): """Get the list of clean steps from the agent. #TODO(JoshNang) move to BootInterface :param task: a TaskManager object containing the node :raises: NodeCleaningFailure if the agent returns invalid results :returns: A list of clean step dictionaries """ client = agent_client.AgentClient() ports = objects.Port.list_by_node_id( task.context, task.node.id) result = client.get_clean_steps(task.node, ports).get('command_result') if ('clean_steps' not in result or 'hardware_manager_version' not in result): raise exception.NodeCleaningFailure(_( 'get_clean_steps for node %(node)s returned invalid result:' ' %(result)s') % ({'node': task.node.uuid, 'result': result})) driver_internal_info = task.node.driver_internal_info driver_internal_info['hardware_manager_version'] = result[ 'hardware_manager_version'] task.node.driver_internal_info = driver_internal_info task.node.save() # Clean steps looks like {'HardwareManager': [{step1},{steps2}..]..} # Flatten clean steps into one list steps_list = [step for step_list in result['clean_steps'].values() for step in step_list] # Filter steps to only return deploy steps steps = [step for step in steps_list if step.get('interface') == 'deploy'] return steps
def __init__(self): super(AgentPower, self).__init__() if not CONF.deploy.fast_track: raise exception.InvalidParameterValue( _('[deploy]fast_track must be True to enable the agent ' 'power interface')) self._client = agent_client.AgentClient()
def collect_ramdisk_logs(node): """Collect and store the system logs from the IPA ramdisk. Collect and store the system logs from the IPA ramdisk. This method makes a call to the IPA ramdisk to collect the logs and store it according to the configured storage backend. :param node: A node object. """ client = agent_client.AgentClient() try: result = client.collect_system_logs(node) except exception.IronicException as e: LOG.error( 'Failed to invoke collect_system_logs agent command ' 'for node %(node)s. Error: %(error)s', { 'node': node.uuid, 'error': e }) return error = result.get('faultstring') if error is not None: LOG.error( 'Failed to collect logs from the node %(node)s ' 'deployment. Error: %(error)s', { 'node': node.uuid, 'error': error }) return try: store_ramdisk_logs(node, result['command_result']['system_logs']) except exception.SwiftOperationError as e: LOG.error( 'Failed to store the logs from the node %(node)s ' 'deployment in Swift. Error: %(error)s', { 'node': node.uuid, 'error': e }) except EnvironmentError as e: LOG.exception( 'Failed to store the logs from the node %(node)s ' 'deployment due a file-system related error. ' 'Error: %(error)s', { 'node': node.uuid, 'error': e }) except Exception as e: LOG.exception( 'Unknown error when storing logs from the node ' '%(node)s deployment. Error: %(error)s', { 'node': node.uuid, 'error': e })
def agent_get_clean_steps(task, interface=None, override_priorities=None): """Get the list of clean steps from the agent. #TODO(JoshNang) move to BootInterface :param task: a TaskManager object containing the node :param interface: The interface for which clean steps are to be returned. If this is not provided, it returns the clean steps for all interfaces. :param override_priorities: a dictionary with keys being step names and values being new priorities for them. If a step isn't in this dictionary, the step's original priority is used. :raises: NodeCleaningFailure if the agent returns invalid results :returns: A list of clean step dictionaries """ override_priorities = override_priorities or {} client = agent_client.AgentClient() ports = objects.Port.list_by_node_id(task.context, task.node.id) result = client.get_clean_steps(task.node, ports).get('command_result') if ('clean_steps' not in result or 'hardware_manager_version' not in result): raise exception.NodeCleaningFailure( _('get_clean_steps for node %(node)s returned invalid result:' ' %(result)s') % ({ 'node': task.node.uuid, 'result': result })) driver_internal_info = task.node.driver_internal_info driver_internal_info['hardware_manager_version'] = result[ 'hardware_manager_version'] task.node.driver_internal_info = driver_internal_info task.node.save() # Clean steps looks like {'HardwareManager': [{step1},{steps2}..]..} # Flatten clean steps into one list steps_list = [ step for step_list in result['clean_steps'].values() for step in step_list ] result = [] for step in steps_list: if interface and step.get('interface') != interface: continue new_priority = override_priorities.get(step.get('step')) if new_priority is not None: step['priority'] = new_priority result.append(step) return result
def agent_execute_clean_step(task, step): """Execute a clean step asynchronously on the agent. #TODO(JoshNang) move to BootInterface :param task: a TaskManager object containing the node :param step: a clean step dictionary to execute :raises: NodeCleaningFailure if the agent does not return a command status :returns: states.CLEANWAIT to signify the step will be completed async """ client = agent_client.AgentClient() ports = objects.Port.list_by_node_id( task.context, task.node.id) result = client.execute_clean_step(step, task.node, ports) if not result.get('command_status'): raise exception.NodeCleaningFailure(_( 'Agent on node %(node)s returned bad command result: ' '%(result)s') % {'node': task.node.uuid, 'result': result.get('command_error')}) return states.CLEANWAIT
def _get_client(): client = agent_client.AgentClient() return client
def test_content_type_header(self): client = agent_client.AgentClient() self.assertEqual('application/json', client.session.headers['Content-Type'])
def setUp(self): super(TestAgentClient, self).setUp() self.client = agent_client.AgentClient() self.client.session = mock.MagicMock(autospec=requests.Session) self.node = MockNode()