Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils / network: improvements to ping_flood() #6063

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions avocado/utils/network/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,12 +821,15 @@
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}"
Expand All @@ -835,8 +838,10 @@
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(

Check warning on line 841 in avocado/utils/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/network/interfaces.py#L841

Added line #L841 was not covered by tests
"ping flood failed to remote machine, error output: %s",
ping_process.stderr.read(),
)
return False
return True
ping_process.stdout.close()
Expand Down
9 changes: 5 additions & 4 deletions selftests/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions selftests/functional/utils/network.py
Original file line number Diff line number Diff line change
@@ -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"))
Loading