Example #1
0
    def _get_device_from_serial(serial):
        if not serial:
            return Device(serial=None)

        try:
            device = Device.objects.get(serial=serial)
        except Device.DoesNotExist:
            return Device(serial=serial)
        else:
            return device
Example #2
0
def netbox(db):
    box = Netbox(ip='10.254.254.254', sysname='example-sw.example.org',
                 organization_id='myorg', room_id='myroom', category_id='SW',
                 snmp_version=2, read_only='public')
    box.save()

    device = Device(serial="1234test")
    device.save()
    module = Module(device=device, netbox=box, name='Module 1', model='')
    module.save()

    interface = Interface(netbox=box, module=module, ifname='1',
                          ifdescr='Port 1')
    interface.save()

    return box
Example #3
0
def netbox(db, management_profile):
    box = Netbox(ip='10.254.254.254', sysname='example-sw.example.org',
                 organization_id='myorg', room_id='myroom', category_id='SW')
    box.save()
    NetboxProfile(netbox=box, profile=management_profile).save()

    device = Device(serial="1234test")
    device.save()
    module = Module(device=device, netbox=box, name='Module 1', model='')
    module.save()

    interface = Interface(netbox=box, module=module, ifname='1',
                          ifdescr='Port 1')
    interface.save()

    return box
Example #4
0
def test_netbox_should_be_annotated_with_chassis_serial(db, localhost):
    """Mainly, this verifies that regressions haven't rendered the raw SQL used to
    annotate netboxes with serial numbers incompatible with the current schema.
    """
    for index, serial in enumerate(["first", "second"]):
        device = Device(serial=serial)
        device.save()
        chassis = NetboxEntity(
            netbox=localhost,
            device=device,
            index=index,
            physical_class=NetboxEntity.CLASS_CHASSIS,
        )
        chassis.save()

    netbox = Netbox.objects.with_chassis_serials().filter(id=localhost.id)[0]
    assert netbox.chassis_serial == "first"
Example #5
0
 def setUp(self):
     self.event = Event(
         source=Subsystem('someone'),
         netbox=Netbox(),
         device=Device(),
         subid="thing",
         event_type=EventType('boxState'),
         state=Event.STATE_START,
         time=datetime.datetime.now(),
         value=50,
         severity=80,
     )