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') create_fake_zone('asdf90') 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) self.assertTrue(Task.dns_full.all()) self.assertFalse(Task.dns_incremental.all().count()) b.build_dns() self.assertFalse(Task.dns_full.all()) self.assertFalse(Task.dns_incremental.all()) # deleting one ns for ns in root_domain1.nameserver_set.all(): ns.delete() self.assertTrue(Task.dns_full.all()) self.assertEqual(1, Task.dns_incremental.all().count()) 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() b.PUSH_TO_PROD = True self.assertRaises(BuildError, 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') create_fake_zone('asdf90') 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) self.assertTrue(Task.dns_full.all()) self.assertFalse(Task.dns_incremental.all().count()) b.build_dns() self.assertFalse(Task.dns_full.all()) self.assertFalse(Task.dns_incremental.all()) # deleting one ns for ns in root_domain1.nameserver_set.all(): ns.delete() self.assertTrue(Task.dns_full.all()) self.assertEqual(1, Task.dns_incremental.all().count()) 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() b.PUSH_TO_PROD = True self.assertRaises(BuildError, b.build_dns)
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((28, 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))
def test_change_a_record(self): 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, ) b.svn_lines_changed(b.PROD_DIR) b.PUSH_TO_PROD = False root_domain = create_fake_zone("asdfz1") b.build_dns() # This won't check anything in since PUSH_TO_PROD==False self.assertEqual((28, 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() # We just updated a zone so a full build shouldn't be triggered self.assertFalse(Task.dns_full.all()) # we should see one zone being rebuilt self.assertEqual(1, Task.dns_incremental.all().count()) 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 # Since push-to-prod is false, we should still see the tasks in the # same state self.assertFalse(Task.dns_full.all()) self.assertEqual(1, Task.dns_incremental.all().count()) self.assertEqual(SOA.objects.get(pk=root_domain.soa.pk).serial, tmp_serial + 1) # The dirty bit should still be true because we didn't check things in self.assertTrue(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 b.PUSH_TO_PROD = True b.build_dns() # Since push-to-prod is true all tasks should be back 0 self.assertFalse(Task.dns_full.all()) self.assertFalse(Task.dns_incremental.all()) 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. # 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() # Nothing changed self.assertFalse(Task.dns_full.all()) self.assertFalse(Task.dns_incremental.all()) 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))
def test_change_a_record(self): 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) b.svn_lines_changed(b.PROD_DIR) b.PUSH_TO_PROD = False root_domain = create_fake_zone('asdfz1') b.build_dns() # This won't check anything in since PUSH_TO_PROD==False self.assertEqual((28, 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() # We just updated a zone so a full build shouldn't be triggered self.assertFalse(Task.dns_full.all()) # we should see one zone being rebuilt self.assertEqual(1, Task.dns_incremental.all().count()) 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 # Since push-to-prod is false, we should still see the tasks in the # same state self.assertFalse(Task.dns_full.all()) self.assertEqual(1, Task.dns_incremental.all().count()) self.assertEqual( SOA.objects.get(pk=root_domain.soa.pk).serial, tmp_serial + 1) # The dirty bit should still be true because we didn't check things in self.assertTrue(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 b.PUSH_TO_PROD = True b.build_dns() # Since push-to-prod is true all tasks should be back 0 self.assertFalse(Task.dns_full.all()) self.assertFalse(Task.dns_incremental.all()) 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. # 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() # Nothing changed self.assertFalse(Task.dns_full.all()) self.assertFalse(Task.dns_incremental.all()) 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))