From efdbefc0dc04b24a068ce15e2c0e7ad9e95806c0 Mon Sep 17 00:00:00 2001 From: Divya ChanneGowda Date: Wed, 9 Sep 2015 15:14:28 -0700 Subject: [PATCH] Add device_id when a loadbalancer is created instead of at listener create nova boot on lbaas_vip port is not blocked as nova throws PortInUse exception only if the port device_id is set. Currently device_id is updated during lbaas listener create. This fix sets the device_id to loadbalancer id during the loadbalancer create. Change-Id: I2dfce54322eff5f4830b94ac8424057780ebeb9d Closes-Bug: #1482763 (cherry picked from commit f9b93a3d748ba0326883b6e50b46f3059c769c29) --- neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py | 2 +- neutron_lbaas/drivers/common/agent_callbacks.py | 4 ---- .../drivers/haproxy/synchronous_namespace_driver.py | 5 ----- .../tests/unit/drivers/common/test_agent_callbacks.py | 6 ++---- .../tests/unit/drivers/haproxy/test_synchronous_driver.py | 4 ---- 5 files changed, 3 insertions(+), 18 deletions(-) diff --git a/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py b/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py index 7b4849419..7067a162f 100644 --- a/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py +++ b/neutron_lbaas/db/loadbalancer/loadbalancer_dbv2.py @@ -98,7 +98,7 @@ class LoadBalancerPluginDbv2(base_db.CommonDbMixin, 'network_id': subnet['network_id'], 'mac_address': attributes.ATTR_NOT_SPECIFIED, 'admin_state_up': False, - 'device_id': '', + 'device_id': lb_db.id, 'device_owner': n_constants.DEVICE_OWNER_LOADBALANCERV2, 'fixed_ips': [fixed_ip] } diff --git a/neutron_lbaas/drivers/common/agent_callbacks.py b/neutron_lbaas/drivers/common/agent_callbacks.py index 02e6ab5f2..a4d5cb837 100644 --- a/neutron_lbaas/drivers/common/agent_callbacks.py +++ b/neutron_lbaas/drivers/common/agent_callbacks.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid - from neutron.common import exceptions as n_exc from neutron.extensions import portbindings from neutron.i18n import _LW @@ -166,8 +164,6 @@ class LoadBalancerCallbacks(object): return port['admin_state_up'] = True - port['device_owner'] = 'neutron:' + constants.LOADBALANCERV2 - port['device_id'] = str(uuid.uuid5(uuid.NAMESPACE_DNS, str(host))) port[portbindings.HOST_ID] = host self.plugin.db._core_plugin.update_port( context, diff --git a/neutron_lbaas/drivers/haproxy/synchronous_namespace_driver.py b/neutron_lbaas/drivers/haproxy/synchronous_namespace_driver.py index a029be3c2..659cb3b7e 100644 --- a/neutron_lbaas/drivers/haproxy/synchronous_namespace_driver.py +++ b/neutron_lbaas/drivers/haproxy/synchronous_namespace_driver.py @@ -15,7 +15,6 @@ import os import shutil import socket -import uuid import netaddr from neutron.agent.common import config @@ -148,10 +147,6 @@ class HaproxyNSDriver(driver_base.LoadBalancerBaseDriver): def _build_port_dict(self): return {'admin_state_up': True, - 'device_owner': 'neutron:{0}'.format( - constants.LOADBALANCER), - 'device_id': str(uuid.uuid5(uuid.NAMESPACE_DNS, - str(self.conf.host))), portbindings.HOST_ID: self.conf.host} def _get_state_file_path(self, loadbalancer_id, kind, diff --git a/neutron_lbaas/tests/unit/drivers/common/test_agent_callbacks.py b/neutron_lbaas/tests/unit/drivers/common/test_agent_callbacks.py index 02db2a593..199cedf99 100644 --- a/neutron_lbaas/tests/unit/drivers/common/test_agent_callbacks.py +++ b/neutron_lbaas/tests/unit/drivers/common/test_agent_callbacks.py @@ -161,6 +161,8 @@ class TestLoadBalancerCallbacks( with self.loadbalancer() as loadbalancer: lb_id = loadbalancer['loadbalancer']['id'] + if 'device_id' not in expected: + expected['device_id'] = lb_id self.plugin_instance.db.update_loadbalancer_provisioning_status( context.get_admin_context(), loadbalancer['loadbalancer']['id']) @@ -173,8 +175,6 @@ class TestLoadBalancerCallbacks( def test_plug_vip_port(self): exp = { - 'device_owner': 'neutron:' + constants.LOADBALANCERV2, - 'device_id': 'c596ce11-db30-5c72-8243-15acaae8690f', 'admin_state_up': True } self._update_port_test_helper( @@ -185,8 +185,6 @@ class TestLoadBalancerCallbacks( def test_plug_vip_port_mock_with_host(self): exp = { - 'device_owner': 'neutron:' + constants.LOADBALANCERV2, - 'device_id': 'c596ce11-db30-5c72-8243-15acaae8690f', 'admin_state_up': True, portbindings.HOST_ID: 'host' } diff --git a/neutron_lbaas/tests/unit/drivers/haproxy/test_synchronous_driver.py b/neutron_lbaas/tests/unit/drivers/haproxy/test_synchronous_driver.py index 9fa217fc0..75fd4c4bf 100644 --- a/neutron_lbaas/tests/unit/drivers/haproxy/test_synchronous_driver.py +++ b/neutron_lbaas/tests/unit/drivers/haproxy/test_synchronous_driver.py @@ -15,7 +15,6 @@ import collections import contextlib -import uuid import mock from neutron.common import exceptions @@ -138,9 +137,6 @@ class TestHaproxyNSDriver(base.BaseTestCase): def test_build_port_dict(self): self.driver.conf.host = 'host1' ret = {'admin_state_up': True, - 'device_owner': 'neutron:LOADBALANCER', - 'device_id': str(uuid.uuid5(uuid.NAMESPACE_DNS, - str(self.conf.host))), portbindings.HOST_ID: self.conf.host} self.assertEqual(ret, self.driver._build_port_dict())