ascension

Migrate DNS zones to the GNU Name System
Log | Files | Refs | README | LICENSE

commit 8d952a71d8e466f39e541df97be90186f77a2704
parent 1ff17a356bfb2aeae3eb4dfa45b0c2400be962a6
Author: rexxnor <rexxnor+gnunet@brief.li>
Date:   Thu, 25 Oct 2018 15:36:11 +0200

added warnings to logging if records failed to be added

Diffstat:
Mgnsmigrator/gnsmigrator.py | 148++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 86 insertions(+), 62 deletions(-)

diff --git a/gnsmigrator/gnsmigrator.py b/gnsmigrator/gnsmigrator.py @@ -25,6 +25,7 @@ from ctypes import c_uint64 from ctypes import c_void_p from enum import Enum from dataclasses import dataclass +import logging import queue import re import sys @@ -34,7 +35,6 @@ import dns.query import dns.resolver import dns.zone import docopt -import logging # GLOBALS GNUNET_ZONE_CREATION_COMMAND = 'gnunet-identity' @@ -115,12 +115,12 @@ class GNSMigrator(): pkey_line.stdout.close() # Create identity in GNUnet try: - ret = sp.run([GNUNET_ZONE_CREATION_COMMAND, - '-C', domainpart], - stdout=sp.DEVNULL, - stderr=sp.DEVNULL) + sp.run([GNUNET_ZONE_CREATION_COMMAND, + '-C', domainpart], + stdout=sp.DEVNULL, + stderr=sp.DEVNULL) except sp.CalledProcessError: - logging.info("Zone %s already exists!" % domainpart) + logging.info("Zone %s already exists!", domainpart) pkey_lookup = sp.Popen([GNUNET_ZONE_CREATION_COMMAND, '-d'], stdout=sp.PIPE) @@ -142,12 +142,17 @@ class GNSMigrator(): reverse_parsing[counter - 1])]) if "No results." in result.decode(): - sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', reverse_parsing[counter - 1], - '-a', '-n', domainpart, - '-t', 'PKEY', - '-V', pkey_zone, - '-e', 'never']) + ret = sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', reverse_parsing[counter - 1], + '-a', '-n', domainpart, + '-t', 'PKEY', + '-V', pkey_zone, + '-e', 'never']) + if ret.returncode != 0: + logging.warning("failed to add record %s", domainpart) + logging.warning("failed to add %s record %s", + "PKEY", domainpart) + counter += 1 @staticmethod @@ -158,12 +163,15 @@ class GNSMigrator(): if not GNSMigrator.check_if_record_exists_in_zone(record, zonename): dnsname, ttl, rdata = record rtype_str = str(dns.rdatatype.to_text(rdata.rdtype)) - sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-a', '-n', str(dnsname), - '-t', rtype_str, - '-V', str(rdata), - '-e', '%ds' % ttl]) + ret = sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', str(dnsname), + '-t', rtype_str, + '-V', str(rdata), + '-e', '%ds' % ttl]) + if ret.returncode != 0: + logging.warning("failed to add %s record %s", + rtype_str, str(dnsname)) @staticmethod def add_srv_record_to_gns(record, zonename): @@ -182,12 +190,15 @@ class GNSMigrator(): '-V', str(value), '-e', '%ds' % ttl]) print(debug) - sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-a', '-n', dnsname_str, - '-t', rtype_str, - '-V', str(value), - '-e', '%ds' % ttl]) + ret = sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', dnsname_str, + '-t', rtype_str, + '-V', str(value), + '-e', '%ds' % ttl]) + if ret.returncode != 0: + logging.warning("failed to add %s record %s", + rtype_str, dnsname_str) @staticmethod def add_a_aaaa_record_to_gns(record, zonename, domain): @@ -197,18 +208,24 @@ class GNSMigrator(): if not GNSMigrator.check_if_record_exists_in_zone(record, zonename): dnsname, ttl, rdata = record rtype_str = str(dns.rdatatype.to_text(rdata.rdtype)) - sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-a', '-n', str(dnsname), - '-t', rtype_str, - '-V', str(rdata), - '-e', '%ds' % ttl]) - sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-a', '-n', str(dnsname), - '-t', 'LEHO', - '-V', '%s.%s' % (str(dnsname), domain), - '-e', '%ds' % ttl]) + ret = sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', str(dnsname), + '-t', rtype_str, + '-V', str(rdata), + '-e', '%ds' % ttl]) + if ret.returncode != 0: + logging.warning("failed to add %s record %s", + rtype_str, str(dnsname)) + ret = sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', str(dnsname), + '-t', 'LEHO', + '-V', '%s.%s' % (str(dnsname), domain), + '-e', '%ds' % ttl]) + if ret.returncode != 0: + logging.warning("failed to add %s record %s", + "LEHO", str(dnsname)) @staticmethod def add_soa_record_to_gns(record, zonename, domain): @@ -224,16 +241,18 @@ class GNSMigrator(): authns = authns[:-1] if owner[-1] == '.': owner = owner[:-1] - sp.call([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-a', '-n', '@', - '-t', 'SOA', - '-V', "rname=%s.%s mname=%s.%s %d,%d,%d,%d,%d" - % (authns, domain, owner, domain, - int(serial), int(refresh), int(retry), - int(expiry), int(irefresh) - ), - '-e', '%ds' % ttl]) + ret = sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', '@', + '-t', 'SOA', + '-V', "rname=%s.%s mname=%s.%s %d,%d,%d,%d,%d" + % (authns, domain, owner, domain, + int(serial), int(refresh), int(retry), + int(expiry), int(irefresh) + ), + '-e', '%ds' % ttl]) + if ret.returncode != 0: + logging.warning("failed to add %s record %s", "SOA", "@") @staticmethod def add_ns_record_to_gns(record, zonename, domain): @@ -270,13 +289,16 @@ class GNSMigrator(): '-u', '%s.%s' % (str(dnsname), zonename)], stdout=sp.PIPE) if 'Got'.encode() not in ret.stdout: - sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-a', '-n', str(dnsname), - '-t', 'GNS2DNS', - '-V', '%s.%s@%s' % - (str(dnsname), domain, dnsresolver), - '-e', '%ds' % ttl]) + ret = sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', str(dnsname), + '-t', 'GNS2DNS', + '-V', '%s.%s@%s' % + (str(dnsname), domain, dnsresolver), + '-e', '%ds' % ttl]) + if ret.returncode != 0: + logging.warning("failed to add %s record %s", + "GNS2DNS", str(dnsname)) @staticmethod def add_mx_record_to_gns(record, zonename): @@ -287,12 +309,15 @@ class GNSMigrator(): if not GNSMigrator.check_if_record_exists_in_zone(record, zonename): rdatalist = str(rdata).split(' ') value = '%s,%s' % (rdatalist[0], rdatalist[1]) - sp.run([GNUNET_NAMESTORE_COMMAND, - '-z', zonename, - '-a', '-n', str(dnsname), - '-t', dns.rdatatype.to_text(rdata.rdtype), - '-V', value, - '-e', '%ds' % int(ttl)]) + ret = sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', str(dnsname), + '-t', dns.rdatatype.to_text(rdata.rdtype), + '-V', value, + '-e', '%ds' % int(ttl)]) + if ret.returncode != 0: + logging.warning("failed to add %s record %s", + "GNS2DNS", str(dnsname)) @staticmethod def check_if_record_exists_in_zone(record, zonename): @@ -306,7 +331,7 @@ class GNSMigrator(): '-u', '%s.%s' % (dnsname, zonename)] ) - if 'Got '.encode() in ret: + if 'Got ' in ret.decode(): return True return False @@ -484,8 +509,7 @@ class GNSMigrator(): elif rtype_str in ['TXT', 'CNAME']: GNSMigrator.add_gen_record_to_gns(record, zonename) else: - logging.warning("Record type %s is not yet supported", rtype_str) - + logging.warning("Unsupported record type: %s", rtype_str) def main(): """