From 7d16dc28f4ef48db3984bee2e919d5408017a868 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Tue, 1 Sep 2015 17:43:34 -0700 Subject: [PATCH] Do not remove network from dhcp agent if they are not supported dhcp_agent_scheduler is optional extension in Neutron which means that we need to check whatever is supported or not before trying to cleanup it. closes-bug: #1491196 Change-Id: I1f7068de9dfd8ea8185206469fdc048c55a54cfc --- rally/plugins/openstack/wrappers/network.py | 11 ++++++----- .../plugins/openstack/wrappers/test_network.py | 17 +++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/rally/plugins/openstack/wrappers/network.py b/rally/plugins/openstack/wrappers/network.py index 7a3e836a74..b2785422ab 100644 --- a/rally/plugins/openstack/wrappers/network.py +++ b/rally/plugins/openstack/wrappers/network.py @@ -325,11 +325,12 @@ class NeutronWrapper(NetworkWrapper): self.client.delete_pool(pool_id) def delete_network(self, network): - net_dhcps = self.client.list_dhcp_agent_hosting_networks( - network["id"])["agents"] - for net_dhcp in net_dhcps: - self.client.remove_network_from_dhcp_agent(net_dhcp["id"], - network["id"]) + if self.supports_extension("dhcp_agent_scheduler")[0]: + net_dhcps = self.client.list_dhcp_agent_hosting_networks( + network["id"])["agents"] + for net_dhcp in net_dhcps: + self.client.remove_network_from_dhcp_agent(net_dhcp["id"], + network["id"]) router_id = network["router_id"] if router_id: self.client.remove_gateway_router(router_id) diff --git a/tests/unit/plugins/openstack/wrappers/test_network.py b/tests/unit/plugins/openstack/wrappers/test_network.py index 8cda76c4dd..f123270f3c 100644 --- a/tests/unit/plugins/openstack/wrappers/test_network.py +++ b/tests/unit/plugins/openstack/wrappers/test_network.py @@ -360,17 +360,15 @@ class NeutronWrapperTestCase(test.TestCase): [mock.call("foo_router", {"subnet_id": "foo_subnet"}) for i in range(subnets_num)]) - def test_delete_network(self): + @mock.patch("rally.plugins.openstack.wrappers.network.NeutronWrapper" + ".supports_extension", return_value=(False, "")) + def test_delete_network(self, mock_neutron_wrapper_supports_extension): service = self.get_wrapper() - service.client.list_dhcp_agent_hosting_networks.return_value = ( - {"agents": []}) service.client.list_ports.return_value = {"ports": []} service.client.delete_network.return_value = "foo_deleted" result = service.delete_network({"id": "foo_id", "router_id": None, "subnets": []}) self.assertEqual(result, "foo_deleted") - self.assertEqual( - service.client.remove_network_from_dhcp_agent.mock_calls, []) self.assertEqual(service.client.remove_gateway_router.mock_calls, []) self.assertEqual( service.client.remove_interface_router.mock_calls, []) @@ -384,7 +382,11 @@ class NeutronWrapperTestCase(test.TestCase): service.delete_v1_pool(pool["pool"]["id"]) service.client.delete_pool.called_once_with([mock.call("pool-id")]) - def test_delete_network_with_dhcp_and_router_and_ports_and_subnets(self): + @mock.patch("rally.plugins.openstack.wrappers.network.NeutronWrapper" + ".supports_extension", return_value=(True, "")) + def test_delete_network_with_dhcp_and_router_and_ports_and_subnets( + self, mock_neutron_wrapper_supports_extension): + service = self.get_wrapper() agents = ["foo_agent", "bar_agent"] subnets = ["foo_subnet", "bar_subnet"] @@ -415,6 +417,9 @@ class NeutronWrapperTestCase(test.TestCase): [mock.call(subnet_id) for subnet_id in subnets]) service.client.delete_network.assert_called_once_with("foo_id") + mock_neutron_wrapper_supports_extension.assert_called_once_with( + "dhcp_agent_scheduler") + def test_list_networks(self): service = self.get_wrapper() service.client.list_networks.return_value = {"networks": "foo_nets"}