Merge "Use dict_merge instead of update"

This commit is contained in:
Jenkins 2016-12-29 11:32:55 +00:00 committed by Gerrit Code Review
commit 2ff59bdf77
6 changed files with 44 additions and 37 deletions

View File

@ -1316,7 +1316,7 @@ class TestNICAttributesHandlers(BaseIntegrationTest):
'description': 'Some description'
},
'metadata': {
'label': 'Test plugin',
'label': 'Test base plugin',
'class': 'plugin'
}
}

View File

@ -967,26 +967,15 @@ class TestBondAttributesDefaultsHandler(BaseIntegrationTest):
}
},
'plugin_a_with_bond_attributes': {
'plugin_name_text': {
'weight': 25,
'type': 'text',
'value': 'value',
'label': 'label',
'metadata': {
'label': 'Test base plugin'
},
'value': {
'weight': 10,
'type': 'number',
'value': None,
'label': 'MTU'
}
},
'plugin_a_with_bond_attributes': {
'plugin_name_text': {
'weight': 25,
'type': 'text',
'value': 'value',
'label': 'label',
'description': 'Some description'
'type': 'text',
'description': 'Some description',
'weight': 25,
'label': 'label'
}
}
}

View File

@ -29,6 +29,7 @@ from nailgun.objects import NailgunCollection
from nailgun.objects import NailgunObject
from nailgun.objects.serializers.plugin import PluginSerializer
from nailgun import plugins
from nailgun import utils as nailgun_utils
class Plugin(NailgunObject):
@ -556,7 +557,10 @@ class NodeNICInterfaceClusterPlugin(BasicNodeClusterPlugin):
}
# TODO(apopovych): resolve conflicts of same attribute names
# for different plugins
nic_attributes[name].update(attributes)
nic_attributes[name] = nailgun_utils.dict_merge(
nic_attributes[name],
attributes
)
return nic_attributes
@ -648,7 +652,10 @@ class NodeBondInterfaceClusterPlugin(BasicNodeClusterPlugin):
}
# TODO(apopovych): resolve conflicts of same attribute names
# for different plugins
bond_attributes[name].update(attributes)
bond_attributes[name] = nailgun_utils.dict_merge(
bond_attributes[name],
attributes
)
return bond_attributes

View File

@ -548,12 +548,10 @@ class PluginManager(object):
plugins.append(attributes.pop(k))
for plugin in plugins:
metadata = plugin.pop('metadata')
metadata = plugin.get('metadata', {})
bond_plugin_id = metadata.pop('bond_plugin_id')
NodeBondInterfaceClusterPlugin.\
set_attributes(
metadata['bond_plugin_id'],
plugin
)
set_attributes(bond_plugin_id, plugin)
@classmethod
def get_nic_default_attributes(cls, cluster):
@ -591,12 +589,10 @@ class PluginManager(object):
plugins.append(attributes.pop(k))
for plugin in plugins:
metadata = plugin.pop('metadata')
metadata = plugin.get('metadata', {})
nic_plugin_id = metadata.pop('nic_plugin_id')
NodeNICInterfaceClusterPlugin.\
set_attributes(
metadata['nic_plugin_id'],
plugin
)
set_attributes(nic_plugin_id, plugin)
@classmethod
def add_plugin_attributes_for_interface(cls, interface):

View File

@ -864,6 +864,9 @@ class EnvironmentManager(object):
def get_default_plugin_nic_config(self, **kwargs):
nic_attributes = {
'metadata': {
'label': 'Test base plugin'
},
'plugin_name_text': {
'value': 'value',
'type': 'text',
@ -878,6 +881,9 @@ class EnvironmentManager(object):
def get_default_plugin_bond_config(self, **kwargs):
bond_attributes = {
'metadata': {
'label': 'Test base plugin'
},
'plugin_name_text': {
'value': 'value',
'type': 'text',

View File

@ -371,10 +371,15 @@ class TestNodeNICInterfaceClusterPlugin(ExtraFunctions):
expected_attributes = {
'plugin_a_with_nic_attributes': {
'metadata': {
'label': 'Test plugin',
'label': 'Test base plugin',
'nic_plugin_id': nic_plugin_id,
'class': 'plugin'}}}
expected_attributes['plugin_a_with_nic_attributes'].update(nic_config)
'class': 'plugin'},
'plugin_name_text': {
'value': 'value',
'type': 'text',
'description': 'Some description',
'weight': 25,
'label': 'label'}}}
self.assertEqual(expected_attributes, attributes)
@ -509,11 +514,15 @@ class TestNodeBondInterfaceClusterPlugin(ExtraFunctions):
expected_attributes = {
'plugin_a_with_bond_attributes': {
'metadata': {
'label': 'Test plugin',
'label': 'Test base plugin',
'bond_plugin_id': bond_plugin_id,
'class': 'plugin'}}}
expected_attributes['plugin_a_with_bond_attributes'].update(
plugin_bond_config)
'class': 'plugin'},
'plugin_name_text': {
'value': 'value',
'type': 'text',
'description': 'Some description',
'weight': 25,
'label': 'label'}}}
self.assertEqual(expected_attributes, attributes)