Пример #1
0
    def test_get_particular_role_for_cluster_w_plugin(self):
        plugin_data = self.env.get_default_plugin_metadata()
        plugin_data['roles_metadata'] = self.ROLES
        plugin_data['volumes_metadata'] = self.VOLUMES
        plugin = objects.Plugin.create(plugin_data)
        self.cluster.plugins.append(plugin)
        objects.ClusterPlugin.set_attributes(self.cluster.id,
                                             plugin.id,
                                             enabled=True)
        self.db.flush()
        plugin_adapter = plugins.wrap_plugin(plugin)

        role = self.app.get(
            url=base.reverse('ClusterRolesHandler', {
                'cluster_id': self.cluster.id,
                'role_name': 'test_role'
            })).json

        self.assertEqual(role['name'], 'test_role')
        self.assertDictEqual(
            role['meta'],
            plugin_adapter.normalized_roles_metadata['test_role'])
        self.assertItemsEqual(
            role['volumes_roles_mapping'],
            plugin_adapter.volumes_metadata['volumes_roles_mapping']
            ['test_role'])
    def test_get_particular_role_for_cluster_w_plugin(self):
        plugin_data = self.env.get_default_plugin_metadata()
        plugin_data['roles_metadata'] = self.ROLES
        plugin_data['volumes_metadata'] = self.VOLUMES
        plugin = objects.Plugin.create(plugin_data)
        self.cluster.plugins.append(plugin)
        objects.ClusterPlugin.set_attributes(self.cluster.id,
                                             plugin.id,
                                             enabled=True)
        self.db.flush()
        plugin_adapter = plugins.wrap_plugin(plugin)

        role = self.app.get(
            url=base.reverse(
                'ClusterRolesHandler',
                {'cluster_id': self.cluster.id, 'role_name': 'test_role'}
            )
        ).json

        self.assertEqual(role['name'], 'test_role')
        self.assertDictEqual(
            role['meta'],
            plugin_adapter.normalized_roles_metadata['test_role']
        )
        self.assertItemsEqual(
            role['volumes_roles_mapping'],
            plugin_adapter.volumes_metadata[
                'volumes_roles_mapping']['test_role']
        )
 def _create_plugin(self):
     plugin_data = self.env.get_default_plugin_metadata()
     plugin_data['roles_metadata'] = self.ROLES
     plugin_data['volumes_metadata'] = self.VOLUMES
     plugin = objects.Plugin.create(plugin_data)
     self.cluster.plugins.append(plugin)
     objects.ClusterPlugin.set_attributes(self.cluster.id,
                                          plugin.id,
                                          enabled=True)
     self.db.flush()
     return plugins.wrap_plugin(plugin)
Пример #4
0
 def _create_plugin(self):
     plugin_data = self.env.get_default_plugin_metadata()
     plugin_data['roles_metadata'] = self.ROLES
     plugin_data['volumes_metadata'] = self.VOLUMES
     plugin = objects.Plugin.create(plugin_data)
     self.cluster.plugins.append(plugin)
     objects.ClusterPlugin.set_attributes(self.cluster.id,
                                          plugin.id,
                                          enabled=True)
     self.db.flush()
     return plugins.wrap_plugin(plugin)
Пример #5
0
    def is_compatible(cls, cluster, plugin):
        """Validates if plugin is compatible with cluster.

        :param cluster: A cluster instance
        :type cluster: nailgun.db.sqlalchemy.models.cluster.Cluster
        :param plugin: A plugin instance
        :type plugin: nailgun.db.sqlalchemy.models.plugins.Plugin
        :return: True if compatible, False if not
        :rtype: bool
        """
        plugin_adapter = plugins.wrap_plugin(plugin)

        return plugin_adapter.validate_compatibility(cluster)
Пример #6
0
    def is_compatible(cls, cluster, plugin):
        """Validates if plugin is compatible with cluster.

        :param cluster: A cluster instance
        :type cluster: nailgun.db.sqlalchemy.models.cluster.Cluster
        :param plugin: A plugin instance
        :type plugin: nailgun.db.sqlalchemy.models.plugins.Plugin
        :return: True if compatible, False if not
        :rtype: bool
        """
        plugin_adapter = plugins.wrap_plugin(plugin)

        return plugin_adapter.validate_compatibility(cluster)
Пример #7
0
    def setUp(self):
        super(TestPrePostHooks, self).setUp()

        self._requests_mock = mock.patch(
            'nailgun.utils.debian.requests.get',
            return_value=mock.Mock(text='Archive: test'))
        self._requests_mock.start()

        resp = self.env.create_plugin(api=True, tasks=self.TASKS_CONFIG)
        self.plugin = plugins.wrap_plugin(
            objects.Plugin.get_by_uid(resp.json['id']))
        self.cluster = self.create_cluster([
            {'roles': ['controller'], 'pending_addition': True},
            {'roles': ['compute'], 'pending_addition': True}]
        )
        objects.Cluster.prepare_for_deployment(self.cluster)

        self.enable_plugin(
            self.cluster, self.sample_plugin['name'], resp.json['id']
        )
Пример #8
0
    def setUp(self):
        super(TestPrePostHooks, self).setUp()

        self._requests_mock = mock.patch(
            'nailgun.utils.debian.requests.get',
            return_value=mock.Mock(text='Archive: test'))
        self._requests_mock.start()

        resp = self.env.create_plugin(api=True, tasks=self.TASKS_CONFIG)
        self.plugin = plugins.wrap_plugin(
            objects.Plugin.get_by_uid(resp.json['id']))
        self.cluster = self.create_cluster([
            {'roles': ['controller'], 'pending_addition': True},
            {'roles': ['compute'], 'pending_addition': True}]
        )
        objects.Cluster.prepare_for_deployment(self.cluster)

        self.enable_plugin(
            self.cluster, self.sample_plugin['name'], resp.json['id']
        )
Пример #9
0
    def setUp(self):
        super(TestPluginBase, self).setUp()
        self.plugin_metadata = self.env.get_default_plugin_metadata(
            package_version=self.package_version,
            roles_metadata={
                'role_x': {
                    'name': 'Role X',
                    'description': 'Role X is ...',
                },
                'role_y': {
                    'name': 'Role Y',
                    'description': 'Role Y is ...',
                    'restrictions': [],
                    'fault_tolerance': '5%'
                },
                'role_z': {
                    'name': 'Role Z',
                    'description': 'Role Z is ...',
                    'restrictions': ['settings:some.stuff.value == false'],
                    'fault_tolerance': '10%'
                }
            })
        self.plugin = Plugin.create(self.plugin_metadata)
        self.cluster = self.env.create(
            cluster_kwargs={'mode': consts.CLUSTER_MODES.multinode},
            release_kwargs={
                'version':
                '2015.1-8.0',
                'operating_system':
                'Ubuntu',
                'modes': [
                    consts.CLUSTER_MODES.multinode,
                    consts.CLUSTER_MODES.ha_compact
                ]
            })
        self.plugin_adapter = plugins.wrap_plugin(self.plugin)
        self.env_config = self.env.get_default_plugin_env_config()
        self.get_config = lambda *args: mock.mock_open(read_data=yaml.dump(
            self.env_config))()

        db().flush()
Пример #10
0
    def create(cls, data):
        """Create plugin.

        WARNING: don't pass keys with none to non nullable fields.

        :param data: data
        :type data: dict

        :return: plugin instance
        :rtype: models.Plugin
        """
        graphs = {}
        for graph in data.pop("graphs", []):
            graphs[graph.pop('type')] = graph

        deployment_tasks = data.pop("deployment_tasks", [])
        data['releases'] = [
            r for r in data.pop("releases", [])
            if not r.get('is_release', False)
        ]

        plugin_obj = super(Plugin, cls).create(data)

        if not graphs.get(consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE):
            graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \
                {'tasks': deployment_tasks}

        for graph_type, graph_data in six.iteritems(graphs):
            DeploymentGraph.create_for_model(graph_data, plugin_obj,
                                             graph_type)

        plugin_adapter = plugins.wrap_plugin(plugin_obj)

        # todo(ikutukov): this update is a smell from the current plugins
        # installation schema. Remove it.
        plugin_meta = cls._process_tags(plugin_adapter.get_metadata())
        cls.update(plugin_obj, plugin_meta)

        ClusterPlugin.add_compatible_clusters(plugin_obj)

        return plugin_obj
Пример #11
0
    def create(cls, data):
        """Create plugin.

        WARNING: don't pass keys with none to non nullable fields.

        :param data: data
        :type data: dict

        :return: plugin instance
        :rtype: models.Plugin
        """
        graphs = {}
        for graph in data.pop("graphs", []):
            graphs[graph.pop('type')] = graph

        deployment_tasks = data.pop("deployment_tasks", [])
        data['releases'] = [
            r for r in data.pop("releases", [])
            if not r.get('is_release', False)
        ]

        plugin_obj = super(Plugin, cls).create(data)

        if not graphs.get(consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE):
            graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \
                {'tasks': deployment_tasks}

        for graph_type, graph_data in six.iteritems(graphs):
            DeploymentGraph.create_for_model(
                graph_data, plugin_obj, graph_type)

        plugin_adapter = plugins.wrap_plugin(plugin_obj)

        # todo(ikutukov): this update is a smell from the current plugins
        # installation schema. Remove it.

        cls.update(plugin_obj, plugin_adapter.get_metadata())

        ClusterPlugin.add_compatible_clusters(plugin_obj)

        return plugin_obj
Пример #12
0
    def setUp(self):
        super(TestPluginBase, self).setUp()
        self.plugin_metadata = self.env.get_default_plugin_metadata(
            package_version=self.package_version,
            roles_metadata={
                'role_x': {
                    'name': 'Role X',
                    'description': 'Role X is ...',
                },
                'role_y': {
                    'name': 'Role Y',
                    'description': 'Role Y is ...',
                    'restrictions': [],
                    'fault_tolerance': '5%'
                },
                'role_z': {
                    'name': 'Role Z',
                    'description': 'Role Z is ...',
                    'restrictions': [
                        'settings:some.stuff.value == false'
                    ],
                    'fault_tolerance': '10%'
                }
            }
        )
        self.plugin = Plugin.create(self.plugin_metadata)
        self.cluster = self.env.create(
            cluster_kwargs={'mode': consts.CLUSTER_MODES.multinode},
            release_kwargs={
                'version': '2015.1-8.0',
                'operating_system': 'Ubuntu',
                'modes': [consts.CLUSTER_MODES.multinode,
                          consts.CLUSTER_MODES.ha_compact]})
        self.plugin_adapter = plugins.wrap_plugin(self.plugin)
        self.env_config = self.env.get_default_plugin_env_config()
        self.get_config = lambda *args: mock.mock_open(
            read_data=yaml.dump(self.env_config))()

        db().flush()
Пример #13
0
    def create(cls, data):
        graphs = data.pop("graphs", {})
        deployment_tasks = data.pop("deployment_tasks", [])

        if not graphs.get(consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE):
            graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \
                {'tasks': deployment_tasks}
        plugin_obj = super(Plugin, cls).create(data)

        for graph_type, graph_data in six.iteritems(graphs):
            DeploymentGraph.create_for_model(
                graph_data, plugin_obj, graph_type)

        plugin_adapter = plugins.wrap_plugin(plugin_obj)

        # todo(ikutukov): this update is a smell from the current plugins
        # todo:           installation schema. Remove it.
        cls.update(plugin_obj, plugin_adapter.get_metadata())

        ClusterPlugin.add_compatible_clusters(plugin_obj)

        return plugin_obj
Пример #14
0
    def serialize_plugin(cls, cluster, plugin):
        os_name = cluster.release.operating_system
        adapter = plugins.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 serialize_plugin(cls, cluster, plugin):
        os_name = cluster.release.operating_system
        adapter = plugins.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.path_name,
                'uri': adapter.repo_url(cluster),
                'priority': settings.REPO_PRIORITIES['plugins']['centos']
            }
        elif os_name == consts.RELEASE_OS.ubuntu:
            repo = {
                'type': 'deb',
                'name': adapter.path_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