def push_tag(): if not args.tag: print('Skip push tag') return print('Push tag: {}'.format(args.tag)) succ(['docker tag', args.temp_name, FULL_TAG]) succ(['docker push', FULL_TAG])
def push_branch(): if args.branch not in args.push_branches.split(','): print('Skip push branch: {}'.format(args.branch)) return print('Push branch {}'.format(args.branch)) succ(['docker tag ', args.temp_name, FULL_BRANCH]) succ(['docker push ', FULL_BRANCH])
def create_database(): print('Create database') c = 0 while c < 30: try: succ( 'echo create database plugin | psql -h localhost -p 40001 -U postgres' ) return except: c += 1 time.sleep(1)
def write_dyn_cfg(myid, myip, others=None): if others: role = 'observer' else: role = 'participant' with open(DYN_CFG, 'w') as f: if others: f.write(others) f.write('\n') f.write(pat(myid=myid, myip=myip, role=role)) else: f.write(pat(myid=myid, myip=myip, role=role)) init(myid) with open(DYN_CFG) as f: printe('CONFIG: {}\n\n'.format(f.read())) if others: init(myid) succ(['/opt/zookeeper/bin/zkServer.sh start'], False) cfg = pat(myid=myid, myip=myip, role='participant') seed = os.environ.get('ZK_SEED') printe('Reconfiguring...') succ([RECONF(seed=seed, cfg=cfg)])
def run(): with open(DYN_CFG) as f: printe('RUN EXISTING CONFIG: {}'.format(f.read())) succ([RUN], False)
def init(myid): succ([INIT(myid=myid)])
def cache(): print('Cache image as: {}'.format(args.cache_name)) succ(['docker tag', args.temp_name, args.cache_name, '&& docker rmi', args.temp_name])
def run_test(): succ([args.test], check_stderr=False)
def build(): sha = args.temp_name cmd = ['docker build -t', sha, '-f', args.docker_file, '.'] print('Build: {}'.format(' '.join(cmd))) succ(cmd)
def run(cmd): return succ(cmd, check_stderr=False)
def test_succ_handle_error(): stderr = [] with pytest.raises(AssertionError): succ('bash randomcommand', stderr=stderr) assert stderr, 'Should have something: {}'.format(stderr)