Exemplo n.º 1
0
    def test_add_net_with_dhcp(self, switch, families, bridged):

        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, IpFamily.IPv6)
            linkSet(server, ['up'])
            with dnsmasq_run(server, DHCPv4_RANGE_FROM, DHCPv4_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO,
                             router=DHCPv4_GATEWAY):

                network_attrs = {'bridged': bridged,
                                 'nic': client,
                                 'blockingdhcp': True,
                                 'switch': switch}

                if IpFamily.IPv4 in families:
                    network_attrs['bootproto'] = 'dhcp'
                if IpFamily.IPv6 in families:
                    network_attrs['dhcpv6'] = True

                netcreate = {NETWORK_NAME: network_attrs}

                with adapter.setupNetworks(netcreate, {}, NOCHK):
                    adapter.assertNetworkIp(
                        NETWORK_NAME, netcreate[NETWORK_NAME])
Exemplo n.º 2
0
    def test_switch_change_bonded_network_with_dhclient(self, sw_src, sw_dst):
        with veth_pair() as (server, nic1):
            with dummy_device() as nic2:
                NETSETUP_SOURCE = {NET1_NAME: {
                    'bonding': BOND_NAME,
                    'bootproto': 'dhcp',
                    'blockingdhcp': True,
                    'switch': sw_src}}
                NETSETUP_TARGET = _change_switch_type(NETSETUP_SOURCE, sw_dst)
                BONDSETUP_SOURCE = {BOND_NAME: {
                    'nics': [nic1, nic2], 'switch': sw_src}}
                BONDSETUP_TARGET = _change_switch_type(BONDSETUP_SOURCE,
                                                       sw_dst)

                addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
                linkSet(server, ['up'])

                with dnsmasq_run(server, DHCPv4_RANGE_FROM, DHCPv4_RANGE_TO,
                                 router=IPv4_ADDRESS):
                    with adapter.setupNetworks(
                            NETSETUP_SOURCE, BONDSETUP_SOURCE, NOCHK):
                        adapter.setupNetworks(
                            NETSETUP_TARGET, BONDSETUP_TARGET, NOCHK)
                        adapter.assertNetwork(
                            NET1_NAME, NETSETUP_TARGET[NET1_NAME])
                        adapter.assertBond(BOND_NAME,
                                           BONDSETUP_TARGET[BOND_NAME])
Exemplo n.º 3
0
    def test_attach_dhcp_nic_to_dhcpv6_bridged_network(self, switch):
        if switch == 'ovs':
            pytest.xfail('IPv6 dynamic fails with OvS'
                         'see https://bugzilla.redhat.com/1773471')
        with veth_pair() as (server, client):
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, IpFamily.IPv6)
            linkSet(server, ['up'])
            with dnsmasq_run(server, DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO):
                with dhcp_client_run(client, family=IpFamily.IPv6):
                    adapter.assertDhclient(client, family=IpFamily.IPv6)

                    NETCREATE = {
                        NETWORK_NAME: {
                            'nic': client,
                            'dhcpv6': True,
                            'blockingdhcp': True,
                            'switch': switch,
                        }
                    }
                    with adapter.setupNetworks(NETCREATE, {}, NOCHK):
                        nic_netinfo = adapter.netinfo.nics[client]
                        adapter.assertDisabledIPv6(nic_netinfo)
                        adapter.assertNoDhclient(client, family=IpFamily.IPv6)
                        net_netinfo = adapter.netinfo.networks[NETWORK_NAME]
                        adapter.assertDHCPv6(net_netinfo)
                        adapter.assertDhclient(NETWORK_NAME,
                                               family=IpFamily.IPv6)
Exemplo n.º 4
0
    def test_ovirtmgmtm_to_ovs(self):
        """ Test transformation of initial management network to OVS.
        # TODO: test it with ovirtmgmt and test-network
        # NOTE: without default route
        # TODO: more asserts
        """
        with veth_pair() as (left, right):
            addrAdd(left, IP_ADDRESS, IP_CIDR)
            addrAdd(left, IPv6_ADDRESS, IPv6_CIDR, 6)
            linkSet(left, ['up'])
            with dnsmasq_run(left, DHCP_RANGE_FROM, DHCP_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO, IP_GATEWAY):
                network = {
                    NETWORK_NAME: {
                        'nic': right,
                        'bootproto': 'dhcp',
                        'bridged': True,
                        'blockingdhcp': True
                    }
                }
                options = NOCHK
                options['ovs'] = False

                try:
                    status, msg = self.setupNetworks(network, {}, options)
                    self.assertEqual(status, SUCCESS, msg)
                    self.assertNetworkExists(NETWORK_NAME)

                    options['ovs'] = True
                    status, msg = self.setupNetworks(network, {}, options)
                    self.assertEqual(status, SUCCESS, msg)
                    self.assertNetworkExists(NETWORK_NAME)
                finally:
                    dhcp.delete_dhclient_leases(NETWORK_NAME, True, False)
Exemplo n.º 5
0
    def test_attach_dhcp_nic_to_dhcpv4_bridged_network(self, switch):
        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            linkSet(server, ['up'])
            with dnsmasq_run(server,
                             DHCPv4_RANGE_FROM,
                             DHCPv4_RANGE_TO,
                             router=DHCPv4_GATEWAY):
                with dhclient_run(client):
                    adapter.assertDhclient(client, family=IpFamily.IPv4)

                    NETCREATE = {
                        NETWORK_NAME: {
                            'nic': client,
                            'bootproto': 'dhcp',
                            'blockingdhcp': True,
                            'switch': switch
                        }
                    }
                    with adapter.setupNetworks(NETCREATE, {}, NOCHK):
                        nic_netinfo = adapter.netinfo.nics[client]
                        adapter.assertDisabledIPv4(nic_netinfo)
                        adapter.assertNoDhclient(client, family=IpFamily.IPv4)
                        net_netinfo = adapter.netinfo.networks[NETWORK_NAME]
                        adapter.assertDHCPv4(net_netinfo)
                        adapter.assertDhclient(NETWORK_NAME,
                                               family=IpFamily.IPv4)
Exemplo n.º 6
0
    def test_attach_dhcp_nic_to_ipless_network(self, switch):
        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, IpFamily.IPv6)
            linkSet(server, ['up'])
            with dnsmasq_run(server,
                             DHCPv4_RANGE_FROM,
                             DHCPv4_RANGE_TO,
                             DHCPv6_RANGE_FROM,
                             DHCPv6_RANGE_TO,
                             router=DHCPv4_GATEWAY):
                with dhclient_run(client):
                    adapter.assertDhclient(client, family=IpFamily.IPv4)
                    adapter.assertDhclient(client, family=IpFamily.IPv6)

                    NETCREATE = {
                        NETWORK_NAME: {
                            'nic': client,
                            'switch': switch
                        }
                    }
                    with adapter.setupNetworks(NETCREATE, {}, NOCHK):
                        nic_netinfo = adapter.netinfo.nics[client]
                        adapter.assertDisabledIPv4(nic_netinfo)
                        adapter.assertDisabledIPv6(nic_netinfo)
                        net_netinfo = adapter.netinfo.networks[NETWORK_NAME]
                        adapter.assertDisabledIPv4(net_netinfo)
                        adapter.assertDisabledIPv6(nic_netinfo)
Exemplo n.º 7
0
    def test_switch_change_bonded_network_with_dhclient(self, sw_src, sw_dst):
        with veth_pair() as (server, nic1):
            with dummy_device() as nic2:
                NETSETUP_SOURCE = {NET1_NAME: {
                    'bonding': BOND_NAME,
                    'bootproto': 'dhcp',
                    'blockingdhcp': True,
                    'switch': sw_src}}
                NETSETUP_TARGET = _change_switch_type(NETSETUP_SOURCE, sw_dst)
                BONDSETUP_SOURCE = {BOND_NAME: {
                    'nics': [nic1, nic2], 'switch': sw_src}}
                BONDSETUP_TARGET = _change_switch_type(BONDSETUP_SOURCE,
                                                       sw_dst)

                addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
                linkSet(server, ['up'])

                with dnsmasq_run(server, DHCPv4_RANGE_FROM, DHCPv4_RANGE_TO,
                                 router=IPv4_ADDRESS):
                    with adapter.setupNetworks(
                            NETSETUP_SOURCE, BONDSETUP_SOURCE, NOCHK):
                        adapter.setupNetworks(
                            NETSETUP_TARGET, BONDSETUP_TARGET, NOCHK)
                        adapter.assertNetwork(
                            NET1_NAME, NETSETUP_TARGET[NET1_NAME])
                        adapter.assertBond(BOND_NAME,
                                           BONDSETUP_TARGET[BOND_NAME])
Exemplo n.º 8
0
    def test_add_net_with_dhcp(self, switch, families, bridged):

        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, IpFamily.IPv6)
            linkSet(server, ['up'])
            with dnsmasq_run(server,
                             DHCPv4_RANGE_FROM,
                             DHCPv4_RANGE_TO,
                             DHCPv6_RANGE_FROM,
                             DHCPv6_RANGE_TO,
                             router=DHCPv4_GATEWAY):

                network_attrs = {
                    'bridged': bridged,
                    'nic': client,
                    'blockingdhcp': True,
                    'switch': switch
                }

                if IpFamily.IPv4 in families:
                    network_attrs['bootproto'] = 'dhcp'
                if IpFamily.IPv6 in families:
                    network_attrs['dhcpv6'] = True

                netcreate = {NETWORK_NAME: network_attrs}

                with adapter.setupNetworks(netcreate, {}, NOCHK):
                    adapter.assertNetworkIp(NETWORK_NAME,
                                            netcreate[NETWORK_NAME])
Exemplo n.º 9
0
    def test_ovirtmgmtm_to_ovs(self):
        """ Test transformation of initial management network to OVS.
        # TODO: test it with ovirtmgmt and test-network
        # NOTE: without default route
        # TODO: more asserts
        """
        with veth_pair() as (left, right):
            addrAdd(left, IP_ADDRESS, IP_CIDR)
            addrAdd(left, IPv6_ADDRESS, IPv6_CIDR, 6)
            linkSet(left, ['up'])
            with dnsmasq_run(left, DHCP_RANGE_FROM, DHCP_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO, IP_GATEWAY):
                network = {
                    NETWORK_NAME: {'nic': right, 'bootproto': 'dhcp',
                                   'bridged': True, 'blockingdhcp': True}}
                options = NOCHK
                options['ovs'] = False

                try:
                    status, msg = self.setupNetworks(network, {}, options)
                    self.assertEqual(status, SUCCESS, msg)
                    self.assertNetworkExists(NETWORK_NAME)

                    options['ovs'] = True
                    status, msg = self.setupNetworks(network, {}, options)
                    self.assertEqual(status, SUCCESS, msg)
                    self.assertNetworkExists(NETWORK_NAME)
                finally:
                    dhcp.delete_dhclient_leases(NETWORK_NAME, True, False)
Exemplo n.º 10
0
def dynamic_ipv4_iface():
    with veth_pair() as (server, client):
        addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
        linkSet(server, ['up'])
        with dnsmasq_run(server,
                         DHCPv4_RANGE_FROM,
                         DHCPv4_RANGE_TO,
                         router=IPv4_ADDRESS):
            yield client
Exemplo n.º 11
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
Exemplo n.º 12
0
    def testDhcpReplaceNicWithBridge(self):
        with veth_pair() as (left, right):
            addrAdd(left, IP_ADDRESS, IP_CIDR)
            addrAdd(left, IPv6_ADDRESS, IPv6_CIDR, 6)
            linkSet(left, ['up'])
            with dnsmasq_run(left, DHCP_RANGE_FROM, DHCP_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO, IP_GATEWAY):

                # first, a network without a bridge should get a certain
                # address

                network = {
                    NETWORK_NAME: {
                        'nic': right,
                        'bridged': False,
                        'bootproto': 'dhcp',
                        'blockingdhcp': True
                    }
                }
                try:
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)
                    self.assertNetworkExists(NETWORK_NAME)

                    test_net = self.vdsm_net.netinfo.networks[NETWORK_NAME]
                    self.assertEqual(test_net['dhcpv4'], True)
                    devs = self.vdsm_net.netinfo.nics
                    device_name = right

                    self.assertIn(device_name, devs)
                    net_attrs = devs[device_name]
                    self.assertEqual(net_attrs['dhcpv4'], True)

                    self.assertEqual(test_net['gateway'], IP_GATEWAY)
                    ip_addr = test_net['addr']
                    self.assertSourceRoutingConfiguration(device_name, ip_addr)

                    # now, a bridged network should get the same address
                    # (because dhclient should send the same dhcp-client-
                    #  identifier)

                    network[NETWORK_NAME]['bridged'] = True
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)
                    test_net = self.vdsm_net.netinfo.networks[NETWORK_NAME]
                    self.assertEqual(ip_addr, test_net['addr'])

                    network = {NETWORK_NAME: {'remove': True}}
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)
                    self.assertNetworkDoesntExist(NETWORK_NAME)

                finally:
                    dhcp.delete_dhclient_leases(right, True, False)
                    dhcp.delete_dhclient_leases(NETWORK_NAME, True, False)
Exemplo n.º 13
0
def _create_configured_dhcp_client_iface(network_config, dhcp_config):
    with _create_dhcp_client_server_peers(network_config) as (server, client):
        dhcp_server = dnsmasq_run(
            server,
            dhcp_config.ipv4_range_from,
            dhcp_config.ipv4_range_to,
            dhcp_config.ipv6_range_from,
            dhcp_config.ipv6_range_to,
            router=network_config.ipv4_address,
        )
        with dhcp_server:
            yield client
Exemplo n.º 14
0
    def test_move_nic_between_bridgeless_and_bridged_keep_ip(
            self, switch, families):
        if switch == 'ovs' and IpFamily.IPv6 in families:
            pytest.xfail('IPv6 dynamic fails with OvS'
                         'see https://bugzilla.redhat.com/1773471')
        if (switch == 'legacy' and IpFamily.IPv6 in families
                and not nftestlib.is_nmstate_backend()):
            pytest.xfail('Fails with ifcfg for IPv6')
        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, IpFamily.IPv6)
            linkSet(server, ['up'])
            linkSet(client, ['up'])
            with dnsmasq_run(
                    server,
                    DHCPv4_RANGE_FROM,
                    DHCPv4_RANGE_TO,
                    DHCPv6_RANGE_FROM,
                    DHCPv6_RANGE_TO,
                    router=DHCPv4_GATEWAY,
            ):

                network_attrs = {
                    'bridged': False,
                    'nic': client,
                    'blockingdhcp': True,
                    'switch': switch,
                }

                if IpFamily.IPv4 in families:
                    network_attrs['bootproto'] = 'dhcp'
                if IpFamily.IPv6 in families:
                    network_attrs['dhcpv6'] = True

                netcreate = {NETWORK_NAME: network_attrs}

                with adapter.setupNetworks(netcreate, {}, NOCHK):
                    adapter.assertNetworkIp(NETWORK_NAME,
                                            netcreate[NETWORK_NAME])
                    client_info = adapter.netinfo.nics[client]
                    ipv4_addr = client_info['ipv4addrs']
                    ipv6_addr = client_info['ipv6addrs']

                    network_attrs['bridged'] = True
                    adapter.setupNetworks(netcreate, {}, NOCHK)
                    adapter.assertNetworkIp(NETWORK_NAME,
                                            netcreate[NETWORK_NAME])
                    network_info = adapter.netinfo.networks[NETWORK_NAME]
                    assert ipv4_addr == network_info['ipv4addrs']
                    assert ipv6_addr == network_info['ipv6addrs']
Exemplo n.º 15
0
    def testSetupNetworksOverDhcpIface(self):
        """When asked to setupNetwork on top of an interface with a running
        dhclient process, Vdsm is expected to stop that dhclient and start
        owning the interface. BZ#1100264"""
        def _get_dhclient_ifaces():
            pids = pgrep('dhclient')
            return [
                open('/proc/%s/cmdline' %
                     pid).read().strip('\0').split('\0')[-1] for pid in pids
            ]

        with veth_pair() as (server, client):
            addrAdd(server, IP_ADDRESS, IP_CIDR)
            linkSet(server, ['up'])
            with dnsmasq_run(server, DHCP_RANGE_FROM, DHCP_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO, IP_GATEWAY):
                with namedTemporaryDir(dir='/var/lib/dhclient') as dhdir:
                    # Start a non-vdsm owned dhclient for the 'client' iface
                    dhclient_runner = dhcp.DhclientRunner(
                        client, 4, dhdir, 'default')
                    with running(dhclient_runner):
                        # Set up a network over it and wait for dhcp success
                        status, msg = self.setupNetworks(
                            {
                                NETWORK_NAME: {
                                    'nic': client,
                                    'bridged': False,
                                    'bootproto': 'dhcp',
                                    'blockingdhcp': True
                                }
                            }, {}, NOCHK)
                        self.assertEqual(status, SUCCESS, msg)
                        self.assertNetworkExists(NETWORK_NAME)

                        # Verify that dhclient is running for the device
                        ifaces = _get_dhclient_ifaces()
                        vdsm_dhclient = [
                            iface for iface in ifaces if iface == client
                        ]
                        self.assertEqual(
                            len(vdsm_dhclient), 1,
                            'There should be one and only one '
                            'running dhclient for the device')

            # cleanup
            self.setupNetworks({NETWORK_NAME: {'remove': True}}, {}, NOCHK)
Exemplo n.º 16
0
    def test_attach_dhcp_nic_to_ipless_network(self, switch):
        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            linkSet(server, ['up'])
            with dnsmasq_run(server, DHCPv4_RANGE_FROM, DHCPv4_RANGE_TO):
                with dhclient_run(client):
                    self.assertDhclient(client, family=4)

                    NETCREATE = {
                        NETWORK_NAME: {
                            'nic': client,
                            'switch': switch
                        }
                    }
                    with self.setupNetworks(NETCREATE, {}, NOCHK):
                        nic_netinfo = self.netinfo.nics[client]
                        self.assertDisabledIPv4(nic_netinfo)
                        net_netinfo = self.netinfo.networks[NETWORK_NAME]
                        self.assertDisabledIPv4(net_netinfo)
Exemplo n.º 17
0
    def _test_add_net_with_dhcpv4(self, switch, bridged=False):

        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            linkSet(server, ['up'])
            with dnsmasq_run(server, DHCPv4_RANGE_FROM, DHCPv4_RANGE_TO):

                netcreate = {
                    NETWORK_NAME: {
                        'bridged': bridged,
                        'nic': client,
                        'blockingdhcp': True,
                        'bootproto': 'dhcp',
                        'switch': switch
                    }
                }

                with self.setupNetworks(netcreate, {}, NOCHK):
                    self.assertNetworkIp(NETWORK_NAME, netcreate[NETWORK_NAME])
Exemplo n.º 18
0
    def test_attach_dhcp_nic_to_dhcpv6_bridged_network(self, switch):
        with veth_pair() as (server, client):
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, IpFamily.IPv6)
            linkSet(server, ['up'])
            with dnsmasq_run(server, DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO):
                with dhclient_run(client, family=IpFamily.IPv6):
                    adapter.assertDhclient(client, family=IpFamily.IPv6)

                    NETCREATE = {NETWORK_NAME: {
                        'nic': client, 'dhcpv6': True,
                        'blockingdhcp': True, 'switch': switch}}
                    with adapter.setupNetworks(NETCREATE, {}, NOCHK):
                        nic_netinfo = adapter.netinfo.nics[client]
                        adapter.assertDisabledIPv6(nic_netinfo)
                        adapter.assertNoDhclient(client, family=IpFamily.IPv6)
                        net_netinfo = adapter.netinfo.networks[NETWORK_NAME]
                        adapter.assertDHCPv6(net_netinfo)
                        adapter.assertDhclient(NETWORK_NAME,
                                               family=IpFamily.IPv6)
Exemplo n.º 19
0
    def test_add_net_with_dhcp(self, switch, families, bridged, def_route):
        if switch == 'legacy' and running_on_fedora(29):
            pytest.xfail('Fails on Fedora 29')
        if switch == 'ovs' and IpFamily.IPv6 in families:
            pytest.xfail('IPv6 dynamic fails with OvS'
                         'see https://bugzilla.redhat.com/1773471')
        if families == (IpFamily.IPv6, ) and def_route:
            pytest.skip('Skipping default route + dynamic with IPv6 '
                        'see https://bugzilla.redhat.com/1467332')

        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, IpFamily.IPv6)
            linkSet(server, ['up'])
            linkSet(client, ['up'])
            with dnsmasq_run(
                    server,
                    DHCPv4_RANGE_FROM,
                    DHCPv4_RANGE_TO,
                    DHCPv6_RANGE_FROM,
                    DHCPv6_RANGE_TO,
                    router=DHCPv4_GATEWAY,
            ):

                network_attrs = {
                    'bridged': bridged,
                    'nic': client,
                    'blockingdhcp': True,
                    'switch': switch,
                    'defaultRoute': def_route,
                }

                if IpFamily.IPv4 in families:
                    network_attrs['bootproto'] = 'dhcp'
                if IpFamily.IPv6 in families:
                    network_attrs['dhcpv6'] = True

                netcreate = {NETWORK_NAME: network_attrs}

                with adapter.setupNetworks(netcreate, {}, NOCHK):
                    adapter.assertNetworkIp(NETWORK_NAME,
                                            netcreate[NETWORK_NAME])
Exemplo n.º 20
0
def _create_configured_dhcp_client_iface(network_config,
                                         dhcp_config,
                                         vlan_id=None,
                                         start_dhcp=True):
    with _create_dhcp_client_server_peers(network_config, vlan_id) as (
            server,
            client,
    ):
        if start_dhcp:
            dhcp_server = dnsmasq_run(
                server,
                dhcp_config.ipv4_range_from,
                dhcp_config.ipv4_range_to,
                dhcp_config.ipv6_range_from,
                dhcp_config.ipv6_range_to,
                router=network_config.ipv4_address,
            )
            with dhcp_server:
                yield client
        else:
            yield client
Exemplo n.º 21
0
    def test_attach_dhcp_nic_to_ipless_network(self, switch):
        with veth_pair() as (server, client):
            addrAdd(server, IPv4_ADDRESS, IPv4_PREFIX_LEN)
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, IpFamily.IPv6)
            linkSet(server, ['up'])
            with dnsmasq_run(server, DHCPv4_RANGE_FROM, DHCPv4_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO,
                             router=DHCPv4_GATEWAY):
                with dhclient_run(client):
                    adapter.assertDhclient(client, family=IpFamily.IPv4)
                    adapter.assertDhclient(client, family=IpFamily.IPv6)

                    NETCREATE = {NETWORK_NAME: {
                        'nic': client, 'switch': switch}}
                    with adapter.setupNetworks(NETCREATE, {}, NOCHK):
                        nic_netinfo = adapter.netinfo.nics[client]
                        adapter.assertDisabledIPv4(nic_netinfo)
                        adapter.assertDisabledIPv6(nic_netinfo)
                        net_netinfo = adapter.netinfo.networks[NETWORK_NAME]
                        adapter.assertDisabledIPv4(net_netinfo)
                        adapter.assertDisabledIPv6(nic_netinfo)
Exemplo n.º 22
0
    def testSetupNetworksReconfigureBridge(self):
        def setup_test_network(dhcp=True):
            network_params = {'nic': right, 'bridged': True}
            if dhcp:
                network_params.update({
                    'bootproto': 'dhcp',
                    'blockingdhcp': True
                })
            else:
                network_params.update({
                    'ipaddr': IP_ADDRESS_IN_NETWORK,
                    'netmask': IP_MASK,
                    'gateway': IP_GATEWAY
                })

            status, msg = self.setupNetworks({NETWORK_NAME: network_params},
                                             {}, NOCHK)
            self.assertEqual(status, SUCCESS, msg)
            self.assertNetworkExists(NETWORK_NAME)

            test_net = self.vdsm_net.netinfo.networks[NETWORK_NAME]
            self.assertEqual(test_net['dhcpv4'], dhcp)

            bridges = self.vdsm_net.netinfo.bridges
            self.assertIn(NETWORK_NAME, bridges)
            self.assertEqual(bridges[NETWORK_NAME]['dhcpv4'], dhcp)

        with veth_pair() as (left, right):
            addrAdd(left, IP_ADDRESS, IP_CIDR)
            linkSet(left, ['up'])
            with dnsmasq_run(left, DHCP_RANGE_FROM, DHCP_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO, IP_GATEWAY):
                try:
                    setup_test_network(dhcp=True)
                    dhcp.delete_dhclient_leases(NETWORK_NAME, dhcpv4=True)
                    setup_test_network(dhcp=False)
                finally:
                    dhcp.delete_dhclient_leases(NETWORK_NAME, dhcpv4=True)
Exemplo n.º 23
0
    def testDhclientLeases(self, family, dateFormat):
        with veth_pair() as (server, client):
            addrAdd(server, IP_ADDRESS, IP_CIDR)
            addrAdd(server, IPv6_ADDRESS, IPv6_CIDR, 6)
            linkSet(server, ['up'])

            with dnsmasq_run(server, DHCP_RANGE_FROM, DHCP_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO, IP_GATEWAY):

                with namedTemporaryDir(dir='/var/lib/dhclient') as dir:
                    dhclient_runner = dhcp.DhclientRunner(
                        client, family, dir, dateFormat)
                    try:
                        with running(dhclient_runner):
                            is_dhcpv4 = dhclient.is_active(client, family=4)
                            is_dhcpv6 = dhclient.is_active(client, family=6)
                    except dhcp.ProcessCannotBeKilled:
                        raise SkipTest('dhclient could not be killed')

        if family == 4:
            self.assertTrue(is_dhcpv4)
        else:
            self.assertTrue(is_dhcpv6)
Exemplo n.º 24
0
    def testSetupNetworksAddDelDhcp(self, bridged, families):
        """Copied from networkTests.py, source_route checking changed from
        device_name to BRIDGE_NAME.
        """
        def _assert_applied(network_name, requested, reported):
            self.assertNetworkExists(network_name)
            reported_network = reported.networks[network_name]

            if requested['bridged']:
                reported_devices = reported.bridges
                device_name = network_name
            else:
                # CHANGED: always bridged
                pass
            self.assertIn(device_name, reported_devices)
            reported_device = reported_devices[device_name]

            requested_dhcpv4 = requested['bootproto'] == 'dhcp'
            self.assertEqual(reported_network['dhcpv4'], requested_dhcpv4)
            self.assertEqual(reported_network['dhcpv6'], requested['dhcpv6'])

            self.assertEqual(reported_device['dhcpv4'], requested_dhcpv4)
            self.assertEqual(reported_device['dhcpv6'], requested['dhcpv6'])

            if requested_dhcpv4:
                self.assertEqual(reported_network['gateway'], IP_GATEWAY)
                # TODO: source routing not ready for IPv6
                ip_addr = reported_network['addr']
                self.assertSourceRoutingConfiguration(BRIDGE_NAME,  # CHANGED
                                                      ip_addr)
                return device_name, ip_addr
            return None, None

        with veth_pair() as (left, right):
            addrAdd(left, IP_ADDRESS, IP_CIDR)
            addrAdd(left, IPv6_ADDRESS, IPv6_CIDR, 6)
            linkSet(left, ['up'])
            with dnsmasq_run(left, DHCP_RANGE_FROM, DHCP_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO, IP_GATEWAY):
                dhcpv4 = 4 in families
                dhcpv6 = 6 in families
                bootproto = 'dhcp' if dhcpv4 else 'none'
                network = {NETWORK_NAME: {'nic': right, 'bridged': bridged,
                                          'bootproto': bootproto,
                                          'dhcpv6': dhcpv6,
                                          'blockingdhcp': True}}
                try:
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)

                    device_name, ip_addr = _assert_applied(
                        NETWORK_NAME, network[NETWORK_NAME],
                        self.vdsm_net.netinfo)

                    # Do not report DHCP from (typically still valid) leases
                    network[NETWORK_NAME]['bootproto'] = 'none'
                    network[NETWORK_NAME]['dhcpv6'] = False
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)

                    _assert_applied(NETWORK_NAME, network[NETWORK_NAME],
                                    self.vdsm_net.netinfo)

                    network = {NETWORK_NAME: {'remove': True}}
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)
                    self.assertNetworkDoesntExist(NETWORK_NAME)

                    # Assert that routes and rules don't exist
                    if dhcpv4:
                        source_route = _get_source_route(device_name, ip_addr)
                        for route in source_route._buildRoutes():
                            self.assertRouteDoesNotExist(route)
                        for rule in source_route._buildRules():
                            self.assertRuleDoesNotExist(rule)
                finally:
                    dhcp.delete_dhclient_leases(
                        NETWORK_NAME if bridged else right, dhcpv4, dhcpv6)
Exemplo n.º 25
0
    def testSetupNetworksAddDelDhcp(self, bridged, families):
        """Copied from networkTests.py, source_route checking changed from
        device_name to BRIDGE_NAME.
        """
        def _assert_applied(network_name, requested, reported):
            self.assertNetworkExists(network_name)
            reported_network = reported.networks[network_name]

            if requested['bridged']:
                reported_devices = reported.bridges
                device_name = network_name
            else:
                # CHANGED: always bridged
                pass
            self.assertIn(device_name, reported_devices)
            reported_device = reported_devices[device_name]

            requested_dhcpv4 = requested['bootproto'] == 'dhcp'
            self.assertEqual(reported_network['dhcpv4'], requested_dhcpv4)
            self.assertEqual(reported_network['dhcpv6'], requested['dhcpv6'])

            self.assertEqual(reported_device['dhcpv4'], requested_dhcpv4)
            self.assertEqual(reported_device['dhcpv6'], requested['dhcpv6'])

            if requested_dhcpv4:
                self.assertEqual(reported_network['gateway'], IP_GATEWAY)
                # TODO: source routing not ready for IPv6
                ip_addr = reported_network['addr']
                self.assertSourceRoutingConfiguration(
                    BRIDGE_NAME,  # CHANGED
                    ip_addr)
                return device_name, ip_addr
            return None, None

        with veth_pair() as (left, right):
            addrAdd(left, IP_ADDRESS, IP_CIDR)
            addrAdd(left, IPv6_ADDRESS, IPv6_CIDR, 6)
            linkSet(left, ['up'])
            with dnsmasq_run(left, DHCP_RANGE_FROM, DHCP_RANGE_TO,
                             DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO, IP_GATEWAY):
                dhcpv4 = 4 in families
                dhcpv6 = 6 in families
                bootproto = 'dhcp' if dhcpv4 else 'none'
                network = {
                    NETWORK_NAME: {
                        'nic': right,
                        'bridged': bridged,
                        'bootproto': bootproto,
                        'dhcpv6': dhcpv6,
                        'blockingdhcp': True
                    }
                }
                try:
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)

                    device_name, ip_addr = _assert_applied(
                        NETWORK_NAME, network[NETWORK_NAME],
                        self.vdsm_net.netinfo)

                    # Do not report DHCP from (typically still valid) leases
                    network[NETWORK_NAME]['bootproto'] = 'none'
                    network[NETWORK_NAME]['dhcpv6'] = False
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)

                    _assert_applied(NETWORK_NAME, network[NETWORK_NAME],
                                    self.vdsm_net.netinfo)

                    network = {NETWORK_NAME: {'remove': True}}
                    status, msg = self.setupNetworks(network, {}, NOCHK)
                    self.assertEqual(status, SUCCESS, msg)
                    self.assertNetworkDoesntExist(NETWORK_NAME)

                    # Assert that routes and rules don't exist
                    if dhcpv4:
                        source_route = _get_source_route(device_name, ip_addr)
                        for route in source_route._buildRoutes():
                            self.assertRouteDoesNotExist(route)
                        for rule in source_route._buildRules():
                            self.assertRuleDoesNotExist(rule)
                finally:
                    dhcp.delete_dhclient_leases(
                        NETWORK_NAME if bridged else right, dhcpv4, dhcpv6)