def test_logger_debug_without_file(self): '''Tests debug logger w/o debug log file''' mock_logger = get_hostpool_logger('mock', parent_logger=self.ctx.logger, debug=True) self.assertThat(mock_logger.parent, Equals(self.ctx.logger)) self.assertThat(mock_logger.level, Equals(logging.DEBUG))
def main(): '''Entry point''' logger = get_hostpool_logger('configure', debug=ctx.node.properties.get('debug')) if not ctx.node.properties.get('pool'): logger.info('Configuration file for the Host-Pool service ' 'was not specified. Continuing without seed hosts') ctx.instance.runtime_properties['seed_hosts'] = None return logger.debug('Downloading host-pool configuration file "{0}" to "{1}"' .format(ctx.node.properties['pool'], POOL_CFG_PATH)) ctx.download_resource(ctx.node.properties['pool'], target_path=POOL_CFG_PATH) if not os.path.exists(POOL_CFG_PATH): raise NonRecoverableError('Configuration file for the Host-Pool ' 'service could not be downloaded') # Load our configuration data with open(POOL_CFG_PATH) as f_cfg: cfg = None logger.info('Loading Host-Pool seed hosts') try: cfg = yaml.load(f_cfg) except yaml.YAMLError: raise NonRecoverableError('Configuration file for the Host-Pool ' 'service is not valid YAML') logger.info('Converting host key files from blueprint') seed_config = set_host_key_content(cfg, logger) ctx.instance.runtime_properties['seed_config'] = seed_config
def main(): '''Entry point''' logger = get_hostpool_logger('start', debug=ctx.node.properties.get('debug')) # Make sure VIRTUALENV is set if not VIRT_DIR: raise NonRecoverableError( 'VIRTUALENV or VIRTUAL_ENV environment variable must be set!') if ctx.node.properties.get('run_as_daemon'): # Grab the init script from the package svc_tmp = download_service(logger) # Set the correct service permissions set_service_permissions(svc_tmp, logger) # Move the init script to /etc/init.d/ install_service(svc_tmp, logger) # Start the service start_service(logger) # Enable the service to start on boot set_service_on_boot(logger) else: # Start the stand-alone process start_standalone_service(logger) # Test if the service is alive test_service_liveness(logger) # Install any seed hosts data into the service install_seed_hosts(logger) # Set runtime properties ctx.instance.runtime_properties['service_name'] = SVC_NAME ctx.instance.runtime_properties['endpoint'] = ENDPOINT
def test_logger_debug_with_file(self): '''Tests debug logger w/ debug log file''' mock_logger = get_hostpool_logger('mock', parent_logger=self.ctx.logger, debug=True, log_file=self.debug_logfile) self.assertThat(mock_logger.parent, Equals(self.ctx.logger)) self.assertThat(mock_logger.level, Equals(logging.DEBUG)) self.assertThat(os.path.exists(self.debug_logfile), Equals(True))
def main(): '''Entry point''' logger = get_hostpool_logger('stop', debug=ctx.node.properties.get('debug')) if ctx.node.properties.get('run_as_daemon'): # Delete working directory stop_service(logger) else: # Kill service process stop_standalone_service(logger)
def main(): '''Entry point''' logger = get_hostpool_logger('delete', debug=ctx.node.properties.get('debug')) if ctx.node.properties.get('run_as_daemon'): # Disable the service from starting on boot remove_service_from_boot(logger) # Delete the actual service sysv init script uninstall_service(logger) # Delete working directory logger.info('Deleting directory "{0}"'.format(BASE_DIR)) rmtree(BASE_DIR, ignore_errors=True)
def test_logger_no_parent_logger(self): '''Tests debug logger w/o parent logger''' with ExpectedException(NonRecoverableError): get_hostpool_logger('mock')
def test_logger_non_debug(self): '''Tests non-debug logger''' mock_logger = get_hostpool_logger('mock', parent_logger=self.ctx.logger) self.assertThat(mock_logger.parent, Equals(self.ctx.logger))