From 3f76cf32c1bfd319f98d8c11f8fbab7b91e24ff8 Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Wed, 25 Apr 2018 10:40:44 +0200 Subject: [PATCH] Store UC hosts/portmaps heat params in output_dir Fix hosts/portmaps params used with undercloud heat installer are generated in output_dir/ instead of /tmp, and given a fixed name. Add this file into a tarball containing produced deployment configuration artifacts. Change-Id: I213d98a69945d98c3618d368613bf7f9908da642 Signed-off-by: Bogdan Dobrelya --- .../tests/v1/tripleo/test_tripleo_deploy.py | 7 ++- tripleoclient/v1/tripleo_deploy.py | 56 ++++++++----------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py index 67fdc1518..d6635679d 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py @@ -50,7 +50,6 @@ class TestDeployUndercloud(TestPluginV1): tripleo_deploy.Deploy.heat_pid = mock.MagicMock( return_value=False) tripleo_deploy.Deploy.tht_render = '/twd/templates' - tripleo_deploy.Deploy.tmp_env_file_name = 'tmp/foo' tripleo_deploy.Deploy.heat_launch = mock.MagicMock( side_effect=(lambda *x, **y: None)) @@ -326,8 +325,9 @@ class TestDeployUndercloud(TestPluginV1): '_update_passwords_env', autospec=True) @mock.patch('tripleoclient.utils.' 'run_command_and_log', autospec=True) + @mock.patch('six.moves.builtins.open') @mock.patch('shutil.copy', autospec=True) - def test_setup_heat_environments(self, mock_cp, + def test_setup_heat_environments(self, mock_cp, mock_open, mock_run, mock_update_pass_env, mock_process_hiera, @@ -373,7 +373,8 @@ class TestDeployUndercloud(TestPluginV1): '~/custom.yaml', 'something.yaml', '../../../outside.yaml', - mock.ANY, 'foo.yaml'] + '/my/tripleo-heat-installer-templates/' + 'tripleoclient-hosts-portmaps.yaml', 'foo.yaml'] environment = self.cmd._setup_heat_environments(parsed_args) diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py index 84e7a2055..669ff1e8a 100644 --- a/tripleoclient/v1/tripleo_deploy.py +++ b/tripleoclient/v1/tripleo_deploy.py @@ -81,7 +81,6 @@ class Deploy(command.Command): heat_pid = None tht_render = None output_dir = None - tmp_env_file_name = None tmp_ansible_dir = None roles_file = None roles_data = None @@ -153,8 +152,6 @@ class Deploy(command.Command): try: tf = tarfile.open(tar_filename, 'w:bz2') tf.add(self.tht_render, recursive=True, filter=remove_output_dir) - if self.tmp_env_file_name: - tf.add(self.tmp_env_file_name, filter=remove_output_dir) tf.add(self.tmp_ansible_dir, recursive=True, filter=remove_output_dir) tf.close() @@ -207,21 +204,12 @@ class Deploy(command.Command): shutil.rmtree(self.tht_render, ignore_errors=True) self.tht_render = None - if self.tmp_env_file_name: - try: - os.remove(self.tmp_env_file_name) - self.tmp_env_file_name = None - except Exception as ex: - if 'No such file or directory' in six.text_type(ex): - pass if self.tmp_ansible_dir and os.path.exists(self.tmp_ansible_dir): shutil.rmtree(self.tmp_ansible_dir) self.tmp_ansible_dir = None else: self.log.warning(_("Not cleaning working directory %s") % self.tht_render) - self.log.warning(_("Not removing temporary environment file %s") - % self.tmp_env_file_name) self.log.warning(_("Not cleaning ansible directory %s") % self.tmp_ansible_dir) @@ -476,32 +464,32 @@ class Deploy(command.Command): if parsed_args.environment_files: environments.extend(parsed_args.environment_files) - with tempfile.NamedTemporaryFile(delete=False) as tmp_env_file: - self.tmp_env_file_name = tmp_env_file.name + maps_file = os.path.join(self.tht_render, + 'tripleoclient-hosts-portmaps.yaml') + ip_nw = netaddr.IPNetwork(parsed_args.local_ip) + ip = str(ip_nw.ip) + cidr_prefixlen = ip_nw.prefixlen - ip_nw = netaddr.IPNetwork(parsed_args.local_ip) - ip = str(ip_nw.ip) - cidr_prefixlen = ip_nw.prefixlen + if parsed_args.control_virtual_ip: + c_ip = parsed_args.control_virtual_ip + else: + c_ip = ip - if parsed_args.control_virtual_ip: - c_ip = parsed_args.control_virtual_ip - else: - c_ip = ip + if parsed_args.public_virtual_ip: + p_ip = parsed_args.public_virtual_ip + else: + p_ip = ip - if parsed_args.public_virtual_ip: - p_ip = parsed_args.public_virtual_ip - else: - p_ip = ip + tmp_env = self._generate_hosts_parameters(parsed_args, p_ip) + tmp_env.update(self._generate_portmap_parameters( + ip, cidr_prefixlen, c_ip, p_ip, + stack_name=parsed_args.stack, + role_name=self._get_primary_role_name())) - tmp_env = self._generate_hosts_parameters(parsed_args, p_ip) - tmp_env.update(self._generate_portmap_parameters( - ip, cidr_prefixlen, c_ip, p_ip, stack_name=parsed_args.stack, - role_name=self._get_primary_role_name())) - - with open(self.tmp_env_file_name, 'w') as env_file: - yaml.safe_dump({'parameter_defaults': tmp_env}, env_file, - default_flow_style=False) - environments.append(self.tmp_env_file_name) + with open(maps_file, 'w') as env_file: + yaml.safe_dump({'parameter_defaults': tmp_env}, env_file, + default_flow_style=False) + environments.append(maps_file) if parsed_args.hieradata_override: environments.append(self._process_hieradata_overrides(