Ejemplo n.º 1
0
    def test_node_create_with_bad_profile(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        body = {
            'node': {
                'name': 'test_node',
                'profile_id': 'bad-profile',
                'cluster_id': None,
                'role': None,
                'metadata': {},
            }
        }
        req = self._post('/nodes', json.dumps(body))

        error = senlin_exc.ProfileNotFound(profile='bad-profile')
        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)
        mock_call.assert_called_once_with(req.context,
                                          ('node_create', body['node']))
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileNotFound', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 2
0
    def test_webhook_create_credential_missing(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        body = {
            'webhook': {
                'name': 'test_webhook',
                'obj_type': 'test_obj_type',
                'obj_id': 'test_obj_id',
                'action': 'test_action',
                'credential': None,
                'params': {
                    'test_param': 'test_value'
                },
            }
        }
        req = self._post('/webhooks', json.dumps(body))

        msg = _('The credential parameter is missing')
        error = senlin_exc.SenlinBadRequest(msg=msg)
        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(400, resp.json['code'])
        self.assertEqual('SenlinBadRequest', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 3
0
    def test_receiver_create_unapplicable_action(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        action = 'BAD'
        body = {
            'receiver': {
                'name': 'test_receiver',
                'type': 'webhook',
                'cluster_id': 'FAKE_CLUSTER',
                'action': action,
            }
        }
        req = self._post('/receivers', jsonutils.dumps(body))

        msg = 'Action BAD is not applicable clusters.'
        error = senlin_exc.BadRequest(msg=msg)
        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 = body['receiver']
        type_name = expected.pop('type')
        expected['type_name'] = type_name
        expected['actor'] = None
        expected['params'] = None
        mock_call.assert_called_once_with(req.context,
                                          ('receiver_create', expected))
        self.assertEqual(400, resp.json['code'])
        self.assertEqual('BadRequest', resp.json['error']['type'])
Ejemplo n.º 4
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'])
Ejemplo n.º 5
0
    def test_receiver_create_with_bad_type(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        r_type = 'unsupported'
        body = {
            'receiver': {
                'name': 'test_receiver',
                'type': r_type,
                'cluster_id': 'FAKE_CLUSTER',
                'action': 'test_action',
            }
        }
        req = self._post('/receivers', jsonutils.dumps(body))

        msg = _('receiver obj_type (%s) is unsupported.') % r_type
        error = senlin_exc.BadRequest(msg=msg)
        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(400, resp.json['code'])
        self.assertEqual('BadRequest', resp.json['error']['type'])
Ejemplo n.º 6
0
    def test_create_with_spec_validation_failed(self, mock_call, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        body = {
            'trigger': {
                'name': 'test_trigger',
                'spec': {'type': 'alarm_type', 'param': 'value'},
                'enabled': True,
            }
        }
        req = self._post('/triggers', jsonutils.dumps(body))

        msg = 'Spec validation error (param): value'
        error = senlin_exc.SpecValidationFailed(message=msg)
        mock_call.side_effect = error

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

        mock_call.assert_called_once_with(
            req.context,
            ('trigger_create',
             {'name': 'test_trigger', 'description': None,
              'spec': {'type': 'alarm_type', 'param': 'value'},
              'enabled': True, 'state': None, 'severity': None}))
        self.assertEqual(400, resp.json['code'])
        self.assertEqual('SpecValidationFailed', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 7
0
    def test_webhook_create_credential_missing(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        body = {
            'webhook': {
                'name': 'test_webhook',
                'obj_type': 'test_obj_type',
                'obj_id': 'test_obj_id',
                'action': 'test_action',
                'credential': None,
                'params': {
                    'test_param': 'test_value'
                },
            }
        }
        req = self._post('/webhooks', json.dumps(body))

        msg = _('The credential parameter is missing')
        error = senlin_exc.SenlinBadRequest(msg=msg)
        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(400, resp.json['code'])
        self.assertEqual('SenlinBadRequest', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 8
0
    def test_policy_create_with_spec_validation_failed(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        body = {
            'policy': {
                'name': 'test_policy',
                'spec': {
                    'type': 'policy_type',
                    'version': '1.0',
                    'properties': {'param': 'value'}
                },
            }
        }
        req = self._post('/policies', jsonutils.dumps(body))

        msg = 'Spec validation error (param): value'
        error = senlin_exc.SpecValidationFailed(message=msg)
        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['policy']
        mock_call.assert_called_once_with(req.context,
                                          ('policy_create', expected_args))
        self.assertEqual(400, resp.json['code'])
        self.assertEqual('SpecValidationFailed', resp.json['error']['type'])
Ejemplo n.º 9
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'])
Ejemplo n.º 10
0
    def test_profile_create_with_spec_validation_failed(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        body = {
            'profile': {
                'name': 'test_profile',
                'spec': {
                    'type': 'test_profile_type',
                    'version': '1.0',
                    'properties': {
                        'param': 'value'
                    },
                },
                'permission': None,
                'metadata': {},
            }
        }
        req = self._post('/profiles', json.dumps(body))

        msg = 'Spec validation error (param): value'
        error = senlin_exc.SpecValidationFailed(message=msg)
        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)
        mock_call.assert_called_once_with(req.context,
                                          ('profile_create', body['profile']))
        self.assertEqual(400, resp.json['code'])
        self.assertEqual('SpecValidationFailed', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 11
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'])
Ejemplo n.º 12
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', json.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,
                                              tenant_id=self.project,
                                              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'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 13
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'])
Ejemplo n.º 14
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'])
Ejemplo n.º 15
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'])
Ejemplo n.º 16
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'])
Ejemplo n.º 17
0
    def test_profile_create_with_bad_type(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        type_name = 'unknown_type'
        body = {
            'profile': {
                'name': 'test_profile',
                'spec': {
                    'type': type_name,
                    'version': '1.0',
                    'properties': {'param': 'value'},
                },
                'spec': {'param': 'value'},
                'metadata': {},
            }
        }
        req = self._post('/profiles', jsonutils.dumps(body))

        error = senlin_exc.ProfileTypeNotFound(profile_type=type_name)
        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,
                                          ('profile_create', body['profile']))
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileTypeNotFound', resp.json['error']['type'])
Ejemplo n.º 18
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'])
Ejemplo n.º 19
0
    def test_index_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, "index", False)
        req = self._get("/events")

        resp = shared.request_with_middleware(fault.FaultWrapper, self.controller.index, req, tenant_id=self.project)
        self.assertEqual(403, resp.status_int)
        self.assertIn("403 Forbidden", six.text_type(resp))
Ejemplo n.º 20
0
    def test_node_index_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'index', False)
        req = self._get('/nodes')

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.index, req)
        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 21
0
    def test_profile_type_list_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'index', False)
        req = self._get('/profile_types')
        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.index,
                                              req, tenant_id=self.project)

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 22
0
    def test_action_index_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'index', False)
        req = self._get('/actions')

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.index,
                                              req, tenant_id=self.project)
        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 23
0
    def test_profile_type_get_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', False)
        type_name = 'BogusProfileType'
        req = self._get('/profile_types/%(type)s' % {'type': type_name})

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req, type_name=type_name)
        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 24
0
    def test_policy_get_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', False)
        pid = 'non-existent-policy'
        req = self._get('/policies/%(policy_id)s' % {'policy_id': pid})

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req, policy_id=pid)

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 25
0
    def test_policy_type_schema_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'schema', False)
        type_name = 'BogusPolicyType'
        req = self._get('/policy_types/%(type)s' % {'type': type_name})

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.schema,
                                              req, tenant_id=self.project,
                                              type_name=type_name)
        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 26
0
    def test_policy_delete_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', False)
        pid = 'aaaa-bbbb-cccc'
        req = self._delete('/policies/%(policy_id)s' % {'policy_id': pid})

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.delete,
                                              req, policy_id=pid)

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 27
0
    def test_cluster_policy_index_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, "index", False)
        cid = "FAKE_CLUSTER"
        req = self._get("/cluster_policy/%s" % cid)

        resp = shared.request_with_middleware(
            fault.FaultWrapper, self.controller.index, req, tenant_id=self.project, cluster_id=cid
        )

        self.assertEqual(403, resp.status_int)
        self.assertIn("403 Forbidden", six.text_type(resp))
Ejemplo n.º 28
0
    def test_event_get_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, "get", False)
        event_id = "non-existent-event"
        req = self._get("/events/%(event_id)s" % {"event_id": event_id})

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

        self.assertEqual(403, resp.status_int)
        self.assertIn("403 Forbidden", six.text_type(resp))
Ejemplo n.º 29
0
    def test_action_get_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', False)
        action_id = 'non-existent-action'
        req = self._get('/actions/%(action_id)s' % {'action_id': action_id})

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

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 30
0
    def test_webhook_delete_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', False)
        wid = 'aaaa-bbbb-cccc'
        req = self._delete('/webhooks/%(webhook_id)s' % {'webhook_id': wid})

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

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 31
0
    def test_delete_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', False)
        trigger_id = 'FAKE_ID'
        req = self._delete('/triggers/FAKE_ID')

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

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 32
0
    def test_action_get_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, "get", False)
        cid = "FAKE_CLUSTER"
        pid = "FAKE_POLICY"
        req = self._get("/cluster_policies/%(cid)s/%(pid)s" "" % {"cid": cid, "pid": pid})

        resp = shared.request_with_middleware(
            fault.FaultWrapper, self.controller.get, req, tenant_id=self.project, cluster_id=cid, policy_id=pid
        )

        self.assertEqual(403, resp.status_int)
        self.assertIn("403 Forbidden", six.text_type(resp))
Ejemplo n.º 33
0
    def test_webhook_get_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', False)
        wid = 'non-existent-webhook'
        req = self._get('/webhooks/%(webhook_id)s' % {'webhook_id': wid})

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

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 34
0
    def test_delete_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'delete', False)
        trigger_id = 'FAKE_ID'
        req = self._delete('/triggers/FAKE_ID')

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

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 35
0
    def test_cluster_policy_index_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'index', False)
        cid = 'FAKE_CLUSTER'
        req = self._get('/cluster_policy/%s' % cid)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.index,
                                              req,
                                              tenant_id=self.project,
                                              cluster_id=cid)

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 36
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'])
Ejemplo n.º 37
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'])
Ejemplo n.º 38
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'])
Ejemplo n.º 39
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"])
Ejemplo n.º 40
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'])
Ejemplo n.º 41
0
    def test_policy_update_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', False)
        pid = 'aaaa-bbbb-cccc'
        body = {
            'policy': {'name': 'test_policy', 'spec': {'param5': 'value5'}},
        }
        req = self._put('/policies/%(policy_id)s' % {'policy_id': pid},
                        jsonutils.dumps(body))

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.update,
                                              req, policy_id=pid, body=body)

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 42
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'])
Ejemplo n.º 43
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'])
Ejemplo n.º 44
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'])
Ejemplo n.º 45
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'])
Ejemplo n.º 46
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'])
Ejemplo n.º 47
0
    def test_create_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', False)
        body = {
            'trigger': {
                'name': 'test_trigger',
                'spec': {
                    'type': 'alarm_type',
                    'param': 'value'
                },
            }
        }

        req = self._post('/triggers', jsonutils.dumps(body))
        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.create,
                                              req,
                                              tenant_id=self.project)
        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 48
0
    def test_webhook_create_unapplicable_action(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        obj_type = 'test_obj_type'
        action = 'unapplicable_action'
        body = {
            'webhook': {
                'name': 'test_webhook',
                'obj_type': obj_type,
                'obj_id': 'test_obj_id',
                'action': action,
                'credential': {
                    'user_id': 'test_user_id',
                    'password': '******',
                },
                'params': {
                    'test_param': 'test_value'
                },
            }
        }
        req = self._post('/webhooks', json.dumps(body))

        msg = _('Action %(action)s is not applicable to '
                'object %(obj_type)s') % {
                    'action': action,
                    'obj_type': obj_type
                }
        error = senlin_exc.SenlinBadRequest(msg=msg)
        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(400, resp.json['code'])
        self.assertEqual('SenlinBadRequest', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 49
0
    def test_action_get_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', False)
        cid = 'FAKE_CLUSTER'
        pid = 'FAKE_POLICY'
        req = self._get('/cluster_policies/%(cid)s/%(pid)s'
                        '' % {
                            'cid': cid,
                            'pid': pid
                        })

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req,
                                              tenant_id=self.project,
                                              cluster_id=cid,
                                              policy_id=pid)

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 50
0
    def test_node_action_err_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'action', False)
        node_id = 'aaaa-bbbb-cccc'
        cluster_id = 'xxxx-yyyy-zzzz'
        body = {
            'join': {
                'cluster_id': cluster_id,
            }
        }
        req = self._put('/nodes/%(node_id)s/action' % {'node_id': node_id},
                        json.dumps(body))

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

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 51
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'])
Ejemplo n.º 52
0
    def test_create_with_bad_type(self, mock_call, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        type_name = 'unknown_type'
        body = {
            'trigger': {
                'name': 'test_trigger',
                'spec': {
                    'type': type_name,
                    'param': 'value'
                },
                'enabled': True,
            }
        }
        req = self._post('/triggers', jsonutils.dumps(body))

        error = senlin_exc.TriggerTypeNotFound(trigger_type=type_name)
        mock_call.side_effect = error

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

        mock_call.assert_called_once_with(req.context, ('trigger_create', {
            'name': 'test_trigger',
            'spec': {
                'type': type_name,
                'param': 'value'
            },
            'enabled': True,
            'state': None,
            'severity': None,
            'description': None
        }))

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('TriggerTypeNotFound', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 53
0
    def test_profile_create_with_bad_type(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        type_name = 'unknown_type'
        body = {
            'profile': {
                'name': 'test_profile',
                'spec': {
                    'type': type_name,
                    'version': '1.0',
                    'properties': {
                        'param': 'value'
                    },
                },
                'spec': {
                    'param': 'value'
                },
                'permission': None,
                'metadata': {},
            }
        }
        req = self._post('/profiles', json.dumps(body))

        error = senlin_exc.ProfileTypeNotFound(profile_type=type_name)
        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)

        mock_call.assert_called_once_with(req.context,
                                          ('profile_create', body['profile']))
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileTypeNotFound', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 54
0
    def test_create_with_spec_validation_failed(self, mock_call, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        body = {
            'trigger': {
                'name': 'test_trigger',
                'spec': {
                    'type': 'alarm_type',
                    'param': 'value'
                },
                'enabled': True,
            }
        }
        req = self._post('/triggers', jsonutils.dumps(body))

        msg = 'Spec validation error (param): value'
        error = senlin_exc.SpecValidationFailed(message=msg)
        mock_call.side_effect = error

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

        mock_call.assert_called_once_with(req.context, ('trigger_create', {
            'name': 'test_trigger',
            'description': None,
            'spec': {
                'type': 'alarm_type',
                'param': 'value'
            },
            'enabled': True,
            'state': None,
            'severity': None
        }))
        self.assertEqual(400, resp.json['code'])
        self.assertEqual('SpecValidationFailed', resp.json['error']['type'])
        self.assertIsNone(resp.json['error']['traceback'])
Ejemplo n.º 55
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'])
Ejemplo n.º 56
0
    def test_profile_update_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', False)
        pid = 'aaaa-bbbb-cccc'
        body = {
            'profile': {
                'name': 'test_profile',
                'spec': {
                    'param5': 'value5'
                }
            },
        }
        req = self._put('/profiles/%(profile_id)s' % {'profile_id': pid},
                        json.dumps(body))

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

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))
Ejemplo n.º 57
0
    def test_node_update_denied_policy(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'update', False)
        node_id = 'test-node-1'
        body = {
            'node': {
                'name': 'test_node',
                'profile_id': 'xxxx-yyyy',
                'role': None,
                'metadata': {},
            }
        }
        req = self._patch('/nodes/%(node_id)s' % {'node_id': node_id},
                          json.dumps(body))

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

        self.assertEqual(403, resp.status_int)
        self.assertIn('403 Forbidden', six.text_type(resp))