diff --git a/vmware_nsx/extension_drivers/dns_integration.py b/vmware_nsx/extension_drivers/dns_integration.py index b349fe65a4..dedd74ab1e 100644 --- a/vmware_nsx/extension_drivers/dns_integration.py +++ b/vmware_nsx/extension_drivers/dns_integration.py @@ -323,27 +323,34 @@ class DNSExtensionDriverNSXv3(DNSExtensionDriver): self._availability_zones = nsx_az.NsxV3AvailabilityZones() LOG.info("DNSExtensionDriverNSXv3 initialization complete") - def _get_network_az(self, network_id, context): + def _get_network_and_az(self, network_id, context): if not context: context = n_context.get_admin_context() network = self._get_network(context, network_id) if az_def.AZ_HINTS in network and network[az_def.AZ_HINTS]: az_name = network[az_def.AZ_HINTS][0] - return self._availability_zones.get_availability_zone(az_name) - return self._availability_zones.get_default_availability_zone() + az = self._availability_zones.get_availability_zone(az_name) + return network, az + az = self._availability_zones.get_default_availability_zone() + return network, az def _get_dns_domain(self, network_id, context=None): + # first try to get the dns_domain configured on the network + net, az = self._get_network_and_az(network_id, context) + if net.get('dns_domain'): + return _dotted_domain(net['dns_domain']) # try to get the dns-domain from the specific availability zone # of this network - az = self._get_network_az(network_id, context) if (az.dns_domain and _dotted_domain(az.dns_domain) != _dotted_domain(DNS_DOMAIN_DEFAULT)): dns_domain = az.dns_domain + # Global nsx_v3 dns domain elif (cfg.CONF.nsx_v3.dns_domain and (_dotted_domain(cfg.CONF.nsx_v3.dns_domain) != _dotted_domain(DNS_DOMAIN_DEFAULT))): dns_domain = cfg.CONF.nsx_v3.dns_domain + # Global neutron dns domain elif cfg.CONF.dns_domain: dns_domain = cfg.CONF.dns_domain else: diff --git a/vmware_nsx/tests/unit/extension_drivers/test_dns_integration.py b/vmware_nsx/tests/unit/extension_drivers/test_dns_integration.py index 47898554d4..6956bd973d 100644 --- a/vmware_nsx/tests/unit/extension_drivers/test_dns_integration.py +++ b/vmware_nsx/tests/unit/extension_drivers/test_dns_integration.py @@ -100,3 +100,18 @@ class NsxV3DNSIntegrationTestCase(NsxDNSIntegrationTestCase, cfg.CONF.set_override('nsx_extension_drivers', ['vmware_nsxv3_dns']) cfg.CONF.set_override('dns_domain', self._domain, 'nsx_v3') super(NsxV3DNSIntegrationTestCase, self).setUp() + + def test_create_port_dns_domain_name(self): + with self.network(dns_domain=NETWORK_DOMAIN_NAME, + arg_list=(dns.DNSDOMAIN,)) as network,\ + self.subnet(network=network, cidr='10.0.0.0/24') as subnet,\ + self.port(subnet=subnet, dns_name=PORT_DNS_NAME, + arg_list=(dns.DNSNAME,)) as port: + port_data = port['port'] + dns_assignment = port_data[dns.DNSASSIGNMENT][0] + self.assertEqual(PORT_DNS_NAME, port_data[dns.DNSNAME]) + self.assertEqual(PORT_DNS_NAME, dns_assignment['hostname']) + self.assertEqual(port_data['fixed_ips'][0]['ip_address'], + dns_assignment['ip_address']) + self.assertEqual(PORT_DNS_NAME + '.' + NETWORK_DOMAIN_NAME, + dns_assignment['fqdn'])