Add option to set undercloud dns nameserver

This adds an undercloud_nameserver option which will be taken into
account in os-net-config to set up the undercloud's nameserver. If left
unset, it will give an empty list to the dns_servers parameter in
os-net-config, which will actually do nothing. If set, it will use that
nameserver as the sole member of a list that is passed to the
aforementioned parameter.

Co-Authored-By: Juan Antonio Osorio Robles <jaosorior@redhat.com>
Change-Id: I2b8a3f64dc1958f00b0471b68ba8283da76a4e7b
This commit is contained in:
Ade Lee 2016-11-22 13:54:25 -05:00 committed by Juan Antonio Osorio Robles
parent 72d8b8079f
commit 2e88f187bb
5 changed files with 34 additions and 1 deletions

View File

@ -121,3 +121,13 @@ class TestValidator(base.BaseTestCase):
save_params = dict(params)
validator.validate_config(params, lambda x: None)
self.assertEqual(save_params, params)
def test_valid_undercloud_nameserver_passes(self):
self.conf.config(undercloud_nameservers=['192.168.24.4',
'192.168.24.5'])
undercloud._validate_network()
def test_invalid_undercloud_nameserver_fails(self):
self.conf.config(undercloud_nameservers=['Iamthewalrus'])
self.assertRaises(validator.FailedValidation,
undercloud._validate_network)

View File

@ -135,6 +135,10 @@ _opts = [
help=('Virtual IP address to use for the admin endpoints of '
'Undercloud services. Only used with SSL.')
),
cfg.ListOpt('undercloud_nameservers',
default=[],
help=('DNS nameserver(s) to use for the undercloud node.'),
),
cfg.StrOpt('undercloud_service_certificate',
default='',
help=('Certificate file to use for OpenStack service SSL '
@ -928,6 +932,8 @@ def _generate_init_data(instack_env):
open(_get_template_path('net-config.json.template')).read()
context['HIERADATA_OVERRIDE'] = hiera_entry
context['UNDERCLOUD_NAMESERVERS'] = json.dumps(
CONF.undercloud_nameservers)
partials = {'net_config': net_config_json}
renderer = pystache.Renderer(partials=partials)
@ -936,6 +942,7 @@ def _generate_init_data(instack_env):
with open(template) as f:
config_json = renderer.render(f.read(), context)
config_json = config_json.replace('&quot;', '"')
cfn_path = '/var/lib/heat-cfntools/cfn-init-data'
tmp_json = tempfile.mkstemp()[1]
with open(tmp_json, 'w') as f:

View File

@ -34,6 +34,18 @@ def validate_config(params, error_callback):
_validate_dhcp_range(local_params, error_callback)
_validate_inspection_range(local_params, error_callback)
_validate_no_overlap(local_params, error_callback)
_validate_ips(local_params, error_callback)
def _validate_ips(params, error_callback):
def is_ip(value, param_name):
try:
netaddr.IPAddress(value)
except netaddr.core.AddrFormatError:
error_callback(
'%s "%s" must be a valid IP address' % (param_name, value))
for ip in params['undercloud_nameservers']:
is_ip(ip, 'undercloud_nameservers')
def _validate_value_formats(params, error_callback):

View File

@ -10,7 +10,8 @@
"type": "interface",
"name": "{{LOCAL_INTERFACE}}",
"primary": "true",
"mtu": {{LOCAL_MTU}}
"mtu": {{LOCAL_MTU}},
"dns_servers": {{UNDERCLOUD_NAMESERVERS}}
}
],
"addresses": [

View File

@ -36,6 +36,9 @@
# services. Only used with SSL. (string value)
#undercloud_admin_vip = 192.168.24.3
# DNS nameserver(s) to use for the undercloud node. (list value)
#undercloud_nameservers =
# Certificate file to use for OpenStack service SSL connections.
# Setting this enables SSL for the OpenStack API endpoints, leaving it
# unset disables SSL. (string value)