Exemplo n.º 1
0
    def test_node_create_with_bad_cluster(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        body = {
            'node': {
                'name': 'test_node',
                'profile_id': 'xxxx-yyyy-zzzz',
                'cluster_id': 'non-existent-cluster',
                'role': None,
                'metadata': {},
            }
        }
        req = self._post('/nodes', jsonutils.dumps(body))

        error = senlin_exc.ClusterNotFound(cluster='non-existent-cluster')
        mock_call = self.patchobject(rpc_client.EngineClient, 'call',
                                     side_effect=error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.create,
                                              req, body=body)

        mock_call.assert_called_once_with(req.context,
                                          ('node_create', body['node']))
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ClusterNotFound', resp.json['error']['type'])
Exemplo n.º 2
0
    def test_node_action_join_cluster_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'action', True)
        node_id = 'test-node-1'
        cluster_id = 'unknown-cluster'
        body = {
            'join': {
                'cluster_id': cluster_id,
            }
        }
        req = self._put('/nodes/%(node_id)s/action' % {'node_id': node_id},
                        json.dumps(body))

        error = senlin_exc.ClusterNotFound(cluster=cluster_id)
        mock_call = self.patchobject(rpc_client.EngineClient, 'call')
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.action,
                                              req,
                                              tenant_id=self.project,
                                              node_id=node_id,
                                              body=body)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ClusterNotFound', resp.json['error']['type'])
Exemplo n.º 3
0
    def test_receiver_create_with_cluster_id_notfound(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        cluster_id = 'FAKE_ID'
        body = {
            'receiver': {
                'name': 'test_receiver',
                'type': 'webhook',
                'cluster_id': cluster_id,
                'action': 'test_action',
            }
        }
        req = self._post('/receivers', jsonutils.dumps(body))

        error = senlin_exc.ClusterNotFound(cluster=cluster_id)
        mock_call = self.patchobject(rpc_client.EngineClient,
                                     'call',
                                     side_effect=error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.create,
                                              req,
                                              body=body)

        expected_args = body['receiver']
        type_name = expected_args.pop('type')
        expected_args['type_name'] = type_name
        expected_args['actor'] = None
        expected_args['params'] = None
        mock_call.assert_called_once_with(req.context,
                                          ('receiver_create', expected_args))
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ClusterNotFound', resp.json['error']['type'])
Exemplo n.º 4
0
 def test_receiver_create_cluster_not_found(self, mock_find):
     mock_find.side_effect = exc.ClusterNotFound(cluster='C1')
     ex = self.assertRaises(rpc.ExpectedException, self.eng.receiver_create,
                            self.ctx, 'r1', 'webhook', 'C1', 'whatever')
     self.assertEqual(exc.BadRequest, ex.exc_info[0])
     self.assertEqual(
         "The request is malformed: The referenced cluster "
         "'C1' is not found.", six.text_type(ex.exc_info[1]))
Exemplo n.º 5
0
    def test_action_create_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ClusterNotFound(cluster='C1')

        ex = self.assertRaises(rpc.ExpectedException, self.eng.action_create,
                               self.ctx, 'a1', 'C1', 'OBJECT_ACTION')

        self.assertEqual(exc.ClusterNotFound, ex.exc_info[0])
        mock_find.assert_called_once_with(self.ctx, 'C1')
Exemplo n.º 6
0
    def test_cluster_policy_list_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ClusterNotFound(cluster='Bogus')

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_list, self.ctx, 'Bogus')

        self.assertEqual("The cluster (Bogus) could not be found.",
                         six.text_type(ex.exc_info[1]))
Exemplo n.º 7
0
def cluster_update(context, cluster_id, values):
    with session_for_write() as session:
        cluster = session.query(models.Cluster).get(cluster_id)

        if not cluster:
            raise exception.ClusterNotFound(cluster=cluster_id)

        cluster.update(values)
        cluster.save(session)
Exemplo n.º 8
0
    def load(cls, context, cluster_id=None, dbcluster=None, project_safe=True):
        '''Retrieve a cluster from database.'''
        if dbcluster is None:
            dbcluster = co.Cluster.get(context, cluster_id,
                                       project_safe=project_safe)
            if dbcluster is None:
                raise exception.ClusterNotFound(cluster=cluster_id)

        return cls._from_object(context, dbcluster)
Exemplo n.º 9
0
    def load(cls, context, cluster_id=None, cluster=None, project_safe=True):
        '''Retrieve a cluster from database.'''
        if cluster is None:
            cluster = db_api.cluster_get(context,
                                         cluster_id,
                                         project_safe=project_safe)
            if cluster is None:
                raise exception.ClusterNotFound(cluster=cluster_id)

        return cls._from_db_record(context, cluster)
Exemplo n.º 10
0
    def load(cls, context, cluster_id=None, cluster=None, show_deleted=False):
        '''Retrieve a cluster from database.'''
        if cluster is None:
            cluster = db_api.cluster_get(context,
                                         cluster_id,
                                         show_deleted=show_deleted)
            if cluster is None:
                raise exception.ClusterNotFound(cluster=cluster_id)

        return cls._from_db_record(context, cluster)
Exemplo n.º 11
0
    def test_cluster_policy_detach_cluster_not_found(self, mock_cluster):
        mock_cluster.side_effect = exc.ClusterNotFound(cluster='Bogus')

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_detach, self.ctx,
                               'Bogus', 'POLICY_ID')

        self.assertEqual(exc.ClusterNotFound, ex.exc_info[0])
        self.assertEqual("The cluster (Bogus) could not be found.",
                         six.text_type(ex.exc_info[1]))
        mock_cluster.assert_called_once_with(self.ctx, 'Bogus')
Exemplo n.º 12
0
    def test_node_list_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ClusterNotFound(cluster='BOGUS')

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.node_list,
                               self.ctx,
                               cluster_id='BOGUS')

        self.assertEqual(exc.ClusterNotFound, ex.exc_info[0])
        self.assertEqual("The cluster (BOGUS) could not be found.",
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'BOGUS')
Exemplo n.º 13
0
    def test_webhook_trigger_cluster_not_found(self, mock_cluster, mock_find):
        receiver = mock.Mock()
        receiver.cluster_id = 'BOGUS'
        mock_find.return_value = receiver
        mock_cluster.side_effect = exception.ClusterNotFound(cluster='BOGUS')
        ex = self.assertRaises(rpc.ExpectedException, self.eng.webhook_trigger,
                               self.ctx, 'RRR')

        self.assertEqual(exception.BadRequest, ex.exc_info[0])
        self.assertEqual(
            'The request is malformed: The referenced cluster '
            '(BOGUS) is not found.', six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'RRR')
        mock_cluster.assert_called_once_with(self.ctx, 'BOGUS')
Exemplo n.º 14
0
    def test_node_index_cluster_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'index', True)
        cluster_id = 'non-existent'
        req = self._get('/nodes', {'cluster_id': cluster_id})

        error = senlin_exc.ClusterNotFound(cluster=cluster_id)
        self.patchobject(rpc_client.EngineClient, 'call',
                         side_effect=shared.to_remote_error(error))

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.index, req)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ClusterNotFound', resp.json['error']['type'])
Exemplo n.º 15
0
 def test_openstack_exception_with_kwargs(self):
     wrapper = fault.FaultWrapper(None)
     msg = wrapper._error(senlin_exc.ClusterNotFound(cluster='a'))
     expected = {
         'code': 404,
         'error': {
             'code': 404,
             'message': 'The cluster (a) could not be found.',
             'type': 'ClusterNotFound'
         },
         'explanation': 'The resource could not be found.',
         'title': 'Not Found'
     }
     self.assertEqual(expected, msg)
Exemplo n.º 16
0
    def test_node_create_cluster_not_found(self, mock_profile, mock_cluster):
        mock_profile.return_value = mock.Mock()
        mock_cluster.side_effect = exc.ClusterNotFound(cluster='Bogus')

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.node_create,
                               self.ctx,
                               'node-1',
                               'FAKE_PROFILE',
                               cluster_id='Bogus')

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual(
            "The request is malformed: The specified cluster "
            "(Bogus) is not found.", six.text_type(ex.exc_info[1]))
        mock_profile.assert_called_once_with(self.ctx, 'FAKE_PROFILE')
        mock_cluster.assert_called_once_with(self.ctx, 'Bogus')
Exemplo n.º 17
0
def cluster_delete(context, cluster_id):
    with session_for_write() as session:
        cluster = session.query(models.Cluster).get(cluster_id)
        if cluster is None:
            raise exception.ClusterNotFound(cluster=cluster_id)

        query = session.query(models.Node).filter_by(cluster_id=cluster_id)
        nodes = query.all()

        if len(nodes) != 0:
            for node in nodes:
                session.delete(node)

        # Delete all related cluster_policies records
        for cp in cluster.policies:
            session.delete(cp)

        # Delete cluster
        session.delete(cluster)
Exemplo n.º 18
0
 def test_remote_exception(self):
     cfg.CONF.set_override('debug', True, enforce_type=True)
     error = senlin_exc.ClusterNotFound(cluster='a')
     exc_info = (type(error), error, None)
     serialized = rpc_common.serialize_remote_exception(exc_info)
     remote_error = rpc_common.deserialize_remote_exception(
         serialized, ["senlin.common.exception"])
     wrapper = fault.FaultWrapper(None)
     msg = wrapper._error(remote_error)
     expected_message = six.text_type(remote_error).split('\n', 1)[0]
     expected = {
         'code': 404,
         'error': {
             'code': 404,
             'message': expected_message,
             'type': 'ClusterNotFound'
         },
         'explanation': 'The resource could not be found.',
         'title': 'Not Found'
     }
     self.assertEqual(expected, msg)
Exemplo n.º 19
0
    def test_webhook_create_with_obj_id_notfound(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        obj_id = 'false_obj_id'
        body = {
            'webhook': {
                'name': 'test_webhook',
                'obj_type': 'cluster',
                'obj_id': obj_id,
                'action': 'test_action',
                'credential': {
                    'user_id': 'test_user_id',
                    'password': '******',
                },
                'params': {
                    'test_param': 'test_value'
                },
            }
        }
        req = self._post('/webhooks', json.dumps(body))

        error = senlin_exc.ClusterNotFound(cluster=obj_id)
        mock_call = self.patchobject(rpc_client.EngineClient,
                                     'call',
                                     side_effect=error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.create,
                                              req,
                                              tenant_id=self.project,
                                              body=body)

        expected_args = body['webhook']
        mock_call.assert_called_once_with(req.context,
                                          ('webhook_create', expected_args))
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ClusterNotFound', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])