コード例 #1
0
    def update_report_file(self):
        """
        Update the xml report file
        """
        try:

            temp_test_report_file = os.path.join(tempfile.gettempdir(),
                                                 "Temporary_TestReport.xml")
            processing_instruction = etree.ProcessingInstruction(
                "xml-stylesheet", "type=\"text/xsl\" href=\"report.xsl\"")
            with open(temp_test_report_file, 'w') as f_test_report:
                f_test_report.write(
                    etree.tostring(processing_instruction,
                                   pretty_print=True,
                                   xml_declaration=True))
                f_test_report.write(
                    etree.tostring(self.document, pretty_print=True))

            # Copy the temporary file into the test report
            shutil.move(temp_test_report_file, self.filename)
            # copy the XSL file in the same folder ad the XML file
            shutil.copy(self._xsl_path, self._base)

        except Exception as report_exception:
            LOGGER_FWK.warning("Fail to update test report '%s' ! (%s)" %
                               (str(self.filename), str(report_exception)))
def timezone():
    """
    Return host timezone

    :rtype: str
    :return: Timezone (i.e: 'Europe/Paris')
    """
    # Trying to get local timezone
    try:
        import tzlocal
        host_localtimezone = str(tzlocal.get_localzone())
    except Exception as tzlocal_exception:
        # Set default host time
        host_localtimezone = DEFAULT_TIMEZONE
        LOGGER_FWK.warning("Cannot get host timezone ! "
                           "Use default timezone ('{0}') => {1}".format(
                               host_localtimezone, str(tzlocal_exception)))
    return host_localtimezone
コード例 #3
0
    def _override_parameters_bench(self):
        """
        Override device config with device parameters available in bench config if applicable.

        """
        device_model_name = self.device_model_name
        device_name = self._device_name

        if self.bench_conf:
            do_the_override = False
            if device_name == AcsConstants.DEFAULT_DEVICE_NAME:
                if "Name" not in self.bench_conf:
                    # No device specified in the bench config for PHONE1
                    # Do the override then
                    do_the_override = True
                elif self.bench_conf.Name == device_model_name:
                    # Same device specified on the command line then in the bench config
                    # Do the override
                    do_the_override = True
                else:
                    warning_msg = (
                        "Different device model specified on the command line ({0}) "
                        "then in the bench config ({1}) for {2}! Related parameters specified "
                        "in bench config will be ignored !").format(
                            device_model_name, self.bench_conf.Name,
                            AcsConstants.DEFAULT_DEVICE_NAME)
                    LOGGER_FWK.warning(warning_msg)
            else:
                # For other phones (PHONE2, ...) we do the override every time
                do_the_override = True

            if do_the_override:
                for key, value in self.bench_conf.iteritems():
                    if key == "device_modules":
                        for module, module_conf in value.iteritems():
                            self.device_conf.device_modules[
                                module] = module_conf
                    else:
                        self._override_through_sections(
                            self.device_conf, key, value,
                            self._bench_unknown_parameters)