def test_policy_type_get_nonexist(self, mock_env): x_env = mock.Mock() err = exc.PolicyTypeNotFound(policy_type='FAKE_TYPE') x_env.get_policy.side_effect = err mock_env.return_value = x_env ex = self.assertRaises(rpc.ExpectedException, self.eng.policy_type_get, self.ctx, 'FAKE_TYPE') self.assertEqual(exc.PolicyTypeNotFound, ex.exc_info[0]) self.assertEqual('Policy type (FAKE_TYPE) is not found.', six.text_type(ex.exc_info[1])) mock_env.assert_called_once_with() x_env.get_policy.assert_called_once_with('FAKE_TYPE')
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'])
def get_policy(self, name): self._check_plugin_name('Policy', name) plugin = self.policy_registry.get_plugin(name) if plugin is None: raise exception.PolicyTypeNotFound(policy_type=name) return plugin