On 09/22/2014 01:48 PM, Petr Spacek wrote:
On 22.9.2014 10:38, Martin Kosek wrote:
On 09/22/2014 10:31 AM, Petr Spacek wrote:
On 22.9.2014 10:14, Martin Kosek wrote:
On 09/19/2014 07:29 PM, Petr Viktorin wrote:
https://fedorahosted.org/freeipa/ticket/4551

See ticket & commit message for details.

Shouldn't we add a 1 sec sleep between tries? Wouldn't current
version just
hammer DNS server with as many DNS queries as it can send?

Oh yes, please add some time.sleep() call :-)

Wow, no idea how that slipped out. Thanks for the catch.

Also I would like to see more detailed message:
+        self.log.info('Waiting for hostname %s to be resolvable',
+                      self.replica_fqdn)

=> 'Waiting for hostname %s to be resolvable to A or AAAA record'

<bikeshed>

Really? Shouldn't term "resolvable" already have that covered? A good
software
should work on all network types, whether it is IPv4, IPv6 or IPv8. So I
personally do not think we need to be that specific and can stick to
original
proposal.

I will agree with you if you post magic code which will work with DNS
records for IPv8 :-) The code is not going to work with IPv8 just
because we didn't mention 'A/AAAA' in the error message, A and AAAA
RRtypes are hardcoded in the code.

+1; we're checking A and AAAA so that's what we should say we're doing.

Is this wording OK?


--
Petr³

From 29b751d5791a813f0faccda1c0640ca5a9c3f6df Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Fri, 19 Sep 2014 15:57:44 +0200
Subject: [PATCH] ipa-replica-prepare: Wait for the DNS entry to be resolvable

It takes some time after the DNS record is added until it propagates
to Bind. In automated installations, it might happen that
replica-install is attempted before the hostname is resolvable;
in that case the connection check would fail.

Wait for the name to be resolvable at the end of replica-prepare.
Mention that this can be interrupted (Ctrl+C).
Provide an option to skip the wait.

In case DNS is not managed by IPA, this reminds the admin of the necessary
configuration and checks their work, but it's possible to skip (either by
interrupting it interactively, or by the option).

https://fedorahosted.org/freeipa/ticket/4551
---
 ipaserver/install/ipa_replica_prepare.py | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/ipaserver/install/ipa_replica_prepare.py b/ipaserver/install/ipa_replica_prepare.py
index 2e91ddd92d9eb9ccd690daa1c78d9027f1b0b965..5d3127c1399f18646c2f1c6ff51ed5eae117c0c1 100644
--- a/ipaserver/install/ipa_replica_prepare.py
+++ b/ipaserver/install/ipa_replica_prepare.py
@@ -21,9 +21,12 @@
 import os
 import shutil
 import tempfile
+import time
 from optparse import OptionGroup
 from ConfigParser import SafeConfigParser
 
+import dns.resolver
+
 from ipaserver.install import certs, installutils, bindinstance, dsinstance
 from ipaserver.install.replication import enable_replication_version_checking
 from ipaserver.plugins.ldap2 import ldap2
@@ -64,6 +67,9 @@ def add_options(cls, parser):
         parser.add_option("--ca", dest="ca_file", default=paths.CACERT_P12,
             metavar="FILE",
             help="location of CA PKCS#12 file, default /root/cacert.p12")
+        parser.add_option('--no-wait-for-dns', dest='wait_for_dns',
+            action='store_false', default=True,
+            help="do not wait until the replica is resolvable in DNS")
 
         group = OptionGroup(parser, "SSL certificate options",
             "Only used if the server was installed using custom SSL certificates")
@@ -290,6 +296,8 @@ def run(self):
         if options.ip_address:
             self.add_dns_records()
 
+        self.wait_for_dns()
+
     def copy_ds_certificate(self):
         options = self.options
 
@@ -452,6 +460,37 @@ def add_dns_records(self):
                 raise admintool.ScriptError(
                     "Could not add reverse DNS record for the replica: %s" % e)
 
+    def check_dns(self):
+        """Return true if the replica hostname is resolvable"""
+        resolver = dns.resolver.Resolver()
+        exceptions = dns.resolver.NXDOMAIN, dns.resolver.NoAnswer
+
+        try:
+            dns_answer = resolver.query(self.replica_fqdn, 'A', 'IN')
+        except exceptions:
+            try:
+                dns_answer = resolver.query(self.replica_fqdn, 'AAAA', 'IN')
+            except exceptions:
+                return False
+
+        return True
+
+    def wait_for_dns(self):
+        options = self.options
+
+        if not options.wait_for_dns or self.check_dns():
+            return
+
+        self.log.info('Waiting for %s A or AAAA record to be resolvable',
+                      self.replica_fqdn)
+        print 'This can be safely interrupted (Ctrl+C)'
+
+        try:
+            while not self.check_dns():
+                time.sleep(1)
+        except KeyboardInterrupt:
+            self.log.info('Interrupted')
+
     def copy_info_file(self, source, dest):
         """Copy a file into the info directory
 
-- 
1.9.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to