Ejemplo n.º 1
0
    def test_validate_extensions(self):
        global_exts = 'volume_manager', 'bareon', 'ultralogger'

        with mock.patch(
                'nailgun.api.v1.validators.extension.get_all_extensions',
                return_value=make_mock_extensions(global_exts)):

            ExtensionValidator.validate(jsonutils.dumps(global_exts))
Ejemplo n.º 2
0
    def test_validate_extensions(self):
        global_exts = 'volume_manager', 'bareon', 'ultralogger'

        with mock.patch(
                'nailgun.api.v1.validators.extension.get_all_extensions',
                return_value=make_mock_extensions(global_exts)):

            ExtensionValidator.validate(jsonutils.dumps(global_exts))
Ejemplo n.º 3
0
    def test_invalid_extension(self):
        global_exts = 'volume_manager', 'bareon', 'ultralogger'
        data = 'volume_manager', 'baleron'

        with mock.patch(
                'nailgun.api.v1.validators.extension.get_all_extensions',
                return_value=make_mock_extensions(global_exts)):

            with self.assertRaisesRegexp(errors.CannotFindExtension,
                                         'No such extensions: baleron'):

                ExtensionValidator.validate(jsonutils.dumps(data))
Ejemplo n.º 4
0
    def test_invalid_extension(self):
        global_exts = 'volume_manager', 'bareon', 'ultralogger'
        data = 'volume_manager', 'baleron'

        with mock.patch(
                'nailgun.api.v1.validators.extension.get_all_extensions',
                return_value=make_mock_extensions(global_exts)):

            with self.assertRaisesRegexp(errors.CannotFindExtension,
                                         'No such extensions: baleron'):

                ExtensionValidator.validate(jsonutils.dumps(data))
Ejemplo n.º 5
0
    def test_enabling_extensions(self):
        extensions = 'bareon', 'volume_manager'

        with mock.patch(
                'nailgun.api.v1.validators.extension.get_all_extensions',
                return_value=make_mock_extensions(extensions)):
            resp = self.app.put(
                reverse('ClusterExtensionsHandler',
                        kwargs={'cluster_id': self.cluster.id}),
                jsonutils.dumps(extensions),
                headers=self.default_headers,
            )
        self.assertEqual(resp.status_code, 200)

        self.db.refresh(self.cluster)
        for ext in extensions:
            self.assertIn(ext, self.cluster.extensions)
    def test_enabling_extensions(self):
        extensions = 'bareon', 'volume_manager'

        with mock.patch(
                'nailgun.api.v1.validators.extension.get_all_extensions',
                return_value=make_mock_extensions(extensions)):
            resp = self.app.put(
                reverse(
                    'ClusterExtensionsHandler',
                    kwargs={'cluster_id': self.cluster.id}),
                jsonutils.dumps(extensions),
                headers=self.default_headers,
            )
        self.assertEqual(resp.status_code, 200)

        self.db.refresh(self.cluster)
        self.assertItemsEqual(self.cluster.extensions, extensions)
Ejemplo n.º 7
0
    def test_enabling_invalid_extensions(self):
        existed_extensions = 'bareon', 'volume_manager'
        requested_extensions = 'network_manager', 'volume_manager'

        with mock.patch(
                'nailgun.api.v1.validators.extension.get_all_extensions',
                return_value=make_mock_extensions(existed_extensions)):
            resp = self.app.put(
                reverse('ClusterExtensionsHandler',
                        kwargs={'cluster_id': self.cluster.id}),
                jsonutils.dumps(requested_extensions),
                headers=self.default_headers,
                expect_errors=True,
            )
        self.assertEqual(resp.status_code, 400)
        self.assertIn(u"No such extensions:", resp.json_body['message'])
        self.assertIn(requested_extensions[0], resp.json_body['message'])
        self.assertNotIn(requested_extensions[1], resp.json_body['message'])
Ejemplo n.º 8
0
    def test_enabling_invalid_extensions(self):
        existed_extensions = 'bareon', 'volume_manager'
        requested_extensions = 'network_manager', 'volume_manager'

        with mock.patch(
                'nailgun.api.v1.validators.extension.get_all_extensions',
                return_value=make_mock_extensions(existed_extensions)):
            resp = self.app.put(
                reverse(
                    'ClusterExtensionsHandler',
                    kwargs={'cluster_id': self.cluster.id}),
                jsonutils.dumps(requested_extensions),
                headers=self.default_headers,
                expect_errors=True,
            )
        self.assertEqual(resp.status_code, 400)
        self.assertIn(u"No such extensions:", resp.json_body['message'])
        self.assertIn(requested_extensions[0], resp.json_body['message'])
        self.assertNotIn(requested_extensions[1], resp.json_body['message'])
Ejemplo n.º 9
0
class TestExtensionUtils(BaseTestCase):
    def make_node(self, node_extensions=[], cluster_extensions=[]):
        node = mock.MagicMock()
        node.extensions = node_extensions
        node.cluster.extensions = cluster_extensions

        return node

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_get_extension(self, get_m):
        extension = get_extension('ex1')
        self.assertEqual(extension.name, 'ex1')

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_get_extension_raises_errors(self, get_m):
        self.assertRaisesRegexp(
            errors.CannotFindExtension,
            "Cannot find extension with name 'unknown_ex'", get_extension,
            'unknown_ex')

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_node_extension_call_raises_error(self, _):
        self.assertRaisesRegexp(
            errors.CannotFindExtension,
            "Cannot find extension which provides 'method_call' call",
            node_extension_call, 'method_call', self.make_node())

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_node_extension_call_extension_from_node(self, get_m):
        node = self.make_node(node_extensions=['ex1'],
                              cluster_extensions=['ex2'])

        node_extension_call('method_call', node)
        ex1 = get_m.return_value[0]
        self.assertEqual('ex1', ex1.name)
        ex2 = get_m.return_value[1]
        self.assertEqual('ex2', ex2.name)

        ex1.method_call.assert_called_once_with(node)
        self.assertFalse(ex2.method_call.called)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_node_extension_call_default_extension_from_cluster(self, get_m):
        node = self.make_node(node_extensions=[], cluster_extensions=['ex2'])

        node_extension_call('method_call', node)
        ex1 = get_m.return_value[0]
        self.assertEqual('ex1', ex1.name)
        ex2 = get_m.return_value[1]
        self.assertEqual('ex2', ex2.name)

        self.assertFalse(ex1.method_call.called)
        ex2.method_call.assert_called_once_with(node)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_node_create(self, get_m):
        node = mock.MagicMock()
        fire_callback_on_node_create(node)

        for ext in get_m.return_value:
            ext.on_node_create.assert_called_once_with(node)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_node_update(self, get_m):
        node = mock.MagicMock()
        fire_callback_on_node_update(node)

        for ext in get_m.return_value:
            ext.on_node_update.assert_called_once_with(node)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_node_reset(self, get_m):
        node = mock.MagicMock()
        fire_callback_on_node_reset(node)

        for ext in get_m.return_value:
            ext.on_node_reset.assert_called_once_with(node)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_node_delete(self, get_m):
        node = mock.MagicMock()
        fire_callback_on_node_delete(node)

        for ext in get_m.return_value:
            ext.on_node_delete.assert_called_once_with(node)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_node_collection_delete(self, get_m):
        node_ids = [1, 2, 3, 4]
        fire_callback_on_node_collection_delete(node_ids)

        for ext in get_m.return_value:
            ext.on_node_collection_delete.assert_called_once_with(node_ids)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_cluster_deletion(self, get_m):
        cluster = mock.MagicMock()
        fire_callback_on_cluster_delete(cluster)

        for ext in get_m.return_value:
            ext.on_cluster_delete.assert_called_once_with(cluster)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_before_deployment_check(self, get_m):
        cluster = mock.MagicMock()
        cluster.extensions = ['ex1']
        fire_callback_on_before_deployment_check(cluster, mock.sentinel.nodes)

        ex1 = get_m.return_value[0]
        self.assertEqual('ex1', ex1.name)
        ex1.on_before_deployment_check.assert_called_once_with(
            cluster, mock.sentinel.nodes)
        ex2 = get_m.return_value[1]
        self.assertEqual('ex2', ex2.name)
        self.assertFalse(ex2.on_before_deployment_check.called)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_before_deployment_serialization(self, get_m):
        cluster = mock.MagicMock()
        cluster.extensions = ['ex1']
        fire_callback_on_before_deployment_serialization(
            cluster, mock.sentinel.nodes, mock.sentinel.ignore_customized)

        ex1 = get_m.return_value[0]
        self.assertEqual('ex1', ex1.name)
        ex1.on_before_deployment_serialization.assert_called_once_with(
            cluster, mock.sentinel.nodes, mock.sentinel.ignore_customized)
        ex2 = get_m.return_value[1]
        self.assertEqual('ex2', ex2.name)
        self.assertFalse(ex2.on_before_deployment_serialization.called)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_fire_callback_on_before_provisioning_serialization(self, get_m):
        cluster = mock.MagicMock()
        cluster.extensions = ['ex1']
        fire_callback_on_before_provisioning_serialization(
            cluster, mock.sentinel.nodes, mock.sentinel.ignore_customized)

        ex1 = get_m.return_value[0]
        self.assertEqual('ex1', ex1.name)
        ex1.on_before_provisioning_serialization.assert_called_once_with(
            cluster, mock.sentinel.nodes, mock.sentinel.ignore_customized)
        ex2 = get_m.return_value[1]
        self.assertEqual('ex2', ex2.name)
        self.assertFalse(ex2.on_before_provisioning_serialization.called)

    @mock.patch('nailgun.extensions.manager.get_all_extensions',
                return_value=make_mock_extensions())
    def test_setup_yaql_context(self, get_m):
        context = mock.Mock()
        setup_yaql_context(context)

        for ext in get_m.return_value:
            ext.setup_yaql_context.assert_called_once_with(context)