summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-11-27 01:14:00 +0000
committerGerrit Code Review <review@openstack.org>2018-11-27 01:14:00 +0000
commit64c7c8f9895cef1e5de0fd0206527c6592b2c1b2 (patch)
treea98a912faa275743d5ddf7d0c9be232dfe5307fc
parent57c04d1eeb14c86186ad5103c032b56fafbf6152 (diff)
parent6b91d5fe2d42e93cdaabdda63631fff2e495e0db (diff)
Merge "Fix the raise error in list services process"
-rw-r--r--karbor/api/v1/services.py6
-rw-r--r--karbor/tests/unit/api/v1/test_services.py20
2 files changed, 18 insertions, 8 deletions
diff --git a/karbor/api/v1/services.py b/karbor/api/v1/services.py
index 52de28a..192d9d7 100644
--- a/karbor/api/v1/services.py
+++ b/karbor/api/v1/services.py
@@ -88,9 +88,9 @@ class ServiceController(wsgi.Controller):
88 try: 88 try:
89 services = objects.ServiceList.get_all_by_args( 89 services = objects.ServiceList.get_all_by_args(
90 context, host, binary) 90 context, host, binary)
91 except exception as e: 91 except Exception as e:
92 LOG.error('List service failed, reason: %s' % e) 92 msg = (_('List service failed, reason: %s') % e)
93 raise 93 raise exc.HTTPBadRequest(explanation=msg)
94 return self._view_builder.detail_list(req, services) 94 return self._view_builder.detail_list(req, services)
95 95
96 def update(self, req, id, body): 96 def update(self, req, id, body):
diff --git a/karbor/tests/unit/api/v1/test_services.py b/karbor/tests/unit/api/v1/test_services.py
index 8b49b04..1873b9e 100644
--- a/karbor/tests/unit/api/v1/test_services.py
+++ b/karbor/tests/unit/api/v1/test_services.py
@@ -25,21 +25,30 @@ class ServiceApiTest(base.TestCase):
25 25
26 @mock.patch('karbor.objects.service.ServiceList.get_all_by_args') 26 @mock.patch('karbor.objects.service.ServiceList.get_all_by_args')
27 def test_service_list_with_admin_context(self, mock_get_all_by_args): 27 def test_service_list_with_admin_context(self, mock_get_all_by_args):
28 req = fakes.HTTPRequest.blank('/v1/services?host=host1', 28 req = fakes.HTTPRequest.blank('/v1/os-services?host=host1',
29 use_admin_context=True) 29 use_admin_context=True)
30 self.controller.index(req) 30 self.controller.index(req)
31 self.assertTrue(mock_get_all_by_args.called) 31 self.assertTrue(mock_get_all_by_args.called)
32 32
33 def test_service_list_with_non_admin_context(self): 33 def test_service_list_with_non_admin_context(self):
34 req = fakes.HTTPRequest.blank('/v1/services', use_admin_context=False) 34 req = fakes.HTTPRequest.blank('/v1/os-services',
35 use_admin_context=False)
35 self.assertRaises( 36 self.assertRaises(
36 exception.PolicyNotAuthorized, self.controller.index, req) 37 exception.PolicyNotAuthorized, self.controller.index, req)
37 38
39 @mock.patch('karbor.objects.service.ServiceList.get_all_by_args')
40 def test_service_list_with_invalid_services(self, mock_get_all_by_args):
41 req = fakes.HTTPRequest.blank('/v1/os-services',
42 use_admin_context=True)
43 mock_get_all_by_args.side_effect = exception.NotFound()
44 self.assertRaises(exc.HTTPBadRequest, self.controller.index, req)
45
38 @mock.patch('karbor.utils.service_is_up') 46 @mock.patch('karbor.utils.service_is_up')
39 @mock.patch('karbor.objects.service.Service.get_by_id') 47 @mock.patch('karbor.objects.service.Service.get_by_id')
40 def test_service_update_with_admin_context( 48 def test_service_update_with_admin_context(
41 self, mock_get_by_id, mock_service_is_up): 49 self, mock_get_by_id, mock_service_is_up):
42 req = fakes.HTTPRequest.blank('/v1/services/1', use_admin_context=True) 50 req = fakes.HTTPRequest.blank('/v1/os-services/1',
51 use_admin_context=True)
43 body = { 52 body = {
44 "status": 'disabled', 53 "status": 'disabled',
45 'disabled_reason': 'reason' 54 'disabled_reason': 'reason'
@@ -53,7 +62,7 @@ class ServiceApiTest(base.TestCase):
53 self.assertTrue(mock_service.save.called) 62 self.assertTrue(mock_service.save.called)
54 63
55 def test_service_update_with_non_admin_context(self): 64 def test_service_update_with_non_admin_context(self):
56 req = fakes.HTTPRequest.blank('/v1/services/1', 65 req = fakes.HTTPRequest.blank('/v1/os-services/1',
57 use_admin_context=False) 66 use_admin_context=False)
58 body = { 67 body = {
59 "status": 'disabled', 68 "status": 'disabled',
@@ -69,7 +78,8 @@ class ServiceApiTest(base.TestCase):
69 78
70 @mock.patch('karbor.objects.service.Service.get_by_id') 79 @mock.patch('karbor.objects.service.Service.get_by_id')
71 def test_update_protection_services(self, mock_get_by_id): 80 def test_update_protection_services(self, mock_get_by_id):
72 req = fakes.HTTPRequest.blank('/v1/services/1', use_admin_context=True) 81 req = fakes.HTTPRequest.blank('/v1/os-services/1',
82 use_admin_context=True)
73 body = { 83 body = {
74 "status": 'disabled', 84 "status": 'disabled',
75 'disabled_reason': 'reason' 85 'disabled_reason': 'reason'