Properly process plugin attributes in default handler

Patch fixes default workflow from CLI, which is:
fuel attributes --env 1 --default
Gets you default attributes for your env, then you are able
to enable/disable plugin and
fuel attributes --env 1 --upload
Upload them back

related to blueprint cinder-neutron-plugins-in-fuel

Change-Id: I805d53f5adfefca4c72662c143d9a5474a98e862
This commit is contained in:
Dima Shulyak 2014-10-28 11:42:55 +02:00 committed by Dmitry Shulyak
parent 316b8854af
commit 1499dca448
3 changed files with 29 additions and 10 deletions

View File

@ -189,7 +189,7 @@ class ClusterAttributesDefaultsHandler(BaseHandler):
* 500 (cluster has no attributes)
"""
cluster = self.get_object_or_404(objects.Cluster, cluster_id)
attrs = cluster.release.attributes_metadata.get("editable")
attrs = objects.Cluster.get_default_editable_attributes(cluster)
if not attrs:
raise self.http(500, "No attributes found!")
return {"editable": attrs}
@ -217,9 +217,8 @@ class ClusterAttributesDefaultsHandler(BaseHandler):
' found for cluster_id %s' % cluster_id)
raise self.http(500, "No attributes found!")
cluster.attributes.editable = cluster.release.attributes_metadata.get(
"editable"
)
cluster.attributes.editable = (
objects.Cluster.get_default_editable_attributes(cluster))
objects.Cluster.add_pending_changes(cluster, "attributes")
logger.debug('ClusterAttributesDefaultsHandler:'

View File

@ -216,9 +216,7 @@ class Cluster(NailgunObject):
"""
attributes = Attributes.create(
{
"editable": instance.release.attributes_metadata.get(
"editable"
),
"editable": cls.get_default_editable_attributes(instance),
"generated": instance.release.attributes_metadata.get(
"generated"
),
@ -226,12 +224,21 @@ class Cluster(NailgunObject):
}
)
Attributes.generate_fields(attributes)
db().flush()
@classmethod
def get_default_editable_attributes(cls, instance):
"""Get editable attributes from release metadata
:param instance: Cluster instance
:returns: Dict object
"""
editable = instance.release.attributes_metadata.get("editable")
# 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, **instance.attributes.editable)
instance.attributes.editable = editable
db().flush()
editable = dict(plugin_attrs, **editable)
return editable
@classmethod
def get_attributes(cls, instance):

View File

@ -101,6 +101,13 @@ class BasePluginTest(base.BaseIntegrationTest):
nodes_kwargs=nodes)
return self.env.clusters[0]
def default_attributes(self, cluster):
resp = self.app.get(
base.reverse('ClusterAttributesDefaultsHandler',
{'cluster_id': cluster.id}),
headers=self.default_headers)
return resp
def modify_plugin(self, cluster, plugin_name, enabled):
editable_attrs = cluster.attributes.editable
editable_attrs[plugin_name]['metadata']['enabled'] = enabled
@ -189,6 +196,12 @@ class TestPluginsApi(BasePluginTest):
updated_data.pop('id')
self.assertEqual(updated_data, data)
def test_default_attributes_after_plugin_is_created(self):
self.create_plugin()
cluster = self.create_cluster()
default_attributes = self.default_attributes(cluster)
self.assertIn(self.SAMPLE_PLUGIN['name'], default_attributes)
class TestPrePostHooks(BasePluginTest):