def _test_plug(self, namespace=None):
        def device_exists(device, root_helper=None, namespace=None):
            return device.startswith('brq')

        root_veth = mock.Mock()
        ns_veth = mock.Mock()

        self.ip().add_veth = mock.Mock(return_value=(root_veth, ns_veth))

        expected = [
            mock.call(c, 'sudo') for c in [[
                'ip', 'tuntap', 'add', 'tap0', 'mode', 'tap'
            ], ['ip', 'link', 'set', 'tap0', 'address', 'aa:bb:cc:dd:ee:ff'],
                                           ['ip', 'link', 'set', 'tap0', 'up']]
        ]

        self.device_exists.side_effect = device_exists
        br = interface.BridgeInterfaceDriver(self.conf)
        br.plug('01234567-1234-1234-99',
                'port-1234',
                'ns-0',
                'aa:bb:cc:dd:ee:ff',
                namespace=namespace)

        ip_calls = [mock.call('sudo'), mock.call().add_veth('tap0', 'ns-0')]
        if namespace:
            ip_calls.extend([
                mock.call().ensure_namespace('01234567-1234-1234-99'),
                mock.call().ensure_namespace().add_device_to_namespace(ns_veth)
            ])

        self.ip.assert_has_calls(ip_calls)

        root_veth.assert_has_calls([mock.call.link.set_up()])
        ns_veth.assert_has_calls([mock.call.link.set_up()])
示例#2
0
    def _test_plug(self, namespace=None, mtu=None):
        def device_exists(device, root_helper=None, namespace=None):
            return device.startswith('brq')

        root_veth = mock.Mock()
        ns_veth = mock.Mock()

        self.ip().add_veth = mock.Mock(return_value=(root_veth, ns_veth))

        self.device_exists.side_effect = device_exists
        br = interface.BridgeInterfaceDriver(self.conf)
        mac_address = 'aa:bb:cc:dd:ee:ff'
        br.plug('01234567-1234-1234-99',
                'port-1234',
                'ns-0',
                mac_address,
                namespace=namespace)

        ip_calls = [
            mock.call('sudo'),
            mock.call().add_veth('tap0', 'ns-0', namespace2=namespace)
        ]
        ns_veth.assert_has_calls([mock.call.link.set_address(mac_address)])
        if mtu:
            ns_veth.assert_has_calls([mock.call.link.set_mtu(mtu)])
            root_veth.assert_has_calls([mock.call.link.set_mtu(mtu)])

        self.ip.assert_has_calls(ip_calls)

        root_veth.assert_has_calls([mock.call.link.set_up()])
        ns_veth.assert_has_calls([mock.call.link.set_up()])
 def test_unplug_no_device(self):
     self.device_exists.return_value = False
     self.ip_dev().link.delete.side_effect = RuntimeError
     with mock.patch('quantum.agent.linux.interface.LOG') as log:
         br = interface.BridgeInterfaceDriver(self.conf)
         br.unplug('tap0')
         [mock.call(), mock.call('tap0', 'sudo'), mock.call().link.delete()]
         self.assertEqual(log.error.call_count, 1)
 def test_unplug(self):
     self.device_exists.return_value = True
     with mock.patch('quantum.agent.linux.interface.LOG.debug') as log:
         br = interface.BridgeInterfaceDriver(self.conf)
         br.unplug('tap0')
         log.assert_called_once()
     self.execute.assert_has_calls(
         [mock.call(['ip', 'link', 'delete', 'tap0'], 'sudo')])
 def test_plug_dev_exists(self):
     self.device_exists.return_value = True
     with mock.patch('quantum.agent.linux.interface.LOG.warn') as log:
         br = interface.BridgeInterfaceDriver(self.conf)
         br.plug('01234567-1234-1234-99', 'port-1234', 'tap0',
                 'aa:bb:cc:dd:ee:ff')
         self.ip_dev.assert_has_calls([])
         self.assertEquals(log.call_count, 1)
示例#6
0
    def test_unplug(self):
        self.device_exists.return_value = True
        with mock.patch('quantum.agent.linux.interface.LOG.debug') as log:
            br = interface.BridgeInterfaceDriver(self.conf)
            br.unplug('tap0')
            log.assert_called_once()

        self.ip_dev.assert_has_calls([mock.call('tap0', 'sudo', None),
                                      mock.call().link.delete()])
 def test_get_device_name(self):
     br = interface.BridgeInterfaceDriver(self.conf)
     device_name = br.get_device_name(FakePort())
     self.assertEqual('ns-abcdef01-12', device_name)