def env(test_results, config='init-myapp.yaml', workdir='/tmp/lago-workdir'): lago_env = sdk.init( config=config, workdir=workdir, ) lago_env.start() yield lago_env collect_path = os.path.join(test_results, 'collect') lago_env.collect_artifacts(output_dir=collect_path, ignore_nopath=True) lago_env.destroy()
def test_init_logger_new_env(self, tmpdir, monkeypatch, mock_workdir, empty_prefix, level): log_path = tmpdir.mkdir('logs').join('test.log') monkeypatch.setattr('lago.cmd.do_init', lambda **kwargs: (mock_workdir, empty_prefix)) sdk.init(config=None, workdir=None, logfile=str(log_path), loglevel=level) handlers = [ h for h in logging.root.handlers if isinstance(h, logging.FileHandler) ] assert len(handlers) == 1 handler = handlers.pop() assert handler.stream.name == str(log_path) assert handler.level == getattr(logging, level) logging.root.removeHandler(handler)
def test_init_logger_new_env( self, tmpdir, monkeypatch, mock_workdir, empty_prefix, level ): log_path = tmpdir.mkdir('logs').join('test.log') monkeypatch.setattr( 'lago.cmd.do_init', lambda **kwargs: (mock_workdir, empty_prefix) ) sdk.init( config=None, workdir=None, logfile=str(log_path), loglevel=level ) handlers = [ h for h in logging.root.handlers if isinstance(h, logging.FileHandler) ] assert len(handlers) == 1 handler = handlers.pop() assert handler.stream.name == str(log_path) assert handler.level == getattr(logging, level) logging.root.removeHandler(handler)
def env(request, init_fname, test_results, tmp_workdir, external_log): workdir = os.path.join(str(tmp_workdir), 'lago') env = sdk.init( init_fname, workdir=workdir, logfile=str(external_log), loglevel=logging.DEBUG, ) env.start() try: yield env collect_path = os.path.join(test_results, 'collect') env.collect_artifacts(output_dir=collect_path, ignore_nopath=True) shutil.copytree(workdir, os.path.join(test_results, 'workdir'), ignore=shutil.ignore_patterns('*images*')) finally: env.stop() env.destroy()
def env(request, init_fname, test_results, tmp_workdir, external_log): workdir = os.path.join(str(tmp_workdir), 'lago') env = sdk.init( init_fname, workdir=workdir, logfile=str(external_log), loglevel=logging.DEBUG, ) env.start() try: yield env collect_path = os.path.join(test_results, 'collect') env.collect_artifacts(output_dir=collect_path, ignore_nopath=True) shutil.copytree( workdir, os.path.join(test_results, 'workdir'), ignore=shutil.ignore_patterns('*images*') ) finally: env.stop() env.destroy()
def env(cls_results_path): config = 'init-jenkins.yaml' workdir = '/tmp/lago-workdir' raise NotImplementedError('Implement me') try: lago_env = sdk.init( config=config, workdir=workdir, logfile=os.path.join(cls_results_path, 'lago.log'), loglevel=logging.DEBUG ) except PrefixAlreadyExists: lago_env = sdk.load_env( workdir=workdir, logfile=os.path.join(cls_results_path, 'lago.log'), loglevel=logging.DEBUG ) lago_env.start() yield lago_env
def env(cls_results_path): config = 'init-jenkins.yaml' workdir = '/tmp/lago-workdir' try: lago_env = sdk.init(config=config, workdir=workdir, logfile=os.path.join(cls_results_path, 'lago.log'), loglevel=logging.DEBUG) except PrefixAlreadyExists: lago_env = sdk.load_env(workdir=workdir, logfile=os.path.join(cls_results_path, 'lago.log'), loglevel=logging.DEBUG) lago_env.start() yield lago_env # Task: Add log collection. The logs should be collected to a # sub directory of 'cls_result_path collect_path = os.path.join(cls_results_path, 'collect') lago_env.collect_artifacts(output_dir=collect_path, ignore_nopath=True)