From: Kyr Shatskyy Date: Wed, 9 Oct 2019 11:18:23 +0000 (+0200) Subject: fog: get rid of StringIO usage for python3 portability X-Git-Tag: 1.1.0~221^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F1320%2Fhead;p=teuthology.git fog: get rid of StringIO usage for python3 portability Signed-off-by: Kyr Shatskyy --- diff --git a/teuthology/provision/fog.py b/teuthology/provision/fog.py index 607e01db4..993f30e3b 100644 --- a/teuthology/provision/fog.py +++ b/teuthology/provision/fog.py @@ -2,10 +2,10 @@ import json import logging import requests import socket +import re from datetime import datetime from paramiko import SSHException -from StringIO import StringIO import teuthology.orchestra @@ -276,15 +276,13 @@ class FOG(object): used to create the image initially. Fix that by making a call to /binhostname and tweaking /etc/hosts. """ - proc = self.remote.run(args='hostname', stdout=StringIO()) - wrong_hostname = proc.stdout.read().strip() - proc = self.remote.run( - args='grep %s /etc/hosts' % wrong_hostname, - stdout=StringIO(), + wrong_hostname = self.remote.sh('hostname').strip() + etc_hosts = self.remote.sh( + 'grep %s /etc/hosts' % wrong_hostname, check_status=False, - ) - if proc.returncode == 0: - wrong_ip = proc.stdout.readlines()[0].split(' ')[0] + ).strip() + if etc_hosts: + wrong_ip = re.split(r'\s+', etc_hosts.split('\n')[0].strip())[0] self.remote.run(args="sudo hostname %s" % self.shortname) self.remote.run( args="sudo sed -i -e 's/%s/%s/g' /etc/hosts" % (