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_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 testFakeNics(self): with MonkeyPatchScope([(ipwrapper.Link, '_fakeNics', ['veth_*', 'dummy_*'])]): with veth_pair() as (v1a, v1b): with dummy_device() as d1: fakes = set([d1, v1a, v1b]) nics = netinfo.nics() self.assertTrue(fakes.issubset(nics), 'Fake devices %s are' ' not listed in nics %s' % (fakes, nics)) with veth_pair(prefix='mehv_') as (v2a, v2b): with dummy_device(prefix='mehd_') as d2: hiddens = set([d2, v2a, v2b]) nics = netinfo.nics() self.assertFalse(hiddens.intersection(nics), 'Some of ' 'hidden devices %s is shown in nics %s' % (hiddens, nics))
def testFakeNics(self): with MonkeyPatchScope([(ipwrapper.Link, '_fakeNics', ['veth_*', 'dummy_*'])]): with veth_pair() as (v1a, v1b): with dummy_device() as d1: fakes = set([d1, v1a, v1b]) nics = netinfo.nics() self.assertTrue( fakes.issubset(nics), 'Fake devices %s are' ' not listed in nics %s' % (fakes, nics)) with veth_pair(prefix='mehv_') as (v2a, v2b): with dummy_device(prefix='mehd_') as d2: hiddens = set([d2, v2a, v2b]) nics = netinfo.nics() self.assertFalse( hiddens.intersection(nics), 'Some of ' 'hidden devices %s is shown in nics %s' % (hiddens, nics))
def test_iperf_upper_limit(self): # 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'] ]) self.assertTrue(0 < max_rate < limit_kbps * 1.5)
def test_iperf_upper_limit(self): # 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']]) self.assertTrue(0 < max_rate < limit_kbps * 1.5)
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 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)