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])
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))
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
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])
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])
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)
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 delDevice(self): self._down() linkDel(self.devName) cmd.exec_sync(['nmcli', 'con', 'del', self.devName])
def removeVlan(self, vlan): ipwrapper.linkDel(vlan.name)
def delDevice(self): self._down() linkDel(self.devName)
def faultyGetLinks(): all_links = list(original_getLinks()) ipwrapper.linkDel(self.NEW_VLAN) return iter(all_links)
def test_missing_bridge_removal_fails(self): with self.assertRaises(ipwrapper.IPRoute2NoDeviceError): ipwrapper.linkDel('missing_bridge')
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, ))
def delDevice(self): self._down() linkDel(self.devName) if nmstate.is_nmstate_backend(): cmd.exec_sync(['nmcli', 'con', 'del', self.devName])
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,))
def _create_bridge(name): linkAdd(name, 'bridge') try: yield finally: linkDel(name)
def remove(self): linkDel(self.dev_name) cmd.exec_sync(['nmcli', 'con', 'del', self.dev_name])