示例#1
0
    def test_sourceroute_add_remove_and_read(self, nic0):
        Interface.from_existing_dev_name(nic0).add_ip(IPV4_ADDRESS, IPV4_MASK,
                                                      IpFamily.IPv4)

        with create_sourceroute(device=nic0,
                                ip=IPV4_ADDRESS,
                                mask=IPV4_MASK,
                                gateway=IPV4_GW):
            dsroute = DynamicSourceRoute(nic0, None, None, None)
            routes, rules = dsroute.current_srconfig()

            assert len(routes) == 2
            assert len(rules) == 2

            assert routes[0].to == '0.0.0.0/0'
            assert routes[0].device == nic0
            assert routes[1].to == IPV4_NET
            assert routes[1].device == nic0

            assert rules[0].to == IPV4_NET
            assert rules[0].table == IPV4_TABLE
            assert rules[0].iif == nic0
            assert rules[0].prio == sourceroute.RULE_PRIORITY
            assert rules[1].src == IPV4_NET
            assert rules[1].table == IPV4_TABLE
            assert rules[1].prio == sourceroute.RULE_PRIORITY
示例#2
0
    def test_routes_device_to(self, ip_addr, ip_netmask, nic0):
        addr_in_net = ipaddress.ip_address(ip_addr) + 1
        ip_version = addr_in_net.version

        Interface.from_existing_dev_name(nic0).add_ip(ip_addr,
                                                      ip_netmask,
                                                      family=ip_version)
        assert routes.getRouteDeviceTo(str(addr_in_net)) == nic0
示例#3
0
def cleanup_leftover_interfaces():
    for interface in getLinks():
        if TEST_NIC_REGEX.match(interface.name):
            logging.warning('Found leftover interface %s', interface)
            try:
                Interface.from_existing_dev_name(interface.name).remove()
            except Exception as e:
                logging.warning('Removal of "%s" failed: %s', interface, e)
示例#4
0
 def test_local_auto_with_static_address_without_ra_server(self, nic0):
     Interface.from_existing_dev_name(nic0).add_ip('2001::88',
                                                   IPV6_PREFIX_LENGTH,
                                                   IpFamily.IPv6)
     ip_addrs = addresses.getIpAddrs()[nic0]
     assert addresses.is_ipv6_local_auto(nic0)
     assert 2 == len(ip_addrs), ip_addrs
     assert addresses.is_ipv6(ip_addrs[0])
     assert not addresses.is_dynamic(ip_addrs[0])
示例#5
0
    def test_sourceroute_add_over_existing_route(self, nic0):
        Interface.from_existing_dev_name(nic0).add_ip(IPV4_ADDRESS, IPV4_MASK,
                                                      IpFamily.IPv4)

        with create_sourceroute(device=nic0,
                                ip=IPV4_ADDRESS,
                                mask=IPV4_MASK,
                                gateway=IPV4_GW):
            sourceroute.add(nic0, IPV4_ADDRESS, IPV4_MASK, IPV4_GW)
示例#6
0
def dynamic_ipv4_iface():
    with veth_pair() as (server, client):
        with wait_for_ipv4(server, IPv4_ADDRESS, IPv4_PREFIX_LEN):
            Interface.from_existing_dev_name(server).add_ip(
                IPv4_ADDRESS, IPv4_PREFIX_LEN, IpFamily.IPv4
            )
        with dnsmasq_run(
            server, DHCPv4_RANGE_FROM, DHCPv4_RANGE_TO, router=IPv4_ADDRESS
        ):
            yield client
示例#7
0
文件: tc_test.py 项目: almusil/vdsm
 def test_iperf_upper_limit(self, requires_tc):
     # Upper limit is not an accurate measure. This is because it converges
     # over time and depends on current machine hardware (CPU).
     # Hence, it is hard to make hard assertions on it. The test should run
     # at least 60 seconds (the longer the better) and the user should
     # inspect the computed average rate and optionally the additional
     # traffic data that was collected in client.out in order to be
     # convinced QOS is working properly.
     limit_kbps = 1000  # 1 Mbps (in kbps)
     server_ip = '192.0.2.1'
     client_ip = '192.0.2.10'
     qos_out = {'ul': {'m2': limit_kbps}, 'ls': {'m2': limit_kbps}}
     # using a network namespace is essential since otherwise the kernel
     # short-circuits the traffic and bypasses the veth devices and the
     # classfull qdisc.
     with network_namespace(
             'server_ns') as ns, bridge_device() as bridge, veth_pair() as (
                 server_peer,
                 server_dev,
             ), veth_pair() as (
                 client_dev,
                 client_peer,
             ):
         # iperf server and its veth peer lie in a separate network
         # namespace
         link_set_netns(server_dev, ns)
         bridge.add_port(server_peer)
         bridge.add_port(client_peer)
         netns_exec(ns, ['ip', 'link', 'set', 'dev', server_dev, 'up'])
         Interface.from_existing_dev_name(client_dev).add_ip(
             client_ip, 24, IpFamily.IPv4)
         netns_exec(
             ns,
             [
                 'ip',
                 '-4',
                 'addr',
                 'add',
                 'dev',
                 server_dev,
                 '%s/24' % server_ip,
             ],
         )
         qos.configure_outbound(qos_out, client_peer, None)
         with running(IperfServer(server_ip, network_ns=ns)):
             client = IperfClient(server_ip, client_ip, test_time=60)
             client.start()
             max_rate = max([
                 float(interval['streams'][0]['bits_per_second']) // (2**10)
                 for interval in client.out['intervals']
             ])
             assert 0 < max_rate < limit_kbps * 1.5
示例#8
0
def dynamic_ipv6_iface():
    if running_on_ovirt_ci():
        pytest.skip('Using dnsmasq for ipv6 RA is unstable on CI')

    with veth_pair() as (server, client):
        with wait_for_ipv6(server, IPV6_ADDR1, IPV6_PREFIX_LENGTH):
            Interface.from_existing_dev_name(server).add_ip(
                IPV6_ADDR1, IPV6_PREFIX_LENGTH, IpFamily.IPv6)
        client_interface = Interface.from_existing_dev_name(client)
        client_interface.down()
        with dnsmasq_run(server, ipv6_slaac_prefix=IPV6_NET_ADDR):
            with wait_for_ipv6(client):
                client_interface.up()
            yield client
示例#9
0
    def test_ip_info(self, nic0):
        nic0_interface = Interface.from_existing_dev_name(nic0)
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR1_CIDR):
            nic0_interface.add_ip(IPV4_ADDR1, IPV4_PREFIX_LENGTH,
                                  IpFamily.IPv4)
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR2_CIDR):
            nic0_interface.add_ip(IPV4_ADDR2, IPV4_PREFIX_LENGTH,
                                  IpFamily.IPv4)
        with waitfor.waitfor_ipv6_addr(nic0, address=IPV6_ADDR_CIDR):
            nic0_interface.add_ip(IPV6_ADDR, IPV6_PREFIX_LENGTH, IpFamily.IPv6)

        # 32 bit addresses are reported slashless by netlink
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR3):
            nic0_interface.add_ip(IPV4_ADDR3, 32, IpFamily.IPv4)

        assert addresses.getIpInfo(nic0) == (
            IPV4_ADDR1,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
        assert addresses.getIpInfo(nic0, ipv4_gateway=IPV4_GATEWAY1) == (
            IPV4_ADDR1,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
        assert addresses.getIpInfo(nic0, ipv4_gateway=IPV4_GATEWAY2) == (
            IPV4_ADDR2,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
示例#10
0
    def _configure_ip(device, families):
        interface = Interface.from_existing_dev_name(device)

        if IpFamily.IPv4 in families:
            interface.add_ip(IPv4_ADDRESS, IPv4_PREFIX_LEN, IpFamily.IPv4)
        if IpFamily.IPv6 in families:
            interface.add_ip(IPv6_ADDRESS, IPv6_PREFIX_LEN, IpFamily.IPv6)
示例#11
0
    def test_replace_broken_network(self, adapter, bridged, nic0):
        NETCREATE = {
            NETWORK_NAME: {'nic': nic0, 'vlan': VLANID, 'bridged': bridged}
        }
        with adapter.setupNetworks(NETCREATE, {}, NOCHK):
            if bridged:
                dev_name = NETWORK_NAME
            else:
                dev_name = f'{nic0}.{NETCREATE[NETWORK_NAME]["vlan"]}'
            Interface.from_existing_dev_name(dev_name).remove()

            adapter.refresh_netinfo()

            adapter.assertNoNetworkExists(NETWORK_NAME)
            with adapter.setupNetworks(NETCREATE, {}, NOCHK):
                adapter.assertNetworkExists(NETWORK_NAME)
示例#12
0
    def test_attach_nic_with_ip_to_ip_network(self, adapter, switch, nic0):
        Interface.from_existing_dev_name(nic0).add_ip(IPv4_ADDRESS,
                                                      IPv4_PREFIX_LEN,
                                                      IpFamily.IPv4)

        NETCREATE = {
            NETWORK_NAME: {
                'nic': nic0,
                'ipaddr': IPv4_ADDRESS,
                'netmask': IPv4_NETMASK,
                'switch': switch,
            }
        }
        with adapter.setupNetworks(NETCREATE, {}, NOCHK):
            nic_netinfo = adapter.netinfo.nics[nic0]
            adapter.assertDisabledIPv4(nic_netinfo)
            adapter.assertNetworkIp(NETWORK_NAME, NETCREATE[NETWORK_NAME])
示例#13
0
    def test_attach_nic_with_ip_to_ipless_network(self, adapter, switch, nic0):
        nic0_interface = Interface.from_existing_dev_name(nic0)
        nic0_interface.add_ip(IPv4_ADDRESS, IPv4_PREFIX_LEN, IpFamily.IPv4)
        nic0_interface.add_ip(IPv6_ADDRESS, IPv6_PREFIX_LEN, IpFamily.IPv6)

        NETCREATE = {NETWORK_NAME: {'nic': nic0, 'switch': switch}}
        with adapter.setupNetworks(NETCREATE, {}, NOCHK):
            nic_netinfo = adapter.netinfo.nics[nic0]
            adapter.assertDisabledIPv4(nic_netinfo)
            adapter.assertDisabledIPv6(nic_netinfo)
示例#14
0
 def test_add_net_on_existing_external_bond_preserving_mac(
         self, adapter, switch, nic0, nic1):
     bond = bond_without_remove(slaves=[nic0, nic1])
     Interface.from_existing_dev_name(bond).set_mac_address(HWADDRESS)
     NETBASE = {
         NETWORK1_NAME: {
             'bonding': bond,
             'bridged': False,
             'switch': switch,
         }
     }
     with adapter.setupNetworks(NETBASE, {}, NOCHK):
         adapter.assertNetwork(NETWORK1_NAME, NETBASE[NETWORK1_NAME])
         adapter.assertBond(
             bond,
             {
                 'nics': [nic0, nic1],
                 'hwaddr': HWADDRESS,
                 'switch': switch
             },
         )
     adapter.setupNetworks({}, {bond: {'remove': True}}, NOCHK)
示例#15
0
def _configure_iface_ip(iface_name, network_config):
    iface = Interface.from_existing_dev_name(iface_name)
    if network_config.ipv4_address:
        with wait_for_ipv4(
                iface_name,
                network_config.ipv4_address,
                network_config.ipv4_prefix_length,
        ):
            iface.add_ip(
                network_config.ipv4_address,
                network_config.ipv4_prefix_length,
                IpFamily.IPv4,
            )
    if network_config.ipv6_address:
        with wait_for_ipv6(
                iface_name,
                network_config.ipv6_address,
                network_config.ipv6_prefix_length,
        ):
            iface.add_ip(
                network_config.ipv6_address,
                network_config.ipv6_prefix_length,
                IpFamily.IPv6,
            )
示例#16
0
 def _set_ip_address(self, iface, addr, prefixlen):
     Interface.from_existing_dev_name(iface).add_ip(addr, prefixlen,
                                                    IpFamily.IPv4)