Ejemplo n.º 1
0
 def ifup(self, iface):
     ipwrapper.linkSet(iface.name, ['up'])
     if iface.ipConfig.bootproto == 'dhcp':
         dhclient = DhcpClient(iface.name)
         rc = dhclient.start(iface.ipConfig.async)
         if not iface.ipConfig.async and rc:
             raise ConfigNetworkError(ERR_FAILED_IFUP, 'dhclient failed')
Ejemplo n.º 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 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)
Ejemplo n.º 3
0
 def _down(self):
     with monitor.Monitor(groups=('link',), timeout=2) as mon:
         linkSet(self.devName, ['down'])
         for event in mon:
             if (event.get('name') == self.devName and
                     event.get('state') == 'down'):
                 return
Ejemplo n.º 4
0
 def _down(self):
     with monitor.Monitor(groups=('link', ), timeout=2) as mon:
         linkSet(self.devName, ['down'])
         for event in mon:
             if (event.get('name') == self.devName
                     and event.get('state') == 'down'):
                 return
Ejemplo n.º 5
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 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)
Ejemplo n.º 6
0
Archivo: ifcfg.py Proyecto: mykaul/vdsm
 def removeNic(self, nic, remove_even_if_used=False):
     to_be_removed = self._ifaceDownAndCleanup(nic, remove_even_if_used)
     if to_be_removed:
         self.configApplier.removeNic(nic.name)
         if nic.name in nics.nics():
             _exec_ifup(nic.name)
         else:
             logging.warning('host interface %s missing', nic.name)
     else:
         set_mtu = self._setNewMtu(nic, vlans.vlan_devs_for_iface(nic.name))
         # Since we are not taking the device up again, ifcfg will not be
         # read at this point and we need to set the live mtu value
         if set_mtu is not None:
             ipwrapper.linkSet(nic.name, ['mtu', str(set_mtu)])
Ejemplo n.º 7
0
Archivo: api.py Proyecto: kripper/vdsm
def _disconnect_bridge_port(bridge, port):
    try:
        ipwrapper.linkSet(port, ['nomaster'])
    except ipwrapper.IPRoute2Error:
        # REQUIRED_FOR: el6
        # rhel6 ip link command does not support 'nomaster'
        rc, _, err = utils.execCmd(
            [constants.EXT_BRCTL, 'delif', bridge, port])
        if rc != 0:
            raise ConfigNetworkError(
                ne.ERR_FAILED_IFDOWN,
                'Failed to disconnect {0} from {1}. error: {2}'.format(
                    port, bridge, err
                ))
Ejemplo n.º 8
0
 def removeNic(self, nic):
     to_be_removed = self._ifaceDownAndCleanup(nic)
     if to_be_removed:
         self.configApplier.removeNic(nic.name)
         if nic.name in netinfo.nics():
             ifup(nic.name)
         else:
             logging.warning('host interface %s missing', nic.name)
     else:
         set_mtu = self._setNewMtu(nic, netinfo.vlanDevsForIface(nic.name))
         # Since we are not taking the device up again, ifcfg will not be
         # read at this point and we need to set the live mtu value
         if set_mtu is not None:
             ipwrapper.linkSet(nic.name, ['mtu', str(set_mtu)])
Ejemplo n.º 9
0
Archivo: api.py Proyecto: eprasad/vdsm
def _disconnect_bridge_port(bridge, port):
    try:
        ipwrapper.linkSet(port, ['nomaster'])
    except ipwrapper.IPRoute2Error:
        # REQUIRED_FOR: el6
        # rhel6 ip link command does not support 'nomaster'
        rc, _, err = utils.execCmd(
            [constants.EXT_BRCTL, 'delif', bridge, port])
        if rc != 0:
            raise ConfigNetworkError(
                ne.ERR_FAILED_IFDOWN,
                'Failed to disconnect {0} from {1}. error: {2}'.format(
                    port, bridge, err
                ))
Ejemplo n.º 10
0
def _set_devices_up(nets, bonds):
    devices = set()
    for net, attrs in six.iteritems(nets):
        if 'remove' not in attrs:
            if 'vlan' in attrs:
                devices.add(net)
            if 'nic' in attrs or 'bond' in attrs:
                devices.add(attrs.get('nic') or attrs.get('bond'))
    for bond, attrs in six.iteritems(bonds):
        if 'remove' not in attrs:
            devices.add(bond)
            devices.update(attrs['nics'])
    if ovs_bridge_exists(BRIDGE_NAME):
        devices.add(BRIDGE_NAME)
    for device in devices:
        linkSet(device, ['up'])
Ejemplo n.º 11
0
def _set_devices_up(nets, bonds):
    devices = set()
    for net, attrs in six.iteritems(nets):
        if 'remove' not in attrs:
            if 'vlan' in attrs:
                devices.add(net)
            if 'nic' in attrs or 'bond' in attrs:
                devices.add(attrs.get('nic') or attrs.get('bond'))
    for bond, attrs in six.iteritems(bonds):
        if 'remove' not in attrs:
            devices.add(bond)
            devices.update(attrs['nics'])
    if ovs_bridge_exists(BRIDGE_NAME):
        devices.add(BRIDGE_NAME)
    for device in devices:
        linkSet(device, ['up'])
Ejemplo n.º 12
0
def change_numvfs(pci_path, numvfs, net_name):
    """Change number of virtual functions of a device.
    The persistence is stored in the same place as other network persistence is
    stored. A call to setSafeNetworkConfig() will persist it across reboots.
    """
    # TODO: net_name is here only because it is hard to call pf_to_net_name
    # TODO: from here. once all our code will be under lib/vdsm this should be
    # TODO: removed.
    logging.info("changing number of vfs on device %s -> %s.", pci_path,
                 numvfs)
    _update_numvfs(pci_path, numvfs)

    logging.info("changing number of vfs on device %s -> %s. succeeded.",
                 pci_path, numvfs)
    _persist_numvfs(pci_path, numvfs)

    ipwrapper.linkSet(net_name, ['up'])
Ejemplo n.º 13
0
Archivo: api.py Proyecto: mykaul/vdsm
def change_numvfs(pci_path, numvfs, net_name):
    """Change number of virtual functions of a device.
    The persistence is stored in the same place as other network persistence is
    stored. A call to setSafeNetworkConfig() will persist it across reboots.
    """
    # TODO: net_name is here only because it is hard to call pf_to_net_name
    # TODO: from here. once all our code will be under lib/vdsm this should be
    # TODO: removed.
    logging.info("changing number of vfs on device %s -> %s.",
                 pci_path, numvfs)
    _update_numvfs(pci_path, numvfs)

    logging.info("changing number of vfs on device %s -> %s. succeeded.",
                 pci_path, numvfs)
    _persist_numvfs(pci_path, numvfs)

    ipwrapper.linkSet(net_name, ['up'])
Ejemplo n.º 14
0
 def removeBond(self, bonding):
     to_be_removed = self._ifaceDownAndCleanup(bonding)
     if to_be_removed:
         self.configApplier.removeBonding(bonding.name)
         if bonding.destroyOnMasterRemoval:
             for slave in bonding.slaves:
                 slave.remove()
             if self.unifiedPersistence:
                 self.runningConfig.removeBonding(bonding.name)
         else:  # Recreate the bond with ip and master info cleared
             bonding.ip = bonding.master = None
             bonding.configure()
     else:
         set_mtu = self._setNewMtu(bonding,
                                   netinfo.vlanDevsForIface(bonding.name))
         # Since we are not taking the device up again, ifcfg will not be
         # read at this point and we need to set the live mtu value.
         # Note that ip link set dev bondX mtu Y sets Y on all its links
         if set_mtu is not None:
             ipwrapper.linkSet(bonding.name, ['mtu', str(set_mtu)])
Ejemplo n.º 15
0
 def removeBond(self, bonding):
     to_be_removed = self._ifaceDownAndCleanup(bonding)
     if to_be_removed:
         self.configApplier.removeBonding(bonding.name)
         if bonding.destroyOnMasterRemoval:
             for slave in bonding.slaves:
                 slave.remove()
             if self.unifiedPersistence:
                 self.runningConfig.removeBonding(bonding.name)
         else:  # Recreate the bond with ip and master info cleared
             bonding.ip = bonding.master = None
             bonding.configure()
     else:
         set_mtu = self._setNewMtu(bonding,
                                   netinfo.vlanDevsForIface(bonding.name))
         # Since we are not taking the device up again, ifcfg will not be
         # read at this point and we need to set the live mtu value.
         # Note that ip link set dev bondX mtu Y sets Y on all its links
         if set_mtu is not None:
             ipwrapper.linkSet(bonding.name, ['mtu', str(set_mtu)])
Ejemplo n.º 16
0
def _set_ip_config(iface, ipv4, ipv6, port, blockingdhcp):
    net_dev = NetDevice(iface, iproute2, ipv4=ipv4, ipv6=ipv6,
                        blockingdhcp=blockingdhcp)
    DynamicSourceRoute.addInterfaceTracking(net_dev)
    ipwrapper.linkSet(iface, ['down'])
    if ipv4.address:
        ipwrapper.addrAdd(iface, ipv4.address, ipv4.netmask)
    if ipv4.gateway and ipv4.defaultRoute:
        ipwrapper.routeAdd(['default', 'via', ipv4.gateway])
    if ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6:
        sysctl.disable_ipv6(iface, disable=False)
    else:
        sysctl.disable_ipv6(iface)
    if ipv6.address:
        ipv6addr, ipv6netmask = ipv6.address.split('/')
        ipwrapper.addrAdd(iface, ipv6addr, ipv6netmask, family=6)
        if ipv6.gateway:
            ipwrapper.routeAdd(['default', 'via', ipv6.gateway], dev=iface,
                               family=6)
    ipwrapper.linkSet(port, ['up'])
    ipwrapper.linkSet(iface, ['up'])
    if ipv4.bootproto == 'dhcp':
        _run_dhclient(iface, blockingdhcp, ipv4.defaultRoute, 4)
    if ipv6.dhcpv6:
        _run_dhclient(iface, blockingdhcp, ipv6.defaultRoute, 6)
    iproute2._addSourceRoute(net_dev)
Ejemplo n.º 17
0
def _set_ip_config(ip_config):
    iface = ip_config.top_dev
    ipv4 = ip_config.ipv4
    ipv6 = ip_config.ipv6
    port = ip_config.port
    blocking_dhcp = ip_config.blocking_dhcp

    net_dev = NetDevice(iface, iproute2, ipv4=ipv4, ipv6=ipv6, blockingdhcp=blocking_dhcp)
    DynamicSourceRoute.addInterfaceTracking(net_dev)
    ipwrapper.linkSet(iface, ["down"])
    if ipv4.address:
        ipwrapper.addrAdd(iface, ipv4.address, ipv4.netmask)
    if ipv4.gateway and ipv4.defaultRoute:
        ipwrapper.routeAdd(["default", "via", ipv4.gateway])
    if ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6:
        sysctl.disable_ipv6(iface, disable=False)
    else:
        sysctl.disable_ipv6(iface)
    if ipv6.address:
        ipv6addr, ipv6netmask = ipv6.address.split("/")
        ipwrapper.addrAdd(iface, ipv6addr, ipv6netmask, family=6)
        if ipv6.gateway:
            ipwrapper.routeAdd(["default", "via", ipv6.gateway], dev=iface, family=6)
    ipwrapper.linkSet(port, ["up"])
    ipwrapper.linkSet(iface, ["up"])
    if ipv4.bootproto == "dhcp":
        _run_dhclient(iface, blocking_dhcp, ipv4.defaultRoute, 4)
    if ipv6.dhcpv6:
        _run_dhclient(iface, blocking_dhcp, ipv6.defaultRoute, 6)
    iproute2._addSourceRoute(net_dev)
Ejemplo n.º 18
0
def _set_network_ip_config(ip_config):
    """Set IP configuration on Vdsm controlled OVS network"""
    iface = ip_config.top_dev
    ipv4 = ip_config.ipv4
    ipv6 = ip_config.ipv6
    port = ip_config.port
    blocking_dhcp = ip_config.blocking_dhcp

    net_dev = NetDevice(iface, iproute2, ipv4=ipv4, ipv6=ipv6,
                        blockingdhcp=blocking_dhcp)
    DynamicSourceRoute.addInterfaceTracking(net_dev)
    ipwrapper.linkSet(iface, ['down'])
    if ipv4.address:
        ipwrapper.addrAdd(iface, ipv4.address, ipv4.netmask)
    if ipv4.gateway and ipv4.defaultRoute:
        ipwrapper.routeAdd(['default', 'via', ipv4.gateway])
    if ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6:
        sysctl.disable_ipv6(iface, disable=False)
    else:
        sysctl.disable_ipv6(iface)
    if ipv6.address:
        ipv6addr, ipv6netmask = ipv6.address.split('/')
        ipwrapper.addrAdd(iface, ipv6addr, ipv6netmask, family=6)
        if ipv6.gateway:
            ipwrapper.routeAdd(['default', 'via', ipv6.gateway], dev=iface,
                               family=6)
    ipwrapper.linkSet(port, ['up'])
    ipwrapper.linkSet(iface, ['up'])
    if ipv4.bootproto == 'dhcp':
        _run_dhclient(iface, blocking_dhcp, ipv4.defaultRoute, 4)
    if ipv6.dhcpv6:
        _run_dhclient(iface, blocking_dhcp, ipv6.defaultRoute, 6)
    iproute2._addSourceRoute(net_dev)
Ejemplo n.º 19
0
    def test_local_auto_with_dynamic_address_from_ra(self):
        IPV6_NETADDRESS = '2001:1:1:1'
        IPV6_NETPREFIX_LEN = '64'
        with veth_pair() as (server, client):
            with dnsmasq_run(server, ipv6_slaac_prefix=IPV6_NETADDRESS + '::'):
                with wait_for_ipv6(client):
                    ipwrapper.linkSet(client, ['up'])
                    ipwrapper.linkSet(server, ['up'])
                    ipwrapper.addrAdd(server, IPV6_NETADDRESS + '::1',
                                      IPV6_NETPREFIX_LEN, family=6)

                # Expecting link and global addresses on client iface
                # The addresses are given randomly, so we sort them
                ip_addrs = sorted(addresses.getIpAddrs()[client],
                                  key=lambda ip: ip['address'])
                self.assertEqual(2, len(ip_addrs))

                self.assertTrue(addresses.is_dynamic(ip_addrs[0]))
                self.assertEqual('global', ip_addrs[0]['scope'])
                self.assertEqual(IPV6_NETADDRESS,
                                 ip_addrs[0]['address'][:len(IPV6_NETADDRESS)])

                self.assertEqual('link', ip_addrs[1]['scope'])
Ejemplo n.º 20
0
 def removeBond(self, bonding):
     to_be_removed = self._ifaceDownAndCleanup(bonding)
     if to_be_removed:
         if bonding.destroyOnMasterRemoval:
             self.configApplier.removeBonding(bonding.name)
             for slave in bonding.slaves:
                 slave.remove()
             if self.unifiedPersistence:
                 self.runningConfig.removeBonding(bonding.name)
         else:
             self.configApplier.setBondingMtu(bonding.name,
                                              netinfo.DEFAULT_MTU)
             if bonding.bridge is not None:
                 self.configApplier._updateConfigValue(
                     netinfo.NET_CONF_PREF + bonding.name, 'BRIDGE', None)
             ifup(bonding.name)
     else:
         set_mtu = self._setNewMtu(bonding,
                                   netinfo.vlanDevsForIface(bonding.name))
         # Since we are not taking the device up again, ifcfg will not be
         # read at this point and we need to set the live mtu value.
         # Note that ip link set dev bondX mtu Y sets Y on all its links
         if set_mtu is not None:
             ipwrapper.linkSet(bonding.name, ['mtu', str(set_mtu)])
Ejemplo n.º 21
0
 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)
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
 def up(self):
     linkSet(self.devName, ['up'])
Ejemplo n.º 24
0
def _setLinkState(dummyName, state):
    try:
        linkSet(dummyName, [state])
    except IPRoute2Error:
        raise SkipTest('Failed to bring %s to state %s' % (dummyName, state))
Ejemplo n.º 25
0
def _update_bridge_ports_mtu(bridge, mtu):
    for port in netinfo.ports(bridge):
        ipwrapper.linkSet(port, ['mtu', str(mtu)])
Ejemplo n.º 26
0
 def setIfaceMtu(self, iface, mtu):
     ipwrapper.linkSet(iface, ['mtu', str(mtu)])
Ejemplo n.º 27
0
 def addIf(self, dev):
     linkSet(dev, ['master', self.devName])
Ejemplo n.º 28
0
 def ifup(self, iface):
     ipwrapper.linkSet(iface.name, ['up'])
     if iface.ipConfig.bootproto == 'dhcp':
         dhclient = DhcpClient(iface.name)
         dhclient.start(iface.ipConfig.async)
Ejemplo n.º 29
0
 def ifdown(self, iface):
     ipwrapper.linkSet(iface.name, ['down'])
     dhclient = DhcpClient(iface.name)
     dhclient.shutdown()
Ejemplo n.º 30
0
 def setIfaceMtu(self, iface, mtu):
     ipwrapper.linkSet(iface, ['mtu', str(mtu)])
Ejemplo n.º 31
0
Archivo: api.py Proyecto: nickxiao/vdsm
def _update_bridge_ports_mtu(bridge, mtu):
    for port in netinfo.ports(bridge):
        ipwrapper.linkSet(port, ["mtu", str(mtu)])
Ejemplo n.º 32
0
def _disconnect_bridge_port(port):
    ipwrapper.linkSet(port, ['nomaster'])
Ejemplo n.º 33
0
def _update_bridge_ports_mtu(bridge, mtu):
    for port in bridges.ports(bridge):
        ipwrapper.linkSet(port, ['mtu', str(mtu)])
Ejemplo n.º 34
0
 def addIf(self, dev):
     linkSet(dev, ['master', self.devName])
Ejemplo n.º 35
0
def _set_iface_mtu(iface, mtu):
    ipwrapper.linkSet(iface, ['mtu', str(mtu)])
Ejemplo n.º 36
0
 def ifdown(self, iface):
     ipwrapper.linkSet(iface.name, ['down'])
     dhclient = DhcpClient(iface.name)
     dhclient.shutdown()
Ejemplo n.º 37
0
 def ifup(self, iface):
     ipwrapper.linkSet(iface.name, ['up'])
     if iface.ipv4.bootproto == 'dhcp':
         runDhclient(iface, 4, iface.ipv4.defaultRoute)
     if iface.ipv6.dhcpv6:
         runDhclient(iface, 6, iface.ipv6.defaultRoute)
Ejemplo n.º 38
0
 def ifup(self, iface):
     ipwrapper.linkSet(iface.name, ['up'])
     if iface.ipconfig.bootproto == 'dhcp':
         runDhclient(iface)
     if iface.ipconfig.dhcpv6:
         runDhclient(iface, 6)
Ejemplo n.º 39
0
def _disconnect_bridge_port(port):
    ipwrapper.linkSet(port, ['nomaster'])
Ejemplo n.º 40
0
def _set_iface_mtu(iface, mtu):
    ipwrapper.linkSet(iface, ['mtu', str(mtu)])
Ejemplo n.º 41
0
 def ifup(self, iface):
     ipwrapper.linkSet(iface.name, ['up'])
     if iface.ipv4.bootproto == 'dhcp':
         runDhclient(iface)
     if iface.ipv6.dhcpv6:
         runDhclient(iface, 6)
Ejemplo n.º 42
0
 def up(self):
     linkSet(self.devName, ['up'])
Ejemplo n.º 43
0
 def ifup(self, iface):
     ipwrapper.linkSet(iface.name, ['up'])
     if iface.ipConfig.bootproto == 'dhcp':
         dhclient = DhcpClient(iface.name)
         rc = dhclient.start(iface.ipConfig.async)
         if not iface.ipConfig.async and rc:
Ejemplo n.º 44
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']:
                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)
Ejemplo n.º 45
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']:
                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)
Ejemplo n.º 46
0
 def ifup(self, iface):
     ipwrapper.linkSet(iface.name, ["up"])
     if iface.ipv4.bootproto == "dhcp":
         runDhclient(iface, 4, iface.ipv4.defaultRoute)
     if iface.ipv6.dhcpv6:
         runDhclient(iface, 6, iface.ipv6.defaultRoute)