orchestra/remote: use sh instead of run
@@ -7,6 +7,7 @@ from teuthology.orchestra import run
from teuthology.orchestra import connection
from teuthology.orchestra.opsys import OS
from teuthology import misc
+from teuthology.exceptions import CommandFailedError
from teuthology.misc import host_shortname
import time
import re
@@ -123,14 +124,9 @@ class Remote(object):
return self._cidr
def _set_iface_and_cidr(self):
- proc = self.run(
- args=['PATH=/sbin:/usr/sbin', 'ip', 'addr', 'show'],
- stdout=StringIO(),
- )
- proc.wait()
+ ip_addr_show = self.sh('PATH=/sbin:/usr/sbin ip addr show')
regexp = 'inet.? %s' % self.ip_address
- proc.stdout.seek(0)
- for line in proc.stdout.readlines():
+ for line in ip_addr_show.split('\n'):
line = line.strip()
if re.match(regexp, line):
items = line.split()
@@ -142,9 +138,7 @@ class Remote(object):
@property
def hostname(self):
if not hasattr(self, '_hostname'):
- proc = self.run(args=['hostname', '--fqdn'], stdout=StringIO())
- proc.wait()
- self._hostname = proc.stdout.getvalue().strip()
+ self._hostname = self.sh('hostname --fqdn').strip()
return self._hostname
@property
@@ -262,7 +256,7 @@ class Remote(object):
"""
ftempl = '/tmp/teuthology-remote-$(date +%Y%m%d%H%M%S)-{}-XXXX'\
.format(label)
- script_file = self.sh("mktemp %s" % ftempl, stdout=StringIO()).strip()
+ script_file = self.sh("mktemp %s" % ftempl).strip()
self.sh("cat - | tee {script} ; chmod a+rx {script}"\
.format(script=script_file), stdin=script)
if sudo:
@@ -448,23 +442,21 @@ class Remote(object):
@property
def os(self):
if not hasattr(self, '_os'):
- proc = self.run(args=['cat', '/etc/os-release'], stdout=StringIO(),
- stderr=StringIO(), check_status=False)
- if proc.exitstatus == 0:
- self._os = OS.from_os_release(proc.stdout.getvalue().strip())
+ try:
+ os_release = self.sh('cat /etc/os-release').strip()
+ self._os = OS.from_os_release(os_release)
return self._os
+ except CommandFailedError:
+ pass
- proc = self.run(args=['lsb_release', '-a'], stdout=StringIO(),
- stderr=StringIO())
- self._os = OS.from_lsb_release(proc.stdout.getvalue().strip())
+ lsb_release = self.sh('lsb_release -a').strip()
+ self._os = OS.from_lsb_release(lsb_release)
return self._os
@property
def arch(self):
if not hasattr(self, '_arch'):
- proc = self.run(args=['uname', '-m'], stdout=StringIO())
- proc.wait()
- self._arch = proc.stdout.getvalue().strip()
+ self._arch = self.sh('uname -m').strip()
return self._arch
@property
