예제 #1
0
    def test_policy_update_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', True)
        pid = 'non-existent-policy'
        body = {
            'policy': {
                'name': 'new_policy',
                'level': 70,
            }
        }
        req = self._patch('/policies/%(policy_id)s' % {'policy_id': pid},
                          json.dumps(body))

        error = senlin_exc.PolicyNotFound(policy=pid)
        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.update,
                                              req,
                                              tenant_id=self.project,
                                              policy_id=pid,
                                              body=body)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('PolicyNotFound', resp.json['error']['type'])
예제 #2
0
    def test_node_update_invalid_profile(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', True)
        nid = 'aaaa-bbbb-cccc'
        body = {
            'node': {
                'name': 'test_node',
                'profile_id': 'profile-not-exist',
                'role': None,
                'metadata': {},
            }
        }

        req = self._patch('/nodes/%(node_id)s' % {'node_id': nid},
                          json.dumps(body))

        error = senlin_exc.ProfileNotFound(profile=nid)
        mock_call = self.patchobject(rpc_client.EngineClient,
                                     'call',
                                     side_effect=shared.to_remote_error(error))

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.update,
                                              req,
                                              tenant_id=self.project,
                                              node_id=nid,
                                              body=body)
        mock_call.assert_called_with(req.context, ('node_update', {
            'identity': nid,
            'name': 'test_node',
            'profile_id': 'profile-not-exist',
            'role': None,
            'metadata': {},
        }))
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileNotFound', resp.json['error']['type'])
예제 #3
0
    def test_profile_update_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', True)
        pid = 'non-existent-profile'
        body = {
            'profile': {
                'name': 'new_profile',
                'metadata': {
                    'author': 'john d'
                },
                'permission': 'xxx',
            }
        }
        req = self._put('/profiles/%(profile_id)s' % {'profile_id': pid},
                        json.dumps(body))

        error = senlin_exc.ProfileNotFound(profile=pid)
        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.update,
                                              req,
                                              tenant_id=self.project,
                                              profile_id=pid,
                                              body=body)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileNotFound', resp.json['error']['type'])
예제 #4
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'])
예제 #5
0
    def test_node_update_invalid_profile(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', True)
        nid = 'aaaa-bbbb-cccc'
        body = {
            'node': {
                'name': 'test_node',
                'profile_id': 'profile-not-exist',
                'role': None,
                'metadata': {},
            }
        }

        req = self._patch('/nodes/%(node_id)s' % {'node_id': nid},
                          jsonutils.dumps(body))

        error = senlin_exc.ProfileNotFound(profile=nid)
        mock_call = self.patchobject(rpc_client.EngineClient, 'call',
                                     side_effect=shared.to_remote_error(error))

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.update,
                                              req, node_id=nid, body=body)
        mock_call.assert_called_with(
            req.context,
            ('node_update', {
                'identity': nid,
                'name': 'test_node',
                'profile_id': 'profile-not-exist',
                'role': None,
                'metadata': {},
            })
        )
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileNotFound', resp.json['error']['type'])
예제 #6
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'])
예제 #7
0
    def test_get_not_found(self, mock_call, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        trigger_id = 'non-existent-trigger'
        req = self._get('/triggers/%(tid)s' % {'tid': trigger_id})

        error = senlin_exc.TriggerNotFound(trigger=trigger_id)
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req, tenant_id=self.project,
                                              trigger_id=trigger_id)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('TriggerNotFound', resp.json['error']['type'])
예제 #8
0
    def test_delete_not_found(self, mock_call, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        tid = 'FAKE_ID'
        req = self._delete('/triggers/FAKE_ID')

        error = senlin_exc.TriggerNotFound(trigger=tid)
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.delete,
                                              req, tenant_id=self.project,
                                              trigger_id=tid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('TriggerNotFound', resp.json['error']['type'])
예제 #9
0
    def test_event_get_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, "get", True)
        event_id = "non-existent-event"
        req = self._get("/events/%(event_id)s" % {"event_id": event_id})

        error = senlin_exc.EventNotFound(event=event_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.get, req, tenant_id=self.project, event_id=event_id
        )

        self.assertEqual(404, resp.json["code"])
        self.assertEqual("EventNotFound", resp.json["error"]["type"])
예제 #10
0
    def test_profile_get_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        pid = 'non-existent-profile'
        req = self._get('/profiles/%(profile_id)s' % {'profile_id': pid})

        error = senlin_exc.ProfileNotFound(profile=pid)
        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.get,
                                              req, profile_id=pid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileNotFound', resp.json['error']['type'])
예제 #11
0
    def test_policy_delete_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        pid = 'aaaa-bbbb-cccc'
        req = self._delete('/policies/%(policy_id)s' % {'policy_id': pid})

        error = senlin_exc.PolicyNotFound(policy=pid)
        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.delete,
                                              req, policy_id=pid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('PolicyNotFound', resp.json['error']['type'])
예제 #12
0
    def test_event_get_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        event_id = 'non-existent-event'
        req = self._get('/events/%(event_id)s' % {'event_id': event_id})

        error = senlin_exc.EventNotFound(event=event_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.get,
                                              req, event_id=event_id)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('EventNotFound', resp.json['error']['type'])
예제 #13
0
    def test_delete_not_found(self, mock_call, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        tid = 'FAKE_ID'
        req = self._delete('/triggers/FAKE_ID')

        error = senlin_exc.TriggerNotFound(trigger=tid)
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.delete,
                                              req,
                                              tenant_id=self.project,
                                              trigger_id=tid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('TriggerNotFound', resp.json['error']['type'])
예제 #14
0
    def test_get_not_found(self, mock_call, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        trigger_id = 'non-existent-trigger'
        req = self._get('/triggers/%(tid)s' % {'tid': trigger_id})

        error = senlin_exc.TriggerNotFound(trigger=trigger_id)
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req,
                                              tenant_id=self.project,
                                              trigger_id=trigger_id)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('TriggerNotFound', resp.json['error']['type'])
예제 #15
0
    def test_profile_delete_resource_in_use(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        pid = 'aaaa-bbbb-cccc'
        req = self._delete('/profiles/%(profile_id)s' % {'profile_id': pid})

        error = senlin_exc.ResourceInUse(resource_type='profile',
                                         resource_id=pid)
        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.delete,
                                              req, profile_id=pid)

        self.assertEqual(409, resp.json['code'])
        self.assertEqual('ResourceInUse', resp.json['error']['type'])
예제 #16
0
    def test_action_get_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        action_id = 'non-existent-action'
        req = self._get('/actions/%(action_id)s' % {'action_id': action_id})

        error = senlin_exc.ActionNotFound(action=action_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.get,
                                              req, tenant_id=self.project,
                                              action_id=action_id)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ActionNotFound', resp.json['error']['type'])
예제 #17
0
    def test_webhook_delete_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        wid = 'aaaa-bbbb-cccc'
        req = self._delete('/webhooks/%(webhook_id)s' % {'webhook_id': wid})

        error = senlin_exc.WebhookNotFound(webhook=wid)
        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.delete,
                                              req, tenant_id=self.project,
                                              webhook_id=wid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('WebhookNotFound', resp.json['error']['type'])
예제 #18
0
    def test_cluster_policy_get_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, "get", True)
        cid = "FAKE_CLUSTER"
        pid = "FAKE_POLICY"
        req = self._get("/cluster_policies/%(cid)s/%(pid)s" "" % {"cid": cid, "pid": pid})

        error = senlin_exc.PolicyBindingNotFound(policy=pid, identity=cid)
        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.get, req, tenant_id=self.project, cluster_id=cid, policy_id=pid
        )

        self.assertEqual(404, resp.json["code"])
        self.assertEqual("PolicyBindingNotFound", resp.json["error"]["type"])
예제 #19
0
    def test_node_action_check_node_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'action', True)
        node_id = 'unknown-node'
        body = {'check': {}}
        req = self._post('/nodes/%(node_id)s/actions' % {'node_id': node_id},
                         jsonutils.dumps(body))

        error = senlin_exc.NodeNotFound(node=node_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, node_id=node_id, body=body)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('NodeNotFound', resp.json['error']['type'])
예제 #20
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,
                                              tenant_id=self.project)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ClusterNotFound', resp.json['error']['type'])
예제 #21
0
    def test_webhook_delete_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        wid = 'aaaa-bbbb-cccc'
        req = self._delete('/webhooks/%(webhook_id)s' % {'webhook_id': wid})

        error = senlin_exc.WebhookNotFound(webhook=wid)
        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.delete,
                                              req,
                                              tenant_id=self.project,
                                              webhook_id=wid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('WebhookNotFound', resp.json['error']['type'])
예제 #22
0
    def test_profile_delete_resource_in_use(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', True)
        pid = 'aaaa-bbbb-cccc'
        req = self._delete('/profiles/%(profile_id)s' % {'profile_id': pid})

        error = senlin_exc.ResourceInUse(resource_type='profile',
                                         resource_id=pid)
        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.delete,
                                              req,
                                              tenant_id=self.project,
                                              profile_id=pid)

        self.assertEqual(409, resp.json['code'])
        self.assertEqual('ResourceInUse', resp.json['error']['type'])
예제 #23
0
    def test_policy_type_get_not_found(self, 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.PolicyTypeNotFound(policy_type=type_name)
        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.get,
                                              req, type_name=type_name)

        mock_call.assert_called_once_with(
            req.context, ('policy_type_get', {'type_name': type_name}))

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('PolicyTypeNotFound', resp.json['error']['type'])
예제 #24
0
    def test_policy_type_schema_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'schema', True)
        type_name = 'BogusPolicyType'
        req = self._get('/policy_types/%(type)s' % {'type': type_name})

        error = senlin_exc.PolicyTypeNotFound(policy_type=type_name)
        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.schema,
                                              req, tenant_id=self.project,
                                              type_name=type_name)

        mock_call.assert_called_once_with(
            req.context,
            ('policy_type_schema', {'type_name': type_name}))

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('PolicyTypeNotFound', resp.json['error']['type'])
예제 #25
0
    def test_policy_update_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', True)
        pid = 'non-existent-policy'
        body = {
            'policy': {
                'name': 'new_policy',
            }
        }
        req = self._patch('/policies/%(policy_id)s' % {'policy_id': pid},
                          jsonutils.dumps(body))

        error = senlin_exc.PolicyNotFound(policy=pid)
        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.update,
                                              req, policy_id=pid, body=body)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('PolicyNotFound', resp.json['error']['type'])
예제 #26
0
    def test_node_action_leave_node_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'action', True)
        node_id = 'xxxx-yyyy'
        body = {'leave': {}}
        req = self._put('/nodes/%(node_id)s/action' % {'node_id': node_id},
                        json.dumps(body))

        error = senlin_exc.NodeNotFound(node=node_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('NodeNotFound', resp.json['error']['type'])

        mock_call.assert_called_once_with(
            req.context, ('node_leave', {'identity': node_id}))
예제 #27
0
    def test_cluster_policy_get_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        cid = 'FAKE_CLUSTER'
        pid = 'FAKE_POLICY'
        req = self._get('/cluster_policies/%(cid)s/%(pid)s'
                        '' % {
                            'cid': cid,
                            'pid': pid
                        })

        error = senlin_exc.PolicyBindingNotFound(policy=pid, identity=cid)
        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.get,
                                              req,
                                              tenant_id=self.project,
                                              cluster_id=cid,
                                              policy_id=pid)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('PolicyBindingNotFound', resp.json['error']['type'])
예제 #28
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'])
예제 #29
0
    def test_node_action_leave_node_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'action', True)
        node_id = 'xxxx-yyyy'
        body = {'leave': {}}
        req = self._put('/nodes/%(node_id)s/action' % {'node_id': node_id},
                        json.dumps(body))

        error = senlin_exc.NodeNotFound(node=node_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('NodeNotFound', resp.json['error']['type'])

        mock_call.assert_called_once_with(req.context, ('node_leave', {
            'identity': node_id
        }))