def test_rr_reload(self): h = self.config['handlers'][0] rr = pdyndns.RoundRobinFileHandler(h['qname'], h['qtype'], h['file']) instr = 'Q\t%s\tIN\tA\t-1\t%s\n' % (h['qname'], self.addrs) outstr = 'DATA\t0\t1\t%s\tIN\tA\t0\t-1\t10.0.0.1\n' % h['qname'] outstr += 'END\n' fdout = StringIO() pdyndns.process_query(instr, [rr], fdout) self.assertEqual(fdout.getvalue(), outstr) with tempfile.NamedTemporaryFile() as fd: # Overwrite t1.txt with t2.txt shutil.copy(h['file'], fd.name) shutil.copy(self.config['handlers'][1]['file'], h['file']) instr = 'Q\t%s\tIN\tA\t-1\t%s\n' % (h['qname'], self.addrs) outstr = 'DATA\t0\t1\t%s\tIN\tA\t0\t-1\t10.1.0.1\n' % h['qname'] outstr += 'END\n' fdout = StringIO() pdyndns.process_query(instr, [rr], fdout) self.assertEqual(fdout.getvalue(), outstr) # Restore shutil.copy(fd.name, h['file']) instr = 'Q\t%s\tIN\tA\t-1\t%s\n' % (h['qname'], self.addrs) outstr = 'DATA\t0\t1\t%s\tIN\tA\t0\t-1\t10.0.0.1\n' % h['qname'] outstr += 'END\n' fdout = StringIO() pdyndns.process_query(instr, [rr], fdout) self.assertEqual(fdout.getvalue(), outstr) rr.close()
def test_rr(self): handlers = [ pdyndns.RoundRobinFileHandler(h['qname'], h['qtype'], h['file']) for h in self.config['handlers'] ] names = [h['qname'] for h in self.config['handlers']] names += ['unknown.dyndns.example.net'] for name in names[0:2]: instr = 'Q\t%s\tIN\tANY\t-1\t%s\n' % (name, self.addrs) outstr = 'DATA\t0\t1\t%s\tIN\tA\t0\t-1\t' % name fdout = StringIO() pdyndns.process_query(instr, handlers, fdout) self.assertTrue(fdout.getvalue().startswith(outstr)) self.assertTrue(fdout.getvalue().endswith('END\n')) for name in names[2:3]: instr = 'Q\t%s\tIN\tANY\t-1\t%s\n' % (name, self.addrs) outstr = 'DATA\t0\t1\t%s\tIN\tAAAA\t0\t-1\t' % name fdout = StringIO() pdyndns.process_query(instr, handlers, fdout) self.assertTrue(fdout.getvalue().startswith(outstr)) self.assertTrue(fdout.getvalue().endswith('END\n')) for name in names[3:4]: instr = 'Q\t%s\tIN\tANY\t-1\t%s\n' % (name, self.addrs) fdout = StringIO() pdyndns.process_query(instr, handlers, fdout) self.assertEqual(fdout.getvalue(), 'END\n') for handler in handlers: handler.close()