Exemplo n.º 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])
Exemplo n.º 2
0
 def addDevice(self):
     linkAdd(
         self.devName,
         'vlan',
         link=self.backing_device_name,
         args=['id', str(self.tag)],
     )
     self.up()
Exemplo n.º 3
0
 def create(self):
     try:
         linkAdd(self.devName, linkType='dummy')
     except IPRoute2Error as e:
         raise SkipTest('Failed to create a dummy interface %s: %s' %
                        (self.devName, e))
     else:
         return self.devName
Exemplo n.º 4
0
 def create(self):
     try:
         linkAdd(self.devName, linkType='dummy')
     except IPRoute2Error as e:
         raise SkipTest('Failed to create a dummy interface %s: %s' %
                        (self.devName, e))
     else:
         return self.devName
Exemplo n.º 5
0
 def create(self):
     linkAdd(
         self.dev_name,
         'vlan',
         link=self.backing_device_name,
         args=['id', str(self.tag)],
     )
     self.up()
     self.set_managed()
Exemplo n.º 6
0
 def create(self):
     linkAdd(
         self.left_side.dev_name,
         linkType='veth',
         args=('peer', 'name', self.right_side.dev_name),
     )
     self.left_side.set_managed()
     self.right_side.set_managed()
     self.left_side.up()
     self.right_side.up()
Exemplo n.º 7
0
 def create(self):
     try:
         linkAdd(self.dev_name, linkType='dummy')
         self.set_managed()
         self.up()
     except IPRoute2Error as e:
         pytest.skip(
             f'Failed to create a dummy interface {self.dev_name}: {e}')
     else:
         return self.dev_name
Exemplo n.º 8
0
 def create(self):
     try:
         linkAdd(self.devName, linkType='dummy')
         cmd.exec_sync(
             ['nmcli', 'dev', 'set', self.devName, 'managed', 'yes'])
     except IPRoute2Error as e:
         pytest.skip('Failed to create a dummy interface %s: %s' %
                     (self.devName, e))
     else:
         return self.devName
Exemplo n.º 9
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
Exemplo n.º 10
0
 def create(self):
     try:
         linkAdd(self.devName, linkType='dummy')
         if nmstate.is_nmstate_backend():
             cmd.exec_sync(
                 ['nmcli', 'dev', 'set', self.devName, 'managed', 'yes'])
     except IPRoute2Error as e:
         raise SkipTest('Failed to create a dummy interface %s: %s' %
                        (self.devName, e))
     else:
         return self.devName
Exemplo n.º 11
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
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
0
 def addVlan(self, vlan):
     ipwrapper.linkAdd(name=vlan.name, linkType='vlan',
                       link=vlan.device.name, args=['id', str(vlan.tag)])
Exemplo n.º 15
0
 def addDevice(self):
     linkAdd(self.devName, 'bridge')
     self.up()
Exemplo n.º 16
0
 def create(self):
     linkAdd(self.dev_name, 'bond')
     self.set_managed()
     self.up()
Exemplo n.º 17
0
 def addDevice(self):
     linkAdd(self.devName, 'vlan', link=self.backing_device_name,
             args=['id', str(self.tag)])
     self.up()
Exemplo n.º 18
0
def _create_bridge(name):
    linkAdd(name, 'bridge')
    try:
        yield
    finally:
        linkDel(name)
Exemplo n.º 19
0
 def addDevice(self):
     linkAdd(self.devName, 'bridge')
     self.up()