Ejemplo n.º 1
0
def test_ip_route():
    context = context_wrap(IP_ROUTE_SHOW_TABLE_ALL_TEST)
    d = ip.RouteDevices(context)
    assert len(d.data) == 6
    assert d["30.142.34.0/26"][0].dev == "bond0.300"
    assert d["30.142.64.0/26"][0].dev == "bond0.400"
    assert d["169.254.0.0/16"][0].dev == "bond0"
    assert d.ifaces(None) is None
    assert d.ifaces("30.142.34.1")[0] == "bond0.300"
    assert d.ifaces("30.142.64.1")[0] == "bond0.400"
    assert d.ifaces("169.254.0.1")[0] == "bond0"
    assert d.ifaces("30.0.0.1")[0] == "notExist"
    assert d.ifaces("192.168.0.1")[0] == "bond0.400"
    assert len(d.data["default"]) == 1
    d_devices = d.by_device['bond0.300']
    for idx in d_devices:
        if idx and getattr(idx, 'prefix') and getattr(idx, 'prefix') == '30.142.34.0/26':
            assert getattr(idx, 'src') == '30.142.34.5'
    d_prefix = d.by_prefix['default']
    assert getattr(d_prefix[0], 'via') == '30.142.64.1'
    d_prefix = d.by_prefix['30.142.34.0/26']
    assert getattr(d_prefix[0], 'scope') == 'link'
    d_table = d.by_table['None']
    for idx in d_table:
        if idx and getattr(idx, 'prefix') and getattr(idx, 'prefix') == "30.0.0.0/8":
            assert getattr(idx, 'proto') == 'kernel'
Ejemplo n.º 2
0
def test_bad_ip_routes():
    context = context_wrap(IP_ROUTE_SHOW_TABLE_ALL_TEST_BAD)
    context.path = "sos_commands/networking/ip_route_show_all"
    tbl = ip.RouteDevices(context)

    # As long as the line has a CIDR-net or address, the Route object is
    # instantiated but most of its fields are None
    assert len(tbl.data) == 3

    assert 'ff00::/16' in tbl
    r0a = tbl['ff00::/16'][0]
    for attr in ['via', 'dev', 'type', 'table']:
        assert hasattr(r0a, attr)
        assert getattr(r0a, attr) is None
    assert hasattr(r0a, 'prefix')
    assert r0a.prefix == 'ff00::/16'
    assert hasattr(r0a, 'netmask')
    assert r0a.netmask == 16

    assert 'ff01::/16' in tbl
    r1a = tbl['ff01::/16'][0]
    for attr in ['via', 'dev', 'type', 'table']:
        assert hasattr(r1a, attr)
        assert getattr(r1a, attr) is None
    assert hasattr(r1a, 'prefix')
    assert r1a.prefix == 'ff01::/16'
    assert hasattr(r1a, 'netmask')
    assert r1a.netmask == 16

    assert 'ff02::/16' in tbl
    r2a = tbl['ff02::/16'][0]
    for attr in ['via', 'type', 'table']:
        assert hasattr(r2a, attr)
        assert getattr(r2a, attr) is None
    assert hasattr(r2a, 'prefix')
    assert r2a.prefix == 'ff02::/16'
    assert hasattr(r2a, 'netmask')
    assert r2a.netmask == 16
    assert hasattr(r2a, 'dev')
    assert r2a.dev == 'enp0s25'
    assert not hasattr(r2a, 'metric')

    # Also a good chance to test the failure to find an interface for a
    # routed address, since we don't have a default route defined.
    assert tbl.ifaces('192.168.0.1') is None
Ejemplo n.º 3
0
def test_ip_route():
    context = context_wrap(IP_ROUTE_SHOW_TABLE_ALL_TEST)
    d = ip.RouteDevices(context)

    assert len(d.data) == 5
    assert d["30.142.34.0/26"][0].dev == "bond0.300"
    assert d["30.142.64.0/26"][0].dev == "bond0.400"
    assert d["169.254.0.0/16"][0].dev == "bond0"
    assert d.ifaces(None) is None
    assert d.ifaces("30.142.34.1")[0] == "bond0.300"
    assert d.ifaces("30.142.64.1")[0] == "bond0.400"
    assert d.ifaces("169.254.0.1")[0] == "bond0"
    assert d.ifaces("30.0.0.1")[0] == "notExist"
    assert d.ifaces("192.168.0.1")[0] == "bond0.400"
    assert len(d.data["default"]) == 1
    assert getattr(d.by_device['bond0.300'][0], 'src') == '30.142.34.5'
    assert getattr(d.by_prefix['default'][0], 'via') == '30.142.64.1'
    assert getattr(d.by_prefix['30.142.34.0/26'][0], 'scope') == 'link'
    assert getattr(d.by_table['None'][1], 'proto') == 'kernel'
    assert getattr(d.by_type['None'][3], 'netmask') == 8
Ejemplo n.º 4
0
def test_ip_route_2():
    context = context_wrap(IP_ROUTE_SHOW_TABLE_ALL_TEST_2)
    context.path = "sos_commands/networking/ip_route_show_all"
    tbl = ip.RouteDevices(context)

    assert len(tbl.data) == 26

    # Ignored route types:
    assert 'broadcast' not in tbl
    assert 'local' not in tbl
    assert 'unreachable' not in tbl
    assert 'throw' not in tbl
    assert 'prohibit' not in tbl
    assert 'blackhole' not in tbl
    assert 'nat' not in tbl

    # Standard route types:
    assert 'default' in tbl

    # Assert existence of the standard route attributes for all route
    # objects, even though the attribute itself may be None
    for prefix in tbl.data.keys():
        for route in tbl[prefix]:
            for attr in ['via', 'dev', 'type', 'netmask', 'prefix', 'table']:
                assert hasattr(route, attr)

    # Route object checks
    # 10.0.0.0/8 via 10.64.54.1 dev tun0  proto static  metric 50
    assert '10.0.0.0/8' in tbl
    r1 = tbl['10.0.0.0/8']
    assert len(r1) == 1
    r1a = r1[0]
    assert hasattr(r1a, 'prefix')
    assert r1a.prefix == '10.0.0.0/8'
    assert hasattr(r1a, 'via')
    assert r1a.via == '10.64.54.1'
    assert hasattr(r1a, 'dev')
    assert r1a.dev == 'tun0'
    assert hasattr(r1a, 'proto')
    assert r1a.proto == 'static'
    assert hasattr(r1a, 'metric')
    assert r1a.metric == '50'

    # 10.64.54.0/23 dev tun0  proto kernel  scope link  src 10.64.54.44  metric 50
    assert '10.64.54.0/23' in tbl
    r2 = tbl['10.64.54.0/23']
    assert len(r2) == 1
    r2a = r2[0]
    assert hasattr(r2a, 'prefix')
    assert r2a.prefix == '10.64.54.0/23'
    assert hasattr(r2a, 'via')
    assert r2a.via is None
    assert hasattr(r2a, 'dev')
    assert r2a.dev == 'tun0'
    assert hasattr(r2a, 'proto')
    assert r2a.proto == 'kernel'
    assert hasattr(r2a, 'scope')
    assert r2a.scope == 'link'
    assert hasattr(r2a, 'src')
    assert r2a.src == '10.64.54.44'
    assert hasattr(r2a, 'metric')
    assert r2a.metric == '50'

    # 2001:708:40:2001:a822:baff:fec4:2428 via fe80::a96:d7ff:fe38:d757 dev enp0s25  metric 0
    #     cache  mtu 1492 hoplimit 255
    assert '2001:708:40:2001:a822:baff:fec4:2428' in tbl
    r3 = tbl['2001:708:40:2001:a822:baff:fec4:2428']
    assert len(r3) == 1
    r3a = r3[0]
    assert hasattr(r3a, 'prefix')
    assert r3a.prefix == '2001:708:40:2001:a822:baff:fec4:2428'
    assert hasattr(r3a, 'via')
    assert r3a.via == 'fe80::a96:d7ff:fe38:d757'
    assert hasattr(r3a, 'dev')
    assert r3a.dev == 'enp0s25'
    assert hasattr(r3a, 'metric')
    assert r3a.metric == '0'
    assert hasattr(r3a, 'cache')
    assert r3a.cache
    assert hasattr(r3a, 'mtu')
    assert r3a.mtu == '1492'
    assert hasattr(r3a, 'hoplimit')
    assert r3a.hoplimit == '255'

    # by_prefix checks
    prefixes = tbl.by_prefix
    for prefix, route in prefixes.items():
        assert route[0] in tbl.by_device[route[0].dev]

    # by_device checks
    devices = tbl.by_device
    assert 'tun0' in devices
    assert 'enp0s25' in devices
    assert 'virbr0' in devices
    assert len(devices) == 4
    assert len(devices['enp0s25']) == 17

    # The order of these data structures is non-deterministic
    # Should be in order of reading, so find them in order by name
    # assert devices['enp0s25'][0] == tbl['2001:44b8:1110:f800::/64'][0]
    # assert devices['enp0s25'][1] == tbl['fe80::/64'][0]
    # assert devices['enp0s25'][2] == tbl['2001:708:40:2001:a822:baff:fec4:2428'][0]
    # Default routes accumulate in the same order?
    # assert devices['enp0s25'][3] == tbl['default'][0]
    # assert devices['enp0s25'][4] == tbl['default'][1]
    # assert devices['enp0s25'][5] == tbl['2404:6800:4008:c02::bd'][0]
    # assert devices['enp0s25'][6] == tbl['2a00:1450:400e:800::2003'][0]
    # assert devices['enp0s25'][7] == tbl['66.187.239.220'][0]
    # assert devices['enp0s25'][8] == tbl['2404:6800:4006:803::2003'][0]
    # assert devices['enp0s25'][9] == tbl['192.168.23.0/24'][0]
    # assert devices['enp0s25'][10] == tbl['2404:6800:4006:802::200e'][0]
    # assert devices['enp0s25'][11] == tbl['2404:6800:4008:c00::bc'][0]
    # assert devices['enp0s25'][12] == tbl['2404:6800:4008:c06::bd'][0]
    # assert devices['enp0s25'][13] == tbl['2001:dbc::/64'][0]
    # assert devices['enp0s25'][14] == tbl['ff02::fb'][0]
    # assert devices['enp0s25'][15] == tbl['ff00::/8'][0]

    # by_type checks
    types = tbl.by_type
    assert sorted(types.keys()) == sorted(['None', 'multicast', 'local'])
    # As we have added `local` in the SAVED_TYPES number of local rules which was
    # treaded as None now treating as a local so this number is changed
    assert len(types['None']) == 18
    for entry in types['None']:
        assert entry in tbl[entry.prefix]

    # by_table checks
    tables = tbl.by_table
    assert sorted(tables.keys()) == sorted(['None', 'local'])
    assert len(tables['None']) == 18
    # Something tells me that out of
    assert len(tables['local']) == 9
    for local in tables['local']:
        if local.dev == 'enp0s25' and local.prefix == 'ff00::/8':
            assert local.via is None
            assert local.metric == '256'
            assert local.prefix == 'ff00::/8'
            assert local.dev == 'enp0s25'
            assert local.mtu == '1492'
            assert local.netmask == 8
            assert local.table == 'local'
            assert local.type is None
        if local.dev == 'lo' and local.prefix == '2001:44b8:1110:f800:56ee:75ff:fe1c:5901':
            assert local.via is None
            assert local.metric == '0'
            assert local.table == 'local'
            assert local.type == 'local'
            assert local.dev == 'lo'