Python oslo_service.service.Service() Examples
The following are 30
code examples of oslo_service.service.Service().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_service.service
, or try the search function
.
Example #1
Source File: rpc.py From neutron-lib with Apache License 2.0 | 6 votes |
def start(self): super(Service, self).start() self.conn = Connection() LOG.debug("Creating Consumer connection for Service %s", self.topic) endpoints = [self.manager] self.conn.create_consumer(self.topic, endpoints) # Hook to allow the manager to do other initializations after # the rpc connection is created. if callable(getattr(self.manager, 'initialize_service_hook', None)): self.manager.initialize_service_hook(self) # Consume from all consumers in threads self.conn.consume_in_threads()
Example #2
Source File: service.py From karbor with Apache License 2.0 | 6 votes |
def __init__(self, host, binary, topic, manager, report_interval=None, periodic_interval=None, periodic_fuzzy_delay=None, service_name=None, *args, **kwargs): super(Service, self).__init__() rpc.init(CONF) self.host = host self.binary = binary self.topic = topic self.manager_class_name = manager manager_class = importutils.import_class(self.manager_class_name) self.manager = manager_class(host=self.host, service_name=service_name, *args, **kwargs) self.report_interval = report_interval self.periodic_interval = periodic_interval self.periodic_fuzzy_delay = periodic_fuzzy_delay self.basic_config_check() self.saved_args, self.saved_kwargs = args, kwargs self.timers = [] self.rpcserver = None
Example #3
Source File: rpc_service.py From ironic-inspector with Apache License 2.0 | 6 votes |
def stop(self): try: self.rpcserver.stop() self.rpcserver.wait() except Exception as e: LOG.exception('Service error occurred when stopping the ' 'RPC server. Error: %s', e) try: self.manager.del_host() except Exception as e: LOG.exception('Service error occurred when cleaning up ' 'the RPC manager. Error: %s', e) super(RPCService, self).stop(graceful=True) LOG.info('Stopped RPC server for service %(service)s on host ' '%(host)s.', {'service': manager.MANAGER_TOPIC, 'host': self.host})
Example #4
Source File: rpc.py From tacker with Apache License 2.0 | 6 votes |
def start(self): super(Service, self).start() self.conn = create_connection() LOG.debug("Creating Consumer connection for Service %s", self.topic) endpoints = [self.manager] self.conn.create_consumer(self.topic, endpoints) # Hook to allow the manager to do other initializations after # the rpc connection is created. if callable(getattr(self.manager, 'initialize_service_hook', None)): self.manager.initialize_service_hook(self) # Consume from all consumers in threads self.conn.consume_in_threads()
Example #5
Source File: service.py From manila with Apache License 2.0 | 6 votes |
def __init__(self, host, binary, topic, manager, report_interval=None, periodic_interval=None, periodic_fuzzy_delay=None, service_name=None, coordination=False, *args, **kwargs): super(Service, self).__init__() if not rpc.initialized(): rpc.init(CONF) self.host = host self.binary = binary self.topic = topic self.manager_class_name = manager manager_class = importutils.import_class(self.manager_class_name) self.manager = manager_class(host=self.host, service_name=service_name, *args, **kwargs) self.availability_zone = self.manager.availability_zone self.report_interval = report_interval self.periodic_interval = periodic_interval self.periodic_fuzzy_delay = periodic_fuzzy_delay self.saved_args, self.saved_kwargs = args, kwargs self.timers = [] self.coordinator = coordination
Example #6
Source File: test_service.py From masakari with Apache License 2.0 | 6 votes |
def test_parent_graceful_shutdown(self, mock_rpc, mock_rpc_init, mock_stop): serv = service.Service(self.host, self.binary, self.topic, 'masakari.tests.unit.test_service.FakeManager') serv.manager = mock.Mock() serv.manager.service_name = self.topic serv.start() serv.stop() serv.rpcserver.start.assert_called_once_with() serv.rpcserver.stop.assert_called_once_with() mock_stop.assert_called_once_with()
Example #7
Source File: service.py From manila with Apache License 2.0 | 6 votes |
def stop(self): # Try to shut the connection down, but if we get any sort of # errors, go ahead and ignore them.. as we're shutting down anyway try: self.rpcserver.stop() except Exception: pass for x in self.timers: try: x.stop() except Exception: pass if self.coordinator: try: coordination.LOCK_COORDINATOR.stop() except Exception: LOG.exception("Unable to stop the Tooz Locking " "Coordinator.") self.timers = [] super(Service, self).stop()
Example #8
Source File: test_service.py From oslo.service with Apache License 2.0 | 5 votes |
def test_mutate_hook_process_launcher(self): """Test mutate_config_files is called by ProcessLauncher on SIGHUP. Forks happen in _spawn_service and ProcessLauncher. So we get three tiers of processes, the top tier being the test process. self.pid refers to the middle tier, which represents our application. Both service_maker and launcher_maker execute in the middle tier. The bottom tier is the workers. The behavior we want is that when the application (middle tier) receives a SIGHUP, it catches that, calls mutate_config_files and relaunches all the workers. This causes them to inherit the mutated config. """ mutate = multiprocessing.Event() ready = multiprocessing.Event() def service_maker(): self.conf.register_mutate_hook(lambda c, f: mutate.set()) return ServiceWithTimer(ready) def launcher_maker(): return service.ProcessLauncher(self.conf, restart_method='mutate') self.pid = self._spawn_service(1, service_maker, launcher_maker) timeout = 5 ready.wait(timeout) self.assertTrue(ready.is_set(), 'Service never became ready') ready.clear() self.assertFalse(mutate.is_set(), "Hook was called too early") os.kill(self.pid, signal.SIGHUP) ready.wait(timeout) self.assertTrue(ready.is_set(), 'Service never back after SIGHUP') self.assertTrue(mutate.is_set(), "Hook wasn't called")
Example #9
Source File: test_service.py From oslo.service with Apache License 2.0 | 5 votes |
def test_service_restart(self): ready = self._spawn() timeout = 5 ready.wait(timeout) self.assertTrue(ready.is_set(), 'Service never became ready') ready.clear() os.kill(self.pid, signal.SIGHUP) ready.wait(timeout) self.assertTrue(ready.is_set(), 'Service never back after SIGHUP')
Example #10
Source File: test_service.py From oslo.service with Apache License 2.0 | 5 votes |
def _test_launch_single(self, workers, mock_launch): svc = service.Service() service.launch(self.conf, svc, workers=workers) mock_launch.assert_called_with(svc, workers=workers)
Example #11
Source File: test_service.py From oslo.service with Apache License 2.0 | 5 votes |
def test_launch_invalid_workers_number(self): svc = service.Service() for num_workers in [0, -1]: self.assertRaises(ValueError, service.launch, self.conf, svc, num_workers) for num_workers in ["0", "a", "1"]: self.assertRaises(TypeError, service.launch, self.conf, svc, num_workers)
Example #12
Source File: test_service.py From oslo.service with Apache License 2.0 | 5 votes |
def test_stop(self, signal_mock, alarm_mock): signal_mock.SIGTERM = 15 launcher = service.ProcessLauncher(self.conf) self.assertTrue(launcher.running) pid_nums = [22, 222] fakeServiceWrapper = service.ServiceWrapper(service.Service(), 1) launcher.children = {pid_nums[0]: fakeServiceWrapper, pid_nums[1]: fakeServiceWrapper} with mock.patch('oslo_service.service.os.kill') as mock_kill: with mock.patch.object(launcher, '_wait_child') as _wait_child: def fake_wait_child(): pid = pid_nums.pop() return launcher.children.pop(pid) _wait_child.side_effect = fake_wait_child with mock.patch('oslo_service.service.Service.stop') as \ mock_service_stop: mock_service_stop.side_effect = lambda: None launcher.stop() self.assertFalse(launcher.running) self.assertFalse(launcher.children) mock_kill.assert_has_calls([mock.call(222, signal_mock.SIGTERM), mock.call(22, signal_mock.SIGTERM)], any_order=True) self.assertEqual(2, mock_kill.call_count) mock_service_stop.assert_called_once_with()
Example #13
Source File: rpc.py From tacker with Apache License 2.0 | 5 votes |
def __init__(self, host, topic, manager=None, serializer=None): super(Service, self).__init__() self.host = host self.topic = topic self.serializer = serializer if manager is None: self.manager = self else: self.manager = manager
Example #14
Source File: rpc.py From tacker with Apache License 2.0 | 5 votes |
def stop(self): # Try to shut the connection down, but if we get any sort of # errors, go ahead and ignore them.. as we're shutting down anyway try: self.conn.close() except Exception: pass super(Service, self).stop()
Example #15
Source File: test_keystone_listener.py From barbican with Apache License 2.0 | 5 votes |
def test_should_wait(self, mock_service_wait): msg_server = keystone_listener.MessageServer(self.conf) msg_server.wait() self.assertFalse(self.msg_server_mock.stop.called, 'No need to call' 'message server wait() as Service itself creates the ' ' wait event') self.assertTrue(mock_service_wait.called, 'Expected to only call ' 'service.Service.wait() method')
Example #16
Source File: keystone_listener.py From barbican with Apache License 2.0 | 5 votes |
def __init__(self, conf): pool_size = conf.keystone_notifications.thread_pool_size NotificationTask.__init__(self, conf) service.Service.__init__(self, threads=pool_size) self.target = queue.get_notification_target() self._msg_server = queue.get_notification_server(targets=[self.target], endpoints=[self])
Example #17
Source File: service.py From senlin with Apache License 2.0 | 5 votes |
def __init__(self, name, host, topic, threads=None): threads = threads or 1000 super(Service, self).__init__(threads) self.name = name self.host = host self.topic = topic
Example #18
Source File: service.py From senlin with Apache License 2.0 | 5 votes |
def start(self): LOG.info('Starting %(name)s service (version: %(version)s)', { 'name': self.name, 'version': version.version_info.version_string() }) super(Service, self).start()
Example #19
Source File: service.py From senlin with Apache License 2.0 | 5 votes |
def stop(self, graceful=True): LOG.info('Stopping %(name)s service', {'name': self.name}) super(Service, self).stop(graceful)
Example #20
Source File: service.py From cyborg with Apache License 2.0 | 5 votes |
def stop(self, graceful=True): try: self.rpcserver.stop() self.rpcserver.wait() except Exception as e: LOG.exception('Service error occurred when stopping the ' 'RPC server. Error: %s', e) super(RPCService, self).stop(graceful=graceful) LOG.info('Stopped RPC server for service %(service)s on host ' '%(host)s.', {'service': self.topic, 'host': self.host})
Example #21
Source File: service.py From karbor with Apache License 2.0 | 5 votes |
def kill(self): """Destroy the service object in the datastore.""" self.stop() try: db.service_destroy(context.get_admin_context(), self.service_id) except exception.NotFound: LOG.warning('Service killed that has no database entry')
Example #22
Source File: service.py From karbor with Apache License 2.0 | 5 votes |
def stop(self): # Try to shut the connection down, but if we get any sort of # errors, go ahead and ignore them.. as we're shutting down anyway try: self.rpcserver.stop() except Exception: pass for x in self.timers: try: x.stop() except Exception: pass self.timers = [] super(Service, self).stop()
Example #23
Source File: rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
def __init__(self, host, topic, manager=None, serializer=None): super(Service, self).__init__() self.host = host self.topic = topic self.serializer = serializer if manager is None: self.manager = self else: self.manager = manager
Example #24
Source File: rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
def stop(self): # Try to shut the connection down, but if we get any sort of # errors, go ahead and ignore them.. as we're shutting down anyway try: self.conn.close() except Exception: # nosec pass super(Service, self).stop()
Example #25
Source File: service.py From manila with Apache License 2.0 | 5 votes |
def kill(self): """Destroy the service object in the datastore.""" self.stop() try: db.service_destroy(context.get_admin_context(), self.service_id) except exception.NotFound: LOG.warning('Service killed that has no database entry.')
Example #26
Source File: rpc_service.py From zun with Apache License 2.0 | 5 votes |
def stop(self): if self._server: self._server.stop() self._server.wait() super(Service, self).stop()
Example #27
Source File: service.py From kuryr-kubernetes with Apache License 2.0 | 5 votes |
def start(self): LOG.info("Service '%s' starting", self.__class__.__name__) super(KuryrK8sService, self).start() if not CONF.kubernetes.controller_ha: LOG.info('Running in non-HA mode, starting watcher immediately.') self.watcher.start() self.pool_driver.sync_pools() else: LOG.info('Running in HA mode, watcher will be started later.') f = functools.partial(self.run_periodic_tasks, None) self.tg.add_timer(1, f) self.health_manager.run() LOG.info("Service '%s' started", self.__class__.__name__)
Example #28
Source File: service.py From kuryr-kubernetes with Apache License 2.0 | 5 votes |
def wait(self): super(KuryrK8sService, self).wait() LOG.info("Service '%s' stopped", self.__class__.__name__)
Example #29
Source File: service.py From kuryr-kubernetes with Apache License 2.0 | 5 votes |
def stop(self, graceful=False): LOG.info("Service '%s' stopping", self.__class__.__name__) self.watcher.stop() super(KuryrK8sService, self).stop(graceful)
Example #30
Source File: service.py From designate with Apache License 2.0 | 5 votes |
def __init__(self, name, threads=None): threads = threads or 1000 super(Service, self).__init__(threads) self.name = name self.host = CONF.host policy.init() if not rpc.initialized(): rpc.init(CONF)