示例#1
0
 def test_unplug(self, bridge=None):
     if not bridge:
         bridge = 'br-int'
     with mock.patch('manila.network.linux.ovs_lib.OVSBridge') as ovs_br:
         ovs = interface.OVSInterfaceDriver()
         ovs.unplug('tap0')
         ovs_br.assert_has_calls([mock.call(bridge),
                                  mock.call().delete_port('tap0')])
示例#2
0
    def test_plug_reset_mac(self):
        fake_mac_addr = 'aa:bb:cc:dd:ee:ff'
        self.device_exists.return_value = True

        self.ip().device().link.address = mock.Mock(return_value=fake_mac_addr)
        ovs = interface.OVSInterfaceDriver()
        ovs.plug('tap0', 'port-1234', 'ff:ee:dd:cc:bb:aa', bridge='br-int')
        expected = [
            mock.call(),
            mock.call().device('tap0'),
            mock.call().device().link.set_address('ff:ee:dd:cc:bb:aa'),
            mock.call().device().link.set_up()
        ]
        self.ip.assert_has_calls(expected)
示例#3
0
    def _test_plug(self,
                   additional_expectation=None,
                   bridge=None,
                   namespace=None):
        if additional_expectation is None:
            additional_expectation = []
        if not bridge:
            bridge = 'br-int'

        def device_exists(dev, namespace=None):
            return dev == bridge

        vsctl_cmd = [
            'ovs-vsctl', '--', '--may-exist', 'add-port', bridge, 'tap0', '--',
            'set', 'Interface', 'tap0', 'type=internal', '--', 'set',
            'Interface', 'tap0', 'external-ids:iface-id=port-1234', '--',
            'set', 'Interface', 'tap0', 'external-ids:iface-status=active',
            '--', 'set', 'Interface', 'tap0',
            'external-ids:attached-mac=aa:bb:cc:dd:ee:ff'
        ]

        with mock.patch.object(utils, 'execute') as execute:
            ovs = interface.OVSInterfaceDriver()
            self.device_exists.side_effect = device_exists
            ovs.plug('tap0',
                     'port-1234',
                     'aa:bb:cc:dd:ee:ff',
                     bridge=bridge,
                     namespace=namespace)
            execute.assert_called_once_with(*vsctl_cmd, run_as_root=True)

        expected = [
            mock.call(),
            mock.call().device('tap0'),
            mock.call().device().link.set_address('aa:bb:cc:dd:ee:ff')
        ]
        expected.extend(additional_expectation)
        if namespace:
            expected.extend([
                mock.call().ensure_namespace(namespace),
                mock.call().ensure_namespace().add_device_to_namespace(
                    mock.ANY)
            ])
        expected.extend([mock.call().device().link.set_up()])

        self.ip.assert_has_calls(expected)
示例#4
0
 def test_get_device_name(self):
     br = interface.OVSInterfaceDriver()
     device_name = br.get_device_name(FakePort)
     self.assertEqual('tapabcdef01-12', device_name)