diff --git a/releasenotes/notes/add-networks-data-support-to-standalone-c06e29b44f44b6d5.yaml b/releasenotes/notes/add-networks-data-support-to-standalone-c06e29b44f44b6d5.yaml new file mode 100644 index 000000000..791fc9d94 --- /dev/null +++ b/releasenotes/notes/add-networks-data-support-to-standalone-c06e29b44f44b6d5.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Standalone deployment now support for custom networks data + (``network_data.yaml``). By default Standalone deploys with no networks + data (all services on the ctlplane network). The new option + ``networks_file`` can be used to provide custom networks data. diff --git a/tripleoclient/config/standalone.py b/tripleoclient/config/standalone.py index ad0701e1a..e17fa51b3 100644 --- a/tripleoclient/config/standalone.py +++ b/tripleoclient/config/standalone.py @@ -155,6 +155,12 @@ class StandaloneConfig(BaseConfig): 'absolute path or the path relative to the ' 't-h-t templates directory used for deployment') ), + cfg.StrOpt('networks_file', + default=None, + help=_('Networks file to override for heat. May be an ' + 'absolute path or the path relative to the ' + 't-h-t templates directory used for deployment') + ), cfg.BoolOpt('heat_native', default=True, help=_('Execute the heat-all process natively on this ' diff --git a/tripleoclient/constants.py b/tripleoclient/constants.py index 46b24d8ea..cf6a0bfbf 100644 --- a/tripleoclient/constants.py +++ b/tripleoclient/constants.py @@ -24,6 +24,8 @@ STANDALONE_EPHEMERAL_STACK_VSTATE = '/var/lib/tripleo-heat-installer' UNDERCLOUD_LOG_FILE = "install-undercloud.log" UNDERCLOUD_CONF_PATH = os.path.join(UNDERCLOUD_OUTPUT_DIR, "undercloud.conf") OVERCLOUD_NETWORKS_FILE = "network_data.yaml" +STANDALONE_NETWORKS_FILE = "/dev/null" +UNDERCLOUD_NETWORKS_FILE = "network_data_undercloud.yaml" RHEL_REGISTRATION_EXTRACONFIG_NAME = ( "extraconfig/pre_deploy/rhel-registration/") diff --git a/tripleoclient/tests/config/test_config_standalone.py b/tripleoclient/tests/config/test_config_standalone.py index 5f7cdde7d..3a978b2cd 100644 --- a/tripleoclient/tests/config/test_config_standalone.py +++ b/tripleoclient/tests/config/test_config_standalone.py @@ -36,6 +36,7 @@ class TestStandaloneConfig(base.TestCase): 'heat_native', 'hieradata_override', 'net_config_override', + 'networks_file', 'output_dir', 'roles_file', 'templates'] @@ -105,6 +106,7 @@ class TestStandaloneConfig(base.TestCase): 'heat_native', 'hieradata_override', 'net_config_override', + 'networks_file', 'output_dir', 'roles_file', 'templates'] diff --git a/tripleoclient/tests/config/test_config_undercloud.py b/tripleoclient/tests/config/test_config_undercloud.py index cf293ad33..fdc0fc509 100644 --- a/tripleoclient/tests/config/test_config_undercloud.py +++ b/tripleoclient/tests/config/test_config_undercloud.py @@ -55,6 +55,7 @@ class TestUndercloudConfig(base.TestCase): 'local_mtu', 'local_subnet', 'net_config_override', + 'networks_file', 'output_dir', 'overcloud_domain_name', 'roles_file', @@ -118,6 +119,7 @@ class TestUndercloudConfig(base.TestCase): 'local_mtu', 'local_subnet', 'net_config_override', + 'networks_file', 'output_dir', 'overcloud_domain_name', 'roles_file', diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py index 7f2732e3b..fa5774f7d 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py @@ -91,6 +91,29 @@ class TestDeployUndercloud(TestPluginV1): self.assertEqual(roles_file, '/tmp/thtroot/roles_data_undercloud.yaml') + def test_get_networks_file_path(self): + parsed_args = self.check_parser(self.cmd, + ['--local-ip', '127.0.0.1/8'], []) + + networks_file = self.cmd._get_networks_file_path(parsed_args) + self.assertEqual('/dev/null', networks_file) + + def test_get_networks_file_path_custom_file(self): + parsed_args = self.check_parser(self.cmd, + ['--local-ip', '127.0.0.1/8', + '--networks-file', 'foobar.yaml'], []) + + networks_file = self.cmd._get_networks_file_path(parsed_args) + self.assertEqual('foobar.yaml', networks_file) + + def test_get_networks_file_path_custom_templates(self): + parsed_args = self.check_parser(self.cmd, + ['--local-ip', '127.0.0.1/8', + '--templates', '/tmp/thtroot'], []) + + networks_file = self.cmd._get_networks_file_path(parsed_args) + self.assertEqual('/dev/null', networks_file) + def test_get_plan_env_file_path(self): parsed_args = self.check_parser(self.cmd, ['--local-ip', '127.0.0.1/8'], []) @@ -575,8 +598,8 @@ class TestDeployUndercloud(TestPluginV1): self.cmd.output_dir = 'tht_to' self.cmd.tht_render = 'tht_from' self.cmd.stack_action = 'UPDATE' - environment = self.cmd._setup_heat_environments(parsed_args.roles_file, - parsed_args) + environment = self.cmd._setup_heat_environments( + parsed_args.roles_file, parsed_args.networks_file, parsed_args) self.assertIn(dropin, environment) mock_open.assert_has_calls([mock.call(dropin, 'w')]) @@ -746,7 +769,8 @@ class TestDeployUndercloud(TestPluginV1): with mock.patch('os.path.abspath', side_effect=abs_path_stub): with mock.patch('os.path.isfile'): environment = self.cmd._setup_heat_environments( - parsed_args.roles_file, parsed_args) + parsed_args.roles_file, parsed_args.networks_file, + parsed_args) self.assertEqual(expected_env, environment) diff --git a/tripleoclient/tests/v1/undercloud/test_install_upgrade.py b/tripleoclient/tests/v1/undercloud/test_install_upgrade.py index d6d363410..bcc99f1a3 100644 --- a/tripleoclient/tests/v1/undercloud/test_install_upgrade.py +++ b/tripleoclient/tests/v1/undercloud/test_install_upgrade.py @@ -75,6 +75,7 @@ class TestUndercloudInstall(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--heat-native', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'undercloud.yaml', '-e', @@ -146,6 +147,7 @@ class TestUndercloudInstall(TestPluginV1): '--local-ip=192.168.24.1/24', '--templates=/usertht', '--roles-file=foo/roles.yaml', + '--networks-file=network_data_undercloud.yaml', '--heat-native=False', '-e', '/usertht/environments/undercloud.yaml', '-e', '/usertht/environments/use-dns-for-vips.yaml', '-e', @@ -298,6 +300,7 @@ class TestUndercloudInstall(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--heat-native', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'undercloud.yaml', '-e', @@ -369,6 +372,7 @@ class TestUndercloudInstall(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--heat-native', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'undercloud.yaml', '-e', @@ -433,6 +437,7 @@ class TestUndercloudInstall(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--heat-native', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'undercloud.yaml', '-e', @@ -494,6 +499,7 @@ class TestUndercloudInstall(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--heat-native', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'undercloud.yaml', '-e', @@ -574,6 +580,7 @@ class TestUndercloudUpgrade(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--upgrade', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'lifecycle/undercloud-upgrade-prepare.yaml', @@ -638,6 +645,7 @@ class TestUndercloudUpgrade(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--upgrade', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'lifecycle/undercloud-upgrade-prepare.yaml', @@ -701,6 +709,7 @@ class TestUndercloudUpgrade(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--upgrade', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'lifecycle/undercloud-upgrade-prepare.yaml', @@ -764,6 +773,7 @@ class TestUndercloudUpgrade(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '-y', '--upgrade', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'lifecycle/undercloud-upgrade-prepare.yaml', @@ -831,6 +841,7 @@ class TestUndercloudUpgrade(TestPluginV1): 'undercloud', '--local-domain=localdomain', '--local-ip=192.168.24.1/24', '--templates=/usr/share/openstack-tripleo-heat-templates/', + '--networks-file=network_data_undercloud.yaml', '--upgrade', '-e', '/usr/share/openstack-tripleo-heat-templates/environments/' 'lifecycle/undercloud-upgrade-prepare.yaml', diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py index 93925b571..1f508fbd9 100644 --- a/tripleoclient/v1/tripleo_deploy.py +++ b/tripleoclient/v1/tripleo_deploy.py @@ -162,6 +162,14 @@ class Deploy(command.Command): roles_file = parsed_args.roles_file return roles_file + def _get_networks_file_path(self, parsed_args): + """Return networks_file for the deployment""" + if not parsed_args.networks_file: + return os.path.join(parsed_args.templates, + constants.STANDALONE_NETWORKS_FILE) + else: + return parsed_args.networks_file + def _get_plan_env_file_path(self, parsed_args): """Return plan_environment_file for the deployment""" if not parsed_args.plan_environment_file: @@ -582,7 +590,8 @@ class Deploy(command.Command): environments.append(target_dest) return environments - def _setup_heat_environments(self, roles_file_path, parsed_args): + def _setup_heat_environments(self, roles_file_path, networks_file_path, + parsed_args): """Process tripleo heat templates with jinja and deploy into work dir * Process j2/install additional templates there @@ -611,7 +620,8 @@ class Deploy(command.Command): process_templates = os.path.join(parsed_args.templates, 'tools/process-templates.py') args = [self.python_cmd, process_templates, '--roles-data', - roles_file_path, '--output-dir', self.tht_render] + roles_file_path, '--network-data', networks_file_path, + '--output-dir', self.tht_render] if utils.run_command_and_log(self.log, args, cwd=self.tht_render) != 0: # TODO(aschultz): improve error messaging msg = _("Problems generating templates.") @@ -718,10 +728,11 @@ class Deploy(command.Command): parsed_args): """Deploy the fixed templates in TripleO Heat Templates""" roles_file_path = self._get_roles_file_path(parsed_args) + networks_file_path = self._get_networks_file_path(parsed_args) # sets self.tht_render to the working dir with deployed templates environments = self._setup_heat_environments( - roles_file_path, parsed_args) + roles_file_path, networks_file_path, parsed_args) # rewrite paths to consume t-h-t env files from the working dir self.log.debug(_("Processing environment files %s") % environments) @@ -753,7 +764,7 @@ class Deploy(command.Command): f.write(yaml.safe_dump(roles_data)) # Redo the dance environments = self._setup_heat_environments( - roles_file_path, parsed_args) + 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) @@ -920,6 +931,14 @@ class Deploy(command.Command): 'absolute path or the path relative to the templates dir.' ) % constants.UNDERCLOUD_ROLES_FILE ) + parser.add_argument( + '--networks-file', '-n', dest='networks_file', + help=_( + 'Roles file, overrides the default %s in the t-h-t templates ' + 'directory used for deployment. May be an ' + 'absolute path or the path relative to the templates dir.' + ) % constants.STANDALONE_NETWORKS_FILE + ) parser.add_argument( '--plan-environment-file', '-p', help=_('Plan Environment file, overrides the default %s in the ' diff --git a/tripleoclient/v1/undercloud_config.py b/tripleoclient/v1/undercloud_config.py index 0f38a79ed..9fa9c5295 100644 --- a/tripleoclient/v1/undercloud_config.py +++ b/tripleoclient/v1/undercloud_config.py @@ -441,6 +441,12 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=False, if CONF.get('roles_file', constants.UNDERCLOUD_ROLES_FILE): deploy_args.append('--roles-file=%s' % CONF['roles_file']) + if CONF.get('networks_file'): + deploy_args.append('--networks-file=%s' % CONF['networks_file']) + else: + deploy_args.append('--networks-file=%s' % + constants.UNDERCLOUD_NETWORKS_FILE) + if yes: deploy_args += ['-y']