From 6b1ef02243d4975284a9214af203e98132289757 Mon Sep 17 00:00:00 2001 From: jiaopengju Date: Thu, 24 Aug 2017 14:52:01 +0800 Subject: [PATCH] Remove network dependency of server resource Currently, network topology is the dependency of server resource, it will make users confused to protect the server with network topology and bring network conflict issues. This patch will fix it. Change-Id: I21d62d66f5d66a1bc5e2c41ffc510fba19393ac5 Closes-Bug:#1711879 (cherry picked from commit 0c042063b6a1ccc9ca51061d961cf746b27bf7eb) --- .../protection/protectable_plugins/network.py | 48 ++----------------- .../test_network_protectable_plugin.py | 3 +- karbor/tests/unit/protection/test_manager.py | 3 +- 3 files changed, 5 insertions(+), 49 deletions(-) diff --git a/karbor/services/protection/protectable_plugins/network.py b/karbor/services/protection/protectable_plugins/network.py index acac4930..e5795e2c 100644 --- a/karbor/services/protection/protectable_plugins/network.py +++ b/karbor/services/protection/protectable_plugins/network.py @@ -39,8 +39,7 @@ class NetworkProtectablePlugin(protectable_plugin.ProtectablePlugin): return self._SUPPORT_RESOURCE_TYPE def get_parent_resource_types(self): - return (constants.SERVER_RESOURCE_TYPE, - constants.PROJECT_RESOURCE_TYPE) + return (constants.PROJECT_RESOURCE_TYPE) def _get_network_id(self): """Set network_id as project_id @@ -89,40 +88,6 @@ class NetworkProtectablePlugin(protectable_plugin.ProtectablePlugin): name="Network Topology") return None - def _get_dependent_resources_by_server(self, - context, - parent_resource): - try: - # get metadata about network from neutron - net_client = self._neutron_client(context) - network_infos = net_client.list_networks().get('networks') - neutron_networks = {network["id"] for network in network_infos} - - # get interface info from server - nova_networks = set() - serverid = parent_resource.id - nova_client = ClientFactory.create_client("nova", context) - interface_list = nova_client.servers.interface_list(serverid) - - # check net_id in interface - for iface in interface_list: - net_id = iface.net_id - if net_id not in nova_networks: - nova_networks.add(net_id) - - # get the exsited networks - valid_networks = nova_networks.intersection(neutron_networks) - if valid_networks: - return [resource.Resource(type=self._SUPPORT_RESOURCE_TYPE, - id=self._get_network_id(), - name="Network Topology")] - return [] - except Exception as e: - LOG.exception("List all interfaces from nova failed.") - raise exception.ListProtectableResourceFailed( - type=self._SUPPORT_RESOURCE_TYPE, - reason=six.text_type(e)) - def _get_dependent_resources_by_project(self, context, parent_resource): @@ -145,12 +110,5 @@ class NetworkProtectablePlugin(protectable_plugin.ProtectablePlugin): reason=six.text_type(e)) def get_dependent_resources(self, context, parent_resource): - if parent_resource.type == constants.SERVER_RESOURCE_TYPE: - return self._get_dependent_resources_by_server(context, - parent_resource) - - if parent_resource.type == constants.PROJECT_RESOURCE_TYPE: - return self._get_dependent_resources_by_project(context, - parent_resource) - - return [] + return self._get_dependent_resources_by_project( + context, parent_resource) diff --git a/karbor/tests/unit/plugins/test_network_protectable_plugin.py b/karbor/tests/unit/plugins/test_network_protectable_plugin.py index 7efeddd6..60e9df54 100644 --- a/karbor/tests/unit/plugins/test_network_protectable_plugin.py +++ b/karbor/tests/unit/plugins/test_network_protectable_plugin.py @@ -111,8 +111,7 @@ class NetworkProtectablePluginTest(base.TestCase): def test_get_parent_resource_type(self): plugin = NetworkProtectablePlugin(self._context) self.assertItemsEqual(plugin.get_parent_resource_types(), - (constants.SERVER_RESOURCE_TYPE, - constants.PROJECT_RESOURCE_TYPE)) + (constants.PROJECT_RESOURCE_TYPE)) @mock.patch.object(client.Client, 'list_networks') def test_list_resources(self, mock_client_list_networks): diff --git a/karbor/tests/unit/protection/test_manager.py b/karbor/tests/unit/protection/test_manager.py index e2033944..21b4009f 100644 --- a/karbor/tests/unit/protection/test_manager.py +++ b/karbor/tests/unit/protection/test_manager.py @@ -66,8 +66,7 @@ class ProtectionServiceTest(base.TestCase): result = self.pro_manager.show_protectable_type(None, "OS::Nova::Server") self.assertEqual("OS::Nova::Server", result["name"]) - self.assertEqual({"OS::Cinder::Volume", "OS::Glance::Image", - "OS::Neutron::Network"}, + self.assertEqual({"OS::Cinder::Volume", "OS::Glance::Image"}, set(result["dependent_types"])) @mock.patch.object(protectable_registry.ProtectableRegistry,