File: test_rules.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,490 bytes parent folder | download | duplicates (3)
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
from socket import AF_INET6

import pytest
from pr2test.context_manager import make_test_matrix
from pr2test.marks import require_root
from pr2test.tools import rule_exists

pytestmark = [require_root()]

test_matrix = make_test_matrix(
    targets=['local', 'netns'],
    tables=[100, 10000],
    dbs=['sqlite3/:memory:', 'postgres/pr2test'],
)


@pytest.mark.parametrize('context', test_matrix, indirect=True)
def test_explicit_ipv6_src(context):
    ipnet = context.new_ip6net
    table = context.table

    spec = {
        'family': AF_INET6,
        'src': ipnet.network,
        'src_len': ipnet.netmask,
        'table': table,
        'priority': 50,
    }
    context.register_rule(spec)

    context.ndb.rules.create(**spec).commit()
    assert rule_exists(context.netns, **spec)

    context.ndb.rules[spec].remove().commit()
    assert not rule_exists(context.netns, **spec)


@pytest.mark.parametrize('context', test_matrix, indirect=True)
def test_implicit_ipv6_src(context):
    ipnet = context.new_ip6net
    table = context.table

    spec = {
        'src': ipnet.network,
        'src_len': ipnet.netmask,
        'table': table,
        'priority': 50,
    }
    search_spec = spec.copy()
    search_spec['family'] = AF_INET6
    context.register_rule(search_spec)

    context.ndb.rules.create(**spec).commit()
    assert rule_exists(context.netns, **search_spec)

    context.ndb.rules[spec].remove().commit()
    assert not rule_exists(context.netns, **search_spec)