Esempio n. 1
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. 2
0
def bond_device(slaves, prefix='bond', max_length=11):
    check_sysfs_bond_permission()
    name = random_iface_name(prefix, max_length)
    with linkbond.Bond(name, slaves) as bond:
        bond.create()
        yield bond.master
    bond.destroy()
Esempio n. 3
0
def bond_device(slaves, prefix='bond', max_length=11):
    check_sysfs_bond_permission()
    name = random_iface_name(prefix, max_length)
    with linkbond.Bond(name, slaves) as bond:
        bond.create()
        yield bond.master
    bond.destroy()
Esempio n. 4
0
def _has_sysfs_bond_permission():
    bond = linkbond.BondSysFS(random_iface_name('check_', max_length=11))
    try:
        bond.create()
        bond.destroy()
    except IOError:
        return False
    return True
Esempio n. 5
0
def bond_device(prefix='bond_', max_length=11):
    bond_name = random_iface_name(prefix, max_length)
    bond = Bond(bond_name)
    bond.create()
    try:
        yield bond
    finally:
        bond.destroy()
Esempio n. 6
0
def bond_device(prefix="bond_", max_length=11):
    bond_name = random_iface_name(prefix, max_length)
    bond = Bond(bond_name)
    bond.create()
    try:
        yield bond
    finally:
        bond.destroy()
Esempio n. 7
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. 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 _has_sysfs_bond_permission():
    BondSysFS = linkbond.sysfs_driver.BondSysFS
    bond = BondSysFS(random_iface_name('check_', max_length=11))
    try:
        bond.create()
        bond.destroy()
    except IOError:
        return False
    return True
Esempio n. 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)
Esempio n. 11
0
    def test_bond_create_failure_on_slave_add(self):
        with dummy_devices(2) as (nic1, nic2):
            with bond_device() as base_bond:
                base_bond.add_slaves((nic1, nic2))

                bond_name = random_iface_name('bond_', max_length=11)
                with self.assertRaises(IOError):
                    with Bond(bond_name) as broken_bond:
                        broken_bond.create()
                        broken_bond.add_slaves((nic1, nic2))
                self.assertFalse(Bond(bond_name).exists())
Esempio n. 12
0
    def test_bond_create_failure_on_slave_add(self):
        with dummy_devices(2) as (nic1, nic2):
            with bond_device() as base_bond:
                base_bond.add_slaves((nic1, nic2))

                bond_name = random_iface_name("bond_", max_length=11)
                with self.assertRaises(IOError):
                    with Bond(bond_name) as broken_bond:
                        broken_bond.create()
                        broken_bond.add_slaves((nic1, nic2))
                self.assertFalse(Bond(bond_name).exists())
Esempio n. 13
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. 14
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. 15
0
    def testGetBondingOptions(self):
        INTERVAL = '12345'
        bondName = random_iface_name()

        with open(BONDING_MASTERS, 'w') as bonds:
            bonds.write('+' + bondName)
            bonds.flush()

            try:  # no error is anticipated but let's make sure we can clean up
                self.assertEqual(
                    _getBondingOptions(bondName), {}, "This test fails when "
                    "a new bonding option is added to the kernel. Please run "
                    "`vdsm-tool dump-bonding-defaults` and retest.")

                with open(BONDING_OPT % (bondName, 'miimon'), 'w') as opt:
                    opt.write(INTERVAL)

                self.assertEqual(_getBondingOptions(bondName),
                                 {'miimon': INTERVAL})

            finally:
                bonds.write('-' + bondName)
Esempio n. 16
0
    def testGetBondingOptions(self):
        INTERVAL = '12345'
        bondName = random_iface_name()

        with open(netinfo.BONDING_MASTERS, 'w') as bonds:
            bonds.write('+' + bondName)
            bonds.flush()

            try:  # no error is anticipated but let's make sure we can clean up
                self.assertEqual(
                    netinfo._getBondingOptions(bondName), {}, "This test fails"
                    " when a new bonding option is added to the kernel. Please"
                    " run vdsm-tool dump-bonding-defaults` and retest.")

                with open(netinfo.BONDING_OPT % (bondName, 'miimon'),
                          'w') as opt:
                    opt.write(INTERVAL)

                self.assertEqual(netinfo._getBondingOptions(bondName),
                                 {'miimon': INTERVAL})

            finally:
                bonds.write('-' + bondName)
Esempio n. 17
0
    def test_get_bonding_options(self):
        INTERVAL = '12345'
        bondName = random_iface_name()

        with open(bonding.BONDING_MASTERS, 'w') as bonds:
            bonds.write('+' + bondName)
            bonds.flush()

            try:  # no error is anticipated but let's make sure we can clean up
                self.assertEqual(
                    self._bond_opts_without_mode(bondName), {},
                    'This test fails when a new bonding option is added to '
                    'the kernel. Please run vdsm-tool dump-bonding-options` '
                    'and retest.')

                with open(bonding.BONDING_OPT % (bondName, 'miimon'),
                          'w') as opt:
                    opt.write(INTERVAL)

                self.assertEqual(self._bond_opts_without_mode(bondName),
                                 {'miimon': INTERVAL})

            finally:
                bonds.write('-' + bondName)
Esempio n. 18
0
    def test_get_bonding_options(self):
        INTERVAL = '12345'
        bondName = random_iface_name()

        with open(bonding.BONDING_MASTERS, 'w') as bonds:
            bonds.write('+' + bondName)
            bonds.flush()

            try:  # no error is anticipated but let's make sure we can clean up
                self.assertEqual(
                    self._bond_opts_without_mode(bondName), {},
                    'This test fails when a new bonding option is added to '
                    'the kernel. Please run vdsm-tool dump-bonding-options` '
                    'and retest.')

                with open(bonding.BONDING_OPT % (bondName, 'miimon'),
                          'w') as opt:
                    opt.write(INTERVAL)

                self.assertEqual(self._bond_opts_without_mode(bondName),
                                 {'miimon': INTERVAL})

            finally:
                bonds.write('-' + bondName)
Esempio n. 19
0
 def _create_br_name():
     return random_iface_name(prefix=BRIDGE_PREFIX)
Esempio n. 20
0
 def _create_br_name():
     return random_iface_name(prefix=BRIDGE_PREFIX)
Esempio n. 21
0
 def __init__(self, prefix='vdsm-', max_length=11):
     self.devName = random_iface_name(prefix, max_length)
Esempio n. 22
0
 def __init__(self, prefix='vdsm-'):
     self.devName = random_iface_name(prefix)
Esempio n. 23
0
 def __init__(self, prefix='vdsm-'):
     self.devName = random_iface_name(prefix)
Esempio n. 24
0
 def __init__(self, prefix='vdsm-', max_length=11):
     self.devName = random_iface_name(prefix, max_length)