def setUp(self): super(ServicesTest, self).setUp() self.context = context.get_admin_context() self.ext_mgr = extensions.ExtensionManager() self.ext_mgr.extensions = {} self.controller = services.ServiceController(self.ext_mgr) self.stubs.Set(self.controller.host_api, "service_get_all", fake_host_api_service_get_all) self.stubs.Set(timeutils, "utcnow", fake_utcnow) self.stubs.Set(db, "service_get_by_args", fake_service_get_by_host_binary) self.stubs.Set(db, "service_update", fake_service_update)
def test_services_disable_log_reason(self): self.ext_mgr.extensions['os-extended-services'] = True self.controller = services.ServiceController(self.ext_mgr) req = \ fakes.HTTPRequest.blank('v2/fakes/os-services/disable-log-reason') body = {'host': 'host1', 'binary': 'nova-compute', 'disabled_reason': 'test-reason', } res_dict = self.controller.update(req, "disable-log-reason", body) self.assertEqual(res_dict['service']['status'], 'disabled') self.assertEqual(res_dict['service']['disabled_reason'], 'test-reason')
def test_services_delete(self): self.ext_mgr.extensions['os-extended-services-delete'] = True self.controller = services.ServiceController(self.ext_mgr) request = fakes.HTTPRequest.blank('/v2/fakes/os-services/1', use_admin_context=True) request.method = 'DELETE' with mock.patch.object(self.controller.host_api, 'service_delete') as service_delete: self.controller.delete(request, '1') service_delete.assert_called_once_with( request.environ['nova.context'], '1') self.assertEqual(self.controller.delete.wsgi_code, 204)
def test_service_detail_with_host_service(self): self.ext_mgr.extensions['os-extended-services'] = True self.controller = services.ServiceController(self.ext_mgr) self.stubs.Set(self.controller.host_api, "service_get_all", fake_host_api_service_get_all) req = FakeRequestWithHostService() res_dict = self.controller.index(req) response = {'services': [ {'binary': 'nova-compute', 'host': 'host1', 'zone': 'nova', 'status': 'disabled', 'state': 'up', 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 5), 'disabled_reason': 'test2'}]} self.assertEqual(res_dict, response)
def setUp(self): super(ServicesTest, self).setUp() self.ext_mgr = extensions.ExtensionManager() self.ext_mgr.extensions = {} self.controller = services.ServiceController(self.ext_mgr) self.stubs.Set(timeutils, "utcnow", fake_utcnow) self.stubs.Set(timeutils, "utcnow_ts", fake_utcnow_ts) self.stubs.Set(self.controller.host_api, "service_get_all", fake_service_get_all(fake_services_list)) self.stubs.Set(db, "service_get_by_args", fake_db_service_get_by_host_binary(fake_services_list)) self.stubs.Set(db, "service_update", fake_db_service_update(fake_services_list))
def setUp(self): super(ServicesCellsTest, self).setUp() host_api = cells_api.HostAPI() self.ext_mgr = extensions.ExtensionManager() self.ext_mgr.extensions = {} self.controller = services.ServiceController(self.ext_mgr) self.controller.host_api = host_api self.stubs.Set(timeutils, "utcnow", fake_utcnow) self.stubs.Set(timeutils, "utcnow_ts", fake_utcnow_ts) services_list = [] for service in fake_services_list: service = service.copy() service['id'] = 'cell1@%d' % service['id'] services_list.append(service) self.stubs.Set(host_api.cells_rpcapi, "service_get_all", fake_service_get_all(services_list))
def test_services_detail(self): self.ext_mgr.extensions['os-extended-services'] = True self.controller = services.ServiceController(self.ext_mgr) self.stubs.Set(self.controller.host_api, "service_get_all", fake_host_api_service_get_all) req = FakeRequest() res_dict = self.controller.index(req) response = {'services': [ {'binary': 'nova-scheduler', 'host': 'host1', 'zone': 'internal', 'status': 'disabled', 'state': 'up', 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 2), 'disabled_reason': 'test1'}, {'binary': 'nova-compute', 'host': 'host1', 'zone': 'nova', 'status': 'disabled', 'state': 'up', 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 5), 'disabled_reason': 'test2'}, {'binary': 'nova-scheduler', 'host': 'host2', 'zone': 'internal', 'status': 'enabled', 'state': 'down', 'updated_at': datetime.datetime(2012, 9, 19, 6, 55, 34), 'disabled_reason': ''}, {'binary': 'nova-compute', 'host': 'host2', 'zone': 'nova', 'status': 'disabled', 'state': 'down', 'updated_at': datetime.datetime(2012, 9, 18, 8, 3, 38), 'disabled_reason': 'test4'}]} self.assertEqual(res_dict, response)
def _set_up_controller(self): self.controller = services_v2.ServiceController(self.ext_mgr)
def test_services_detail_with_delete_extension(self): self.ext_mgr.extensions['os-extended-services-delete'] = True self.controller = services.ServiceController(self.ext_mgr) with mock.patch.object(self.controller.host_api, 'service_get_all', side_effect=fake_host_api_service_get_all): req = FakeRequest() res_dict = self.controller.index(req) response = { 'services': [{ 'binary': 'nova-scheduler', 'host': 'host1', 'id': 1, 'zone': 'internal', 'status': 'disabled', 'state': 'up', 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 2) }, { 'binary': 'nova-compute', 'host': 'host1', 'id': 2, 'zone': 'nova', 'status': 'disabled', 'state': 'up', 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 5) }, { 'binary': 'nova-scheduler', 'host': 'host2', 'id': 3, 'zone': 'internal', 'status': 'enabled', 'state': 'down', 'updated_at': datetime.datetime(2012, 9, 19, 6, 55, 34) }, { 'binary': 'nova-compute', 'host': 'host2', 'id': 4, 'zone': 'nova', 'status': 'disabled', 'state': 'down', 'updated_at': datetime.datetime(2012, 9, 18, 8, 3, 38) }] } self.assertEqual(res_dict, response)