File: test_probe.py

package info (click to toggle)
pyroute2 0.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,700 kB
  • sloc: python: 50,245; makefile: 280; javascript: 183; ansic: 81; sh: 44; awk: 17
file content (57 lines) | stat: -rw-r--r-- 1,725 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.probes.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.probes.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.probes.create(kind='ping', dst=target).commit()
    assert e.value.code == errno.ETIMEDOUT