diff --git a/instack_undercloud/tests/test_undercloud.py b/instack_undercloud/tests/test_undercloud.py index 8dcf837b4..c808322df 100644 --- a/instack_undercloud/tests/test_undercloud.py +++ b/instack_undercloud/tests/test_undercloud.py @@ -714,26 +714,45 @@ class TestPostConfig(base.BaseTestCase): mistralclient_base.APIException) env = { + "UNDERCLOUD_DB_PASSWORD": "root-db-pass", "UNDERCLOUD_CEILOMETER_SNMPD_PASSWORD": "snmpd-pass" } - json_string = '{"undercloud_ceilometer_snmpd_password": "snmpd-pass"}' - undercloud._create_mistral_config_environment(env, mock_mistral) + json_string = { + "undercloud_db_password": "root-db-pass", + "undercloud_ceilometer_snmpd_password": "snmpd-pass" + } + + undercloud._create_mistral_config_environment(json.loads( + json.dumps(env, sort_keys=True)), mock_mistral) mock_mistral.environments.create.assert_called_once_with( - name="tripleo.undercloud-config", - variables=json_string) + name='tripleo.undercloud-config', + description='Undercloud configuration parameters', + variables=json.dumps(json_string, sort_keys=True)) def test_create_config_environment_existing(self): mock_mistral = mock.Mock() - environment = collections.namedtuple('environment', ['name']) - mock_mistral.environments.get.return_value = environment( - name='overcloud') - env = { - "UNDERCLOUD_CEILOMETER_SNMPD_PASSWORD": "snmpd-pass" + environment = collections.namedtuple('environment', + ['name', 'variables']) + + json_string = { + "undercloud_db_password": "root-db-pass", + "undercloud_ceilometer_snmpd_password": "snmpd-pass" } - undercloud._create_mistral_config_environment(env, mock_mistral) + mock_mistral.environments.get.return_value = environment( + name='tripleo.undercloud-config', + variables=json.loads(json.dumps(json_string, sort_keys=True)) + ) + + env = { + "UNDERCLOUD_CEILOMETER_SNMPD_PASSWORD": "snmpd-pass", + "UNDERCLOUD_DB_PASSWORD": "root-db-pass" + } + + undercloud._create_mistral_config_environment(json.loads( + json.dumps(env, sort_keys=True)), mock_mistral) mock_mistral.executions.create.assert_not_called() def test_prepare_ssh_environment(self): diff --git a/instack_undercloud/undercloud.py b/instack_undercloud/undercloud.py index 6ff0018c4..3408eb068 100644 --- a/instack_undercloud/undercloud.py +++ b/instack_undercloud/undercloud.py @@ -1309,19 +1309,51 @@ def _clean_os_refresh_config(): def _create_mistral_config_environment(instack_env, mistral): - # Store the snmpd password in a Mistral environment so it can be accessed + # Store all the required passwords from the Undercloud + # in a Mistral environment so they can be accessed # by the Mistral actions. - snmpd_password = instack_env["UNDERCLOUD_CEILOMETER_SNMPD_PASSWORD"] - env_name = "tripleo.undercloud-config" + config_data = { + 'undercloud_ceilometer_snmpd_password': + instack_env['UNDERCLOUD_CEILOMETER_SNMPD_PASSWORD'], + 'undercloud_db_password': + instack_env['UNDERCLOUD_DB_PASSWORD'] + } + env_name = 'tripleo.undercloud-config' try: - mistral.environments.get(env_name) + env_data = mistral.environments.get(env_name).variables except mistralclient_base.APIException: + # If the environment is not created, we need to + # create it with the information in config_data mistral.environments.create( name=env_name, - variables=json.dumps({ - "undercloud_ceilometer_snmpd_password": snmpd_password - })) + description='Undercloud configuration parameters', + variables=json.dumps(config_data, sort_keys=True) + ) + return + + # If we are upgrading from an environment without + # variables defined in config_data, we need to update + # the environment variables. + + for var, value in iter(config_data.items()): + if var in env_data: + if env_data[var] != config_data[var]: + # Value in config_data is different + # need to update + env_data[var] = value + else: + # The value in config_data + # is new, we need to add it + env_data[var] = value + + # Here we update the current environment + # with the variables updated + mistral.environments.update( + name=env_name, + description='Undercloud configuration parameters', + variables=json.dumps(env_data, sort_keys=True) + ) def _create_default_plan(mistral, timeout=360):