コード例 #1
0
    def test_link_events(self, grpc_server: CoreGrpcServer,
                         ip_prefixes: IpPrefixes):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        wlan = session.add_node(WlanNode)
        node = session.add_node(CoreNode)
        interface = ip_prefixes.create_interface(node)
        session.add_link(node.id, wlan.id, interface)
        link_data = wlan.all_link_data()[0]
        queue = Queue()

        def handle_event(event_data):
            assert event_data.session_id == session.id
            assert event_data.HasField("link_event")
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session.broadcast_link(link_data)

            # then
            queue.get(timeout=5)
コード例 #2
0
ファイル: test_grpc.py プロジェクト: tinchoa/core
    def test_exception_events(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        queue = Queue()
        exception_level = ExceptionLevels.FATAL
        source = "test"
        node_id = None
        text = "exception message"

        def handle_event(event_data):
            assert event_data.session_id == session.id
            assert event_data.HasField("exception_event")
            exception_event = event_data.exception_event
            assert exception_event.level == exception_level.value
            assert exception_event.node_id == 0
            assert exception_event.source == source
            assert exception_event.text == text
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session.exception(exception_level, source, node_id, text)

            # then
            queue.get(timeout=5)
コード例 #3
0
    def test_node_events(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node(CoreNode)
        node.position.lat = 10.0
        node.position.lon = 20.0
        node.position.alt = 5.0
        queue = Queue()

        def handle_event(event_data):
            assert event_data.session_id == session.id
            assert event_data.HasField("node_event")
            event_node = event_data.node_event.node
            assert event_node.geo.lat == node.position.lat
            assert event_node.geo.lon == node.position.lon
            assert event_node.geo.alt == node.position.alt
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session.broadcast_node(node)

            # then
            queue.get(timeout=5)
コード例 #4
0
    def test_exception_events(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        queue = Queue()

        def handle_event(event_data):
            assert event_data.HasField("exception_event")
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session.exception(ExceptionLevels.FATAL, "test", None, "exception message")

            # then
            queue.get(timeout=5)
コード例 #5
0
ファイル: test_grpc.py プロジェクト: lmerat46/core
    def test_session_events(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        queue = Queue()

        def handle_event(event_data):
            assert event_data.HasField("session_event")
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            event = EventData(event_type=EventTypes.RUNTIME_STATE.value, time="%s" % time.time())
            session.broadcast_event(event)

            # then
            queue.get(timeout=5)
コード例 #6
0
    def test_node_events(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node()
        node_data = node.data(message_type=0)
        queue = Queue()

        def handle_event(event_data):
            assert event_data.HasField("node_event")
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session.broadcast_node(node_data)

            # then
            queue.get(timeout=5)
コード例 #7
0
ファイル: test_grpc.py プロジェクト: lmerat46/core
    def test_file_events(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node()
        queue = Queue()

        def handle_event(event_data):
            assert event_data.HasField("file_event")
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            file_data = session.services.get_service_file(node, "DefaultRoute", "defaultroute.sh")
            session.broadcast_file(file_data)

            # then
            queue.get(timeout=5)
コード例 #8
0
ファイル: test_grpc.py プロジェクト: lmerat46/core
    def test_config_events(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        queue = Queue()

        def handle_event(event_data):
            assert event_data.HasField("config_event")
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session_config = session.options.get_configs()
            config_data = ConfigShim.config_data(0, None, ConfigFlags.UPDATE.value, session.options, session_config)
            session.broadcast_config(config_data)

            # then
            queue.get(timeout=5)
コード例 #9
0
ファイル: test_grpc.py プロジェクト: xiaoxiaopingzi/core
    def test_session_events(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        queue = Queue()

        def handle_event(event: Event) -> None:
            assert event.session_id == session.id
            assert event.session_event is not None
            queue.put(event)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            event_data = EventData(event_type=EventTypes.RUNTIME_STATE,
                                   time=str(time.monotonic()))
            session.broadcast_event(event_data)

            # then
            queue.get(timeout=5)
コード例 #10
0
ファイル: test_grpc.py プロジェクト: xiaoxiaopingzi/core
    def test_file_events(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node(CoreNode)
        queue = Queue()

        def handle_event(event: Event) -> None:
            assert event.session_id == session.id
            assert event.file_event is not None
            queue.put(event)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            file_data = session.services.get_service_file(
                node, "DefaultRoute", "defaultroute.sh")
            session.broadcast_file(file_data)

            # then
            queue.get(timeout=5)