Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print stderr when failing to ping new instance #229

Merged
merged 1 commit into from Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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