def main(): parser = argparse.ArgumentParser(description="DNS Build scripts") parser.add_argument( "--stage-only", dest="STAGE_ONLY", action="store_true", default=False, help="Just build staging and don't " "copy to prod. named-checkzone will still be run.", ) parser.add_argument( "--clobber-stage", dest="CLOBBER_STAGE", action="store_true", default=False, help="If stage " "already exists delete it before running the build " "script.", ) parser.add_argument( "--ship-it", dest="PUSH_TO_PROD", action="store_true", default=False, help="Check files " "into rcs and push upstream.", ) parser.add_argument( "--preserve-stage", dest="PRESERVE_STAGE", action="store_true", default=False, help="Do not " "remove staging area after build completes.", ) parser.add_argument( "--no-build", dest="BUILD_ZONES", action="store_false", default=True, help="Do not " "build zone files." ) parser.add_argument( "--no-syslog", dest="LOG_SYSLOG", action="store_false", default=True, help="Do not " "log to syslog." ) parser.add_argument( "--debug", dest="DEBUG", action="store_true", default=False, help="Print " "copious amounts of text." ) parser.add_argument( "--first-run", dest="FIRST_RUN", action="store_true", default=False, help="Ignore " "all change delta thresholds.", ) nas = parser.parse_args(sys.argv[1:]) b = DNSBuilder(**dict(nas._get_kwargs())) try: b.build_dns() except BuildError as why: b.log("LOG_ERR", why) # fail_mail(message.format(why)) except Exception as err: # Make some noise # fail_mail(message.format(err)) b.log("LOG_CRIT", err) raise
def build_dns(): args = {'FIRST_RUN': False, 'PRESERVE_STAGE': False, 'PUSH_TO_PROD': False, 'BUILD_ZONES': True, 'LOG_SYSLOG': True, 'CLOBBER_STAGE': True, 'STAGE_ONLY': False, 'DEBUG': False } b = DNSBuilder(**args) try: b.build_dns() except BuildError as why: b.log(why, 'LOG_ERR') except Exception as err: b.log(err, 'LOG_CRIT') raise
def build_dns(): args = { 'FIRST_RUN': False, 'PRESERVE_STAGE': False, 'PUSH_TO_PROD': False, 'BUILD_ZONES': True, 'LOG_SYSLOG': True, 'CLOBBER_STAGE': True, 'STAGE_ONLY': False, 'DEBUG': False } b = DNSBuilder(**args) try: b.build_dns() except BuildError as why: b.log('LOG_ERR', why) except Exception as err: b.log('LOG_CRIT', err) raise
def test_build_zone(self): create_fake_zone('asdf1') b = DNSBuilder(STAGE_DIR=self.stage_dir, PROD_DIR=self.prod_dir, LOCK_FILE=self.lock_file, LOG_SYSLOG=False, FIRST_RUN=True, PUSH_TO_PROD=False, STOP_UPDATE_FILE=self.stop_update_file) b.build_dns() create_fake_zone('asdf2') b.build_dns() create_fake_zone('asdf3') create_fake_zone('asdf4') b.build_dns() create_fake_zone('asdf5') b.build_dns()
def test_too_many_config_lines_changed(self): create_fake_zone('asdf86') root_domain1 = create_fake_zone('asdf87') root_domain2 = create_fake_zone('asdf88') root_domain3 = create_fake_zone('asdf89') b = DNSBuilder(STAGE_DIR=self.stage_dir, PROD_DIR=self.prod_dir, LOCK_FILE=self.lock_file, LOG_SYSLOG=False, FIRST_RUN=True, PUSH_TO_PROD=True, STOP_UPDATE_FILE=self.stop_update_file) b.build_dns() for ns in root_domain1.nameserver_set.all(): ns.delete() b.build_dns() # One zone removed should be okay for ns in root_domain2.nameserver_set.all(): ns.delete() for ns in root_domain3.nameserver_set.all(): ns.delete() self.assertRaises(BuildError, b.build_dns)
def test_build_svn(self): print "This will take a while, be patient..." b = DNSBuilder(STAGE_DIR=self.stage_dir, PROD_DIR=self.prod_dir, LOCK_FILE=self.lock_file, LOG_SYSLOG=False, FIRST_RUN=True, PUSH_TO_PROD=True) b.build_dns() #self.svn_info() s = SOA.objects.all() if len(s) > 0: s[0].dirty = True s[0].save() b.build_dns() #self.svn_info() b.build_dns()
def test_build_svn(self): print "This will take a while, be patient..." b = DNSBuilder( STAGE_DIR=self.stage_dir, PROD_DIR=self.prod_dir, LOCK_FILE=self.lock_file, LOG_SYSLOG=False, FIRST_RUN=True, PUSH_TO_PROD=True, ) b.build_dns() # self.svn_info() s = SOA.objects.all() if len(s) > 0: s[0].dirty = True s[0].save() b.build_dns() # self.svn_info() b.build_dns()
def main(): parser = argparse.ArgumentParser(description='DNS Build scripts') parser.add_argument('--stage-only', dest='STAGE_ONLY', action='store_true', default=False, help="Just build staging and don't " "copy to prod. named-checkzone will still be run.") parser.add_argument('--clobber-stage', dest='CLOBBER_STAGE', action='store_true', default=False, help="If stage " "already exists delete it before running the build " "script.") parser.add_argument('--ship-it', dest='PUSH_TO_PROD', action='store_true', default=False, help="Check files " "into rcs and push upstream.") parser.add_argument('--preserve-stage', dest='PRESERVE_STAGE', action='store_true', default=False, help="Do not " "remove staging area after build completes.") parser.add_argument('--no-build', dest='BUILD_ZONES', action='store_false', default=True, help="Do not " "build zone files.") parser.add_argument('--no-syslog', dest='LOG_SYSLOG', action='store_false', default=True, help="Do not " "log to syslog.") parser.add_argument('--debug', dest='DEBUG', action='store_true', default=False, help="Print " "copious amounts of text.") parser.add_argument('--first-run', dest='FIRST_RUN', action='store_true', default=False, help="Ignore " "all change delta thresholds.") nas = parser.parse_args(sys.argv[1:]) b = DNSBuilder(**dict(nas._get_kwargs())) try: b.build_dns() except BuildError as why: b.log('LOG_ERR', why) #fail_mail(message.format(why)) except Exception as err: # Make some noise #fail_mail(message.format(err)) b.log('LOG_CRIT', err) raise
def test_change_a_record(self): root_domain = create_fake_zone('asdfz1') b = DNSBuilder(STAGE_DIR=self.stage_dir, PROD_DIR=self.prod_dir, LOCK_FILE=self.lock_file, LOG_SYSLOG=False, FIRST_RUN=True, PUSH_TO_PROD=False, STOP_UPDATE_FILE=self.stop_update_file) b.build_dns() # This won't check anything in since PUSH_TO_PROD==False self.assertEqual((26, 0), b.svn_lines_changed(b.PROD_DIR)) b.PUSH_TO_PROD = True b.build_dns() # This checked stuff in # no lines should have changed b.build_dns() self.assertEqual((0, 0), b.svn_lines_changed(b.PROD_DIR)) # Now add a record. a, c = AddressRecord.objects.get_or_create( label='', domain=root_domain, ip_str="10.0.0.1", ip_type='4' ) a.views.add(View.objects.get_or_create(name='private')[0]) if not c: a.ttl = 8 a.save() self.assertTrue(SOA.objects.get(pk=root_domain.soa.pk).dirty) tmp_serial = SOA.objects.get(pk=root_domain.soa.pk).serial b.PUSH_TO_PROD = False # Task isn't deleted b.build_dns() # Serial get's incrimented self.assertEqual( SOA.objects.get(pk=root_domain.soa.pk).serial, tmp_serial + 1 ) self.assertFalse(SOA.objects.get(pk=root_domain.soa.pk).dirty) # added new record (1) and new serials (2 for both views), old serials # removed. self.assertEqual((3, 2), b.svn_lines_changed(b.PROD_DIR)) tmp_serial = SOA.objects.get(pk=root_domain.soa.pk).serial self.assertFalse(SOA.objects.get(pk=root_domain.soa.pk).dirty) b.PUSH_TO_PROD = True b.build_dns() self.assertFalse(SOA.objects.get(pk=root_domain.soa.pk).dirty) # Serial is again incremented because PUSH_TO_PROD was False during the # last build. When PUSH_TO_PROD is false, no scheduled tasts are # deleted so we should still see this soa being rebuilt. self.assertEqual( SOA.objects.get(pk=root_domain.soa.pk).serial, tmp_serial + 1 ) self.assertEqual((0, 0), b.svn_lines_changed(b.PROD_DIR)) # no lines should have changed if we would have built again self.assertFalse(SOA.objects.get(pk=root_domain.soa.pk).dirty) tmp_serial = SOA.objects.get(pk=root_domain.soa.pk).serial b.PUSH_TO_PROD = False b.build_dns() self.assertEqual(SOA.objects.get(pk=root_domain.soa.pk).serial, tmp_serial) self.assertFalse(SOA.objects.get(pk=root_domain.soa.pk).dirty) self.assertEqual((0, 0), b.svn_lines_changed(b.PROD_DIR))