コード例 #1
0
ファイル: test_link.py プロジェクト: erssebaggala/magma
    def test_edit_link_properties(self) -> None:
        add_link(
            client=self.client,
            equipment_a=self.equipment1,
            port_name_a="Port 1",
            equipment_b=self.equipment2,
            port_name_b="Port 1",
        )
        fetched_port = get_port(client=self.client,
                                equipment=self.equipment1,
                                port_name="Port 1")
        edit_link_properties(
            client=self.client,
            equipment=self.equipment1,
            port_name="Port 1",
            new_link_properties={"link property": "test_link_property"},
        )
        fetched_port = get_port(client=self.client,
                                equipment=self.equipment1,
                                port_name="Port 1")

        link = fetched_port.link
        link_properties = link.properties if link else []
        self.assertEqual(1, len(link_properties))
        link_property = link_properties[0]
        link_property_type = link_property.propertyType if link_property else None
        property_name = link_property_type.name if link_property_type else None
        value = link_property.stringValue if link_property else None

        self.assertEqual(property_name, "link property")
        self.assertEqual(value, "test_link_property")
コード例 #2
0
ファイル: test_link.py プロジェクト: sijad/magma
    def test_cannot_create_link_if_port_occupied(self) -> None:
        location = add_location(
            self.client,
            [("City", "Lima")],
            {
                "Mayor": "Bernard King",
                "Contact": "*****@*****.**"
            },
            10,
            20,
        )
        router1 = add_equipment(
            self.client,
            "TPLinkRouter1",
            "Tp-Link T1600G",
            location,
            {"IP": "192.688.0.1"},
        )
        router2 = add_equipment(
            self.client,
            "TPLinkRouter2",
            "Tp-Link T1600G",
            location,
            {"IP": "192.688.0.2"},
        )
        router3 = add_equipment(
            self.client,
            "TPLinkRouter3",
            "Tp-Link T1600G",
            location,
            {"IP": "192.688.0.2"},
        )
        link = add_link(self.client, router1, "Port 1", router2, "Port 1")
        fetched_link1 = get_link_in_port_of_equipment(self.client, router1,
                                                      "Port 1")
        fetched_link2 = get_link_in_port_of_equipment(self.client, router2,
                                                      "Port 1")
        self.assertEqual(link, fetched_link1)
        self.assertEqual(link, fetched_link2)

        self.assertRaises(
            PortAlreadyOccupiedException,
            add_link,
            self.client,
            router2,
            "Port 1",
            router3,
            "Port 1",
        )

        link = add_link(self.client, router2, "Port 2", router3, "Port 1")
        fetched_link1 = get_link_in_port_of_equipment(self.client, router2,
                                                      "Port 2")
        fetched_link2 = get_link_in_port_of_equipment(self.client, router3,
                                                      "Port 1")
        self.assertEqual(link, fetched_link1)
        self.assertEqual(link, fetched_link2)
コード例 #3
0
ファイル: test_link.py プロジェクト: fbcode/magma_old
 def test_get_links(self) -> None:
     links = get_links(client=self.client)
     self.assertEqual(len(links), 1)
     add_link(
         client=self.client,
         equipment_a=self.equipment2,
         port_name_a="Port 2",
         equipment_b=self.equipment3,
         port_name_b="Port 1",
     )
     links = get_links(client=self.client)
     self.assertEqual(len(links), 2)
コード例 #4
0
    def test_cannot_create_link_if_port_occupied(self) -> None:
        fetched_link1 = get_link_in_port_of_equipment(
            client=self.client, equipment=self.equipment1, port_name="Port 1")
        fetched_link2 = get_link_in_port_of_equipment(
            client=self.client, equipment=self.equipment2, port_name="Port 1")
        self.assertEqual(self.link1, fetched_link1)
        self.assertEqual(self.link1, fetched_link2)

        self.assertRaises(
            PortAlreadyOccupiedException,
            add_link,
            self.client,
            self.equipment2,
            "Port 1",
            self.equipment3,
            "Port 1",
        )

        link = add_link(
            client=self.client,
            equipment_a=self.equipment2,
            port_name_a="Port 2",
            equipment_b=self.equipment3,
            port_name_b="Port 1",
        )
        fetched_link1 = get_link_in_port_of_equipment(
            client=self.client, equipment=self.equipment2, port_name="Port 2")
        fetched_link2 = get_link_in_port_of_equipment(
            client=self.client, equipment=self.equipment3, port_name="Port 1")
        self.assertEqual(link, fetched_link1)
        self.assertEqual(link, fetched_link2)
コード例 #5
0
ファイル: test_service.py プロジェクト: sijad/magma
    def test_service_with_topology_created(self) -> None:
        location = add_location(
            self.client, [("Room", "Room 201")], {"Contact": "*****@*****.**"}, 10, 20
        )
        router1 = add_equipment(
            self.client,
            "TPLinkRouter1",
            "Tp-Link T1600G",
            location,
            {"IP": "192.688.0.1"},
        )
        router2 = add_equipment(
            self.client,
            "TPLinkRouter2",
            "Tp-Link T1600G",
            location,
            {"IP": "192.688.0.2"},
        )
        router3 = add_equipment(
            self.client,
            "TPLinkRouter3",
            "Tp-Link T1600G",
            location,
            {"IP": "192.688.0.3"},
        )
        link1 = add_link(self.client, router1, "Port 1", router2, "Port 1")
        link2 = add_link(self.client, router2, "Port 2", router3, "Port 1")
        endpoint_port = get_port(self.client, router1, "Port 2")
        service = add_service(
            self.client,
            name="Room 201 Internet Access",
            external_id="S3232",
            service_type="Internet Access",
            customer=None,
            properties_dict={"Address Family": "v4"},
            links=[link1, link2],
        )
        add_service_endpoint(
            self.client, service, endpoint_port, ServiceEndpointRole.CONSUMER
        )
        service = get_service(self.client, service.id)

        self.assertEqual([endpoint_port.id], [e.port.id for e in service.endpoints])
        self.assertEqual([link1.id, link2.id], [s.id for s in service.links])
コード例 #6
0
ファイル: test_link.py プロジェクト: erssebaggala/magma
 def test_add_link(self) -> None:
     link = add_link(
         client=self.client,
         equipment_a=self.equipment1,
         port_name_a="Port 1",
         equipment_b=self.equipment2,
         port_name_b="Port 1",
     )
     fetched_link1 = get_link_in_port_of_equipment(
         client=self.client, equipment=self.equipment1, port_name="Port 1")
     fetched_link2 = get_link_in_port_of_equipment(
         client=self.client, equipment=self.equipment2, port_name="Port 1")
     self.assertEqual(link, fetched_link1)
     self.assertEqual(link, fetched_link2)
コード例 #7
0
    def test_service_with_topology_created(self) -> None:
        location = add_location(
            client=self.client,
            location_hirerchy=[("Room", "Room 201")],
            properties_dict={"Contact": "*****@*****.**"},
            lat=10,
            long=20,
        )
        router1 = add_equipment(
            client=self.client,
            name="TPLinkRouter1",
            equipment_type="Tp-Link T1600G",
            location=location,
            properties_dict={"IP": "192.688.0.1"},
        )
        router2 = add_equipment(
            client=self.client,
            name="TPLinkRouter2",
            equipment_type="Tp-Link T1600G",
            location=location,
            properties_dict={"IP": "192.688.0.2"},
        )
        router3 = add_equipment(
            client=self.client,
            name="TPLinkRouter3",
            equipment_type="Tp-Link T1600G",
            location=location,
            properties_dict={"IP": "192.688.0.3"},
        )
        link1 = add_link(
            client=self.client,
            equipment_a=router1,
            port_name_a="Port 1",
            equipment_b=router2,
            port_name_b="Port 1",
        )
        link2 = add_link(
            client=self.client,
            equipment_a=router2,
            port_name_a="Port 2",
            equipment_b=router3,
            port_name_b="Port 1",
        )
        endpoint_port = get_port(client=self.client,
                                 equipment=router1,
                                 port_name="Port 2")
        service = add_service(
            self.client,
            name="Room 201 Internet Access",
            external_id="S3232",
            service_type="Internet Access",
            customer=None,
            properties_dict={"Address Family": "v4"},
            links=[link1, link2],
        )
        # TODO add service_endpoint_type api
        add_service_endpoint(client=self.client,
                             service=service,
                             port=endpoint_port)

        service = get_service(client=self.client,
                              id=service.id if service is not None else "")
        ports = [e.port for e in service.endpoints]
        self.assertEqual([endpoint_port.id],
                         [p.id if p is not None else None for p in ports])
        self.assertEqual([link1.id, link2.id], [s.id for s in service.links])
コード例 #8
0
 def test_service_link_added(self) -> None:
     add_equipment_port_type(
         self.client,
         name="port type 1",
         properties=[
             PropertyDefinition(
                 property_name="port property",
                 property_kind=PropertyKind.string,
                 default_raw_value="port property value",
                 is_fixed=False,
             )
         ],
         link_properties=[
             PropertyDefinition(
                 property_name="link property",
                 property_kind=PropertyKind.string,
                 default_raw_value="link property value",
                 is_fixed=False,
             )
         ],
     )
     add_location_type(
         client=self.client,
         name="Room",
         properties=[
             PropertyDefinition(
                 property_name="Contact",
                 property_kind=PropertyKind.email,
                 default_raw_value=None,
                 is_fixed=False,
             )
         ],
     )
     location = add_location(
         client=self.client,
         location_hirerchy=[("Room", "Room 201")],
         properties_dict={"Contact": "*****@*****.**"},
         lat=10,
         long=20,
     )
     equipment_type = add_equipment_type(
         client=self.client,
         name="Tp-Link T1600G",
         category="Router",
         properties=[
             PropertyDefinition(
                 property_name="IP",
                 property_kind=PropertyKind.string,
                 default_raw_value=None,
                 is_fixed=False,
             )
         ],
         ports_dict={
             "Port 1": "port type 1",
             "Port 2": "port type 1"
         },
         position_list=[],
     )
     router1 = add_equipment(
         client=self.client,
         name="TPLinkRouter1",
         equipment_type=equipment_type.name,
         location=location,
         properties_dict={"IP": "192.688.0.1"},
     )
     router2 = add_equipment(
         client=self.client,
         name="TPLinkRouter2",
         equipment_type=equipment_type.name,
         location=location,
         properties_dict={"IP": "192.688.0.2"},
     )
     router3 = add_equipment(
         client=self.client,
         name="TPLinkRouter3",
         equipment_type=equipment_type.name,
         location=location,
         properties_dict={"IP": "192.688.0.3"},
     )
     link1 = add_link(
         client=self.client,
         equipment_a=router1,
         port_name_a="Port 1",
         equipment_b=router2,
         port_name_b="Port 1",
     )
     link2 = add_link(
         client=self.client,
         equipment_a=router2,
         port_name_a="Port 2",
         equipment_b=router3,
         port_name_b="Port 1",
     )
     links = get_service_links(client=self.client,
                               service_id=self.service.id)
     self.assertFalse(links)
     for link in [link1, link2]:
         add_service_link(client=self.client,
                          service_id=self.service.id,
                          link_id=link.id)
     links = get_service_links(client=self.client,
                               service_id=self.service.id)
     self.assertEqual(len(links), 2)
コード例 #9
0
 def setUp(self) -> None:
     super().setUp()
     add_equipment_port_type(
         self.client,
         name="port type 1",
         properties=[
             PropertyDefinition(
                 property_name="port property",
                 property_kind=PropertyKind.string,
                 default_raw_value="port property value",
                 is_fixed=False,
             )
         ],
         link_properties=[
             PropertyDefinition(
                 property_name="link property",
                 property_kind=PropertyKind.string,
                 default_raw_value="link property value",
                 is_fixed=False,
             )
         ],
     )
     add_location_type(
         client=self.client,
         name="City",
         properties=[
             PropertyDefinition(
                 property_name="Mayor",
                 property_kind=PropertyKind.string,
                 default_raw_value=None,
                 is_fixed=False,
             ),
             PropertyDefinition(
                 property_name="Contact",
                 property_kind=PropertyKind.email,
                 default_raw_value=None,
                 is_fixed=False,
             ),
         ],
     )
     self.location = add_location(
         client=self.client,
         location_hirerchy=[("City", "Lima")],
         properties_dict={
             "Mayor": "Bernard King",
             "Contact": "*****@*****.**"
         },
         lat=10,
         long=20,
     )
     add_equipment_type(
         client=self.client,
         name="Tp-Link T1600G",
         category="Router",
         properties=[
             PropertyDefinition(
                 property_name="IP",
                 property_kind=PropertyKind.string,
                 default_raw_value=None,
                 is_fixed=False,
             )
         ],
         ports_dict={
             "Port 1": "port type 1",
             "Port 2": "port type 1"
         },
         position_list=[],
     )
     self.equipment1 = add_equipment(
         client=self.client,
         name="TPLinkRouter1",
         equipment_type="Tp-Link T1600G",
         location=self.location,
         properties_dict={"IP": "192.688.0.1"},
     )
     self.equipment2 = add_equipment(
         client=self.client,
         name="TPLinkRouter2",
         equipment_type="Tp-Link T1600G",
         location=self.location,
         properties_dict={"IP": "192.688.0.2"},
     )
     self.equipment3 = add_equipment(
         client=self.client,
         name="TPLinkRouter3",
         equipment_type="Tp-Link T1600G",
         location=self.location,
         properties_dict={"IP": "192.688.0.2"},
     )
     self.link1 = add_link(
         client=self.client,
         equipment_a=self.equipment1,
         port_name_a="Port 1",
         equipment_b=self.equipment2,
         port_name_b="Port 1",
     )
コード例 #10
0
    def test_service_with_topology_created(self) -> None:
        add_equipment_port_type(
            self.client,
            name="port type 1",
            properties=[
                PropertyDefinition(
                    property_name="port property",
                    property_kind=PropertyKind.string,
                    default_value="port property value",
                    is_fixed=False,
                )
            ],
            link_properties=[
                PropertyDefinition(
                    property_name="link property",
                    property_kind=PropertyKind.string,
                    default_value="link property value",
                    is_fixed=False,
                )
            ],
        )
        add_location_type(
            client=self.client,
            name="Room",
            properties=[("Contact", "email", None, True)],
        )
        location = add_location(
            client=self.client,
            location_hirerchy=[("Room", "Room 201")],
            properties_dict={"Contact": "*****@*****.**"},
            lat=10,
            long=20,
        )
        add_equipment_type(
            client=self.client,
            name="Tp-Link T1600G",
            category="Router",
            properties=[("IP", "string", None, True)],
            ports_dict={
                "Port 1": "port type 1",
                "Port 2": "port type 1"
            },
            position_list=[],
        )
        router1 = add_equipment(
            client=self.client,
            name="TPLinkRouter1",
            equipment_type="Tp-Link T1600G",
            location=location,
            properties_dict={"IP": "192.688.0.1"},
        )
        router2 = add_equipment(
            client=self.client,
            name="TPLinkRouter2",
            equipment_type="Tp-Link T1600G",
            location=location,
            properties_dict={"IP": "192.688.0.2"},
        )
        router3 = add_equipment(
            client=self.client,
            name="TPLinkRouter3",
            equipment_type="Tp-Link T1600G",
            location=location,
            properties_dict={"IP": "192.688.0.3"},
        )
        link1 = add_link(
            client=self.client,
            equipment_a=router1,
            port_name_a="Port 1",
            equipment_b=router2,
            port_name_b="Port 1",
        )
        link2 = add_link(
            client=self.client,
            equipment_a=router2,
            port_name_a="Port 2",
            equipment_b=router3,
            port_name_b="Port 1",
        )

        endpoint_port = get_port(client=self.client,
                                 equipment=router1,
                                 port_name="Port 2")

        for link in [link1, link2]:
            add_service_link(client=self.client,
                             service_id=self.service.id,
                             link_id=link.id)
        # TODO add service_endpoint_defintion api
        add_service_endpoint(
            client=self.client,
            service_id=self.service.id,
            equipment_id="1",
            endpoint_definition_id="1",
        )

        ports = [e.port for e in self.service.endpoints]
        self.assertEqual([endpoint_port.id],
                         [p.id if p is not None else None for p in ports])
        self.assertEqual([link1.id, link2.id],
                         [s.id for s in self.service.links])