示例#1
0
    def test_single_sreg_update(self):
        hostname = 'puppet12.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "system_type": {system_type},
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                    "staticreg_set": {{
                        "nic1": {{
                            "description": "Migrated SREG",
                            "views": [{private_view_pk}],
                            "fqdn": "{hostname}",
                            "ttl": null,
                            "ip_type": "4",
                            "ip_str": "10.8.75.10"
                        }}
                    }}
                }}
            }}
        }}
        """.format(system_type=self.system_type.pk,
                   allocation_pk=self.allocation.pk,
                   hostname=hostname,
                   private_view_pk=View.objects.get(name='private').pk)
        blobs, error = bulk_import(data)
        self.assertFalse(error)
        self.assertTrue(
            'pk' in blobs['systems'][hostname]['staticreg_set']['nic1'])
        sreg = StaticReg.objects.get(
            pk=blobs['systems'][hostname]['staticreg_set']['nic1']['pk'])
        self.assertTrue(sreg)
        self.assertTrue(sreg.system)

        # Change the views and ip address. Make sure the updates worked.
        new_ip = "10.8.75.11"
        blobs['systems'][hostname]['staticreg_set']['nic1']['ip_str'] = new_ip
        blobs['systems'][hostname]['staticreg_set']['nic1']['views'] = [
            View.objects.get(name='public').pk,
            View.objects.get(name='private').pk
        ]

        blobs, error = bulk_import(blobs, load_json=False)
        sreg = StaticReg.objects.get(pk=sreg.pk)
        self.assertTrue(sreg)
        self.assertEqual(new_ip, sreg.ip_str)
        self.assertEqual(2, sreg.views.all().count())
        self.assertTrue(sreg.system)
示例#2
0
 def test_single_create(self):
     hostname = 'puppet1.foobar.mozilla.com'
     data = """
     {{
         "systems": {{
             "{hostname}": {{
                 "asset_tag": "7349",
                 "serial": "MXQ14901XV",
                 "system_type": {system_type},
                 "rack_order": "1.16",
                 "hostname": "{hostname}",
                 "patch_panel_port": "",
                 "purchase_date": null,
                 "warranty_start": null,
                 "purchase_price": "1.0",
                 "oob_ip": "10.8.0.25",
                 "allocation": {allocation_pk},
                 "warranty_end": null,
                 "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16"
             }}
         }}
     }}
     """.format(allocation_pk=self.allocation.pk,
                hostname=hostname,
                system_type=self.system_type.pk)
     pre_count = System.objects.all().count()
     json_data, error = bulk_import(data)
     self.assertFalse(error)
     s = System.objects.get(hostname=hostname)
     post_count = System.objects.all().count()
     self.assertTrue(pre_count == post_count - 1)
     self.assertUpdated(hostname, json_data, s)
示例#3
0
文件: tests.py 项目: bclary/inventory
 def test_single_create(self):
     hostname = 'puppet1.foobar.mozilla.com'
     data = """
     {{
         "systems": {{
             "{hostname}": {{
                 "asset_tag": "7349",
                 "serial": "MXQ14901XV",
                 "system_type": {system_type},
                 "rack_order": "1.16",
                 "hostname": "{hostname}",
                 "patch_panel_port": "",
                 "purchase_date": null,
                 "warranty_start": null,
                 "purchase_price": "1.0",
                 "oob_ip": "10.8.0.25",
                 "allocation": {allocation_pk},
                 "warranty_end": null,
                 "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16"
             }}
         }}
     }}
     """.format(allocation_pk=self.allocation.pk, hostname=hostname,
                system_type=self.system_type.pk)
     pre_count = System.objects.all().count()
     json_data, error = bulk_import(data)
     self.assertFalse(error)
     s = System.objects.get(hostname=hostname)
     post_count = System.objects.all().count()
     self.assertTrue(pre_count == post_count - 1)
     self.assertUpdated(hostname, json_data, s)
示例#4
0
    def test_single_update(self):
        hostname = 'puppet2.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "system_type": {system_type},
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16"
                }}
            }}
        }}
        """.format(allocation_pk=self.allocation.pk,
                   hostname=hostname,
                   system_type=self.system_type.pk)
        pre_count = System.objects.all().count()
        json_data, error = bulk_import(data)
        self.assertFalse(error)
        s = System.objects.get(hostname=hostname)
        post_count = System.objects.all().count()
        self.assertTrue(pre_count == post_count - 1)
        s = System.objects.get(pk=s.pk)
        self.assertUpdated(hostname, json_data, s)

        # We now have an object created and the blob has a 'pk'. try changing
        # the hostname.
        new_hostname = 'asdf' + hostname
        json_data['systems'][hostname]['hostname'] = new_hostname

        pre_count = System.objects.all().count()
        json_data, error = bulk_import(json_data, load_json=False)
        self.assertFalse(error)
        s = System.objects.get(hostname=new_hostname)
        post_count = System.objects.all().count()
        self.assertTrue(pre_count == post_count)
        s = System.objects.get(pk=s.pk)
        self.assertUpdated(new_hostname, json_data, s)
示例#5
0
文件: tests.py 项目: bclary/inventory
    def test_single_update(self):
        hostname = 'puppet2.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "system_type": {system_type},
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16"
                }}
            }}
        }}
        """.format(allocation_pk=self.allocation.pk, hostname=hostname,
                   system_type=self.system_type.pk)
        pre_count = System.objects.all().count()
        json_data, error = bulk_import(data)
        self.assertFalse(error)
        s = System.objects.get(hostname=hostname)
        post_count = System.objects.all().count()
        self.assertTrue(pre_count == post_count - 1)
        s = System.objects.get(pk=s.pk)
        self.assertUpdated(hostname, json_data, s)

        # We now have an object created and the blob has a 'pk'. try changing
        # the hostname.
        new_hostname = 'asdf' + hostname
        json_data['systems'][hostname]['hostname'] = new_hostname

        pre_count = System.objects.all().count()
        json_data, error = bulk_import(json_data, load_json=False)
        self.assertFalse(error)
        s = System.objects.get(hostname=new_hostname)
        post_count = System.objects.all().count()
        self.assertTrue(pre_count == post_count)
        s = System.objects.get(pk=s.pk)
        self.assertUpdated(new_hostname, json_data, s)
示例#6
0
文件: tests.py 项目: bclary/inventory
 def test_single_sreg_create(self):
     hostname = 'puppet5.foobar.mozilla.com'
     data = """
     {{
         "systems": {{
             "{hostname}": {{
                 "system_type": {system_type},
                 "asset_tag": "7349",
                 "serial": "MXQ14901XV",
                 "rack_order": "1.16",
                 "hostname": "{hostname}",
                 "patch_panel_port": "",
                 "purchase_date": null,
                 "warranty_start": null,
                 "purchase_price": "1.0",
                 "oob_ip": "10.8.0.25",
                 "allocation": {allocation_pk},
                 "warranty_end": null,
                 "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                 "staticreg_set": {{
                     "nic0": {{
                         "description": "Migrated SREG",
                         "views": [{private_view_pk}],
                         "fqdn": "{hostname}",
                         "ttl": null,
                         "ip_type": "4",
                         "ip_str": "10.8.75.10"
                     }}
                 }}
             }}
         }}
     }}
     """.format(
         allocation_pk=self.allocation.pk, hostname=hostname,
         system_type=self.system_type.pk,
         private_view_pk=self.private_view.pk
     )
     blobs, error = bulk_import(data)
     self.assertFalse(error)
     self.assertTrue(
         'pk' in blobs['systems'][hostname]['staticreg_set']['nic0']
     )
     sreg = StaticReg.objects.get(
         pk=blobs['systems'][hostname]['staticreg_set']['nic0']['pk']
     )
     self.assertTrue(sreg)
     self.assertTrue(sreg.system)
     self.assertTrue(sreg.views.filter(name='private'))
     self.assertEqual(1, len(sreg.views.all()))
 def test_single_sreg_create(self):
     hostname = 'puppet5.foobar.mozilla.com'
     data = """
     {{
         "systems": {{
             "{hostname}": {{
                 "system_type": {system_type},
                 "asset_tag": "7349",
                 "serial": "MXQ14901XV",
                 "rack_order": "1.16",
                 "hostname": "{hostname}",
                 "patch_panel_port": "",
                 "purchase_date": null,
                 "warranty_start": null,
                 "purchase_price": "1.0",
                 "oob_ip": "10.8.0.25",
                 "allocation": {allocation_pk},
                 "warranty_end": null,
                 "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                 "staticreg_set": {{
                     "nic0": {{
                         "description": "Migrated SREG",
                         "views": [{private_view_pk}],
                         "fqdn": "{hostname}",
                         "ttl": null,
                         "ip_type": "4",
                         "ip_str": "10.8.75.10"
                     }}
                 }}
             }}
         }}
     }}
     """.format(
         allocation_pk=self.allocation.pk, hostname=hostname,
         system_type=self.system_type.pk,
         private_view_pk=self.private_view.pk
     )
     blobs, error = bulk_import(data)
     self.assertFalse(error)
     self.assertTrue(
         'pk' in blobs['systems'][hostname]['staticreg_set']['nic0']
     )
     sreg = StaticReg.objects.get(
         pk=blobs['systems'][hostname]['staticreg_set']['nic0']['pk']
     )
     self.assertTrue(sreg)
     self.assertTrue(sreg.system)
     self.assertTrue(sreg.views.filter(name='private'))
     self.assertEqual(1, len(sreg.views.all()))
示例#8
0
文件: tests.py 项目: bclary/inventory
 def test_pk_in_new_objects(self):
     hostname = 'puppet3.foobar.mozilla.com'
     data = """
     {{
         "systems": {{
             "{hostname}": {{
                 "asset_tag": "7349",
                 "serial": "MXQ14901XV",
                 "rack_order": "1.16",
                 "hostname": "{hostname}",
                 "patch_panel_port": "",
                 "purchase_date": null,
                 "warranty_start": null,
                 "purchase_price": "1.0",
                 "oob_ip": "10.8.0.25",
                 "allocation": {allocation_pk},
                 "warranty_end": null,
                 "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                 "staticreg_set": {{
                     "nic0": {{
                         "description": "Migrated SREG",
                         "views": [{private_view_pk}],
                         "system": 5046,
                         "fqdn": "puppet1.private.phx1.mozilla.com",
                         "ttl": null,
                         "ip_type": "4",
                         "pk": 11,
                         "ip_str": "10.8.75.10"
                     }}
                 }}
             }}
         }}
     }}
     """.format(
         allocation_pk=self.allocation.pk, hostname=hostname,
         private_view_pk=self.private_view.pk,
         system_type=self.system_type.pk
     )
     blobs, error = bulk_import(data)
     self.assertFalse(blobs)
     self.assertTrue(error)
 def test_pk_in_new_objects(self):
     hostname = 'puppet3.foobar.mozilla.com'
     data = """
     {{
         "systems": {{
             "{hostname}": {{
                 "asset_tag": "7349",
                 "serial": "MXQ14901XV",
                 "rack_order": "1.16",
                 "hostname": "{hostname}",
                 "patch_panel_port": "",
                 "purchase_date": null,
                 "warranty_start": null,
                 "purchase_price": "1.0",
                 "oob_ip": "10.8.0.25",
                 "allocation": {allocation_pk},
                 "warranty_end": null,
                 "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                 "staticreg_set": {{
                     "nic0": {{
                         "description": "Migrated SREG",
                         "views": [{private_view_pk}],
                         "system": 5046,
                         "fqdn": "puppet1.private.phx1.mozilla.com",
                         "ttl": null,
                         "ip_type": "4",
                         "pk": 11,
                         "ip_str": "10.8.75.10"
                     }}
                 }}
             }}
         }}
     }}
     """.format(
         allocation_pk=self.allocation.pk, hostname=hostname,
         private_view_pk=self.private_view.pk,
         system_type=self.system_type.pk
     )
     blobs, error = bulk_import(data)
     self.assertFalse(blobs)
     self.assertTrue(error)
示例#10
0
文件: tests.py 项目: bclary/inventory
    def test_single_sreg_update(self):
        hostname = 'puppet12.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "system_type": {system_type},
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                    "staticreg_set": {{
                        "nic1": {{
                            "description": "Migrated SREG",
                            "views": [{private_view_pk}],
                            "fqdn": "{hostname}",
                            "ttl": null,
                            "ip_type": "4",
                            "ip_str": "10.8.75.10"
                        }}
                    }}
                }}
            }}
        }}
        """.format(
            system_type=self.system_type.pk,
            allocation_pk=self.allocation.pk, hostname=hostname,
            private_view_pk=View.objects.get(name='private').pk
        )
        blobs, error = bulk_import(data)
        self.assertFalse(error)
        self.assertTrue(
            'pk' in blobs['systems'][hostname]['staticreg_set']['nic1']
        )
        sreg = StaticReg.objects.get(
            pk=blobs['systems'][hostname]['staticreg_set']['nic1']['pk']
        )
        self.assertTrue(sreg)
        self.assertTrue(sreg.system)

        # Change the views and ip address. Make sure the updates worked.
        new_ip = "10.8.75.11"
        blobs['systems'][hostname]['staticreg_set']['nic1']['ip_str'] = new_ip
        blobs['systems'][hostname]['staticreg_set']['nic1']['views'] = [
            View.objects.get(name='public').pk,
            View.objects.get(name='private').pk
        ]

        blobs, error = bulk_import(blobs, load_json=False)
        sreg = StaticReg.objects.get(pk=sreg.pk)
        self.assertTrue(sreg)
        self.assertEqual(new_ip, sreg.ip_str)
        self.assertEqual(2, sreg.views.all().count())
        self.assertTrue(sreg.system)
示例#11
0
    def test_clone_system(self):
        """Make sure the system's history is copied over. Also, check the
        created_on field to make sure it is coppied correctly"""
        old_hostname = 'puppet678.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "system_type": {system_type},
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16"
                }}
            }}
        }}
        """.format(allocation_pk=self.allocation.pk,
                   hostname=old_hostname,
                   system_type=self.system_type.pk)

        _, error = bulk_import(data)
        self.assertFalse(error)

        s = System.objects.get(hostname=old_hostname)
        s.serial = "asdf"
        s.save()
        System.objects.filter(pk=s.pk).update(created_on=None)

        self.assertEqual(1, s.systemchangelog_set.all().count())

        hostname = 'puppet679.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "asset_tag": "7349",
                    "clone": "{clone_hostname}",
                    "serial": "MXQ14901XV",
                    "system_type": {system_type},
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16"
                }}
            }}
        }}
        """.format(allocation_pk=self.allocation.pk,
                   hostname=hostname,
                   system_type=self.system_type.pk,
                   clone_hostname=old_hostname)

        _, error = bulk_import(data)
        self.assertFalse(error)

        new_s = System.objects.get(hostname=hostname)
        self.assertEqual(2, new_s.systemchangelog_set.all().count())
        self.assertEqual(None, new_s.created_on)
示例#12
0
    def test_single_hw_update(self):
        hostname = 'puppet99.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "system_type": {system_type},
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                    "staticreg_set": {{
                        "nic1": {{
                            "description": "Migrated SREG",
                            "views": [{private_view_pk}],
                            "fqdn": "{hostname}",
                            "ttl": null,
                            "ip_type": "4",
                            "ip_str": "10.8.75.10",
                            "hwadapter_set": {{
                                "hw0": {{
                                    "mac": "44:1E:A1:5C:01:B4",
                                    "name": "hw0",
                                    "enable_dhcp": true,
                                    "description": null,
                                    "keyvalue_set": {{
                                        "{hostname}": {{
                                          "key": "hostname",
                                          "value": "{hostname}"
                                        }},
                                        "phx1-vlan80": {{
                                          "key": "dhcp_scope",
                                          "value": "phx1-vlan80"
                                        }}
                                    }}
                                }}
                            }}
                        }}
                    }}
                }}
            }}
        }}
        """.format(system_type=self.system_type.pk,
                   allocation_pk=self.allocation.pk,
                   hostname=hostname,
                   private_view_pk=View.objects.get(name='private').pk)
        blobs, error = bulk_import(data)
        self.assertFalse(error)
        self.assertTrue(
            'pk' in blobs['systems'][hostname]['staticreg_set']['nic1'])
        sreg = StaticReg.objects.get(
            pk=blobs['systems'][hostname]['staticreg_set']['nic1']['pk'])
        hw = sreg.hwadapter_set.get(mac="44:1E:A1:5C:01:B4")
        kv = hw.keyvalue_set.get(key='hostname')
        self.assertTrue(sreg)
        self.assertTrue(sreg.system)
        self.assertEqual(1, sreg.hwadapter_set.all().count())

        # Change the mac, make things are saved
        new_hostname = 'asdfasdf' + hostname
        new_mac = "44:1E:A1:5C:01:99"
        blobs['systems'][hostname]['staticreg_set']['nic1']['hwadapter_set'][
            'hw0']['mac'] = new_mac  # noqa
        # Chage the hostname in the kv set too
        kvs = blobs['systems'][hostname]['staticreg_set']['nic1'][
            'hwadapter_set']['hw0']['keyvalue_set'].values()  # noqa
        for kv in kvs:
            if kv['key'] == 'hostname':
                kv['value'] = new_hostname

        blobs, error = bulk_import(blobs, load_json=False)

        hw = hw.__class__.objects.get(pk=hw.pk)
        kv = hw.keyvalue_set.get(key='hostname')
        self.assertEqual(new_mac, hw.mac)
        self.assertEqual(new_hostname, kv.value)
示例#13
0
    def test_single_cname_update(self):
        hostname = 'puppet101.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "system_type": {system_type},
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                    "staticreg_set": {{
                        "nic1": {{
                            "cname": [
                                {{
                                    "description": "",
                                    "views": [{private_view_pk}],
                                    "fqdn": "puppet99.build.mozilla.org",
                                    "target": "{hostname}",
                                    "ttl": null
                                }}
                            ],
                            "description": "Migrated SREG",
                            "views": [{private_view_pk}],
                            "fqdn": "{hostname}",
                            "ttl": null,
                            "ip_type": "4",
                            "ip_str": "10.8.75.10",
                            "hwadapter_set": {{
                                "hw0": {{
                                    "mac": "44:1E:A1:5C:01:B4",
                                    "name": "hw0",
                                    "enable_dhcp": true,
                                    "description": null,
                                    "keyvalue_set": {{
                                        "{hostname}": {{
                                          "key": "hostname",
                                          "value": "{hostname}"
                                        }},
                                        "phx1-vlan80": {{
                                          "key": "dhcp_scope",
                                          "value": "phx1-vlan80"
                                        }}
                                    }}
                                }}
                            }}
                        }}
                    }}
                }}
            }}
        }}
        """.format(system_type=self.system_type.pk,
                   allocation_pk=self.allocation.pk,
                   hostname=hostname,
                   private_view_pk=self.private_view.pk)
        blobs, error = bulk_import(data)
        self.assertFalse(error)
        self.assertTrue(
            'pk' in blobs['systems'][hostname]['staticreg_set']['nic1'])
        self.assertEqual(
            1,
            len(blobs['systems'][hostname]['staticreg_set']['nic1']
                ['cname'])  # noqa
        )
        self.assertTrue('pk' in blobs['systems'][hostname]['staticreg_set']
                        ['nic1']['cname'][0]  # noqa
                        )
        sreg = StaticReg.objects.get(
            pk=blobs['systems'][hostname]['staticreg_set']['nic1']['pk'])
        self.assertTrue(sreg)
        cname = CNAME.objects.get(
            pk=blobs['systems'][hostname]['staticreg_set']['nic1']['cname'][0][
                'pk']  # noqa
        )
        self.assertTrue(cname.views.filter(name='private').exists())

        new_fqdn = 'asdfasdfasdf.build.mozilla.org'
        blobs['systems'][hostname]['staticreg_set']['nic1']['cname'][0][
            'fqdn'] = new_fqdn  # noqa

        blobs, error = bulk_import(blobs, load_json=False)
        cname = CNAME.objects.get(pk=cname.pk)
        self.assertEqual(new_fqdn, cname.fqdn)
示例#14
0
 def test_single_hw_create(self):
     hostname = 'puppet6.foobar.mozilla.com'
     data = """
     {{
         "systems": {{
             "{hostname}": {{
                 "system_type": {system_type},
                 "asset_tag": "7349",
                 "serial": "MXQ14901XV",
                 "rack_order": "1.16",
                 "hostname": "{hostname}",
                 "patch_panel_port": "",
                 "purchase_date": null,
                 "warranty_start": null,
                 "purchase_price": "1.0",
                 "oob_ip": "10.8.0.25",
                 "allocation": {allocation_pk},
                 "warranty_end": null,
                 "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                 "staticreg_set": {{
                     "nic1": {{
                         "description": "Migrated SREG",
                         "views": [{private_view_pk}],
                         "fqdn": "{hostname}",
                         "ttl": null,
                         "ip_type": "4",
                         "ip_str": "10.8.75.10",
                         "hwadapter_set": {{
                             "hw0": {{
                                 "mac": "44:1E:A1:5C:01:B4",
                                 "name": "hw0",
                                 "enable_dhcp": true,
                                 "description": null,
                                 "keyvalue_set": {{
                                     "{hostname}": {{
                                       "key": "hostname",
                                       "value": "{hostname}"
                                     }},
                                     "phx1-vlan80": {{
                                       "key": "dhcp_scope",
                                       "value": "phx1-vlan80"
                                     }}
                                 }}
                             }}
                         }}
                     }}
                 }}
             }}
         }}
     }}
     """.format(system_type=self.system_type.pk,
                allocation_pk=self.allocation.pk,
                hostname=hostname,
                private_view_pk=self.private_view.pk)
     blobs, error = bulk_import(data)
     self.assertFalse(error)
     self.assertTrue(
         'pk' in blobs['systems'][hostname]['staticreg_set']['nic1'])
     sreg = StaticReg.objects.get(
         pk=blobs['systems'][hostname]['staticreg_set']['nic1']['pk'])
     self.assertTrue(sreg)
     self.assertTrue(sreg.system)
     self.assertEqual(1, sreg.hwadapter_set.all().count())
     hw = sreg.hwadapter_set.get(mac="44:1E:A1:5C:01:B4")
     self.assertEqual(2, hw.keyvalue_set.all().count())
     hw.keyvalue_set.get(key='hostname', value=hostname)
     hw.keyvalue_set.get(key='dhcp_scope', value='phx1-vlan80')
示例#15
0
文件: tests.py 项目: bclary/inventory
 def test_single_hw_create(self):
     hostname = 'puppet6.foobar.mozilla.com'
     data = """
     {{
         "systems": {{
             "{hostname}": {{
                 "system_type": {system_type},
                 "asset_tag": "7349",
                 "serial": "MXQ14901XV",
                 "rack_order": "1.16",
                 "hostname": "{hostname}",
                 "patch_panel_port": "",
                 "purchase_date": null,
                 "warranty_start": null,
                 "purchase_price": "1.0",
                 "oob_ip": "10.8.0.25",
                 "allocation": {allocation_pk},
                 "warranty_end": null,
                 "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                 "staticreg_set": {{
                     "nic1": {{
                         "description": "Migrated SREG",
                         "views": [{private_view_pk}],
                         "fqdn": "{hostname}",
                         "ttl": null,
                         "ip_type": "4",
                         "ip_str": "10.8.75.10",
                         "hwadapter_set": {{
                             "hw0": {{
                                 "mac": "44:1E:A1:5C:01:B4",
                                 "name": "hw0",
                                 "enable_dhcp": true,
                                 "description": null,
                                 "keyvalue_set": {{
                                     "{hostname}": {{
                                       "key": "hostname",
                                       "value": "{hostname}"
                                     }},
                                     "phx1-vlan80": {{
                                       "key": "dhcp_scope",
                                       "value": "phx1-vlan80"
                                     }}
                                 }}
                             }}
                         }}
                     }}
                 }}
             }}
         }}
     }}
     """.format(
         system_type=self.system_type.pk,
         allocation_pk=self.allocation.pk, hostname=hostname,
         private_view_pk=self.private_view.pk
     )
     blobs, error = bulk_import(data)
     self.assertFalse(error)
     self.assertTrue(
         'pk' in blobs['systems'][hostname]['staticreg_set']['nic1']
     )
     sreg = StaticReg.objects.get(
         pk=blobs['systems'][hostname]['staticreg_set']['nic1']['pk']
     )
     self.assertTrue(sreg)
     self.assertTrue(sreg.system)
     self.assertEqual(1, sreg.hwadapter_set.all().count())
     hw = sreg.hwadapter_set.get(mac="44:1E:A1:5C:01:B4")
     self.assertEqual(2, hw.keyvalue_set.all().count())
     hw.keyvalue_set.get(key='hostname', value=hostname)
     hw.keyvalue_set.get(key='dhcp_scope', value='phx1-vlan80')
示例#16
0
文件: tests.py 项目: bclary/inventory
    def test_single_hw_update(self):
        hostname = 'puppet99.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "system_type": {system_type},
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                    "staticreg_set": {{
                        "nic1": {{
                            "description": "Migrated SREG",
                            "views": [{private_view_pk}],
                            "fqdn": "{hostname}",
                            "ttl": null,
                            "ip_type": "4",
                            "ip_str": "10.8.75.10",
                            "hwadapter_set": {{
                                "hw0": {{
                                    "mac": "44:1E:A1:5C:01:B4",
                                    "name": "hw0",
                                    "enable_dhcp": true,
                                    "description": null,
                                    "keyvalue_set": {{
                                        "{hostname}": {{
                                          "key": "hostname",
                                          "value": "{hostname}"
                                        }},
                                        "phx1-vlan80": {{
                                          "key": "dhcp_scope",
                                          "value": "phx1-vlan80"
                                        }}
                                    }}
                                }}
                            }}
                        }}
                    }}
                }}
            }}
        }}
        """.format(
            system_type=self.system_type.pk,
            allocation_pk=self.allocation.pk, hostname=hostname,
            private_view_pk=View.objects.get(name='private').pk
        )
        blobs, error = bulk_import(data)
        self.assertFalse(error)
        self.assertTrue(
            'pk' in blobs['systems'][hostname]['staticreg_set']['nic1']
        )
        sreg = StaticReg.objects.get(
            pk=blobs['systems'][hostname]['staticreg_set']['nic1']['pk']
        )
        hw = sreg.hwadapter_set.get(mac="44:1E:A1:5C:01:B4")
        kv = hw.keyvalue_set.get(key='hostname')
        self.assertTrue(sreg)
        self.assertTrue(sreg.system)
        self.assertEqual(1, sreg.hwadapter_set.all().count())

        # Change the mac, make things are saved
        new_hostname = 'asdfasdf' + hostname
        new_mac = "44:1E:A1:5C:01:99"
        blobs['systems'][hostname]['staticreg_set']['nic1']['hwadapter_set']['hw0']['mac'] = new_mac  # noqa
        # Chage the hostname in the kv set too
        kvs = blobs['systems'][hostname]['staticreg_set']['nic1']['hwadapter_set']['hw0']['keyvalue_set'].values()  # noqa
        for kv in kvs:
            if kv['key'] == 'hostname':
                kv['value'] = new_hostname

        blobs, error = bulk_import(blobs, load_json=False)

        hw = hw.__class__.objects.get(pk=hw.pk)
        kv = hw.keyvalue_set.get(key='hostname')
        self.assertEqual(new_mac, hw.mac)
        self.assertEqual(new_hostname, kv.value)
示例#17
0
文件: tests.py 项目: bclary/inventory
    def test_clone_system(self):
        """Make sure the system's history is copied over. Also, check the
        created_on field to make sure it is coppied correctly"""
        old_hostname = 'puppet678.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "system_type": {system_type},
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16"
                }}
            }}
        }}
        """.format(allocation_pk=self.allocation.pk, hostname=old_hostname,
                   system_type=self.system_type.pk)

        _, error = bulk_import(data)
        self.assertFalse(error)

        s = System.objects.get(hostname=old_hostname)
        s.serial = "asdf"
        s.save()
        System.objects.filter(pk=s.pk).update(created_on=None)

        self.assertEqual(1, s.systemchangelog_set.all().count())

        hostname = 'puppet679.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "asset_tag": "7349",
                    "clone": "{clone_hostname}",
                    "serial": "MXQ14901XV",
                    "system_type": {system_type},
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16"
                }}
            }}
        }}
        """.format(allocation_pk=self.allocation.pk, hostname=hostname,
                   system_type=self.system_type.pk,
                   clone_hostname=old_hostname)

        _, error = bulk_import(data)
        self.assertFalse(error)

        new_s = System.objects.get(hostname=hostname)
        self.assertEqual(2, new_s.systemchangelog_set.all().count())
        self.assertEqual(None, new_s.created_on)
示例#18
0
文件: tests.py 项目: bclary/inventory
    def test_single_cname_update(self):
        hostname = 'puppet101.foobar.mozilla.com'
        data = """
        {{
            "systems": {{
                "{hostname}": {{
                    "system_type": {system_type},
                    "asset_tag": "7349",
                    "serial": "MXQ14901XV",
                    "rack_order": "1.16",
                    "hostname": "{hostname}",
                    "patch_panel_port": "",
                    "purchase_date": null,
                    "warranty_start": null,
                    "purchase_price": "1.0",
                    "oob_ip": "10.8.0.25",
                    "allocation": {allocation_pk},
                    "warranty_end": null,
                    "switch_ports": "    bsx-b09: Gi1/0/16, Gi2/0/16",
                    "staticreg_set": {{
                        "nic1": {{
                            "cname": [
                                {{
                                    "description": "",
                                    "views": [{private_view_pk}],
                                    "fqdn": "puppet99.build.mozilla.org",
                                    "target": "{hostname}",
                                    "ttl": null
                                }}
                            ],
                            "description": "Migrated SREG",
                            "views": [{private_view_pk}],
                            "fqdn": "{hostname}",
                            "ttl": null,
                            "ip_type": "4",
                            "ip_str": "10.8.75.10",
                            "hwadapter_set": {{
                                "hw0": {{
                                    "mac": "44:1E:A1:5C:01:B4",
                                    "name": "hw0",
                                    "enable_dhcp": true,
                                    "description": null,
                                    "keyvalue_set": {{
                                        "{hostname}": {{
                                          "key": "hostname",
                                          "value": "{hostname}"
                                        }},
                                        "phx1-vlan80": {{
                                          "key": "dhcp_scope",
                                          "value": "phx1-vlan80"
                                        }}
                                    }}
                                }}
                            }}
                        }}
                    }}
                }}
            }}
        }}
        """.format(
            system_type=self.system_type.pk,
            allocation_pk=self.allocation.pk, hostname=hostname,
            private_view_pk=self.private_view.pk
        )
        blobs, error = bulk_import(data)
        self.assertFalse(error)
        self.assertTrue(
            'pk' in blobs['systems'][hostname]['staticreg_set']['nic1']
        )
        self.assertEqual(
            1, len(blobs['systems'][hostname]['staticreg_set']['nic1']['cname'])  # noqa
        )
        self.assertTrue(
            'pk' in blobs['systems'][hostname]['staticreg_set']['nic1']['cname'][0]  # noqa
        )
        sreg = StaticReg.objects.get(
            pk=blobs['systems'][hostname]['staticreg_set']['nic1']['pk']
        )
        self.assertTrue(sreg)
        cname = CNAME.objects.get(
            pk=blobs['systems'][hostname]['staticreg_set']['nic1']['cname'][0]['pk']  # noqa
        )
        self.assertTrue(cname.views.filter(name='private').exists())

        new_fqdn = 'asdfasdfasdf.build.mozilla.org'
        blobs['systems'][hostname]['staticreg_set']['nic1']['cname'][0]['fqdn'] = new_fqdn  # noqa

        blobs, error = bulk_import(blobs, load_json=False)
        cname = CNAME.objects.get(pk=cname.pk)
        self.assertEqual(new_fqdn, cname.fqdn)