-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import errno | ||
|
||
import pytest | ||
from pr2test.context_manager import make_test_matrix, skip_if_not_supported | ||
from pr2test.marks import require_root | ||
|
||
from pyroute2 import NetlinkError | ||
|
||
pytestmark = [require_root()] | ||
test_matrix = make_test_matrix(targets=['local', 'netns']) | ||
|
||
|
||
@pytest.mark.parametrize('context', test_matrix, indirect=True) | ||
@skip_if_not_supported | ||
def test_ping_ok(context): | ||
index, ifname = context.default_interface | ||
ipaddr = context.new_ipaddr | ||
|
||
with context.ndb.interfaces[ifname] as i: | ||
i.add_ip(address=ipaddr, prefixlen=24) | ||
i.set(state='up') | ||
|
||
with context.ndb.interfaces['lo'] as i: | ||
i.set(state='up') | ||
|
||
context.ndb.probe.create(kind='ping', dst=ipaddr).commit() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'context', make_test_matrix(targets=['netns']), indirect=True | ||
) | ||
@skip_if_not_supported | ||
def test_ping_fail_ehostunreach(context): | ||
with context.ndb.interfaces['lo'] as i: | ||
i.set(state='down') | ||
with pytest.raises(NetlinkError) as e: | ||
context.ndb.probe.create(kind='ping', dst='127.0.0.1').commit() | ||
assert e.value.code == errno.EHOSTUNREACH | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'context', make_test_matrix(targets=['netns']), indirect=True | ||
) | ||
@skip_if_not_supported | ||
def test_ping_fail_etimedout(context): | ||
index, ifname = context.default_interface | ||
ipaddr = context.new_ipaddr | ||
target = context.new_ipaddr | ||
|
||
with context.ndb.interfaces[ifname] as i: | ||
i.add_ip(address=ipaddr, prefixlen=24) | ||
i.set(state='up') | ||
with context.ndb.interfaces['lo'] as i: | ||
i.set(state='up') | ||
with pytest.raises(NetlinkError) as e: | ||
context.ndb.probe.create(kind='ping', dst=target).commit() | ||
assert e.value.code == errno.ETIMEDOUT |