def test_quoted(self): create_fake_host(hostname='foobob.mozilla.com', serial='xxx') test_csv = """ hostname, switch_ports foobob.mozilla.com, "sdf,asfd,asfd" """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(hostname='foobob.mozilla.com') self.assertEqual(s1.switch_ports, 'sdf,asfd,asfd')
def test_system_type(self): create_fake_host(hostname='foobob1.mozilla.com', serial='xxx') test_csv = """ hostname, system_type % type_name foobob1.mozilla.com, foobar """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(hostname='foobob1.mozilla.com') self.assertEqual(s1.system_type.type_name, 'foobar')
def test_primary_attribute2(self): create_fake_host(hostname='foobob.mozilla.com', asset_tag='YM0090PW9G6') test_csv = """ primary_attribute%asset_tag,warranty_start,warranty_end,purchase_date,serial,system_type%type_name,allocation%name YM0090PW9G6,2010-03-24,2013-03-24,2010-03-24,asdf,foobar,something """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(asset_tag='YM0090PW9G6') self.assertTrue(s1.warranty_start) self.assertTrue(s1.warranty_end)
def setUp(self): self.num = 0 create_fake_zone('2.ip6.arpa', suffix="") self.domain = create_fake_zone('foo.mozilla.com', suffix='') self.s = create_fake_host(hostname='foo.mozilla.com') self.sreg = StaticReg.objects.create( label='', domain=self.domain, ip_str='2222:123::', ip_type='6', system=self.s ) self.s = create_fake_host(hostname='foobar.mozilla.com') self.g = Group.objects.create(name='foobar') super(HWAdapterTest, self).setUp()
def test_system_type(self): create_fake_host( hostname='foobob1.mozilla.com', serial='xxx' ) test_csv = """ hostname, system_type % type_name foobob1.mozilla.com, foobar """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(hostname='foobob1.mozilla.com') self.assertEqual(s1.system_type.type_name, 'foobar')
def test_quoted(self): create_fake_host( hostname='foobob.mozilla.com', serial='xxx' ) test_csv = """ hostname, switch_ports foobob.mozilla.com, "sdf,asfd,asfd" """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(hostname='foobob.mozilla.com') self.assertEqual(s1.switch_ports, 'sdf,asfd,asfd')
def test_two_switches(self): create_fake_host(hostname='foobob.mozilla.com', serial='xxx') test_csv = """ primary_attribute%serial,switch_ports,ram xxx,"switch1.r101-10:xe-0/0/36,switch1.r101-10:xe-1/0/36",1000 """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(serial='xxx') self.assertEqual( s1.switch_ports, "switch1.r101-10:xe-0/0/36,switch1.r101-10:xe-1/0/36")
def test_primary_attribute3(self): create_fake_host(hostname='foobob.mozilla.com', serial='SC07HT03WDKDJ') test_csv = """ primary_attribute%serial,warranty_start,warranty_end,purchase_date,system_type%type_name,allocation%name SC07HT03WDKDJ,2012-06-06,2013-06-06,2012-06-06,foobar,something """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(serial='SC07HT03WDKDJ') self.assertEqual( datetime.datetime(2012, 6, 6, 0, 0).date(), s1.warranty_start) self.assertEqual( datetime.datetime(2013, 6, 6, 0, 0).date(), s1.warranty_end)
def test_primary_attribute2(self): create_fake_host( hostname='foobob.mozilla.com', asset_tag='YM0090PW9G6' ) test_csv = """ primary_attribute%asset_tag,warranty_start,warranty_end,purchase_date,serial,system_type%type_name,allocation%name YM0090PW9G6,2010-03-24,2013-03-24,2010-03-24,asdf,foobar,something """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(asset_tag='YM0090PW9G6') self.assertTrue(s1.warranty_start) self.assertTrue(s1.warranty_end)
def test_two_switches(self): create_fake_host( hostname='foobob.mozilla.com', serial='xxx' ) test_csv = """ primary_attribute%serial,switch_ports,ram xxx,"switch1.r101-10:xe-0/0/36,switch1.r101-10:xe-1/0/36",1000 """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(serial='xxx') self.assertEqual( s1.switch_ports, "switch1.r101-10:xe-0/0/36,switch1.r101-10:xe-1/0/36" )
def test_primary_attribute3(self): create_fake_host( hostname='foobob.mozilla.com', serial='SC07HT03WDKDJ' ) test_csv = """ primary_attribute%serial,warranty_start,warranty_end,purchase_date,system_type%type_name,allocation%name SC07HT03WDKDJ,2012-06-06,2013-06-06,2012-06-06,foobar,something """ self.client_tst(test_csv, save=True) # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(serial='SC07HT03WDKDJ') self.assertEqual( datetime.datetime(2012, 6, 6, 0, 0).date(), s1.warranty_start) self.assertEqual( datetime.datetime(2013, 6, 6, 0, 0).date(), s1.warranty_end)
def test_bad_warranty(self): s = create_fake_host(hostname='foo.mozilla.com') earlier = datetime.date.fromtimestamp(time.time() - 60 * 60 * 24 * 7) now = datetime.datetime.now() s.warranty_start = now s.warranty_end = earlier self.assertRaises(ValidationError, s.save)
def setUp(self): Domain.objects.all().delete() Domain.objects.create(name="com") self.domain = Domain.objects.create(name="foo.com") Domain.objects.create(name="arpa") Domain.objects.create(name="in-addr.arpa") Domain.objects.create(name="10.in-addr.arpa") Domain.objects.create(name="ip6.arpa") Domain.objects.create(name="1.ip6.arpa") self.network_v6 = Network.objects.create( network_str="1234:1234:1234::/16", ip_type='6') start_str = "1234:1234:1234:1::" end_str = "1234:1234:1234:1234:1234:1234::" self.r_v6 = Range.objects.create(start_str=start_str, end_str=end_str, network=self.network_v6, ip_type='6') self.network_v4 = Network.objects.create(network_str="10.0.0.0/8", ip_type='4') start_str = "10.0.0.0" end_str = "10.200.0.0" self.r_v4 = Range.objects.create(start_str=start_str, end_str=end_str, network=self.network_v4, ip_type='4') self.s = create_fake_host(hostname="foo1.mozilla.com")
def test_non_existant_system(self): # add two systems: one real one and one with a hostname that doesn't # exist. Make sure the real one didn't get associated with the service # (this checks wheter we rolledback or not.) # a real new system system = create_fake_host(hostname='foobar9.mozilla.com') sblob, resp = self.export_services( 'service.name="{0}"'.format(self.s1.name) ) self.assertEqual(200, resp.status_code, resp.content) self.assertEqual( 1, len(sblob['services']), "Should have seen only one service" ) sblob['services'][0]['systems'] += [system.hostname, 'not.real.com'] resp_json, resp = self.import_services(sblob) self.assertEqual( resp.status_code, 400, "Expected error but got: " "{0}".format(resp.content) ) self.assertTrue( 'errors' in resp_json, "expected to see an 'errors' key" ) # The real system still sholdn't be in the service system = system.refresh() self.assertFalse(system.service_set.exists())
def setUp(self): Domain.objects.create(name="com") self.domain = Domain.objects.create(name="foo.com") Domain.objects.create(name="arpa") Domain.objects.create(name="in-addr.arpa") Domain.objects.create(name="10.in-addr.arpa") Domain.objects.create(name="ip6.arpa") Domain.objects.create(name="1.ip6.arpa") self.network_v6 = Network.objects.create( network_str="1234:1234:1234::/16", ip_type='6' ) start_str = "1234:1234:1234:1::" end_str = "1234:1234:1234:1234:1234:1234::" self.r_v6 = Range.objects.create( start_str=start_str, end_str=end_str, network=self.network_v6, ip_type='6' ) self.network_v4 = Network.objects.create( network_str="10.0.0.0/8", ip_type='4' ) start_str = "10.0.0.0" end_str = "10.200.0.0" self.r_v4 = Range.objects.create( start_str=start_str, end_str=end_str, network=self.network_v4, ip_type='4' ) self.s = create_fake_host(hostname="foo1.mozilla.com")
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 = create_fake_host(hostname="foo.mozilla.com") 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") StaticReg.objects.create( label="foo", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system ) self.assertEqual(str(r.get_next_ip()), "10.0.33.2") StaticReg.objects.create( label="foo", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system ) self.assertEqual(str(r.get_next_ip()), "10.0.33.3") StaticReg.objects.create( label="foo", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system ) self.assertEqual(r.get_next_ip(), None)
def setUp(self): View.objects.create(name="public") View.objects.create(name="private") self.d = create_fake_zone('foo.com', suffix="") self.rd = create_fake_zone('10.in-addr.arpa', suffix="") self.client = Client() self.s = create_fake_host(hostname='exists.mozilla.com')
def test2(self): ip_start = "10.0.1.0" ip_end = "10.0.1.99" ptr = PTR(name="foo.mz", ip_str="10.0.1.3", ip_type="4") ptr.full_clean() ptr.save() a = AddressRecord(label="foo", domain=self.domain, ip_str="10.0.1.3", ip_type="4") a.full_clean() a.save() s = create_fake_host(hostname="foo.mozilla.com") s.save() sreg = StaticReg.objects.create(label="foo", domain=self.domain, ip_str="10.0.1.4", ip_type="4", system=s) istart, iend, ipf_q = start_end_filter(ip_start, ip_end, "4") addrs = list(AddressRecord.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper")) ptrs = list(PTR.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper")) sregs = list(StaticReg.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper")) self.assertEqual(a.pk, addrs[0].pk) self.assertEqual(ptr.pk, ptrs[0].pk) self.assertEqual(sreg.pk, sregs[0].pk) range_details = range_usage(ip_start, ip_end, "4") self.assertEqual(98, range_details["unused"]) self.assertEqual(2, range_details["used"]) self.assertEqual( [(int(istart) + 0, int(istart) + 2), (int(istart) + 5, int(istart) + 99)], range_details["free_ranges"] )
def test_non_existant_system(self): # add two systems: one real one and one with a hostname that doesn't # exist. Make sure the real one didn't get associated with the service # (this checks wheter we rolledback or not.) # a real new system system = create_fake_host(hostname='foobar9.mozilla.com') sblob, resp = self.export_services('service.name="{0}"'.format( self.s1.name)) self.assertEqual(200, resp.status_code, resp.content) self.assertEqual(1, len(sblob['services']), "Should have seen only one service") sblob['services'][0]['systems'] += [system.hostname, 'not.real.com'] resp_json, resp = self.import_services(sblob) self.assertEqual(resp.status_code, 400, "Expected error but got: " "{0}".format(resp.content)) self.assertTrue('errors' in resp_json, "expected to see an 'errors' key") # The real system still sholdn't be in the service system = system.refresh() self.assertFalse(system.service_set.exists())
def setUp(self): create_fake_zone('10.in-addr.arpa', suffix='') self.domain = create_fake_zone('foo.mozilla.com', suffix='') self.s = create_fake_host(hostname='foo.mozilla.com') self.sreg = StaticReg.objects.create( label='', domain=self.domain, ip_str='10.0.0.1', ip_type='4', system=self.s )
def setUp(self): System.objects.all().delete() self.hostname = "searching.mozilla.com" self.notes = "foo bar baz" s = create_fake_host(hostname=self.hostname) s.notes = self.notes s.save() self.status = s.system_status.status
def setUp(self): Domain.objects.all().delete() self.arpa = self.create_domain(name='arpa') self.i_arpa = self.create_domain(name='in-addr.arpa') self.i6_arpa = self.create_domain(name='ip6.arpa') self.domain = create_fake_zone('foo.mozilla.com', suffix='') self.s = create_fake_host(hostname='mozilla.com')
def test_override_spaces(self): test_csv = """ hostname , warranty_start, warranty_end, serial,system_type%type_name,allocation%name foobob.mozilla.com, 2011-03-01 , 2012-03-12,asdf,foobar,something """ s = create_fake_host(hostname='foobob.mozilla.com', serial='1234') self.client_tst(test_csv, save=True) s = System.objects.get(hostname='foobob.mozilla.com') self.assertTrue(s.serial, '1234')
def setUp(self): create_fake_zone('10.in-addr.arpa', suffix='') self.domain = create_fake_zone('foo.mozilla.com', suffix='') self.s = create_fake_host(hostname='foo.mozilla.com') self.sreg = StaticReg.objects.create(label='', domain=self.domain, ip_str='10.0.0.1', ip_type='4', system=self.s)
def setUp(self): self.g = create_fake_zone("gz", suffix="") self.c_g = create_fake_zone("coo.gz", suffix="") self.d = create_fake_zone("dz", suffix="") self.r1 = create_fake_zone("10.in-addr.arpa", suffix="") self.r1.save() self.s = create_fake_host(hostname="foo.mozilla.com") self.s.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='ip6.arpa') self.i6_arpa.save() self.domain = create_fake_zone('foo.mozilla.com', suffix='') self.s = create_fake_host(hostname='mozilla.com')
def test_primary_attribute(self): s = create_fake_host(hostname='foobob.mozilla.com') test_csv = """ primary_attribute%hostname,hostname,warranty_start,warranty_end,serial,system_type%type_name,allocation%name foobob.mozilla.com,foobar.mozilla.com,2012-01-01,2012-01-01,asdf,foobar,something """ self.client_tst(test_csv, save=True, primary_attr='asset_tag') # The primary_attr kwarg shouldn't affect anything s1 = System.objects.get(pk=s.pk) self.assertEqual('foobar.mozilla.com', s1.hostname)
def test_system_update(self): s = create_fake_host(hostname='foo.mozilla.com') new_hostname = 'foo1.mozilla.com' post_data = { 'hostname': new_hostname } resp = self.client.post( self.localize_url(s.get_edit_url()), post_data, follow=True ) self.assertTrue(resp.status_code in (200, 201)) s = System.objects.get(pk=s.pk) self.assertEqual(s.hostname, new_hostname)
def setUp(self): self.client = Client() self.site = Site.objects.create(full_name='foo') self.s1 = Service.objects.create(name='ldap', site=self.site) sys1 = create_fake_host(hostname='foobar1.mozilla.com') sys2 = create_fake_host(hostname='foobar2.mozilla.com') sys3 = create_fake_host(hostname='foobar3.mozilla.com') self.s1.systems.add(sys1) self.s1.systems.add(sys2) self.s1.systems.add(sys3) self.s1.save() self.s2 = Service.objects.create(name='dns and stuff') sys4 = create_fake_host(hostname='foobar4.mozilla.com') sys5 = create_fake_host(hostname='foobar5.mozilla.com') sys6 = create_fake_host(hostname='foobar6.mozilla.com') self.s2.systems.add(sys4) self.s2.systems.add(sys5) self.s2.systems.add(sys6) self.s2.save() self.s3 = Service.objects.create(name='dns and stuff', site=self.site) # make s1 depend on s2 and s3 Dependency.objects.get_or_create( dependant=self.s1, provider=self.s2 ) Dependency.objects.get_or_create( dependant=self.s1, provider=self.s3 )
def setUp(self): self.client = Client() self.site = Site.objects.create(full_name='foo') self.s1 = Service.objects.create(name='ldap', site=self.site) self.sys1 = create_fake_host(hostname='foobar1.mozilla.com') self.sys2 = create_fake_host(hostname='foobar2.mozilla.com') self.sys3 = create_fake_host(hostname='foobar3.mozilla.com') self.s1.systems.add(self.sys1) self.s1.systems.add(self.sys2) self.s1.systems.add(self.sys3) self.s1.save() self.s2 = Service.objects.create(name='dns and stuff') sys4 = create_fake_host(hostname='foobar4.mozilla.com') sys5 = create_fake_host(hostname='foobar5.mozilla.com') sys6 = create_fake_host(hostname='foobar6.mozilla.com') self.s2.systems.add(sys4) self.s2.systems.add(sys5) self.s2.systems.add(sys6) self.s2.save() self.s3 = Service.objects.create(name='dns and stuff', site=self.site) # make s1 depend on s2 and s3 Dependency.objects.get_or_create(dependant=self.s1, provider=self.s2) Dependency.objects.get_or_create(dependant=self.s1, provider=self.s3)
def setUp(self): serial = 'asdf' self.external_serial = serial + 'asdf' self.s = create_fake_host(hostname='fakehost.mozilla.com', serial=serial) ExternalData.objects.create( system=self.s, name='serial', source_name='serial', data=self.external_serial, # conflict data source='foo-source', policy=P_OVERLAY) self.c = Client()
def test_import_add_system(self): # export, add one system, assert the sytem was added original = self.get_service(self.s1.iql_stmt()) s = create_fake_host(hostname='hihihi.mozilla.com') original['services'][0]['systems'].append(s.hostname) self.assertFalse(self.s1.systems.filter(hostname=s.hostname).exists()) _, resp = self.import_services(original) self.assertEqual(resp.status_code, 200, resp.content) self.assertTrue(self.s1.systems.filter(hostname=s.hostname).exists())
def test1_delete_basic(self): # Does deleting a system delete it's interfaces? label = "foo" domain = self.f_c ip_str = "10.0.0.2" system = create_fake_host(hostname="foo") system.save() kwargs = { 'label': label, 'domain': domain, 'ip_str': ip_str, 'system': system} self.do_add(**kwargs) self.assertTrue(StaticReg.objects.filter(**kwargs)) system.delete() self.assertFalse(StaticReg.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 = create_fake_host(hostname="foo.mozilla.com") self.n.clean() self.n.save()
def setUp(self): serial = 'asdf' self.external_serial = serial + 'asdf' self.s = create_fake_host( hostname='fakehost.mozilla.com', serial=serial ) ExternalData.objects.create( system=self.s, name='serial', source_name='serial', data=self.external_serial, # conflict data source='foo-source', policy=P_OVERLAY ) self.c = Client()
def setUp(self): self.o = Domain(name="org") self.o.save() self.f_o = Domain(name="foo.org") self.f_o.save() self.s = create_fake_host(hostname="foo.mozilla.com") 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 setUp(self): self.factory = RequestFactory() self.arpa = self.create_domain(name='arpa') self.i_arpa = self.create_domain(name='in-addr.arpa') self.i6_arpa = self.create_domain(name='ip6.arpa') self.r, _ = Domain.objects.get_or_create(name="ru") self.f_r, _ = Domain.objects.get_or_create(name="foo.ru") self.b_f_r, _ = Domain.objects.get_or_create(name="bar.foo.ru") self.f, _ = Domain.objects.get_or_create(name="fam") self._128 = self.create_domain(name='128', ip_type='4') self._128.save() self.s = create_fake_host(hostname="foo.mozilla.com")
def setUp(self): self.arpa = self.create_domain(name='arpa') self.arpa.save() self.i_arpa = self.create_domain(name='ip6.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 = create_fake_host(hostname="foo.mozilla.com") self.n.clean() self.n.save()
def setUp(self): self.test_type.objects.all().delete() self.rdtype = self.test_type().rdtype self.create_url = "{0}/create/{1}/".format(self.record_base_url, self.rdtype) self.update_url_template = self.create_url + "{1}/" self.c = Client() self.factory = RequestFactory() self.domain = create_fake_zone("{0}.{1}.{2}".format( random_label(), random_label(), random_label())) self.second_domain = create_fake_zone("{0}.{1}.{2}".format( random_label(), random_label(), random_label())) self.public_view = View.objects.get_or_create(name='public')[0] self.private_view = View.objects.get_or_create(name='private')[0] self.system = create_fake_host(hostname="foo.bar.com") self.system.save()
def setUp(self): self.c = Client() create_fake_zone('10.in-addr.arpa', suffix='') root_domain = create_fake_zone('foobar.mozilla.com', suffix='') system = create_fake_host(hostname="asdf.mozilla.com") sreg = StaticReg.objects.create( label='foo', domain=root_domain, system=system, ip_type='4', ip_str='10.0.0.0' ) g = Group.objects.create(name="foo") self.test_objs = ( ('groupkeyvalue', g), ('staticregkeyvalue', sreg), ('keyvalue', system), )
def setUp(self): self.r1 = create_fake_zone("10.in-addr.arpa", suffix="") self.sr = self.r1.soa self.sr.dirty = False self.sr.save() self.dom = create_fake_zone("bgaz", suffix="") self.soa = self.dom.soa self.soa.dirty = False self.soa.save() self.rdom = create_fake_zone("123.in-addr.arpa", suffix="") self.rsoa = self.r1.soa self.rsoa.dirty = False self.rsoa.save() self.s = create_fake_host(hostname="foo.mozilla.com") self.s.save()
def setUp(self): self.c = Client() create_fake_zone('10.in-addr.arpa', suffix='') root_domain = create_fake_zone('foobar.mozilla.com', suffix='') system = create_fake_host(hostname="asdf.mozilla.com") sreg = StaticReg.objects.create(label='foo', domain=root_domain, system=system, ip_type='4', ip_str='10.0.0.0') g = Group.objects.create(name="foo") self.test_objs = ( ('groupkeyvalue', g), ('staticregkeyvalue', sreg), ('keyvalue', system), )
def setUp(self): self.test_type.objects.all().delete() self.rdtype = self.test_type().rdtype self.create_url = "{0}/create/{1}/".format(self.record_base_url, self.rdtype) self.update_url_template = self.create_url + "{1}/" self.c = Client() self.factory = RequestFactory() self.domain = create_fake_zone("{0}.{1}.{2}".format(random_label(), random_label(), random_label())) self.second_domain = create_fake_zone("{0}.{1}.{2}".format( random_label(), random_label(), random_label()) ) self.public_view = View.objects.get_or_create(name='public')[0] self.private_view = View.objects.get_or_create(name='private')[0] self.system = create_fake_host(hostname="foo.bar.com") self.system.save()
def setUp(self): self.r1 = create_fake_zone("10.in-addr.arpa", suffix="") self.sr = self.r1.soa self.sr.dirty = False self.sr.save() self.dom = create_fake_zone("bgaz", suffix="") self.soa = self.dom.soa self.soa.dirty = False self.soa.save() self.rdom = create_fake_zone("123.in-addr.arpa", suffix="") self.rsoa = self.r1.soa self.rsoa.dirty = False self.rsoa.save() self.s = create_fake_host(hostname="foo.mozilla.com") self.s.save() Task.dns_full.all().delete()
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.r2 = self.create_domain(name="128") self.r2.save() self.n = create_fake_host(hostname="foo.mozilla.com") self.n.clean() self.n.save() View.objects.get_or_create(name="private")
def test2(self): ip_start = "10.0.1.0" ip_end = "10.0.1.99" ptr = PTR(name="foo.mz", ip_str="10.0.1.3", ip_type='4') ptr.full_clean() ptr.save() a = AddressRecord(label="foo", domain=self.domain, ip_str="10.0.1.3", ip_type='4') a.full_clean() a.save() s = create_fake_host(hostname="foo.mozilla.com") s.save() sreg = StaticReg.objects.create(label="foo", domain=self.domain, ip_str="10.0.1.4", ip_type='4', system=s) istart, iend, ipf_q = start_end_filter(ip_start, ip_end, '4') addrs = list( AddressRecord.objects.filter(ipf_q).order_by('ip_lower').order_by( 'ip_upper')) ptrs = list( PTR.objects.filter(ipf_q).order_by('ip_lower').order_by( 'ip_upper')) sregs = list( StaticReg.objects.filter(ipf_q).order_by('ip_lower').order_by( 'ip_upper')) self.assertEqual(a.pk, addrs[0].pk) self.assertEqual(ptr.pk, ptrs[0].pk) self.assertEqual(sreg.pk, sregs[0].pk) range_details = range_usage(ip_start, ip_end, '4') self.assertEqual(98, range_details['unused']) self.assertEqual(2, range_details['used']) self.assertEqual([(int(istart) + 0, int(istart) + 2), (int(istart) + 5, int(istart) + 99)], range_details['free_ranges'])
def test_get_asset_tag(self): test_csv = """ hostname,warranty_start,warranty_end,asset_tag,serial,system_type%type_name,allocation%name foobob.mozilla.com,2011-03-01,2012-03-12,1234,asdf,foobar,something """ s = create_fake_host(hostname='foobob.mozilla.com') self.client_tst(test_csv, save=True) s = System.objects.get(hostname='foobob.mozilla.com') self.assertTrue(s.asset_tag, '1234') test_csv = """ hostname,warranty_start,warranty_end,asset_tag,serial,system_type%type_name,allocation%name changed-the-hostname.mozilla.com,2011-03-01,2012-03-12,1234,asdf,foobar,something """ self.client_tst(test_csv, save=True, primary_attr='asset_tag') self.assertEqual( 0, System.objects.filter(hostname='foobob.mozilla.com').count()) s = System.objects.get(hostname='changed-the-hostname.mozilla.com') self.assertTrue(s) self.assertEqual('1234', s.asset_tag)
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 = create_fake_host(hostname="fooasdf.mozilla.com") 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") StaticReg.objects.create(label="foobar", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system) self.assertEqual(str(r.get_next_ip()), "10.0.33.2") StaticReg.objects.create(label="foobar", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system) self.assertEqual(str(r.get_next_ip()), "10.0.33.3") StaticReg.objects.create(label="foobar", domain=self.d, ip_type='4', ip_str=str(r.get_next_ip()), system=system) self.assertEqual(r.get_next_ip(), None)
def test_import_remove_system(self): # export, add one system, assert the sytem was added, remove it, assert # it was removed sblob = self.get_service(self.s1.iql_stmt()) # create s = create_fake_host(hostname='hihihi.mozilla.com') # add sblob['services'][0]['systems'].append(s.hostname) # new host shouldn't exist in the service self.assertFalse(self.s1.systems.filter(hostname=s.hostname).exists()) # import _, resp = self.import_services(sblob) self.assertEqual(resp.status_code, 200, resp.content) # new host should now exist in the service self.assertTrue(self.s1.systems.filter(hostname=s.hostname).exists()) # refresh the blob for good measure sblob = self.get_service(self.s1.iql_stmt()) # make sure the system's hostname is in the blob (this may be # redundant) self.assertTrue(s.hostname in sblob['services'][0]['systems']) # remove the host form the export blob sblob['services'][0]['systems'].remove(s.hostname) # import the blob _, resp = self.import_services(sblob) self.assertEqual(resp.status_code, 200, resp.content) # make sure it was removed self.assertFalse(self.s1.systems.filter(hostname=s.hostname).exists())