From 463097a6c708e99c9e3de56f327005bdce0e3112 Mon Sep 17 00:00:00 2001 From: Bulat Gaifullin Date: Fri, 1 Apr 2016 23:02:28 +0300 Subject: [PATCH] Added information about plugins data into astute.yaml Added information about plugins scripts and plugins repositories. This information will be used by puppet to create repositories and synchronise plugins scripts. Change-Id: Ie2df470a4f05b73162144f9c87d1023760b282c7 Closes-Bug: 1565061 --- .../orchestrator/deployment_serializers.py | 64 ++++++++++++++++- .../test_orchestrator_serializer_90.py | 69 ++++++++++++++++++- 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/nailgun/nailgun/orchestrator/deployment_serializers.py b/nailgun/nailgun/orchestrator/deployment_serializers.py index 9c8d216ec0..a1454ebf4b 100644 --- a/nailgun/nailgun/orchestrator/deployment_serializers.py +++ b/nailgun/nailgun/orchestrator/deployment_serializers.py @@ -27,6 +27,8 @@ from nailgun.extensions import node_extension_call from nailgun.extensions.volume_manager import manager as volume_manager from nailgun.logger import logger from nailgun import objects +from nailgun.plugins import adapters +from nailgun.settings import settings from nailgun import utils from nailgun.utils.ceph import get_pool_pg_count from nailgun.utils.role_resolver import NameMatchingPolicy @@ -333,10 +335,25 @@ class DeploymentMultinodeSerializer(object): for node in serialized_nodes: node['tasks'] = self.task_graph.deploy_task_serialize(node) - @classmethod - def inject_list_of_plugins(cls, attributes, cluster): + def inject_list_of_plugins(self, attributes, cluster): + """Added information about plugins to serialized attributes. + + :param attributes: the serialized attributes + :param cluster: the cluster object + """ plugins = objects.ClusterPlugins.get_enabled(cluster.id) - attributes['plugins'] = [p['name'] for p in plugins] + attributes['plugins'] = [ + self.serialize_plugin(cluster, p) for p in plugins + ] + + @classmethod + def serialize_plugin(cls, cluster, plugin): + """Gets plugin information to include into serialized attributes. + + :param cluster: the cluster object + :param plugin: the plugin object + """ + return plugin['name'] class DeploymentHASerializer(DeploymentMultinodeSerializer): @@ -724,6 +741,47 @@ class DeploymentLCMSerializer(DeploymentHASerializer90): self.inject_configs(node, roles, serialized_node) return serialized_node + @classmethod + def serialize_plugin(cls, cluster, plugin): + os_name = cluster.release.operating_system + adapter = adapters.wrap_plugin(plugin) + result = { + 'name': plugin['name'], + 'scripts': [ + { + 'remote_url': adapter.master_scripts_path(cluster), + 'local_path': adapter.slaves_scripts_path + } + ] + } + + if not adapter.repo_files(cluster): + return result + + # TODO(bgaifullin) move priority to plugin metadata + if os_name == consts.RELEASE_OS.centos: + repo = { + 'type': 'rpm', + 'name': adapter.full_name, + 'uri': adapter.repo_url(cluster), + 'priority': settings.REPO_PRIORITIES['plugins']['centos'] + } + elif os_name == consts.RELEASE_OS.ubuntu: + repo = { + 'type': 'deb', + 'name': adapter.full_name, + 'uri': adapter.repo_url(cluster), + 'suite': '/', + 'section': '', + 'priority': settings.REPO_PRIORITIES['plugins']['ubuntu'] + } + else: + logger.warning("Unsupported OS: %s.", os_name) + return result + + result['repositories'] = [repo] + return result + def inject_configs(self, node, roles, output): node_config = output.setdefault('configuration', {}) for config in self._configs: diff --git a/nailgun/nailgun/test/integration/test_orchestrator_serializer_90.py b/nailgun/nailgun/test/integration/test_orchestrator_serializer_90.py index 034c3aef60..3a3cf6a9cb 100644 --- a/nailgun/nailgun/test/integration/test_orchestrator_serializer_90.py +++ b/nailgun/nailgun/test/integration/test_orchestrator_serializer_90.py @@ -20,6 +20,7 @@ import six from nailgun import consts from nailgun import objects from nailgun.orchestrator import deployment_serializers +from nailgun.plugins import adapters from nailgun.orchestrator.neutron_serializers import \ NeutronNetworkDeploymentSerializer90 @@ -437,7 +438,10 @@ class TestDeploymentLCMSerialization90( def setUp(self): super(TestDeploymentLCMSerialization90, self).setUp() self.cluster = self.env.create( - release_kwargs={'version': self.env_version}, + release_kwargs={ + 'version': self.env_version, + 'operating_system': consts.RELEASE_OS.ubuntu + }, cluster_kwargs={ 'mode': consts.CLUSTER_MODES.ha_compact, 'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron, @@ -501,6 +505,69 @@ class TestDeploymentLCMSerialization90( serialized[1]['roles'] ) + @mock.patch.object( + adapters.PluginAdapterBase, 'repo_files', + mock.MagicMock(return_value=True) + ) + def test_plugins_in_serialized(self): + releases = [ + {'repository_path': 'repositories/ubuntu', + 'version': 'mitaka-9.0', 'os': 'ubuntu', + 'mode': ['ha', 'multinode'], + 'deployment_scripts_path': 'deployment_scripts/'} + ] + plugin1 = self.env.create_plugin( + cluster=self.cluster_db, + name='plugin_1', + attributes_metadata={'attributes': {'name': 'plugin_1'}}, + package_version='4.0.0', + releases=releases + ) + plugin2 = self.env.create_plugin( + cluster=self.cluster_db, + name='plugin_2', + attributes_metadata={'attributes': {'name': 'plugin_2'}}, + package_version='4.0.0', + releases=releases + ) + self.env.create_plugin( + cluster=self.cluster_db, + enabled=False, + name='plugin_3', + attributes_metadata={'attributes': {'name': 'plugin_3'}}, + package_version='4.0.0', + releases=releases + ) + + self.env.create_node( + cluster_id=self.cluster_db.id, + roles=['compute'] + ) + plugins_data = [ + { + 'name': p.name, + 'scripts': [{ + 'remote_url': p.master_scripts_path(self.cluster_db), + 'local_path': p.slaves_scripts_path + }], + 'repositories': [{ + 'type': 'deb', + 'name': p.full_name, + 'uri': p.repo_url(self.cluster_db), + 'suite': '/', + 'section': '', + 'priority': 1100 + }] + } + for p in six.moves.map(adapters.wrap_plugin, [plugin1, plugin2]) + ] + objects.Cluster.prepare_for_deployment(self.cluster_db) + serialized = self.serializer.serialize( + self.cluster_db, self.cluster_db.nodes) + for node in serialized: + self.assertIn('plugins', node) + self.datadiff(plugins_data, node['plugins'], compare_sorted=True) + class TestDeploymentHASerializer90( TestSerializer90Mixin,