diff --git a/unit_tests/utilities/test_zaza_utilities_openstack.py b/unit_tests/utilities/test_zaza_utilities_openstack.py index 915d66145..46efb0d1f 100644 --- a/unit_tests/utilities/test_zaza_utilities_openstack.py +++ b/unit_tests/utilities/test_zaza_utilities_openstack.py @@ -16,6 +16,7 @@ import datetime import io import mock +import subprocess import tenacity import unit_tests.utils as ut_utils @@ -664,17 +665,19 @@ def test_get_ports_from_device_id_no_match(self): []) def test_ping_response(self): - self.patch_object(openstack_utils.subprocess, 'check_call') + self.patch_object(openstack_utils.subprocess, 'run') openstack_utils.ping_response('10.0.0.10') - self.check_call.assert_called_once_with( - ['ping', '-c', '1', '-W', '1', '10.0.0.10'], stdout=-3) + self.run.assert_called_once_with( + ['ping', '-c', '1', '-W', '1', '10.0.0.10'], check=True, + stdout=mock.ANY, stderr=mock.ANY) def test_ping_response_fail(self): openstack_utils.ping_response.retry.wait = \ tenacity.wait_none() - self.patch_object(openstack_utils.subprocess, 'check_call') - self.check_call.side_effect = Exception() - with self.assertRaises(Exception): + self.patch_object(openstack_utils.subprocess, 'run') + self.run.side_effect = subprocess.CalledProcessError(returncode=42, + cmd='mycmd') + with self.assertRaises(subprocess.CalledProcessError): openstack_utils.ping_response('10.0.0.10') def test_ssh_test(self): diff --git a/zaza/openstack/configure/guest.py b/zaza/openstack/configure/guest.py index 920b539c9..bd70bcaec 100644 --- a/zaza/openstack/configure/guest.py +++ b/zaza/openstack/configure/guest.py @@ -16,6 +16,7 @@ """Encapsulate nova testing.""" +import subprocess import logging import time @@ -132,7 +133,13 @@ def launch_instance(instance_key, use_boot_volume=False, vm_name=None, external_network_name, port=port)['floating_ip_address'] logging.info('Assigned floating IP {} to {}'.format(ip, vm_name)) - openstack_utils.ping_response(ip) + try: + openstack_utils.ping_response(ip) + except subprocess.CalledProcessError as e: + logging.error('Pinging {} failed with {}'.format(ip, e.returncode)) + logging.error('stdout: {}'.format(e.stdout)) + logging.error('stderr: {}'.format(e.stderr)) + raise # Check ssh'ing to instance. logging.info('Testing ssh access.') diff --git a/zaza/openstack/utilities/openstack.py b/zaza/openstack/utilities/openstack.py index f4f1374b8..de324e47b 100644 --- a/zaza/openstack/utilities/openstack.py +++ b/zaza/openstack/utilities/openstack.py @@ -2258,7 +2258,8 @@ def ping_response(ip): :raises: subprocess.CalledProcessError """ cmd = ['ping', '-c', '1', '-W', '1', ip] - subprocess.check_call(cmd, stdout=subprocess.DEVNULL) + subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + check=True) def ssh_test(username, ip, vm_name, password=None, privkey=None):