def _config_changed(self, filename, metadata, new_mtime): if metadata.config is not None: del self._services[metadata.config['name']] metadata.config = self._load_config(filename) metadata.mtime = new_mtime if (metadata.config is not None and metadata.config['name'] in self._services): LOGGER.error('Duplicate service name "%s" (defined in %s and %s)' % ( metadata.config['name'], self._services[metadata.config['name']], filename)) metadata.config = None if metadata.config is None: if metadata.thread is not None: metadata.thread.stop_service() return LOGGER.info('Updating service config for %s', metadata.config['name']) if metadata.thread is None: metadata.thread = service_thread.ServiceThread( self._service_poll_interval, self._state_directory, metadata.config) metadata.thread.start() metadata.thread.start_service() else: metadata.thread.restart_with_new_config(metadata.config) self._services[metadata.config['name']] = filename
def setUp(self): service_thread.ServiceThread.failures.reset() service_thread.ServiceThread.reconfigs.reset() service_thread.ServiceThread.upgrades.reset() self.mock_service_ctor = mock.patch( 'infra.services.service_manager.service.Service').start() self.mock_service = self.mock_service_ctor.return_value self.mock_service.name = 'foo' config = {'name': 'foo'} self.condition = FakeCondition() self.t = service_thread.ServiceThread( 10, '/foo', config, wait_condition=self.condition) self.mock_service_ctor.assert_called_once_with('/foo', config)
def _config_added(self, filename, mtime): config = self._load_config(filename) if config is None: # Add a bad metadata entry so we don't call _config_added again every # time we read it. self._metadata[filename] = _Metadata(mtime) return if config['name'] in self._services: LOGGER.error('Duplicate service name "%s" (defined in %s and %s)' % ( config['name'], self._services[config['name']], filename)) return LOGGER.info('Adding new service config for %s', config['name']) thread = service_thread.ServiceThread( self._service_poll_interval, self._state_directory, config) thread.start() thread.start_service() self._metadata[filename] = _Metadata(mtime, config, thread) self._services[config['name']] = filename