Merge "Drop stack_update function"
This commit is contained in:
commit
f456b465c8
@ -25,93 +25,6 @@ from tripleo_common.tests import base
|
||||
from tripleo_common.utils import stack
|
||||
|
||||
|
||||
class UpdateStackTest(base.TestCase):
|
||||
|
||||
@mock.patch('tripleo_common.utils.template.process_templates')
|
||||
@mock.patch('heatclient.common.template_utils.get_template_contents')
|
||||
@mock.patch('tripleo_common.utils.plan.put_env')
|
||||
@mock.patch('tripleo_common.utils.plan.get_env')
|
||||
@mock.patch('tripleo_common.utils.plan.update_in_env')
|
||||
def test_stack_update(self, mock_updateinenv,
|
||||
mock_getenv,
|
||||
mock_putenv,
|
||||
mock_template_contents,
|
||||
mock_process_templates):
|
||||
heat = mock.MagicMock()
|
||||
heat.stacks.get.return_value = mock.MagicMock(
|
||||
stack_name='mycloud', id='stack_id')
|
||||
|
||||
mock_template_contents.return_value = ({}, {
|
||||
'heat_template_version': '2016-04-30'
|
||||
})
|
||||
mock_swift = mock.MagicMock()
|
||||
env = {
|
||||
'name': 'mycloud',
|
||||
'parameter_defaults': {
|
||||
'ControllerCount': 1,
|
||||
'ComputeCount': 1,
|
||||
'ObjectStorageCount': 0,
|
||||
'BlockStorageCount': 0,
|
||||
'CephStorageCount': 0,
|
||||
},
|
||||
'stack_name': 'mycloud',
|
||||
'stack_status': "CREATE_COMPLETE",
|
||||
'outputs': [
|
||||
{'output_key': 'RoleConfig',
|
||||
'output_value': {
|
||||
'foo_config': 'foo'}},
|
||||
{'output_key': 'RoleData',
|
||||
'output_value': {
|
||||
'FakeCompute': {
|
||||
'config_settings': {'nova::compute::fake'
|
||||
'libvirt_virt_type': 'qemu'},
|
||||
'global_config_settings': {},
|
||||
'logging_groups': ['root', 'neutron', 'nova'],
|
||||
'logging_sources': [{'path': '/var/log/fake.log',
|
||||
'type': 'tail'}],
|
||||
'monitoring_subscriptions': ['nova-compute'],
|
||||
'service_config_settings': None,
|
||||
'service_metadata_settings': None,
|
||||
'service_names': ['nova_compute', 'fake_service'],
|
||||
'step_config': ['include ::tripleo::profile::fake',
|
||||
'include ::timezone'],
|
||||
'upgrade_batch_tasks': [],
|
||||
'upgrade_tasks': [{'name': 'Stop fake service',
|
||||
'service': 'name=fo state=stopped',
|
||||
'tags': 'step1',
|
||||
'when': 'existingcondition'},
|
||||
{'name': 'Stop nova-compute',
|
||||
'service': 'name=nova-compute '
|
||||
'state=stopped',
|
||||
'tags': 'step1',
|
||||
'when': ['existing', 'list']}]
|
||||
}}}]}
|
||||
|
||||
mock_getenv.return_value = env
|
||||
mock_swift.get_object.return_value = ({}, env)
|
||||
|
||||
stack.stack_update(mock_swift, heat, 120)
|
||||
mock_putenv.assert_called_once_with(mock_swift, {
|
||||
'name': env['name'],
|
||||
'resource_registry': {
|
||||
'OS::TripleO::DeploymentSteps': 'OS::Heat::None',
|
||||
},
|
||||
'parameter_defaults': {
|
||||
'DeployIdentifier': mock.ANY,
|
||||
'ControllerCount': 1,
|
||||
'ComputeCount': 1,
|
||||
'ObjectStorageCount': 0,
|
||||
'BlockStorageCount': 0,
|
||||
'CephStorageCount': 0,
|
||||
},
|
||||
'stack_name': env['stack_name'],
|
||||
'stack_status': env['stack_status'],
|
||||
'outputs': env['outputs'],
|
||||
})
|
||||
|
||||
heat.stacks.update.assert_called_once_with('stack_id')
|
||||
|
||||
|
||||
class DeployStackTest(base.TestCase):
|
||||
|
||||
@mock.patch('tripleo_common.utils.stack.time')
|
||||
|
@ -19,7 +19,6 @@ import logging
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from heatclient.common import template_utils
|
||||
from heatclient import exc as heat_exc
|
||||
from swiftclient import exceptions as swiftexceptions
|
||||
|
||||
@ -31,68 +30,6 @@ from tripleo_common.utils import template as templates
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def stack_update(swift, heat, timeout,
|
||||
container=constants.DEFAULT_CONTAINER_NAME):
|
||||
# get the stack. Error if doesn't exist
|
||||
try:
|
||||
stack = heat.stacks.get(container)
|
||||
except heat_exc.HTTPNotFound:
|
||||
msg = "Error retrieving stack: %s" % container
|
||||
LOG.exception(msg)
|
||||
raise RuntimeError(msg)
|
||||
|
||||
try:
|
||||
env = plan_utils.get_env(swift, container)
|
||||
except swiftexceptions.ClientException as err:
|
||||
err_msg = ("Error retrieving environment for plan %s: %s" % (
|
||||
container, err))
|
||||
LOG.exception(err_msg)
|
||||
raise RuntimeError(err_msg)
|
||||
|
||||
update_env = {
|
||||
'parameter_defaults': {
|
||||
'DeployIdentifier': int(time.time()),
|
||||
},
|
||||
}
|
||||
|
||||
noop_env = {
|
||||
'resource_registry': {
|
||||
'OS::TripleO::DeploymentSteps': 'OS::Heat::None',
|
||||
},
|
||||
}
|
||||
|
||||
for output in stack.to_dict().get('outputs', {}):
|
||||
if output['output_key'] == 'RoleData':
|
||||
for role in output['output_value']:
|
||||
role_env = {
|
||||
"OS::TripleO::Tasks::%sPreConfig" % role:
|
||||
'OS::Heat::None',
|
||||
"OS::TripleO::Tasks::%sPostConfig" % role:
|
||||
'OS::Heat::None',
|
||||
}
|
||||
noop_env['resource_registry'].update(role_env)
|
||||
update_env.update(noop_env)
|
||||
template_utils.deep_update(env, update_env)
|
||||
try:
|
||||
plan_utils.put_env(swift, env)
|
||||
except swiftexceptions.ClientException as err:
|
||||
err_msg = ("Error updating environment for plan %s: %s" % (
|
||||
container, err))
|
||||
LOG.exception(err_msg)
|
||||
raise RuntimeError(err_msg)
|
||||
|
||||
# process all plan files and create or update a stack
|
||||
processed_data = templates.process_templates(
|
||||
swift, heat, container
|
||||
)
|
||||
stack_args = processed_data.copy()
|
||||
stack_args['timeout_mins'] = timeout
|
||||
|
||||
LOG.info("Performing Heat stack update")
|
||||
LOG.info('updating stack: %s', stack.stack_name)
|
||||
return heat.stacks.update(stack.id, **stack_args)
|
||||
|
||||
|
||||
def _process_params(flattened, params):
|
||||
for item in params:
|
||||
if item not in flattened['parameters']:
|
||||
|
Loading…
Reference in New Issue
Block a user