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 addDevice(self): linkAdd( self.devName, 'vlan', link=self.backing_device_name, args=['id', str(self.tag)], ) self.up()
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
def create(self): linkAdd( self.dev_name, 'vlan', link=self.backing_device_name, args=['id', str(self.tag)], ) self.up() self.set_managed()
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()
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
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
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 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
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 addVlan(self, vlan): ipwrapper.linkAdd(name=vlan.name, linkType='vlan', link=vlan.device.name, args=['id', str(vlan.tag)])
def addDevice(self): linkAdd(self.devName, 'bridge') self.up()
def create(self): linkAdd(self.dev_name, 'bond') self.set_managed() self.up()
def addDevice(self): linkAdd(self.devName, 'vlan', link=self.backing_device_name, args=['id', str(self.tag)]) self.up()
def _create_bridge(name): linkAdd(name, 'bridge') try: yield finally: linkDel(name)