Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 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
Esempio n. 5
0
File: dummy.py Progetto: Caez83/vdsm
def create(prefix='dummy_', max_length=11):
    """
    Create a dummy interface with a pseudo-random suffix, e.g. dummy_ilXaYiSn7.
    Limit the name to 11 characters to make room for VLAN IDs.
    This assumes root privileges.
    """
    dummy_name = random_iface_name(prefix, max_length)
    try:
        linkAdd(dummy_name, linkType='dummy')
    except IPRoute2Error as e:
        raise SkipTest('Failed to load a dummy interface %s: %s' %
                       (dummy_name, e))
    else:
        return dummy_name
Esempio n. 6
0
def create(prefix='dummy_', max_length=11):
    """
    Create a dummy interface with a pseudo-random suffix, e.g. dummy_ilXaYiSn7.
    Limit the name to 11 characters to make room for VLAN IDs.
    This assumes root privileges.
    """
    dummy_name = random_iface_name(prefix, max_length)
    try:
        linkAdd(dummy_name, linkType='dummy')
    except IPRoute2Error as e:
        raise SkipTest('Failed to create a dummy interface %s: %s' %
                       (dummy_name, e))
    else:
        return dummy_name
Esempio n. 7
0
def create(prefix='veth_', max_length=15):
    """
    Create a veth interface with a pseudo-random suffix (e.g. veth_m6Lz7uMK9c)
    for both endpoints. Use the longest possible name length by default.
    This assumes root privileges.
    """
    leftPoint = random_iface_name(prefix, max_length)
    rightPoint = random_iface_name(prefix, max_length)
    try:
        linkAdd(leftPoint, linkType='veth', args=('peer', 'name', rightPoint))
    except IPRoute2Error:
        raise SkipTest('Failed to create a veth interface')
    else:
        return (leftPoint, rightPoint)
Esempio n. 8
0
def 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))
        yield left_side, right_side
    except IPRoute2Error:
        raise SkipTest("Failed to create a veth pair.")
    finally:
        # the peer device is removed by the kernel
        dummy.remove(left_side)
Esempio n. 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))
        yield left_side, right_side
    except IPRoute2Error:
        raise SkipTest('Failed to create a veth pair.')
    finally:
        # the peer device is removed by the kernel
        linkDel(left_side)
Esempio n. 10
0
def create(prefix='dummy_'):
    """
    Creates a dummy interface, in a fixed number of attempts (100).
    The dummy interface created has a pseudo-random name (e.g. dummy_85
    in the format dummy_Number). Assumes root privileges.
    """

    for i in random.sample(range(100), 100):
        dummy_name = '%s%s' % (prefix, i)
        try:
            linkAdd(dummy_name, linkType='dummy')
        except IPRoute2Error:
            pass
        else:
            return dummy_name

    raise SkipTest('Failed to load a dummy interface')
Esempio n. 11
0
def create(prefix='veth_'):
    """
    Creates a veth interface with a pseudo-random name for both endpoints (e.g.
    veth_85 and veth_31 in the format veth_Number). Assumes root privileges.
    """

    deviceNumbers = random.sample(range(100), 2)
    leftPoint = '%s%s' % (prefix, deviceNumbers[0])
    rightPoint = '%s%s' % (prefix, deviceNumbers[1])
    try:
        linkAdd(leftPoint, linkType='veth', args=('peer', 'name', rightPoint))
    except IPRoute2Error:
        pass
    else:
        return (leftPoint, rightPoint)

    raise SkipTest('Failed to create a veth interface')
Esempio 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)
Esempio n. 13
0
 def addVlan(self, vlan):
     ipwrapper.linkAdd(name=vlan.name, linkType='vlan',
                       link=vlan.device.name, args=['id', str(vlan.tag)])
Esempio n. 14
0
 def addVlan(self, vlan):
     ipwrapper.linkAdd(name=vlan.name,
                       linkType='vlan',
                       link=vlan.device.name,
                       args=['id', str(vlan.tag)])
Esempio n. 15
0
 def addDevice(self):
     linkAdd(self.devName, 'bridge')
     self.up()
Esempio n. 16
0
 def addDevice(self):
     linkAdd(self.devName, 'vlan', link=self.backing_device_name,
             args=['id', str(self.tag)])
     self.up()
Esempio n. 17
0
 def addDevice(self):
     linkAdd(self.devName,
             'vlan',
             link=self.backing_device_name,
             args=['id', str(self.tag)])
     self.up()
Esempio n. 18
0
 def addDevice(self):
     linkAdd(self.devName, 'bridge')
     self.up()
Esempio n. 19
0
 def addVlan(self, vlan):
     ipwrapper.linkAdd(name=vlan.name, linkType="vlan", link=vlan.device.name, args=["id", str(vlan.tag)])