Beispiel #1
0
def veth_pair(prefix='veth_', max_length=15):
    """
    Yield a pair of veth devices. This assumes root privileges (currently
    required by all tests anyway).

    Both sides of the pair have a pseudo-random suffix (e.g. veth_m6Lz7uMK9c).
    """
    left_side = random_iface_name(prefix, max_length)
    right_side = random_iface_name(prefix, max_length)
    try:
        linkAdd(left_side, linkType='veth', args=('peer', 'name', right_side))
        if nmstate.is_nmstate_backend():
            cmd.exec_sync(['nmcli', 'dev', 'set', left_side, 'managed', 'yes'])
            cmd.exec_sync(
                ['nmcli', 'dev', 'set', right_side, 'managed', 'yes'])
    except IPRoute2Error as e:
        pytest.skip('Failed to create a veth pair: %s', e)
    try:
        yield left_side, right_side
    finally:
        # the peer device is removed by the kernel
        linkDel(left_side)
        if nmstate.is_nmstate_backend():
            cmd.exec_sync(['nmcli', 'con', 'del', left_side])
            cmd.exec_sync(['nmcli', 'con', 'del', right_side])
Beispiel #2
0
 def remove(self):
     """
     Remove the dummy interface. This assumes root privileges.
     """
     try:
         linkDel(self.devName)
     except IPRoute2Error as e:
         raise SkipTest("Unable to delete the dummy interface %s: %s" %
                        (self.devName, e))
Beispiel #3
0
 def remove(self):
     """
     Remove the dummy interface. This assumes root privileges.
     """
     try:
         linkDel(self.devName)
     except IPRoute2Error as e:
         raise SkipTest("Unable to delete the dummy interface %s: %s" %
                        (self.devName, e))
Beispiel #4
0
def vlan(name, link, vlan_id):
    ipwrapper.linkAdd(name, 'vlan', link=link, args=['id', str(vlan_id)])
    try:
        yield
    finally:
        try:
            ipwrapper.linkDel(name)
        except ipwrapper.IPRoute2Error:
            # faultyGetLinks is expected to have already removed the vlan
            # device.
            pass
Beispiel #5
0
def vlan(name, link, vlan_id):
    ipwrapper.linkAdd(name, 'vlan', link=link, args=['id', str(vlan_id)])
    try:
        yield
    finally:
        try:
            ipwrapper.linkDel(name)
        except ipwrapper.IPRoute2Error:
            # faultyGetLinks is expected to have already removed the vlan
            # device.
            pass
Beispiel #6
0
 def remove(self):
     """
     Remove the dummy interface. This assumes root privileges.
     """
     try:
         linkDel(self.devName)
     except IPRoute2Error as e:
         pytest.skip("Unable to delete the dummy interface %s: %s" %
                     (self.devName, e))
     finally:
         cmd.exec_sync(['nmcli', 'con', 'del', self.devName])
Beispiel #7
0
 def remove(self):
     """
     Remove the dummy interface. This assumes root privileges.
     """
     try:
         linkDel(self.devName)
     except IPRoute2Error as e:
         raise SkipTest("Unable to delete the dummy interface %s: %s" %
                        (self.devName, e))
     finally:
         if nmstate.is_nmstate_backend():
             cmd.exec_sync(['nmcli', 'con', 'del', self.devName])
Beispiel #8
0
    def test_replace_broken_network(self, bridged):
        with dummy_device() as nic:
            NETCREATE = {NETWORK_NAME: {'nic': nic, 'vlan': VLANID,
                                        'bridged': bridged}}
            with adapter.setupNetworks(NETCREATE, {}, NOCHK):
                if bridged:
                    ipwrapper.linkDel(NETWORK_NAME)
                else:
                    ipwrapper.linkDel(
                        nic + '.' + str(NETCREATE[NETWORK_NAME]['vlan']))

                adapter.refresh_netinfo()

                adapter.assertNoNetworkExists(NETWORK_NAME)
                with adapter.setupNetworks(NETCREATE, {}, NOCHK):
                    adapter.assertNetworkExists(NETWORK_NAME)
Beispiel #9
0
def veth_pair(prefix='veth_', max_length=15):
    """
    Yield a pair of veth devices. This assumes root privileges (currently
    required by all tests anyway).

    Both sides of the pair have a pseudo-random suffix (e.g. veth_m6Lz7uMK9c).
    """
    left_side = random_iface_name(prefix, max_length)
    right_side = random_iface_name(prefix, max_length)
    try:
        linkAdd(left_side, linkType='veth', args=('peer', 'name', right_side))
    except IPRoute2Error as e:
        raise SkipTest('Failed to create a veth pair: %s', e)
    try:
        yield left_side, right_side
    finally:
        # the peer device is removed by the kernel
        linkDel(left_side)
Beispiel #10
0
def veth_pair(prefix='veth_', max_length=15):
    """
    Yield a pair of veth devices. This assumes root privileges (currently
    required by all tests anyway).

    Both sides of the pair have a pseudo-random suffix (e.g. veth_m6Lz7uMK9c).
    """
    left_side = random_iface_name(prefix, max_length)
    right_side = random_iface_name(prefix, max_length)
    try:
        linkAdd(left_side, linkType='veth',
                args=('peer', 'name', right_side))
    except IPRoute2Error as e:
        raise SkipTest('Failed to create a veth pair: %s', e)
    try:
        yield left_side, right_side
    finally:
        # the peer device is removed by the kernel
        linkDel(left_side)
Beispiel #11
0
 def delDevice(self):
     self._down()
     linkDel(self.devName)
     cmd.exec_sync(['nmcli', 'con', 'del', self.devName])
Beispiel #12
0
 def removeVlan(self, vlan):
     ipwrapper.linkDel(vlan.name)
Beispiel #13
0
 def delDevice(self):
     self._down()
     linkDel(self.devName)
Beispiel #14
0
 def faultyGetLinks():
     all_links = list(original_getLinks())
     ipwrapper.linkDel(self.NEW_VLAN)
     return iter(all_links)
Beispiel #15
0
 def test_missing_bridge_removal_fails(self):
     with self.assertRaises(ipwrapper.IPRoute2NoDeviceError):
         ipwrapper.linkDel('missing_bridge')
Beispiel #16
0
 def faultyGetLinks():
     all_links = list(original_getLinks())
     ipwrapper.linkDel(self.NEW_VLAN)
     return iter(all_links)
Beispiel #17
0
 def test_missing_bridge_removal_fails(self):
     with self.assertRaises(ipwrapper.IPRoute2NoDeviceError):
         ipwrapper.linkDel('missing_bridge')
Beispiel #18
0
def _remove_device(device_name):
    try:
        ipwrapper.linkDel(device_name)
    except ipwrapper.IPRoute2NoDeviceError:
        logging.debug('Failed to remove device %s, '
                      'it does not exist' % (device_name, ))
Beispiel #19
0
 def delDevice(self):
     self._down()
     linkDel(self.devName)
     if nmstate.is_nmstate_backend():
         cmd.exec_sync(['nmcli', 'con', 'del', self.devName])
Beispiel #20
0
def _remove_device(device_name):
    try:
        ipwrapper.linkDel(device_name)
    except ipwrapper.IPRoute2NoDeviceError:
        logging.debug('Failed to remove device %s, '
                      'it does not exist' % (device_name,))
Beispiel #21
0
 def delDevice(self):
     self._down()
     linkDel(self.devName)
Beispiel #22
0
def _create_bridge(name):
    linkAdd(name, 'bridge')
    try:
        yield
    finally:
        linkDel(name)
Beispiel #23
0
 def remove(self):
     linkDel(self.dev_name)
     cmd.exec_sync(['nmcli', 'con', 'del', self.dev_name])