示例#1
0
    def test_policy_get2_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='policy',
                                                     id='Fake')
        req = orpo.PolicyGetRequest(identity='POLICY')

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.policy_get2,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
示例#2
0
    def load(cls, ctx, profile=None, profile_id=None, project_safe=True):
        '''Retrieve a profile object from database.'''
        if profile is None:
            profile = po.Profile.get(ctx,
                                     profile_id,
                                     project_safe=project_safe)
            if profile is None:
                raise exc.ResourceNotFound(type='profile', id=profile_id)

        return cls.from_object(profile)
示例#3
0
 def test_get2_cluster_not_found(self, mock_find):
     mock_find.side_effect = exc.ResourceNotFound(type='cluster', id='cid')
     req = orcp.ClusterPolicyGetRequest(identity='cid', policy_id='pid')
     ex = self.assertRaises(rpc.ExpectedException,
                            self.svc.cluster_policy_get, self.ctx,
                            req.obj_to_primitive())
     self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
     self.assertEqual("The cluster 'cid' could not be found.",
                      six.text_type(ex.exc_info[1]))
     mock_find.assert_called_once_with(self.ctx, 'cid')
    def test__get_random_node_cluster_not_found(self, mock_load):
        mock_load.side_effect = exc.ResourceNotFound(type='cluster',
                                                     id='host_cluster')
        ctx = mock.Mock()
        profile = dp.DockerProfile('container', self.spec)

        ex = self.assertRaises(exc.InternalError, profile._get_random_node,
                               ctx, 'host_cluster')

        msg = _("The host cluster 'host_cluster' could not be found.")
        self.assertEqual(msg, ex.message)
示例#5
0
    def test_policy_update_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='policy', id='Fake')
        p_req = orpo.PolicyUpdateRequestBody(name='NEW_NAME')
        request = {'identity': 'Fake', 'policy': p_req}

        req = orpo.PolicyUpdateRequest(**request)

        ex = self.assertRaises(rpc.ExpectedException, self.svc.policy_update,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
示例#6
0
    def test_profile_get_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='profile',
                                                     id='Bogus')
        req = vorp.ProfileGetRequest(identity='Bogus')
        ex = self.assertRaises(rpc.ExpectedException, self.eng.profile_get,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual("The profile 'Bogus' could not be found.",
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'Bogus')
示例#7
0
    def test_node_recover2_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='node', id='Bogus')

        req = orno.NodeRecoverRequest(identity='Bogus')
        ex = self.assertRaises(rpc.ExpectedException, self.eng.node_recover2,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual('The node (Bogus) could not be found.',
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'Bogus')
示例#8
0
    def test_cluster_op_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='cluster',
                                                     id='Bogus')
        req = orco.ClusterOperationRequest(identity='Bogus', operation='dance')
        ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_op,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, 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')
    def test__get_host_node_not_found(self, mock_load):
        mock_load.side_effect = exc.ResourceNotFound(type='node',
                                                     id='fake_node')
        profile = dp.DockerProfile('container', self.spec)
        ctx = mock.Mock()

        ex = self.assertRaises(exc.InternalError, profile._get_host, ctx,
                               'fake_node', None)

        msg = _("The host node 'fake_node' could not be found.")
        self.assertEqual(msg, ex.message)
示例#10
0
    def test_action_create_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='cluster', id='C1')

        req = orao.ActionCreateRequestBody(name='NODE1', cluster_id='C1')
        ex = self.assertRaises(rpc.ExpectedException, self.eng.action_create,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual("Cannot find the given cluster: C1.",
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'C1')
示例#11
0
    def test_webhook_trigger_receiver_not_found(self, mock_find):
        mock_find.side_effect = exception.ResourceNotFound(type='receiver',
                                                           id='RRR')
        body = vorw.WebhookTriggerRequestBody(params=None)
        req = vorw.WebhookTriggerRequest(identity='RRR', body=body)
        ex = self.assertRaises(rpc.ExpectedException, self.eng.webhook_trigger,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exception.ResourceNotFound, ex.exc_info[0])
        self.assertEqual('The receiver (RRR) could not be found.',
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'RRR')
示例#12
0
    def test_node_create2_profile_not_found(self, mock_profile):
        mock_profile.side_effect = exc.ResourceNotFound(type='profile',
                                                        id='Bogus')
        req = orno.NodeCreateRequestBody(name='NODE1', profile_id='Bogus')

        ex = self.assertRaises(rpc.ExpectedException, self.eng.node_create2,
                               self.ctx, req.obj_to_primitive())
        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual(
            "The request is malformed: The specified profile "
            "(Bogus) could not be found.", six.text_type(ex.exc_info[1]))
        mock_profile.assert_called_once_with(self.ctx, 'Bogus')
示例#13
0
    def test_policy_delete_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='policy', id='Bogus')

        req = orpo.PolicyDeleteRequest(identity='Bogus')

        ex = self.assertRaises(rpc.ExpectedException, self.svc.policy_delete,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual("The policy 'Bogus' could not be found.",
                         str(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'Bogus')
    def test_do_validate_node_not_found(self, mock_find):
        obj = mock.Mock()
        profile = dp.DockerProfile('container', self.spec)
        mock_find.side_effect = exc.ResourceNotFound(type='node',
                                                     id='fake_node')

        ex = self.assertRaises(exc.InvalidSpec, profile.do_validate, obj)

        self.assertEqual(
            "The specified host_node 'fake_node' could not be "
            "found or is not unique.", six.text_type(ex))
        mock_find.assert_called_once_with(profile.context, 'fake_node')
示例#15
0
    def test_get2_policy_not_found(self, mock_policy, mock_cluster):
        mock_cluster.return_value = mock.Mock(id='cid')
        mock_policy.side_effect = exc.ResourceNotFound(type='policy', id='pid')
        req = orcp.ClusterPolicyGetRequest(identity='cid', policy_id='pid')
        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_get2, self.ctx,
                               req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual("The policy (pid) could not be found.",
                         six.text_type(ex.exc_info[1]))
        mock_cluster.assert_called_once_with(self.ctx, 'cid')
        mock_policy.assert_called_once_with(self.ctx, 'pid')
示例#16
0
    def test_receiver_create_webhook_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='cluster', id='C1')
        req = orro.ReceiverCreateRequestBody(
            name='r1', type=consts.RECEIVER_WEBHOOK, cluster_id='C1',
            action=consts.CLUSTER_RESIZE)

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.receiver_create,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual("The referenced cluster 'C1' could not be found.",
                         six.text_type(ex.exc_info[1]))
示例#17
0
    def test_detach2_cluster_not_found(self, mock_cluster):
        mock_cluster.side_effect = exc.ResourceNotFound(type='cluster',
                                                        id='Bogus')
        req = orco.ClusterDetachPolicyRequest(identity='Bogus',
                                              policy_id='POLICY_ID')

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_detach, self.ctx,
                               req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, 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')
示例#18
0
    def test_receiver_update_not_found(self, mock_find):

        mock_find.side_effect = exc.ResourceNotFound(type='receiver',
                                                     id='Bogus')

        kwargs = {'identity': 'Bogus', 'name': 'NEW_NAME'}
        req = orro.ReceiverUpdateRequest(**kwargs)
        ex = self.assertRaises(rpc.ExpectedException, self.svc.receiver_update,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual("The receiver 'Bogus' could not be found.",
                         str(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'Bogus')
示例#19
0
    def load(cls, context, action_id=None, db_action=None):
        """Retrieve an action from database.

        :param context: Instance of request context.
        :param action_id: An UUID for the action to deserialize.
        :param db_action: An action object for the action to deserialize.
        :return: A `Action` object instance.
        """
        if db_action is None:
            db_action = ao.Action.get(context, action_id)
            if db_action is None:
                raise exception.ResourceNotFound(type='action', id=action_id)

        return cls._from_object(db_action)
示例#20
0
    def test_policy_type_get_not_found(self, mock_call, mock_parse,
                                       mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        type_name = 'BogusPolicyType'
        req = self._get('/policy_types/%(type)s' % {'type': type_name})

        error = senlin_exc.ResourceNotFound(type='policy_type', id=type_name)
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req, type_name=type_name)
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ResourceNotFound', resp.json['error']['type'])
示例#21
0
    def test_update2_cluster_not_found(self, mock_cluster):
        mock_cluster.side_effect = exc.ResourceNotFound(type='cluster',
                                                        id='Bogus')
        req = orco.ClusterUpdatePolicyRequest(identity='Bogus', policy_id='P1',
                                              enabled=True)

        ex = self.assertRaises(rpc.ExpectedException,
                               self.svc.cluster_policy_update,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual("The cluster 'Bogus' could not be found.",
                         str(ex.exc_info[1]))
        mock_cluster.assert_called_once_with(self.ctx, 'Bogus')
示例#22
0
    def test_node_list2_cluster_not_found(self, mock_find):
        mock_find.side_effect = exc.ResourceNotFound(type='cluster',
                                                     id='BOGUS')

        req = orno.NodeListRequest(cluster_id='BOGUS', project_safe=True)

        ex = self.assertRaises(rpc.ExpectedException, self.eng.node_list2,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual(
            'The request is malformed: Cannot find the given '
            'cluster: BOGUS.', six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'BOGUS')
    def test_do_validate_cluster_not_found(self, mock_find):
        spec = copy.deepcopy(self.spec)
        del spec['properties']['host_node']
        spec['properties']['host_cluster'] = 'fake_cluster'
        obj = mock.Mock()
        mock_find.side_effect = exc.ResourceNotFound(type='node',
                                                     id='fake_cluster')
        profile = dp.DockerProfile('container', spec)

        ex = self.assertRaises(exc.InvalidSpec, profile.do_validate, obj)

        self.assertEqual(
            "The specified host_cluster 'fake_cluster' could "
            "not be found or is not unique.", six.text_type(ex))
        mock_find.assert_called_once_with(profile.context, 'fake_cluster')
示例#24
0
    def test_event_list_with_cluster_not_found(self, mock_load, mock_find):
        mock_find.side_effect = [
            mock.Mock(id='FAKE1'),
            exc.ResourceNotFound(type='cluster', id='CLUSTER2'),
        ]
        req = oreo.EventListRequest(cluster_id=['CLUSTERA', 'CLUSTER2'],
                                    project_safe=True)

        result = self.svc.event_list(self.ctx, req.obj_to_primitive())

        self.assertEqual([], result)
        self.assertEqual(0, mock_load.call_count)
        mock_find.assert_has_calls(
            [mock.call(self.ctx, 'CLUSTERA'),
             mock.call(self.ctx, 'CLUSTER2')])
示例#25
0
    def test_node_create_cluster_not_found(self, mock_profile, mock_cluster):
        mock_cluster.side_effect = exc.ResourceNotFound(type='cluster',
                                                        id='Bogus')
        req = orno.NodeCreateRequestBody(name='NODE1',
                                         profile_id='PROFILE_NAME',
                                         cluster_id='Bogus')

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.node_create,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual("The specified cluster 'Bogus' could not be found.",
                         six.text_type(ex.exc_info[1]))
        mock_cluster.assert_called_once_with(self.ctx, 'Bogus')
示例#26
0
    def test_receiver_get_not_found(self, mock_call, mock_parse,
                                    mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        wid = 'non-existent-receiver'
        req = self._get('/receivers/%(receiver_id)s' % {'receiver_id': wid})

        error = senlin_exc.ResourceNotFound(type='receiver', id=wid)
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req, receiver_id=wid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ResourceNotFound', resp.json['error']['type'])
示例#27
0
    def test_node_delete_not_found(self, mock_call, mock_parse, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        nid = 'aaaa-bbbb-cccc'
        req = self._delete('/nodes/%(node_id)s' % {'node_id': nid})

        error = senlin_exc.ResourceNotFound(type='node', id=nid)
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.delete,
                                              req,
                                              node_id=nid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ResourceNotFound', resp.json['error']['type'])
示例#28
0
    def test_profile_update_not_found(self, mock_find):

        mock_find.side_effect = exc.ResourceNotFound(type='profile',
                                                     id='Bogus')

        req_body = vorp.ProfileUpdateRequestBody(name='NEW_NAME')
        req = vorp.ProfileUpdateRequest(identity='Bogus', profile=req_body)

        ex = self.assertRaises(rpc.ExpectedException, self.svc.profile_update,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
        self.assertEqual("The profile 'Bogus' could not be found.",
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'Bogus')
示例#29
0
    def test_node_update2_profile_not_found(self, mock_find, mock_profile):
        mock_find.return_value = mock.Mock()
        mock_profile.side_effect = exc.ResourceNotFound(type='profile',
                                                        id='Bogus')

        req = orno.NodeUpdateRequest(identity='FAKE_NODE', profile_id='Bogus')
        ex = self.assertRaises(rpc.ExpectedException, self.eng.node_update2,
                               self.ctx, req.obj_to_primitive())

        self.assertEqual(exc.BadRequest, ex.exc_info[0])
        self.assertEqual(
            'The request is malformed: The specified profile '
            '(Bogus) could not be found.', six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'FAKE_NODE')
        mock_profile.assert_called_once_with(self.ctx, 'Bogus')
示例#30
0
 def test_build_action_cluster_notfound(self, mock_find_cluster):
     mock_find_cluster.side_effect = exception.ResourceNotFound(
         type='cluster', id='c1')
     msg = {
         'body': {
             'cluster': 'c1',
             'action': 'CLUSTER_SCALE_IN'
         },
         'id': 'ID123456'
     }
     message = mmod.Message('message', None, None, id=UUID)
     ex = self.assertRaises(exception.InternalError, message._build_action,
                            self.context, msg)
     ex_msg = _('Cluster (c1) cannot be found.')
     self.assertEqual(ex_msg, ex.message)