Add configuration parameter for setting PTG subnet DNS nameservers

Change-Id: Ic5a7a7cf5ff6cff7d32e8337fb5a8d0231f35380
Closes-Bug: 1479460
This commit is contained in:
Magesh GV 2015-07-30 14:40:51 +05:30 committed by mageshgv
parent c763b6524d
commit 1a11f30df9
3 changed files with 41 additions and 3 deletions

View File

@ -1,4 +1,4 @@
[resource_mapping]
# ID of an admin Tenant that will own the service chain instances for this driver.
# chain_tenant_id = <tenant_id>
# DNS nameservers to be used configured in the PTG subnets by this driver.
# dns_nameservers = 8.8.8.7, 8.8.8.8

View File

@ -44,6 +44,16 @@ from gbpservice.neutron.services.grouppolicy.common import exceptions as exc
LOG = logging.getLogger(__name__)
opts = [
cfg.ListOpt('dns_nameservers',
default=[],
help=_("List of DNS nameservers to be configured for the "
"PTG subnets")),
]
cfg.CONF.register_opts(opts, "resource_mapping")
class OwnedPort(model_base.BASEV2):
"""A Port owned by the resource_mapping driver."""
@ -1434,7 +1444,9 @@ class ResourceMappingDriver(api.PolicyDriver):
'enable_dhcp': True,
'gateway_ip': attributes.ATTR_NOT_SPECIFIED,
'allocation_pools': attributes.ATTR_NOT_SPECIFIED,
'dns_nameservers': attributes.ATTR_NOT_SPECIFIED,
'dns_nameservers': (
cfg.CONF.resource_mapping.dns_nameservers or
attributes.ATTR_NOT_SPECIFIED),
'host_routes': attributes.ATTR_NOT_SPECIFIED}
subnet = self._create_subnet(context._plugin_context, attrs)
subnet_id = subnet['id']

View File

@ -505,6 +505,32 @@ class TestPolicyTarget(ResourceMappingTestCase):
data['NeutronError']['type'])
class TestPolicyTargetGroupWithDNSConfiguration(ResourceMappingTestCase):
def setUp(self):
self.dns_servers = ['8.8.8.7', '8.8.8.8']
config.cfg.CONF.set_override('dns_nameservers', self.dns_servers,
group='resource_mapping')
super(TestPolicyTargetGroupWithDNSConfiguration, self).setUp()
def test_subnet_create(self):
ptg = self.create_policy_target_group(name="ptg1")
subnets = ptg['policy_target_group']['subnets']
req = self.new_show_request('subnets', subnets[0], fmt=self.fmt)
subnet = self.deserialize(self.fmt, req.get_response(self.api))
self.assertEqual(self.dns_servers, subnet['subnet']['dns_nameservers'])
class TestPolicyTargetGroupWithoutDNSConfiguration(ResourceMappingTestCase):
def test_subnet_create(self):
ptg = self.create_policy_target_group(name="ptg1")
subnets = ptg['policy_target_group']['subnets']
req = self.new_show_request('subnets', subnets[0], fmt=self.fmt)
subnet = self.deserialize(self.fmt, req.get_response(self.api))
self.assertEqual([], subnet['subnet']['dns_nameservers'])
class TestPolicyTargetGroup(ResourceMappingTestCase):
def _test_implicit_subnet_lifecycle(self, shared=False):