Пример #1
0
 def test_cable_front_port_cannot_connect_to_corresponding_rear_port(self):
     """
     A cable cannot connect a front port to its corresponding rear port
     """
     cable = Cable(termination_a=self.front_port1, termination_b=self.rear_port1)
     with self.assertRaises(ValidationError):
         cable.clean()
Пример #2
0
 def test_cable_cannot_have_the_same_terminination_on_both_ends(self):
     """
     A cable cannot be made with the same A and B side terminations
     """
     cable = Cable(termination_a=self.interface1, termination_b=self.interface1)
     with self.assertRaises(ValidationError):
         cable.clean()
Пример #3
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()
Пример #4
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()
Пример #5
0
 def test_cable_cannot_terminate_to_an_existing_connection(self):
     """
     Either side of a cable cannot be terminated when that side already has a connection
     """
     # Try to create a cable with the same interface terminations
     cable = Cable(termination_a=self.interface2, termination_b=self.interface1)
     with self.assertRaises(ValidationError):
         cable.clean()
Пример #6
0
 def test_cable_validates_compatible_types(self):
     """
     The clean method should have a check to ensure only compatible port types can be connected by a cable
     """
     # An interface cannot be connected to a power port
     cable = Cable(termination_a=self.interface1, termination_b=self.power_port1)
     with self.assertRaises(ValidationError):
         cable.clean()
Пример #7
0
 def test_cable_cannot_terminate_to_a_provider_network_circuittermination(
         self):
     """
     Neither side of a cable can be terminated to a CircuitTermination which is attached to a Provider Network
     """
     cable = Cable(termination_a=self.interface3,
                   termination_b=self.circuittermination3)
     with self.assertRaises(ValidationError):
         cable.clean()
Пример #8
0
    def test_rearport_connections(self):
        """
        Test various combinations of RearPort connections.
        """
        # Connecting a single-position RearPort to a multi-position RearPort is ok
        Cable(
            termination_a=self.rear_port1,
            termination_b=self.rear_port2,
            status=self.status,
        ).full_clean()

        # Connecting a single-position RearPort to an Interface is ok
        Cable(
            termination_a=self.rear_port1,
            termination_b=self.interface3,
            status=self.status,
        ).full_clean()

        # Connecting a single-position RearPort to a CircuitTermination is ok
        Cable(
            termination_a=self.rear_port1,
            termination_b=self.circuittermination1,
            status=self.status,
        ).full_clean()

        # Connecting a multi-position RearPort to another RearPort with the same number of positions is ok
        Cable(
            termination_a=self.rear_port3,
            termination_b=self.rear_port4,
            status=self.status,
        ).full_clean()

        # Connecting a multi-position RearPort to an Interface is ok
        Cable(
            termination_a=self.rear_port2,
            termination_b=self.interface3,
            status=self.status,
        ).full_clean()

        # Connecting a multi-position RearPort to a CircuitTermination is ok
        Cable(
            termination_a=self.rear_port2,
            termination_b=self.circuittermination1,
            status=self.status,
        ).full_clean()

        # Connecting a two-position RearPort to a three-position RearPort is NOT ok
        with self.assertRaises(
                ValidationError,
                msg=
                "Connecting a 2-position RearPort to a 3-position RearPort should fail",
        ):
            Cable(termination_a=self.rear_port2,
                  termination_b=self.rear_port3).full_clean()
Пример #9
0
    def setUp(self):

        site = Site.objects.create(name="Test Site 1", slug="test-site-1")
        manufacturer = Manufacturer.objects.create(name="Test Manufacturer 1",
                                                   slug="test-manufacturer-1")
        devicetype = DeviceType.objects.create(
            manufacturer=manufacturer,
            model="Test Device Type 1",
            slug="test-device-type-1",
        )
        devicerole = DeviceRole.objects.create(name="Test Device Role 1",
                                               slug="test-device-role-1",
                                               color="ff0000")
        self.device1 = Device.objects.create(
            device_type=devicetype,
            device_role=devicerole,
            name="TestDevice1",
            site=site,
        )
        self.device2 = Device.objects.create(
            device_type=devicetype,
            device_role=devicerole,
            name="TestDevice2",
            site=site,
        )
        self.interface1 = Interface.objects.create(device=self.device1,
                                                   name="eth0")
        self.interface2 = Interface.objects.create(device=self.device2,
                                                   name="eth0")
        self.interface3 = Interface.objects.create(device=self.device2,
                                                   name="eth1")
        self.status = Status.objects.get_for_model(Cable).get(slug="connected")
        self.cable = Cable(
            termination_a=self.interface1,
            termination_b=self.interface2,
            status=self.status,
        )
        self.cable.save()

        self.power_port1 = PowerPort.objects.create(device=self.device2,
                                                    name="psu1")
        self.patch_panel = Device.objects.create(
            device_type=devicetype,
            device_role=devicerole,
            name="TestPatchPanel",
            site=site,
        )
        self.rear_port1 = RearPort.objects.create(device=self.patch_panel,
                                                  name="RP1",
                                                  type="8p8c")
        self.front_port1 = FrontPort.objects.create(
            device=self.patch_panel,
            name="FP1",
            type="8p8c",
            rear_port=self.rear_port1,
            rear_port_position=1,
        )
        self.rear_port2 = RearPort.objects.create(device=self.patch_panel,
                                                  name="RP2",
                                                  type="8p8c",
                                                  positions=2)
        self.front_port2 = FrontPort.objects.create(
            device=self.patch_panel,
            name="FP2",
            type="8p8c",
            rear_port=self.rear_port2,
            rear_port_position=1,
        )
        self.rear_port3 = RearPort.objects.create(device=self.patch_panel,
                                                  name="RP3",
                                                  type="8p8c",
                                                  positions=3)
        self.front_port3 = FrontPort.objects.create(
            device=self.patch_panel,
            name="FP3",
            type="8p8c",
            rear_port=self.rear_port3,
            rear_port_position=1,
        )
        self.rear_port4 = RearPort.objects.create(device=self.patch_panel,
                                                  name="RP4",
                                                  type="8p8c",
                                                  positions=3)
        self.front_port4 = FrontPort.objects.create(
            device=self.patch_panel,
            name="FP4",
            type="8p8c",
            rear_port=self.rear_port4,
            rear_port_position=1,
        )
        self.provider = Provider.objects.create(name="Provider 1",
                                                slug="provider-1")
        provider_network = ProviderNetwork.objects.create(
            name="Provider Network 1", provider=self.provider)
        self.circuittype = CircuitType.objects.create(name="Circuit Type 1",
                                                      slug="circuit-type-1")
        self.circuit1 = Circuit.objects.create(provider=self.provider,
                                               type=self.circuittype,
                                               cid="1")
        self.circuit2 = Circuit.objects.create(provider=self.provider,
                                               type=self.circuittype,
                                               cid="2")
        self.circuittermination1 = CircuitTermination.objects.create(
            circuit=self.circuit1, site=site, term_side="A")
        self.circuittermination2 = CircuitTermination.objects.create(
            circuit=self.circuit1, site=site, term_side="Z")
        self.circuittermination3 = CircuitTermination.objects.create(
            circuit=self.circuit2,
            provider_network=provider_network,
            term_side="Z")