remote_ip = socket.gethostbyname(hostname)
return local_ip == remote_ip
except:
- utils.header("WARNING : something wrong in is_local_hostname with hostname=%s"%hostname)
+ utils.header("WARNING : something wrong in is_local_hostname with hostname={}".format(hostname))
return False
# some boxes have their working space in user's homedir (/root),
def key_part(self):
if not self.key:
return ""
- return "-i %s " % self.key
+ return "-i {} ".format(self.key)
def hostname_part(self):
if not self.username:
return self.hostname
else:
- return "%s@%s" % (self.username,self.hostname)
+ return "{}@{}".format(self.username,self.hostname)
# command gets run on the right box
def actual_command(self, command, keep_stdin=False, dry_run=False, backslash=True):
def header(self, message):
if not message:
return
- print "===============",message
+ print("===============",message)
sys.stdout.flush()
def run(self, command, message=None, background=False, dry_run=False):
if self.is_local():
return utils.system(command, background)
self.create_buildname_once(dry_run)
- return self.run("cd %s ; %s" % (self.fullname(self.buildname), command),
+ return self.run("cd {} ; {}".format(self.fullname(self.buildname), command),
background=background, dry_run=dry_run)
def fullname(self, dirname):
# ab. paths remain as-is
if not abs:
if dirname:
- dirname = "%s/%s" % (self.buildname,dirname)
+ dirname = "{}/{}".format(self.buildname, dirname)
else:
dirname = self.buildname
dirname = self.fullname(dirname)
if dirname == '.':
return
- return self.run("mkdir -p %s" % dirname, dry_run=dry_run)
+ return self.run("mkdir -p {}".format(dirname), dry_run=dry_run)
def rmdir(self, dirname=None, dry_run=False):
if self.is_local():
return shutil.rmtree(dirname)
return 0
if dirname:
- dirname = "%s/%s" % (self.buildname,dirname)
+ dirname = "{}/{}".format(self.buildname, dirname)
else:
dirname = self.buildname
dirname = self.fullname(dirname)
- return self.run("rm -rf %s" % dirname, dry_run=dry_run)
+ return self.run("rm -rf {}".format(dirname), dry_run=dry_run)
def create_buildname_once(self, dry_run):
if self.is_local():
if recursive:
scp_command += "-r "
scp_command += self.key_part()
- scp_command += "%s %s:%s/%s" % (local_file, self.hostname_part(),
- self.fullname(self.buildname),
- os.path.basename(local_file) or ".")
+ scp_command += "{} {}:{}/{}".format(local_file, self.hostname_part(),
+ self.fullname(self.buildname),
+ os.path.basename(local_file) or ".")
if dry_run:
- utils.header("DRY RUN TestSsh.copy %s" % scp_command)
+ utils.header("DRY RUN TestSsh.copy {}".format(scp_command))
# need to be consistent with the non-dry-run mode
return 0
return utils.system(scp_command)
if self.is_local():
dest = ""
else:
- dest = "%s:" % self.hostname_part()
+ dest = "{}:".format(self.hostname_part())
scp_command = "scp "
scp_command += TestSsh.std_options
if recursive:
scp_command += "-r "
scp_command += self.key_part()
- scp_command += "%s %s%s" % (local_file, dest, remote_file)
+ scp_command += "{} {}{}".format(local_file, dest, remote_file)
if dry_run:
- utils.header("DRY RUN TestSsh.copy %s" % scp_command)
+ utils.header("DRY RUN TestSsh.copy {}".format(scp_command))
# need to be consistent with the non-dry-run mode
return 0
return utils.system(scp_command)
command="cp "
if recursive:
command += "-r "
- command += "%s %s" % (remote_file,local_file)
+ command += "{} {}".format(remote_file, local_file)
else:
command = "scp "
if not dry_run:
if remote_file.find("/") == 0:
remote_path = remote_file
else:
- remote_path = "%s/%s" % (self.buildname, remote_file)
+ remote_path = "{}/{}".format(self.buildname, remote_file)
remote_path = self.fullname(remote_path)
- command += "%s:%s %s" % (self.hostname_part(), remote_path, local_file)
+ command += "{}:{} {}".format(self.hostname_part(), remote_path, local_file)
return utils.system(command)
# this is only to avoid harmless message when host cannot be identified
# the only place where this is needed is when tring to reach a slice in a node,
# which is done from the test master box
def clear_known_hosts(self):
- known_hosts = "%s/.ssh/known_hosts" % os.getenv("HOME")
- utils.header("Clearing entry for %s in %s" % (self.hostname, known_hosts))
- return utils.system("sed -i -e /^%s/d %s" % (self.hostname, known_hosts))
+ known_hosts = "{}/.ssh/known_hosts".format(os.getenv("HOME"))
+ utils.header("Clearing entry for {} in {}".format(self.hostname, known_hosts))
+ return utils.system("sed -i -e /^{}/d {}".format(self.hostname, known_hosts))