From 72cfa4f653204f54fa42244542ab256eb5d6e756 Mon Sep 17 00:00:00 2001 From: apetrich Date: Tue, 28 Jan 2020 14:13:22 +0100 Subject: [PATCH] Client code to do node import with ansible instead of mistral This moves the node import into ansible. Story: 2007126 Task: 38183 Change-Id: I7889228333dfc503529770d5cf06a35f39432f18 Signed-off-by: Kevin Carter --- tripleoclient/tests/fakes.py | 1 + .../v1/overcloud_node/test_overcloud_node.py | 21 +++++++++++++++---- tripleoclient/tests/v1/test_plugin.py | 1 - .../tests/v1/tripleo/test_tripleo_deploy.py | 2 -- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tripleoclient/tests/fakes.py b/tripleoclient/tests/fakes.py index a3dafe621..75ebd70c7 100644 --- a/tripleoclient/tests/fakes.py +++ b/tripleoclient/tests/fakes.py @@ -163,6 +163,7 @@ class FakePlaybookExecution(utils.TestCommand): def setUp(self, ansible_mock=True): super(FakePlaybookExecution, self).setUp() + self.app.options = FakeOptions() self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN") self.app.client_manager.baremetal = mock.Mock() compute = self.app.client_manager.compute = mock.Mock() diff --git a/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py b/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py index 8bd82e5a1..a5924950d 100644 --- a/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py +++ b/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py @@ -19,6 +19,7 @@ import fixtures import json import mock import os +import sys import tempfile from osc_lib import exceptions as oscexc @@ -75,8 +76,6 @@ class TestDeleteNode(fakes.TestDeleteNode): self.addCleanup(wait_stack.stop) self.app.client_manager.compute.servers.get.return_value = None - # TODO(someone): This test does not pass with autospec=True, it should - # probably be fixed so that it can pass with that. @mock.patch('tripleoclient.utils.run_ansible_playbook', autospec=True) def test_node_delete(self, mock_playbook): @@ -247,9 +246,11 @@ class TestDeleteNode(fakes.TestDeleteNode): ) ]) + @mock.patch('tripleoclient.utils.run_ansible_playbook', + autospec=True) @mock.patch('tripleoclient.workflows.baremetal.expand_roles', autospec=True) - def test_nodes_to_delete(self, mock_expand_roles): + def test_nodes_to_delete(self, mock_expand_roles, mock_playbook): bm_yaml = [{ 'name': 'Compute', 'count': 5, @@ -615,7 +616,19 @@ class TestImportNodeMultiArch(fakes.TestOvercloudNode): with mock.patch('tripleoclient.utils.run_ansible_playbook', autospec=True): - self.cmd.take_action(parsed_args) + file_return_nodes = [ + { + 'uuid': 'MOCK_NODE_UUID' + } + ] + mock_open = mock.mock_open(read_data=json.dumps(file_return_nodes)) + # TODO(cloudnull): Remove this when py27 is dropped + if sys.version_info >= (3, 0): + mock_open_path = 'builtins.open' + else: + mock_open_path = 'tripleoclient.v1.overcloud_node.open' + with mock.patch(mock_open_path, mock_open): + self.cmd.take_action(parsed_args) nodes_list = copy.deepcopy(self.nodes_list) if not no_deploy_image: diff --git a/tripleoclient/tests/v1/test_plugin.py b/tripleoclient/tests/v1/test_plugin.py index 3b07bef5f..d266bc6db 100644 --- a/tripleoclient/tests/v1/test_plugin.py +++ b/tripleoclient/tests/v1/test_plugin.py @@ -32,7 +32,6 @@ class FakePluginV1Client(object): class TestPluginV1(base.TestCommand): def setUp(self): super(TestPluginV1, self).setUp() - self.app.client_manager.tripleoclient = FakePluginV1Client( endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN, diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py index 1ae39ad02..f4c7cc33b 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py @@ -64,8 +64,6 @@ class TestDeployUndercloud(TestPluginV1): self.orc.stacks.create = mock.MagicMock( return_value={'stack': {'id': 'foo'}}) - self.ansible_playbook_cmd = "ansible-playbook" - @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy._is_undercloud_deploy') @mock.patch('tripleoclient.utils.check_hostname') def test_run_preflight_checks(self, mock_check_hostname, mock_uc):