Merge "Fix how nc is called in qos test"
This commit is contained in:
commit
22d7cc950b
|
@ -117,6 +117,14 @@ def kill_nc_process(ssh_client):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def process_is_running(ssh_client, process_name):
|
||||||
|
try:
|
||||||
|
ssh_client.exec_command("pidof %s" % process_name)
|
||||||
|
return True
|
||||||
|
except exceptions.SSHExecCommandFailed:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def spawn_http_server(ssh_client, port, message):
|
def spawn_http_server(ssh_client, port, message):
|
||||||
cmd = ("(echo -e 'HTTP/1.1 200 OK\r\n'; echo '%(msg)s') "
|
cmd = ("(echo -e 'HTTP/1.1 200 OK\r\n'; echo '%(msg)s') "
|
||||||
"| sudo nc -lp %(port)d &" % {'msg': message, 'port': port})
|
"| sudo nc -lp %(port)d &" % {'msg': message, 'port': port})
|
||||||
|
|
|
@ -31,6 +31,7 @@ from neutron_tempest_plugin.api import base as base_api
|
||||||
from neutron_tempest_plugin.common import ip as ip_utils
|
from neutron_tempest_plugin.common import ip as ip_utils
|
||||||
from neutron_tempest_plugin.common import shell
|
from neutron_tempest_plugin.common import shell
|
||||||
from neutron_tempest_plugin.common import ssh
|
from neutron_tempest_plugin.common import ssh
|
||||||
|
from neutron_tempest_plugin.common import utils
|
||||||
from neutron_tempest_plugin import config
|
from neutron_tempest_plugin import config
|
||||||
from neutron_tempest_plugin import exceptions
|
from neutron_tempest_plugin import exceptions
|
||||||
from neutron_tempest_plugin.scenario import constants
|
from neutron_tempest_plugin.scenario import constants
|
||||||
|
@ -53,16 +54,19 @@ def get_ncat_version(ssh_client=None):
|
||||||
return distutils.version.StrictVersion(m.group(1) if m else '7.60')
|
return distutils.version.StrictVersion(m.group(1) if m else '7.60')
|
||||||
|
|
||||||
|
|
||||||
def get_ncat_server_cmd(port, protocol, msg):
|
def get_ncat_server_cmd(port, protocol, msg=None):
|
||||||
udp = ''
|
udp = ''
|
||||||
if protocol.lower() == neutron_lib_constants.PROTO_NAME_UDP:
|
if protocol.lower() == neutron_lib_constants.PROTO_NAME_UDP:
|
||||||
udp = '-u'
|
udp = '-u'
|
||||||
cmd = "nc %(udp)s -p %(port)s -lk " % {
|
cmd = "nc %(udp)s -p %(port)s -lk " % {
|
||||||
'udp': udp, 'port': port}
|
'udp': udp, 'port': port}
|
||||||
if CONF.neutron_plugin_options.default_image_is_advanced:
|
if msg:
|
||||||
cmd += "-c 'echo %s' &" % msg
|
if CONF.neutron_plugin_options.default_image_is_advanced:
|
||||||
|
cmd += "-c 'echo %s' &" % msg
|
||||||
|
else:
|
||||||
|
cmd += "-e echo %s &" % msg
|
||||||
else:
|
else:
|
||||||
cmd += "-e echo %s &" % msg
|
cmd += "< /dev/zero &"
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
|
@ -468,7 +472,20 @@ class BaseTempestTestCase(base_api.BaseNetworkTest):
|
||||||
self._log_console_output(servers)
|
self._log_console_output(servers)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def nc_listen(self, server, ssh_client, port, protocol, echo_msg):
|
def ensure_nc_listen(self, ssh_client, port, protocol, echo_msg=None,
|
||||||
|
servers=None):
|
||||||
|
"""Ensure that nc server listening on the given TCP/UDP port is up.
|
||||||
|
|
||||||
|
Listener is created always on remote host.
|
||||||
|
"""
|
||||||
|
def spawn_and_check_process():
|
||||||
|
self.nc_listen(ssh_client, port, protocol, echo_msg, servers)
|
||||||
|
return utils.process_is_running(ssh_client, "nc")
|
||||||
|
|
||||||
|
utils.wait_until_true(spawn_and_check_process)
|
||||||
|
|
||||||
|
def nc_listen(self, ssh_client, port, protocol, echo_msg=None,
|
||||||
|
servers=None):
|
||||||
"""Create nc server listening on the given TCP/UDP port.
|
"""Create nc server listening on the given TCP/UDP port.
|
||||||
|
|
||||||
Listener is created always on remote host.
|
Listener is created always on remote host.
|
||||||
|
@ -479,7 +496,7 @@ class BaseTempestTestCase(base_api.BaseNetworkTest):
|
||||||
become_root=True)
|
become_root=True)
|
||||||
except lib_exc.SSHTimeout as ssh_e:
|
except lib_exc.SSHTimeout as ssh_e:
|
||||||
LOG.debug(ssh_e)
|
LOG.debug(ssh_e)
|
||||||
self._log_console_output([server])
|
self._log_console_output(servers)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def nc_client(self, ip_address, port, protocol):
|
def nc_client(self, ip_address, port, protocol):
|
||||||
|
|
|
@ -83,11 +83,11 @@ class PortForwardingTestJSON(base.BaseTempestTestCase):
|
||||||
def _test_udp_port_forwarding(self, servers):
|
def _test_udp_port_forwarding(self, servers):
|
||||||
|
|
||||||
def _message_received(server, ssh_client, expected_msg):
|
def _message_received(server, ssh_client, expected_msg):
|
||||||
self.nc_listen(server,
|
self.nc_listen(ssh_client,
|
||||||
ssh_client,
|
|
||||||
server['port_forwarding_udp']['internal_port'],
|
server['port_forwarding_udp']['internal_port'],
|
||||||
constants.PROTO_NAME_UDP,
|
constants.PROTO_NAME_UDP,
|
||||||
expected_msg)
|
expected_msg,
|
||||||
|
[server])
|
||||||
received_msg = self.nc_client(
|
received_msg = self.nc_client(
|
||||||
self.fip['floating_ip_address'],
|
self.fip['floating_ip_address'],
|
||||||
server['port_forwarding_udp']['external_port'],
|
server['port_forwarding_udp']['external_port'],
|
||||||
|
|
|
@ -81,8 +81,7 @@ class QoSTestMixin(object):
|
||||||
|
|
||||||
def _check_bw(self, ssh_client, host, port, expected_bw=LIMIT_BYTES_SEC):
|
def _check_bw(self, ssh_client, host, port, expected_bw=LIMIT_BYTES_SEC):
|
||||||
utils.kill_nc_process(ssh_client)
|
utils.kill_nc_process(ssh_client)
|
||||||
cmd = ("(nc -ll -p %d < /dev/zero > /dev/null &)" % port)
|
self.ensure_nc_listen(ssh_client, port, "tcp")
|
||||||
ssh_client.exec_command(cmd, timeout=5)
|
|
||||||
|
|
||||||
# Open TCP socket to remote VM and download big file
|
# Open TCP socket to remote VM and download big file
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
Loading…
Reference in New Issue