class StaticIntrV6APITests(CydnsAPITests, ResourceTestCase): test_type = StaticInterface def setUp(self): Domain.objects.get_or_create(name='arpa') Domain.objects.get_or_create(name='ipv6.arpa') Domain.objects.get_or_create(name='2.ipv6.arpa') super(StaticIntrV6APITests, self).setUp() self.s = System(hostname="foobar") self.s.save() def compare_data(self, old_data, new_obj_data): for key in old_data.keys(): if key == 'iname' or key == 'system': continue # StaticInterface needs this done. Too lazy to factor # a comparison function out self.assertEqual(old_data[key], new_obj_data[key]) def post_data(self): return { 'comment': random_label(), 'ttl': random_byte(), 'label': 'p' + random_label(), 'iname': 'mgmt4', 'dhcp_enabled': True, 'dns_enabled': True, 'mac': '11:22:33:44:55:00', 'system': '/tasty/systems/system/{0}/'.format(self.s.pk), 'domain': self.domain.name, 'ip_str': "2000:a{0}:a{1}:a{2}::".format(random_byte(), random_byte(), random_byte()), 'ip_type': '6' }
def setUp(self): Domain.objects.get_or_create(name='arpa') Domain.objects.get_or_create(name='ipv6.arpa') Domain.objects.get_or_create(name='2.ipv6.arpa') super(StaticIntrV6APITests, self).setUp() self.s = System(hostname="foobar") self.s.save()
def setUp(self): Domain.objects.get_or_create(name="arpa") Domain.objects.get_or_create(name="in-addr.arpa") self.r1, _ = Domain.objects.get_or_create(name="10.in-addr.arpa") self.sr, sr_c = SOA.objects.get_or_create(primary="ns1.foo.gaz", contact= "hostmaster.foo", comment="123foo.gazsdi2") self.r1.soa = self.sr self.r1.save() s1, s1_c = SOA.objects.get_or_create(primary="ns1.foo.gaz", contact= "hostmaster.dfdfoo", comment="123fooasdfsdfasdfsa.gaz2") self.soa = s1 d, _ = Domain.objects.get_or_create(name="bgaz") d.soa = s1 d.save() self.dom = d self.soa.dirty = False self.dom.dirty = False s2, s1_c = SOA.objects.get_or_create(primary="ns1.foo.gaz", contact= "hostmaster.foo", comment="123fooasdfsdf.gaz2") self.rsoa = s2 rd, _ = Domain.objects.get_or_create(name="123.in-addr.arpa") rd.soa = s2 rd.save() self.rdom = rd self.rsoa.dirty = False self.rdom.dirty = False self.s = System() self.s.save()
class DeleteStaticInterTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() View.objects.get_or_create(name="private") def do_add(self, mac, label, domain, ip_str, system, ip_type='4'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=system) r.clean() r.save() return r def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse( AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_delete_basic(self): # Does deleting a system delete it's interfaces? mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" system = System(hostname="foo") system.save() kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str, 'system': system} i = self.do_add(**kwargs) intr_pk = i.pk self.assertTrue(StaticInterface.objects.filter(**kwargs)) system.delete() self.assertFalse(StaticInterface.objects.filter(**kwargs))
def do_add(self, mac, label, domain, ip_str, ip_type='4'): self.n = System() r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() repr(r) return r
def test1_delete_basic(self): # Does deleting a system delete it's interfaces? mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" system = System(hostname="foo") system.save() kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str, 'system': system} i = self.do_add(**kwargs) intr_pk = i.pk self.assertTrue(StaticInterface.objects.filter(**kwargs)) system.delete() self.assertFalse(StaticInterface.objects.filter(**kwargs))
def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save()
def test_cleanup_intr(self): self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo")) self.assertFalse(Domain.objects.filter(name="y.z.foo.poo")) self.assertFalse(Domain.objects.filter(name="z.foo.poo")) self.assertTrue(Domain.objects.filter(name="foo.poo")) Domain.objects.get_or_create(name="arpa") Domain.objects.get_or_create(name="in-addr.arpa") Domain.objects.get_or_create(name="10.in-addr.arpa") fqdn = "bar.x.y.z.foo.poo" label, the_domain = ensure_label_domain(fqdn) system = System() addr = StaticInterface(label=label, domain=the_domain, ip_type='4', ip_str="10.2.3.4", mac="00:11:22:33:44:55", system=system) addr.save() self.assertFalse(prune_tree(the_domain)) addr.delete() self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo")) self.assertFalse(Domain.objects.filter(name="y.z.foo.poo")) self.assertFalse(Domain.objects.filter(name="z.foo.poo")) self.assertTrue(Domain.objects.filter(name="foo.poo"))
def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() View.objects.get_or_create(name="private")
def setUp(self): primary = "ns5.oregonstate.edu" contact = "admin.oregonstate.edu" retry = 1234 refresh = 1234123 self.soa = SOA(primary=primary, contact=contact, retry=retry, refresh=refresh) self.soa.save() self.g = Domain(name="gz") self.g.save() self.c_g = Domain(name="coo.gz") self.c_g.soa = self.soa self.c_g.save() self.d = Domain(name="dz") self.d.save() self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.r1 = self.create_domain(name="10") self.r1.save() self.s = System() self.s.save()
class StaticIntrV4APITests(CydnsAPITests, ResourceTestCase): test_type = StaticInterface def setUp(self): Domain.objects.get_or_create(name='arpa') Domain.objects.get_or_create(name='in-addr.arpa') Domain.objects.get_or_create(name='11.in-addr.arpa') super(StaticIntrV4APITests, self).setUp() self.s = System(hostname="foobar") self.s.save() def compare_data(self, old_data, new_obj_data): for key in old_data.keys(): if key == 'system_hostname': self.assertEqual( old_data[key], new_obj_data['system']['hostname']) continue if key in ('iname', 'system'): continue # StaticInterface needs this done. Too lazy to factor # a comparison function out self.assertEqual(old_data[key], new_obj_data[key]) def test_create_hostname(self): post_data = self.post_data() del post_data['system'] post_data['system_hostname'] = self.s.hostname resp, post_data = self.generic_create(post_data) _, (_, new_object_url) = resp.items() new_resp = self.api_client.get(new_object_url, format='json') self.assertValidJSONResponse(new_resp) new_obj_data = json.loads(new_resp.content) self.compare_data(post_data, new_obj_data) def post_data(self): return { 'comment': 'm' + random_label(), 'ttl': random_byte(), 'mac': '11:22:33:44:55:00', 'system': '/tasty/systems/system/{0}/'.format(self.s.pk), 'label': 'a' + random_label(), 'iname': 'eth2.4', 'dhcp_enabled': False, 'dns_enabled': True, 'domain': self.domain.name, 'ip_str': "11.255.{0}.{1}".format(random_byte(), random_byte()), 'ip_type': '4' }
class StaticIntrV4APITests(CydnsAPITests, ResourceTestCase): test_type = StaticInterface def setUp(self): Domain.objects.get_or_create(name='arpa') Domain.objects.get_or_create(name='in-addr.arpa') Domain.objects.get_or_create(name='11.in-addr.arpa') super(StaticIntrV4APITests, self).setUp() self.s = System(hostname="foobar") self.s.save() def compare_data(self, old_data, new_obj_data): for key in old_data.keys(): if key == 'system_hostname': self.assertEqual(old_data[key], new_obj_data['system']['hostname']) continue if key in ('iname', 'system'): continue # StaticInterface needs this done. Too lazy to factor # a comparison function out self.assertEqual(old_data[key], new_obj_data[key]) def test_create_hostname(self): post_data = self.post_data() del post_data['system'] post_data['system_hostname'] = self.s.hostname resp, post_data = self.generic_create(post_data) _, (_, new_object_url) = resp.items() new_resp = self.api_client.get(new_object_url, format='json') self.assertValidJSONResponse(new_resp) new_obj_data = json.loads(new_resp.content) self.compare_data(post_data, new_obj_data) def post_data(self): return { 'comment': 'm' + random_label(), 'ttl': random_byte(), 'mac': '11:22:33:44:55:00', 'system': '/tasty/systems/system/{0}/'.format(self.s.pk), 'label': 'a' + random_label(), 'iname': 'eth2.4', 'dhcp_enabled': False, 'dns_enabled': True, 'domain': self.domain.name, 'ip_str': "11.255.{0}.{1}".format(random_byte(), random_byte()), 'ip_type': '4' }
def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='ipv6.arpa', ip_type='6') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="0", ip_type='6') self.r1.save() self.r2 = self.create_domain(name="1", ip_type='6') self.r2.save() self.n = System() self.n.clean() self.n.save()
def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.i6_arpa = self.create_domain(name='ipv6.arpa') self.i6_arpa.save() self.r = Domain(name="ru") self.r.save() self.f_r = Domain(name="foo.ru") self.f_r.save() self.b_f_r = Domain(name="bar.foo.ru") self.b_f_r.save() self.f = Domain(name="fam") self.f.save() self._128 = self.create_domain(name='128', ip_type='4') self._128.save() self.s = System() self.s.save()
def setUp(self): self.o = Domain(name="org") self.o.save() self.f_o = Domain(name="foo.org") self.f_o.save() self.s = System() Domain.objects.get_or_create(name="arpa") Domain.objects.get_or_create(name="in-addr.arpa") Domain.objects.get_or_create(name="10.in-addr.arpa") Domain.objects.get_or_create(name="172.in-addr.arpa") Domain.objects.get_or_create(name="192.in-addr.arpa") self.public, _ = View.objects.get_or_create(name="public") self.private, _ = View.objects.get_or_create(name="private")
def test1_freeip(self): start_str = "10.0.33.1" end_str = "10.0.33.3" default_domain = self.d network = self.s rtype = 's' ip_type = '4' system = System() kwargs = { 'start_str': start_str, 'end_str': end_str, 'default_domain': default_domain, 'network': network, 'rtype': rtype, 'ip_type': ip_type } r = self.do_add(**kwargs) self.assertEqual(str(r.get_next_ip()), "10.0.33.1") self.assertEqual(str(r.get_next_ip()), "10.0.33.1") s = StaticInterface(label="foo", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system, mac="00:00:00:00:00:00") s.clean() s.save() self.assertEqual(str(r.get_next_ip()), "10.0.33.2") s = StaticInterface(label="foo", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system, mac="00:00:00:00:00:00") s.clean() s.save() self.assertEqual(str(r.get_next_ip()), "10.0.33.3") s = StaticInterface(label="foo", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system, mac="00:00:00:00:00:00") s.clean() s.save() self.assertEqual(r.get_next_ip(), None)
def setUp(self): self.system = System() Domain.objects.get_or_create(name="com") d1, _ = Domain.objects.get_or_create(name="mozilla.com") soa, _ = SOA.objects.get_or_create(primary="fo.bar", contact="foo.bar.com", comment="foo bar") self.s = soa d1.soa = soa d1.save() v, _ = Vlan.objects.get_or_create(name="private", number=3) s, _ = Site.objects.get_or_create(name="phx1") s1, _ = Site.objects.get_or_create(name="corp", parent=s) d, _ = Domain.objects.get_or_create(name="phx1.mozilla.com") d.soa = soa d.save() d1, _ = Domain.objects.get_or_create(name="corp.phx1.mozilla.com") d1.soa = soa d1.save() d2, _ = Domain.objects.get_or_create( name="private.corp.phx1.mozilla.com") d2.soa = soa d2.save() d, _ = Domain.objects.get_or_create(name="arpa") d, _ = Domain.objects.get_or_create(name="in-addr.arpa") d, _ = Domain.objects.get_or_create(name="ipv6.arpa") d, _ = Domain.objects.get_or_create(name="15.in-addr.arpa") d, _ = Domain.objects.get_or_create(name="2.in-addr.arpa") n = Network(network_str="15.0.0.0/8", ip_type="4") n.clean() n.site = s1 n.vlan = v n.save() r = Range(start_str="15.0.0.0", end_str="15.0.0.10", network=n) r.clean() r.save()
def setUp(self): self.arpa = self.create_domain(name="arpa") self.arpa.save() self.i_arpa = self.create_domain(name="in-addr.arpa") self.i_arpa.save() self.i6_arpa = self.create_domain(name="ipv6.arpa") self.i6_arpa.save() self.r = Domain(name="ru") self.r.save() self.f_r = Domain(name="foo.ru") self.f_r.save() self.b_f_r = Domain(name="bar.foo.ru") self.b_f_r.save() self.f = Domain(name="fam") self.f.save() self._128 = self.create_domain(name="128", ip_type="4") self._128.save() self.s = System() self.s.save()
def test1_delete_basic(self): # Does deleting a system delete it's interfaces? mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" system = System(hostname="foo") system.save() kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str, 'system': system } i = self.do_add(**kwargs) intr_pk = i.pk self.assertTrue(StaticInterface.objects.filter(**kwargs)) system.delete() self.assertFalse(StaticInterface.objects.filter(**kwargs))
class V6StaticInterTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='ipv6.arpa', ip_type='6') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="0", ip_type='6') self.r1.save() self.r2 = self.create_domain(name="1", ip_type='6') self.r2.save() self.n = System() self.n.clean() self.n.save() def do_add(self, mac, label, domain, ip_str, ip_type='6'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() repr(r) return r def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse( AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_create_basic(self): mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "12::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add(**kwargs) def test2_create_basic(self): mac = "20:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "123::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add(**kwargs) def test3_create_basic(self): mac = "11:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "1234::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add(**kwargs) def test4_create_basic(self): mac = "12:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "11::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add(**kwargs) def test1_delete(self): mac = "12:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "112::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} r = self.do_add(**kwargs) self.do_delete(r) def test1_dup_create_basic(self): mac = "11:22:33:44:55:66" label = "foo3" domain = self.f_c ip_str = "1123::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add(**kwargs) self.assertRaises(ValidationError, self.do_add, **kwargs) def test1_bad_add_for_a_ptr(self): # Intr exists, then try ptr and A mac = "11:22:33:44:55:6e" label = "9988fooddfdf" domain = self.c ip_str = "111::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} ip_type = '6' i = self.do_add(**kwargs) i.clean() i.save() a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) self.assertRaises(ValidationError, a.clean) ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=i.fqdn) self.assertRaises(ValidationError, ptr.clean) def test2_bad_add_for_a_ptr(self): # PTR and A exist, then try add intr mac = "11:22:33:44:55:66" label = "9988fdfood" domain = self.c ip_str = "1112::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} ip_type = '6' a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) a.clean() a.save() ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=a.fqdn) ptr.clean() ptr.save() self.assertRaises(ValidationError, self.do_add, **kwargs) def test1_bad_reverse_domain(self): mac = "11:22:33:44:55:66" label = "8888foo" domain = self.f_c ip_str = "115::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} i = self.do_add(**kwargs) i.ip_str = "9111::" self.assertRaises(ValidationError, i.clean) def test1_no_system(self): mac = "15:22:33:44:55:66" label = "8888foo" domain = self.f_c ip_str = "188::" + mac ip_type = '6' r = StaticInterface(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=None) self.assertRaises(ValidationError, r.clean)
class NSTestsModels(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = "4" if name in ("arpa", "in-addr.arpa", "ipv6.arpa"): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name="arpa") self.arpa.save() self.i_arpa = self.create_domain(name="in-addr.arpa") self.i_arpa.save() self.i6_arpa = self.create_domain(name="ipv6.arpa") self.i6_arpa.save() self.r = Domain(name="ru") self.r.save() self.f_r = Domain(name="foo.ru") self.f_r.save() self.b_f_r = Domain(name="bar.foo.ru") self.b_f_r.save() self.f = Domain(name="fam") self.f.save() self._128 = self.create_domain(name="128", ip_type="4") self._128.save() self.s = System() self.s.save() def do_add(self, domain, server): ns = Nameserver(domain=domain, server=server) ns.save() self.assertTrue(ns.__repr__()) self.assertTrue(ns.details()) self.assertTrue(ns.get_detail_url()) self.assertTrue(ns.get_update_url()) self.assertTrue(ns.get_delete_url()) ret = Nameserver.objects.filter(domain=domain, server=server) self.assertEqual(len(ret), 1) return ns def test_add_ns(self): data = {"domain": self.r, "server": "ns2.moot.ru"} self.do_add(**data) data = {"domain": self.r, "server": "ns5.moot.ru"} self.do_add(**data) data = {"domain": self.r, "server": u"ns3.moot.ru"} self.do_add(**data) data = {"domain": self.b_f_r, "server": "n1.moot.ru"} self.do_add(**data) data = {"domain": self.b_f_r, "server": "ns2.moot.ru"} self.do_add(**data) data = {"domain": self.r, "server": "asdf.asdf"} self.do_add(**data) def test_add_invalid(self): data = {"domain": self.f_r, "server": "ns3.foo.ru"} self.assertRaises(ValidationError, self.do_add, **data) def testtest_add_ns_in_domain(self): # Use an A record as a glue record. glue = AddressRecord(label="ns2", domain=self.r, ip_str="128.193.1.10", ip_type="4") glue.clean() glue.save() data = {"domain": self.r, "server": "ns2.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) self.assertRaises(ValidationError, glue.delete) glue = AddressRecord(label="ns3", domain=self.f_r, ip_str="128.193.1.10", ip_type="4") glue.save() data = {"domain": self.f_r, "server": "ns3.foo.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) def test_disallow_name_update_of_glue_A(self): # Glue records should not be allowed to change their name. glue = AddressRecord(label="ns39", domain=self.f_r, ip_str="128.193.1.77", ip_type="4") glue.clean() glue.save() data = {"domain": self.f_r, "server": "ns39.foo.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) glue.label = "ns22" self.assertRaises(ValidationError, glue.clean) def test_disallow_name_update_of_glue_Intr(self): # Glue records should not be allowed to change their name. glue = StaticInterface( label="ns24", domain=self.f_r, ip_str="128.193.99.10", ip_type="4", system=self.s, mac="11:22:33:44:55:66" ) glue.clean() glue.save() data = {"domain": self.f_r, "server": "ns24.foo.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) glue.label = "ns22" self.assertRaises(ValidationError, glue.clean) def test_disallow_delete_of_glue_intr(self): # Interface glue records should not be allowed to be deleted. glue = StaticInterface( label="ns24", domain=self.f_r, ip_str="128.193.99.10", ip_type="4", system=self.s, mac="11:22:33:44:55:66" ) glue.clean() glue.save() data = {"domain": self.f_r, "server": "ns24.foo.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) self.assertRaises(ValidationError, glue.delete) def test_manual_assign_of_glue(self): # Test that assigning a different glue record doesn't get overriden by # the auto assinging during the Nameserver's clean function. glue = StaticInterface( label="ns25", domain=self.f_r, ip_str="128.193.99.10", ip_type="4", system=self.s, mac="11:22:33:44:55:66" ) glue.clean() glue.save() data = {"domain": self.f_r, "server": "ns25.foo.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) glue2 = AddressRecord(label="ns25", domain=self.f_r, ip_str="128.193.1.78", ip_type="4") glue2.clean() glue2.save() ns.clean() # Make sure things didn't get overriden. self.assertEqual(ns.glue, glue) ns.glue = glue2 ns.save() # Refresh the object ns = Nameserver.objects.get(pk=ns.pk) # Again, Make sure things didn't get overriden. self.assertEqual(ns.glue, glue2) # Make sure we still can't delete. self.assertRaises(ValidationError, glue2.delete) self.assertRaises(ValidationError, ns.glue.delete) # We shuold be able to delelte the other one. glue.delete() def testtest_add_ns_in_domain_intr(self): # Use an Interface as a glue record. glue = StaticInterface( label="ns232", domain=self.r, ip_str="128.193.99.10", ip_type="4", system=self.s, mac="12:23:45:45:45:45" ) glue.clean() glue.save() data = {"domain": self.r, "server": "ns232.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) self.assertRaises(ValidationError, glue.delete) glue = StaticInterface( label="ns332", domain=self.f_r, ip_str="128.193.1.10", ip_type="4", system=self.s, mac="11:22:33:44:55:66" ) glue.clean() glue.save() data = {"domain": self.f_r, "server": "ns332.foo.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) def test_add_ns_outside_domain(self): data = {"domain": self.f_r, "server": "ns2.ru"} ns = self.do_add(**data) self.assertFalse(ns.glue) def test_update_glue_to_no_intr(self): glue = StaticInterface( label="ns34", domain=self.r, ip_str="128.193.1.10", ip_type="4", system=self.s, mac="11:22:33:44:55:66" ) glue.save() data = {"domain": self.r, "server": "ns34.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) ns.server = "ns4.wee" ns.save() self.assertTrue(ns.glue is None) def test_update_glue_record_intr(self): # Glue records can't change their name. glue = StaticInterface( label="ns788", domain=self.r, ip_str="128.193.1.10", ip_type="4", system=self.s, mac="11:22:33:44:55:66" ) glue.save() data = {"domain": self.r, "server": "ns788.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) glue.label = "asdfasdf" self.assertRaises(ValidationError, glue.clean) def test_update_glue_to_no_glue(self): glue = AddressRecord(label="ns3", domain=self.r, ip_str="128.193.1.10", ip_type="4") glue.save() data = {"domain": self.r, "server": "ns3.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) ns.server = "ns4.wee" ns.save() self.assertTrue(ns.glue is None) def test_delete_ns(self): glue = AddressRecord(label="ns4", domain=self.f_r, ip_str="128.196.1.10", ip_type="4") glue.save() data = {"domain": self.f_r, "server": "ns4.foo.ru"} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) ns.delete() nsret = Nameserver.objects.filter(server="ns2.foo.ru", domain=self.f_r) self.assertFalse(nsret) def test_invalid_create(self): glue = AddressRecord(label="ns2", domain=self.r, ip_str="128.193.1.10", ip_type="4") glue.save() data = {"domain": self.r, "server": "ns2 .ru"} self.assertRaises(ValidationError, self.do_add, **data) data = {"domain": self.r, "server": "ns2$.ru"} self.assertRaises(ValidationError, self.do_add, **data) data = {"domain": self.r, "server": "ns2..ru"} self.assertRaises(ValidationError, self.do_add, **data) data = {"domain": self.r, "server": "ns2.ru "} self.assertRaises(ValidationError, self.do_add, **data) data = {"domain": self.r, "server": ""} self.assertRaises(ValidationError, self.do_add, **data) def test_add_dup(self): data = {"domain": self.r, "server": "ns2.moot.ru"} self.do_add(**data) self.assertRaises(ValidationError, self.do_add, **data)
class CNAMEStaticRegTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() def do_add_intr(self, mac, label, domain, ip_str, ip_type='4'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() repr(r) return r def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse( AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_delete_cname(self): mac = "11:22:33:44:55:66" label = "foo4" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} i = self.do_add_intr(**kwargs) cn, _ = CNAME.objects.get_or_create(label='foo', domain=domain, target=label + "." + domain.name) self.assertRaises(ValidationError, i.delete) def test1_delete_override(self): mac = "12:22:33:44:55:66" label = "foo6" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} i = self.do_add_intr(**kwargs) cn, _ = CNAME.objects.get_or_create(label='food', domain=domain, target=label + "." + domain.name) i.delete(check_cname=False)
class DirtySOATests(cyder.base.tests.TestCase): def setUp(self): Domain.objects.get_or_create(name="arpa") Domain.objects.get_or_create(name="in-addr.arpa") self.r1, _ = Domain.objects.get_or_create(name="10.in-addr.arpa") self.sr, sr_c = SOA.objects.get_or_create(primary="ns1.foo.gaz", contact= "hostmaster.foo", comment="123foo.gazsdi2") self.r1.soa = self.sr self.r1.save() s1, s1_c = SOA.objects.get_or_create(primary="ns1.foo.gaz", contact= "hostmaster.dfdfoo", comment="123fooasdfsdfasdfsa.gaz2") self.soa = s1 d, _ = Domain.objects.get_or_create(name="bgaz") d.soa = s1 d.save() self.dom = d self.soa.dirty = False self.dom.dirty = False s2, s1_c = SOA.objects.get_or_create(primary="ns1.foo.gaz", contact= "hostmaster.foo", comment="123fooasdfsdf.gaz2") self.rsoa = s2 rd, _ = Domain.objects.get_or_create(name="123.in-addr.arpa") rd.soa = s2 rd.save() self.rdom = rd self.rsoa.dirty = False self.rdom.dirty = False self.s = System() self.s.save() def generic_dirty(self, Klass, create_data, update_data, local_soa): local_soa.dirty = False local_soa.save() rec = Klass(**create_data) rec.full_clean() rec.save() local_soa = SOA.objects.get(pk=local_soa.pk) self.assertTrue(local_soa.dirty) # Now try updating local_soa.dirty = False local_soa.save() local_soa = SOA.objects.get(pk=local_soa.pk) self.assertFalse(local_soa.dirty) for k, v in update_data.iteritems(): setattr(rec, k, v) rec.save() local_soa = SOA.objects.get(pk=local_soa.pk) self.assertTrue(local_soa.dirty) def test_dirty_a(self): create_data = { 'label': 'asdf', 'domain': self.dom, 'ip_str': '10.2.3.1', 'ip_type': '4' } update_data = { 'label': 'asdfx', } self.generic_dirty(AddressRecord, create_data, update_data, self.soa) def test_dirty_intr(self): create_data = { 'label': 'asdf1', 'domain': self.dom, 'ip_str': '10.2.3.1', 'ip_type': '4', 'system': self.s, 'mac': '11:22:33:44:55:66' } update_data = { 'label': 'asdfx1', } self.generic_dirty(StaticInterface, create_data, update_data, self.soa) def test_dirty_cname(self): create_data = { 'label': 'asdf2', 'domain': self.dom, 'target': 'foo.bar.com', } update_data = { 'label': 'asdfx2', } self.generic_dirty(CNAME, create_data, update_data, self.soa) def test_dirty_ptr(self): create_data = { 'ip_str': '10.2.3.4', 'ip_type': '4', 'name': 'foo.bar.com', } update_data = { 'label': 'asdfx2', } self.generic_dirty(PTR, create_data, update_data, local_soa=self.sr) def test_dirty_mx(self): create_data = { 'label': '', 'domain': self.dom, 'priority': 10, 'server': 'foo.bar.com', } update_data = { 'label': 'asdfx3', } self.generic_dirty(MX, create_data, update_data, self.soa) def test_dirty_ns(self): create_data = { 'domain': self.dom, 'server': 'foo.bar.com', } update_data = { 'label': 'asdfx4', } self.generic_dirty(Nameserver, create_data, update_data, self.soa) def test_dirty_soa(self): self.soa.dirty = False self.soa.refresh = 123 self.soa.save() self.assertTrue(self.soa.dirty) def test_dirty_srv(self): create_data = { 'label': '_asdf7', 'domain': self.dom, 'priority': 10, 'port': 10, 'weight': 10, 'target': 'foo.bar.com', } update_data = { 'label': '_asdfx4', } self.generic_dirty(SRV, create_data, update_data, self.soa) def test_dirty_txt(self): create_data = { 'label': 'asdf8', 'domain': self.dom, 'txt_data': 'some shit', } update_data = { 'label': 'asdfx5', } self.generic_dirty(TXT, create_data, update_data, self.soa)
class StaticInterTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() View.objects.get_or_create(name="private") def do_add(self, mac, label, domain, ip_str, ip_type='4'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() r.details() r.get_update_url() r.get_delete_url() r.get_detail_url() repr(r) return r def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse(AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_create_basic(self): mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } i = self.do_add(**kwargs) i.update_attrs() self.assertEqual('None', i.interface_name()) i.attrs.interface_type = "eth" self.assertEqual('None', i.interface_name()) i.attrs.primary = "0" self.assertEqual('eth0', i.interface_name()) i.attrs.alias = "0" self.assertEqual('eth0.0', i.interface_name()) i.clean() def bad_assign(): i.attrs.interface_type = "wee" self.assertRaises(ValidationError, bad_assign) def bad_assign(): i.attrs.primary = "wee" self.assertRaises(ValidationError, bad_assign) def bad_assign(): i.attrs.alias = "wee" self.assertRaises(ValidationError, bad_assign) def test2_create_basic(self): mac = "11:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "10.0.0.1" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } i = self.do_add(**kwargs) i.dhcp_enabled = False i.clean() i.save() i2 = StaticInterface.objects.get(pk=i.pk) self.assertFalse(i2.dhcp_enabled) i.dhcp_enabled = True i.clean() i.save() i3 = StaticInterface.objects.get(pk=i.pk) self.assertTrue(i3.dhcp_enabled) def test3_create_basic(self): mac = "11:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.do_add(**kwargs) def test4_create_basic(self): mac = "12:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.do_add(**kwargs) def test5_create_basic(self): mac = "00:00:00:00:00:00" label = "foo1" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } r = self.do_add(**kwargs) # Change the mac by one. mac = "00:00:00:00:00:01" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } r = self.do_add(**kwargs) def test1_delete(self): mac = "12:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } r = self.do_add(**kwargs) self.do_delete(r) def test1_dup_create_basic(self): mac = "11:22:33:44:55:66" label = "foo3" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.do_add(**kwargs) self.assertRaises(ValidationError, self.do_add, **kwargs) def test1_bad_add_for_a_ptr(self): # Intr exists, then try ptr and A mac = "11:22:33:44:55:66" label = "9988food" domain = self.c ip_str = "10.0.0.1" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } ip_type = '4' i = self.do_add(**kwargs) i.clean() i.save() a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) self.assertRaises(ValidationError, a.clean) ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=i.fqdn) self.assertRaises(ValidationError, ptr.clean) def test2_bad_add_for_a_ptr(self): # PTR and A exist, then try add intr mac = "11:22:33:44:55:66" label = "9988fdfood" domain = self.c ip_str = "10.0.0.1" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } ip_type = '4' a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) a.clean() a.save() ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=a.fqdn) ptr.clean() ptr.save() self.assertRaises(ValidationError, self.do_add, **kwargs) def test1_bad_reverse_domain(self): mac = "11:22:33:44:55:66" label = "8888foo" domain = self.f_c ip_str = "10.0.0.1" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } i = self.do_add(**kwargs) i.ip_str = "9.0.0.1" self.assertRaises(ValidationError, i.clean) def test1_no_system(self): mac = "15:22:33:44:55:66" label = "8888foo" domain = self.f_c ip_str = "10.0.0.1" ip_type = '4' r = StaticInterface(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=None) self.assertRaises(ValidationError, r.clean)
class CNAMETests(cyder.base.tests.TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): primary = "ns5.oregonstate.edu" contact = "admin.oregonstate.edu" retry = 1234 refresh = 1234123 self.soa = SOA(primary=primary, contact=contact, retry=retry, refresh=refresh) self.soa.save() self.g = Domain(name="gz") self.g.save() self.c_g = Domain(name="coo.gz") self.c_g.soa = self.soa self.c_g.save() self.d = Domain(name="dz") self.d.save() self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.r1 = self.create_domain(name="10") self.r1.save() self.s = System() self.s.save() def do_add(self, label, domain, data): cn = CNAME(label=label, domain=domain, target=data) cn.full_clean() cn.save() cn.save() self.assertTrue(cn.get_detail_url()) self.assertTrue(cn.get_update_url()) self.assertTrue(cn.get_delete_url()) self.assertTrue(cn.details()) cs = CNAME.objects.filter( label=label, domain=domain, target=data) self.assertEqual(len(cs), 1) return cn def test_add(self): label = "foo" domain = self.g data = "foo.com" x = self.do_add(label, domain, data) label = "boo" domain = self.c_g data = "foo.foo.com" self.do_add(label, domain, data) label = "fo1" domain = self.g data = "foo.com" self.do_add(label, domain, data) self.assertRaises(ValidationError, self.do_add, *(label, domain, data)) label = "" domain = self.g data = "foo.com" self.do_add(label, domain, data) def test1_add_glob(self): label = "*foo" domain = self.g data = "foo.com" x = self.do_add(label, domain, data) label = "*" domain = self.c_g data = "foo.foo.com" self.do_add(label, domain, data) label = "*.fo1" domain = self.g data = "foo.com" self.assertRaises(ValidationError, self.do_add, *(label, domain, data)) label = "*sadfasfd-asdf" domain = self.g data = "foo.com" self.do_add(label, domain, data) def test2_add_glob(self): label = "*coo" domain = self.g data = "foo.com" x = self.do_add(label, domain, data) label = "*" domain = self.c_g data = "foo.com" x = self.do_add(label, domain, data) def test_soa_condition(self): label = "" domain = self.c_g data = "foo.com" self.assertRaises(ValidationError, self.do_add, *(label, domain, data)) def test_data_domain(self): label = "fo1" domain = self.g data = "foo.dz" cn = self.do_add(label, domain, data) self.assertTrue(self.d == cn.target_domain) def test_add_bad(self): label = "" domain = self.g data = "..foo.com" self.assertRaises(ValidationError, self.do_add, *(label, domain, data)) def test_add_mx_with_cname(self): label = "cnamederp1" domain = self.c_g data = "foo.com" fqdn = label + '.' + domain.name mx_data = {'label': '', 'domain': self.c_g, 'server': fqdn, 'priority': 2, 'ttl': 2222} mx = MX(**mx_data) mx.save() cn = CNAME(label=label, domain=domain, target=data) self.assertRaises(ValidationError, cn.full_clean) def test_address_record_exists(self): label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") rec, _ = AddressRecord.objects.get_or_create( label=label, domain=dom, ip_type='4', ip_str="128.193.1.1") cn = CNAME(label=label, domain=dom, target=data) self.assertRaises(ValidationError, cn.full_clean) def test_address_record_cname_exists(self): label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") cn = CNAME.objects.get_or_create( label=label, domain=dom, target=data) rec = AddressRecord(label=label, domain=dom, ip_str="128.193.1.1") self.assertRaises(ValidationError, rec.save) def test_srv_exists(self): label = "_testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") rec, _ = SRV.objects.get_or_create( label=label, domain=dom, target="asdf", port=2, priority=2, weight=4) cn = CNAME(label=label, domain=dom, target=data) self.assertRaises(ValidationError, cn.full_clean) def test_srv_cname_exists(self): label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") cn = CNAME.objects.get_or_create( label=label, domain=dom, target=data) rec = SRV(label=label, domain=dom, target="asdf", port=2, priority=2, weight=4) self.assertRaises(ValidationError, rec.save) def test_txt_exists(self): label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") rec, _ = TXT.objects.get_or_create( label=label, domain=dom, txt_data="asdf") cn = CNAME(label=label, domain=dom, target=data) self.assertRaises(ValidationError, cn.full_clean) def test_txt_cname_exists(self): label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") cn, _ = CNAME.objects.get_or_create( label=label, domain=dom, target=data) cn.full_clean() cn.save() rec = TXT(label=label, domain=dom, txt_data="asdf1") self.assertRaises(ValidationError, rec.save) def test_mx_exists(self): label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") rec, _ = MX.objects.get_or_create( label=label, domain=dom, server="asdf", priority=123, ttl=123) cn = CNAME(label=label, domain=dom, target=data) self.assertRaises(ValidationError, cn.full_clean) def test_mx_cname_exists(self): # Duplicate test? label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") cn, _ = CNAME.objects.get_or_create( label=label, domain=dom, target=data) cn.full_clean() cn.save() rec = MX(label=label, domain=dom, server="asdf1", priority=123, ttl=123) self.assertRaises(ValidationError, rec.save) def test_ns_exists(self): # Duplicate test? label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") rec = Nameserver(domain=dom, server="asdf1") rec.save() cn = CNAME(label='', domain=dom, target=data) self.assertRaises(ValidationError, cn.clean) def test_ns_cname_exists(self): # Duplicate test? label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") cn, _ = CNAME.objects.get_or_create( label='', domain=dom, target=data) cn.full_clean() cn.save() rec = Nameserver(domain=dom, server="asdf1") self.assertRaises(ValidationError, rec.save) def test_intr_exists(self): label = "tdfestyfoo" data = "waasdft" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") intr = StaticInterface(label=label, domain=dom, ip_str="10.0.0.1", ip_type='4', system=self.s, mac="11:22:33:44:55:66") intr.clean() intr.save() cn = CNAME(label=label, domain=dom, target=data) self.assertRaises(ValidationError, cn.full_clean) def test_intr_cname_exists(self): # Duplicate test? label = "tesafstyfoo" data = "wadfakt" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") cn, _ = CNAME.objects.get_or_create( label=label, domain=dom, target=data) cn.full_clean() cn.save() intr = StaticInterface(label=label, domain=dom, ip_str="10.0.0.2", ip_type='4', system=self.s, mac="00:11:22:33:44:55") self.assertRaises(ValidationError, intr.clean) cn.label = "differentlabel" cn.save() intr.clean() intr.save()
class AuxAttrTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() def do_add(self, mac, label, domain, ip_str, ip_type='4'): self.n = System() r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() repr(r) return r def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse( AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_create(self): mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} intr = self.do_add(**kwargs) intr.update_attrs() def bad_get(): intr.attrs.primary self.assertRaises(AttributeError, bad_get) x = StaticIntrKeyValue.objects.filter(key='primary', intr=intr) self.assertFalse(x) intr.attrs.primary = '1' self.assertEqual(intr.attrs.cache['primary'], '1') self.assertEqual(intr.attrs.primary, '1') x = StaticIntrKeyValue.objects.filter(key='primary', intr=intr) self.assertEqual(x[0].value, '1') def test6_create(self): mac = "24:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} intr = self.do_add(**kwargs) intr.update_attrs() intr.update_attrs() intr.update_attrs() def bad_get(): x = intr.attrs.primary self.assertRaises(AttributeError, bad_get) intr.attrs.primary = '1' self.assertEqual(intr.attrs.primary, '1') self.assertEqual(intr.attrs.cache['primary'], '1') def test2_create(self): mac = "13:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} intr = self.do_add(**kwargs) intr.update_attrs() intr.attrs.primary = '2' self.assertEqual(intr.attrs.primary, '2') self.assertEqual(intr.attrs.cache['primary'], '2') del intr.attrs.primary def bad_get(): intr.attrs.primary self.assertRaises(AttributeError, bad_get) intr.attrs.primary = '3' self.assertEqual(intr.attrs.primary, '3') self.assertEqual(intr.attrs.cache['primary'], '3') def test1_del(self): mac = "12:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} intr = self.do_add(**kwargs) intr.update_attrs() intr.attrs.primary = '88' self.assertEqual(intr.attrs.primary, '88') del intr.attrs.primary def bad_get(): intr.attrs.primary self.assertRaises(AttributeError, bad_get) def test3_create(self): mac = "19:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} intr = self.do_add(**kwargs) intr.update_attrs() def bad_assign(): intr.attrs.primary = 'a' self.assertRaises(ValidationError, bad_assign) def test1_existing_attrs(self): mac = "19:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} intr = self.do_add(**kwargs) StaticIntrKeyValue(key="foo", value="bar", intr=intr).save() StaticIntrKeyValue( key="interface_type", value="eth0", intr=intr).save() StaticIntrKeyValue(key="alias", value="5", intr=intr).save() intr.update_attrs() self.assertEqual(intr.attrs.alias, '5') self.assertEqual(intr.attrs.cache['alias'], '5') self.assertEqual(intr.attrs.interface_type, 'eth0') self.assertEqual(intr.attrs.cache['interface_type'], 'eth0') self.assertEqual(intr.attrs.foo, 'bar') self.assertEqual(intr.attrs.cache['foo'], 'bar')
class DeleteStaticInterTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() View.objects.get_or_create(name="private") def do_add(self, mac, label, domain, ip_str, system, ip_type='4'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=system) r.clean() r.save() return r def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse(AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_delete_basic(self): # Does deleting a system delete it's interfaces? mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" system = System(hostname="foo") system.save() kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str, 'system': system } i = self.do_add(**kwargs) intr_pk = i.pk self.assertTrue(StaticInterface.objects.filter(**kwargs)) system.delete() self.assertFalse(StaticInterface.objects.filter(**kwargs))
class NSTestsModels(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.i6_arpa = self.create_domain(name='ipv6.arpa') self.i6_arpa.save() self.r = Domain(name="ru") self.r.save() self.f_r = Domain(name="foo.ru") self.f_r.save() self.b_f_r = Domain(name="bar.foo.ru") self.b_f_r.save() self.f = Domain(name="fam") self.f.save() self._128 = self.create_domain(name='128', ip_type='4') self._128.save() self.s = System() self.s.save() def do_add(self, domain, server): ns = Nameserver(domain=domain, server=server) ns.save() self.assertTrue(ns.__repr__()) self.assertTrue(ns.details()) self.assertTrue(ns.get_detail_url()) self.assertTrue(ns.get_update_url()) self.assertTrue(ns.get_delete_url()) ret = Nameserver.objects.filter(domain=domain, server=server) self.assertEqual(len(ret), 1) return ns def test_add_ns(self): data = {'domain': self.r, 'server': 'ns2.moot.ru'} self.do_add(**data) data = {'domain': self.r, 'server': 'ns5.moot.ru'} self.do_add(**data) data = {'domain': self.r, 'server': u'ns3.moot.ru'} self.do_add(**data) data = {'domain': self.b_f_r, 'server': 'n1.moot.ru'} self.do_add(**data) data = {'domain': self.b_f_r, 'server': 'ns2.moot.ru'} self.do_add(**data) data = {'domain': self.r, 'server': 'asdf.asdf'} self.do_add(**data) def test_add_invalid(self): data = {'domain': self.f_r, 'server': 'ns3.foo.ru'} self.assertRaises(ValidationError, self.do_add, **data) def testtest_add_ns_in_domain(self): # Use an A record as a glue record. glue = AddressRecord(label='ns2', domain=self.r, ip_str='128.193.1.10', ip_type='4') glue.clean() glue.save() data = {'domain': self.r, 'server': 'ns2.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) self.assertRaises(ValidationError, glue.delete) glue = AddressRecord(label='ns3', domain=self.f_r, ip_str='128.193.1.10', ip_type='4') glue.save() data = {'domain': self.f_r, 'server': 'ns3.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) def test_disallow_name_update_of_glue_A(self): # Glue records should not be allowed to change their name. glue = AddressRecord(label='ns39', domain=self.f_r, ip_str='128.193.1.77', ip_type='4') glue.clean() glue.save() data = {'domain': self.f_r, 'server': 'ns39.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) glue.label = "ns22" self.assertRaises(ValidationError, glue.clean) def test_disallow_name_update_of_glue_Intr(self): # Glue records should not be allowed to change their name. glue = StaticInterface(label='ns24', domain=self.f_r, ip_str='128.193.99.10', ip_type='4', system=self.s, mac="11:22:33:44:55:66") glue.clean() glue.save() data = {'domain': self.f_r, 'server': 'ns24.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) glue.label = "ns22" self.assertRaises(ValidationError, glue.clean) def test_disallow_delete_of_glue_intr(self): # Interface glue records should not be allowed to be deleted. glue = StaticInterface(label='ns24', domain=self.f_r, ip_str='128.193.99.10', ip_type='4', system=self.s, mac="11:22:33:44:55:66") glue.clean() glue.save() data = {'domain': self.f_r, 'server': 'ns24.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) self.assertRaises(ValidationError, glue.delete) def test_manual_assign_of_glue(self): # Test that assigning a different glue record doesn't get overriden by # the auto assinging during the Nameserver's clean function. glue = StaticInterface(label='ns25', domain=self.f_r, ip_str='128.193.99.10', ip_type='4', system=self.s, mac="11:22:33:44:55:66") glue.clean() glue.save() data = {'domain': self.f_r, 'server': 'ns25.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) glue2 = AddressRecord(label='ns25', domain=self.f_r, ip_str='128.193.1.78', ip_type='4') glue2.clean() glue2.save() ns.clean() # Make sure things didn't get overriden. self.assertEqual(ns.glue, glue) ns.glue = glue2 ns.save() # Refresh the object ns = Nameserver.objects.get(pk=ns.pk) # Again, Make sure things didn't get overriden. self.assertEqual(ns.glue, glue2) # Make sure we still can't delete. self.assertRaises(ValidationError, glue2.delete) self.assertRaises(ValidationError, ns.glue.delete) # We shuold be able to delelte the other one. glue.delete() def testtest_add_ns_in_domain_intr(self): # Use an Interface as a glue record. glue = StaticInterface(label='ns232', domain=self.r, ip_str='128.193.99.10', ip_type='4', system=self.s, mac="12:23:45:45:45:45") glue.clean() glue.save() data = {'domain': self.r, 'server': 'ns232.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) self.assertRaises(ValidationError, glue.delete) glue = StaticInterface(label='ns332', domain=self.f_r, ip_str='128.193.1.10', ip_type='4', system=self.s, mac="11:22:33:44:55:66") glue.clean() glue.save() data = {'domain': self.f_r, 'server': 'ns332.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) def test_add_ns_outside_domain(self): data = {'domain': self.f_r, 'server': 'ns2.ru'} ns = self.do_add(**data) self.assertFalse(ns.glue) def test_update_glue_to_no_intr(self): glue = StaticInterface(label='ns34', domain=self.r, ip_str='128.193.1.10', ip_type='4', system=self.s, mac="11:22:33:44:55:66") glue.save() data = {'domain': self.r, 'server': 'ns34.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) ns.server = "ns4.wee" ns.save() self.assertTrue(ns.glue is None) def test_update_glue_record_intr(self): # Glue records can't change their name. glue = StaticInterface(label='ns788', domain=self.r, ip_str='128.193.1.10', ip_type='4', system=self.s, mac="11:22:33:44:55:66") glue.save() data = {'domain': self.r, 'server': 'ns788.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) glue.label = "asdfasdf" self.assertRaises(ValidationError, glue.clean) def test_update_glue_to_no_glue(self): glue = AddressRecord(label='ns3', domain=self.r, ip_str='128.193.1.10', ip_type='4') glue.save() data = {'domain': self.r, 'server': 'ns3.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) ns.server = "ns4.wee" ns.save() self.assertTrue(ns.glue is None) def test_delete_ns(self): glue = AddressRecord(label='ns4', domain=self.f_r, ip_str='128.196.1.10', ip_type='4') glue.save() data = {'domain': self.f_r, 'server': 'ns4.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) ns.delete() nsret = Nameserver.objects.filter(server='ns2.foo.ru', domain=self.f_r) self.assertFalse(nsret) def test_invalid_create(self): glue = AddressRecord(label='ns2', domain=self.r, ip_str='128.193.1.10', ip_type='4') glue.save() data = {'domain': self.r, 'server': 'ns2 .ru'} self.assertRaises(ValidationError, self.do_add, **data) data = {'domain': self.r, 'server': 'ns2$.ru'} self.assertRaises(ValidationError, self.do_add, **data) data = {'domain': self.r, 'server': 'ns2..ru'} self.assertRaises(ValidationError, self.do_add, **data) data = {'domain': self.r, 'server': 'ns2.ru '} self.assertRaises(ValidationError, self.do_add, **data) data = {'domain': self.r, 'server': ''} self.assertRaises(ValidationError, self.do_add, **data) def test_add_dup(self): data = {'domain': self.r, 'server': 'ns2.moot.ru'} self.do_add(**data) self.assertRaises(ValidationError, self.do_add, **data)
class AStaticRegTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() def do_add_intr(self, mac, label, domain, ip_str, ip_type='4'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() repr(r) return r def do_add_a(self, label, domain, ip_str, ip_type='4'): a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) a.clean() a.save() return a def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse(AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_conflict_add_intr_first(self): # Add an intr and make sure A can't exist. mac = "11:22:33:44:55:66" label = "foo4" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.do_add_intr(**kwargs) kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} self.assertRaises(ValidationError, self.do_add_a, **kwargs) def test1_conflict_add_A_first(self): # Add an A and make sure an intr can't exist. mac = "11:22:33:44:55:66" label = "foo5" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add_a(**kwargs) kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.assertRaises(ValidationError, self.do_add_intr, **kwargs) def test2_conflict_add_intr_first(self): # Add an intr and update an existing A to conflict. Test for exception. mac = "12:22:33:44:55:66" label = "fo99" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.do_add_intr(**kwargs) ip_str = "10.0.0.3" kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} a = self.do_add_a(**kwargs) a.ip_str = "10.0.0.2" self.assertRaises(ValidationError, a.save) def test2_conflict_add_A_first(self): # Add an A and update and existing intr to conflict. Test for exception. mac = "11:22:33:44:55:66" label = "foo98" domain = self.f_c ip_str = "10.0.0.2" # Add A kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} a = self.do_add_a(**kwargs) # Add Intr with diff IP ip_str = "10.0.0.3" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } intr = self.do_add_intr(**kwargs) # Conflict the IP on the intr intr.ip_str = "10.0.0.2" self.assertRaises(ValidationError, intr.save)
class PTRStaticRegTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() def do_add_intr(self, mac, label, domain, ip_str, ip_type='4'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() repr(r) return r def do_add_ptr(self, label, domain, ip_str, ip_type='4'): ptr = PTR(name=label + '.' + domain.name, ip_str=ip_str, ip_type=ip_type) ptr.clean() ptr.save() return ptr def test1_conflict_add_intr_first(self): # PTRdd an intr and make sure PTR can't exist. mac = "11:22:33:44:55:66" label = "foo4" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.do_add_intr(**kwargs) kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} self.assertRaises(ValidationError, self.do_add_ptr, **kwargs) def test1_conflict_add_PTR_first(self): # Add an PTR and make sure an intr can't exist. mac = "11:22:33:44:55:66" label = "foo5" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add_ptr(**kwargs) kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.assertRaises(ValidationError, self.do_add_intr, **kwargs) def test2_conflict_add_intr_first(self): # Add an intr and update an existing PTR to conflict. Test for exception. mac = "12:22:33:44:55:66" label = "fo99" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } self.do_add_intr(**kwargs) ip_str = "10.0.0.3" kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} ptr = self.do_add_ptr(**kwargs) ptr.ip_str = "10.0.0.2" self.assertRaises(ValidationError, ptr.clean) def test2_conflict_add_A_first(self): # Add an PTR and update and existing intr to conflict. Test for exception. mac = "11:22:33:44:55:66" label = "foo98" domain = self.f_c ip_str = "10.0.0.2" # Add PTR kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} ptr = self.do_add_ptr(**kwargs) # Add Intr with diff IP ip_str = "10.0.0.3" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } intr = self.do_add_intr(**kwargs) # Conflict the IP on the intr intr.ip_str = "10.0.0.2" self.assertRaises(ValidationError, intr.save)
class SystemIntegrationTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() def do_add(self, mac, label, domain, ip_str, ip_type='4'): self.n = System() r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() repr(r) return r def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse(AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_create(self): mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } intr = self.do_add(**kwargs) intr.update_attrs() def bad_get(): intr.attrs.primary self.assertRaises(AttributeError, bad_get) x = StaticIntrKeyValue.objects.filter(key='primary', intr=intr) self.assertFalse(x) intr.attrs.primary = '1' self.assertEqual(intr.attrs.primary, '1') x = StaticIntrKeyValue.objects.filter(key='primary', intr=intr) self.assertEqual(x[0].value, '1') def test6_create(self): mac = "24:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } intr = self.do_add(**kwargs) intr.update_attrs() intr.update_attrs() intr.update_attrs() def bad_get(): x = intr.attrs.primary self.assertRaises(AttributeError, bad_get) intr.attrs.primary = '1' self.assertEqual(intr.attrs.primary, '1') def test2_create(self): mac = "13:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } intr = self.do_add(**kwargs) intr.update_attrs() intr.attrs.primary = '2' self.assertEqual(intr.attrs.primary, '2') del intr.attrs.primary def bad_get(): intr.attrs.primary self.assertRaises(AttributeError, bad_get) intr.attrs.primary = '3' self.assertEqual(intr.attrs.primary, '3') def test1_del(self): mac = "12:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } intr = self.do_add(**kwargs) intr.update_attrs() intr.attrs.primary = '88' self.assertEqual(intr.attrs.primary, '88') del intr.attrs.primary def bad_get(): intr.attrs.primary self.assertRaises(AttributeError, bad_get) def test3_create(self): mac = "19:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = { 'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str } intr = self.do_add(**kwargs) intr.update_attrs() def bad_assign(): intr.attrs.primary = 'a' self.assertRaises(ValidationError, bad_assign)
class PTRStaticRegTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() def do_add_intr(self, mac, label, domain, ip_str, ip_type='4'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() repr(r) return r def do_add_ptr(self, label, domain, ip_str, ip_type='4'): ptr = PTR(name=label + '.' + domain.name, ip_str=ip_str, ip_type=ip_type) ptr.clean() ptr.save() return ptr def test1_conflict_add_intr_first(self): # PTRdd an intr and make sure PTR can't exist. mac = "11:22:33:44:55:66" label = "foo4" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add_intr(**kwargs) kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} self.assertRaises(ValidationError, self.do_add_ptr, **kwargs) def test1_conflict_add_PTR_first(self): # Add an PTR and make sure an intr can't exist. mac = "11:22:33:44:55:66" label = "foo5" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add_ptr(**kwargs) kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.assertRaises(ValidationError, self.do_add_intr, **kwargs) def test2_conflict_add_intr_first(self): # Add an intr and update an existing PTR to conflict. Test for exception. mac = "12:22:33:44:55:66" label = "fo99" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add_intr(**kwargs) ip_str = "10.0.0.3" kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} ptr = self.do_add_ptr(**kwargs) ptr.ip_str = "10.0.0.2" self.assertRaises(ValidationError, ptr.clean) def test2_conflict_add_A_first(self): # Add an PTR and update and existing intr to conflict. Test for exception. mac = "11:22:33:44:55:66" label = "foo98" domain = self.f_c ip_str = "10.0.0.2" # Add PTR kwargs = {'label': label, 'domain': domain, 'ip_str': ip_str} ptr = self.do_add_ptr(**kwargs) # Add Intr with diff IP ip_str = "10.0.0.3" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} intr = self.do_add_intr(**kwargs) # Conflict the IP on the intr intr.ip_str = "10.0.0.2" self.assertRaises(ValidationError, intr.save)
def setUp(self): self.system = System() Domain.objects.get_or_create(name="com") Domain.objects.get_or_create(name="mozilla.com")
class StaticInterTests(TestCase): def create_domain(self, name, ip_type=None, delegated=False): if ip_type is None: ip_type = '4' if name in ('arpa', 'in-addr.arpa', 'ipv6.arpa'): pass else: name = ip_to_domain_name(name, ip_type=ip_type) d = Domain(name=name, delegated=delegated) d.clean() self.assertTrue(d.is_reverse) return d def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='in-addr.arpa') self.i_arpa.save() self.c = Domain(name="ccc") self.c.save() self.f_c = Domain(name="foo.ccc") self.f_c.save() self.r1 = self.create_domain(name="10") self.r1.save() self.n = System() self.n.clean() self.n.save() View.objects.get_or_create(name="private") def do_add(self, mac, label, domain, ip_str, ip_type='4'): r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=self.n) r.clean() r.save() r.details() r.get_update_url() r.get_delete_url() r.get_detail_url() repr(r) return r def do_delete(self, r): ip_str = r.ip_str fqdn = r.fqdn r.delete() self.assertFalse( AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn)) def test1_create_basic(self): mac = "11:22:33:44:55:66" label = "foo" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} i = self.do_add(**kwargs) i.update_attrs() self.assertEqual('None', i.interface_name()) i.attrs.interface_type = "eth" self.assertEqual('None', i.interface_name()) i.attrs.primary = "0" self.assertEqual('eth0', i.interface_name()) i.attrs.alias = "0" self.assertEqual('eth0.0', i.interface_name()) i.clean() def bad_assign(): i.attrs.interface_type = "wee" self.assertRaises(ValidationError, bad_assign) def bad_assign(): i.attrs.primary = "wee" self.assertRaises(ValidationError, bad_assign) def bad_assign(): i.attrs.alias = "wee" self.assertRaises(ValidationError, bad_assign) def test2_create_basic(self): mac = "11:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "10.0.0.1" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} i = self.do_add(**kwargs) i.dhcp_enabled = False i.clean() i.save() i2 = StaticInterface.objects.get(pk=i.pk) self.assertFalse(i2.dhcp_enabled) i.dhcp_enabled = True i.clean() i.save() i3 = StaticInterface.objects.get(pk=i.pk) self.assertTrue(i3.dhcp_enabled) def test3_create_basic(self): mac = "11:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add(**kwargs) def test4_create_basic(self): mac = "12:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add(**kwargs) def test5_create_basic(self): mac = "00:00:00:00:00:00" label = "foo1" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} r = self.do_add(**kwargs) # Change the mac by one. mac = "00:00:00:00:00:01" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} r = self.do_add(**kwargs) def test1_delete(self): mac = "12:22:33:44:55:66" label = "foo1" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} r = self.do_add(**kwargs) self.do_delete(r) def test1_dup_create_basic(self): mac = "11:22:33:44:55:66" label = "foo3" domain = self.f_c ip_str = "10.0.0.2" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} self.do_add(**kwargs) self.assertRaises(ValidationError, self.do_add, **kwargs) def test1_bad_add_for_a_ptr(self): # Intr exists, then try ptr and A mac = "11:22:33:44:55:66" label = "9988food" domain = self.c ip_str = "10.0.0.1" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} ip_type = '4' i = self.do_add(**kwargs) i.clean() i.save() a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) self.assertRaises(ValidationError, a.clean) ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=i.fqdn) self.assertRaises(ValidationError, ptr.clean) def test2_bad_add_for_a_ptr(self): # PTR and A exist, then try add intr mac = "11:22:33:44:55:66" label = "9988fdfood" domain = self.c ip_str = "10.0.0.1" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} ip_type = '4' a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) a.clean() a.save() ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=a.fqdn) ptr.clean() ptr.save() self.assertRaises(ValidationError, self.do_add, **kwargs) def test1_bad_reverse_domain(self): mac = "11:22:33:44:55:66" label = "8888foo" domain = self.f_c ip_str = "10.0.0.1" kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} i = self.do_add(**kwargs) i.ip_str = "9.0.0.1" self.assertRaises(ValidationError, i.clean) def test1_no_system(self): mac = "15:22:33:44:55:66" label = "8888foo" domain = self.f_c ip_str = "10.0.0.1" ip_type = '4' r = StaticInterface(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type, system=None) self.assertRaises(ValidationError, r.clean)