def rsync(project,node,files='.',includes=None,excludes=None,**kwargs): '''Runs the rsync command on project, rsyncing it to node''' if includes is None: includes = [] if excludes is None: excludes = [] excludes_opts = [] for e in excludes: excludes_opts.append("--exclude={0}".format(e)) includes_opts = [] for i in includes: includes_opts.append("--include={0}".format(i)) local_project_files = os.path.join(project.get_cache_dir(),files) remote_project_path = project.location if config.testmode: remote_project_path = config.testmode_prefix+remote_project_path key_stmt = "" if project.key: key_stmt = "-i {0}".format(os.path.join(os.getcwd(),project.key)) command = ["rsync", "-av", "--delete"] command += excludes_opts command += includes_opts command += ["-e",'/usr/bin/ssh {0} -p{1}'.format(key_stmt,str(node.ssh_port))] command += ["--rsync-path=mkdir -p {0} && rsync".format(remote_project_path)] command += [local_project_files] command += ["{0}@{1}:{2}".format(project.user,node.ip,remote_project_path)] print(command) command_check_error(command,**kwargs)
def ssh(node, command, cwd="/tmp", user=getpass.getuser(), key=None, **kwargs): '''ssh's into a node and runs command, cd-ing into cwd first''' ssh_command = "cd {0} && {1}".format(cwd, command) command = ["ssh", "-t", "-q", "-p", str(node.ssh_port)] if key: command += ["-i", key] command += ["{0}@{1}".format(user, node.ip), ssh_command] print(str.join(" ", command[:-1]) + " '{0}'".format(ssh_command)) command_check_error(command, **kwargs)
def ssh(node,command,cwd="/tmp",user=getpass.getuser(),key=None,**kwargs): '''ssh's into a node and runs command, cd-ing into cwd first''' ssh_command = "cd {0} && {1}".format(cwd,command) command = ["ssh","-t","-q","-p",str(node.ssh_port)] if key: command += [ "-i",key] command += ["{0}@{1}".format(user,node.ip),ssh_command] print(str.join(" ",command[:-1])+" '{0}'".format(ssh_command)) command_check_error(command,**kwargs)
def rsync(project, node, files='.', includes=None, excludes=None, **kwargs): '''Runs the rsync command on project, rsyncing it to node''' if includes is None: includes = [] if excludes is None: excludes = [] excludes_opts = [] for e in excludes: excludes_opts.append("--exclude={0}".format(e)) includes_opts = [] for i in includes: includes_opts.append("--include={0}".format(i)) local_project_files = os.path.join(project.get_cache_dir(), files) remote_project_path = project.location if config.testmode: remote_project_path = config.testmode_prefix + remote_project_path key_stmt = "" if project.key: key_stmt = "-i {0}".format(os.path.join(os.getcwd(), project.key)) command = ["rsync", "-av", "--delete"] command += excludes_opts command += includes_opts command += [ "-e", '/usr/bin/ssh {0} -p{1}'.format(key_stmt, str(node.ssh_port)) ] command += [ "--rsync-path=mkdir -p {0} && rsync".format(remote_project_path) ] command += [local_project_files] command += [ "{0}@{1}:{2}".format(project.user, node.ip, remote_project_path) ] print(command) command_check_error(command, **kwargs)
def test_command_check_error(stderr_script): # exit code 0 is NOT an error assert command_check_error('/bin/true') == None # a nonzero exit code is an error with pytest.raises(Exception) as excinfo: command_check_error('/bin/false') m = re.search('returned exit code (\d)', str(excinfo.value)) assert int(m.groups()[0]) > 0 # stderr output w/ fail_on_stderr == True (the default) is an error with pytest.raises(Exception) as excinfo: command_check_error(stderr_script) assert 'There was error output running' in str(excinfo.value) # stderr output w/ fail_on_stderr == False is NOT an error assert command_check_error(stderr_script, fail_on_stderr=False) == None