示例#1
0
    def test_topology_rules(self):
        restclient = RESTClient("localhost:8082",
                                scheme=self.schemeHTTP,
                                username=self.username,
                                password=self.password,
                                insecure=True)

        noderule1 = restclient.noderule_create(
            "create", metadata={"Name": "node1", "Type": "fabric"})
        noderule2 = restclient.noderule_create(
            "create", metadata={"Name": "node2", "Type": "fabric"})

        time.sleep(1)

        edgerule = restclient.edgerule_create(
                "G.V().Has('Name', 'node1')", "G.V().Has('Name', 'node2')",
                {"RelationType": "layer2", "EdgeName": "my_edge"})

        time.sleep(1)

        node1 = restclient.lookup_nodes("G.V().Has('Name', 'node1')")
        self.assertEqual(len(node1), 1, "should find only one node as node1")

        node2 = restclient.lookup_nodes("G.V().Has('Name', 'node2')")
        self.assertEqual(len(node2), 1, "should find only one node as node2")

        edge = restclient.lookup_edges(
                "G.E().Has('RelationType', 'layer2', 'EdgeName', 'my_edge')")
        self.assertEqual(len(edge), 1, "should find only one edge")

        restclient.edgerule_delete(edgerule.uuid)
        restclient.noderule_delete(noderule1.uuid)
        restclient.noderule_delete(noderule2.uuid)
示例#2
0
    def test_injection(self):
        def create_node(protocol):
            node = Node("TOR_TEST",
                        "",
                        metadata={
                            "Name": "Test TOR",
                            "Type": "fabric"
                        })
            msg = WSMessage("Graph", NodeAddedMsgType, node)
            protocol.sendWSMessage(msg)

            node = Node("PORT_TEST",
                        "",
                        metadata={
                            "Name": "Test port",
                            "Type": "fabric"
                        })
            msg = WSMessage("Graph", NodeAddedMsgType, node)
            protocol.sendWSMessage(msg)

            edge = Edge("TOR_L2LINK",
                        "",
                        "TOR_TEST",
                        "PORT_TEST",
                        metadata={"RelationType": "layer2"})
            msg = WSMessage("Graph", EdgeAddedMsgType, edge)
            protocol.sendWSMessage(msg)

        self.wsclient = WSClient("host-test2",
                                 self.schemeWS +
                                 "://localhost:8082/ws/publisher",
                                 protocol=WSTestClient,
                                 test=create_node,
                                 username=self.username,
                                 password=self.password,
                                 insecure=True)
        self.wsclient.connect()
        self.wsclient.start()

        time.sleep(1)

        restclient = RESTClient("localhost:8082",
                                scheme=self.schemeHTTP,
                                username=self.username,
                                password=self.password,
                                insecure=True)
        nodes = restclient.lookup_nodes("G.V().Has('Name', 'Test port')")
        self.assertEqual(len(nodes), 1, "should find one an only one node")

        tor_id = nodes[0].id
        self.assertEqual(tor_id, nodes[0].id, "wrong id for node")

        edges = restclient.lookup_edges("G.E().Has('RelationType', 'layer2')")
        self.assertEqual(len(edges), 1, "should find one an only one edge")
示例#3
0
 def clear_dragonflow_items(self):
     """Delete all the items created by DragonFlow"""
     restclient = RESTClient(cfg.CONF.df_skydive.analyzer_endpoint,
                             username=cfg.CONF.df_skydive.user,
                             password=cfg.CONF.df_skydive.password)
     items = restclient.lookup_edges("G.E().Has('source', 'dragonflow')")
     for edge in items:
         edge_del_msg = skydive_client.WSMessage(
             "Graph", skydive_client.EdgeDeletedMsgType, edge)
         self.protocol.sendWSMessage(edge_del_msg)
     items = restclient.lookup_nodes("G.V().Has('source', 'dragonflow')")
     for node in items:
         node_del_msg = skydive_client.WSMessage(
             "Graph", skydive_client.NodeDeletedMsgType, node)
         self.protocol.sendWSMessage(node_del_msg)
示例#4
0
文件: tests.py 项目: xuacker/skydive
    def test_injection(self):
        def create_node(protocol):
            node = Node("TOR_TEST", "",
                        metadata={"Name": "Test TOR", "Type": "fabric"})
            msg = WSMessage("Graph", NodeAddedMsgType, node)
            protocol.sendWSMessage(msg)

            node = Node("PORT_TEST", "",
                        metadata={"Name": "Test port", "Type": "fabric"})
            msg = WSMessage("Graph", NodeAddedMsgType, node)
            protocol.sendWSMessage(msg)

            edge = Edge("TOR_L2LINK", "",
                        "TOR_TEST", "PORT_TEST",
                        metadata={"RelationType": "layer2"})
            msg = WSMessage("Graph", EdgeAddedMsgType, edge)
            protocol.sendWSMessage(msg)

        self.wsclient = WSClient("host-test2",
                                 self.schemeWS +
                                 "://localhost:8082/ws/publisher",
                                 protocol=WSTestClient, test=create_node,
                                 username=self.username,
                                 password=self.password,
                                 insecure=True)
        self.wsclient.connect()
        self.wsclient.start()

        time.sleep(1)

        restclient = RESTClient("localhost:8082",
                                scheme=self.schemeHTTP,
                                username=self.username,
                                password=self.password,
                                insecure=True)
        nodes = restclient.lookup_nodes("G.V().Has('Name', 'Test port')")
        self.assertEqual(len(nodes), 1, "should find one an only one node")

        tor_id = nodes[0].id
        self.assertEqual(tor_id, nodes[0].id, "wrong id for node")

        edges = restclient.lookup_edges(
            "G.E().Has('RelationType', 'layer2')")
        self.assertEqual(len(edges), 1, "should find one an only one edge")
示例#5
0
        def create_node(protocol):
            node = Node("TOR_TEST",
                        "",
                        metadata={
                            "Name": "Test TOR",
                            "Type": "fabric"
                        })
            msg = WSMessage("Graph", NodeAddedMsgType, node)
            protocol.sendWSMessage(msg)

            node = Node("PORT_TEST",
                        "",
                        metadata={
                            "Name": "Test port",
                            "Type": "fabric"
                        })
            msg = WSMessage("Graph", NodeAddedMsgType, node)
            protocol.sendWSMessage(msg)

            edge = Edge("TOR_L2LINK",
                        "",
                        "TOR_TEST",
                        "PORT_TEST",
                        metadata={"RelationType": "layer2"})
            msg = WSMessage("Graph", EdgeAddedMsgType, edge)
            protocol.sendWSMessage(msg)

            time.sleep(1)

            restclient = RESTClient("localhost:8082")
            nodes = restclient.lookup_nodes("G.V().Has('Name', 'Test port')")
            self.assertEqual(len(nodes), 1, "should find one an only one node")

            tor_id = nodes[0].id
            self.assertEqual(tor_id, nodes[0].id, "wrong id for node")

            edges = restclient.lookup_edges(
                "G.E().Has('RelationType', 'layer2')")
            self.assertEqual(len(edges), 1, "should find one an only one edge")