Browse Source

Use {{role.name}}Services parameters

This would ensure that we don't build service chains for
not enabled roles and cip would not try to pull images
for services mapped to OS::Heat::None.

Depends-On: https://review.opendev.org/c/openstack/tripleo-common/+/797173
Change-Id: I8f2f7700d0dd5a6c7459c8bc69d7937d72d23687
changes/74/797174/1
ramishra 1 year ago
parent
commit
e895c32635
  1. 96
      tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py
  2. 24
      tripleoclient/utils.py
  3. 2
      tripleoclient/v1/overcloud_deploy.py
  4. 33
      tripleoclient/v1/tripleo_deploy.py

96
tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py

@ -316,6 +316,8 @@ class TestDeployUndercloud(TestPluginV1):
mock.ANY,
default_flow_style=False)
@mock.patch('tripleoclient.utils.fetch_roles_file',
return_value={}, autospec=True)
@mock.patch('heatclient.common.template_utils.'
'process_environment_and_files', return_value=({}, {}),
autospec=True)
@ -336,7 +338,8 @@ class TestDeployUndercloud(TestPluginV1):
mock_hc_templ_parse,
mock_hc_env_parse,
mock_hc_get_templ_cont,
mock_hc_process):
mock_hc_process,
mock_role_data):
with tempfile.NamedTemporaryFile(delete=False) as roles_file:
self.addCleanup(os.unlink, roles_file.name)
@ -371,6 +374,8 @@ class TestDeployUndercloud(TestPluginV1):
mock.call(env_path='../outside.yaml',
include_env_in_files=False)])
@mock.patch('tripleoclient.utils.fetch_roles_file',
return_value={}, autospec=True)
@mock.patch('tripleoclient.utils.rel_or_abs_path')
@mock.patch('heatclient.common.template_utils.'
'process_environment_and_files', return_value=({}, {}),
@ -400,7 +405,8 @@ class TestDeployUndercloud(TestPluginV1):
mock_hc_env_parse,
mock_hc_get_templ_cont,
mock_hc_process,
mock_norm_path):
mock_norm_path,
mock_roles_data):
def hc_process(*args, **kwargs):
if 'abs.yaml' in kwargs['env_path']:
raise hc_exc.CommandError
@ -444,92 +450,6 @@ class TestDeployUndercloud(TestPluginV1):
mock_yaml_dump.assert_has_calls([mock.call(rewritten_env,
default_flow_style=False)])
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_populate_templates_dir')
@mock.patch('tripleoclient.utils.fetch_roles_file')
@mock.patch('tripleoclient.utils.rel_or_abs_path')
@mock.patch('heatclient.common.template_utils.'
'process_environment_and_files', return_value=({}, {}),
autospec=True)
@mock.patch('heatclient.common.template_utils.'
'get_template_contents', return_value=({}, {}),
autospec=True)
@mock.patch('heatclient.common.environment_format.'
'parse', autospec=True, return_value=dict())
@mock.patch('heatclient.common.template_format.'
'parse', autospec=True, return_value=dict())
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_setup_heat_environments', autospec=True)
@mock.patch('yaml.safe_dump', autospec=True)
@mock.patch('yaml.safe_load', autospec=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('tempfile.NamedTemporaryFile', autospec=True)
@mock.patch('tripleo_common.image.kolla_builder.'
'container_images_prepare_multi')
def test_deploy_tripleo_heat_templates_remove(self,
mock_cipm,
mock_temp, mock_open,
mock_yaml_load,
mock_yaml_dump,
mock_setup_heat_envs,
mock_hc_templ_parse,
mock_hc_env_parse,
mock_hc_get_templ_cont,
mock_hc_process,
mock_norm_path,
mock_fetch_roles,
mock_populate):
def hc_process(*args, **kwargs):
if 'myenv.yaml' in kwargs['env_path']:
env = {
'resource_registry': {
'OS::TripleO::Services::Foo': 'OS::Heat::None'}}
return ({}, env)
else:
return ({}, {})
mock_fetch_roles.return_value = [
{'name': 'Bar', 'ServicesDefault': [
'OS::TripleO::Services::Foo', 'OS::TripleO::Services::Bar']},
{'name': 'Foo', 'tags': ['primary']}
]
def set_tht(templates, stack_name):
self.cmd.tht_render = "tht_from"
mock_populate.side_effect = set_tht
mock_cipm.return_value = {}
mock_hc_process.side_effect = hc_process
parsed_args = self.check_parser(self.cmd,
['--templates', '/tmp/thtroot'], [])
rewritten_role = [
{'name': 'Bar', 'ServicesDefault': ['OS::TripleO::Services::Bar']},
{'name': 'Foo', 'tags': ['primary']}
]
myenv = {'resource_registry': {
'OS::Foo::Bar': '../outside.yaml',
'OS::Foo::Baz': './inside.yaml',
'OS::Foo::Qux': '/tmp/thtroot/abs.yaml',
'OS::Foo::Quux': '/tmp/thtroot42/notouch.yaml',
'OS::Foo::Corge': '/tmp/thtroot/puppet/foo.yaml'
}
}
mock_yaml_load.return_value = myenv
mock_setup_heat_envs.return_value = [
'./inside.yaml', '/tmp/thtroot/abs.yaml',
'/tmp/thtroot/puppet/foo.yaml',
'/tmp/thtroot/environments/myenv.yaml',
'../outside.yaml']
self.cmd._deploy_tripleo_heat_templates(self.orc, parsed_args)
mock_yaml_dump.assert_has_calls([mock.call(rewritten_role)])
@mock.patch('shutil.copy')
@mock.patch('os.path.exists', return_value=False)
def test_normalize_user_templates(self, mock_exists, mock_copy):

24
tripleoclient/utils.py

@ -2750,11 +2750,9 @@ def get_undercloud_host_entry():
return cleanup_host_entry(out)
def build_image_params(env_files, parsed_args, new_tht_root, user_tht_root):
image_params = plan_utils.default_image_params()
if parsed_args.disable_container_prepare:
return image_params
def build_enabled_sevices_image_params(env_files, parsed_args,
new_tht_root, user_tht_root):
params = {}
if parsed_args.environment_directories:
env_files.extend(load_environment_directories(
parsed_args.environment_directories))
@ -2765,13 +2763,21 @@ def build_image_params(env_files, parsed_args, new_tht_root, user_tht_root):
env_files, new_tht_root, user_tht_root,
cleanup=(not parsed_args.no_cleanup))
image_params.update(
roles_data = roles.get_roles_data(
parsed_args.roles_file, new_tht_root)
params.update(kolla_builder.get_enabled_services(env, roles_data))
params.update(plan_utils.default_image_params())
if parsed_args.disable_container_prepare:
return params
params.update(
kolla_builder.container_images_prepare_multi(
env, roles.get_roles_data(parsed_args.roles_file, new_tht_root),
env, roles_data,
dry_run=True)
)
return image_params
return params
def copy_env_files(files_dict, tht_root):

2
tripleoclient/v1/overcloud_deploy.py

@ -248,7 +248,7 @@ class DeployOvercloud(command.Command):
created_env_files.append(
os.path.join(new_tht_root, constants.DEFAULT_RESOURCE_REGISTRY))
parameters = utils.build_image_params(
parameters = utils.build_enabled_sevices_image_params(
created_env_files, parsed_args, new_tht_root, user_tht_root)
self._update_parameters(

33
tripleoclient/v1/tripleo_deploy.py

@ -745,33 +745,12 @@ class Deploy(command.Command):
roles_data = utils.fetch_roles_file(
roles_file_path, parsed_args.templates)
to_remove = set()
for key, value in env.get('resource_registry', {}).items():
if (key.startswith('OS::TripleO::Services::') and
value == 'OS::Heat::None'):
to_remove.add(key)
if to_remove:
for role in roles_data:
for service in to_remove:
try:
role.get('ServicesDefault', []).remove(service)
except ValueError:
pass
self.log.info('Removing unused services, updating roles')
# This will clean up the directory and set it up again
self.tht_render = None
self._populate_templates_dir(parsed_args.templates,
parsed_args.stack.lower())
roles_file_path = os.path.join(
self.tht_render, 'roles-data-override.yaml')
with open(roles_file_path, "w") as f:
f.write(yaml.safe_dump(roles_data))
# Redo the dance
environments = self._setup_heat_environments(
roles_file_path, networks_file_path, parsed_args)
env_files, env = utils.process_multiple_environments(
environments, self.tht_render, parsed_args.templates,
cleanup=parsed_args.cleanup)
parameter_defaults = env.get('parameter_defaults', {})
enabled_service_map = kolla_builder.get_enabled_services(
env, roles_data)
if enabled_service_map:
parameter_defaults.update(enabled_service_map)
if not parsed_args.disable_container_prepare:
self._prepare_container_images(env, roles_data)

Loading…
Cancel
Save