def install_deps(cc_src): cmd = ['python', cc_src, 'deps'] deps = check_output(cmd).strip() if deps: cmd = 'sudo apt-get -y install ' + deps if call(cmd, shell=True) != 0: sys.stderr.write('Some dependencies failed to install ' 'but assuming things okay.\n')
def install_deps(cc_src): cmd = ['python', cc_src, 'deps'] deps = check_output(cmd).strip() if deps: cmd = 'sudo apt-get -y install ' + deps if call(cmd, shell=True) != 0: sys.stderr.write('Some dependencies failed to install ' 'but assuming things okay.\n')
def get_git_summary(mode='local', remote_path=None): git_summary_src = path.join(project_root.DIR, 'test', 'git_summary.sh') local_git_summary = check_output(git_summary_src, cwd=project_root.DIR) if mode == 'remote': r = parse_remote_path(remote_path) git_summary_src = path.join( r['pantheon_dir'], 'test', 'git_summary.sh') ssh_cmd = 'cd %s; %s' % (r['pantheon_dir'], git_summary_src) ssh_cmd = ' '.join(r['ssh_cmd']) + ' "%s"' % ssh_cmd remote_git_summary = check_output(ssh_cmd, shell=True) if local_git_summary != remote_git_summary: sys.stderr.write( '--- local git summary ---\n%s\n' % local_git_summary) sys.stderr.write( '--- remote git summary ---\n%s\n' % remote_git_summary) sys.exit('Repository differed between local and remote sides') return local_git_summary
def get_git_summary(mode='local', remote_path=None): git_summary_src = path.join(project_root.DIR, 'test', 'git_summary.sh') local_git_summary = check_output(git_summary_src, cwd=project_root.DIR) if mode == 'remote': r = parse_remote_path(remote_path) git_summary_src = path.join(r['pantheon_dir'], 'test', 'git_summary.sh') ssh_cmd = 'cd %s; %s' % (r['pantheon_dir'], git_summary_src) ssh_cmd = ' '.join(r['ssh_cmd']) + ' "%s"' % ssh_cmd remote_git_summary = check_output(ssh_cmd, shell=True) if local_git_summary != remote_git_summary: sys.stderr.write('--- local git summary ---\n%s\n' % local_git_summary) sys.stderr.write('--- remote git summary ---\n%s\n' % remote_git_summary) sys.exit('Repository differed between local and remote sides') return local_git_summary
def who_runs_first(cc): cc_src = path.join(project_root.DIR, 'src', cc + '.py') cmd = ['python', cc_src, 'run_first'] run_first = check_output(cmd).strip() if run_first == 'receiver': run_second = 'sender' elif run_first == 'sender': run_second = 'receiver' else: sys.exit('Must specify "receiver" or "sender" runs first') return run_first, run_second
def who_runs_first(cc): cc_src = path.join(project_root.DIR, 'src', cc + '.py') cmd = ['python', cc_src, 'run_first'] run_first = check_output(cmd).strip() if run_first == 'receiver': run_second = 'sender' elif run_first == 'sender': run_second = 'receiver' else: sys.exit('Must specify "receiver" or "sender" runs first') return run_first, run_second
def test_schemes(args): src_dir = path.join(project_root.DIR, 'src') if args.all: schemes = parse_config()['schemes'].keys() elif args.schemes is not None: schemes = args.schemes.split() for scheme in schemes: sys.stderr.write('Testing %s...\n' % scheme) src = path.join(src_dir, scheme + '.py') run_first = check_output([src, 'run_first']).strip() run_second = 'receiver' if run_first == 'sender' else 'sender' port = get_open_port() # run first to run cmd = [src, run_first, port] first_proc = Popen(cmd, preexec_fn=os.setsid) # wait for 'run_first' to be ready time.sleep(3) # run second to run cmd = [src, run_second, '127.0.0.1', port] second_proc = Popen(cmd, preexec_fn=os.setsid) # test lasts for 3 seconds signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(3) try: for proc in [first_proc, second_proc]: proc.wait() if proc.returncode != 0: sys.exit('%s failed in tests' % scheme) except TimeoutError: pass except Exception as exception: sys.exit('test_schemes.py: %s\n' % exception) else: signal.alarm(0) sys.exit('test exited before time limit') finally: # cleanup kill_proc_group(first_proc) kill_proc_group(second_proc)
def test_schemes(args): src_dir = path.join(project_root.DIR, 'src') if args.all: schemes = parse_config()['schemes'].keys() elif args.schemes is not None: schemes = args.schemes.split() for scheme in schemes: sys.stderr.write('Testing %s...\n' % scheme) src = path.join(src_dir, scheme + '.py') run_first = check_output([src, 'run_first']).strip() run_second = 'receiver' if run_first == 'sender' else 'sender' port = get_open_port() # run first to run cmd = [src, run_first, port] first_proc = Popen(cmd, preexec_fn=os.setsid) # wait for 'run_first' to be ready time.sleep(3) # run second to run cmd = [src, run_second, '127.0.0.1', port] second_proc = Popen(cmd, preexec_fn=os.setsid) # test lasts for 3 seconds signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(3) try: for proc in [first_proc, second_proc]: proc.wait() if proc.returncode != 0: sys.exit('%s failed in tests' % scheme) except TimeoutError: pass except Exception as exception: sys.exit('test_schemes.py: %s\n' % exception) else: signal.alarm(0) sys.exit('test exited before time limit') finally: # cleanup kill_proc_group(first_proc) kill_proc_group(second_proc)
def main(): h.call(['echo', '1']) h.check_call('echo 2', shell=True) ret = h.check_output(['echo', '3']).strip() print ret assert ret == '3' proc = h.Popen(['echo', '4'], stdout=h.PIPE) ret = proc.communicate()[0].strip() print ret assert ret == '4' print h.get_open_port() h.make_sure_path_exists(h.TMPDIR) print h.parse_config()
def query_clock_offset(ntp_addr, ssh_cmd): local_clock_offset = None remote_clock_offset = None ntp_cmds = {} ntpdate_cmd = ['ntpdate', '-t', '5', '-quv', ntp_addr] ntp_cmds['local'] = ntpdate_cmd ntp_cmds['remote'] = ssh_cmd + ntpdate_cmd for side in ['local', 'remote']: cmd = ntp_cmds[side] fail = True for _ in xrange(3): try: offset = check_output(cmd) sys.stderr.write(offset) offset = offset.rsplit(' ', 2)[-2] offset = str(float(offset) * 1000) except subprocess.CalledProcessError: sys.stderr.write('Failed to get clock offset\n') except ValueError: sys.stderr.write('Cannot convert clock offset to float\n') else: if side == 'local': local_clock_offset = offset else: remote_clock_offset = offset fail = False break if fail: sys.stderr.write('Failed after 3 queries to NTP server\n') return local_clock_offset, remote_clock_offset
def query_clock_offset(ntp_addr, ssh_cmd): local_clock_offset = None remote_clock_offset = None ntp_cmds = {} ntpdate_cmd = ['ntpdate', '-t', '5', '-quv', ntp_addr] ntp_cmds['local'] = ntpdate_cmd ntp_cmds['remote'] = ssh_cmd + ntpdate_cmd for side in ['local', 'remote']: cmd = ntp_cmds[side] fail = True for _ in xrange(3): try: offset = check_output(cmd) sys.stderr.write(offset) offset = offset.rsplit(' ', 2)[-2] offset = str(float(offset) * 1000) except subprocess.CalledProcessError: sys.stderr.write('Failed to get clock offset\n') except ValueError: sys.stderr.write('Cannot convert clock offset to float\n') else: if side == 'local': local_clock_offset = offset else: remote_clock_offset = offset fail = False break if fail: sys.stderr.write('Failed after 3 queries to NTP server\n') return local_clock_offset, remote_clock_offset