Merge "Fix configuration merging for multiple roles" into stable/8.0

This commit is contained in:
Jenkins 2016-01-21 13:51:09 +00:00 committed by Gerrit Code Review
commit f81311bbd6
2 changed files with 46 additions and 11 deletions

View File

@ -377,6 +377,23 @@ class UploadConfiguration(GenericRolesHook):
)
self.configs = configs
@staticmethod
def _merge_configs(dest, src):
"""Merge configuration parameters within groups.
Configuration uploaded to node has format:
::
--
config_group:
param_name: {'value': '<some_value>'}
Merge should happen on 2nd nesting level to merge parameters
within groups.
"""
for group, value in six.iteritems(src):
dest.setdefault(group, {}).update(value)
def serialize(self):
configs = self.configs
if configs is None:
@ -395,8 +412,8 @@ class UploadConfiguration(GenericRolesHook):
elif config.config_type == consts.OPENSTACK_CONFIG_TYPES.role:
for node in self.nodes:
if config.node_role in node.roles:
node_configs[node.id]['role'].update(
config.configuration)
self._merge_configs(node_configs[node.id]['role'],
config.configuration)
elif config.config_type == consts.OPENSTACK_CONFIG_TYPES.node:
if config.node_id in nodes_to_update:

View File

@ -229,16 +229,16 @@ class TestHooksSerializers(BaseTaskSerializationTest):
configs = [
mock.Mock(config_type=consts.OPENSTACK_CONFIG_TYPES.cluster,
configuration={'cluster': 'foo'}),
configuration={'cluster': {'value': 'foo'}}),
mock.Mock(config_type=consts.OPENSTACK_CONFIG_TYPES.role,
node_role='compute',
configuration={'compute': 'bar'}),
configuration={'compute': {'value': 'bar'}}),
mock.Mock(config_type=consts.OPENSTACK_CONFIG_TYPES.role,
node_role='cinder',
configuration={'cinder': 'buzz'}),
configuration={'cinder': {'value': 'buzz'}}),
mock.Mock(config_type=consts.OPENSTACK_CONFIG_TYPES.node,
node_id=self.env.nodes[0].id,
configuration={'node_0': 'quux'})
configuration={'node_0': {'value': 'quux'}})
]
task = tasks_serializer.UploadConfiguration(
@ -271,12 +271,26 @@ class TestHooksSerializers(BaseTaskSerializationTest):
cluster_id=self.cluster.id,
config_type=consts.OPENSTACK_CONFIG_TYPES.role,
node_role='compute',
configuration={'value_a': 'compute', 'value_b': 'compute'}),
configuration={
'nova_config': {
'DEFAULT/param_a': {'value': 'value_compute'},
},
'keystone_config': {
'DEFAULT/param_a': {'value': 'value_compute'},
}
}),
self.env.create_openstack_config(
cluster_id=self.cluster.id,
config_type=consts.OPENSTACK_CONFIG_TYPES.role,
node_role='cinder',
configuration={'value_a': 'cinder', 'value_c': 'cinder'})
configuration={
'nova_config': {
'DEFAULT/param_b': {'value': 'value_cinder'}
},
'keystone_config': {
'DEFAULT/param_a': {'value': 'value_cinder'},
}
})
task = tasks_serializer.UploadConfiguration(
task_config, self.cluster, self.nodes)
@ -285,9 +299,13 @@ class TestHooksSerializers(BaseTaskSerializationTest):
serialized_task['parameters']['data'])
self.assertEqual(config, {
'configuration': {
'value_a': 'compute',
'value_b': 'compute',
'value_c': 'cinder'
'nova_config': {
'DEFAULT/param_a': {'value': 'value_compute'},
'DEFAULT/param_b': {'value': 'value_cinder'}
},
'keystone_config': {
'DEFAULT/param_a': {'value': 'value_compute'},
}
}})
def test_update_hosts(self):