From b056ac25c90b4cd8459291f1eb12081b7ace304d Mon Sep 17 00:00:00 2001 From: Flavio Fernandes Date: Wed, 1 Jul 2020 14:57:13 -0400 Subject: [PATCH] test_port_forwarding_to_2_servers: netcat listen stops too soon This change is a continuation of https://review.opendev.org/#/c/713208/ Even with the changes from commit fd4141f2015d25f1b009d7cf2ebdd2907cd8e81a our tests have intermittent failures where nc listen process terminates as soon as the shell that spawns it closes. By (1) breaking the cmd script to have an extra line, (2) adding a 0.1 sec delay and (3) setting stdin of process the proposed changes ensures that this termination no longer takes place. In order to reproduce this issue, follow these set of steps as a reference: From a separate shell session in the cirros vm, watch out for nc processes $ watch -n1 -d "ps -elf | grep nc" Then, start a python session to interact with that vm via ssh session: $ python3 from neutron_tempest_plugin.common import ssh cirros_vm_ip='10.0.0.10' c=ssh.Client(cirros_vm_ip, 'cirros', 'gocubsgo', port=22) c.execute_script('nc udp -p 12346 &') If you are lucky (or unlucky), you will see that there are no nc processes running, unless you use a variation to that command that looks like this: c.execute_script('nc udp -p 12349 &\nsleep 0') Than then in the watch session you will see something that look like: __ cirros nc udp -p 12349 And that will remain running even after the python session closes. Closes-Bug: #1868100 Change-Id: I8192391d6f2e86f9e486805374f710444e770ea4 --- neutron_tempest_plugin/scenario/base.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/neutron_tempest_plugin/scenario/base.py b/neutron_tempest_plugin/scenario/base.py index b4412093..9223893f 100644 --- a/neutron_tempest_plugin/scenario/base.py +++ b/neutron_tempest_plugin/scenario/base.py @@ -62,11 +62,10 @@ def get_ncat_server_cmd(port, protocol, msg=None): 'udp': udp, 'port': port} if msg: if CONF.neutron_plugin_options.default_image_is_advanced: - cmd += "-c 'echo %s' &" % msg + cmd += "-c 'echo %s' " % msg else: - cmd += "-e echo %s &" % msg - else: - cmd += "< /dev/zero &" + cmd += "-e echo %s " % msg + cmd += "< /dev/zero &{0}sleep 0.1{0}".format('\n') return cmd @@ -497,7 +496,7 @@ class BaseTempestTestCase(base_api.BaseNetworkTest): try: return ssh_client.execute_script( get_ncat_server_cmd(port, protocol, echo_msg), - become_root=True) + become_root=True, combine_stderr=True) except lib_exc.SSHTimeout as ssh_e: LOG.debug(ssh_e) self._log_console_output(servers)