From 197f5cf9cbdd802721b529e06794d4720900e520 Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Tue, 24 Mar 2020 11:28:38 +0530 Subject: [PATCH] Remove CreateContinerAction usage This replaces the CreateContinerAction calls with tripleo-common api call. Change-Id: I58ad4b4b00b0889a16b2a211d8dbbd1a967f88ae --- .../overcloud_deploy/test_overcloud_deploy.py | 42 +++++++++++++++---- tripleoclient/tests/v1/test_overcloud_plan.py | 21 ++-------- .../tests/workflows/test_plan_management.py | 14 +------ tripleoclient/workflows/plan_management.py | 26 +----------- 4 files changed, 41 insertions(+), 62 deletions(-) diff --git a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py index e538fa606..76e5854bf 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py +++ b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py @@ -163,13 +163,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): horizon_url.return_value = 'fake://url:12345' self.addCleanup(horizon_url.stop) - self.create_action = mock.patch( - 'tripleo_common.actions.plan.CreateContainerAction.run', - autospec=True, - return_value=None - ) - self.create_action.start() - self.addCleanup(self.create_action.stop) + client.object_store.get_account = mock.MagicMock() def tearDown(self): super(TestDeployOvercloud, self).tearDown() @@ -224,6 +218,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'environments': []}) object_client.get_object.return_value = ({}, mock_env) @@ -276,6 +271,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_create_tempest_deployer_input.assert_called_with() mock_copy.assert_called_once() + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.utils.copy_clouds_yaml') @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' @@ -325,6 +322,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'environments': []}) object_client.get_object.return_value = ({}, mock_env) @@ -398,6 +396,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): self.assertEqual(env_map.get('parameter_defaults'), parameters_env.get('parameter_defaults')) mock_copy.assert_called_once() + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('os.chdir') @mock.patch('tripleoclient.utils.copy_clouds_yaml') @@ -464,6 +464,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'environments': []}) object_client.get_object.return_value = ({}, mock_env) @@ -538,6 +539,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): clients.tripleoclient.object_store.put_object.assert_called() self.assertTrue(mock_invoke_plan_env_wf.called) mock_copy.assert_called_once() + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('os.chdir') @mock.patch('tripleoclient.utils.copy_clouds_yaml') @@ -598,6 +601,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'environments': []}) object_client.get_object.return_value = ({}, mock_env) @@ -625,6 +629,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): self.cmd.take_action(parsed_args) mock_rm.assert_called_once() mock_copy.assert_called_once() + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.utils.copy_clouds_yaml') @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' @@ -680,6 +686,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'environments': []}) object_client.get_object.return_value = ({}, mock_env) @@ -697,6 +704,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_create_tempest_deployer_input.assert_called_with() mock_copy.assert_called_once() + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' '_deploy_tripleo_heat_templates', autospec=True) @@ -773,6 +782,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_deploy_heat.side_effect = _fake_heat_deploy object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'parameter_defaults': {'NovaComputeLibvirtType': 'qemu'}}) object_client.get_object.return_value = ({}, mock_env) @@ -780,6 +790,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) mock_copy.assert_called_once() + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.utils.check_stack_network_matches_env_files') @mock.patch('tripleoclient.utils.get_stack', autospec=True) @@ -834,9 +846,13 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): 'resource_registry': {'Test': u'OS::Heat::None'}}, env) mock_deploy_heat.side_effect = _fake_heat_deploy + object_client = clients.tripleoclient.object_store + object_client.put_container = mock.Mock() parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' '_deploy_postconfig', autospec=True) @@ -882,6 +898,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'parameter_defaults': {'NovaComputeLibvirtType': 'qemu'}}) object_client.get_object.return_value = ({}, mock_env) @@ -890,6 +907,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): error = self.assertRaises(hc_exc.CommandError, self.cmd.take_action, parsed_args) self.assertIn('tmp/doesnexit.yaml', str(error)) + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.workflows.plan_management.tarball', autospec=True) @@ -1087,6 +1106,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'parameter_defaults': {'NovaComputeLibvirtType': 'qemu'}}) object_client.get_object.return_value = ({}, mock_env) @@ -1109,6 +1129,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): utils_fixture.mock_deploy_tht.assert_called_with() mock_copy.assert_called_once() + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' '_get_undercloud_host_entry', autospec=True, @@ -1144,6 +1166,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'environments': []}) object_client.get_object.return_value = ({}, mock_env) @@ -1164,6 +1187,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): self.assertRaises(exceptions.InvalidConfiguration, self.cmd.take_action, parsed_args) + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.utils.copy_clouds_yaml') @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' @@ -1223,6 +1248,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): object_client = clients.tripleoclient.object_store object_client.get_object = mock.Mock() + object_client.put_container = mock.Mock() mock_env = yaml.safe_dump({'environments': []}) object_client.get_object.return_value = ({}, mock_env) @@ -1277,6 +1303,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_validate_args.assert_called_once_with(parsed_args) mock_copy.assert_called_once() + object_client.put_container.assert_called_once_with( + 'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'}) @mock.patch('tripleoclient.workflows.parameters.' 'check_deprecated_parameters', autospec=True) diff --git a/tripleoclient/tests/v1/test_overcloud_plan.py b/tripleoclient/tests/v1/test_overcloud_plan.py index 99c4db617..43d6f5685 100644 --- a/tripleoclient/tests/v1/test_overcloud_plan.py +++ b/tripleoclient/tests/v1/test_overcloud_plan.py @@ -98,27 +98,10 @@ class TestOvercloudCreatePlan(utils.TestCommand): self.cmd = overcloud_plan.CreatePlan(self.app, None) self.app.client_manager.workflow_engine = mock.Mock() self.tripleoclient = mock.Mock() - - self.websocket = mock.Mock() - self.websocket.__enter__ = lambda s: self.websocket - self.websocket.__exit__ = lambda s, *exc: None - self.tripleoclient = mock.Mock() - self.tripleoclient.messaging_websocket.return_value = self.websocket self.app.client_manager.tripleoclient = self.tripleoclient - self.workflow = self.app.client_manager.workflow_engine - execution = mock.Mock() - execution.id = "IDID" - self.workflow.executions.create.return_value = execution self.swift = self.app.client_manager.tripleoclient.object_store - - self.create_action = mock.patch( - 'tripleo_common.actions.plan.CreateContainerAction.run', - autospec=True, - return_value=None - ) - self.create_action.start() - self.addCleanup(self.create_action.stop) + self.swift.get_account = mock.MagicMock() @mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True) def test_create_default_plan(self, mock_run_playbook): @@ -175,6 +158,7 @@ class TestOvercloudCreatePlan(utils.TestCommand): }, verbosity=3, ) + self.swift.get_account.assert_called_once() @mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True) @mock.patch("tripleoclient.workflows.plan_management.tarball") @@ -211,6 +195,7 @@ class TestOvercloudCreatePlan(utils.TestCommand): }, verbosity=3, ) + self.swift.get_account.assert_called_once() @mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True) def test_create_default_plan_with_password_gen_disabled( diff --git a/tripleoclient/tests/workflows/test_plan_management.py b/tripleoclient/tests/workflows/test_plan_management.py index f99023a3d..bd70292af 100644 --- a/tripleoclient/tests/workflows/test_plan_management.py +++ b/tripleoclient/tests/workflows/test_plan_management.py @@ -27,19 +27,7 @@ class TestPlanCreationWorkflows(utils.TestCommand): super(TestPlanCreationWorkflows, self).setUp() self.tripleoclient = mock.Mock() self.app.client_manager.tripleoclient = self.tripleoclient - - self.message_success = iter([{ - "execution_id": "IDID", - "status": "SUCCESS", - }]) - - self.create_action = mock.patch( - 'tripleo_common.actions.plan.CreateContainerAction.run', - autospec=True, - return_value=None - ) - self.create_action.start() - self.addCleanup(self.create_action.stop) + self.tripleoclient.object_store.get_account = mock.MagicMock() @mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True) @mock.patch('tripleoclient.workflows.plan_management.tarball', diff --git a/tripleoclient/workflows/plan_management.py b/tripleoclient/workflows/plan_management.py index 4ffa5574a..3b689a70e 100644 --- a/tripleoclient/workflows/plan_management.py +++ b/tripleoclient/workflows/plan_management.py @@ -16,6 +16,7 @@ import yaml from swiftclient import exceptions as swift_exc from tripleo_common.actions import plan +from tripleo_common.utils import plan as plan_utils from tripleo_common.utils import swift as swiftutils from tripleo_common.utils import tarball @@ -122,36 +123,13 @@ def list_deployment_plans(clients): return plan.ListPlansAction().run(mistral_context) -def create_container(clients, container): - """Create a container. - - :param clients: openstack clients - :type clients: Object - - :param container: Name of the container to create - :type container: String - - :returns: Object - """ - - mistral_context = clients.tripleoclient.create_mistral_context() - return plan.CreateContainerAction( - container=container - ).run(context=mistral_context) - - def create_plan_from_templates(clients, name, tht_root, roles_file=None, generate_passwords=True, plan_env_file=None, networks_file=None, validate_stack=True): swift_client = clients.tripleoclient.object_store print("Creating Swift container to store the plan") - result = create_container(clients, container=name) - if result: - # create_container returns 'None' on success and a string with - # the error message when failing. - raise exceptions.PlanCreationError( - "Unable to create plan. {}".format(result)) + plan_utils.create_plan_container(swift_client, name) print("Creating plan from template files in: {}".format(tht_root)) _upload_templates(swift_client, name, tht_root,