PEP8: fix E241: multiple spaces after ','
[samba.git] / python / samba / tests / samba_tool / dnscmd.py
index 9b942e59ff7de003b89c671deda38fb8a4cfe8a0..9bbc65827c54c44be00c69bdf0df7a7778796e07 100644 (file)
@@ -44,7 +44,7 @@ class DnsCmdTestCase(SambaToolCmdTest):
 
         good_dns = ["SAMDOM.EXAMPLE.COM",
                     "1.EXAMPLE.COM",
-                    "%sEXAMPLE.COM" % ("1."*100),
+                    "%sEXAMPLE.COM" % ("1." * 100),
                     "EXAMPLE",
                     "\n.COM",
                     "!@#$%^&*()_",
@@ -67,7 +67,7 @@ class DnsCmdTestCase(SambaToolCmdTest):
         good_srv = ["SAMDOM.EXAMPLE.COM 65530 65530 65530"]
         bad_srv = ["SAMDOM.EXAMPLE.COM 0 65536 0",
                    "SAMDOM.EXAMPLE.COM 0 0 65536",
-                   "SAMDOM.EXAMPLE.COM 65536 0 0" ]
+                   "SAMDOM.EXAMPLE.COM 65536 0 0"]
 
         for bad_dn in bad_dns:
             bad_mx.append("%s 1" % bad_dn)
@@ -88,12 +88,12 @@ class DnsCmdTestCase(SambaToolCmdTest):
                         "::1",
                         "::",
                         "1:1:1:1:1:1:1:1"],
-                "PTR":good_dns,
-                "CNAME":good_dns,
-                "NS":good_dns,
-                "MX":good_mx,
-                "SRV":good_srv,
-                "TXT":["text", "", "@#!", "\n"]
+                "PTR": good_dns,
+                "CNAME": good_dns,
+                "NS": good_dns,
+                "MX": good_mx,
+                "SRV": good_srv,
+                "TXT": ["text", "", "@#!", "\n"]
         }
 
         self.bad_records = {
@@ -105,11 +105,11 @@ class DnsCmdTestCase(SambaToolCmdTest):
                         "1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0:1234",
                         "1234:5678:9ABC:DEF0:1234:5678:9ABC",
                         "1111::1111::1111"],
-                "PTR":bad_dns,
-                "CNAME":bad_dns,
-                "NS":bad_dns,
-                "MX":bad_mx,
-                "SRV":bad_srv
+                "PTR": bad_dns,
+                "CNAME": bad_dns,
+                "NS": bad_dns,
+                "MX": bad_mx,
+                "SRV": bad_srv
         }
 
     def tearDown(self):
@@ -189,7 +189,7 @@ class DnsCmdTestCase(SambaToolCmdTest):
             self.assertTrue("testrecord" in out and record_str in out,
                             "Query for a record which had DNS_RANK_NONE" \
                             "succeeded but produced no resulting records.")
-        except AssertionError, e:
+        except AssertionError as e:
             # Windows produces no resulting records
             pass
 
@@ -200,7 +200,7 @@ class DnsCmdTestCase(SambaToolCmdTest):
         try:
             self.assertCmdFail(result, "Successfully added duplicate record" \
                                "of one which had DNS_RANK_NONE.")
-        except AssertionError, e:
+        except AssertionError as e:
             errors.append(e)
 
         # We should be able to delete it
@@ -210,7 +210,7 @@ class DnsCmdTestCase(SambaToolCmdTest):
         try:
             self.assertCmdSuccess(result, out, err, "Failed to delete record" \
                                   "which had DNS_RANK_NONE.")
-        except AssertionError, e:
+        except AssertionError as e:
             errors.append(e)
 
         # Now the record should not exist
@@ -220,7 +220,7 @@ class DnsCmdTestCase(SambaToolCmdTest):
         try:
             self.assertCmdFail(result, "Successfully queried for deleted record" \
                                "which had DNS_RANK_NONE.")
-        except AssertionError, e:
+        except AssertionError as e:
             errors.append(e)
 
         if len(errors) > 0:
@@ -706,6 +706,56 @@ class DnsCmdTestCase(SambaToolCmdTest):
             for record in records:
                 self.assertEqual(str(record['dNSTombstoned']), 'TRUE')
 
+    def test_cleanup_record_no_A_record(self):
+        """
+        Test dns cleanup command works with no A record.
+        """
+
+        # add a A record
+        self.runsubcmd("dns", "add", os.environ["SERVER"], self.zone,
+                       'notesta', "A", self.testip, self.creds_string)
+
+        # the above A record points to this host
+        dnshostname = '{}.{}'.format('testa', self.zone.lower())
+
+        # add a CNAME record points to above host
+        self.runsubcmd("dns", "add", os.environ["SERVER"], self.zone,
+                       'notestcname', "CNAME", dnshostname, self.creds_string)
+
+        # add a NS record
+        self.runsubcmd("dns", "add", os.environ["SERVER"], self.zone,
+                       'notestns', "NS", dnshostname, self.creds_string)
+
+        # add a PTR record points to above host
+        self.runsubcmd("dns", "add", os.environ["SERVER"], self.zone,
+                       'notestptr', "PTR", dnshostname, self.creds_string)
+
+        # add a SRV record points to above host
+        srv_record = "{} 65530 65530 65530".format(dnshostname)
+        self.runsubcmd("dns", "add", os.environ["SERVER"], self.zone,
+                       'notestsrv', "SRV", srv_record, self.creds_string)
+
+        # Remove the initial A record (leading to hanging references)
+        self.runsubcmd("dns", "delete", os.environ["SERVER"], self.zone,
+                       'notesta', "A", self.testip, self.creds_string)
+
+        # cleanup record for this dns host
+        self.runsubcmd("dns", "cleanup", os.environ["SERVER"],
+                       dnshostname, self.creds_string)
+
+        # all records should be marked as dNSTombstoned
+        for record_name in ['notestcname', 'notestns', 'notestptr', 'notestsrv']:
+
+            records = self.samdb.search(
+                base="DC=DomainDnsZones,{}".format(self.samdb.get_default_basedn()),
+                scope=ldb.SCOPE_SUBTREE,
+                expression="(&(objectClass=dnsNode)(name={}))".format(record_name),
+                attrs=["dNSTombstoned"])
+
+            self.assertEqual(len(records), 1)
+            for record in records:
+                self.assertEqual(str(record['dNSTombstoned']), 'TRUE')
+
     def test_cleanup_multi_srv_record(self):
         """
         Test dns cleanup command for multi-valued SRV record.
@@ -750,7 +800,7 @@ class DnsCmdTestCase(SambaToolCmdTest):
             base="DC=DomainDnsZones,{}".format(self.samdb.get_default_basedn()),
             scope=ldb.SCOPE_SUBTREE,
             expression="(&(objectClass=dnsNode)(name={}))".format(srv_name),
-            attrs=['dnsRecord'])
+            attrs=['dnsRecord', 'dNSTombstoned'])
 
         # dnsRecord for host1 should be deleted
         self.assertEqual(len(records[0]['dnsRecord']), 1)
@@ -763,14 +813,18 @@ class DnsCmdTestCase(SambaToolCmdTest):
         dnshostname2 = 'host2.{}'.format(self.zone.lower())
         self.assertEqual(dns_record_obj.data.nameTarget, dnshostname2)
 
+        # assert that the record isn't spuriously tombstoned
+        self.assertTrue('dNSTombstoned' not in records[0] or
+                        str(record['dNSTombstoned']) == 'FALSE')
+
     def test_dns_wildcards(self):
         """
         Ensure that DNS wild card entries can be added deleted and queried
         """
         num_failures = 0
         failure_msgs = []
-        records = [("*.",       "MISS",         "A", "1.1.1.1"),
-                   ("*.SAMDOM", "MISS.SAMDOM",  "A", "1.1.1.2")]
+        records = [("*.", "MISS", "A", "1.1.1.1"),
+                   ("*.SAMDOM", "MISS.SAMDOM", "A", "1.1.1.2")]
         for (name, miss, dnstype, record) in records:
             try:
                 result, out, err = self.runsubcmd("dns", "add",