def test_normal_flow_update_mode(self): utils.init_ignore() db = utils.DB(None, [ utils.Job(tag='test_normal_flow', hosts=[remote_host], using_host=remote_host, remote_path='~/Projects/test-remotedocker/normal-flow', command=['cat', 'supplementary/hello.py'], step=None), utils.Job(tag='another_task', hosts=[remote_host], using_host=remote_host, remote_path='~/Projects/test-remotedocker/normal-flow', command=['cat', 'supplementary/hello.py'], step='running') ]) log = run.run(db.jobs[0], db, run.NormalFlow) print('run output:', log) self.assertEqual(log, 'print(\'hello world!\')') _db = utils.DB.load() print(_db.dict()) self.assertDictEqual(_db.latest_job.dict(), db.jobs[0].dict()) from os import remove remove(utils.path_file_ignore()) remove(utils.path_file_db())
def test_print_list(self): db = utils.DB('[email protected]', [ utils.Job(tag='firstjob', hosts=['[email protected]', '*****@*****.**'], using_host='[email protected]', remote_path='~/Projects/test/this/is/the/path', command=['python', 'test_test_test.py'], step=None) ]) print_list(db)
def test_DB_remove_job(self): import arrow a = arrow.utcnow() d = { 'latest_job': { 'tag': 'tag', 'hosts': ['host1', 'host2'], 'using_host': 'host1', 'step': 'step', 'docker': 'docker', 'remote_path': 'remote_path', 'command': 'command', 'start_time': str(a), 'container': 'container', 'oth': dict(a=10), }, 'jobs': [{ 'tag': 'tag', 'hosts': ['host1', 'host2'], 'using_host': 'host1', 'step': 'step', 'docker': 'docker', 'remote_path': 'remote_path', 'command': 'command', 'start_time': str(a), 'container': 'container', 'oth': dict(a=10), }, { 'tag': 'tag2', 'hosts': ['host1', 'host2'], 'using_host': 'host1', 'step': 'step', 'docker': 'docker', 'remote_path': 'remote_path', 'command': 'command', 'start_time': str(a), 'container': 'container', 'oth': dict(a=10), }] } db = utils.DB.parse(d) db.remove_job(utils.Job('tag', [], None, None, None, None)) self.assertEqual(len(db.jobs), 1) self.assertEqual(db.jobs[0].tag, 'tag2')
def act_run_new(args): from src import utils db = utils.DB.load() if not args.tag: raise utils.errors.ArgumentError('Tag not provided') if not args.host: latest_host = db.get_latest('using_host') if not latest_host: raise utils.errors.LatestHostNotFound('No default (latest) host, must explicitly provide one') args.host = latest_host if not args.path: args.path = db.get_path_by_host(args.host) if not args.docker: latest_docker = db.get_latest('docker') if not latest_docker: latest_docker = 'docker' args.docker = latest_docker # search for existing job for duplicates try: job = db.get_job_by_tag(args.tag) raise utils.errors.JobDuplicate('Job duplicate with tag: {} host: {}'.format(job.tag, job.hosts)) except utils.errors.TagNotFound: # no job duplicate great! pass print('Run using docker: {}'.format(args.docker)) job = utils.Job(tag=args.tag, hosts=[args.host], using_host=args.host, remote_path=args.path, command=args.command, step=None, docker=args.docker) db.add_job(job) from src.actions import run run.run(job, db, run.NormalFlow)
def test_normal_flow_err(self): utils.init_ignore() db = utils.DB(None, [ utils.Job( tag='test_normal_flow_err', hosts=[remote_host], using_host=remote_host, remote_path='~/Projects/test-remotedocker/normal-flow-err', command=['aoeu'], step=None) ]) self.assertRaises(utils.errors.WrongExitCode, run.run, db.jobs[0], db, run.NormalFlow) _db = utils.DB.load() self.assertDictEqual(_db.latest_job.dict(), db.jobs[0].dict()) from os import remove remove(utils.path_file_ignore()) remove(utils.path_file_db())
def test_Job_init_without_start_time(self): import arrow j = utils.Job('tag', ['host1', 'host2'], 'host1', 'remote_path', 'command', 'step') aa = arrow.get(j.start_time) print(aa)