diff --git a/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py b/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py index 96c1bc9f9..94c48e3de 100644 --- a/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py +++ b/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py @@ -236,27 +236,13 @@ class LoadBalancerPluginDbv2(base_db.CommonDbMixin, lb_db.update(loadbalancer) return data_models.LoadBalancer.from_sqlalchemy_model(lb_db) - def delete_loadbalancer(self, context, id, delete_vip_port=True, - cascade=False): + def delete_loadbalancer(self, context, id, delete_vip_port=True): with context.session.begin(subtransactions=True): - if cascade: - lb = self.get_loadbalancer(context, id) - for pool in lb.pools: - if pool.healthmonitor_id: - self.delete_healthmonitor( - context, pool.healthmonitor_id) - self.delete_pool(context, pool.id) - for listener in lb.listeners: - # todo (xgerman): delete L7 - self.delete_listener(context, listener.id) lb_db = self._get_resource(context, models.LoadBalancer, id) context.session.delete(lb_db) if delete_vip_port and lb_db.vip_port: self._core_plugin.delete_port(context, lb_db.vip_port_id) - def delete_loadbalancer_cascade(self, context, id, delete_vip_port=True): - self.delete_loadbalancer(context, id, delete_vip_port, cascade=True) - def prevent_lbaasv2_port_deletion(self, context, port_id): try: port_db = self._core_plugin._get_port(context, port_id) diff --git a/neutron_lbaas/drivers/common/agent_driver_base.py b/neutron_lbaas/drivers/common/agent_driver_base.py index e0e32b59e..bc0e7e82a 100644 --- a/neutron_lbaas/drivers/common/agent_driver_base.py +++ b/neutron_lbaas/drivers/common/agent_driver_base.py @@ -175,21 +175,6 @@ class LoadBalancerManager(driver_base.BaseLoadBalancerManager): self.driver.agent_rpc.delete_loadbalancer(context, loadbalancer, agent['host']) - def delete_cascade(self, context, loadbalancer): - if not self.deletes_cascade: - raise NotImplementedError() - - super(LoadBalancerManager, self).delete(context, loadbalancer) - agent = self.driver.get_loadbalancer_agent(context, loadbalancer.id) - # TODO(blogan): Rethink deleting from the database here. May want to - # wait until the agent actually deletes it. Doing this now to keep - # what v1 had. - self.driver.plugin.db.delete_loadbalancer_cascade(context, - loadbalancer.id) - if agent: - self.driver.agent_rpc.delete_loadbalancer(context, loadbalancer, - agent['host']) - def stats(self, context, loadbalancer): pass diff --git a/neutron_lbaas/drivers/driver_base.py b/neutron_lbaas/drivers/driver_base.py index 9f2adedae..d4f5adbeb 100644 --- a/neutron_lbaas/drivers/driver_base.py +++ b/neutron_lbaas/drivers/driver_base.py @@ -92,11 +92,6 @@ class BaseLoadBalancerManager(driver_mixins.BaseRefreshMixin, """Does this driver need to allocate its own virtual IPs""" return False - @property - def deletes_cascade(self): - """Does this driver cascade delete LB""" - return False - def create_and_allocate_vip(self, context, obj): """Create the load balancer and allocate a VIP @@ -110,13 +105,7 @@ class BaseLoadBalancerManager(driver_mixins.BaseRefreshMixin, @property def db_delete_method(self): - if self.deletes_cascade: - return self.driver.plugin.db.delete_loadbalancer_cascade - else: - return self.driver.plugin.db.delete_loadbalancer - - def delete_cascade(self, context, obj): - raise NotImplementedError() + return self.driver.plugin.db.delete_loadbalancer class BaseListenerManager(driver_mixins.BaseManagerMixin): diff --git a/neutron_lbaas/drivers/logging_noop/driver.py b/neutron_lbaas/drivers/logging_noop/driver.py index 79181da98..1ef8c8ff4 100644 --- a/neutron_lbaas/drivers/logging_noop/driver.py +++ b/neutron_lbaas/drivers/logging_noop/driver.py @@ -64,11 +64,6 @@ class LoggingNoopLoadBalancerManager(LoggingNoopCommonManager, LOG.debug('allocates_vip queried') return False - @property - def deletes_cascade(self): - LOG.debug('deletes_cascade queried') - return False - def create_and_allocate_vip(self, context, obj): LOG.debug("LB %s no-op, create_and_allocate_vip %s", self.__class__.__name__, obj.id) @@ -90,16 +85,6 @@ class LoggingNoopLoadBalancerManager(LoggingNoopCommonManager, "total_connections": 0 } - @driver_base.driver_op - def delete(self, context, obj): - LOG.debug("LB %s no-op, delete %s", self.__class__.__name__, - obj.id) - - @driver_base.driver_op - def delete_cascade(self, context, obj): - LOG.debug("LB %s no-op, delete cascade %s", self.__class__.__name__, - obj.id) - class LoggingNoopListenerManager(LoggingNoopCommonManager, driver_base.BaseListenerManager): diff --git a/neutron_lbaas/extensions/cascade_delete.py b/neutron_lbaas/extensions/cascade_delete.py deleted file mode 100644 index 3cc8af450..000000000 --- a/neutron_lbaas/extensions/cascade_delete.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2014 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.api import extensions - -from neutron_lbaas.extensions import loadbalancerv2 - - -class Cascade_delete(extensions.ExtensionDescriptor): - - @classmethod - def get_name(cls): - return "LoadBalancing Cascade Delete" - - @classmethod - def get_alias(cls): - return "n-lbaasv2-cascade-delete" - - @classmethod - def get_description(cls): - return "Extension for LoadBalancing service v2 Cascade Delete" - - @classmethod - def get_namespace(cls): - return "http://wiki.openstack.org/neutron/LBaaS/API_2.0" - - @classmethod - def get_updated(cls): - return "2016-01-18T10:00:00-00:00" - - @classmethod - def get_resources(cls): - return [] - - @classmethod - def get_plugin_interface(cls): - return loadbalancerv2.LoadBalancerPluginBaseV2 - - def get_extended_resources(self, version): - return {} diff --git a/neutron_lbaas/services/loadbalancer/plugin.py b/neutron_lbaas/services/loadbalancer/plugin.py index 7dfe7f495..710da6c48 100644 --- a/neutron_lbaas/services/loadbalancer/plugin.py +++ b/neutron_lbaas/services/loadbalancer/plugin.py @@ -386,8 +386,7 @@ class LoadBalancerPluginv2(loadbalancerv2.LoadBalancerPluginBaseV2): "shared_pools", "l7", "lbaas_agent_schedulerv2", - "service-type", - "n-lbaasv2-cascade-delete"] + "service-type"] path_prefix = loadbalancerv2.LOADBALANCERV2_PREFIX agent_notifiers = ( @@ -489,8 +488,6 @@ class LoadBalancerPluginv2(loadbalancerv2.LoadBalancerPluginBaseV2): except (lbaas_agentschedulerv2.NoEligibleLbaasAgent, lbaas_agentschedulerv2.NoActiveLbaasAgent) as no_agent: raise no_agent - except NotImplementedError as e: - raise e except Exception: LOG.exception(_LE("There was an error in the driver")) self._handle_driver_error(context, db_entity) @@ -606,28 +603,22 @@ class LoadBalancerPluginv2(loadbalancerv2.LoadBalancerPluginBaseV2): def delete_loadbalancer(self, context, id): old_lb = self.db.get_loadbalancer(context, id) - + if old_lb.listeners: + raise loadbalancerv2.EntityInUse( + entity_using=models.Listener.NAME, + id=old_lb.listeners[0].id, + entity_in_use=models.LoadBalancer.NAME) + if old_lb.pools: + raise loadbalancerv2.EntityInUse( + entity_using=models.PoolV2.NAME, + id=old_lb.pools[0].id, + entity_in_use=models.LoadBalancer.NAME) self.db.test_and_set_status(context, models.LoadBalancer, id, constants.PENDING_DELETE) driver = self._get_driver_for_provider(old_lb.provider.provider_name) db_lb = self.db.get_loadbalancer(context, id) - try: - self._call_driver_operation( - context, driver.load_balancer.delete_cascade, db_lb) - except NotImplementedError: - if old_lb.listeners: - raise loadbalancerv2.EntityInUse( - entity_using=models.Listener.NAME, - id=old_lb.listeners[0].id, - entity_in_use=models.LoadBalancer.NAME) - if old_lb.pools: - raise loadbalancerv2.EntityInUse( - entity_using=models.PoolV2.NAME, - id=old_lb.pools[0].id, - entity_in_use=models.LoadBalancer.NAME) - #driver does not support cascade - self._call_driver_operation( - context, driver.load_balancer.delete, db_lb) + self._call_driver_operation( + context, driver.load_balancer.delete, db_lb) def get_loadbalancer(self, context, id, fields=None): return self.db.get_loadbalancer(context, id).to_api_dict() diff --git a/neutron_lbaas/tests/unit/db/loadbalancer/test_db_loadbalancerv2.py b/neutron_lbaas/tests/unit/db/loadbalancer/test_db_loadbalancerv2.py index 34c72643b..981b65323 100644 --- a/neutron_lbaas/tests/unit/db/loadbalancer/test_db_loadbalancerv2.py +++ b/neutron_lbaas/tests/unit/db/loadbalancer/test_db_loadbalancerv2.py @@ -642,7 +642,7 @@ class LbaasPluginDbTestCase(LbaasTestMixin, base.NeutronDbPluginV2TestCase): hm_status['provisioning_status']) -class TestLbaasLoadBalancerTests(LbaasPluginDbTestCase): +class LbaasLoadBalancerTests(LbaasPluginDbTestCase): def test_create_loadbalancer(self, **extras): expected = { @@ -718,16 +718,16 @@ class TestLbaasLoadBalancerTests(LbaasPluginDbTestCase): resp = self._delete_loadbalancer_api(loadbalancer_id) self.assertEqual(webob.exc.HTTPNoContent.code, resp.status_int) - def test_delete_loadbalancer_when_loadbalancer_in_use_cascade(self): + def test_delete_loadbalancer_when_loadbalancer_in_use(self): with self.subnet() as subnet: - with self.loadbalancer( - subnet=subnet, no_delete=True) as loadbalancer: + with self.loadbalancer(subnet=subnet) as loadbalancer: lb_id = loadbalancer['loadbalancer']['id'] - with self.listener(loadbalancer_id=lb_id, no_delete=True): + with self.listener(loadbalancer_id=lb_id): ctx = context.get_admin_context() - self.plugin.delete_loadbalancer( + self.assertRaises(loadbalancerv2.EntityInUse, + self.plugin.delete_loadbalancer, ctx, lb_id) - # lb deleted + self._validate_statuses(lb_id) def test_show_loadbalancer(self): name = 'lb_show' @@ -945,24 +945,6 @@ class LoadBalancerDelegateVIPCreation(LbaasPluginDbTestCase): self.assertIsNotNone(port) -class LoadBalancerDeleteCascade(LbaasPluginDbTestCase): - - def setUp(self): - driver_patcher = mock.patch.object( - noop_driver.LoggingNoopLoadBalancerManager, - 'deletes_cascade', new_callable=mock.PropertyMock) - driver_patcher.start().return_value = True - super(LoadBalancerDeleteCascade, self).setUp() - - def test_delete_loadbalancer(self): - with self.subnet() as subnet: - with self.loadbalancer(subnet=subnet, no_delete=True) as lb: - lb_id = lb['loadbalancer']['id'] - acontext = context.get_admin_context() - self.plugin.db.delete_loadbalancer( - acontext, lb_id, delete_vip_port=True) - - class ListenerTestBase(LbaasPluginDbTestCase): def setUp(self): super(ListenerTestBase, self).setUp() diff --git a/neutron_lbaas/tests/unit/drivers/logging_noop/test_logging_noop_driver.py b/neutron_lbaas/tests/unit/drivers/logging_noop/test_logging_noop_driver.py index e3b9de23b..ce5715af9 100644 --- a/neutron_lbaas/tests/unit/drivers/logging_noop/test_logging_noop_driver.py +++ b/neutron_lbaas/tests/unit/drivers/logging_noop/test_logging_noop_driver.py @@ -125,14 +125,6 @@ class LoadBalancerManagerTest(ManagerTestWithUpdates): h = self.manager.stats(self.parent.context, model) self.parent.assertEqual(dummy_stats, h) - @patch_manager - def delete(self, model): - self.manager.delete(self.parent.context, model) - - @patch_manager - def delete_cascade(self, model): - self.manager.delete_cascade(self.parent.context, model) - class TestLoggingNoopLoadBalancerDriver( test_db_loadbalancer.LoadBalancerPluginDbTestCase):