File: test_nlmsg.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 (50 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download | duplicates (2)
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
from pr2test.marks import require_root

pytestmark = [require_root()]


def test_nlmsg_operators(context):
    ifname = context.new_ifname
    ipaddr1 = context.new_ipaddr
    ipaddr2 = context.new_ipaddr
    interface = (
        context.ndb.interfaces.create(ifname=ifname, kind='dummy', state='up')
        .add_ip(f'{ipaddr1}/24')
        .add_ip(f'{ipaddr2}/24')
        .commit()
    )

    r = tuple(context.ipr.addr('dump', index=interface['index']))
    complement = r[0] - r[1]
    intersection = r[0] & r[1]

    assert complement.get_attr('IFA_ADDRESS') == ipaddr1
    assert complement.get_attr('IFA_LABEL') is None
    assert 'prefixlen' not in complement
    assert 'index' not in complement

    assert intersection.get_attr('IFA_ADDRESS') is None
    assert intersection.get_attr('IFA_LABEL') == ifname
    assert intersection['prefixlen'] == 24
    assert intersection['index'] == context.ndb.interfaces[ifname]['index']


def test_nlmsg_compare_equal(context):
    lvalue = tuple(context.ipr.get_links())[0]
    rvalue = tuple(context.ipr.get_links())[0]
    assert lvalue is not rvalue
    assert lvalue == rvalue


def test_nlmsg_compare_not_equal(context):
    lvalue = tuple(context.ipr.get_links())[0]
    rvalue = tuple(context.ipr.get_links())[1]
    assert lvalue is not rvalue
    assert lvalue != rvalue


def test_nlmsg_compare_int(context):
    lvalue = tuple(context.ipr.get_links())[0]
    rvalue = 42
    assert lvalue is not rvalue
    assert lvalue != rvalue