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 fd4141f201
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:

_<PID>_  cirros   nc udp -p 12349

And that will remain running even after the python session closes.

Closes-Bug: #1868100
Change-Id: I8192391d6f2e86f9e486805374f710444e770ea4
This commit is contained in:
Flavio Fernandes 2020-07-01 14:57:13 -04:00
parent 722055abdc
commit b056ac25c9

View File

@ -62,11 +62,10 @@ def get_ncat_server_cmd(port, protocol, msg=None):
'udp': udp, 'port': port} 'udp': udp, 'port': port}
if msg: if msg:
if CONF.neutron_plugin_options.default_image_is_advanced: if CONF.neutron_plugin_options.default_image_is_advanced:
cmd += "-c 'echo %s' &" % msg cmd += "-c 'echo %s' " % msg
else: else:
cmd += "-e echo %s &" % msg cmd += "-e echo %s " % msg
else: cmd += "< /dev/zero &{0}sleep 0.1{0}".format('\n')
cmd += "< /dev/zero &"
return cmd return cmd
@ -497,7 +496,7 @@ class BaseTempestTestCase(base_api.BaseNetworkTest):
try: try:
return ssh_client.execute_script( return ssh_client.execute_script(
get_ncat_server_cmd(port, protocol, echo_msg), get_ncat_server_cmd(port, protocol, echo_msg),
become_root=True) become_root=True, combine_stderr=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(servers) self._log_console_output(servers)