예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)