Пример #1
0
    def test_unplug_device_cannot_determine_bridge_port(self):
        device = mock.Mock()
        device.name = 'tap1'
        device.link.delete.side_effect = RuntimeError

        with mock.patch(
                'neutron.agent.common.ovs_lib.OVSBridge') as ovs_br_cls:
            br_patch = mock.patch(
                'neutron.agent.common.ovs_lib.BaseOVS.get_bridge_for_iface')
            with br_patch as mock_get_bridge_for_iface:
                with mock.patch.object(util.LOG, 'debug') as debug:
                    mock_get_bridge_for_iface.return_value = None
                    ovs_bridge = mock.Mock()
                    ovs_br_cls.return_value = ovs_bridge

                    util.unplug_device(device)

                    mock_get_bridge_for_iface.assert_called_once_with('tap1')
                    self.assertEqual([], ovs_br_cls.mock_calls)
                    self.assertTrue(debug.called)
Пример #2
0
    def test_unplug_device_ovs_port(self):
        device = mock.Mock()
        device.name = 'tap1'
        device.link.delete.side_effect = RuntimeError

        with mock.patch(
                'neutron.agent.common.ovs_lib.OVSBridge') as ovs_br_cls:
            br_patch = mock.patch(
                'neutron.agent.common.ovs_lib.BaseOVS.get_bridge_for_iface')
            with br_patch as mock_get_bridge_for_iface:
                mock_get_bridge_for_iface.return_value = 'br-int'
                ovs_bridge = mock.Mock()
                ovs_br_cls.return_value = ovs_bridge

                util.unplug_device(device)

                mock_get_bridge_for_iface.assert_called_once_with('tap1')
                ovs_br_cls.assert_called_once_with('br-int')
                ovs_bridge.assert_has_calls(
                    [mock.call.delete_port(device.name)])
Пример #3
0
    def test_unplug_device_ovs_port(self):
        conf = mock.Mock()
        conf.ovs_integration_bridge = "br-int"

        device = mock.Mock()
        device.name = "tap1"
        device.link.delete.side_effect = RuntimeError

        with mock.patch("neutron.agent.common.ovs_lib.OVSBridge") as ovs_br_cls:
            br_patch = mock.patch("neutron.agent.common.ovs_lib.BaseOVS.get_bridge_for_iface")
            with br_patch as mock_get_bridge_for_iface:
                mock_get_bridge_for_iface.return_value = "br-int"
                ovs_bridge = mock.Mock()
                ovs_br_cls.return_value = ovs_bridge

                util.unplug_device(conf, device)

                mock_get_bridge_for_iface.assert_called_once_with("tap1")
                ovs_br_cls.assert_called_once_with("br-int")
                ovs_bridge.assert_has_calls([mock.call.delete_port(device.name)])
Пример #4
0
    def test_unplug_device_cannot_determine_bridge_port(self):
        conf = mock.Mock()
        conf.ovs_integration_bridge = "br-int"

        device = mock.Mock()
        device.name = "tap1"
        device.link.delete.side_effect = RuntimeError

        with mock.patch("neutron.agent.common.ovs_lib.OVSBridge") as ovs_br_cls:
            br_patch = mock.patch("neutron.agent.common.ovs_lib.BaseOVS.get_bridge_for_iface")
            with br_patch as mock_get_bridge_for_iface:
                with mock.patch.object(util.LOG, "debug") as debug:
                    mock_get_bridge_for_iface.return_value = None
                    ovs_bridge = mock.Mock()
                    ovs_br_cls.return_value = ovs_bridge

                    util.unplug_device(conf, device)

                    mock_get_bridge_for_iface.assert_called_once_with("tap1")
                    self.assertEqual([], ovs_br_cls.mock_calls)
                    self.assertTrue(debug.called)
Пример #5
0
    def test_unplug_device_regular_device(self):
        conf = mock.Mock()
        device = mock.Mock()

        util.unplug_device(conf, device)
        device.assert_has_calls([mock.call.link.delete()])
Пример #6
0
    def test_unplug_device_regular_device(self):
        conf = mock.Mock()
        device = mock.Mock()

        util.unplug_device(conf, device)
        device.assert_has_calls([mock.call.link.delete()])