From 7bbab37916be99cf2a8d98e0add3071142fe9155 Mon Sep 17 00:00:00 2001 From: yanyanhu Date: Mon, 6 Jun 2016 00:59:36 -0400 Subject: [PATCH] Revise some neutron_v2 driver interfaces This patch revises all resource_get interfaces of neutron_v2 driver to add ignore_missing parameter. This allows Senlin driver to catch and handle NotFound exception raised by openstacksdk when specified resource can not be found. Change-Id: I8ae52eea5811edd67232484e116b3ccd9d2a1a78 Closes-Bug: #1589341 --- senlin/drivers/openstack/neutron_v2.py | 35 +++++++++++-------- .../drivers/openstack/neutron_v2.py | 2 +- .../unit/drivers/test_neutron_v2_driver.py | 16 +++++---- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/senlin/drivers/openstack/neutron_v2.py b/senlin/drivers/openstack/neutron_v2.py index 25d5e06a2..1866ae109 100644 --- a/senlin/drivers/openstack/neutron_v2.py +++ b/senlin/drivers/openstack/neutron_v2.py @@ -22,18 +22,21 @@ class NeutronClient(base.DriverBase): self.conn = sdk.create_connection(params) @sdk.translate_exception - def network_get(self, name_or_id): - network = self.conn.network.find_network(name_or_id) + def network_get(self, name_or_id, ignore_missing=False): + network = self.conn.network.find_network(name_or_id, + ignore_missing) return network @sdk.translate_exception - def subnet_get(self, name_or_id): - subnet = self.conn.network.find_subnet(name_or_id) + def subnet_get(self, name_or_id, ignore_missing=False): + subnet = self.conn.network.find_subnet(name_or_id, + ignore_missing) return subnet @sdk.translate_exception - def loadbalancer_get(self, name_or_id): - lb = self.conn.network.find_load_balancer(name_or_id) + def loadbalancer_get(self, name_or_id, ignore_missing=False): + lb = self.conn.network.find_load_balancer(name_or_id, + ignore_missing) return lb @sdk.translate_exception @@ -67,8 +70,9 @@ class NeutronClient(base.DriverBase): return @sdk.translate_exception - def listener_get(self, name_or_id): - listener = self.conn.network.find_listener(name_or_id) + def listener_get(self, name_or_id, ignore_missing=False): + listener = self.conn.network.find_listener(name_or_id, + ignore_missing) return listener @sdk.translate_exception @@ -105,8 +109,9 @@ class NeutronClient(base.DriverBase): return @sdk.translate_exception - def pool_get(self, name_or_id): - pool = self.conn.network.find_pool(name_or_id) + def pool_get(self, name_or_id, ignore_missing=False): + pool = self.conn.network.find_pool(name_or_id, + ignore_missing) return pool @sdk.translate_exception @@ -140,9 +145,10 @@ class NeutronClient(base.DriverBase): return @sdk.translate_exception - def pool_member_get(self, pool_id, name_or_id): + def pool_member_get(self, pool_id, name_or_id, ignore_missing=False): member = self.conn.network.find_pool_member(name_or_id, - pool_id) + pool_id, + ignore_missing) return member @sdk.translate_exception @@ -174,8 +180,9 @@ class NeutronClient(base.DriverBase): return @sdk.translate_exception - def healthmonitor_get(self, name_or_id): - hm = self.conn.network.find_health_monitor(name_or_id) + def healthmonitor_get(self, name_or_id, ignore_missing=False): + hm = self.conn.network.find_health_monitor(name_or_id, + ignore_missing) return hm @sdk.translate_exception diff --git a/senlin/tests/functional/drivers/openstack/neutron_v2.py b/senlin/tests/functional/drivers/openstack/neutron_v2.py index a87cd713c..543613771 100644 --- a/senlin/tests/functional/drivers/openstack/neutron_v2.py +++ b/senlin/tests/functional/drivers/openstack/neutron_v2.py @@ -33,5 +33,5 @@ class NeutronClient(base.DriverBase): "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22" } - def network_get(self, value): + def network_get(self, value, ignore_missing=False): return sdk.FakeResourceObject(self.fake_network) diff --git a/senlin/tests/unit/drivers/test_neutron_v2_driver.py b/senlin/tests/unit/drivers/test_neutron_v2_driver.py index 7646678eb..ff0c57c08 100644 --- a/senlin/tests/unit/drivers/test_neutron_v2_driver.py +++ b/senlin/tests/unit/drivers/test_neutron_v2_driver.py @@ -41,7 +41,7 @@ class TestNeutronV2Driver(base.SenlinTestCase): self.conn.network.find_network.return_value = network_obj res = self.nc.network_get(net_id) - self.conn.network.find_network.assert_called_once_with(net_id) + self.conn.network.find_network.assert_called_once_with(net_id, False) self.assertEqual(network_obj, res) def test_subnet_get(self): @@ -50,7 +50,7 @@ class TestNeutronV2Driver(base.SenlinTestCase): self.conn.network.find_subnet.return_value = subnet_obj res = self.nc.subnet_get(subnet_id) - self.conn.network.find_subnet.assert_called_once_with(subnet_id) + self.conn.network.find_subnet.assert_called_once_with(subnet_id, False) self.assertEqual(subnet_obj, res) def test_loadbalancer_get(self): @@ -59,7 +59,8 @@ class TestNeutronV2Driver(base.SenlinTestCase): self.conn.network.find_load_balancer.return_value = loadbalancer_obj res = self.nc.loadbalancer_get(lb_id) - self.conn.network.find_load_balancer.assert_called_once_with(lb_id) + self.conn.network.find_load_balancer.assert_called_once_with(lb_id, + False) self.assertEqual(loadbalancer_obj, res) def test_loadbalancer_list(self): @@ -113,7 +114,7 @@ class TestNeutronV2Driver(base.SenlinTestCase): self.conn.network.find_listener.return_value = listener_obj res = self.nc.listener_get(name_or_id) self.conn.network.find_listener.assert_called_once_with( - name_or_id) + name_or_id, False) self.assertEqual(listener_obj, res) def test_listener_list(self): @@ -171,7 +172,8 @@ class TestNeutronV2Driver(base.SenlinTestCase): self.conn.network.find_pool.return_value = pool_obj res = self.nc.pool_get(name_or_id) - self.conn.network.find_pool.assert_called_once_with(name_or_id) + self.conn.network.find_pool.assert_called_once_with(name_or_id, + False) self.assertEqual(pool_obj, res) def test_pool_list(self): @@ -230,7 +232,7 @@ class TestNeutronV2Driver(base.SenlinTestCase): self.conn.network.find_pool_member.return_value = member_obj res = self.nc.pool_member_get(pool_id, name_or_id) self.conn.network.find_pool_member.assert_called_once_with( - name_or_id, pool_id) + name_or_id, pool_id, False) self.assertEqual(member_obj, res) def test_pool_member_list(self): @@ -291,7 +293,7 @@ class TestNeutronV2Driver(base.SenlinTestCase): self.conn.network.find_health_monitor.return_value = healthmonitor_obj res = self.nc.healthmonitor_get(name_or_id) self.conn.network.find_health_monitor.assert_called_once_with( - name_or_id) + name_or_id, False) self.assertEqual(healthmonitor_obj, res) def test_healthmonitor_list(self):