Skip to content

Commit

Permalink
Merge pull request #229 from AurelienLourot/instance-ping
Browse files Browse the repository at this point in the history
Print stderr when failing to ping new instance
  • Loading branch information
Liam Young committed Apr 14, 2020
2 parents f383064 + 83246a9 commit df52f37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
15 changes: 9 additions & 6 deletions unit_tests/utilities/test_zaza_utilities_openstack.py
Expand Up @@ -16,6 +16,7 @@
import datetime
import io
import mock
import subprocess
import tenacity

import unit_tests.utils as ut_utils
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion zaza/openstack/configure/guest.py
Expand Up @@ -16,6 +16,7 @@

"""Encapsulate nova testing."""

import subprocess
import logging
import time

Expand Down Expand Up @@ -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.')
Expand Down
3 changes: 2 additions & 1 deletion zaza/openstack/utilities/openstack.py
Expand Up @@ -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):
Expand Down

0 comments on commit df52f37

Please sign in to comment.