Tags info calculation is supported on plugins update

For instance we made plugins sync operation. In this case
tags info should be processed on the same way as on plugin
creation.
Also test for tags metadata migration improved.

Change-Id: I937bb581f61034d027b28a8e4fd5b42a35fcd7f6
Closes-Bug: #1655264
This commit is contained in:
Alexander Kislitsky 2017-01-10 17:59:33 +03:00
parent 6b9b4ae715
commit baa107f318
3 changed files with 50 additions and 1 deletions

View File

@ -130,6 +130,8 @@ class Plugin(NailgunObject):
graphs[graph.pop('type')] = graph graphs[graph.pop('type')] = graph
data.pop("deployment_tasks", []) # could not be updated data.pop("deployment_tasks", []) # could not be updated
# We must save tags info in the roles_metadata on the update
data = cls._process_tags(data)
super(Plugin, cls).update(instance, data) super(Plugin, cls).update(instance, data)
for graph_type, graph_data in six.iteritems(graphs): for graph_type, graph_data in six.iteritems(graphs):

View File

@ -497,6 +497,32 @@ def prepare():
}] }]
) )
db.execute(
meta.tables['plugins'].insert(),
[{
'name': 'test_tags',
'title': 'Test tags plugin',
'version': '2.0.0',
'description': 'Test plugin A for Fuel',
'homepage': 'http://fuel_plugins.test_plugin.com',
'package_version': '5.0.0',
'groups': jsonutils.dumps(['tgroup']),
'authors': jsonutils.dumps(['tauthor']),
'licenses': jsonutils.dumps(['tlicense']),
'releases': jsonutils.dumps([
{'repository_path': 'repositories/ubuntu'}
]),
'deployment_tasks': jsonutils.dumps([]),
'fuel_version': jsonutils.dumps(['9.2']),
'network_roles_metadata': jsonutils.dumps([]),
'roles_metadata': jsonutils.dumps({
'plugin-tags-controller': {
'name': 'Plugin Tags Controller',
},
}),
}]
)
db.commit() db.commit()
@ -620,7 +646,7 @@ class TestTags(base.BaseAlembicMigrationTest):
primary_tags = db.execute(query).fetchone()[0] primary_tags = db.execute(query).fetchone()[0]
self.assertItemsEqual(primary_tags, ['controller']) self.assertItemsEqual(primary_tags, ['controller'])
def test_tags_meta_migration(self): def test_tags_releases_meta_migration(self):
releases = self.meta.tables['releases'] releases = self.meta.tables['releases']
query = sa.select([releases.c.roles_metadata, query = sa.select([releases.c.roles_metadata,
releases.c.tags_metadata]) releases.c.tags_metadata])
@ -632,6 +658,21 @@ class TestTags(base.BaseAlembicMigrationTest):
tags_meta[role_name].get('has_primary', False), tags_meta[role_name].get('has_primary', False),
role_meta.get('has_primary', False) role_meta.get('has_primary', False)
) )
self.assertIn('tags', role_meta)
def test_tags_plugins_meta_migration(self):
plugins = self.meta.tables['plugins']
query = sa.select([plugins.c.roles_metadata,
plugins.c.tags_metadata])
for roles_meta, tags_meta in db.execute(query):
tags_meta = jsonutils.loads(tags_meta)
for role_name, role_meta in six.iteritems(
jsonutils.loads(roles_meta)):
self.assertEqual(
tags_meta[role_name].get('has_primary', False),
role_meta.get('has_primary', False)
)
self.assertIn('tags', role_meta)
def test_tags_migration_for_supported_releases(self): def test_tags_migration_for_supported_releases(self):
releases = self.meta.tables['releases'] releases = self.meta.tables['releases']

View File

@ -160,6 +160,12 @@ class TestPluginBase(base.BaseTestCase):
self.assertEqual( self.assertEqual(
getattr(self.plugin, key), val) getattr(self.plugin, key), val)
def test_tags_saved_on_plugins_update(self):
Plugin.update(self.plugin,
{'roles_metadata': self.plugin.roles_metadata})
for role, meta in self.plugin.roles_metadata.items():
self.assertIn('tags', meta)
def test_get_deployment_tasks(self): def test_get_deployment_tasks(self):
dg = DeploymentGraph.get_for_model(self.plugin_adapter.plugin) dg = DeploymentGraph.get_for_model(self.plugin_adapter.plugin)
DeploymentGraph.update( DeploymentGraph.update(