File: test_iwutil.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 (54 lines) | stat: -rw-r--r-- 1,203 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
import collections
import errno

import pytest
from pr2test.marks import require_root

from pyroute2 import IW, IPRoute
from pyroute2.netlink.exceptions import NetlinkError


@pytest.fixture
def ctx():
    iw = None
    ifname = None
    wiphy = None
    index = None
    try:
        iw = IW()
    except NetlinkError as e:
        if e.code == errno.ENOENT:
            pytest.skip('nl80211 not supported')
        raise
    ifaces = iw.get_interfaces_dump()
    if not ifaces:
        raise pytest.skip('no wireless interfaces found')
    for i in ifaces:
        ifname = i.get_attr('NL80211_ATTR_IFNAME')
        index = i.get_attr('NL80211_ATTR_IFINDEX')
        wiphy = i.get_attr('NL80211_ATTR_WIPHY')
        if index:
            break
    else:
        pytest.skip('can not detect the interface to use')

    yield collections.namedtuple(
        'WirelessContext', ['iw', 'ifname', 'index', 'wiphy']
    )(iw, ifname, index, wiphy)

    iw.close()


def test_list_wiphy(ctx):
    ctx.iw.list_wiphy()


def test_list_dev(ctx):
    ctx.iw.list_dev()


@require_root
def test_scan(ctx):
    with IPRoute() as ipr:
        ipr.link('set', index=ctx.index, state='up')
    ctx.iw.scan(ctx.index)