コード例 #1
0
    def _load_bench_conf(self):
        """
        Loads The Bench Configuration from its XML representation into a dict

        """
        self._bench_conf = AttributeDict()

        # New way of defining device parameters == as defined in the device catalog
        try:
            self._bench_tree_node = etree.parse(self.bench_conf_filename)
        except XMLParsingErrors:
            _error("Corrupted file {0}: {1}".format(
                self.bench_conf_filename,
                Utils.get_exception_info()[1]))

        node = self.bench_device_node
        if node is not None and len(node) > 0:
            # To load proper device config, need to get device model name
            device_conf = self.device_conf
            if device_conf:
                self._device_model_name = device_conf.get("DeviceModel")
            if self._device_model_name in ('', "", None, 'multi'):
                self._device_model_name = node[0].get("deviceModel")

            conf = self._parse_bench_node(node[0])
            if conf:
                self._bench_conf.update(conf)
コード例 #2
0
 def parse(self):
     try:
         parsed_doc = et.parse(self.__script)
         self.__doc = parsed_doc.getroot()
     except et.XMLSyntaxError:
         _, error_msg, _ = Utils.get_exception_info()
         raise AcsConfigException(AcsConfigException.XML_PARSING_ERROR, error_msg)
     return self.__parse_cmds(self.__doc)
コード例 #3
0
 def _parse_campaign_file_path(self, campaign_file_path):
     # XML parser parses the campaign config file
     try:
         return et.parse(campaign_file_path)
     except et.XMLSyntaxError:
         _, error_msg, _ = Utils.get_exception_info()
         self._logger.error(
             "Campaign file is corrupted : parsing-reading issue in {0}".
             format(campaign_file_path))
         raise AcsConfigException(AcsConfigException.XML_PARSING_ERROR,
                                  error_msg)
コード例 #4
0
 def get_action_nodes(self):
     """
     Returns the list of all I{ACTION} XML nodes.
     :rtype: NodeList
     :return: the list of all I{ACTION} XML nodes
     """
     ui_seq = None
     actions = []
     try:
         ui_seq = et.parse(self.__script)
     except et.XMLSyntaxError:
         _, error_msg, _ = Utils.get_exception_info()
         raise AcsConfigException(AcsConfigException.XML_PARSING_ERROR, error_msg)
     actions = ui_seq.xpath("//ACTION")
     return actions
コード例 #5
0
    def _load_device_conf(self):
        """
        Loads The Device Configuration from its XML representation into a dict

        """
        try:
            self._device_tree_node = etree.parse(self.device_conf_filename)
        except XMLParsingErrors:
            _error("Corrupted file {0}: {1}".format(
                self.device_conf_filename,
                Utils.get_exception_info()[1]))

        self._parse_device_node()
        self._device_schema = self.extract_schema(
            self.device_root_node,
            schema_folder=Paths.FWK_DEVICE_MODELS_CATALOG,
            file_only=False)
コード例 #6
0
    def parse_operation_config(self):
        """
        Parse the operation configure file. Each type of DUT has a dedicated configure file for holding
        UI operation commands
        The operation configures will be stored in a dictionary like this
        {
            sms_send: [[command, param], []]
            sms_delete: []
            sms_receive: []
        }
        """

        # Check if op dictionary exist
        if not os.path.isfile(self._dictionary_file):
            error_msg = \
                "OpDictionary file '%s' not found !" % \
                os.path.basename(str(self._dictionary_file))

            raise AcsConfigException(AcsConfigException.FILE_NOT_FOUND,
                                     error_msg)

        try:
            operation_config_doc = et.parse(self._dictionary_file)
        except et.XMLSyntaxError:
            _, error_msg, _ = Utils.get_exception_info()
            raise AcsConfigException(AcsConfigException.XML_PARSING_ERROR,
                                     error_msg)
        operation_sets = operation_config_doc.xpath(
            "//operationsets/operationset")

        # Check if found operation sets
        if not operation_sets:
            error_msg = \
                "No operations sets found from OpDictionary file '%s' !" % \
                os.path.basename(str(self._dictionary_file))

            raise AcsConfigException(AcsConfigException.XML_PARSING_ERROR,
                                     error_msg)

        for operation_set in operation_sets:
            operation_set_name = operation_set.get('name', "")
            if not operation_set_name:
                error_msg = "one operationset declared in UI dictionary has no name defined!"
                LOGGER_TEST_SCRIPT.warning(error_msg)
                continue

            # one operation set contains several operations
            operations = operation_set.xpath("./operation")
            op_triglog = operation_set.findtext("./triglog")
            op_timeout = operation_set.findtext("./timeout")
            operation_list = []

            # each operation is combined by command and parameter
            for operation in operations:
                op = {}
                for key in ["command", "triglog", "timeout", "log"]:
                    op[key] = operation.findtext("./%s" % (key, ))
                parameters = operation.xpath("./parameter")

                param_array = []
                if parameters:
                    for parameter in parameters:
                        param_array.append(parameter.text)
                op["parameters"] = param_array

                # add this operation to the operation list
                operation_list.append(op)

            operation_set_parameters = {}
            operation_set_parameters["operations"] = operation_list
            operation_set_parameters["triglog"] = op_triglog
            operation_set_parameters["timeout"] = op_timeout
            # add the operation set into operation dictionary
            self.__op_dictionary[operation_set_name] = operation_set_parameters
コード例 #7
0
    def _extract_test_cases(self, campaign_config_doc, parent_campaign_list,
                            group_id):
        """
        This function creates a set of test cases objects from parsing and returns
        the test cases list + the subcampaign list
        :type Document
        :param campaign_config_doc a Etree
        :param group_id a reference number for test group list inside test case list
        :type list
        :return test_cases a TestCaseConf list + subcampaigns a CampaignConf list
        """
        def create_test_case_element(node,
                                     last_parent,
                                     random=False,
                                     group_id=None):
            parse_status = True
            tcelement = TestCaseConf(node, random, group_id)
            error_msg = None
            try:
                tcelement = self._unify_path(tcelement, last_parent)
            except AcsConfigException as ex_msg:
                error_msg = "Error while reading-parsing TC item in " + \
                            str(last_parent) + " file => ignore TestCase item (exception = " + \
                            str(ex_msg) + ")"
                self._logger.warning(error_msg)
                self._logger.error(
                    "Test case not found, it will not be executed")
                parse_status = False

            try:
                tcelement = self._load_usecase_of_testcase(tcelement)
            except AcsConfigException as ex_msg:
                error_msg = "Error while reading-parsing TC item in " + \
                            str(last_parent) + " file => ignore TestCase item (exception = " + \
                            str(ex_msg) + ")"
                self._logger.warning(error_msg)
                self._logger.error("Test case based on unknown usecase (%s)," %
                                   (tcelement.get_name(), ) +
                                   " it will not be executed")
                parse_status = False

            tcelement.add_message(error_msg)
            tcelement.set_valid(parse_status)
            return tcelement

        # Get the list of Test cases to execute
        test_case_list = []
        sub_campaign_list = []
        tcs_node = campaign_config_doc.xpath('//TestCases')
        if not tcs_node:
            # Inform the user that the campaign config template is bad
            error_msg = "Error while reading-parsing campaign item " + \
                        str(parent_campaign_list[-1]) + " file => no <TestCases> ...  </TestCases> node found "
            self._logger.warning(error_msg)

        tc_nodes = campaign_config_doc.xpath('//TestCases/*')
        if tc_nodes:
            for node in tc_nodes:
                last_parent = parent_campaign_list[
                    -1] if parent_campaign_list else ""
                if node.tag == "TestCase":
                    tcelement = create_test_case_element(node, last_parent)
                    if tcelement is not None:
                        test_case_list.append(tcelement)
                elif node.tag == "RANDOM":
                    for subnode in node:
                        if True:  # subnode.nodeType == subnode.ELEMENT_NODE:
                            if subnode.tag == "TestCase":
                                tcelement = create_test_case_element(
                                    subnode, last_parent, random=True)
                                if tcelement is not None:
                                    test_case_list.append(tcelement)
                            elif subnode.tag == "GROUP":
                                group_id += 1
                                for group_node in subnode:
                                    if group_node.tag == "TestCase":
                                        tcelement = create_test_case_element(
                                            group_node,
                                            last_parent,
                                            random=True,
                                            group_id=group_id)
                                        if tcelement is not None:
                                            test_case_list.append(tcelement)
                elif node.tag == "SubCampaign":
                    # Parse sub campaign config and check arguments
                    # Check also that we do not fall into infinite loop by calling again a parent campaign name
                    try:
                        sub_campaign_config = CampaignConf(
                            node, parent_campaign_list)
                        # unify path according to the closest parent campaign
                        sub_campaign_config = self._unify_path(
                            sub_campaign_config, last_parent)
                        sub_campaign_config.check_campaign_sanity()
                    except AcsConfigException as ex_msg:
                        error_msg = "Error while reading-parsing campaign item in " + \
                                    str(last_parent) + " file => ignore SubCampaign item (exception = " + \
                                    str(ex_msg) + ")"
                        self._logger.warning(error_msg)
                        continue
                    # Compose relative file path for sub campaign config file
                    sub_campaign_file_path = sub_campaign_config.get_name()
                    campaign_path = os.path.join(
                        Paths.EXECUTION_CONFIG,
                        sub_campaign_file_path + self._file_extension)

                    if not os.path.isfile(campaign_path):
                        error_msg = "Campaign file not found %s !" % (
                            campaign_path, )
                        raise AcsConfigException(
                            AcsConfigException.FILE_NOT_FOUND, error_msg)
                    try:
                        sub_campaign_config_doc = et.parse(
                            os.path.abspath(campaign_path))
                    except et.XMLSyntaxError:
                        _, error_msg, _ = Utils.get_exception_info()
                        raise AcsConfigException(
                            AcsConfigException.XML_PARSING_ERROR, error_msg)
                    # Parse of the Sub Campaign node is OK in parent campaign file + Parse of the file sub Campaign is OK
                    # add sub campaign item to sub campaign list (for debug purpose - configuration file copy in AWR)
                    sub_campaign_list.append(sub_campaign_config)

                    # After parsing sub Campaign node, we shall update the sub campaign parent campaign list
                    parent_sub_campaign_list = sub_campaign_config.get_parent_campaign_list(
                    )[:]
                    parent_sub_campaign_list.append(sub_campaign_file_path)

                    # we call a sub campaign, parse it by a recursive call to _extract_test_cases() method
                    try:
                        test_case_subset_list, sub_campaign_subset_list = self._extract_test_cases(
                            sub_campaign_config_doc, parent_sub_campaign_list,
                            group_id)
                    except Exception:  # pylint: disable=W0703
                        _, error_msg, _ = Utils.get_exception_info()
                        self._logger.warning(error_msg)
                        continue

                    # Repeat test case subset list runNumber of time in the current test case list
                    if test_case_subset_list:
                        exec_number = int(sub_campaign_config.get_run_number())
                        test_case_list.extend(test_case_subset_list *
                                              exec_number)
                    # add sub campaign subset list to sub campaign list (for debug purpose -
                    # configuration file copy in AWR)
                    if sub_campaign_subset_list:
                        sub_campaign_list.extend(sub_campaign_subset_list)
                else:
                    # other case of parsing error continue the campaign execution
                    error_msg = "Error while reading-parsing campaign item in " + \
                                str(last_parent) + " file => node <" + node.tag + \
                                "> is not parsed according to campaign config template "
                    self._logger.warning(error_msg)
        else:
            # Inform the user that the campaign config template is bad
            error_msg = "Campaign item " + str(
                parent_campaign_list[-1]) + " is empty"
            self._logger.warning(error_msg)

        return test_case_list, sub_campaign_list
コード例 #8
0
    def __google_test_xml_report_as_dict(self, xml_gtest_report_file,
                                         testsuite_dict):
        """
        This private function parses xml result file generated by google test command
        add put all the data inside a dictionnary
        This function returns a dictionary with all google test result execution data
        and the status of google test report file parsing

        :type xml_gtest_report_file: str
        :param xml_gtest_report_file: name of the local gtest report file

        :type testsuite_dict: dictionnary
        :param testsuite_dict: gtest report data dict

        :rtype: boolean, str
        :return: status and message
        """

        status_message = "Undefined error while parsing gtest xml file %s" % xml_gtest_report_file
        status = False

        try:
            gtest_result_doc = et.parse(xml_gtest_report_file)

        except et.XMLSyntaxError:
            _, error_msg, _ = Utils.get_exception_info()
            status_message = "Cannot parse gtest xml result file for test %s" % self._google_test_command

        try:
            # Parse etree tool result
            testsuites_nodes = gtest_result_doc.xpath('//testsuites')

            if not testsuites_nodes:
                # Inform the user that there is no results inside gtest result file
                status_message = "Error while parsing gtest xml result file for test %s" % self._google_test_command + \
                    " - file => no <testsuites> ...  </testsuites> node found"
            else:
                # Parse the testsuites node, it should be uniq
                if len(testsuites_nodes) == 1:

                    # EXTRACT DATAS FROM GTEST RESULT FILE
                    ##########################################################################
                    # Extract the test suite nodes + test case nodes for every test suite
                    # put all values in testsuite_list dictionnary => contain testsuite name +
                    # testsuite attributes + testcase dictionnary

                    testsuite_node_list = testsuites_nodes[0].xpath(
                        './testsuite')
                    if testsuite_node_list:
                        testcase_count = self.__parse_tc_nodes(
                            testsuite_node_list, testsuite_dict)

                        # Test if a test case has been run
                        if testcase_count:
                            status = True
                        else:
                            # no test case inside the gtest result file report so no test case run
                            status_message = "Error while parsing gtest xml result file for test %s" % self._google_test_command + \
                                " - no <testscase> node found, no test case run in current google test"
                    else:
                        # no test suite inside the gtest result file report so no test case run
                        status_message = "Error while parsing gtest xml result file for test %s" % self._google_test_command + \
                            " - no <testsuite> node, no test case run in current google test"
                else:
                    # We do not handle several <testsuites> in google test report parsing
                    status_message = "Error while parsing gtest xml result file for test %s" % self._google_test_command + \
                        " - file => several <testsuites> ...  </testsuites> node found"

        except Exception:
            _, error_msg, _ = Utils.get_exception_info()
            status_message = "Error while parsing gtest xml result file for test %s - error = %s" % (
                self._google_test_command, error_msg)

            if not testsuite_dict:
                status_message = "Error while parsing gtest xml result file for test %s" % self._google_test_command + \
                    " - no testsuite succesfully parsed "

        return status, status_message