Remove CreateContinerAction usage

This replaces the CreateContinerAction calls with tripleo-common
api call.

Change-Id: I58ad4b4b00b0889a16b2a211d8dbbd1a967f88ae
This commit is contained in:
Rabi Mishra 2020-03-24 11:28:38 +05:30
parent 50191cddf5
commit 197f5cf9cb
4 changed files with 41 additions and 62 deletions

View File

@ -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)

View File

@ -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(

View File

@ -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',

View File

@ -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,