Use text_format_safe instead of text_format

Use text_format_safe for traversing plugin attributes

Change-Id: Ib21a7386fe7cea982c98cfeaaa26040463f72b9d
Closes-Bug: #1576197
This commit is contained in:
Andriy Popovych 2016-05-05 17:13:17 +03:00
parent afdceb7fad
commit a4b427fca4
2 changed files with 16 additions and 0 deletions

View File

@ -47,6 +47,7 @@ from nailgun.policy.merge import NetworkRoleMergePolicy
from nailgun.settings import settings from nailgun.settings import settings
from nailgun.utils import AttributesGenerator from nailgun.utils import AttributesGenerator
from nailgun.utils import dict_merge from nailgun.utils import dict_merge
from nailgun.utils import text_format_safe
from nailgun.utils import traverse from nailgun.utils import traverse
@ -363,6 +364,7 @@ class Cluster(NailgunObject):
plugin_attrs = traverse( plugin_attrs = traverse(
plugin_attrs, plugin_attrs,
formatter=text_format_safe,
formatter_context={'cluster': instance, 'settings': settings}, formatter_context={'cluster': instance, 'settings': settings},
keywords={'generator': AttributesGenerator.evaluate} keywords={'generator': AttributesGenerator.evaluate}
) )

View File

@ -1679,6 +1679,20 @@ class TestClusterObject(BaseTestCase):
updated_attributes['editable']['test_plugin'] updated_attributes['editable']['test_plugin']
['plugin_name_text']['value']) ['plugin_name_text']['value'])
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): class TestClusterObjectVirtRoles(BaseTestCase):