Fix intermittent port_forwarding test failures
This test was failing from time to time on checking UDP port
forwarding.
The reason for that was that sometimes (for unknown for me reason)
nc server spawned on guest vm wasn't run properly. Due to that there was
no response from this nc server and test was failing.
This patch changes that to use wait_until_true() helper and wait
60 seconds to received msg. Every time it tries to receive message,
first it tries also to spawn nc server on guest vm.
This patch also reverts commit
526f53722fc51eb1f9bdac957495518cbeae5e10.
as port_forwarding test don't need to be marked as unstable anymore.
Closes-Bug: #1850800
Change-Id: I95d5ba02b2851a07e6e1a8a2bedfdce7d20f32fc
diff --git a/neutron_tempest_plugin/scenario/test_port_forwardings.py b/neutron_tempest_plugin/scenario/test_port_forwardings.py
index 7283887..2d77b65 100644
--- a/neutron_tempest_plugin/scenario/test_port_forwardings.py
+++ b/neutron_tempest_plugin/scenario/test_port_forwardings.py
@@ -14,12 +14,12 @@
# under the License.
from neutron_lib import constants
-from neutron_lib.utils import test
from oslo_log import log
from tempest.lib.common.utils import data_utils
from tempest.lib import decorators
from neutron_tempest_plugin.common import ssh
+from neutron_tempest_plugin.common import utils
from neutron_tempest_plugin import config
from neutron_tempest_plugin.scenario import base
@@ -81,27 +81,32 @@
return servers
def _test_udp_port_forwarding(self, servers):
+
+ def _message_received(server, ssh_client, expected_msg):
+ self.nc_listen(server,
+ ssh_client,
+ server['port_forwarding_udp']['internal_port'],
+ constants.PROTO_NAME_UDP,
+ expected_msg)
+ received_msg = self.nc_client(
+ self.fip['floating_ip_address'],
+ server['port_forwarding_udp']['external_port'],
+ constants.PROTO_NAME_UDP)
+ return expected_msg in received_msg
+
for server in servers:
- msg = "%s-UDP-test" % server['name']
+ expected_msg = "%s-UDP-test" % server['name']
ssh_client = ssh.Client(
self.fip['floating_ip_address'],
CONF.validation.image_ssh_user,
pkey=self.keypair['private_key'],
port=server['port_forwarding_tcp']['external_port'])
- self.nc_listen(server,
- ssh_client,
- server['port_forwarding_udp']['internal_port'],
- constants.PROTO_NAME_UDP,
- msg)
- for server in servers:
- expected_msg = "%s-UDP-test" % server['name']
- self.assertIn(
- expected_msg, self.nc_client(
- self.fip['floating_ip_address'],
- server['port_forwarding_udp']['external_port'],
- constants.PROTO_NAME_UDP))
+ utils.wait_until_true(
+ lambda: _message_received(server, ssh_client, expected_msg),
+ exception=RuntimeError(
+ "Timed out waiting for message from server {!r} ".format(
+ server['id'])))
- @test.unstable_test("bug 1850800")
@decorators.idempotent_id('ab40fc48-ca8d-41a0-b2a3-f6679c847bfe')
def test_port_forwarding_to_2_servers(self):
udp_sg_rule = {'protocol': constants.PROTO_NAME_UDP,