Пример #1
0
    def test_interface_ordering_ios(self):

        INTERFACES = [
            "GigabitEthernet0/1",
            "GigabitEthernet0/2",
            "GigabitEthernet0/10",
            "TenGigabitEthernet0/20",
            "TenGigabitEthernet0/21",
            "GigabitEthernet1/1",
            "GigabitEthernet1/2",
            "GigabitEthernet1/10",
            "TenGigabitEthernet1/20",
            "TenGigabitEthernet1/21",
            "FastEthernet1",
            "FastEthernet2",
            "FastEthernet10",
        ]

        for name in INTERFACES:
            iface = Interface(device=self.device, name=name)
            iface.save()

        self.assertListEqual(
            list(
                Interface.objects.filter(device=self.device).values_list(
                    "name", flat=True)),
            INTERFACES,
        )
Пример #2
0
    def test_interface_ordering_linux(self):

        INTERFACES = [
            "eth0",
            "eth0.1",
            "eth0.2",
            "eth0.10",
            "eth0.100",
            "eth1",
            "eth1.1",
            "eth1.2",
            "eth1.100",
            "lo0",
        ]

        for name in INTERFACES:
            iface = Interface(device=self.device, name=name)
            iface.save()

        self.assertListEqual(
            list(
                Interface.objects.filter(device=self.device).values_list(
                    "name", flat=True)),
            INTERFACES,
        )
Пример #3
0
    def test_interface_ordering_junos(self):

        INTERFACES = [
            "xe-0/0/0",
            "xe-0/0/1",
            "xe-0/0/2",
            "xe-0/0/3",
            "xe-0/1/0",
            "xe-0/1/1",
            "xe-0/1/2",
            "xe-0/1/3",
            "xe-1/0/0",
            "xe-1/0/1",
            "xe-1/0/2",
            "xe-1/0/3",
            "xe-1/1/0",
            "xe-1/1/1",
            "xe-1/1/2",
            "xe-1/1/3",
            "xe-2/0/0.1",
            "xe-2/0/0.2",
            "xe-2/0/0.10",
            "xe-2/0/0.11",
            "xe-2/0/0.100",
            "xe-3/0/0:1",
            "xe-3/0/0:2",
            "xe-3/0/0:10",
            "xe-3/0/0:11",
            "xe-3/0/0:100",
            "xe-10/1/0",
            "xe-10/1/1",
            "xe-10/1/2",
            "xe-10/1/3",
            "ae1",
            "ae2",
            "ae10.1",
            "ae10.10",
            "irb.1",
            "irb.2",
            "irb.10",
            "irb.100",
            "lo0",
        ]

        for name in INTERFACES:
            iface = Interface(device=self.device, name=name)
            iface.save()

        self.assertListEqual(
            list(
                Interface.objects.filter(device=self.device).values_list(
                    "name", flat=True)),
            INTERFACES,
        )
Пример #4
0
    def test_interface_ordering_numeric(self):

        INTERFACES = [
            "0",
            "0.0",
            "0.1",
            "0.2",
            "0.10",
            "0.100",
            "0:1",
            "0:1.0",
            "0:1.1",
            "0:1.2",
            "0:1.10",
            "0:2",
            "0:2.0",
            "0:2.1",
            "0:2.2",
            "0:2.10",
            "1",
            "1.0",
            "1.1",
            "1.2",
            "1.10",
            "1.100",
            "1:1",
            "1:1.0",
            "1:1.1",
            "1:1.2",
            "1:1.10",
            "1:2",
            "1:2.0",
            "1:2.1",
            "1:2.2",
            "1:2.10",
        ]

        for name in INTERFACES:
            iface = Interface(device=self.device, name=name)
            iface.save()

        self.assertListEqual(
            list(
                Interface.objects.filter(device=self.device).values_list(
                    "name", flat=True)),
            INTERFACES,
        )
Пример #5
0
 def test_cable_cannot_terminate_to_a_wireless_interface(self):
     """
     A cable cannot terminate to a wireless interface
     """
     wireless_interface = Interface(device=self.device1, name="W1", type=InterfaceTypeChoices.TYPE_80211A)
     cable = Cable(termination_a=self.interface2, termination_b=wireless_interface)
     with self.assertRaises(ValidationError):
         cable.clean()
Пример #6
0
 def test_cable_cannot_terminate_to_a_virtual_interface(self):
     """
     A cable cannot terminate to a virtual interface
     """
     virtual_interface = Interface(device=self.device1, name="V1", type=InterfaceTypeChoices.TYPE_VIRTUAL)
     cable = Cable(termination_a=self.interface2, termination_b=virtual_interface)
     with self.assertRaises(ValidationError):
         cable.clean()
Пример #7
0
    def setUpTestData(cls):

        manufacturers = (
            Manufacturer(name="Manufacturer 1", slug="manufacturer-1"),
            Manufacturer(name="Manufacturer 2", slug="manufacturer-2"),
            Manufacturer(name="Manufacturer 3", slug="manufacturer-3"),
        )
        Manufacturer.objects.bulk_create(manufacturers)

        device_types = (
            DeviceType(
                manufacturer=manufacturers[0],
                model="Model 1",
                slug="model-1",
                is_full_depth=True,
            ),
            DeviceType(
                manufacturer=manufacturers[1],
                model="Model 2",
                slug="model-2",
                is_full_depth=True,
            ),
            DeviceType(
                manufacturer=manufacturers[2],
                model="Model 3",
                slug="model-3",
                is_full_depth=False,
            ),
        )
        DeviceType.objects.bulk_create(device_types)

        device_roles = (
            DeviceRole(name="Device Role 1", slug="device-role-1"),
            DeviceRole(name="Device Role 2", slug="device-role-2"),
            DeviceRole(name="Device Role 3", slug="device-role-3"),
        )
        DeviceRole.objects.bulk_create(device_roles)

        device_statuses = Status.objects.get_for_model(Device)
        device_status_map = {ds.slug: ds for ds in device_statuses.all()}

        platforms = (
            Platform(name="Platform 1", slug="platform-1"),
            Platform(name="Platform 2", slug="platform-2"),
            Platform(name="Platform 3", slug="platform-3"),
        )
        Platform.objects.bulk_create(platforms)

        regions = (
            Region(name="Region 1", slug="region-1"),
            Region(name="Region 2", slug="region-2"),
            Region(name="Region 3", slug="region-3"),
        )
        for region in regions:
            region.save()

        sites = (
            Site(name="Site 1",
                 slug="abc-site-1",
                 region=regions[0],
                 asn=65001),
            Site(name="Site 2",
                 slug="def-site-2",
                 region=regions[1],
                 asn=65101),
            Site(name="Site 3",
                 slug="ghi-site-3",
                 region=regions[2],
                 asn=65201),
        )
        Site.objects.bulk_create(sites)

        racks = (
            Rack(name="Rack 1", site=sites[0]),
            Rack(name="Rack 2", site=sites[1]),
            Rack(name="Rack 3", site=sites[2]),
        )
        Rack.objects.bulk_create(racks)

        devices = (
            Device(
                name="Device 1",
                device_type=device_types[0],
                device_role=device_roles[0],
                platform=platforms[0],
                serial="ABC",
                asset_tag="1001",
                site=sites[0],
                rack=racks[0],
                position=1,
                face=DeviceFaceChoices.FACE_FRONT,
                status=device_status_map["active"],
                local_context_data={"foo": 123},
                comments="Device 1 comments",
            ),
            Device(
                name="Device 2",
                device_type=device_types[1],
                device_role=device_roles[1],
                platform=platforms[1],
                serial="DEF",
                asset_tag="1002",
                site=sites[1],
                rack=racks[1],
                position=2,
                face=DeviceFaceChoices.FACE_FRONT,
                status=device_status_map["staged"],
                comments="Device 2 comments",
            ),
            Device(
                name="Device 3",
                device_type=device_types[2],
                device_role=device_roles[2],
                platform=platforms[2],
                serial="GHI",
                asset_tag="1003",
                site=sites[2],
                rack=racks[2],
                position=3,
                face=DeviceFaceChoices.FACE_REAR,
                status=device_status_map["failed"],
                comments="Device 3 comments",
            ),
        )
        Device.objects.bulk_create(devices)

        interfaces = (
            Interface(device=devices[0],
                      name="Interface 1",
                      mac_address="00-00-00-00-00-01"),
            Interface(device=devices[0],
                      name="Interface 2",
                      mac_address="aa-00-00-00-00-01"),
            Interface(device=devices[1],
                      name="Interface 3",
                      mac_address="00-00-00-00-00-02"),
            Interface(device=devices[1],
                      name="Interface 4",
                      mac_address="bb-00-00-00-00-02"),
            Interface(device=devices[2],
                      name="Interface 5",
                      mac_address="00-00-00-00-00-03"),
            Interface(device=devices[2],
                      name="Interface 6",
                      mac_address="cc-00-00-00-00-03"),
        )
        Interface.objects.bulk_create(interfaces)