Merge "Remove logging import unused"
diff --git a/neutron/tests/tempest/scenario/base.py b/neutron/tests/tempest/scenario/base.py
index 351e587..6cf73c9 100644
--- a/neutron/tests/tempest/scenario/base.py
+++ b/neutron/tests/tempest/scenario/base.py
@@ -18,6 +18,7 @@
from tempest.common import waiters
from tempest.lib.common import ssh
from tempest.lib.common.utils import data_utils
+from tempest.lib import exceptions as lib_exc
from neutron.tests.tempest.api import base as base_api
from neutron.tests.tempest import config
@@ -149,11 +150,6 @@
return fip
@classmethod
- def check_connectivity(cls, host, ssh_user, ssh_key=None):
- ssh_client = ssh.Client(host, ssh_user, pkey=ssh_key)
- ssh_client.test_connection_auth()
-
- @classmethod
def setup_network_and_server(cls, router=None, **kwargs):
"""Create network resources and a server.
@@ -189,3 +185,30 @@
device_id=cls.server[
'server']['id'])['ports'][0]
cls.fip = cls.create_and_associate_floatingip(port['id'])
+
+ def check_connectivity(self, host, ssh_user, ssh_key, servers=None):
+ ssh_client = ssh.Client(host, ssh_user, pkey=ssh_key)
+ try:
+ ssh_client.test_connection_auth()
+ except lib_exc.SSHTimeout as ssh_e:
+ LOG.debug(ssh_e)
+ self._log_console_output(servers)
+ raise
+
+ def _log_console_output(self, servers=None):
+ if not CONF.compute_feature_enabled.console_output:
+ LOG.debug('Console output not supported, cannot log')
+ return
+ if not servers:
+ servers = self.manager.servers_client.list_servers()
+ servers = servers['servers']
+ for server in servers:
+ try:
+ console_output = (
+ self.manager.servers_client.get_console_output(
+ server['id'])['output'])
+ LOG.debug('Console output for %s\nbody=\n%s',
+ server['id'], console_output)
+ except lib_exc.NotFound:
+ LOG.debug("Server %s disappeared(deleted) while looking "
+ "for the console log", server['id'])
diff --git a/neutron/tests/tempest/scenario/test_qos.py b/neutron/tests/tempest/scenario/test_qos.py
index b558438..8b8e90a 100644
--- a/neutron/tests/tempest/scenario/test_qos.py
+++ b/neutron/tests/tempest/scenario/test_qos.py
@@ -38,7 +38,6 @@
client_socket = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
client_socket.connect((host_ip, port))
- client_socket.setblocking(0)
return client_socket
except socket.error as serr:
if serr.errno == errno.ECONNREFUSED:
@@ -97,10 +96,6 @@
file=QoSTest.FILE_PATH)
def _check_bw(self, ssh_client, host, port):
- total_bytes_read = 0
- cycle_start_time = time.time()
- cycle_data_read = 0
-
cmd = "killall -q nc"
try:
ssh_client.exec_command(cmd)
@@ -109,36 +104,26 @@
cmd = ("(nc -ll -p %(port)d < %(file_path)s > /dev/null &)" % {
'port': port, 'file_path': QoSTest.FILE_PATH})
ssh_client.exec_command(cmd)
+
+ start_time = time.time()
client_socket = _connect_socket(host, port)
+ total_bytes_read = 0
while total_bytes_read < QoSTest.FILE_SIZE:
- try:
- data = client_socket.recv(QoSTest.BUFFER_SIZE)
- except socket.error as e:
- if e.args[0] in [errno.EAGAIN, errno.EWOULDBLOCK]:
- continue
- else:
- raise
+ data = client_socket.recv(QoSTest.BUFFER_SIZE)
total_bytes_read += len(data)
- cycle_data_read += len(data)
- time_elapsed = time.time() - cycle_start_time
- should_check = (time_elapsed >= 5 or
- total_bytes_read == QoSTest.FILE_SIZE)
- if should_check:
- LOG.debug("time_elapsed = %(time_elapsed)d,"
- "total_bytes_read = %(bytes_read)d,"
- "cycle_data_read = %(cycle_data)d",
- {"time_elapsed": time_elapsed,
- "bytes_read": total_bytes_read,
- "cycle_data": cycle_data_read})
- if cycle_data_read / time_elapsed > QoSTest.LIMIT_BYTES_SEC:
- # Limit reached
- return False
- else:
- cycle_start_time = time.time()
- cycle_data_read = 0
- return True
+ time_elapsed = time.time() - start_time
+ bytes_per_second = total_bytes_read / time_elapsed
+
+ LOG.debug("time_elapsed = %(time_elapsed)d, "
+ "total_bytes_read = %(total_bytes_read)d, "
+ "bytes_per_second = %(bytes_per_second)d",
+ {'time_elapsed': time_elapsed,
+ 'total_bytes_read': total_bytes_read,
+ 'bytes_per_second': bytes_per_second})
+
+ return bytes_per_second <= QoSTest.LIMIT_BYTES_SEC
@test.idempotent_id('1f7ed39b-428f-410a-bd2b-db9f465680df')
def test_qos(self):