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)
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()
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
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()
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()
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)
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)
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
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)
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())
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())
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
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
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)
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)
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)
def _create_br_name(): return random_iface_name(prefix=BRIDGE_PREFIX)
def __init__(self, prefix='vdsm-', max_length=11): self.devName = random_iface_name(prefix, max_length)
def __init__(self, prefix='vdsm-'): self.devName = random_iface_name(prefix)