def test_get_all_attributes_by_interface_with_enabled_plugin(self):
        nic_config = self.env.get_default_plugin_nic_config()
        plugin = self.env.create_plugin(
            name='plugin_a_with_nic_attributes',
            package_version='5.0.0',
            nic_attributes_metadata=nic_config)
        cluster = self._create_test_cluster()
        # create node with 1 interface for easy testing
        node = self.env.create_nodes_w_interfaces_count(
            1, 1, **{"cluster_id": cluster.id})[0]
        interface = node.nic_interfaces[0]
        nic_plugin_id = node.node_nic_interface_cluster_plugins[0].id
        ClusterPlugin.set_attributes(cluster.id, plugin.id, enabled=True)

        attributes = NodeNICInterfaceClusterPlugin.\
            get_all_enabled_attributes_by_interface(interface)
        expected_attributes = {
            'plugin_a_with_nic_attributes': {
                'metadata': {
                    'label': 'Test base plugin',
                    'nic_plugin_id': nic_plugin_id,
                    'class': 'plugin'},
                'plugin_name_text': {
                    'value': 'value',
                    'type': 'text',
                    'description': 'Some description',
                    'weight': 25,
                    'label': 'label'}}}

        self.assertEqual(expected_attributes, attributes)
    def test_get_all_attributes_by_bond_with_enabled_plugin(self):
        plugin_bond_config = self.env.get_default_plugin_bond_config()
        plugin = self.env.create_plugin(
            name='plugin_a_with_bond_attributes',
            package_version='5.0.0',
            bond_attributes_metadata=plugin_bond_config)
        cluster = self._create_test_cluster()
        node = self.env.create_nodes_w_interfaces_count(
            1, 2, **{"cluster_id": cluster.id})[0]
        bond_config = {
            'type__': {'value': consts.BOND_TYPES.linux},
            'mode': {'value': {'value': consts.BOND_MODES.balance_rr}}}
        nic_names = [iface.name for iface in node.nic_interfaces]
        self.env.make_bond_via_api(
            'lnx_bond', '', nic_names, node.id, attrs=bond_config)
        bond = node.bond_interfaces[0]
        bond_plugin_id = node.node_bond_interface_cluster_plugins[0].id
        ClusterPlugin.set_attributes(cluster.id, plugin.id, enabled=True)

        attributes = NodeBondInterfaceClusterPlugin.\
            get_all_enabled_attributes_by_bond(bond)
        expected_attributes = {
            'plugin_a_with_bond_attributes': {
                'metadata': {
                    'label': 'Test base plugin',
                    'bond_plugin_id': bond_plugin_id,
                    'class': 'plugin'},
                'plugin_name_text': {
                    'value': 'value',
                    'type': 'text',
                    'description': 'Some description',
                    'weight': 25,
                    'label': 'label'}}}

        self.assertEqual(expected_attributes, attributes)
Beispiel #3
0
    def setUp(self):
        super(TestNailgunReceiver, self).setUp()

        self.cluster = self.env.create(
            status=consts.CLUSTER_STATUSES.operational,
            nodes_kwargs=[{
                'roles': ['controller'],
                'status': consts.NODE_STATUSES.ready
            }])

        for i in range(2):
            meta = self.env.get_default_plugin_metadata(
                name='name{0}'.format(i),
                title='title{0}'.format(i),
                description='description{0}'.format(i))

            self.plugin = Plugin.create(meta)
            self.cluster.plugins.append(self.plugin)
            ClusterPlugin.set_attributes(self.cluster.id,
                                         self.plugin.id,
                                         enabled=True)

        self.task = self.env.create_task(name=consts.TASK_NAMES.deployment,
                                         status=consts.TASK_STATUSES.ready,
                                         cluster_id=self.cluster.id)
Beispiel #4
0
    def setUp(self):
        super(TestNailgunReceiver, self).setUp()

        self.cluster = self.env.create(
            status=consts.CLUSTER_STATUSES.operational,
            nodes_kwargs=[
                {'roles': ['controller'],
                 'status': consts.NODE_STATUSES.ready}])

        for i in range(2):
            meta = self.env.get_default_plugin_metadata(
                name='name{0}'.format(i),
                title='title{0}'.format(i),
                description='description{0}'.format(i))

            self.plugin = Plugin.create(meta)
            self.cluster.plugins.append(self.plugin)
            ClusterPlugin.set_attributes(self.cluster.id,
                                         self.plugin.id,
                                         enabled=True)

        self.task = self.env.create_task(
            name=consts.TASK_NAMES.deployment,
            status=consts.TASK_STATUSES.ready,
            cluster_id=self.cluster.id)
    def test_is_plugin_used(self):
        self._create_test_plugins()
        cluster = self._create_test_cluster()

        plugin = ClusterPlugin.get_connected_plugins(cluster).first()
        self.assertFalse(ClusterPlugin.is_plugin_used(plugin.id))
        ClusterPlugin.set_attributes(cluster.id, plugin.id, enabled=True)
        self.assertTrue(ClusterPlugin.is_plugin_used(plugin.id))
    def test_get_enabled(self):
        self._create_test_plugins()
        cluster = self._create_test_cluster()

        plugin = ClusterPlugin.get_connected_plugins(cluster).first()
        ClusterPlugin.set_attributes(cluster.id, plugin.id, enabled=True)

        enabled_plugin = ClusterPlugin.get_enabled(cluster.id).first()
        self.assertEqual(plugin.id, enabled_plugin.id)
    def test_get_enabled_plugins(self):
        plugin_a = self._create_plugin(**self._compat_meta)
        plugin_b = self._create_plugin(**self._compat_meta)

        ClusterPlugin.set_attributes(
            self.cluster.id, plugin_a.id, enabled=True)

        compat_plugins = ClusterPlugin.get_compatible_plugins(self.cluster)
        self.assertItemsEqual(compat_plugins, [plugin_a, plugin_b])

        enabled_plugins = ClusterPlugin.get_enabled(self.cluster.id)
        self.assertItemsEqual(enabled_plugins, [plugin_a])
    def test_get_enabled_plugins(self):
        plugin_a = self._create_plugin(**self._compat_meta)
        plugin_b = self._create_plugin(**self._compat_meta)

        ClusterPlugin.set_attributes(
            self.cluster.id, plugin_a.id, enabled=True)

        compat_plugins = ClusterPlugin.get_compatible_plugins(self.cluster)
        self.assertItemsEqual(compat_plugins, [plugin_a, plugin_b])

        enabled_plugins = ClusterPlugin.get_enabled(self.cluster.id)
        self.assertItemsEqual(enabled_plugins, [plugin_a])
    def test_set_plugin_attributes(self):
        meta = base.reflect_db_metadata()
        self._create_test_plugins()
        cluster = self._create_test_cluster()

        plugin = ClusterPlugin.get_connected_plugins(cluster).first()
        ClusterPlugin.set_attributes(cluster.id, plugin.id, enabled=True)

        columns = meta.tables["cluster_plugins"].c
        enabled = self.db.execute(
            sa.select([columns.enabled]).where(columns.cluster_id == cluster.id).where(columns.plugin_id == plugin.id)
        ).fetchone()
        self.assertTrue(enabled[0])
Beispiel #10
0
    def test_set_plugin_attributes(self):
        meta = base.reflect_db_metadata()
        self._create_test_plugins()
        cluster = self._create_test_cluster()

        plugin = ClusterPlugin.get_connected_plugins(cluster).first()
        ClusterPlugin.set_attributes(cluster.id, plugin.id, enabled=True)

        columns = meta.tables['cluster_plugins'].c
        enabled = self.db.execute(
            sa.select([columns.enabled
                       ]).where(columns.cluster_id == cluster.id).where(
                           columns.plugin_id == plugin.id)).fetchone()
        self.assertTrue(enabled[0])
 def test_get_connected_for_specific_plugins(self):
     plugin_ids = self._create_test_plugins()
     cluster = self._create_test_cluster()
     number_of_connected_plugins =\
         ClusterPlugin.get_connected_plugins(
             cluster, plugin_ids[1:]).count()
     self.assertEqual(6, number_of_connected_plugins)
    def test_add_nodes_for_cluster_plugin_with_empty_attributes(self):
        meta = base.reflect_db_metadata()
        self.env.create_node(
            cluster_id=self.cluster.id,
            roles=['compute']
        )
        plugin = Plugin.create({
            'name': 'plugin_a_with_node_attributes',
            'title': 'Test Plugin',
            'package_version': '5.0.0',
            'version': '1.0.0',
            'node_attributes_metadata': {}
        })
        cluster_plugin = ClusterPlugin.create({
            'cluster_id': self.cluster.id,
            'plugin_id': plugin.id,
            'enabled': False,
            'attributes': plugin.node_attributes_metadata
        })

        NodeClusterPlugin.add_nodes_for_cluster_plugin(cluster_plugin)

        node_cluster_plugins = self.db.execute(
            meta.tables['node_cluster_plugins'].select()
        ).fetchall()
        self.assertEqual(0, len(node_cluster_plugins))
 def test_get_connected_clusters(self):
     plugin_id = self._create_test_plugins()[0]
     for _ in range(2):
         self._create_test_cluster()
     number_of_connected_clusters =\
         ClusterPlugin.get_connected_clusters(plugin_id).count()
     self.assertEqual(2, number_of_connected_clusters)
    def test_get_compatible_plugins_for_new_cluster(self):
        plugin_a = self._create_plugin(**self._compat_meta)
        plugin_b = self._create_plugin(**self._compat_meta)
        self._create_plugin(**self._uncompat_meta)

        cluster = self.env.create(
            cluster_kwargs={
                'release_id': self.cluster.release.id,
                'mode': consts.CLUSTER_MODES.ha_compact,
            })

        compat_plugins = ClusterPlugin.get_compatible_plugins(cluster)
        self.assertItemsEqual(compat_plugins, [plugin_a, plugin_b])
    def test_get_compatible_plugins_for_new_cluster(self):
        plugin_a = self._create_plugin(**self._compat_meta)
        plugin_b = self._create_plugin(**self._compat_meta)
        self._create_plugin(**self._uncompat_meta)

        cluster = self.env.create(
            cluster_kwargs={
                'release_id': self.cluster.release.id,
                'mode': consts.CLUSTER_MODES.ha_compact,
            })

        compat_plugins = ClusterPlugin.get_compatible_plugins(cluster)
        self.assertItemsEqual(compat_plugins, [plugin_a, plugin_b])
Beispiel #16
0
    def test_enable_plugins_by_component(self):
        self.env.create_plugin(
            name='plugin_with_test_storage',
            package_version='4.0.0',
            fuel_version=['8.0'],
            releases=[{
                'repository_path': 'repositories/ubuntu',
                'version': '2015.1-8.3',
                'os': 'ubuntu',
                'mode': ['ha'],
                'deployment_scripts_path': 'deployment_scripts/'
            }],
            components_metadata=self.env.get_default_components(
                name='storage:test_storage'))

        plugin = self.env.create_plugin(
            version='1.0.0',
            name='plugin_with_test_storage',
            package_version='4.0.0',
            fuel_version=['8.0'],
            releases=[{
                'repository_path': 'repositories/ubuntu',
                'version': '2015.1-8.3',
                'os': 'ubuntu',
                'mode': ['ha'],
                'deployment_scripts_path': 'deployment_scripts/'
            }],
            components_metadata=self.env.get_default_components(
                name='storage:test_storage'))

        cluster = self.env.create(
            release_kwargs={
                'operating_system': consts.RELEASE_OS.ubuntu,
                'version': '2015.1-8.3'
            },
            cluster_kwargs={
                'mode':
                consts.CLUSTER_MODES.ha_compact,
                'api':
                False,
                'components':
                ['hypervisor:test_hypervisor', 'storage:test_storage']
            })

        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        self.assertItemsEqual([plugin], enabled_plugins)
    def test_enable_plugins_by_component(self):
        self.env.create_plugin(
            name='plugin_with_test_storage',
            package_version='4.0.0',
            fuel_version=['8.0'],
            releases=[{
                'repository_path': 'repositories/ubuntu',
                'version': '2015.1-8.3',
                'os': 'ubuntu',
                'mode': ['ha'],
                'deployment_scripts_path': 'deployment_scripts/'}],
            components_metadata=self.env.get_default_components(
                name='storage:test_storage'))

        plugin = self.env.create_plugin(
            version='1.0.0',
            name='plugin_with_test_storage',
            package_version='4.0.0',
            fuel_version=['8.0'],
            releases=[{
                'repository_path': 'repositories/ubuntu',
                'version': '2015.1-8.3',
                'os': 'ubuntu',
                'mode': ['ha'],
                'deployment_scripts_path': 'deployment_scripts/'}],
            components_metadata=self.env.get_default_components(
                name='storage:test_storage'))

        cluster = self.env.create(
            release_kwargs={
                'operating_system': consts.RELEASE_OS.ubuntu,
                'version': '2015.1-8.3'},
            cluster_kwargs={
                'mode': consts.CLUSTER_MODES.ha_compact,
                'api': False,
                'components': [
                    'hypervisor:test_hypervisor',
                    'storage:test_storage']})

        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        self.assertItemsEqual([plugin], enabled_plugins)
Beispiel #18
0
 def validate_delete(cls, data, instance):
     if ClusterPlugin.is_plugin_used(instance.id):
         raise errors.CannotDelete(
             "Can't delete plugin which is enabled "
             "for some environment."
         )
 def validate_with_cluster(self, **kwargs):
     cluster = self.cluster_mock(**kwargs)
     return ClusterPlugin.is_compatible(cluster, self.plugin)
Beispiel #20
0
 def validate_with_cluster(self, **kwargs):
     cluster = self.cluster_mock(**kwargs)
     return ClusterPlugin.is_compatible(cluster, self.plugin)
    def test_get_compatible_plugins(self):
        plugin_a = self._create_plugin(**self._compat_meta)
        self._create_plugin(**self._uncompat_meta)

        compat_plugins = ClusterPlugin.get_compatible_plugins(self.cluster)
        self.assertItemsEqual(compat_plugins, [plugin_a])
Beispiel #22
0
 def validate_delete(cls, data, instance):
     if ClusterPlugin.is_plugin_used(instance.id):
         raise errors.CannotDelete("Can't delete plugin which is enabled "
                                   "for some environment.")
    def test_get_compatible_plugins(self):
        plugin_a = self._create_plugin(**self._compat_meta)
        self._create_plugin(**self._uncompat_meta)

        compat_plugins = ClusterPlugin.get_compatible_plugins(self.cluster)
        self.assertItemsEqual(compat_plugins, [plugin_a])
 def test_get_connected_plugins_data(self):
     self._create_test_plugins()
     cluster = self._create_test_cluster()
     number_of_connected_plugins_data_items =\
         ClusterPlugin.get_connected_plugins_data(cluster.id).count()
     self.assertEqual(7, number_of_connected_plugins_data_items)
 def test_get_all_connected_plugins(self):
     self._create_test_plugins()
     cluster = self._create_test_cluster()
     number_of_connected_plugins =\
         ClusterPlugin.get_connected_plugins(cluster).count()
     self.assertEqual(7, number_of_connected_plugins)