예제 #1
0
    def write(self, msg):
        """
        :type msg: str
        :param msg: message to log
        """
        if msg.startswith("%s%s" % (self.LOG_PREFIX, self.SEPARATOR)):
            print >> self.logging_messages_stream, "".join(
                msg.split(self.SEPARATOR)[1:])
        elif msg.startswith("%s%s" % (self.TEST_CASE_TITLE, self.SEPARATOR)):
            Indent.indent_reset()
            test_case = "".join(msg.split(self.SEPARATOR)[1:]).strip()
            self.logging_messages_stream.set_active_case(test_case)

            msg = '\nTest case: {test_case}'.format(test_case=test_case)
            print "%s%s" % (indent(),
                            ColorPrinter.format_text(
                                msg, color=ColorPrinter.BLUE_FORE, bold=True))
            Indent.indent_right()
        elif msg.startswith("%s%s" % (self.STATUS, self.SEPARATOR)):
            status = "".join(msg.split(self.SEPARATOR)[1:]).strip()
            self.logging_messages_stream.set_case_status(status)
            print "%s%s" % (indent(),
                            ColorPrinter.format_status(status, bold=True))
            Indent.indent_reset()
        elif msg.startswith(self.SCREEN):
            print "%s%s" % (indent(), "".join(msg.split(
                self.SCREEN)[1:]).strip())
        else:
            print >> self.logging_messages_stream, msg
예제 #2
0
    def write(self, msg):
        """
        :type msg: str
        :param msg: message to log
        """
        if msg.startswith("%s%s" % (self.LOG_PREFIX, self.SEPARATOR)):
            print >> self.logging_messages_stream, "".join(msg.split(self.SEPARATOR)[1:])
        elif msg.startswith("%s%s" % (self.TEST_CASE_TITLE, self.SEPARATOR)):
            Indent.indent_reset()
            test_case = "".join(msg.split(self.SEPARATOR)[1:]).strip()
            self.logging_messages_stream.set_active_case(test_case)

            msg = '\nTest case: {test_case}'.format(test_case=test_case)
            print "%s%s" % (
                indent(),
                ColorPrinter.format_text(msg, color=ColorPrinter.BLUE_FORE, bold=True))
            Indent.indent_right()
        elif msg.startswith("%s%s" % (self.STATUS, self.SEPARATOR)):
            status = "".join(msg.split(self.SEPARATOR)[1:]).strip()
            self.logging_messages_stream.set_case_status(status)
            print "%s%s" % (
                indent(),
                ColorPrinter.format_status(status, bold=True)
            )
            Indent.indent_reset()
        elif msg.startswith(self.SCREEN):
            print "%s%s" % (
                indent(),
                "".join(msg.split(self.SCREEN)[1:]).strip()
            )
        else:
            print >> self.logging_messages_stream, msg
예제 #3
0
 def all_not_bool_test(self, discovery_container, resource_collection,
                       collection_name, mode, properties):
     """function to test if all requested properties in collection are not true/false"""
     if self.collection_is_not_empty(resource_collection,
                                     collection_name) is True:
         for resource in resource_collection:
             print "MESSAGE::%s" % resource
             for subproperty in self.format_body(discovery_container,
                                                 resource, properties):
                 construct = self.construct(discovery_container, resource,
                                            subproperty)
                 if construct is mode:
                     print "MESSAGE::" + ColorPrinter.format_text(
                         "Failed", color=ColorPrinter.RED_FORE
                     ) + ": " + subproperty + " property is " + str(mode)
                     self.failure = True
                 elif construct is None:
                     print "MESSAGE::" + ColorPrinter.format_text(
                         "Failed", color=ColorPrinter.RED_FORE
                     ) + ": " + subproperty + " property is Null"
                     self.failure = True
                 else:
                     print "MESSAGE::" + ColorPrinter.format_text(
                         "Passed", color=ColorPrinter.GREEN_FORE
                     ) + ": " + subproperty + " property is not " + str(
                         mode)
예제 #4
0
 def numeric_logical_test(self, discovery_container, resource_collection,
                          collection_name, properties):
     """function to test if requested properties are integer and higher than zero"""
     if self.collection_is_not_empty(resource_collection,
                                     collection_name) is True:
         for resource in resource_collection:
             print "MESSAGE::%s" % resource
             for subproperty in self.format_body(discovery_container,
                                                 resource, properties):
                 construct = self.construct(discovery_container, resource,
                                            subproperty)
                 if type(construct) != int:
                     print "MESSAGE::" + ColorPrinter.format_text(
                         "Failed", color=ColorPrinter.RED_FORE
                     ) + ": " + subproperty + " property is not an integer"
                     self.failure = True
                 elif construct <= 0:
                     print "MESSAGE::" + ColorPrinter.format_text(
                         "Failed", color=ColorPrinter.RED_FORE
                     ) + ": " + subproperty + " property is not > 0"
                     self.failure = True
                 else:
                     print "MESSAGE::" + ColorPrinter.format_text(
                         "Passed", color=ColorPrinter.GREEN_FORE
                     ) + ": " + subproperty + " property is > 0"
예제 #5
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(
            BuildInformation.get_version(), bold=True))
        print "\nComparing...\n\n"

        with ErrorMute():
            report = self.report_name()
            with open(report, 'w') as sys.stdout:
                comparator = MetadataComparator(configuration.METADATA,
                                                configuration.qualifiers)
                result = comparator.run()
                if result is not None:
                    if result.result == Comparator.EQUAL:
                        msg = "\n\nMetadata sets {metadata} are equal\n\n".format(
                            metadata=" and ".join(configuration.METADATA))
                        sys.stderr.write(msg)
                        sys.stdout.write(msg)
                    else:
                        msg = "\n\nMetadata sets {metadata} differ\n\n".format(
                            metadata=" and ".join(configuration.METADATA))
                        sys.stderr.write(msg)
                        sys.stdout.write(msg)
                        print result.get_side_by_side(*configuration.METADATA)

            sys.stdout = sys.__stdout__
            print "Report has been written to: {name}".format(name=report)
예제 #6
0
    def run(self):
        api_explorer = ApiExplorer(self.metadata_container, self.configuration)
        discovery_container, status = api_explorer.discover(
            MetadataConstants.SERVICE_ROOT_URI, MetadataConstants.SERVICE_ROOT)
        status = ValidationStatus.PASSED

        catalog = expanduser(
            "~"
        ) + "/.cts/tests/Rack_Scale_2_5_Storage_Services/required/tests_archeo_ss/"
        for test in listdir(catalog):
            with open(catalog + test) as f:
                data = json.load(f)
                test_name = data["name"]
                print "TEST_CASE::Validating section " + ColorPrinter.format_text(test_name,
                                                                                  color=ColorPrinter.YELLOW_FORE) + \
                      " of architecture specification"
                status_of_test = ArchSpecTests().parse_json(
                    discovery_container, data)
                if _skip_pnc_tests_if_resource_is_not_available(test) and \
                        (status_of_test == ValidationStatus.FAILED):
                    status = ValidationStatus.join_statuses(
                        status, ValidationStatus.PASSED_WITH_WARNINGS)
                    print "MESSAGE:: CTS can not detect a PNC. Skipping this tests"
                else:
                    status = ValidationStatus.join_statuses(
                        status, status_of_test)
                print "STATUS::{status}".format(status=status_of_test)
        print "MESSAGE::All tests finished"
        print "STATUS::{status}".format(status=status)
예제 #7
0
    def process_action(self, configuration):
        replay_id = configuration.replay_id[0]
        print "Using CTS in version %s to replay execution %s" \
              % (ColorPrinter.format_text(BuildInformation.BUILD_VERSION, bold=True), replay_id)

        error, script_execution_id = split_replay_id(replay_id)
        if error:
            return

        # TODO: warn user when he tries to replay using newer CTS

        script_execution = ScriptDAO.get_script_execution_details(
            script_execution_id)
        if script_execution is None:
            cts_error(
                "Recording for script execution id={id:ignore} not found",
                id=script_execution_id)
            return

        script_path = script_execution.script_path
        configuration = self._configuration_from_string(
            script_execution.configuration)

        test_plan = self._prepare_test_plan(script_path)

        environ[ReplayController.CTS_REPLAY_SCRIPT_EXECUTION_ID] = str(
            script_execution_id)
        self._execute(configuration, test_plan)
예제 #8
0
    def run(self):
        if self.metadata_container is None:
            return

        self.chosen_endpoint, self.chosen_zone, self.chosen_volume, self.chosen_volume_collection = (None,)*4
        self.initiator_endpoint, self.target_endpoint, self.zone_endpoint, self.created_volume = (None,)*4

        test_name = "Storage Services CRUD test"
        print "MESSAGE::%s starting" % test_name

        print "TEST_CASE::API crawling"
        api_explorer = ApiExplorer(self.metadata_container, self.configuration)
        self.discovery_container, status = api_explorer.discover(MetadataConstants.SERVICE_ROOT_URI,
                                                                 MetadataConstants.SERVICE_ROOT)
        print "STATUS::{status}".format(status=status)

        requirements = [
            Requirement(MetadataConstants.SERVICE_ROOT, min=1, max=1),
            Requirement(MetadataConstants.STORAGE_SERVICE, min=1),
            Requirement(MetadataConstants.VOLUME, min=1),
            Requirement(MetadataConstants.VOLUME_COLLECTION, min=1)
        ]
        preconditions = Preconditions(self.metadata_container, requirements)
        status = preconditions.validate(self.discovery_container)

        if status == ValidationStatus.FAILED:
            self.set_status_failed()
            return

        self.api_caller = ApiCaller(self.configuration)

        status = ValidationStatus.join_statuses(status, self.crud_fabrics_target())

        print "MESSAGE::%s overall status: %s" % (test_name, ColorPrinter.format_status(status))
예제 #9
0
    def run(self):
        if self.metadata_container is None:
            return

        test_name = "Storage Services CRUD test"
        print "MESSAGE::%s starting" % test_name

        print "TEST_CASE::API crawling"
        api_explorer = ApiExplorer(self.metadata_container, self.configuration)
        self.discovery_container, status = api_explorer.discover(MetadataConstants.SERVICE_ROOT_URI,
                                                                 MetadataConstants.SERVICE_ROOT)
        print "STATUS::{status}".format(status=status)

        requirements = [
            Requirement(MetadataConstants.SERVICE_ROOT, min=1, max=1),
            Requirement(MetadataConstants.STORAGE_SERVICE, min=1),
            Requirement(MetadataConstants.LOGICAL_DRIVE_COLLECTION, min=1),
            Requirement(MetadataConstants.REMOTE_TARGET_COLLECTION, min=1),
            Requirement(MetadataConstants.LOGICAL_DRIVE, min=2)
        ]
        preconditions = Preconditions(self.metadata_container, requirements)
        status = preconditions.validate(self.discovery_container)

        if  status == ValidationStatus.FAILED:
            self.set_status_blocked()
            return

        self.api_caller = ApiCaller(self.configuration)

        status = ValidationStatus.join_statuses(status, self.crud_logical_drive())
        status = ValidationStatus.join_statuses(status, self.crud_remote_target())

        print "MESSAGE::%s overall status: %s" % (test_name, ColorPrinter.format_status(status))
예제 #10
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(BuildInformation.BUILD_VERSION, bold=True))
        tests_manager = TestsManager()

        configuration_files = configuration.config_files
        test_scripts_configuration = get_configuration_from_files(configuration_files)

        if not configuration.usecase:
            print('\nMissing --usecase argument\n')
            JsonLoader().print_available_actions()
            sys.exit(64)  # EX_USAGE = 64    command line usage error

        test_scripts_configuration['UseCase'] = configuration.usecase[0]

        if test_scripts_configuration is None:
            sys.exit(-1)

        if not certificates_files_are_valid(test_scripts_configuration):
            sys.exit(-1)

        test_plan = TestsPackagesContainer()

        if configuration.test_scripts:
            test_scripts_found = tests_manager.get_packages()

            test_scripts_found.filter(scripts=configuration.test_scripts,
                                      remove_empty=True)
            test_plan += test_scripts_found
        else:
            test_plan += tests_manager.get_packages()

        if not test_plan.packages:
            print('No script selected to execute')
            exit(64)  # EX_USAGE = 64    command line usage error

        message = "Executing "
        print('Executing:')
        for package in test_plan.packages:
            for suite in package.suites:
                for script in suite.scripts:
                    print "\t* %s from suite %s from package %s" % (script.name, suite.name, package.name)
                    message += "%s from suite %s from package %s, " % (script.name, suite.name, package.name)

        self._logger.log_debug(message)

        if configuration.timeout is not None:
            message = "setting timeout execution to %s" % configuration.timeout[0]
            self._logger.log_debug(message)
            print "\n%s" % message
            test_plan.set_scripts_timeout(configuration.timeout[0])

        execution_feed = ExecutionFeed(test_plan, test_scripts_configuration)

        for case in configuration.usecase:
            if not self.check_use_case_exist(case):
                print('\nUse Case was not found: %s ' % case)
                exit(64)  # EX_USAGE = 64    command line usage error

        ScenarioAction.execute_configuration_group(execution_feed,
                                                   test_status_as_exit_code=configuration.return_tests_status_as_exit_code)
예제 #11
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(
            BuildInformation.BUILD_VERSION, bold=True))
        tests_manager = TestsManager()

        configuration_files = configuration.config_files
        test_scripts_configuration = get_configuration_from_files(
            configuration_files)

        if not configuration.use_case:
            print('\nMissing --use_case argument\n')
            JsonLoader().print_available_actions()
            sys.exit(64)  # EX_USAGE = 64    command line usage error

        test_scripts_configuration['UseCase'] = configuration.use_case[0]

        if test_scripts_configuration is None:
            sys.exit(-1)

        if not certificates_files_are_valid(test_scripts_configuration):
            sys.exit(-1)

        test_plan = TestsPackagesContainer()
        test_scripts_found = tests_manager.get_packages()
        test_scripts_found.filter(scripts='validate_use_case',
                                  remove_empty=True)
        test_plan += test_scripts_found

        if not test_plan.packages:
            print('No script selected to execute')
            exit(64)  # EX_USAGE = 64    command line usage error

        message = "Executing "
        print('Executing:')
        for package in test_plan.packages:
            for suite in package.suites:
                for script in suite.scripts:
                    print "\t* %s from suite %s from package %s" % (
                        script.name, suite.name, package.name)
                    message += "%s from suite %s from package %s, " % (
                        script.name, suite.name, package.name)

        self._logger.log_debug(message)

        if configuration.timeout is not None:
            message = "setting timeout execution to %s" % configuration.timeout[
                0]
            self._logger.log_debug(message)
            print('\n%s' % message)
            test_plan.set_scripts_timeout(configuration.timeout[0])

        execution_feed = ExecutionFeed(test_plan, test_scripts_configuration)

        for case in configuration.use_case:
            if not self.check_use_case_exist(case):
                print('\nUse Case was not found: %s ' % case)
                exit(64)  # EX_USAGE = 64    command line usage error
예제 #12
0
 def collection_is_not_empty(self, resource_collection, name):
     """function to test if collection is empty"""
     if resource_collection is not None:
         if len(resource_collection) == 0:
             self.failure = True
             print "MESSAGE::" + ColorPrinter.format_text(
                 "Failed", color=ColorPrinter.RED_FORE
             ) + ": Collection of " + name + " is empty"
             return False
         else:
             print "MESSAGE::" + ColorPrinter.format_text(
                 "Passed", color=ColorPrinter.GREEN_FORE
             ) + ": Collection of " + name + " is not empty"
             return True
     else:
         self.failure = True
         print "MESSAGE::" + ColorPrinter.format_text(
             "Failed", color=ColorPrinter.RED_FORE
         ) + ": Collection of " + name + " does not exist!"
         return False
예제 #13
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(BuildInformation.BUILD_VERSION, bold=True))
        tests_manager = TestsManager()

        configuration_files = configuration.config_files
        test_scripts_configuration = get_configuration_from_files(configuration_files)
        if test_scripts_configuration is None:
            sys.exit(-1)

        if not certificates_files_are_valid(test_scripts_configuration):
            sys.exit(-1)

        test_plan = TestsPackagesContainer()

        if configuration.test_suites or configuration.test_scripts:
            if configuration.test_suites:
                test_suites_found = tests_manager.get_packages()
                test_suites_found.filter(packages=configuration.package, suites=configuration.test_suites,
                                         remove_empty=True)
                test_plan += test_suites_found
            if configuration.test_scripts:
                test_scripts_found = tests_manager.get_packages()

                test_scripts_found.filter(packages=configuration.package, scripts=configuration.test_scripts,
                                          remove_empty=True)
                test_plan += test_scripts_found
        else:
            test_plan += tests_manager.get_packages()

        test_plan.filter(packages=configuration.package)

        if not test_plan.packages:
            print "No script selected to execute"
            exit(64)  # EX_USAGE = 64    command line usage error

        message = "Executing "
        print "Executing:"
        for package in test_plan.packages:
            for suite in package.suites:
                for script in suite.scripts:
                    print "\t* %s from suite %s from package %s" % (script.name, suite.name, package.name)
                    message += "%s from suite %s from package %s, " % (script.name, suite.name, package.name)

        self._logger.log_debug(message)

        if configuration.timeout is not None:
            message = "setting timeout execution to %s" % configuration.timeout[0]
            self._logger.log_debug(message)
            print "\n%s" % message
            test_plan.set_scripts_timeout(configuration.timeout[0])

        execution_feed = ExecutionFeed(test_plan, test_scripts_configuration)

        ExecuteTestScriptsAction.execute_configuration_group(execution_feed, test_status_as_exit_code=configuration.return_tests_status_as_exit_code)
예제 #14
0
 def all_elements_identical(self, elements, name):
     """function to test if all elements in list are identical"""
     if not elements:
         self.failure = True
         print "MESSAGE::" + ColorPrinter.format_text(
             "Failed", color=ColorPrinter.RED_FORE
         ) + ": List is empty or does not exist!"
         return False
     else:
         if len(set(elements)) > 1:
             self.failure = True
             print "MESSAGE::" + ColorPrinter.format_text(
                 "Failed", color=ColorPrinter.RED_FORE
             ) + ": All " + name + " are not identical"
             return False
         else:
             print "MESSAGE::" + ColorPrinter.format_text(
                 "Passed", color=ColorPrinter.GREEN_FORE
             ) + ": All " + name + " are identical"
             return True
예제 #15
0
 def string_logical_test(self,
                         discovery_container,
                         resource_collection,
                         collection_name,
                         properties,
                         str_value,
                         consists=False):
     """function to test if requested properties are equal to string"""
     if self.collection_is_not_empty(resource_collection,
                                     collection_name) is True:
         for resource in resource_collection:
             print "MESSAGE::%s" % resource
             for subproperty in self.format_body(discovery_container,
                                                 resource, properties):
                 construct = self.construct(discovery_container, resource,
                                            subproperty)
                 if consists is False:
                     if str_value in re.split('\W+', construct):
                         print "MESSAGE::" + ColorPrinter.format_text(
                             "Passed", color=ColorPrinter.GREEN_FORE
                         ) + ": " + subproperty + " property is " + str_value
                     elif construct != str_value:
                         print "MESSAGE::" + ColorPrinter.format_text(
                             "Failed", color=ColorPrinter.RED_FORE
                         ) + ": " + subproperty + " property is not " + str_value
                         self.failure = True
                     else:
                         print "MESSAGE::" + ColorPrinter.format_text(
                             "Passed", color=ColorPrinter.GREEN_FORE
                         ) + ": " + subproperty + " property is " + str_value
                 else:
                     if str_value not in construct:
                         print "MESSAGE::" + ColorPrinter.format_text(
                             "Failed", color=ColorPrinter.RED_FORE
                         ) + ": " + subproperty + " property does not contain " + str_value
                         self.failure = True
                     else:
                         print "MESSAGE::" + ColorPrinter.format_text(
                             "Passed", color=ColorPrinter.GREEN_FORE
                         ) + ": " + subproperty + " property does contain " + str_value
예제 #16
0
    def format_script_results(self, script_execution_id):
        script_execution = ScriptDAO.get_script_execution_details(script_execution_id)

        status, passed, total = ScriptDAO.get_script_execution_statistics(script_execution_id)
        overall_status = ResultStatus.PASSED if status else ResultStatus.FAILED

        results_header = "Test script{horizontal_separator}{test_script_path}{vertical_separator}".format(
            horizontal_separator=HORIZONTAL_SEPARATOR, test_script_path=script_execution.script_path,
            vertical_separator=VERTICAL_SEPARATOR)

        results_header += "Overall status{horizontal_separator}{overall_status}{vertical_separator}".format(
            horizontal_separator=HORIZONTAL_SEPARATOR, overall_status=ColorPrinter.format_status(overall_status),
            vertical_separator=VERTICAL_SEPARATOR)

        results_header += "Pass rate{horizontal_separator}{passed}/{total}{vertical_separator}".format(
            horizontal_separator=HORIZONTAL_SEPARATOR, passed=passed, total=total,
            vertical_separator=VERTICAL_SEPARATOR)

        results_header += "configuration:{vertical_separator}".format(vertical_separator=VERTICAL_SEPARATOR)
        for param in script_execution.configuration.split("--"):
            if not param:
                continue

            param_name = param.split(" ")[0]
            if param_name in [PARAM_USER, PARAM_PASSWORD]:
                param_value = "**********"
            else:
                param_value = "".join(param.split(" ")[1:])

            results_header += \
                "{horizontal_separator}" \
                "{param_name:10}{horizontal_separator}" \
                "{param_value}{vertical_separator}" \
                    .format(vertical_separator=VERTICAL_SEPARATOR,
                            param_name=param_name,
                            param_value=param_value,
                            horizontal_separator=HORIZONTAL_SEPARATOR)

        results_header += "Level of details -d{level}\n".format(level=self.message_level)

        results_header += "Reported cases"
        yield results_header

        cases_results = (self.format_case_results(case_execution_id) for case_execution_id in
                         CaseDAO.get_cases_execution_ids_for_script_execution(script_execution_id))

        yield VERTICAL_SEPARATOR

        for case_result in cases_results:
            for line in case_result:
                yield line
            yield VERTICAL_SEPARATOR
예제 #17
0
    def format_script_results(self, script_execution_id):
        script_execution = ScriptDAO.get_script_execution_details(script_execution_id)

        status, passed, total = ScriptDAO.get_script_execution_statistics(script_execution_id)
        overall_status = ResultStatus.PASSED if status else ResultStatus.FAILED

        results_header = "Test script{horizontal_separator}{test_script_path}{vertical_separator}".format(
            horizontal_separator=HORIZONTAL_SEPARATOR, test_script_path=script_execution.script_path,
            vertical_separator=VERTICAL_SEPARATOR)

        results_header += "Overall status{horizontal_separator}{overall_status}{vertical_separator}".format(
            horizontal_separator=HORIZONTAL_SEPARATOR, overall_status=ColorPrinter.format_status(overall_status),
            vertical_separator=VERTICAL_SEPARATOR)

        results_header += "Pass rate{horizontal_separator}{passed}/{total}{vertical_separator}".format(
            horizontal_separator=HORIZONTAL_SEPARATOR, passed=passed, total=total,
            vertical_separator=VERTICAL_SEPARATOR)

        results_header += "configuration:{vertical_separator}".format(vertical_separator=VERTICAL_SEPARATOR)
        for param in script_execution.configuration.split("--"):
            if not param:
                continue

            param_name = param.split(" ")[0]
            if param_name in [PARAM_USER, PARAM_PASSWORD]:
                param_value = "**********"
            else:
                param_value = "".join(param.split(" ")[1:])

            results_header += \
                "{horizontal_separator}" \
                "{param_name:10}{horizontal_separator}" \
                "{param_value}{vertical_separator}" \
                    .format(vertical_separator=VERTICAL_SEPARATOR,
                            param_name=param_name,
                            param_value=param_value,
                            horizontal_separator=HORIZONTAL_SEPARATOR)

        results_header += "Level of details -d{level}\n".format(level=self.message_level)

        results_header += "Reported cases"
        yield results_header

        cases_results = (self.format_case_results(case_execution_id) for case_execution_id in
                         CaseDAO.get_cases_execution_ids_for_script_execution(script_execution_id))

        yield VERTICAL_SEPARATOR

        for case_result in cases_results:
            for line in case_result:
                yield line
            yield VERTICAL_SEPARATOR
예제 #18
0
 def string_logical_test_special(self, discovery_container,
                                 resource_collection, collection_name,
                                 property, str_list):
     """function to test if at least one of members matches one of strings"""
     if self.collection_is_not_empty(resource_collection,
                                     collection_name) is True:
         i = 0
         for resource in resource_collection:
             i = i + 1
             for string in str_list:
                 for prop in self.format_body(discovery_container, resource,
                                              [property]):
                     construct = self.construct(discovery_container,
                                                resource, prop)
                     if construct == string:
                         print "MESSAGE::" + ColorPrinter.format_text("Passed", color=ColorPrinter.GREEN_FORE) + ": " + \
                               "One of " + str(property) + " property equals one of strings " + str(str_list)
                         return
             else:
                 if i == len(resource_collection):
                     print "MESSAGE::" + ColorPrinter.format_text("Failed", color=ColorPrinter.RED_FORE) + ": " + \
                           "None of " + str(property) + " property equals one of strings " + str(str_list)
                     self.failure = True
예제 #19
0
파일: sos_cts.py 프로젝트: 01org/intelRSD
    def process_action(self, configuration):
        """
        The SOS process collects the information needed for easier debugging
        :return:
        """
        print "Using SOS CTS in version %s" % (ColorPrinter.format_text(BuildInformation.BUILD_VERSION, bold=True))
        SOS_SCRIPT_PATH = ""
        SOS_SCRIPT_NAME = "cts-sos.sh"

        resource_package = __name__
        resource_path = '/'.join((SOS_SCRIPT_PATH, SOS_SCRIPT_NAME))

        script_path = pkg_resources.resource_filename(resource_package, resource_path)
        subprocess.call(['sh', script_path])
예제 #20
0
파일: sos_cts.py 프로젝트: weikman/intelRSD
    def process_action(self, configuration):
        """
        The SOS process collects the information needed for easier debugging
        :return:
        """
        print "Using SOS CTS in version %s" % (ColorPrinter.format_text(
            BuildInformation.get_version(), bold=True))
        SOS_SCRIPT_PATH = ""
        SOS_SCRIPT_NAME = "cts-sos.sh"

        resource_package = __name__
        resource_path = '/'.join((SOS_SCRIPT_PATH, SOS_SCRIPT_NAME))

        script_path = pkg_resources.resource_filename(resource_package,
                                                      resource_path)
        subprocess.call(['sh', script_path])
예제 #21
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(BuildInformation.BUILD_VERSION, bold=True))
        print "\nComparing...\n\n"

        if not self.__create_dirs():
            exit(1)  # if you can not create a dirs dont create a report

        include_reports = set(configuration.include_reports)
        if include_reports:
            reports_details = self.get_information_about_test_case_from_db(include_reports)
        else:
            reports_details = {}

        with ErrorMute():
            report = self.report_name(configuration.RackScaleMetadata, configuration.RedfishMetadata)
            comparator = MetadataComparator([configuration.RackScaleMetadata, configuration.RedfishMetadata])
            result = comparator.run()
            if result is not None:
                if result.result == Comparator.EQUAL:
                    print "\n\nMetadata sets {metadata} are equal\n\n".format(metadata=" and ".join(
                        (configuration.RackScaleMetadata, configuration.RedfishMetadata)))
                else:
                    print "\n\nMetadata sets {metadata} differ\n\n".format(metadata=" and ".join(
                        (configuration.RackScaleMetadata, configuration.RedfishMetadata)))

                    if configuration.preview:
                        print result.get_side_by_side(*(configuration.RackScaleMetadata, configuration.RedfishMetadata))

            left_text_container = result.left_ext_file.getvalue().split('\n')
            right_text_container = result.right_ext_file.getvalue().split('\n')

            missing_elements_on_left = self._generate_statistics_from_text_container(left_text_container,
                                                                                     right_text_container)
            missing_elements_on_right = self._generate_statistics_from_text_container(right_text_container,
                                                                                      left_text_container)

            preformat_left = self._update_view_for_more_human_readable(left_text_container)
            preformat_right = self._update_view_for_more_human_readable(right_text_container)

            self._build_html_view(configuration,
                                  {'left': preformat_left,
                                   'right': preformat_right,
                                   'missing_left': missing_elements_on_left,
                                   'missing_right': missing_elements_on_right,
                                   'reports_details': reports_details})
            print "Report has been written to: {name}".format(name=report)
예제 #22
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(BuildInformation.get_version(), bold=True))
        print "\nComparing...\n\n"

        if not self.__create_dirs():
            exit(1)  # if you can not create a dirs dont create a report

        include_reports = set(configuration.include_reports)
        if include_reports:
            reports_details = self.get_information_about_test_case_from_db(include_reports)
        else:
            reports_details = {}

        with ErrorMute():
            report = self.report_name(configuration.RackScaleMetadata, configuration.RedfishMetadata)
            comparator = MetadataComparator([configuration.RackScaleMetadata, configuration.RedfishMetadata])
            result = comparator.run()
            if result is not None:
                if result.result == Comparator.EQUAL:
                    print "\n\nMetadata sets {metadata} are equal\n\n".format(metadata=" and ".join(
                        (configuration.RackScaleMetadata, configuration.RedfishMetadata)))
                else:
                    print "\n\nMetadata sets {metadata} differ\n\n".format(metadata=" and ".join(
                        (configuration.RackScaleMetadata, configuration.RedfishMetadata)))

                    if configuration.preview:
                        print result.get_side_by_side(*(configuration.RackScaleMetadata, configuration.RedfishMetadata))

            left_text_container = result.left_ext_file.getvalue().split('\n')
            right_text_container = result.right_ext_file.getvalue().split('\n')

            missing_elements_on_left = self._generate_statistics_from_text_container(left_text_container,
                                                                                     right_text_container)
            missing_elements_on_right = self._generate_statistics_from_text_container(right_text_container,
                                                                                      left_text_container)

            preformat_left = self._update_view_for_more_human_readable(left_text_container)
            preformat_right = self._update_view_for_more_human_readable(right_text_container)

            self._build_html_view(configuration,
                                  {'left': preformat_left,
                                   'right': preformat_right,
                                   'missing_left': missing_elements_on_left,
                                   'missing_right': missing_elements_on_right,
                                   'reports_details': reports_details})
            print "Report has been written to: {name}".format(name=report)
예제 #23
0
    def log_screen_message(self, message, message_level, message_datetime):
        if MessageLevel.DEBUG != message_level:
            try:
                color = {MessageLevel.ERROR: ColorPrinter.RED_FORE, MessageLevel.WARNING: ColorPrinter.YELLOW_FORE}[message_level]
            except KeyError:
                color = ColorPrinter.DEFAULT

            m = re.match(INDENT_RE, message)
            if m:
                shift = indent() + m.group('get_indent')
                msg = m.group('therest')

                multiline_log = to_multiline(str(msg), 140, '\n{indent}    '.format(indent=shift))

                print "%s%s" % (
                    shift,
                    ColorPrinter.format_text(multiline_log, color=color))
예제 #24
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(BuildInformation.BUILD_VERSION, bold=True))

        running_list = ConfigParser.ConfigParser()
        running_list.optionxform = str
        running_list.read(configuration.test_run_list)

        test_run = TestRun()

        for running_list_section in running_list.sections():
            self.process_running_list_section(running_list_section, running_list, test_run)

        test_run.register_all()

        execution_status = test_run.run_all()

        if not execution_status and configuration.return_tests_status_as_exit_code:
            print "Tests finished with status failed, exit code set to 4"
            exit(4)
예제 #25
0
    def run(self):
        api_explorer = ApiExplorer(self.metadata_container, self.configuration)
        discovery_container, status = api_explorer.discover(MetadataConstants.SERVICE_ROOT_URI,
                                                            MetadataConstants.SERVICE_ROOT)
        status = ValidationStatus.PASSED

        catalog = expanduser("~") + "/.cts/tests/Rack_Scale_2_5_PSME/required/tests_archeo_psme/"
        for test in listdir(catalog):
            with open(catalog + test) as f:
                data = json.load(f)
                test_name = data["name"]
                print "TEST_CASE::Validating section " + ColorPrinter.format_text(test_name,
                                                                                  color=ColorPrinter.YELLOW_FORE) + \
                      " of architecture specification"
                status_of_test = ArchSpecTests().parse_json(discovery_container, data)
                print "STATUS::{status}".format(status=status_of_test)
                status = ValidationStatus.join_statuses(status, status_of_test)
        print "MESSAGE::All tests finished"
        print "STATUS::{status}".format(status=status)
예제 #26
0
    def run(self):
        if self.metadata_container is None:
            return

        self.chosen_endpoint, self.chosen_zone, self.chosen_volume, self.chosen_volume_collection = (
            None, ) * 4
        self.initiator_endpoint, self.target_endpoint, self.zone_endpoint, self.created_volume = (
            None, ) * 4

        self.initiator_unique_name = self.generate_unique_names() if self.configuration.UniqueInitiatorName \
            != "generate" else self.configuration.UniqueInitiatorName
        self.target_unique_name = self.generate_unique_names() if self.configuration.UniqueTargetName \
            != "generate" else self.configuration.UniqueTargetName

        test_name = "Storage Services CRUD test with NVM Express (NVMe) Support"
        print "MESSAGE::%s starting" % test_name

        print "TEST_CASE::API crawling"
        api_explorer = ApiExplorer(self.metadata_container, self.configuration)
        self.discovery_container, status = api_explorer.discover(
            MetadataConstants.SERVICE_ROOT_URI, MetadataConstants.SERVICE_ROOT)
        print "STATUS::{status}".format(status=status)

        requirements = [
            Requirement(MetadataConstants.SERVICE_ROOT, min=1, max=1),
            Requirement(MetadataConstants.STORAGE_SERVICE, min=1),
            Requirement(MetadataConstants.VOLUME, min=1),
            Requirement(MetadataConstants.VOLUME_COLLECTION, min=1)
        ]
        preconditions = Preconditions(self.metadata_container, requirements)
        status = preconditions.validate(self.discovery_container)

        if status == ValidationStatus.FAILED:
            self.set_status_failed()
            return

        self.api_caller = ApiCaller(self.configuration)

        status = ValidationStatus.join_statuses(status, self.crud_nvme())

        print "MESSAGE::%s overall status: %s" % (
            test_name, ColorPrinter.format_status(status))
예제 #27
0
    def format_case_results(self, case_execution_id):
        case_execution_details = CaseDAO.get_case_execution_details(case_execution_id)
        results_header = "Test Case: {case_name}{vertical_separator}{vertical_separator}".format(
            case_name=case_execution_details.name,
            vertical_separator=VERTICAL_SEPARATOR)

        results_footer = "{vertical_separator}{horizontal_separator}[{status}]\t{case_name}{vertical_separator}".format(
            horizontal_separator=HORIZONTAL_SEPARATOR, case_name=case_execution_details.name,
            status=ColorPrinter.format_status(case_execution_details.status), vertical_separator=VERTICAL_SEPARATOR)

        yield VERTICAL_SEPARATOR
        yield results_header

        for messages in self.format_case_messages(case_execution_id):
            yield messages
            yield VERTICAL_SEPARATOR

        yield results_footer
        yield VERTICAL_SEPARATOR
        yield CASE_SEPARATOR
예제 #28
0
    def format_case_results(self, case_execution_id):
        case_execution_details = CaseDAO.get_case_execution_details(case_execution_id)
        results_header = "Test Case: {case_name}{vertical_separator}{vertical_separator}".format(
            case_name=case_execution_details.name,
            vertical_separator=VERTICAL_SEPARATOR)

        results_footer = "{vertical_separator}{horizontal_separator}[{status}]\t{case_name}{vertical_separator}".format(
            horizontal_separator=HORIZONTAL_SEPARATOR, case_name=case_execution_details.name,
            status=ColorPrinter.format_status(case_execution_details.status), vertical_separator=VERTICAL_SEPARATOR)

        yield VERTICAL_SEPARATOR
        yield results_header

        for messages in self.format_case_messages(case_execution_id):
            yield messages
            yield VERTICAL_SEPARATOR

        yield results_footer
        yield VERTICAL_SEPARATOR
        yield CASE_SEPARATOR
예제 #29
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(BuildInformation.BUILD_VERSION, bold=True))
        print "\nComparing...\n\n"

        with ErrorMute():
            report = self.report_name()
            with open(report, 'w') as sys.stdout:
                comparator = MetadataComparator(configuration.METADATA, configuration.qualifiers)
                result = comparator.run()
                if result is not None:
                    if result.result == Comparator.EQUAL:
                        msg = "\n\nMetadata sets {metadata} are equal\n\n".format(metadata=" and ".join(configuration.METADATA))
                        sys.stderr.write(msg)
                        sys.stdout.write(msg)
                    else:
                        msg = "\n\nMetadata sets {metadata} differ\n\n".format(metadata=" and ".join(configuration.METADATA))
                        sys.stderr.write(msg)
                        sys.stdout.write(msg)
                        print result.get_side_by_side(*configuration.METADATA)

            sys.stdout = sys.__stdout__
            print "Report has been written to: {name}".format(name=report)
예제 #30
0
 def process_application(self):
     ColorPrinter.init()
     DatabaseConnectionHandler.initialize_db_connection_handler()
     configuration = self.parser.parse_args()
     self.action_handlers[configuration.ACTION].process_action(
         configuration)
예제 #31
0
    def process_action(self, configuration):
        print "Using CTS in version %s\n" % (ColorPrinter.format_text(BuildInformation.BUILD_VERSION, bold=True))

        JsonLoader().print_available_actions()
예제 #32
0
    def process_action(self, configuration):
        print "Using CTS in version %s" % (ColorPrinter.format_text(
            BuildInformation.BUILD_VERSION, bold=True))
        tests_manager = TestsManager()

        configuration_files = configuration.config_files
        test_scripts_configuration = get_configuration_from_files(
            configuration_files)
        if test_scripts_configuration is None:
            sys.exit(-1)

        if not certificates_files_are_valid(test_scripts_configuration):
            sys.exit(-1)

        test_plan = TestsPackagesContainer()

        if configuration.test_suites or configuration.test_scripts:
            if configuration.test_suites:
                test_suites_found = tests_manager.get_packages()
                test_suites_found.filter(packages=configuration.package,
                                         suites=configuration.test_suites,
                                         remove_empty=True)
                test_plan += test_suites_found
            if configuration.test_scripts:
                test_scripts_found = tests_manager.get_packages()

                test_scripts_found.filter(packages=configuration.package,
                                          scripts=configuration.test_scripts,
                                          remove_empty=True)
                test_plan += test_scripts_found
        else:
            test_plan += tests_manager.get_packages()

        test_plan.filter(packages=configuration.package)

        if not test_plan.packages:
            print "No script selected to execute"
            exit(64)  # EX_USAGE = 64    command line usage error

        message = "Executing "
        print "Executing:"
        for package in test_plan.packages:
            for suite in package.suites:
                for script in suite.scripts:
                    print "\t* %s from suite %s from package %s" % (
                        script.name, suite.name, package.name)
                    message += "%s from suite %s from package %s, " % (
                        script.name, suite.name, package.name)

        self._logger.log_debug(message)

        if configuration.timeout is not None:
            message = "setting timeout execution to %s" % configuration.timeout[
                0]
            self._logger.log_debug(message)
            print "\n%s" % message
            test_plan.set_scripts_timeout(configuration.timeout[0])

        execution_feed = ExecutionFeed(test_plan, test_scripts_configuration)

        ExecuteTestScriptsAction.execute_configuration_group(
            execution_feed,
            test_status_as_exit_code=configuration.
            return_tests_status_as_exit_code)
예제 #33
0
    def process_action(self, configuration):
        print "Using CTS in version %s\n" % (ColorPrinter.format_text(
            BuildInformation.BUILD_VERSION, bold=True))

        JsonLoader().print_available_actions()
예제 #34
0
 def process_application(self):
     ColorPrinter.init()
     DatabaseConnectionHandler.initialize_db_connection_handler()
     configuration = self.parser.parse_args()
     self.action_handlers[configuration.ACTION].process_action(configuration)