コード例 #1
0
    def check_session_start_status(self):
        retries_left = 10

        while retries_left > 0:
            try:
                current_status = amqp_request(
                    self.connection,
                    MsgTestSuiteGetStatus(),
                    COMPONENT_ID,
                    use_message_typing=True
                )  # get status
                if isinstance(current_status, MsgTestSuiteGetStatusReply):
                    for tc in current_status.tc_list:
                        if tc['state'] is not None:
                            raise Exception("Session has already (partly) run. Cannot perform full testsuite")

                    logger.debug("Session state seems to be ok to start")
                    return True
                else:
                    raise Exception("Unexpected reply when getting TestSuite status")
            except AmqpSynchCallTimeoutError as e:
                pass  # ignore it

            retries_left -= 1

        raise Exception("Unable to verify testsuite starting state")
コード例 #2
0
def save_result_into_RS_db(message: Message):
    if isinstance(message, MsgTestSuiteReport):
        m_data = message.tc_results  # this is a list
        m_type = "final"
    elif isinstance(message, MsgTestCaseVerdict):
        m_data = message.to_dict()
        m_type = "intermediate"
    else:
        raise TypeError("Expecting Report or TC verdict message")

    m = MsgReportSaveRequest(
        type=m_type,
        data=m_data,
    )
    logger.info("Sending %s results to RS" % m_type)
    try:

        reply = amqp_request(
            connection=pika.BlockingConnection(pika.URLParameters(AMQP_URL)),
            request_message=m,
            component_id=COMPONENT_ID,
            retries=3,
            use_message_typing=True,
        )

    except AmqpSynchCallTimeoutError as tout:
        logger.warning("Request for %s timed out. Is RS up?" % type(m))
        return

    if not reply or not reply.ok:
        logger.warning("Couldn't save results, got response: %s " %
                       repr(reply))
        return

    logger.info("Successful %s results save into RS" % m_type)
コード例 #3
0
    def _04_stop_sniffer(self):
        response = amqp_request(
            connection=self.connection,
            request_message=MsgSniffingStop(),
            component_id=self.__class__.__name__,
            retries=10,
            use_message_typing=True,
        )

        assert response.ok, 'Returned %s' % repr(response)
コード例 #4
0
ファイル: amqp_connector.py プロジェクト: fsismondi/ioppytest
    def call_service_testcase_analysis(self, **kwargs):

        try:
            response = amqp_request(self.connection,
                                    MsgInteropTestCaseAnalyze(**kwargs),
                                    COMPONENT_ID,
                                    30,
                                    use_message_typing=True)
            logger.info("Received answer from TAT: %s, answer: %s" %
                        (response.routing_key, repr(response)))
            return response
        except AmqpSynchCallTimeoutError as e:
            raise e  # let caller handle it
コード例 #5
0
ファイル: amqp_connector.py プロジェクト: fsismondi/ioppytest
    def call_service_sniffer_get_capture(self, **kwargs):

        try:
            response = amqp_request(self.connection,
                                    MsgSniffingGetCapture(**kwargs),
                                    COMPONENT_ID,
                                    use_message_typing=True)
            logger.debug("Received answer from sniffer: %s, answer: %s" %
                         (response.routing_key, repr(response)))
            return response
        except AmqpSynchCallTimeoutError as e:
            logger.error(
                "Sniffer API didn't respond. Maybe it isn't up yet?. More info: %s"
                % e)
コード例 #6
0
    def get_status(self):
        try:
            current_status = amqp_request(
                self.connection,
                MsgTestSuiteGetStatus(),
                COMPONENT_ID,
                use_message_typing=True
            )  # get status

            if isinstance(current_status, MsgTestSuiteGetStatusReply):
                logger.info("Testsuite status: \n%s", testsuite_state_to_ascii_table(current_status.to_dict()))
            else:
                logger.warning("Could not get testsuite status: unexpected reply")
            pass
        except AmqpSynchCallTimeoutError as e:
            logger.warning("Could not get testsuite status: timeout")
コード例 #7
0
    def _03_get_capture(self):
        time.sleep(5)
        forged_agent_raw_packet = MsgPacketSniffedRaw()
        forged_agent_raw_packet.routing_key = self.routing_key_data_packet

        publish_message(self.connection, forged_agent_raw_packet)
        publish_message(self.connection, forged_agent_raw_packet)

        time.sleep(1)

        response = amqp_request(
            connection=self.connection,
            request_message=MsgSniffingGetCaptureLast(),
            component_id=self.__class__.__name__,
            retries=10,
            use_message_typing=True,
        )

        assert response.ok, 'Returned %s' % repr(response)

        logging.info(repr(response))
コード例 #8
0
    def run(self):

        try:
            for th in self.threads:
                th.start()

            self.check_session_start_status()

            logger.info("Sending session configuration to start tests")
            publish_message(
                self.connection,
                MsgSessionConfiguration(configuration=default_configuration),
            )  # configures test suite, this triggers start of userMock also

            t = 0
            # wait until we get MsgTestSuiteReport
            while t < SESSION_TIMEOUT and MsgTestSuiteReport not in self.msg_logger_th.messages_by_type_dict:
                time.sleep(5)
                t += 5

                if t % 15 == 0:
                    self.get_status()

            if t >= SESSION_TIMEOUT:
                r = amqp_request(self.connection,
                                 MsgTestSuiteGetStatus(),
                                 COMPONENT_ID)
                logger.warning('Test TIMED-OUT! Test suite status:\n%s' % pprint.pformat(r.to_dict()))
            else:
                assert MsgTestSuiteReport in self.msg_logger_th.messages_by_type_dict

                # we can now terminate the session
                publish_message(
                    self.connection,
                    MsgTestingToolTerminate(description="Received report, functional test finished..")
                )

                time.sleep(2)

        except Exception as e:
            self.error_state = True
            logger.error("Exception encountered in %s:\n%s" % (self.__class__.__name__, e))
            logger.error("Traceback:\n%s", traceback.format_exc())

        finally:
            if MsgTestingToolTerminate not in self.msg_logger_th.messages_by_type_dict:
                logger.warning('Never received TERMINATE signal')
                publish_message(
                    self.connection,
                    MsgTestingToolTerminate(description="Integration test of CoAP interop test: sth went wrong :/")
                )

            time.sleep(10)  # so threads process TERMINATE signal

            try:
                for th in self.threads:
                    if th.is_alive():
                        logger.warning("Thread %s didn't stop" % th.name)
                        th.stop()
            except Exception as e:  # i dont want this to make my tests fail
                logger.warning('Exception thrown while stopping threads:\n%s' % e)
コード例 #9
0
ファイル: __main__.py プロジェクト: fsismondi/ioppytest
    def synch_request(self, request, user_id=None, timeout=30):
        """ method for synch requests:
        sends request, waits for response, and returns it (unless timeout, in that case it raises exception)
        :param message: request Message (any type of Message subclass object)
        :param timeout: Timeout in seconds, else exception is raised
        :return: MsgReply reply (MsgReply subclass object)
        """
        if user_id:
            request = self._update_ui_message_rkeys(ui_message=request, user_id=user_id)

        # if request to a user and is unicast (e.g. to user 1) then let's notify user2 that he's waiting for user1 reply
        if 'ui.user.' in request.routing_key and '.all.' not in request.routing_key:

            waiting_for_user = self.get_user_id_from_rkey(
                rkey=request.routing_key
            )

            assert waiting_for_user

            logger.debug("Publishing message REQUEST (synch call to {user}): {rk}".format(
                rk=request.routing_key,
                user=waiting_for_user
            ))

            # notify the other users that they will be waiting for another users request
            users = self.get_session_users(
                exclude_user_id=waiting_for_user
            )

            if not users:
                m = MsgUiDisplay(
                    fields=[{"type": "p", "value": "Waiting for {user} reply..".format(
                        user=waiting_for_user
                    )}]
                )

                self.publish_ui_display(
                    message=m,
                    user_id='all'
                )

            else:
                for u in users:
                    m = MsgUiDisplay(
                        fields=[{"type": "p", "value": "Waiting for {user} reply..".format(
                            user=waiting_for_user
                        )}]
                    )

                    self.publish_ui_display(
                        message=m,
                        user_id=u
                    )

        else:
            logger.debug("Publishing message REQUEST (synch call): {rk}".format(rk=request.routing_key, ))

        # fixme in amqp request use timeout instead of retries
        time.sleep(PUBLISH_DELAY)
        resp = amqp_request(self.connection,
                            request,
                            COMPONENT_ID,
                            retries=timeout * 2,
                            use_message_typing=True)
        return resp