Fixed generators support in fuel plugin environment_config.yaml

Fixed attributes processing mechanism in such a way that at the first step
instance editable metadata attributes are merged with plugin attributes and
only after that the resulting attributes dict goes through generator processing

Change-Id: I4bda81f323a3f77ae5ace3927ac5f157503822ee
Closes-bug: #1473452
(cherry picked from commit d8608388be)
This commit is contained in:
Dmitry Stepanenko 2015-08-26 11:47:00 +03:00 committed by dstepanenko
parent 433d7ab0a7
commit 153e0c0b5f
2 changed files with 25 additions and 4 deletions

View File

@ -241,14 +241,14 @@ class Cluster(NailgunObject):
:returns: Dict object
"""
editable = instance.release.attributes_metadata.get("editable")
editable = traverse(editable, AttributesGenerator, {
'cluster': instance,
'settings': settings,
})
# when attributes created we need to understand whether should plugin
# be applied for created cluster
plugin_attrs = PluginManager.get_plugin_attributes(instance)
editable = dict(plugin_attrs, **editable)
editable = traverse(editable, AttributesGenerator, {
'cluster': instance,
'settings': settings,
})
return editable
@classmethod

View File

@ -268,6 +268,27 @@ class TestPluginsApi(BasePluginTest):
resp.json_body["message"],
'Problem with loading YAML file')
@mock.patch('nailgun.objects.cluster.AttributesGenerator')
def test_plugin_generator(self, mock_attributes_generator):
mock_attributes_generator.test_plugin_generator.return_value = 'test'
plugin_name = 'testing_plugin'
self.sample_plugin = self.env.get_default_plugin_metadata(
name=plugin_name
)
self.plugin_env_config = \
self.env.get_default_plugin_env_config(
value={
'generator': 'test_plugin_generator',
},
plugin_name=plugin_name
)
self.create_plugin()
cluster = self.create_cluster()
self.assertIn(self.sample_plugin['name'], cluster.attributes.editable)
plugin_dict = cluster.attributes.editable[plugin_name]
value = plugin_dict['%s_text' % plugin_name]['value']
self.assertEqual(value, 'test')
def _create_new_and_old_version_plugins_for_sync(self):
plugin_ids = []