diff --git a/avocado/utils/network/interfaces.py b/avocado/utils/network/interfaces.py index d0263669bf..9fe26af770 100644 --- a/avocado/utils/network/interfaces.py +++ b/avocado/utils/network/interfaces.py @@ -821,12 +821,15 @@ def ping_flood(self, int_name, peer_ip, ping_count): returns False on ping flood failure. :rtype: boolean """ - cmd = f"ping -I {int_name} {peer_ip} -c {ping_count} -f " + cmd = f"ping -I {int_name} {peer_ip} -c {ping_count} -f" + if os.getuid() != 0: + cmd = f"{cmd} -i 0.002" + print(cmd) ping_process = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=subprocess.PIPE, universal_newlines=True, ) pattern = r"\.{10}" @@ -835,8 +838,10 @@ def ping_flood(self, int_name, peer_ip, ping_count): match = re.search(pattern, char) if match: ping_process.terminate() - msg = "ping flood failed to remote machine, Please check the logs" - LOG.debug(msg) + LOG.debug( + "ping flood failed to remote machine, error output: %s", + ping_process.stderr.read(), + ) return False return True ping_process.stdout.close() diff --git a/selftests/check.py b/selftests/check.py index d24009bd49..e345ec7f9b 100755 --- a/selftests/check.py +++ b/selftests/check.py @@ -29,7 +29,7 @@ "nrunner-requirement": 28, "unit": 678, "jobs": 11, - "functional-parallel": 313, + "functional-parallel": 315, "functional-serial": 7, "optional-plugins": 0, "optional-plugins-golang": 2, @@ -864,9 +864,10 @@ def main(args): # pylint: disable=W0621 f" it has {suite.size}." ) print( - "If you made some changes into selftests please update `TEST_SIZE`" - " variable in `check.py`. If you haven't done any changes to" - " selftests this behavior is an ERROR, and it needs to be fixed." + f"If you made some changes into selftests please update the " + f"value for the `{suite.name}` key in the `TEST_SIZE` " + f"dictionary in `check.py`. If you haven't done any changes to " + f"selftests this behavior is an ERROR, and it needs to be fixed." ) # tmp dirs clean up check diff --git a/selftests/functional/utils/network.py b/selftests/functional/utils/network.py new file mode 100644 index 0000000000..9b9ed1ffdc --- /dev/null +++ b/selftests/functional/utils/network.py @@ -0,0 +1,14 @@ +from avocado import Test +from avocado.utils.network.hosts import LocalHost +from avocado.utils.network.interfaces import NetworkInterface + + +class Interface(Test): + def setUp(self): + self.interface = NetworkInterface("lo", LocalHost("lo")) + + def test_ping_flood(self): + self.assertTrue(self.interface.ping_flood("lo", "127.0.0.1", "1")) + + def test_ping_flood_fail(self): + self.assertFalse(self.interface.ping_flood("lo", "172.16.1.1", "100"))