Пример #1
0
    def convert_parameter_value(self, tc_param_value, tc_param_name, default_cast_type=str):
        """
        convert value according to a cast type

        This function returns the value of a parameter.

        :type tc_param_value: string
        :param tc_param_value: value to convert

        :type default_cast_type: type object
        :param default_cast_type: type to cast (int, str, list ...)
        By default cast into str type.

        :rtype: depends on default_cast_type
        :return: test case parameter value
        """
        if default_cast_type == "str_to_bool":
            if Utils.is_bool(str(tc_param_value)):
                tc_param_value = Utils.str_to_bool(str(tc_param_value))
            else:
                self._logger.warning("%s='%s', invalid value in campaign for test %s" %
                                     (tc_param_name, tc_param_value, self._name))
                tc_param_value = None
        elif default_cast_type is int or default_cast_type is float:
            if Utils.is_number(str(tc_param_value)):
                tc_param_value = default_cast_type(str(tc_param_value))
            else:
                tc_param_value = None
        else:
            tc_param_value = default_cast_type(tc_param_value)
        return tc_param_value
    def _setup(self, **kwargs):
        """
            This function initializes all global variables used in acs execution.
            It parses the arguments given to CampaignEngine,
            parses XML files associated & read the campaign content
            for the TestCaseManager to execute.

            :param device_name: Device model under test.
            :type device_name: str

            :param serial_number: Device id or serial number of the DUT.
            :type serial_number: str

            :param campaign_name: Campaign xml file to execute.
            :type campaign_name: str

            :param campaign_relative_path: Campaign relative path.
            :type campaign_relative_path: str

            :param bench_config: Bench Config file to use.
            :type bench_config: str

            :param device_parameters: List of device parameters to override default values in Device_Catalog.
            :type device_parameters: list

            :param flash_file_path: Flash file full path.
            :type flash_file_path: str

            :param random_mode: Enable random mode if your campaign is configured to run random TC.
            :type random_mode: bool

            :param user_email: Valid user email.
            :type user_email: str

            :param credentials: Credentials in User:Password format.
            :type credentials: str

            :rtype: bool
            :return: True if setup is correctly done, else False
        """

        status = None

        device_name = kwargs["device_name"]
        serial_number = kwargs["serial_number"]
        campaign_name = kwargs["campaign_name"]
        campaign_relative_path = kwargs["campaign_relative_path"]
        device_parameters = kwargs["device_parameter_list"]
        random_mode = kwargs["random_mode"]
        user_email = kwargs["user_email"]
        credentials = kwargs["credentials"]
        log_level_param = kwargs["log_level"]

        # In case the uuid is not set, generate it to ensure that the campaign has an id
        # This id is used for reporting purpose
        self.__logger.info('Checking metacampaign UUID integrity...')
        metacampaign_uuid = kwargs["metacampaign_uuid"]
        valid_uuid = is_uuid4(metacampaign_uuid)
        if not valid_uuid:
            self.__logger.warning("Metacampaign UUID is empty or not a valid UUID4; a new one is generated ...")
        metacampaign_uuid = metacampaign_uuid if valid_uuid else str(uuid.uuid4())
        self.__logger.info("Metacampaign UUID is {0}".format(metacampaign_uuid))

        self.__init_configuration(**kwargs)

        # Init Campaign report path
        self.__init_report_path(campaign_name)
        # Instantiate a live reporting interface
        campaign_name = os.path.splitext(os.path.basename(campaign_name))[0]
        self.__init_live_reporting(campaign_name,
                                   metacampaign_uuid,
                                   user_email,
                                   kwargs.get("live_reporting_plugin"))

        self.__stop_on_critical_failure = Util.str_to_bool(
            self.__global_config.campaignConfig.get("stopCampaignOnCriticalFailure", "False"))
        self.__stop_on_first_failure = Util.str_to_bool(
            self.__global_config.campaignConfig.get("stopCampaignOnFirstFailure", "False"))

        # Provide the global configuration for equipment manager and device manager
        # They will use it to retrieve or set values in it.
        EquipmentManager().set_global_config(self.__global_config)
        DeviceManager().set_global_config(self.__global_config)

        # Initialize equipments necessary to control DUT (io card, power supply, usb hub)
        EquipmentManager().initialize()

        # Read serial number if given as ACS command line
        if serial_number not in ["", None]:
            # Priority to serialNumber from --sr parameter
            device_parameters.append("serialNumber=%s" % str(serial_number))
        # Load the device
        device = DeviceManager().load(device_name, device_parameters)[Util.AcsConstants.DEFAULT_DEVICE_NAME]
        # store the device config file
        device_conf_list = []
        for dev in DeviceManager().get_all_devices():
            device_config_file = dev.get_config("DeviceConfigPath")
            if device_config_file:
                device_conf_list.append(device_config_file)
        self._campaign_elements.update({"devices": device_conf_list})

        # Init the logger
        self.__init_logger(device.hw_variant_name, serial_number, self.campaign_report_path, metacampaign_uuid)

        self.__logger.info('Checking acs version : %s' % str(Util.get_acs_release_version()))

        if self.__test_case_conf_list:
            if random_mode:
                self.__test_case_conf_list = self.__randomize_test_cases(self.__test_case_conf_list)
            # Parse parameter catalog
            parameter_catalog_parser = ParameterCatalogParser()
            self.__global_config.__setattr__("parameterConfig", parameter_catalog_parser.parse_catalog_folder())

            # Retrieve MTBF custom parameter to align logging level between the console and the log file
            is_logging_level_aligned = Util.str_to_bool(
                self.__global_config.campaignConfig.get("isLoggingLevelAligned", "False"))
            # Set log level according to global_config file content
            if log_level_param:
                logging_level = log_level_param
            else:
                logging_level = self.__global_config.campaignConfig.get("loggingLevel", "DEBUG")
            ACSLogging.set_log_level(logging_level, is_logging_level_aligned)

            # Set campaign_type when it exists
            campaign_type = self.__global_config.campaignConfig.get("CampaignType")

            # Set credentials
            self.__global_config.__setattr__("credentials", credentials)

            # Init reports
            self.__init_reports(self.campaign_report_path,
                                device_name, campaign_name, campaign_relative_path,
                                campaign_type, user_email, metacampaign_uuid)

            # Creates Test case Manager object
            self.__test_case_manager = TestCaseManager(self.__test_report,
                                                       live_reporting_interface=self._live_reporting_interface)

            # Setup Test Case Manager
            tcm_stop_execution = self.__test_case_manager.setup(self.__global_config,
                                                                self.__debug_report,
                                                                self.__test_case_conf_list[0].do_device_connection)
            status = tcm_stop_execution
        else:
            status = AcsBaseException.NO_TEST

        return status