Use text_format_safe instead of text_format

Use text_format_safe for traversing plugin attributes

Change-Id: Ib21a7386fe7cea982c98cfeaaa26040463f72b9d
Closes-Bug: #1576197
Closes-Bug: #1614401
(cherry picked from commit a4b427fca4)
This commit is contained in:
Andriy Popovych 2016-05-05 17:13:17 +03:00 committed by Alexey Stupnikov
parent 3198aa7b19
commit 9360a35704
2 changed files with 22 additions and 4 deletions

View File

@ -44,6 +44,7 @@ from nailgun.policy.merge import NetworkRoleMergePolicy
from nailgun.settings import settings
from nailgun.utils import AttributesGenerator
from nailgun.utils import dict_merge
from nailgun.utils import text_format_safe
from nailgun.utils import traverse
@ -343,10 +344,13 @@ class Cluster(NailgunObject):
# Merge plugins attributes into editable ones
plugin_attrs = PluginManager.get_plugins_attributes(
instance, all_versions=all_plugins_versions)
plugin_attrs = traverse(plugin_attrs, AttributesGenerator, {
'cluster': instance,
'settings': settings,
})
plugin_attrs = traverse(
plugin_attrs,
formatter=text_format_safe,
formatter_context={'cluster': instance, 'settings': settings},
keywords={'generator': AttributesGenerator.evaluate}
)
attrs['editable'].update(plugin_attrs)
return attrs

View File

@ -1453,6 +1453,20 @@ class TestClusterObject(BaseTestCase):
self.db().refresh(config)
self.assertFalse(config.is_active)
def test_get_attributes_with_plugin(self):
cluster = self.env.create_cluster(api=False)
self.env.create_plugin(
name='test_plugin',
version='1.0.0',
package_version='4.0.0',
cluster=cluster,
attributes_metadata=self.env.get_default_plugin_env_config(
value='{}')
)
attr = objects.Cluster.get_attributes(cluster, True)
plugin_attrs = attr.editable['test_plugin']['metadata']['versions'][0]
self.assertEqual('{}', plugin_attrs['plugin_name_text']['value'])
class TestClusterObjectVirtRoles(BaseTestCase):