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, ): linkSet(server_peer, ['up']) linkSet(client_peer, ['up']) # iperf server and its veth peer lie in a separate network # namespace link_set_netns(server_dev, ns) bridge.addIf(server_peer) bridge.addIf(client_peer) linkSet(client_dev, ['up']) netns_exec(ns, ['ip', 'link', 'set', 'dev', server_dev, 'up']) addrAdd(client_dev, client_ip, 24) 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
def test_restore_missing_dynamic_ipv4_network( self, adapter, switch, bridged ): with veth_pair() as (server, client): linkSet(server, ['up']) linkSet(client, ['up']) SETUP_NET = { NETWORK_NAME: { 'nic': client, 'bridged': bridged, 'bootproto': 'dhcp', 'switch': switch, } } REMOVE_NET = {NETWORK_NAME: {'remove': True}} with adapter.reset_persistent_config(): with adapter.setupNetworks(SETUP_NET, {}, NOCHK): adapter.setSafeNetworkConfig() adapter.setupNetworks(REMOVE_NET, {}, NOCHK) adapter.assertNoNetworkExists(NETWORK_NAME) adapter.restore_nets() adapter.assertNetworkExists(NETWORK_NAME)
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])
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)
def test_interfaces_stats(switch): with veth_pair() as (nic1, nic2): NETSETUP1 = { NETWORK_NAME1: { 'bridged': False, 'nic': nic1, 'switch': switch } } NETSETUP2 = { NETWORK_NAME2: { 'bridged': False, 'nic': nic2, 'switch': switch } } with adapter.setupNetworks(NETSETUP1, {}, NOCHK): with adapter.setupNetworks(NETSETUP2, {}, NOCHK): stats = adapter.getNetworkStatistics() netstats = stats.get('network') assert netstats assert nic1 in netstats assert nic2 in netstats tx1 = int(netstats[nic1]['tx']) tx2 = int(netstats[nic2]['tx']) rx1 = int(netstats[nic1]['rx']) rx2 = int(netstats[nic2]['rx']) assert tx1 >= 0 assert tx2 >= 0 assert rx1 >= 0 assert rx2 >= 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)
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])
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)
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 dnsmasqDhcp(left): 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)
def test_restore_dynamic_ipv4_network(self, switch): if switch == 'ovs': # With OVS, the restoration creates the network without an IP. pytest.xfail('Inconsistent behaviour with OVS') with veth_pair() as (server, client): linkSet(server, ['up']) SETUP_NET = { NETWORK_NAME: { 'nic': client, 'bridged': False, 'bootproto': 'dhcp', 'switch': switch, } } REMOVE_NET = {NETWORK_NAME: {'remove': True}} with adapter.reset_persistent_config(): with adapter.setupNetworks(SETUP_NET, {}, NOCHK): adapter.setSafeNetworkConfig() adapter.setupNetworks(REMOVE_NET, {}, NOCHK) adapter.assertNoNetworkExists(NETWORK_NAME) adapter.restore_nets() # Attempt to restore network without dhcp server. # As expected, restoration occurs with blockingdhcp=True # and therefore it should fail the setup. adapter.assertNoNetworkExists(NETWORK_NAME)
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])
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)
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
def _create_dhcp_client_server_peers(network_config, vlan_id): with veth_pair(max_length=10) as (server, client): if vlan_id: with vlan_device(server, vlan_id) as vlan_iface: _configure_iface_ip(vlan_iface, network_config) yield vlan_iface, client else: _configure_iface_ip(server, network_config) yield server, client
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
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)
def _create_dhcp_client_server_peers(network_config, vlan_id): with veth_pair(max_length=10) as (server, client): linkSet(server, ['up']) linkSet(client, ['up']) if vlan_id: with vlan_device(server, vlan_id) as vlan_iface: vlan_iface_name = vlan_iface.devName _configure_iface_ip(vlan_iface_name, network_config) yield vlan_iface_name, client else: _configure_iface_ip(server, network_config) yield server, client
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']
def _create_dhcp_client_server_peers(network_config): with veth_pair() as (server, client): addrAdd( server, network_config.ipv4_address, network_config.ipv4_prefix_length, ) if network_config.ipv6_address: addrAdd( server, network_config.ipv6_address, network_config.ipv6_prefix_length, IpFamily.IPv6, ) linkSet(server, ['up']) linkSet(client, ['up']) yield server, client
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)
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)
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])
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)
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])
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)
def test_restore_missing_dynamic_ipv4_network(self, adapter, switch, bridged): if switch == 'ovs': # With OVS, the restoration creates the network without an IP. pytest.xfail('Inconsistent behaviour with OVS') elif bridged and not nmstate.is_nmstate_backend(): pytest.xfail('https://bugzilla.redhat.com/1790392') with veth_pair() as (server, client): linkSet(server, ['up']) linkSet(client, ['up']) SETUP_NET = { NETWORK_NAME: { 'nic': client, 'bridged': bridged, 'bootproto': 'dhcp', 'switch': switch, } } REMOVE_NET = {NETWORK_NAME: {'remove': True}} with adapter.reset_persistent_config(): with adapter.setupNetworks(SETUP_NET, {}, NOCHK): adapter.setSafeNetworkConfig() adapter.setupNetworks(REMOVE_NET, {}, NOCHK) adapter.assertNoNetworkExists(NETWORK_NAME) adapter.restore_nets() if nmstate.is_nmstate_backend(): # nmstate successfully restores a network without # a dhcp server in place. adapter.assertNetworkExists(NETWORK_NAME) else: # Attempt to restore network without dhcp server. # As expected, restoration occurs with # blockingdhcp=True and therefore it should fail the # setup. adapter.assertNoNetworkExists(NETWORK_NAME)
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)
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)
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']: self.assertEqual(reported_network['cfg']['BOOTPROTO'], requested['bootproto']) 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['cfg']['BOOTPROTO'], requested['bootproto']) 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 dnsmasqDhcp(left): 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)
def two_connected_pair_of_bond_slaves(): with veth_pair() as (n1, n2), veth_pair() as (n3, n4): yield [n1, n3], [n2, n4]
def veth_nics(): with veth_pair() as nics: for nic in nics: iface(nic).up() yield nics
def veth_nics(): with veth_pair() as nics: yield nics
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)