Browse Source

overcloud deploy - provision networks

When the network file provided as input to the overcloud
deploy command is a network-v2 format file. Provision
networks and include the deployed network environment
file in user environments.

Change-Id: I20da47f8dfbf48f6ee46e60a07c00482545cb444
changes/83/793383/9
Harald Jensås 2 months ago
parent
commit
2b2e52c882
  1. 58
      tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py
  2. 43
      tripleoclient/v1/overcloud_deploy.py

58
tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py

@ -111,6 +111,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
os.unlink(self.parameter_defaults_env_file)
shutil.rmtree = self.real_shutil
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_provision_networks', autospec=True)
@mock.patch('tripleoclient.utils.check_service_vips_migrated_to_service')
@mock.patch('tripleoclient.utils.build_stack_data', autospec=True)
@mock.patch('tripleo_common.utils.plan.default_image_params',
@ -155,7 +157,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_process_env, mock_roles_data,
mock_container_prepare, mock_generate_password,
mock_rc_params, mock_default_image_params,
mock_stack_data, mock_check_service_vip_migr):
mock_stack_data, mock_check_service_vip_migr,
mock_provision_networks):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
clients = self.app.client_manager
@ -229,6 +232,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
output_dir=self.cmd.working_dir)
mock_copy.assert_called_once()
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_provision_networks', autospec=True)
@mock.patch('tripleoclient.utils.build_stack_data', autospec=True)
@mock.patch('tripleo_common.utils.plan.default_image_params',
return_value={})
@ -274,7 +279,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_process_env, mock_roles_data,
mock_container_prepare, mock_generate_password,
mock_rc_params, mock_default_image_params,
mock_stack_data):
mock_stack_data, mock_provision_networks):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
utils_fixture = deployment.UtilsFixture()
@ -335,6 +340,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_validate_args.assert_called_once_with(parsed_args)
self.assertFalse(mock_invoke_plan_env_wf.called)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_provision_networks', autospec=True)
@mock.patch('tripleoclient.utils.build_stack_data', autospec=True)
@mock.patch('tripleoclient.utils.get_rc_params', autospec=True)
@mock.patch('tripleo_common.utils.plan.generate_passwords',
@ -376,7 +383,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_chdir,
mock_process_env, mock_roles_data,
mock_image_prepare, mock_generate_password,
mock_rc_params, mock_stack_data):
mock_rc_params, mock_stack_data,
mock_provision_networks):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
utils_fixture = deployment.UtilsFixture()
@ -419,6 +427,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
self.cmd.take_action(parsed_args)
mock_copy.assert_called_once()
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_provision_networks', autospec=True)
@mock.patch('tripleoclient.utils.check_service_vips_migrated_to_service')
@mock.patch('tripleoclient.utils.build_stack_data', autospec=True)
@mock.patch('tripleoclient.utils.get_rc_params', autospec=True)
@ -462,7 +472,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_generate_password,
mock_rc_params,
mock_stack_data,
mock_check_service_vip_migr):
mock_check_service_vip_migr,
mock_provision_networks):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
utils_fixture = deployment.UtilsFixture()
@ -734,6 +745,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
self.assertFalse(utils_fixture.mock_deploy_tht.called)
self.assertFalse(mock_deploy.called)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_provision_networks', autospec=True)
@mock.patch('tripleoclient.utils.check_service_vips_migrated_to_service')
@mock.patch('tripleoclient.utils.get_rc_params', autospec=True)
@mock.patch('tripleo_common.utils.plan.generate_passwords',
@ -762,7 +775,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_copy, mock_nic_ansible,
mock_roles_data, mock_image_prepare,
mock_generate_password, mock_rc_params,
mock_check_service_vip_migr):
mock_check_service_vip_migr,
mock_provision_networks):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
clients = self.app.client_manager
@ -837,6 +851,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
output_dir=self.cmd.working_dir)
mock_copy.assert_called_once()
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_provision_networks', autospec=True)
@mock.patch('tripleoclient.utils.build_stack_data', autospec=True)
@mock.patch('tripleo_common.utils.plan.default_image_params',
autospec=True)
@ -885,7 +901,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_generate_password,
mock_rc_params,
mock_default_image_params,
mock_stack_data):
mock_stack_data,
mock_provision_networks):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
utils_fixture = deployment.UtilsFixture()
@ -1440,6 +1457,35 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
'overcloud'
)
def test__provision_networks(self):
networks_file_path = self.tmp_dir.join('networks.yaml')
network_data = [
{'name': 'Network', 'name_lower': 'network', 'subnets': {}}
]
with open(networks_file_path, 'w') as temp_file:
yaml.safe_dump(network_data, temp_file)
arglist = ['--networks-file', networks_file_path]
verifylist = [('networks_file', networks_file_path)]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
tht_root = self.tmp_dir.join('tht')
env_dir = os.path.join(tht_root, 'user-environments')
env_path = os.path.join(env_dir, 'networks-deployed.yaml')
os.makedirs(env_dir)
result = self.cmd._provision_networks(parsed_args, tht_root)
self.assertEqual([env_path], result)
self.mock_playbook.assert_called_once_with(
extra_vars={'network_data_path': networks_file_path,
'network_deployed_path': env_path,
'overwrite': True},
inventory='localhost,',
playbook='cli-overcloud-network-provision.yaml',
playbook_dir='/usr/share/ansible/tripleo-playbooks',
verbosity=3,
workdir=mock.ANY)
@mock.patch('subprocess.Popen', autospec=True)
def test__get_undercloud_host_entry(self, mock_popen):
mock_process = mock.Mock()

43
tripleoclient/v1/overcloud_deploy.py

@ -303,6 +303,8 @@ class DeployOvercloud(command.Command):
new_tht_root,
constants.DEPLOYED_SERVER_ENVIRONMENT))
created_env_files.extend(
self._provision_networks(parsed_args, new_tht_root))
created_env_files.extend(
self._provision_baremetal(parsed_args, new_tht_root))
@ -604,6 +606,47 @@ class DeployOvercloud(command.Command):
}
)
@staticmethod
def _is_network_data_v2(networks_file_path):
with open(networks_file_path, 'r') as f:
network_data = yaml.safe_load(f.read())
for network in network_data:
if 'ip_subnet' in network or 'ipv6_subnet' in network:
return False
return True
def _provision_networks(self, parsed_args, tht_root):
# Parse the network data, if any network have 'ip_subnet' or
# 'ipv6_subnet' keys this is not a network-v2 format file. In this
# case do nothing.
networks_file_path = utils.get_networks_file_path(
parsed_args.networks_file, parsed_args.templates)
if not self._is_network_data_v2(networks_file_path):
return []
output_path = utils.build_user_env_path(
'networks-deployed.yaml',
tht_root)
extra_vars = {
"network_data_path": networks_file_path,
"network_deployed_path": output_path,
"overwrite": True,
}
with utils.TempDirs() as tmp:
utils.run_ansible_playbook(
playbook='cli-overcloud-network-provision.yaml',
inventory='localhost,',
workdir=tmp,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=utils.playbook_verbosity(self=self),
extra_vars=extra_vars,
)
return [output_path]
def setup_ephemeral_heat(self, parsed_args, parameters):
self.log.info("Using ephemeral heat for stack operation")
api_container_image = parameters['ContainerHeatApiImage']

Loading…
Cancel
Save