コード例 #1
0
    def get_param_value(self, key, default_value=None, attribute="value"):
        """
        Returns the value associated to a given key.
        If key isn't present, raise an AcsConfigException.

        :type key: string
        :param key: parameter's name.

        :type default_value: String
        :param default_value: Default value if parameter is not present

        :type attribute: String
        :param attribute: the key attribute where the value is read from, by default it will read "value" attribute

        :rtype: string
        :return: parameter's value.
        """
        try:
            param = None
            param = self.__dict[key]
            return param[attribute]
        except Exception:  # pylint: disable=W0703
            if default_value is not None:
                return default_value
            elif param is None:
                raise AcsConfigException(
                    AcsConfigException.DATA_STORAGE_ERROR,
                    "Bad parameter's name (%s)." % (str(key)))
            else:
                raise AcsConfigException(
                    AcsConfigException.DATA_STORAGE_ERROR,
                    "No attribute [%s] value found for parameter %s." %
                    (str(attribute), str(key)))
コード例 #2
0
    def parse_equipment_catalog(self):
        """
        This function parses the equipment catalog XML file into a dictionary.
        """
        # Instantiate empty dictionaries
        eqt_type_dic = {}

        # Get the xml doc
        equipment_catalog_path = os.path.join(self._equipment_catalog_path, self._equipment_catalog_name)

        if not os.path.isfile(equipment_catalog_path):
            error_msg = "Equipment catalog file : %s does not exist" % equipment_catalog_path
            raise AcsConfigException(AcsConfigException.FILE_NOT_FOUND, error_msg)

        try:
            equipment_catalog_doc = et.parse(equipment_catalog_path)
        except et.XMLSyntaxError:
            _, error_msg, _ = Utils.get_exception_info()
            error_msg = "{}; {}".format(equipment_catalog_path, error_msg)
            raise AcsConfigException(AcsConfigException.XML_PARSING_ERROR, error_msg)

        root_node = equipment_catalog_doc.xpath('/Equipment_Catalog')
        if not root_node:
            raise AcsConfigException(AcsConfigException.FILE_NOT_FOUND,
                                     "Wrong XML: could not find expected document root node: "
                                     "'Equipment_Catalog'")
        # Parse EquipmentTypes
        list_eq_types = root_node[0].xpath('./EquipmentType')
        for eq_type in list_eq_types:
            eqt_type_dic.update(self._load_equipment_type(eq_type))

        self._global_config.equipmentCatalog = eqt_type_dic.copy()
コード例 #3
0
    def get_parser(file_path, schema_file=None):
        """
        Get the right parser according to file path extension

        Schema file is not mandatory
        Moreover, if no schema file provided here, parser can try to find this information in parsed content

        :type file_path: str
        :param file_path: path to the file to parse
        :type schema_file: str
        :param schema_file: path to schema file to ensure file to parse integrity

        :rtype: a parser class
        :return: the parser class which handle the file format
        """
        if not os.path.isfile(file_path):
            error_msg = "Cannot parse {0}, the file was not found".format(
                file_path)
            raise AcsConfigException(AcsConfigException.FILE_NOT_FOUND,
                                     error_msg)

        _, extension = os.path.splitext(file_path)
        if extension not in Parser.available_parsers:
            error_msg = "The {0} extension is not supported by the parser".format(
                extension)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                     error_msg)

        try:
            parser = Parser.available_parsers[extension](file_path,
                                                         schema_file)
        except Exception as e:
            error_msg = "Cannot instantiate parser : {0}".format(e)
            raise AcsConfigException(error_msg)
        return parser
コード例 #4
0
    def _get_ucase_class_from_ucase(self, ucase):
        """
        This function gets the use case class from the use case name.

        :type   ucase: string
        :param  ucase: use case name

        :rtype:     object
        :return:    use case class
        """

        if not self._ucase_catalogs:
            error_msg = "No use case catalog has been found!"
            raise AcsConfigException(AcsConfigException.FILE_NOT_FOUND,
                                     error_msg)

        ucase_dic = self._ucase_catalogs.get(ucase)

        if not ucase_dic:
            error_msg = "Use case {0} not found in UC catalog!".format(ucase)
            raise AcsConfigException(AcsConfigException.XML_PARSING_ERROR,
                                     error_msg)

        # Presence of ClassName element
        # is already checked by CatalogParser using xsd
        ucase_class_name = ucase_dic.get(CatalogParser.CLASSNAME_ELEM)
        ucase_class = Utils.get_class(ucase_class_name)
        return ucase_class
    def run(self, context):
        """
        Runs the test step

        :type context: :py:class:`~acs.Core.TestStep.TestStepContext`
        :param context: Test Case context
        """
        TestStepBase.run(self, context)

        loop_id = str(self._pars.id)

        try:
            nb_iteration = int(self._pars.nb)
        except ValueError:
            error_msg = ("Loop expects an integer value as "
                         "iteration number (Given value type: {0})").format(type(self._pars.nb))
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, error_msg)

        if nb_iteration < 0:
            error_msg = ("Loop expects a positive value as "
                         "iteration number (Given value: {0})").format(self._pars.nb)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, error_msg)

        # Log in acs logs
        self._logger.info("--- Running loop '%s' of %d iterations ---", loop_id, nb_iteration)

        # Loop on Test Steps
        for iteration in xrange(nb_iteration):
            self._logger.info("--- Loop '%s' - Iteration %d ---", loop_id, (iteration + 1))
            TestStepSet.run(self, context)
コード例 #6
0
    def _check_subdomain(self, catalog_file, item_id, item_domain,
                         item_subdomain, possible_domains,
                         possible_subdomains):
        """
        Validate SubDomain attributes using YAML config

        :type catalog_file: string
        :param catalog_file: Catalog file

        :type item_id: string
        :param item_id: Id of the item (UseCase or Test Step)

        :type item_domain: string
        :param item_domain: Domain to be checked

        :type item_subdomain: string
        :param item_subdomain: SubDomain to be checked

        :type possible_domains: list
        :param possible_domains: List of possible domains

        :type possible_subdomains: list
        :param possible_subdomains: List of possible subdomains

        :rtype: list
        :return: List of associated features when item_subdomain is validated
        """

        subdomains = self._yaml_config.get("SUB_DOMAINS")

        if not subdomains:
            raise AcsConfigException(
                AcsConfigException.YAML_PARSING_ERROR,
                "'%s' file is invalid ! (SUB_DOMAINS section does not exists!)"
                % self._yaml_config_file)
        elif possible_subdomains is None:
            raise AcsConfigException(
                AcsConfigException.XML_PARSING_ERROR,
                "'%s' is invalid ! (Domain %s is not valid for item %s; Expected values are %s)"
                % (catalog_file, str(item_domain), str(item_id),
                   str(possible_domains)))
        elif len(possible_subdomains) == 0:
            raise AcsConfigException(
                AcsConfigException.YAML_PARSING_ERROR,
                "'%s' file is invalid ! (no SubDomains exist for Domain %s)" %
                (self._yaml_config_file, str(item_domain)))
        elif item_subdomain not in possible_subdomains:
            raise AcsConfigException(
                AcsConfigException.XML_PARSING_ERROR,
                "'%s' catalog is invalid ! (SubDomain %s is not valid for item %s; Expected values are %s)"
                % (catalog_file, str(item_subdomain), str(item_id),
                   str(possible_subdomains)))
        else:
            return subdomains.get(item_subdomain)
コード例 #7
0
    def _read_from_test_case(self, tc_parameters, value, param_ref_value):
        """
        Read value from the test case parameter
        """
        if not tc_parameters:
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, "No test case parameters defined !")

        from_tc = re.match(self.REGEX_FROM_TC, value)
        if from_tc:
            ref_key = from_tc.group("tc_param")
            param_ref_value = tc_parameters.get_param_value(ref_key)
            if not param_ref_value:
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         "'{0:s}' is not a test case parameter !".format(ref_key))
        return param_ref_value
コード例 #8
0
    def connect(self):
        """ Connects to logger probe.

            probe: Probe name. Can be 'FIDO' or 'LTB'.
        """

        if self.__probe == "LTB":

            # establish tcp connection with LTB
            host = '127.0.0.1'  # Symbolic name meaning the local host
            port = 6666  # Arbitrary non-privileged port
            self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

            self._s.connect((host, port))

        elif self.__probe == "FIDO":
            # establish tcp connection with FIDO
            host = '127.0.0.1'  # Symbolic name meaning the local host
            port = 7654  # Arbitrary non-privileged port
            self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self._s.connect((host, port))

            # Send Reserve Data Channel command to Fido
            data_cmd = "DATA FidoTest TRACEBOX/0.0.0.0\r\n\r\n"
            self._s.send(data_cmd)
        else:
            error_msg = "MptaLoggerThread lib error in 'connect' - Unknown probe name"
            raise AcsConfigException(AcsConfigException.EXTERNAL_LIBRARY_ERROR, error_msg)
コード例 #9
0
    def parse_catalog_folder(self):
        """
        Parse folder(s) which are known to contain catalogs (usecases, test steps, parameters)
        If multiple catalogs are in the folder, it will return a concatenated dictionary.
        If a key is already defined in the dictionary, raise an AcsConfigException

        :type catalog_paths: list
        :param catalog_paths: catalog paths list. Catalogs can come from different locations (acs, acs_test_scripts)

        :type: dict
        :return: Dictionary containing catalog elements
        """
        concatenated_dictionary = {}

        for catalog_path in self._catalog_paths:
            for root, _, catalog_list in os.walk(catalog_path):
                for catalog_file in catalog_list:
                    if catalog_file.lower().endswith(self.CATALOG_EXTENTION):
                        temp_dictionary = self.parse_catalog_file(
                            os.path.join(root, catalog_file))
                        for item_name in temp_dictionary.iterkeys():
                            if item_name in concatenated_dictionary:
                                raise AcsConfigException(
                                    AcsConfigException.PROHIBITIVE_BEHAVIOR,
                                    "item '%s' is defined more than one time !"
                                    % item_name)
                        concatenated_dictionary.update(temp_dictionary)

        return concatenated_dictionary
コード例 #10
0
    def __check_xml_schema(self, catalog_file):
        """
        Validate catalog file regarding loaded xml schema (if any)
        Return it as a dictionary

        :type catalog_file: string
        :param catalog_file: Catalog file to parse

        :rtype: etree.XML
        :return: X to validate the xml catalog file
        """

        try:
            # Parse the xml file
            catalog_etree = etree.parse(catalog_file)

            if catalog_etree and self._xml_schema:
                # Apply xml schema on the xml file
                self._xml_schema.assertValid(catalog_etree)

        except etree.Error as xml_parsing_error:
            raise AcsConfigException(
                AcsConfigException.XML_PARSING_ERROR,
                "'%s' catalog is invalid ! (%s)" %
                (catalog_file, str(xml_parsing_error)))

        return catalog_etree
コード例 #11
0
    def load(self, device_name, device_parameters):
        """
        Load and instantiate device configured on the cmd line and those define in bench config.

        :type device_name: str
        :param device_name: Device model to instantiate (if specify from the command line, else None)

        :type device_parameters: list
        :param device_parameters: Device parameters to overload (if specify from the command line)
        """
        # Load device(s) configuration
        device_cfg_loader = DeviceConfigLoader(self.get_global_config())
        device_configs = device_cfg_loader.load(device_name, device_parameters)

        for device_name in sorted(device_configs.keys()):
            device = self._instantiate_device(device_name,
                                              device_configs[device_name])
            self.get_logger().debug(
                "Creating Device with parameters: {0}".format(
                    device_configs[device_name]))
            LOGGER_DEVICE_STATS.info("Create device_model={0}".format(
                device.get_phone_model()))
            self._device_instances[device_name] = device

        if not self._device_instances:
            msg = "No Devices configured, please specify one on the command line or in the bench config."
            self.get_logger().error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_BENCH_CONFIG,
                                     msg)

        return self._device_instances
コード例 #12
0
 def _raise_config_exception(self, msg, category=AcsConfigException.INVALID_PARAMETER):
     """
     Raise an exception; It can be used in inheriting classes to log and raise an exception
     in a consistent manner.
     """
     self._logger.error(msg)
     raise AcsConfigException(category, msg)
コード例 #13
0
    def set_output_file(self, path):
        """ Specify the path where log will be saved

        :type  path: string
        :param path: Path to the output log file
        """
        raise AcsConfigException(AcsConfigException.FEATURE_NOT_IMPLEMENTED)
コード例 #14
0
    def _update_parameter(module, module_configuration, module_name):
        """
        Overload device parameter if device module conf was overloaded in bench config

        :type module: object
        :param module: module instance

        :type module_configuration: Attribute_dict
        :param module_configuration: Module configuration

        :type module_name: str
        :param module_name: name of the module
        """
        if module_configuration.get("parameter_overloaded"):
            # Overload module parameter
            for parameter_name, parameter_value in module_configuration.parameter_overloaded.items(
            ):
                if module.configuration.get(parameter_name) is not None:
                    # Overload parameter value
                    module.configuration[parameter_name] = parameter_value
                else:
                    # Parameter does not exist, raise the issue
                    raise AcsConfigException(
                        AcsConfigException.INVALID_PARAMETER,
                        "Device module parameter \"{0}\" is not define for device module \"{1}\""
                        .format(parameter_name, module_name))
コード例 #15
0
    def get_parameters(self, key):
        """
        Returns parameters associated to the key,
        or raise AcsConfigException if the key doesn't exist
        or return an empty dict if the key doesn't refer to any parameters.

        :type key: string
        :param key: Key that refers to parameters.

        :rtype: object
        :return: Instance of BenchConfigParameters.
        """

        try:
            # Store default empty dictionary
            parameters_dict = BenchConfigParameters({}, key)
            if isinstance(self.__dict[key], dict):
                for sub_key in self.__dict[key].iterkeys():
                    if isinstance(self.__dict[key][sub_key], dict):
                        parameters_dict = BenchConfigParameters(
                            self.__dict[key], key)
                        break

            return parameters_dict
        except Exception:
            raise AcsConfigException(AcsConfigException.DATA_STORAGE_ERROR,
                                     "Bad key name (%s)." % (str(key)))
    def _check_xml_logic(self, catalog_file):
        """
        Validate catalog file regarding loaded YAML logic
        regarding to Domains &SubDomains
        Return a boolean setting if xml file logic is valid

        :type catalog_file: string
        :param catalog_file: Catalog file to parse

        :rtype: none
        :return: none
        """

        # Parse the xml file
        catalog_etree = etree.parse(catalog_file)

        if catalog_etree and self._yaml_config:

            domains = self._yaml_config.get("DOMAINS")
            if not domains:
                raise AcsConfigException(
                    AcsConfigException.YAML_PARSING_ERROR,
                    "'%s' file is invalid ! (DOMAINS section does not exists!)"
                    % self._yaml_config_file)

            for node in catalog_etree.getroot():
                item_id = node.attrib[CatalogParser.ID_ATTRIB]
                item_domain = node.attrib[CatalogParser.DOMAIN_ATTRIB]
                item_subdomain = node.attrib[CatalogParser.SUBDOMAIN_ATTRIB]

                # Check that logic between Domain, SubDomain is respected
                self._check_subdomain(catalog_file, item_id, item_domain,
                                      item_subdomain, domains.keys(),
                                      domains.get(item_domain))
コード例 #17
0
    def _process_test_step_tag(self, test_steps, pars, ts_name=None):
        """
        Process **<TestStep>** tag, to create test steps.

        :type test_steps: list
        :param test_steps: list of test steps

        :type pars: dict
        :param pars: test step's parameters

        :type ts_name: str
        :param ts_name: test step's parent name
        """
        if TestStepConstants.STR_TS_ID in pars.keys():
            test_step = self._create_test_step_instance(pars, ts_name)
        elif TestStepConstants.STR_SET_ID in pars.keys():
            test_step = self._create_test_step_set_instance(pars, ts_name)
        else:
            error_msg = "Either %s or %s <TestStep> attribute " \
                        " is mandatory " % (TestStepConstants.STR_TS_ID, TestStepConstants.STR_SET_ID)
            self._logger.error(error_msg)
            raise AcsConfigException(AcsConfigException.XML_PARSING_ERROR,
                                     error_msg)

        # Everything went fine, add the step to test step list
        test_steps.append(test_step)
コード例 #18
0
    def _load_conf(module, conf_file):
        """
        Load module configuration.
        It will look first at the file in the EXECUTION_CONFIG folder
        Else, if not find, it will load the configuration based on the module path


        :type module: object
        :param module: Module instance

        :type conf_file: str
        :param conf_file: Configuration file to load
        """
        execution_conf_patch_path = os.path.join(
            PathManager.Paths.EXECUTION_CONFIG, conf_file)
        if os.path.isfile(execution_conf_patch_path):
            # We found a module conf in the execution folder, we use it instead of default one
            configuration_file = execution_conf_patch_path
        else:
            module_conf = os.path.join(module.path, conf_file)
            if os.path.isfile(module_conf):
                configuration_file = module_conf
            else:
                raise AcsConfigException(
                    "Cannot find \"{0}\" device module configuration: {1}".
                    format(module.path, conf_file))

        return configuration_file
コード例 #19
0
    def _instantiate_device(self, device_name, device_config):
        """
        Instantiate a device according to the classname found in config

        :type   device_name: str
        :param  device_name: Device name to instantiate (e.g.: PHONE1)

        :type   device_config: AttributeDict
        :param  device_config: Configuration of the device to instantiate

        :rtype:     device
        :return:    Instance of the device
        """
        # Instantiate the device
        if device_config.get("ClassName"):
            device_model_class = get_class(device_config.ClassName)

            if device_model_class is not None:
                device_logger = logging.getLogger("%s.DEVICE.%s" % (
                    ACS_LOGGER_NAME,
                    device_name,
                ))
                device_config.device_name = device_name
                device = device_model_class(device_config, device_logger)
            else:
                error_msg = "Class name %s not found!" % (str(
                    device_config.ClassName), )
                self.get_logger().error(error_msg)
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         error_msg)
        else:
            raise AcsConfigException(
                AcsConfigException.INVALID_PARAMETER,
                "Cannot instantiate \"{0}\", class name is missing in the configuration:\n {1}"
                .format(device_name, device_config))

        # Raise an error if the instance is none
        if device is None:
            msg = "Unable to instantiate device %s" % (str(
                device_config.Name), )
            self.get_logger().error(msg)
            raise AcsConfigException(AcsConfigException.INSTANTIATION_ERROR,
                                     msg)

        # Setup environment of the board
        device.initialize()
        return device
コード例 #20
0
    def add_trigger_message(self, message):
        """
        Trigger a message

        :type  message: string
        :param path: message to be triggered
        """
        raise AcsConfigException(AcsConfigException.FEATURE_NOT_IMPLEMENTED)
コード例 #21
0
 def _raise_init_exception_if_exists(self):
     """
     If an ACS exception was caught in the constructor, now it's the good time to raise it
     """
     if self._init_exc:
         raise AcsConfigException(
             self._init_exc.get_generic_error_message(),
             self._init_exc.get_specific_message())
コード例 #22
0
    def reset_trigger_message(self, message):
        """
        Reset triggered message

        :type  message: string
        :param path: message to be reseted
        """
        raise AcsConfigException(AcsConfigException.FEATURE_NOT_IMPLEMENTED)
コード例 #23
0
    def __init__(self, tc_conf, global_config):
        """
        Constructor
        """
        UseCaseBase.__init__(self, tc_conf, global_config)

        # Get TC Parameters
        self._step = self._tc_parameters.get_param_value("STEP", "RUNTEST")
        self._return_code = self._tc_parameters.get_param_value(
            "RETURN_CODE", Verdict.PASS)
        # Update return code for retro-compatibility
        self._return_code = self._return_code.replace("SUCCESS", Verdict.PASS)
        self._return_code = self._return_code.replace("FAILURE", Verdict.FAIL)

        self._comment = self._tc_parameters.get_param_value(
            "COMMENT", "No Comment")
        self._duration = int(self._tc_parameters.get_param_value(
            "DURATION", 0))
        self._init_exception = self._tc_parameters.get_param_value(
            "INIT_EXCEPTION", False, "str_to_bool")

        if self._init_exception is True:
            raise AcsConfigException(
                AcsConfigException.PROHIBITIVE_BEHAVIOR,
                "Exception raised according to TC param 'INIT_EXCEPTION'")

        # Clear existing queue to avoid unexpected behavior
        if not Dummy.returns_code.empty():
            with Dummy.returns_code.mutex:
                Dummy.returns_code.queue.clear()

        if not Dummy.steps.empty():
            with Dummy.steps.mutex:
                Dummy.steps.queue.clear()

        # Fill the FIFO queue taking into account the b2b iteration number
        for _i in range(self.get_b2b_iteration()):
            for code in self._return_code.split(";"):
                if code.strip() == "RANDOM":
                    code = random.choice(Verdict2Global.map.keys())
                Dummy.returns_code.put(code.strip())

            for step in self._step.split(";"):
                if step.strip() == "RANDOM":
                    step = random.choice(["SETUP", "RUNTEST", "TEARDOWN"])
                Dummy.steps.put(step.strip())

        # Get return code and step only if queue is not empty.
        # By default verdict = PASS, step = RUNTEST
        self._current_verdict = Verdict.PASS
        self._current_step = "RUNTEST"

        if not Dummy.returns_code.empty():
            self._current_verdict = Dummy.returns_code.get()

        if not Dummy.steps.empty():
            self._current_step = Dummy.steps.get()
    def _check_subdomain(self, catalog_file, item_id, item_domain,
                         item_subdomain, possible_domains,
                         possible_subdomains):
        """
        Validate SubDomain attributes using YAML config

        :type catalog_file: string
        :param catalog_file: Catalog file

        :type item_id: string
        :param item_id: Id of the item (UseCase or Test Step)

        :type item_domain: string
        :param item_domain: Domain to be checked

        :type item_subdomain: string
        :param item_subdomain: SubDomain to be checked

        :type possible_domains: list
        :param possible_domains: List of possible domains

        :type possible_subdomains: list
        :param possible_subdomains: List of possible subdomains

        """

        if possible_subdomains is None:
            raise AcsConfigException(
                AcsConfigException.XML_PARSING_ERROR,
                "'%s' is invalid ! (Domain %s is not valid for item %s; Expected values are %s)"
                % (catalog_file, str(item_domain), str(item_id),
                   str(possible_domains)))
        elif len(possible_subdomains) == 0:
            raise AcsConfigException(
                AcsConfigException.YAML_PARSING_ERROR,
                "'%s' file is invalid ! (no SubDomains exist for Domain %s)" %
                (self._yaml_config_file, str(item_domain)))
        elif item_subdomain not in possible_subdomains:
            raise AcsConfigException(
                AcsConfigException.XML_PARSING_ERROR,
                "'%s' catalog is invalid ! (SubDomain %s is not valid for item %s; Expected values are %s)"  # NOQA
                % (catalog_file, str(item_subdomain), str(item_id),
                   str(possible_subdomains)))
コード例 #25
0
    def get_message_triggered_status(self, message):
        """
        Get the status of a message triggered

        :type  message: string
        :param path: message triggered
        :return: Array of message received, empty array if nothing
        :rtype: list
        """
        raise AcsConfigException(AcsConfigException.FEATURE_NOT_IMPLEMENTED)
コード例 #26
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)
コード例 #27
0
    def _check_feature(self, catalog_file, item_id, item_subdomain,
                       item_feature, possible_features):
        """
        Validate Feature attributes using YAML config

        :type catalog_file: string
        :param catalog_file: Catalog file

        :type item_id: string
        :param item_id: Id of the item (UseCase or Test Step)

        :type item_subdomain: string
        :param item_subdomain: SubDomain to be checked

        :type item_feature: string
        :param item_feature: Feature to be checked

        :type possible_features: list
        :param possible_features: List of possible features

        :rtype: none
        :return: none
        """

        if possible_features is None:
            raise AcsConfigException(
                AcsConfigException.YAML_PARSING_ERROR,
                "'%s' is invalid ! (SubDomain %s does not exist)" %
                (self._yaml_config_file, str(item_subdomain)))
        elif len(possible_features
                 ) > 0 and item_feature not in possible_features:
            raise AcsConfigException(
                AcsConfigException.XML_PARSING_ERROR,
                "'%s' catalog is invalid ! (Feature %s is not valid for item %s; Expected values are %s)"
                % (catalog_file, str(item_feature), str(item_id),
                   str(possible_features)))
        elif len(possible_features) == 0 and len(item_feature) > 0:
            raise AcsConfigException(
                AcsConfigException.XML_PARSING_ERROR,
                "'%s' catalog is invalid ! (Feature %s is not valid for item %s; No features expected)"
                % (catalog_file, str(item_feature), str(item_id)))
コード例 #28
0
 def check_campaign_sanity(self):
     if self._parent_campaign_list:
         # Check that we do not have the same campaign called before we create the campaign conf element
         if self._name in self._parent_campaign_list:
             # Inform user in ACS log that we have an infinite loop while calling sub campaigns
             error_msg = "Campaign config file issue: Infinite loop detected while calling SubCampaign '" + \
                 str(self._raw_name) + "'"
             # Raise an exception to stop the campaign as campaign config file
             raise AcsConfigException(
                 AcsConfigException.PROHIBITIVE_BEHAVIOR, error_msg)
     else:
         self._parent_campaign_list = []
コード例 #29
0
    def __check_and_set_run_number(self, value):

        if (not value.isdigit()) or value == "0":
            # Inform user in ACS log that runNumber has a bad value
            error_msg = "Campaign config file issue: " + \
                "Wrong format or value for runNumber attribute (value used: '" + str(value) + \
                " for SubCampaign " + str(self._raw_name) + "), runNumber parameter should be a positive integer"
            # Raise an exception to stop the campaign as campaign config file
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                     error_msg)

        return value
コード例 #30
0
    def _process_include_tag(self, path, node):
        """
        Include another XML file and add its nodes to node

        :type path: str
        :param path: the XML path

        :type node: Element
        :param node: the XML node to add the included information to
        """

        nodes = node.xpath(path)
        for elem in nodes:
            if TestStepConstants.STR_SRC in elem.attrib.keys():
                src = elem.attrib[TestStepConstants.STR_SRC]
                # Raise an exception in case file does not exists
                file_name = os.path.normpath(
                    os.path.join(self._execution_config_path, src))
                self.__check_file_exists(file_name)

                # Parse the xml file to include
                to_include = self.__parse_xml_file(file_name)

                # User can add TestStep and/or TestStepSets in his include file
                teststeps_root_node = to_include.xpath(
                    "/" + TestStepConstants.STR_PATH_TEST_STEPS)
                if teststeps_root_node:
                    # TestSteps to include into the reference Test Step catalog
                    teststeps_to_include = self._teststep_catalog_parser.parse_catalog_file(
                        file_name)

                    # Raise an exception if a test step is already defined
                    for teststep_name in teststeps_to_include.iterkeys():
                        if teststep_name in self._teststep_dictionary:
                            error_msg = "TestStep '%s' is defined more than one time !" % teststep_name
                            self.__config_error = True
                            raise AcsConfigException(
                                AcsConfigException.PROHIBITIVE_BEHAVIOR,
                                error_msg)

                    self._teststep_dictionary.update(teststeps_to_include)

                # All the TestStepSet shall be defined in <TestStepSets/> node
                teststepsets_root_node = to_include.xpath(
                    "/" + TestStepConstants.STR_PATH_INCLUDE)
                if teststepsets_root_node:
                    # As xpath query has been done to get the root node of the xml file,
                    # we will have only one STR_PATH_INCLUDE tag. That is why we take the first element
                    for item in teststepsets_root_node[0]:
                        # Add all nodes to the root node which are not Comments
                        if isinstance(item.tag, basestring):
                            node.append(item)