Add host routes and dns nameservers to Midonet DHCP
In the Midonet plugin, the host routes and dns nameserver information was not being passed down to the midonet client API. This fix addresses this by passing down the correct information. Change-Id: I142ad4ceccdcf8b0e13db55fa54513f82995efc5 Closes-Bug: #1229655
This commit is contained in:
parent
9f34f6ba3e
commit
b07d7454e8
@ -21,7 +21,7 @@
|
||||
# @author: Rossella Sblendido, Midokura Japan KK
|
||||
|
||||
|
||||
from midonetclient import midoapi_exceptions
|
||||
from midonetclient import exc
|
||||
from webob import exc as w_exc
|
||||
|
||||
from neutron.common import exceptions as n_exc
|
||||
@ -37,7 +37,7 @@ def handle_api_error(fn):
|
||||
try:
|
||||
return fn(*args, **kwargs)
|
||||
except (w_exc.HTTPException,
|
||||
midoapi_exceptions.MidoApiConnectionError) as ex:
|
||||
exc.MidoApiConnectionError) as ex:
|
||||
raise MidonetApiException(msg=ex)
|
||||
return wrapped
|
||||
|
||||
@ -107,21 +107,25 @@ class MidoClient:
|
||||
raise MidonetResourceNotFound(resource_type='Bridge', id=id)
|
||||
|
||||
@handle_api_error
|
||||
def create_dhcp(self, bridge, gateway_ip, cidr):
|
||||
def create_dhcp(self, bridge, gateway_ip, cidr, host_rts=None,
|
||||
dns_servers=None):
|
||||
"""Create a new DHCP entry
|
||||
|
||||
:param bridge: bridge object to add dhcp to
|
||||
:param gateway_ip: IP address of gateway
|
||||
:param cidr: subnet represented as x.x.x.x/y
|
||||
:param host_rts: list of routes set in the host
|
||||
:param dns_servers: list of dns servers
|
||||
:returns: newly created dhcp
|
||||
"""
|
||||
LOG.debug(_("MidoClient.create_dhcp called: bridge=%(bridge)s, "
|
||||
"cidr=%(cidr)s, gateway_ip=%(gateway_ip)s"),
|
||||
{'bridge': bridge, 'cidr': cidr, 'gateway_ip': gateway_ip})
|
||||
net_addr, net_len = net_util.net_addr(cidr)
|
||||
return bridge.add_dhcp_subnet().default_gateway(
|
||||
gateway_ip).subnet_prefix(net_addr).subnet_length(
|
||||
net_len).create()
|
||||
"cidr=%(cidr)s, gateway_ip=%(gateway_ip)s, "
|
||||
"host_rts=%(host_rts)s, dns_servers=%(dns_servers)s"),
|
||||
{'bridge': bridge, 'cidr': cidr, 'gateway_ip': gateway_ip,
|
||||
'host_rts': host_rts, 'dns_servers': dns_servers})
|
||||
self.mido_api.add_bridge_dhcp(bridge, gateway_ip, cidr,
|
||||
host_rts=host_rts,
|
||||
dns_nservers=dns_servers)
|
||||
|
||||
@handle_api_error
|
||||
def add_dhcp_host(self, bridge, cidr, ip, mac):
|
||||
@ -319,6 +323,9 @@ class MidoClient:
|
||||
prefix, length = dst_ip.split("/")
|
||||
routes = [{'destinationPrefix': prefix, 'destinationLength': length,
|
||||
'gatewayAddr': gw_ip}]
|
||||
cur_routes = subnet.get_opt121_routes()
|
||||
if cur_routes:
|
||||
routes = routes + cur_routes
|
||||
subnet.opt121_routes(routes).update()
|
||||
|
||||
@handle_api_error
|
||||
|
@ -24,6 +24,7 @@
|
||||
from midonetclient import api
|
||||
from oslo.config import cfg
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron.common import rpc as n_rpc
|
||||
@ -367,7 +368,7 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
"""
|
||||
LOG.debug(_("MidonetPluginV2.create_subnet called: subnet=%r"), subnet)
|
||||
|
||||
subnet_data = subnet["subnet"]
|
||||
s = subnet["subnet"]
|
||||
net = super(MidonetPluginV2, self).get_network(
|
||||
context, subnet['subnet']['network_id'], fields=None)
|
||||
|
||||
@ -377,9 +378,19 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
subnet)
|
||||
bridge = self.client.get_bridge(sn_entry['network_id'])
|
||||
|
||||
gateway_ip = subnet_data['gateway_ip']
|
||||
cidr = subnet_data['cidr']
|
||||
self.client.create_dhcp(bridge, gateway_ip, cidr)
|
||||
gateway_ip = s['gateway_ip']
|
||||
cidr = s['cidr']
|
||||
dns_nameservers = None
|
||||
host_routes = None
|
||||
if s['dns_nameservers'] is not attributes.ATTR_NOT_SPECIFIED:
|
||||
dns_nameservers = s['dns_nameservers']
|
||||
|
||||
if s['host_routes'] is not attributes.ATTR_NOT_SPECIFIED:
|
||||
host_routes = s['host_routes']
|
||||
|
||||
self.client.create_dhcp(bridge, gateway_ip, cidr,
|
||||
host_rts=host_routes,
|
||||
dns_servers=dns_nameservers)
|
||||
|
||||
# For external network, link the bridge to the provider router.
|
||||
if net['router:external']:
|
||||
|
@ -79,15 +79,21 @@ class MidoClientTestCase(testtools.TestCase):
|
||||
def test_create_dhcp(self):
|
||||
|
||||
bridge = mock.Mock()
|
||||
gw_call = mock.call.add_dhcp_subnet().default_gateway("192.168.1.1")
|
||||
subnet_prefix_call = gw_call.subnet_prefix("192.168.1.0")
|
||||
subnet_length_call = subnet_prefix_call.subnet_length(24)
|
||||
|
||||
calls = [gw_call, subnet_prefix_call, subnet_length_call,
|
||||
subnet_length_call.create()]
|
||||
gateway_ip = "192.168.1.1"
|
||||
cidr = "192.168.1.0/24"
|
||||
host_rts = [{'destination': '10.0.0.0/24', 'nexthop': '10.0.0.1'},
|
||||
{'destination': '10.0.1.0/24', 'nexthop': '10.0.1.1'}]
|
||||
dns_servers = ["8.8.8.8", "8.8.4.4"]
|
||||
|
||||
self.client.create_dhcp(bridge, "192.168.1.1", "192.168.1.0/24")
|
||||
bridge.assert_has_calls(calls, any_order=True)
|
||||
dhcp_call = mock.call.add_bridge_dhcp(bridge, gateway_ip, cidr,
|
||||
host_rts=host_rts,
|
||||
dns_servers=dns_servers)
|
||||
|
||||
self.client.create_dhcp(bridge, gateway_ip, cidr, host_rts=host_rts,
|
||||
dns_servers=dns_servers)
|
||||
|
||||
bridge.assert_has_call(dhcp_call)
|
||||
|
||||
def test_add_dhcp_host(self):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user