When building the native dhcp server config we use the dns domain/nameservers from the network/subnet objects. If not defined, we use the global values in the nsxlib config. Now adding optional default parameters to be used instead of global ones. This will enable using different configuration per network availability zone. Change-Id: I38b458e2c530f29a0e5518257ed3041d0610df25changes/45/443045/1
parent
f20ebba9ef
commit
c6f7c2c082
@ -0,0 +1,88 @@
|
||||
# Copyright (c) 2017 VMware, Inc.
|
||||
# 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 vmware_nsxlib.tests.unit.v3 import nsxlib_testcase
|
||||
from vmware_nsxlib.v3 import native_dhcp
|
||||
|
||||
|
||||
# TODO(asarfaty): Add more test cases here
|
||||
class TestNativeDhcp(nsxlib_testcase.NsxLibTestCase):
|
||||
"""Tests for vmware_nsxlib.v3.native_dhcp.NsxLibNativeDhcp."""
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestNativeDhcp, self).setUp()
|
||||
self.handler = native_dhcp.NsxLibNativeDhcp(
|
||||
self.nsxlib.client,
|
||||
nsxlib_testcase.get_default_nsxlib_config())
|
||||
self.net_dns_domain = 'a.com'
|
||||
self.subnet_dns_nameserver = '1.1.1.1'
|
||||
self.default_dns_domain = 'b.com'
|
||||
self.default_dns_nameserver = '2.2.2.2'
|
||||
|
||||
def _get_server_config(self, with_net_dns=True, with_default_dns=True):
|
||||
net = {'name': 'dummy',
|
||||
'id': 'dummy'}
|
||||
subnet = {'dns_nameservers': None,
|
||||
'gateway_ip': '2.2.2.2',
|
||||
'cidr': '5.5.0.0/24',
|
||||
'host_routes': []}
|
||||
port = {'fixed_ips': [{'ip_address': '5.5.0.1'}]}
|
||||
tags = []
|
||||
if with_net_dns:
|
||||
net['dns_domain'] = {'dns_domain': self.net_dns_domain}
|
||||
subnet['dns_nameservers'] = [self.subnet_dns_nameserver]
|
||||
if with_default_dns:
|
||||
result = self.handler.build_server_config(
|
||||
net, subnet, port, tags,
|
||||
default_dns_nameservers=[self.default_dns_nameserver],
|
||||
default_dns_domain=self.default_dns_domain)
|
||||
else:
|
||||
result = self.handler.build_server_config(net, subnet, port, tags)
|
||||
return result
|
||||
|
||||
def test_build_server_config_dns_from_net_no_defaults(self):
|
||||
# Verify that net/subnet dns params are used if exist
|
||||
result = self._get_server_config(with_net_dns=True,
|
||||
with_default_dns=False)
|
||||
self.assertEqual(self.net_dns_domain, result['domain_name'])
|
||||
self.assertEqual([self.subnet_dns_nameserver],
|
||||
result['dns_nameservers'])
|
||||
|
||||
def test_build_server_config_dns_from_net_with_defaults(self):
|
||||
# Verify that net/subnet dns params are used if exist, even if there
|
||||
# are defaults
|
||||
result = self._get_server_config(with_net_dns=True,
|
||||
with_default_dns=True)
|
||||
self.assertEqual(self.net_dns_domain, result['domain_name'])
|
||||
self.assertEqual([self.subnet_dns_nameserver],
|
||||
result['dns_nameservers'])
|
||||
|
||||
def test_build_server_config_dns_from_defaults(self):
|
||||
# Verify that default dns params are used if net/subnet dns params
|
||||
# are missing
|
||||
result = self._get_server_config(with_net_dns=False,
|
||||
with_default_dns=True)
|
||||
self.assertEqual(self.default_dns_domain, result['domain_name'])
|
||||
self.assertEqual([self.default_dns_nameserver],
|
||||
result['dns_nameservers'])
|
||||
|
||||
def test_build_server_config_dns_from_config(self):
|
||||
# Verify that config dns params are used if net/subnet and default
|
||||
# dns params are missing
|
||||
result = self._get_server_config(with_net_dns=False,
|
||||
with_default_dns=False)
|
||||
self.assertEqual(nsxlib_testcase.DNS_DOMAIN, result['domain_name'])
|
||||
self.assertEqual(nsxlib_testcase.DNS_NAMESERVERS,
|
||||
result['dns_nameservers'])
|
Loading…
Reference in new issue