Merge "Pass network MTU into namespace driver" into stable/newton

This commit is contained in:
Jenkins 2016-12-09 22:03:59 +00:00 committed by Gerrit Code Review
commit 0a32ba610e
4 changed files with 34 additions and 4 deletions

View File

@ -76,6 +76,11 @@ class LoadBalancerCallbacks(object):
device_driver = self.plugin.drivers[
lb_model.provider.provider_name].device_driver
setattr(lb_model.provider, 'device_driver', device_driver)
if lb_model.vip_port:
network_dict = self.plugin.db._core_plugin.get_network(
context, lb_model.vip_port.network_id)
setattr(lb_model.vip_port, 'network',
data_models.Network.from_dict(network_dict))
lb_dict = lb_model.to_dict(stats=False)
return lb_dict

View File

@ -315,7 +315,8 @@ class HaproxyNSDriver(agent_device_driver.AgentDeviceDriver):
port.id,
interface_name,
port.mac_address,
namespace=namespace
namespace=namespace,
mtu=port.network.mtu
)
cidrs = [

View File

@ -82,8 +82,10 @@ class BaseDataModel(object):
continue
if attr_mapping and attr_name in attr_mapping.keys():
attr = getattr(sa_model, attr_mapping[attr_name])
else:
elif hasattr(sa_model, attr_name):
attr = getattr(sa_model, attr_name)
else:
continue
# Handles M:1 or 1:1 relationships
if isinstance(attr, model_base.BASEV2):
if hasattr(instance, attr_name):
@ -161,6 +163,17 @@ class HostRoute(BaseDataModel):
self.nexthop = nexthop
class Network(BaseDataModel):
fields = ['id', 'name', 'description', 'mtu']
def __init__(self, id=None, name=None, description=None, mtu=None):
self.id = id
self.name = name
self.description = description
self.mtu = mtu
class Subnet(BaseDataModel):
fields = ['id', 'name', 'tenant_id', 'network_id', 'ip_version', 'cidr',
@ -227,11 +240,12 @@ class Port(BaseDataModel):
fields = ['id', 'tenant_id', 'name', 'network_id', 'mac_address',
'admin_state_up', 'status', 'device_id', 'device_owner',
'fixed_ips']
'fixed_ips', 'network']
def __init__(self, id=None, tenant_id=None, name=None, network_id=None,
mac_address=None, admin_state_up=None, status=None,
device_id=None, device_owner=None, fixed_ips=None):
device_id=None, device_owner=None, fixed_ips=None,
network=None):
self.id = id
self.tenant_id = tenant_id
self.name = name
@ -242,12 +256,16 @@ class Port(BaseDataModel):
self.device_id = device_id
self.device_owner = device_owner
self.fixed_ips = fixed_ips or []
self.network = network
@classmethod
def from_dict(cls, model_dict):
fixed_ips = model_dict.pop('fixed_ips', [])
model_dict['fixed_ips'] = [IPAllocation.from_dict(fixed_ip)
for fixed_ip in fixed_ips]
if model_dict.get('network'):
network_dict = model_dict.pop('network')
model_dict['network'] = Network.from_dict(network_dict)
return super(Port, cls).from_dict(model_dict)

View File

@ -155,6 +155,12 @@ class TestLoadBalancerCallbacks(
ctx, expected_lb['vip_subnet_id'])
subnet = data_models.Subnet.from_dict(subnet).to_dict()
expected_lb['vip_port']['fixed_ips'][0]['subnet'] = subnet
network = self.plugin_instance.db._core_plugin.get_network(
ctx, expected_lb['vip_port']['network_id']
)
expected_lb['vip_port']['network'] = {}
for key in ('id', 'name', 'description', 'mtu'):
expected_lb['vip_port']['network'][key] = network[key]
del expected_lb['stats']
self.assertEqual(expected_lb, load_balancer)