def init_ctx(global_dict, logger, global_config): # VERDICT GLOBALS global_dict["VERDICT"] = Global.FAILURE global_dict["OUTPUT"] = "" global_dict["FAILURE"] = Global.FAILURE global_dict["SUCCESS"] = Global.SUCCESS # LOG GLOBALS global_dict["PRINT_DEBUG"] = logger.debug global_dict["PRINT_INFO"] = logger.info global_dict["PRINT_ERROR"] = logger.error global_dict["PRINT_WARNING"] = logger.warning # DEVICE GLOBALS device = DeviceManager().get_device(AcsConstants.DEFAULT_DEVICE_NAME) global_dict["DEVICE_MANAGER"] = DeviceManager() global_dict["DEVICE"] = device global_dict["DEVICE_LOGGER"] = device.get_device_logger() # EQUIPMENT GLOBALS global_dict["EQUIPMENT_MANAGER"] = EquipmentManager() io_card_name = device.config.get("IoCard", "IO_CARD") global_dict["IO_CARD"] = EquipmentManager().get_io_card(io_card_name) # REPORT GLOBALS global_dict["REPORT_PATH"] = device.get_report_tree().get_report_path() global_dict["ACS_REPORT_FILE_PATH"] = device.get_report_tree( ).report_file_path # ACS GLOBALS global_dict["PATH_MANAGER"] = Paths global_dict["LOCAL_EXEC"] = internal_shell_exec global_dict["BENCH_CONFIG"] = global_config.benchConfig global_dict["EXECUTION_CONFIG_PATH"] = path.abspath(Paths.EXECUTION_CONFIG) global_dict["CREDENTIALS"] = global_config.credentials
def __init__(self, tc_conf, global_config): """ Constructor """ TestStepEngine.__init__(self, tc_conf, global_config) # Get Device Instance self._device = DeviceManager().get_device("PHONE1") self._dut_config = DeviceManager().get_device_config("PHONE1") self._device.inject_device_log("i", "ACS_TESTCASE", "INIT: %s" % self._name) # Get a reference of equipment manager self._em = EquipmentManager() # Get IO card instance. Default value is 'IO_CARD' io_card_name = self._dut_config.get("IoCard", "IO_CARD") self._io_card = self._em.get_io_card(io_card_name) # Get Global TC Parameters self._wait_btwn_cmd = float(self._dut_config.get("waitBetweenCmd"))
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
class UseCaseBase(TestStepEngine): """ Base class for all use case implementation """ def __init__(self, tc_conf, global_config): """ Constructor """ TestStepEngine.__init__(self, tc_conf, global_config) # Get Device Instance self._device = DeviceManager().get_device("PHONE1") self._dut_config = DeviceManager().get_device_config("PHONE1") self._device.inject_device_log("i", "ACS_TESTCASE", "INIT: %s" % self._name) # Get a reference of equipment manager self._em = EquipmentManager() # Get IO card instance. Default value is 'IO_CARD' io_card_name = self._dut_config.get("IoCard", "IO_CARD") self._io_card = self._em.get_io_card(io_card_name) # Get Global TC Parameters self._wait_btwn_cmd = float(self._dut_config.get("waitBetweenCmd")) def _run_test_steps(self, path, optional_step=True): return TestStepEngine._run_test_steps(self, path, optional_step=True) def initialize(self): verdict, msg = TestStepEngine.initialize(self) self._device.inject_device_log("i", "ACS_TESTCASE", "INITIALIZE: %s" % self._name) return verdict, msg def set_up(self): """ Initialize the test """ verdict, msg = TestStepEngine.set_up(self) self._device.inject_device_log("i", "ACS_TESTCASE", "SETUP: %s" % self._name) return verdict, msg def run_test(self): """ Execute the test """ verdict, msg = TestStepEngine.run_test(self) self._device.inject_device_log("i", "ACS_TESTCASE", "RUNTEST: %s" % self._name) return verdict, msg def tear_down(self): """ End and dispose the test """ verdict, msg = TestStepEngine.tear_down(self) self._device.inject_device_log("i", "ACS_TESTCASE", "TEARDOWN: %s" % self._name) return verdict, msg def finalize(self): verdict, msg = TestStepEngine.finalize(self) self._device.inject_device_log("i", "ACS_TESTCASE", "FINALIZE: %s" % self._name) return verdict, msg
""" """ Check artifact is in cache folder Clean cache folder """ import os from acs.Core.Equipment.EquipmentManager import EquipmentManager VERDICT = FAILURE OUTPUT = "Fake Artifact cannot be created" artifact = TC_PARAMETERS("ARTIFACT_NAME") if artifact: artifact = os.path.normpath(artifact) PRINT_INFO("Create fake : %s" % artifact) artifact_manager = EquipmentManager().get_artifact_manager( "ARTIFACT_MANAGER") cache_path = artifact_manager.cache_artifacts_path expected_downloaded_artifact = os.path.join(cache_path, artifact) if os.path.isfile(expected_downloaded_artifact): PRINT_INFO("Removing existing file : %s" % expected_downloaded_artifact) os.remove(expected_downloaded_artifact) with open(expected_downloaded_artifact, "w") as f: f.write("Fake Artifact") VERDICT = SUCCESS OUTPUT = "Fake artifact %s has been generated" % expected_downloaded_artifact PRINT_INFO("Fake artifact %s has been generated" % expected_downloaded_artifact)
def create_equipment_manager(self): """ Returns an equipment manager """ return EquipmentManager()