From a5efe06b243759e144d8c70dc06c97912e8cc98c Mon Sep 17 00:00:00 2001 From: Alin Balutoiu Date: Thu, 25 Aug 2016 13:42:01 +0300 Subject: [PATCH] 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 --- os_win/tests/utils/dns/test_dnsutils.py | 10 ++++++++++ os_win/utils/dns/dnsutils.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/os_win/tests/utils/dns/test_dnsutils.py b/os_win/tests/utils/dns/test_dnsutils.py index c8dd9974..e6b42611 100644 --- a/os_win/tests/utils/dns/test_dnsutils.py +++ b/os_win/tests/utils/dns/test_dnsutils.py @@ -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) diff --git a/os_win/utils/dns/dnsutils.py b/os_win/utils/dns/dnsutils.py index 4f9ff244..f872282c 100644 --- a/os_win/utils/dns/dnsutils.py +++ b/os_win/utils/dns/dnsutils.py @@ -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)