Best Python code snippet using avocado_python
test_interface.py
Source:test_interface.py  
...95        if additional_expectation is None:96            additional_expectation = []97        if not bridge:98            bridge = 'br-int'99        def device_exists(dev, namespace=None):100            return dev == bridge101        vsctl_cmd = ['ovs-vsctl', '--', '--may-exist', 'add-port',102                     bridge, 'tap0', '--', 'set', 'Interface', 'tap0',103                     'type=internal', '--', 'set', 'Interface', 'tap0',104                     'external-ids:iface-id=port-1234', '--', 'set',105                     'Interface', 'tap0',106                     'external-ids:iface-status=active', '--', 'set',107                     'Interface', 'tap0',108                     'external-ids:attached-mac=aa:bb:cc:dd:ee:ff']109        with mock.patch.object(utils, 'execute') as execute:110            ovs = interface.OVSInterfaceDriver()111            self.device_exists.side_effect = device_exists112            ovs.plug('tap0',113                     'port-1234',114                     'aa:bb:cc:dd:ee:ff',115                     bridge=bridge,116                     namespace=namespace)117            execute.assert_called_once_with(*vsctl_cmd, run_as_root=True)118        expected = [mock.call(),119                    mock.call().device('tap0'),120                    mock.call().device().link.set_address('aa:bb:cc:dd:ee:ff')]121        expected.extend(additional_expectation)122        if namespace:123            expected.extend(124                [mock.call().ensure_namespace(namespace),125                 mock.call().ensure_namespace().add_device_to_namespace(126                     mock.ANY)])127        expected.extend([mock.call().device().link.set_up()])128        self.ip.assert_has_calls(expected)129    def test_unplug(self, bridge=None):130        if not bridge:131            bridge = 'br-int'132        with mock.patch('manila.network.linux.ovs_lib.OVSBridge') as ovs_br:133            ovs = interface.OVSInterfaceDriver()134            ovs.unplug('tap0')135            ovs_br.assert_has_calls([mock.call(bridge),136                                     mock.call().delete_port('tap0')])137class TestBridgeInterfaceDriver(TestBase):138    def test_get_device_name(self):139        br = interface.BridgeInterfaceDriver()140        device_name = br.get_device_name(FakePort)141        self.assertEqual('ns-abcdef01-12', device_name)142    def test_plug_no_ns(self):143        self._test_plug()144    def test_plug_with_ns(self):145        self._test_plug(namespace='01234567-1234-1234-99')146    def _test_plug(self, namespace=None, mtu=None):147        def device_exists(device, root_helper=None, namespace=None):148            return device.startswith('brq')149        root_veth = mock.Mock()150        ns_veth = mock.Mock()151        self.ip().add_veth = mock.Mock(return_value=(root_veth, ns_veth))152        self.device_exists.side_effect = device_exists153        br = interface.BridgeInterfaceDriver()154        mac_address = 'aa:bb:cc:dd:ee:ff'155        br.plug('ns-0',156                'port-1234',157                mac_address,158                namespace=namespace)159        ip_calls = [mock.call(),160                    mock.call().add_veth('tap0', 'ns-0', namespace2=namespace)]161        ns_veth.assert_has_calls([mock.call.link.set_address(mac_address)])...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
