def test_one_file_svn_lines_changed(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_file) test_file = os.path.join(self.prod_dir, 'test') with open(test_file, 'w+') as fd: fd.write('line 1\n') lc = b.svn_lines_changed(b.PROD_DIR) self.assertEqual((1, 0), lc) b.svn_checkin(lc) with open(test_file, 'w+') as fd: fd.write('line 1\nline 2\n') lc = b.svn_lines_changed(b.PROD_DIR) self.assertEqual((1, 0), lc) b.svn_checkin(lc) with open(test_file, 'w+') as fd: fd.write('line 1\n') lc = b.svn_lines_changed(b.PROD_DIR) self.assertEqual((0, 1), lc) b.svn_checkin(lc)
def test_one_file_svn_lines_changed(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) test_file = os.path.join(self.prod_dir, 'test') with open(test_file, 'w+') as fd: fd.write('line 1\n') lc = b.svn_lines_changed(self.prod_dir) self.assertEqual((1, 0), lc) b.svn_checkin(lc) with open(test_file, 'w+') as fd: fd.write('line 1\nline 2\n') lc = b.svn_lines_changed(self.prod_dir) self.assertEqual((1, 0), lc) b.svn_checkin(lc) with open(test_file, 'w+') as fd: fd.write('line 1\n') lc = b.svn_lines_changed(self.prod_dir) self.assertEqual((0, 1), lc) b.svn_checkin(lc)
def test_two_file_svn_lines_changed(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, ) test1_file = os.path.join(self.prod_dir, "test1") test2_file = os.path.join(self.prod_dir, "test2") with open(test1_file, "w+") as fd: fd.write("line 1.1\n") lc = b.svn_lines_changed(b.PROD_DIR) self.assertEqual((1, 0), lc) b.svn_checkin(lc) with open(test1_file, "w+") as fd: fd.write("line 1.1\nline 1.2\n") with open(test2_file, "w+") as fd: fd.write("line 2.1\nline 2.2\n") lc = b.svn_lines_changed(b.PROD_DIR) self.assertEqual((3, 0), lc) b.svn_checkin(lc) with open(test1_file, "w+") as fd: fd.write("line 1\n") lc = b.svn_lines_changed(b.PROD_DIR) self.assertEqual((1, 2), lc) b.svn_checkin(lc) with open(test1_file, "w+") as fd: fd.write("line 1.1\nline 1.2\n") with open(test2_file, "w+") as fd: fd.write("line 2.3\nline 2.4\n") lc = b.svn_lines_changed(b.PROD_DIR) self.assertEqual((4, 3), lc) b.svn_checkin(lc)
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))