Merge pull request #229 from AurelienLourot/instance-ping
Print stderr when failing to ping new instance
This commit is contained in:
@@ -16,6 +16,7 @@ import copy
|
||||
import datetime
|
||||
import io
|
||||
import mock
|
||||
import subprocess
|
||||
import tenacity
|
||||
|
||||
import unit_tests.utils as ut_utils
|
||||
@@ -664,17 +665,19 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
|
||||
[])
|
||||
|
||||
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):
|
||||
|
||||
@@ -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.')
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user