diff --git a/tox.ini b/tox.ini index 9541926..3852a6a 100644 --- a/tox.ini +++ b/tox.ini @@ -26,7 +26,14 @@ commands = commands = {posargs} [flake8] +# H106: Don't put vim configuration in source files +# H203: Use assertIs(Not)None to check for None +# H204: Use assert(Not)Equal to check for equality +# H205: Use assert(Greater|Less)(Equal) for comparison +# H904: Delay string interpolations at logging calls enable-extensions = H106,H203,H204,H205,H904 +# H405: multi line docstring summary not separated with an empty line +ignore = H405 show-source = true exclude = ./.*,build,dist,doc,*egg*,releasenotes import-order-style = pep8 diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/test_security_groups.py b/whitebox_neutron_tempest_plugin/tests/scenario/test_security_groups.py index a192f33..7044bf8 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_security_groups.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_security_groups.py @@ -87,6 +87,25 @@ class NetworkDefaultSecGroupTest(base.BaseTempestTestCase): :param should_succeed(boolean): Should the connection be successful :param server_id(str): ID of server where nc listens """ + def _run_commands(cmd1, cmd2, cmd3, cmd4, cmd5): + ssh_server.exec_command(cmd1) + # cmd2 needs to be executed with execute_script method on RHEL8 + # instances because it includes a command that runs in background + # An exception will be launched for RHEL7 and cirros instances and + # exec_command method will be used for them + try: + ssh_server.execute_script(cmd2) + except paramiko.SSHException: + ssh_server.exec_command(cmd2) + ssh_client.exec_command(cmd3) + output = ssh_server.exec_command(cmd5) + if should_succeed: + result = expected_output in output + else: + result = expected_output not in output + ssh_server.exec_command(cmd4) + return result + # Creating a script on the server to write sg_check # to /tmp/1 file expected_output = "sg_check_" + server_id @@ -110,29 +129,19 @@ class NetworkDefaultSecGroupTest(base.BaseTempestTestCase): cmd4 = 'sudo kill -9 $($(PATH=$PATH:/usr/sbin which pidof) nc) || true' cmd5 = "cat /tmp/{server_ip}".format(server_ip=server_ip) - ssh_server.exec_command(cmd1) - # cmd2 needs to be executed with execute_script method on RHEL8 - # instances because it includes a command that runs in background - # An exception will be launched for RHEL7 and cirros instances and - # exec_command method will be used for them try: - ssh_server.execute_script(cmd2) - except paramiko.SSHException: - ssh_server.exec_command(cmd2) - ssh_client.exec_command(cmd3) - output = ssh_server.exec_command(cmd5) - if should_succeed: - result = expected_output in output - else: - result = expected_output not in output - ssh_server.exec_command(cmd4) + result = _run_commands(cmd1, cmd2, cmd3, cmd4, cmd5) + except base.SSH_EXC_TUPLE as ssh_e: + LOG.debug(ssh_e) + self._log_console_output() + self._log_local_network_status() + raise return result @decorators.idempotent_id('921f91f8-7734-4c42-8934-a1438d45747b') def test_securitygroup_udp(self): - """Test connectivity between VMs when they have security group set. - - In this test Security groups are configured to allow traffic using UDP. + """Test connectivity between VMs when they have security group with + UDP port configured """ PORT_UDP = 60000 secgrp_name = 'udp-secgrp' @@ -207,9 +216,8 @@ class NetworkDefaultSecGroupTest(base.BaseTempestTestCase): @decorators.idempotent_id('db6ab68e-0b9b-46e8-9b15-c9612da57a08') def test_securitygroup_udp_dns(self): - """Test connectivity between VMs on two different tenant networks. - - This test is done through the DNS port (UDP port 53) + """Test connectivity between VMs on two different tenant networks + through the DNS port (UDP port 53) """ PORT_UDP = 53 secgrp_name = 'udp-dns-secgrp'