Fix DNS zone serial number retrieval

In case of secondary DNS zones, the serial number
is not available until the zone completes a DNS transfer
from the master.

This patch addresses this issue by adding an extra check to
make sure the Microsoft_SOAType object exists before trying
to access it.

Change-Id: Id006a0aac6d0772b60c51d3a458a7b35aefe8dd3
This commit is contained in:
Alin Balutoiu 2016-08-25 13:42:01 +03:00
parent fb5c5da675
commit a5efe06b24
2 changed files with 12 additions and 0 deletions

View File

@ -259,3 +259,13 @@ class DNSUtilsTestCase(test_base.OsWinBaseTestCase):
self.assertIsNone(serial_number)
mock_zone_exists.assert_called_once_with(mock.sentinel.zone_name)
@mock.patch.object(dnsutils.DNSUtils, 'zone_exists')
def test_get_zone_serial_zone_soatype_not_found(self, mock_zone_exists):
mock_zone_exists.return_value = True
self._dnsutils._dns_manager.MicrosoftDNS_SOAType.return_value = []
serial_number = self._dnsutils.get_zone_serial(mock.sentinel.zone_name)
self.assertIsNone(serial_number)
mock_zone_exists.assert_called_once_with(mock.sentinel.zone_name)

View File

@ -183,6 +183,8 @@ class DNSUtils(baseutils.BaseUtils):
zone_soatype = self._dns_manager.MicrosoftDNS_SOAType(
ContainerName=zone_name)
if not zone_soatype:
return None
# Serial number of the SOA record
SOA = zone_soatype[0].SerialNumber
return int(SOA)