diff --git a/tripleoclient/tests/v1/overcloud_node/fakes.py b/tripleoclient/tests/v1/overcloud_node/fakes.py index 21baff532..63bb4c272 100644 --- a/tripleoclient/tests/v1/overcloud_node/fakes.py +++ b/tripleoclient/tests/v1/overcloud_node/fakes.py @@ -13,6 +13,8 @@ # under the License. # +import mock + from tripleoclient.tests import fakes @@ -26,3 +28,10 @@ class TestOvercloudNode(fakes.FakePlaybookExecution): def setUp(self): super(TestOvercloudNode, self).setUp() + + self.mock_playbook = mock.patch( + 'tripleoclient.utils.run_ansible_playbook', + autospec=True + ) + self.mock_playbook.start() + self.addCleanup(self.mock_playbook.stop) diff --git a/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py b/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py index 55b0f5502..862f9d5cf 100644 --- a/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py +++ b/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py @@ -874,13 +874,6 @@ class TestDiscoverNode(fakes.TestOvercloudNode): self.http_boot = '/var/lib/ironic/httpboot' - self.mock_playbook = mock.patch( - 'tripleoclient.utils.run_ansible_playbook', - autospec=True - ) - self.mock_playbook.start() - self.addCleanup(self.mock_playbook.stop) - def test_with_ip_range(self): argslist = ['--range', '10.0.0.0/24', '--credentials', 'admin:password'] diff --git a/tripleoclient/tests/workflows/test_baremetal.py b/tripleoclient/tests/workflows/test_baremetal.py index d78a1ef01..478258157 100644 --- a/tripleoclient/tests/workflows/test_baremetal.py +++ b/tripleoclient/tests/workflows/test_baremetal.py @@ -141,61 +141,9 @@ class TestBaremetalWorkflows(fakes.FakePlaybookExecution): baremetal.configure_manageable_nodes(self.app.client_manager) def test_clean_nodes_success(self): - - self.websocket.wait_for_messages.return_value = self.message_success - baremetal.clean_nodes(self.app.client_manager, node_uuids=[]) - self.workflow.executions.create.assert_called_once_with( - 'tripleo.baremetal.v1.clean_nodes', - workflow_input={ - 'node_uuids': [], - }) - - def test_clean_nodes_error(self): - - self.websocket.wait_for_messages.return_value = self.message_failed - - self.assertRaises( - exceptions.NodeConfigurationError, - baremetal.clean_nodes, - self.app.client_manager, - node_uuids=[] - ) - - self.workflow.executions.create.assert_called_once_with( - 'tripleo.baremetal.v1.clean_nodes', - workflow_input={ - 'node_uuids': [], - }) - def test_clean_manageable_nodes_success(self): - - self.websocket.wait_for_messages.return_value = iter([{ - "execution_id": "IDID", - "status": "SUCCESS", - "cleaned_nodes": [], - }]) - baremetal.clean_manageable_nodes( self.app.client_manager ) - - self.workflow.executions.create.assert_called_once_with( - 'tripleo.baremetal.v1.clean_manageable_nodes', - workflow_input={} - ) - - def test_clean_manageable_nodes_error(self): - - self.websocket.wait_for_messages.return_value = self.message_failed - - self.assertRaises( - exceptions.NodeConfigurationError, - baremetal.clean_manageable_nodes, - self.app.client_manager) - - self.workflow.executions.create.assert_called_once_with( - 'tripleo.baremetal.v1.clean_manageable_nodes', - workflow_input={} - ) diff --git a/tripleoclient/workflows/baremetal.py b/tripleoclient/workflows/baremetal.py index accf734d7..97421693b 100644 --- a/tripleoclient/workflows/baremetal.py +++ b/tripleoclient/workflows/baremetal.py @@ -404,59 +404,44 @@ def discover_and_enroll(clients, ip_addresses, credentials, kernel_name, ) -def clean_nodes(clients, **workflow_input): +def clean_nodes(clients, node_uuids): """Clean Baremetal Nodes - Run the tripleo.baremetal.v1.clean_nodes Mistral workflow. + :param clients: application client object. + :type clients: Object + + :param node_uuids: List of instance UUID(s). + :type node_uuids: List """ - workflow_client = clients.workflow_engine - tripleoclients = clients.tripleoclient - - with tripleoclients.messaging_websocket() as ws: - execution = base.start_workflow( - workflow_client, - 'tripleo.baremetal.v1.clean_nodes', - workflow_input={'node_uuids': workflow_input['node_uuids']} + with utils.TempDirs() as tmp: + utils.run_ansible_playbook( + playbook='cli-baremetal-clean.yaml', + inventory='localhost,', + workdir=tmp, + playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS, + extra_vars={ + 'node_uuids': node_uuids + } ) - for payload in base.wait_for_messages(workflow_client, ws, execution): - if payload.get('message'): - print(payload['message']) - - if payload['status'] != 'SUCCESS': - message = _format_errors(payload) - raise exceptions.NodeConfigurationError( - 'Error(s) cleaning nodes:\n{}'.format(message)) - - print('Successfully cleaned nodes') + print('Successfully cleaned nodes: {}'.format(node_uuids)) -def clean_manageable_nodes(clients, **workflow_input): +def clean_manageable_nodes(clients): """Clean all manageable Nodes - Run the tripleo.baremetal.v1.clean_manageable_nodes Mistral workflow. + :param clients: application client object. + :type clients: Object """ - workflow_client = clients.workflow_engine - tripleoclients = clients.tripleoclient - - with tripleoclients.messaging_websocket() as ws: - execution = base.start_workflow( - workflow_client, - 'tripleo.baremetal.v1.clean_manageable_nodes', - workflow_input=workflow_input - ) - - for payload in base.wait_for_messages(workflow_client, ws, execution): - if payload.get('message'): - print(payload['message']) - - if payload['status'] != 'SUCCESS': - raise exceptions.NodeConfigurationError( - 'Error cleaning nodes: {}'.format(payload['message'])) - - print('Cleaned %d node(s)' % len(payload['cleaned_nodes'])) + clean_nodes( + clients=clients, + node_uuids=[ + i.uuid for i in clients.baremetal.node.list() + if i.provision_state == "manageable" and not i.maintenance + ] + ) def apply_bios_configuration(clients, node_uuids, configuration):