Browse Source

Check CephClusterFSID against proposed env files

There have been cases where operators inadvertenly changed the
CephClusterFSID on a stack update, which is unsupported by both
Ceph and openstack.
For this reason we need to check that the existing deployed Ceph
cluster ID present in the stack is consistent with the value of
the environment, raising an InvalidConfiguration exception if
they are different.

Change-Id: I6aca5c701cb00c82c6b3f92db72b5547799a10bf
Closes-Bug: #1882548
(cherry picked from commit 58f913512c)
(cherry picked from commit 05a909c355)
changes/85/784385/2 queens-eol
Francesco Pantano 10 months ago
parent
commit
9871ac7bc6
No known key found for this signature in database GPG Key ID: 458D4D1F41BD75C
  1. 43
      tripleoclient/tests/test_utils.py
  2. 30
      tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py
  3. 27
      tripleoclient/utils.py
  4. 10
      tripleoclient/v1/overcloud_deploy.py

43
tripleoclient/tests/test_utils.py

@ -575,6 +575,49 @@ class TestWaitForStackUtil(TestCase):
with self.assertRaises(exceptions.InvalidConfiguration):
utils.check_stack_network_matches_env_files(mock_stack, env)
def test_check_ceph_fsid_matches_env_files(self):
stack_params = {
'CephClusterFSID': 'ceph_fsid_val',
'key1': 'val1',
'key2': 'val2',
}
mock_stack = mock.MagicMock()
mock_stack.environment = mock.MagicMock()
mock_stack.environment.return_value = {
'parameter_defaults': stack_params
}
provided_env = {
'parameter_defaults': {
'CephClusterFSID': mock_stack.environment()
.get('parameter_defaults', {})
.get('CephClusterFSID', False),
'key1': 'val1',
'key2': 'val2',
}
}
utils.check_ceph_fsid_matches_env_files(mock_stack, provided_env)
def test_check_ceph_fsid_matches_env_files_fail(self):
stack_params = {
'CephClusterFSID': 'ceph_fsid_val',
'key1': 'val1',
'key2': 'val2',
}
provided_env = {
'parameter_defaults': {
'CephClusterFSID': 'new_or_wrong_fsid_val',
'key1': 'val1',
'key2': 'val2',
}
}
mock_stack = mock.MagicMock()
mock_stack.environment = mock.MagicMock()
mock_stack.environment.return_value = {
'parameter_defaults': stack_params
}
with self.assertRaises(exceptions.InvalidConfiguration):
utils.check_ceph_fsid_matches_env_files(mock_stack, provided_env)
@mock.patch('subprocess.check_call')
@mock.patch('os.path.exists')
def test_remove_known_hosts(self, mock_exists, mock_check_call):

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

@ -78,6 +78,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
autospec=True)
@mock.patch('tripleoclient.workflows.plan_management.tarball',
autospec=True)
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch("heatclient.common.event_utils.get_events")
@mock.patch('tripleo_common.update.add_breakpoints_cleanup_into_env',
autospec=True)
@ -106,6 +107,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_create_parameters_env,
mock_breakpoints_cleanupm,
mock_events, mock_tarball,
mock_ceph_fsid,
mock_get_horizon_url,
mock_list_plans,
mock_config_download,
@ -332,6 +334,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
parameters_env.get('parameter_defaults'))
@mock.patch('tripleoclient.utils.check_stack_network_matches_env_files')
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch('tripleoclient.workflows.deployment.get_overcloud_hosts')
@mock.patch('tripleoclient.workflows.deployment.enable_ssh_admin')
@mock.patch('tripleoclient.workflows.deployment.config_download')
@ -381,7 +384,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_list_plans, mock_config_download,
mock_enable_ssh_admin,
mock_get_overcloud_hosts,
mock_stack_network_check):
mock_stack_network_check, mock_ceph_fsid):
arglist = ['--templates', '-p', 'the-plan-environment.yaml']
verifylist = [
@ -489,6 +492,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
autospec=True)
@mock.patch('tripleoclient.workflows.deployment.get_horizon_url',
autospec=True)
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch('tripleoclient.workflows.parameters.'
'check_deprecated_parameters', autospec=True)
@mock.patch('tripleoclient.utils.get_overcloud_endpoint', autospec=True)
@ -527,7 +531,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_breakpoints_cleanup, mock_tarball,
mock_postconfig, mock_get_overcloud_endpoint,
mock_deprecated_params, mock_get_horizon_url,
mock_list_plans, mock_config_downlad,
mock_ceph_fsid, mock_list_plans, mock_config_downlad,
mock_enable_ssh_admin,
mock_get_overcloud_hosts,
mock_stack_network_check):
@ -598,6 +602,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
autospec=True)
@mock.patch('tripleoclient.workflows.plan_management.tarball',
autospec=True)
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch("heatclient.common.event_utils.get_events", autospec=True)
@mock.patch('tripleo_common.update.add_breakpoints_cleanup_into_env',
autospec=True)
@ -621,7 +626,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_deploy_postconfig,
mock_breakpoints_cleanup,
mock_events, mock_tarball,
mock_get_horizon_url,
mock_ceph_fsid, mock_get_horizon_url,
mock_list_plans,
mock_config_download,
mock_enable_ssh_admin,
@ -725,6 +730,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
autospec=True)
@mock.patch('tripleoclient.workflows.plan_management.tarball',
autospec=True)
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch('tripleoclient.utils.create_tempest_deployer_input',
autospec=True)
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
@ -740,8 +746,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_update_parameters, mock_post_config,
mock_utils_endpoint, mock_utils_createrc,
mock_utils_tempest, mock_tarball,
mock_get_horizon_url, mock_list_plans,
mock_config_download,
mock_ceph_fsid, mock_get_horizon_url,
mock_list_plans, mock_config_download,
mock_enable_ssh_admin,
mock_get_overcloud_hosts,
mock_stack_network_check):
@ -799,6 +805,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
autospec=True)
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
@mock.patch('tripleoclient.utils.get_overcloud_endpoint', autospec=True)
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch('tripleoclient.utils.get_stack', autospec=True)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_deploy_postconfig', autospec=True)
@ -810,8 +817,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
def test_environment_dirs_env(self, mock_copy, mock_deploy_heat,
mock_update_parameters, mock_post_config,
mock_utils_get_stack, mock_utils_endpoint,
mock_utils_createrc, mock_utils_tempest,
mock_tarball,
mock_ceph_fsid, mock_utils_createrc,
mock_utils_tempest, mock_tarball,
mock_stack_network_check):
clients = self.app.client_manager
@ -1279,6 +1286,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
autospec=True)
@mock.patch('tripleoclient.workflows.plan_management.tarball',
autospec=True)
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch('tripleoclient.utils.create_tempest_deployer_input',
autospec=True)
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
@ -1293,7 +1301,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_oc_endpoint,
mock_create_ocrc,
mock_create_tempest_deployer_input,
mock_tarball, mock_get_horizon_url,
mock_tarball, mock_ceph_fsid,
mock_get_horizon_url,
mock_list_plans,
mock_config_download,
mock_enable_ssh_admin,
@ -1413,6 +1422,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
@mock.patch('tripleoclient.utils.check_stack_network_matches_env_files')
@mock.patch('tripleoclient.workflows.plan_management.tarball',
autospec=True)
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_create_parameters_env', autospec=True)
@mock.patch('tripleoclient.utils.write_overcloudrc')
@ -1426,7 +1436,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_process_env,
mock_write_overcloudrc,
mock_create_parameters_env,
mock_tarball,
mock_tarball, mock_ceph_fsid,
mock_stack_network_check):
clients = self.app.client_manager
orchestration_client = clients.orchestration
@ -1475,6 +1485,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
autospec=True)
@mock.patch('tripleoclient.workflows.deployment.get_horizon_url',
autospec=True)
@mock.patch('tripleoclient.utils.check_ceph_fsid_matches_env_files')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_deploy_postconfig', autospec=True)
@mock.patch('tripleoclient.workflows.plan_management.tarball',
@ -1511,6 +1522,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_tarball,
mock_deploy_post_config,
mock_get_horizon_url,
mock_ceph_fsid,
mock_list_plans,
mock_config_download,
mock_enable_ssh_admin,

27
tripleoclient/utils.py

@ -579,6 +579,33 @@ def get_stack(orchestration_client, stack_name):
pass
def check_ceph_fsid_matches_env_files(stack, environment):
"""Check CephClusterFSID against proposed env files
There have been cases where operators inadvertenly changed the
CephClusterFSID on a stack update, which is unsupported by both
Ceph and openstack.
For this reason we need to check that the existing deployed Ceph
cluster ID present in the stack is consistent with the value of
the environment, raising an exception if they are different.
"""
env_ceph_fsid = environment.get('parameter_defaults',
{}).get('CephClusterFSID', False)
stack_ceph_fsid = stack.environment().get('parameter_defaults',
{}).get('CephClusterFSID', False)
if bool(env_ceph_fsid) and env_ceph_fsid != stack_ceph_fsid:
raise exceptions.InvalidConfiguration('The CephFSID environment value '
' ({}) does not match the stack '
' configuration value ({}).'
' Ensure the CephClusterFSID '
' param is properly configured '
' in the storage environment '
' files.'
.format(env_ceph_fsid,
stack_ceph_fsid))
def check_stack_network_matches_env_files(stack, environment):
"""Check stack against proposed env files to ensure non-breaking change

10
tripleoclient/v1/overcloud_deploy.py

@ -512,6 +512,16 @@ class DeployOvercloud(command.Command):
if not parsed_args.disable_validations:
# note(aschultz): network validation goes here before we deploy
utils.check_stack_network_matches_env_files(stack, env)
ceph_deployed = env.get('resource_registry', {}).get(
'OS::TripleO::Services::CephMon', 'OS::Heat::None')
ceph_external = env.get('resource_registry', {}).get(
'OS::TripleO::Services::CephExternal', 'OS::Heat::None')
# note (fpantano) if ceph is not TripleO deployed and no
# external ceph cluster are present, there's no reason to
# make this check and we can simply ignore it
if (ceph_deployed != "OS::Heat::None"
or ceph_external != "OS::Heat::None"):
utils.check_ceph_fsid_matches_env_files(stack, env)
bp_cleanup = self._create_breakpoint_cleanup_env(
tht_root, parsed_args.stack)
template_utils.deep_update(env, bp_cleanup)

Loading…
Cancel
Save