add portbinding host into vip port

When creating vip port, add 'host' into port data.

Bug #1227091

Change-Id: I0f59b3b56a4a26561a10e5645c8ebf803b2c6a70
This commit is contained in:
Yong Sheng Gong 2013-09-19 12:45:31 +08:00
parent ba835ab38c
commit 66c9fe253c
3 changed files with 32 additions and 1 deletions

View File

@ -26,6 +26,7 @@ from neutron.common import rpc as q_rpc
from neutron.db import agents_db
from neutron.db.loadbalancer import loadbalancer_db
from neutron.extensions import lbaas_agentscheduler
from neutron.extensions import portbindings
from neutron.openstack.common import importutils
from neutron.openstack.common import log as logging
from neutron.openstack.common import rpc
@ -168,7 +169,7 @@ class LoadBalancerCallbacks(object):
port['admin_state_up'] = True
port['device_owner'] = 'neutron:' + constants.LOADBALANCER
port['device_id'] = str(uuid.uuid5(uuid.NAMESPACE_DNS, str(host)))
port[portbindings.HOST_ID] = host
self.plugin._core_plugin.update_port(
context,
port_id,

View File

@ -22,6 +22,7 @@ from neutron.common import exceptions
from neutron import context
from neutron.db.loadbalancer import loadbalancer_db as ldb
from neutron.db import servicetype_db as st_db
from neutron.extensions import portbindings
from neutron import manager
from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants
@ -30,6 +31,7 @@ from neutron.services.loadbalancer.drivers.haproxy import (
)
from neutron.tests import base
from neutron.tests.unit.db.loadbalancer import test_db_loadbalancer
from neutron.tests.unit import testlib_api
class TestLoadBalancerPluginBase(
@ -275,6 +277,24 @@ class TestLoadBalancerCallbacks(TestLoadBalancerPluginBase):
host='host'
)
def test_plug_vip_port_mock_with_host(self):
exp = {
'device_owner': 'neutron:' + constants.LOADBALANCER,
'device_id': 'c596ce11-db30-5c72-8243-15acaae8690f',
'admin_state_up': True,
portbindings.HOST_ID: 'host'
}
with mock.patch.object(
self.plugin._core_plugin, 'update_port') as mock_update_port:
with self.pool() as pool:
with self.vip(pool=pool) as vip:
ctx = context.get_admin_context()
self.callbacks.plug_vip_port(
ctx, port_id=vip['vip']['port_id'], host='host')
mock_update_port.assert_called_once_with(
ctx, vip['vip']['port_id'],
{'port': testlib_api.SubDictMatch(exp)})
def test_unplug_vip_port(self):
exp = {
'device_owner': '',

View File

@ -72,3 +72,13 @@ class WebTestCase(base.BaseTestCase):
result = wsgi.Serializer(
attributes.get_attr_metadata()).serialize(data, ctype)
return result
class SubDictMatch(object):
def __init__(self, sub_dict):
self.sub_dict = sub_dict
def __eq__(self, super_dict):
return all(item in super_dict.items()
for item in self.sub_dict.items())