From 7422aef799dd3f03bf01d40a60fb9a3c5abc8432 Mon Sep 17 00:00:00 2001 From: "yanjun.fu" Date: Thu, 4 May 2017 16:41:25 +0800 Subject: [PATCH] Fix tap device disappear after node restart When use driver_handles_share_servers driver, the tap device will down and the tap device mac address is changed after restart the node, that will caused manila can not manage share that created by this service. This path fix this issue. When restart manila-share service, call setup_connectivity_with_service_instances() to create host port and check the the mac address. Change-Id: Ibcdd4f58f15a53c69d35db06bc42283859349758 Closes-Bug:#1688155 --- manila/network/linux/interface.py | 3 +++ manila/share/manager.py | 4 ++++ manila/tests/fake_driver.py | 6 ++++++ manila/tests/fake_service_instance.py | 15 +++++++++++++++ manila/tests/network/linux/test_interface.py | 16 ++++++++++++++++ ...vice_after_node_restart-0690a6beca077b95.yaml | 5 +++++ 6 files changed, 49 insertions(+) create mode 100644 releasenotes/notes/reset_tap_device_after_node_restart-0690a6beca077b95.yaml diff --git a/manila/network/linux/interface.py b/manila/network/linux/interface.py index a02a5914aa..b5a7f8012c 100644 --- a/manila/network/linux/interface.py +++ b/manila/network/linux/interface.py @@ -155,6 +155,9 @@ class OVSInterfaceDriver(LinuxInterfaceDriver): else: LOG.warning("Device %s already exists.", device_name) + if ns_dev.link.address != mac_address: + LOG.warning("Reset mac address to %s", mac_address) + ns_dev.link.set_address(mac_address) ns_dev.link.set_up() @device_name_synchronized diff --git a/manila/share/manager.py b/manila/share/manager.py index d8ab2719b9..57d1eaaecc 100644 --- a/manila/share/manager.py +++ b/manila/share/manager.py @@ -312,6 +312,10 @@ class ShareManager(manager.SchedulerDependentManager): self.driver.initialized = True _driver_setup() + if (self.driver.driver_handles_share_servers and + hasattr(self.driver, 'service_instance_manager')): + (self.driver.service_instance_manager.network_helper. + setup_connectivity_with_service_instances()) self.ensure_driver_resources(ctxt) diff --git a/manila/tests/fake_driver.py b/manila/tests/fake_driver.py index 177bc9fef9..70af04ea84 100644 --- a/manila/tests/fake_driver.py +++ b/manila/tests/fake_driver.py @@ -17,6 +17,7 @@ from oslo_log import log import six from manila.share import driver +from manila.tests import fake_service_instance LOG = log.getLogger(__name__) @@ -39,8 +40,13 @@ class FakeShareDriver(driver.ShareDriver): """ def __init__(self, *args, **kwargs): + self._setup_service_instance_manager() super(FakeShareDriver, self).__init__([True, False], *args, **kwargs) + def _setup_service_instance_manager(self): + self.service_instance_manager = ( + fake_service_instance.FakeServiceInstanceManager()) + def manage_existing(self, share, driver_options): LOG.debug("Fake share driver: manage") LOG.debug("Fake share driver: driver options: %s", diff --git a/manila/tests/fake_service_instance.py b/manila/tests/fake_service_instance.py index e3475258cd..be6ffe078e 100644 --- a/manila/tests/fake_service_instance.py +++ b/manila/tests/fake_service_instance.py @@ -29,10 +29,19 @@ class FakeServiceInstanceManager(object): self.share_networks_servers = {} self.fake_server = fake_compute.FakeServer() self.service_instance_name_template = 'manila_fake_service_instance-%s' + self._network_helper = None def get_service_instance(self, context, share_network_id, create=True): return self.fake_server + @property + def network_helper(self): + return self._get_network_helper() + + def _get_network_helper(self): + self._network_helper = FakeNeutronNetworkHelper() + return self._network_helper + def _create_service_instance(self, context, instance_name, share_network_id, old_server_ip): return self.fake_server @@ -42,3 +51,9 @@ class FakeServiceInstanceManager(object): def _get_service_instance_name(self, share_network_id): return self.service_instance_name_template % share_network_id + + +class FakeNeutronNetworkHelper(object): + + def setup_connectivity_with_service_instances(self): + pass diff --git a/manila/tests/network/linux/test_interface.py b/manila/tests/network/linux/test_interface.py index 609e4b20cf..5c9c9afd76 100644 --- a/manila/tests/network/linux/test_interface.py +++ b/manila/tests/network/linux/test_interface.py @@ -160,6 +160,22 @@ class TestOVSInterfaceDriver(TestBase): self.ip.assert_has_calls(expected) + 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) + def test_unplug(self, bridge=None): if not bridge: bridge = 'br-int' diff --git a/releasenotes/notes/reset_tap_device_after_node_restart-0690a6beca077b95.yaml b/releasenotes/notes/reset_tap_device_after_node_restart-0690a6beca077b95.yaml new file mode 100644 index 0000000000..fdd6204d9d --- /dev/null +++ b/releasenotes/notes/reset_tap_device_after_node_restart-0690a6beca077b95.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - When use driver_handles_share_servers driver, + reset the tap device after manila-share service + start.