]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NVP LBaaS: check for association before deleting health monitor
authorberlin <linb@vmware.com>
Thu, 16 Jan 2014 07:02:29 +0000 (15:02 +0800)
committerGerrit Code Review <review@openstack.org>
Tue, 4 Mar 2014 05:20:54 +0000 (05:20 +0000)
    Bug #1243129 suggests to check for associations before deleting
health monitor in DB logic, so NVP advanced LBaaS should also Change
its operations when deleting a healthmonitor.

Change-Id: I57677cc4b65a13df9f72ec689f34771c7af6a57e
Closes-Bug: #1254639

neutron/plugins/vmware/plugins/service.py
neutron/tests/unit/vmware/vshield/test_lbaas_plugin.py

index 4ed362cfd9b1a88b542a938dafe4ca9d3391a0f8..258677242726fdd080c6d209378e8bf6945a1639 100644 (file)
@@ -1454,49 +1454,6 @@ class NsxAdvancedPlugin(sr_db.ServiceRouter_mixin,
                                         "with id: %s!"), id)
         return hm
 
-    def delete_health_monitor(self, context, id):
-        with context.session.begin(subtransactions=True):
-            qry = context.session.query(
-                loadbalancer_db.PoolMonitorAssociation
-            ).filter_by(monitor_id=id)
-            for assoc in qry:
-                pool_id = assoc['pool_id']
-                super(NsxAdvancedPlugin,
-                      self).delete_pool_health_monitor(context,
-                                                       id,
-                                                       pool_id)
-                pool = self.get_pool(context, pool_id)
-                if not pool.get('vip_id'):
-                    continue
-                edge_id = self._get_edge_id_by_vip_id(
-                    context, pool['vip_id'])
-                self._resource_set_status(
-                    context, loadbalancer_db.Pool,
-                    pool_id, service_constants.PENDING_UPDATE)
-                try:
-                    self._vcns_update_pool(context, pool)
-                except Exception:
-                    with excutils.save_and_reraise_exception():
-                        LOG.exception(_("Failed to update pool with monitor!"))
-                self._resource_set_status(
-                    context, loadbalancer_db.Pool,
-                    pool_id, service_constants.ACTIVE)
-                try:
-                    self.vcns_driver.delete_health_monitor(
-                        context, id, edge_id)
-                except Exception:
-                    with excutils.save_and_reraise_exception():
-                        LOG.exception(_("Failed to delete monitor "
-                                        "with id: %s!"), id)
-                        super(NsxAdvancedPlugin,
-                              self).delete_health_monitor(context, id)
-                        self._delete_resource_router_id_binding(
-                            context, id, loadbalancer_db.HealthMonitor)
-
-        super(NsxAdvancedPlugin, self).delete_health_monitor(context, id)
-        self._delete_resource_router_id_binding(
-            context, id, loadbalancer_db.HealthMonitor)
-
     def create_pool_health_monitor(self, context,
                                    health_monitor, pool_id):
         monitor_id = health_monitor['health_monitor']['id']
index becbde04b52c54b50ace99ed033ff1229ee3d672..99338f6007a1f80960cea029f3b2303212d9aa66 100644 (file)
@@ -19,7 +19,6 @@ from webob import exc as web_exc
 
 from neutron.api.v2 import attributes
 from neutron import context
-from neutron.db.loadbalancer import loadbalancer_db as ldb
 from neutron.extensions import loadbalancer as lb
 from neutron import manager
 from neutron.openstack.common import uuidutils
@@ -125,9 +124,9 @@ class TestLoadbalancerPlugin(
 
         with contextlib.nested(
             self.subnet(),
-            self.pool(),
-            self.health_monitor()
-        ) as (subnet, pool, health_mon):
+            self.health_monitor(),
+            self.pool()
+        ) as (subnet, health_mon, pool):
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)
             with self.vip(
@@ -150,31 +149,6 @@ class TestLoadbalancerPlugin(
                     for k, v in keys:
                         self.assertEqual(res['health_monitor'][k], v)
 
-    def test_delete_healthmonitor(self):
-        ctx = context.get_admin_context()
-        with contextlib.nested(
-            self.subnet(),
-            self.pool(),
-            self.health_monitor(no_delete=True)
-        ) as (subnet, pool, health_mon):
-            net_id = subnet['subnet']['network_id']
-            self._set_net_external(net_id)
-            with self.vip(
-                router_id=self._create_and_get_router(),
-                pool=pool, subnet=subnet):
-                    self.plugin.create_pool_health_monitor(
-                        context.get_admin_context(),
-                        health_mon, pool['pool']['id']
-                    )
-
-            req = self.new_delete_request('health_monitors',
-                                          health_mon['health_monitor']['id'])
-            res = req.get_response(self.ext_api)
-            self.assertEqual(res.status_int, 204)
-            qry = ctx.session.query(ldb.HealthMonitor)
-            qry = qry.filter_by(id=health_mon['health_monitor']['id'])
-            self.assertIsNone(qry.first())
-
     def test_create_vip(self, **extras):
         expected = {
             'name': 'vip1',
@@ -194,9 +168,9 @@ class TestLoadbalancerPlugin(
 
         with contextlib.nested(
             self.subnet(),
-            self.pool(),
-            self.health_monitor()
-        ) as (subnet, pool, monitor):
+            self.health_monitor(),
+            self.pool()
+        ) as (subnet, monitor, pool):
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)
             expected['pool_id'] = pool['pool']['id']
@@ -228,9 +202,9 @@ class TestLoadbalancerPlugin(
 
         with contextlib.nested(
             self.subnet(),
-            self.pool(),
-            self.health_monitor()
-        ) as (subnet, pool, monitor):
+            self.health_monitor(),
+            self.pool()
+        ) as (subnet, monitor, pool):
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)
             self.plugin.create_pool_health_monitor(
@@ -257,9 +231,9 @@ class TestLoadbalancerPlugin(
     def test_delete_vip(self):
         with contextlib.nested(
             self.subnet(),
-            self.pool(),
-            self.health_monitor()
-        ) as (subnet, pool, monitor):
+            self.health_monitor(),
+            self.pool()
+        ) as (subnet, monitor, pool):
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)
             self.plugin.create_pool_health_monitor(
@@ -287,9 +261,9 @@ class TestLoadbalancerPlugin(
 
         with contextlib.nested(
             self.subnet(),
-            self.pool(),
-            self.health_monitor()
-        ) as (subnet, pool, monitor):
+            self.health_monitor(),
+            self.pool()
+        ) as (subnet, monitor, pool):
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)
             self.plugin.create_pool_health_monitor(
@@ -348,9 +322,9 @@ class TestLoadbalancerPlugin(
                          'admin_state_up': False}}
         with contextlib.nested(
             self.subnet(),
-            self.pool(),
-            self.health_monitor()
-        ) as (subnet, pool, monitor):
+            self.health_monitor(),
+            self.pool()
+        ) as (subnet, monitor, pool):
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)
             self.plugin.create_pool_health_monitor(
@@ -371,9 +345,9 @@ class TestLoadbalancerPlugin(
         router_id = self._create_and_get_router()
         with contextlib.nested(
             self.subnet(),
-            self.pool(),
-            self.health_monitor()
-        ) as (subnet, pool, monitor):
+            self.health_monitor(),
+            self.pool()
+        ) as (subnet, monitor, pool):
             pool_id = pool['pool']['id']
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)
@@ -413,10 +387,10 @@ class TestLoadbalancerPlugin(
     def test_update_member(self):
         with contextlib.nested(
             self.subnet(),
+            self.health_monitor(),
             self.pool(name="pool1"),
-            self.pool(name="pool2"),
-            self.health_monitor()
-        ) as (subnet, pool1, pool2, monitor):
+            self.pool(name="pool2")
+        ) as (subnet, monitor, pool1, pool2):
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)
             self.plugin.create_pool_health_monitor(
@@ -465,9 +439,9 @@ class TestLoadbalancerPlugin(
     def test_delete_member(self):
         with contextlib.nested(
             self.subnet(),
-            self.pool(),
-            self.health_monitor()
-        ) as (subnet, pool, monitor):
+            self.health_monitor(),
+            self.pool()
+        ) as (subnet, monitor, pool):
             pool_id = pool['pool']['id']
             net_id = subnet['subnet']['network_id']
             self._set_net_external(net_id)