From: Loic Dachary Date: Sat, 6 Aug 2016 08:48:14 +0000 (+0200) Subject: openstack: do not display openstack client warnings X-Git-Tag: 1.1.0~552^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9478bc7d069350180cba13479280964479988180;p=teuthology.git openstack: do not display openstack client warnings Because they are concatenated with the STDOUT by the sh function despite being output on STDERR and that breaks json parsing. Signed-off-by: Loic Dachary --- diff --git a/teuthology/nuke.py b/teuthology/nuke.py index 24cbb62ea6..f9b7887603 100644 --- a/teuthology/nuke.py +++ b/teuthology/nuke.py @@ -450,7 +450,7 @@ def stale_openstack_volumes(ctx, volumes): for volume in volumes: volume_id = volume.get('ID') or volume['id'] try: - volume = json.loads(sh("openstack volume show -f json " + + volume = json.loads(sh("openstack -q volume show -f json " + volume_id)) except subprocess.CalledProcessError: log.debug("stale-openstack: {id} disappeared, ignored" diff --git a/teuthology/openstack/__init__.py b/teuthology/openstack/__init__.py index f929fea293..b828452a91 100644 --- a/teuthology/openstack/__init__.py +++ b/teuthology/openstack/__init__.py @@ -66,7 +66,7 @@ class OpenStackInstance(object): def set_info(self): try: self.info = json.loads( - misc.sh("openstack server show -f json " + self.name_or_id)) + misc.sh("openstack -q server show -f json " + self.name_or_id)) enforce_json_dictionary(self.info) except CalledProcessError: self.info = None @@ -142,7 +142,7 @@ class OpenStackInstance(object): self.get_addresses())[0] def get_floating_ip(self): - ips = json.loads(misc.sh("openstack ip floating list -f json")) + ips = json.loads(misc.sh("openstack -q ip floating list -f json")) for ip in ips: if ip['Instance ID'] == self['id']: return ip['IP'] @@ -162,13 +162,13 @@ class OpenStackInstance(object): if not self.exists(): return True volumes = self.get_volumes() - misc.sh("openstack server set --name REMOVE-ME-" + self.name_or_id + + misc.sh("openstack -q server set --name REMOVE-ME-" + self.name_or_id + " " + self['id']) - misc.sh("openstack server delete --wait " + self['id'] + + misc.sh("openstack -q server delete --wait " + self['id'] + " || true") for volume in volumes: - misc.sh("openstack volume set --name REMOVE-ME " + volume + " || true") - misc.sh("openstack volume delete " + volume + " || true") + misc.sh("openstack -q volume set --name REMOVE-ME " + volume + " || true") + misc.sh("openstack -q volume delete " + volume + " || true") return True @@ -236,7 +236,7 @@ class OpenStack(object): """ Return true if the image exists in OpenStack. """ - found = misc.sh("openstack image list -f json --property name='" + + found = misc.sh("openstack -q image list -f json --property name='" + self.image_name(image) + "'") return len(json.loads(found)) > 0 @@ -244,7 +244,7 @@ class OpenStack(object): """ Return the uuid of the network in OpenStack. """ - r = json.loads(misc.sh("openstack network show -f json " + + r = json.loads(misc.sh("openstack -q network show -f json " + network)) return self.get_value(r, 'id') @@ -293,7 +293,7 @@ class OpenStack(object): """ Return the smallest flavor that satisfies the desired size. """ - flavors_string = misc.sh("openstack flavor list -f json") + flavors_string = misc.sh("openstack -q flavor list -f json") flavors = json.loads(flavors_string) found = [] for flavor in flavors: @@ -339,14 +339,14 @@ class OpenStack(object): def list_instances(): ownedby = "ownedby='" + teuth_config.openstack['ip'] + "'" all = json.loads(misc.sh( - "openstack server list -f json --long --name 'target'")) + "openstack -q server list -f json --long --name 'target'")) return filter(lambda instance: ownedby in instance['Properties'], all) @staticmethod def list_volumes(): ownedby = "ownedby='" + teuth_config.openstack['ip'] + "'" all = json.loads(misc.sh( - "openstack volume list -f json --long")) + "openstack -q volume list -f json --long")) def select(volume): return (ownedby in volume['Properties'] and volume['Display Name'].startswith('target')) @@ -587,9 +587,9 @@ ssh access : ssh {identity}{username}@{ip} # logs in /usr/share/nginx/ know already. """ try: - misc.sh("openstack flavor list | tail -2") + misc.sh("openstack -q flavor list | tail -2") except subprocess.CalledProcessError: - log.exception("openstack flavor list") + log.exception("openstack -q flavor list") raise Exception("verify openrc.sh has been sourced") self.set_provider() @@ -676,7 +676,7 @@ ssh access : ssh {identity}{username}@{ip} # logs in /usr/share/nginx/ among instances created within the same tenant. """ try: - misc.sh("openstack security group show teuthology") + misc.sh("openstack -q security group show teuthology") return except subprocess.CalledProcessError: pass @@ -698,7 +698,7 @@ openstack security group rule create --proto udp --dst-port 16000:65535 teutholo """ Return a floating IP address not associated with an instance or None. """ - ips = json.loads(misc.sh("openstack ip floating list -f json")) + ips = json.loads(misc.sh("openstack -q ip floating list -f json")) for ip in ips: if not ip['Instance ID']: return ip['IP'] @@ -706,13 +706,13 @@ openstack security group rule create --proto udp --dst-port 16000:65535 teutholo @staticmethod def create_floating_ip(): - pools = json.loads(misc.sh("openstack ip floating pool list -f json")) + pools = json.loads(misc.sh("openstack -q ip floating pool list -f json")) if not pools: return None pool = pools[0]['Name'] try: ip = json.loads(misc.sh( - "openstack ip floating create -f json '" + pool + "'")) + "openstack -q ip floating create -f json '" + pool + "'")) return TeuthologyOpenStack.get_value(ip, 'ip') except subprocess.CalledProcessError: log.debug("create_floating_ip: not creating a floating ip") @@ -729,14 +729,14 @@ openstack security group rule create --proto udp --dst-port 16000:65535 teutholo if not ip: ip = TeuthologyOpenStack.create_floating_ip() if ip: - misc.sh("openstack ip floating add " + ip + " " + name_or_id) + misc.sh("openstack -q ip floating add " + ip + " " + name_or_id) @staticmethod def get_floating_ip_id(ip): """ Return the id of a floating IP """ - results = json.loads(misc.sh("openstack ip floating list -f json")) + results = json.loads(misc.sh("openstack -q ip floating list -f json")) for result in results: if result['IP'] == ip: return str(result['ID']) @@ -754,9 +754,9 @@ openstack security group rule create --proto udp --dst-port 16000:65535 teutholo ip = OpenStackInstance(instance_id).get_floating_ip() if not ip: return - misc.sh("openstack ip floating remove " + ip + " " + instance_id) + misc.sh("openstack -q ip floating remove " + ip + " " + instance_id) ip_id = TeuthologyOpenStack.get_floating_ip_id(ip) - misc.sh("openstack ip floating delete " + ip_id) + misc.sh("openstack -q ip floating delete " + ip_id) def create_cluster(self): user_data = self.get_user_data() @@ -787,8 +787,8 @@ openstack security group rule create --proto udp --dst-port 16000:65535 teutholo self.ssh("sudo /etc/init.d/teuthology stop || true") instance_id = self.get_instance_id(self.args.name) self.delete_floating_ip(instance_id) - misc.sh("openstack server delete packages-repository || true") - misc.sh("openstack server delete --wait " + self.args.name) + misc.sh("openstack -q server delete packages-repository || true") + misc.sh("openstack -q server delete --wait " + self.args.name) def main(ctx, argv): return TeuthologyOpenStack(ctx, teuth_config, argv).main() diff --git a/teuthology/openstack/test/openstack-integration.py b/teuthology/openstack/test/openstack-integration.py index 58bd919d7f..e679967b07 100644 --- a/teuthology/openstack/test/openstack-integration.py +++ b/teuthology/openstack/test/openstack-integration.py @@ -58,10 +58,10 @@ class Integration(object): # move that to def tearDown for debug and when it works move it # back in tearDownClass so it is not called on every test ownedby = "ownedby='" + teuth_config.openstack['ip'] - all_instances = teuthology.misc.sh("openstack server list -f json --long") + all_instances = teuthology.misc.sh("openstack -q server list -f json --long") for instance in json.loads(all_instances): if ownedby in instance['Properties']: - teuthology.misc.sh("openstack server delete --wait " + instance['ID']) + teuthology.misc.sh("openstack -q server delete --wait " + instance['ID']) def setup_worker(self): self.logs = self.d + "/log" @@ -192,7 +192,7 @@ class TestSchedule(Integration): account if the instance has less than 4GB RAM. """ try: - teuthology.misc.sh("openstack volume list") + teuthology.misc.sh("openstack -q volume list") job = 'teuthology/openstack/test/resources_hint.yaml' has_cinder = True except subprocess.CalledProcessError: diff --git a/teuthology/openstack/test/test_openstack.py b/teuthology/openstack/test/test_openstack.py index 107103d0ec..7b9ba750ae 100644 --- a/teuthology/openstack/test/test_openstack.py +++ b/teuthology/openstack/test/test_openstack.py @@ -286,7 +286,7 @@ class TestTeuthologyOpenStack(object): ip = TeuthologyOpenStack.create_floating_ip() if ip: ip_id = TeuthologyOpenStack.get_floating_ip_id(ip) - misc.sh("openstack ip floating delete " + ip_id) + misc.sh("openstack -q ip floating delete " + ip_id) self.can_create_floating_ips = True else: self.can_create_floating_ips = False @@ -378,4 +378,4 @@ openstack keypair delete {key_name} || true ip = TeuthologyOpenStack.get_unassociated_floating_ip() assert expected == ip ip_id = TeuthologyOpenStack.get_floating_ip_id(ip) - misc.sh("openstack ip floating delete " + ip_id) + misc.sh("openstack -q ip floating delete " + ip_id) diff --git a/teuthology/provision/openstack.py b/teuthology/provision/openstack.py index 56d9b90482..2080fde6a3 100644 --- a/teuthology/provision/openstack.py +++ b/teuthology/provision/openstack.py @@ -75,7 +75,7 @@ class ProvisionOpenStack(OpenStack): with safe_while(sleep=2, tries=100, action="volume " + volume_name) as proceed: while proceed(): - r = misc.sh("openstack volume show -f json " + + r = misc.sh("openstack -q volume show -f json " + volume_name) status = self.get_value(json.loads(r), 'status') if status == 'available':