Пример #1
0
        def cleanup():

            if not system_helper.is_storage_system():
                skip("This test requires a storage system")

            profiles_created = self._pop_cleanup_list('profile')
            old_new_types = self._pop_cleanup_list('local_storage_type')

            # Add hosts to module level recovery fixture in case of modify or unlock fail in following class level
            # recovery attempt.
            for item in old_new_types:
                HostsToRecover.add(item[0], scope='module')

            exceptions = []
            try:
                LOG.fixture_step("(class) Delete created storage profiles")
                while profiles_created:
                    storage_helper.delete_storage_profile(
                        profile=profiles_created.pop())

            except Exception as e:
                LOG.exception(e)
                exceptions.append(e)

            try:
                LOG.fixture_step(
                    "(class) Revert local storage backing for {}".format(
                        old_new_types))
                while old_new_types:
                    host_to_revert, old_type, _ = old_new_types.pop()
                    LOG.info("Revert {} local storage to {}".format(
                        host_to_revert, old_type))
                    host_helper.set_host_storage_backing(host=host_to_revert,
                                                         inst_backing=old_type,
                                                         unlock=True)

            except Exception as e:
                LOG.exception(e)
                exceptions.append(e)

            assert not exceptions, "Failure occurred. Errors: {}".format(
                exceptions)
Пример #2
0
def parse_config_file():
    """ Get defaults from the ini file
    """

    # set the name of the config file
    config = configparser.ConfigParser()
    config_file = os.path.join(LOCAL_PATH, 'config.ini')
    try:
        config_file = open(config_file, 'r')
        config.read_file(config_file)
    except Exception:
        msg = "Failed to read file: " + config_file
        LOG.exception(msg)

    info_dict = {}
    for section in config.sections():
        for opt in config.options(section):
            info_dict[opt] = config.get(section, opt)

    return info_dict
Пример #3
0
def pytest_unconfigure(config):
    # collect all if needed
    if config.getoption('help'):
        return

    try:
        natbox_ssh = ProjVar.get_var('NATBOX_SSH')
        natbox_ssh.close()
    except:
        pass

    version_and_patch = ''
    try:
        version_and_patch = setups.get_version_and_patch_info()
    except Exception as e:
        LOG.debug(e)
        pass
    log_dir = ProjVar.get_var('LOG_DIR')
    if not log_dir:
        try:
            from utils.clients.ssh import ControllerClient
            ssh_list = ControllerClient.get_active_controllers(fail_ok=True)
            for con_ssh_ in ssh_list:
                con_ssh_.close()
        except:
            pass
        return

    log_dir = ProjVar.get_var('LOG_DIR')
    if not log_dir:
        try:
            from utils.clients.ssh import ControllerClient
            ssh_list = ControllerClient.get_active_controllers(fail_ok=True)
            for con_ssh_ in ssh_list:
                con_ssh_.close()
        except:
            pass
        return

    try:
        tc_res_path = log_dir + '/test_results.log'
        build_info = ProjVar.get_var('BUILD_INFO')
        build_id = build_info.get('BUILD_ID', '')
        build_job = build_info.get('JOB', '')
        build_server = build_info.get('BUILD_HOST', '')
        system_config = ProjVar.get_var('SYS_TYPE')
        session_str = ''
        total_exec = TestRes.PASSNUM + TestRes.FAILNUM
        # pass_rate = fail_rate = '0'
        if total_exec > 0:
            pass_rate = "{}%".format(
                round(TestRes.PASSNUM * 100 / total_exec, 2))
            fail_rate = "{}%".format(
                round(TestRes.FAILNUM * 100 / total_exec, 2))
            with open(tc_res_path, mode='a') as f:
                # Append general info to result log
                f.write('\n\nLab: {}\n'
                        'Build ID: {}\n'
                        'Job: {}\n'
                        'Build Server: {}\n'
                        'System Type: {}\n'
                        'Automation LOGs DIR: {}\n'
                        'Ends at: {}\n'
                        '{}'  # test session id and tag
                        '{}'.format(ProjVar.get_var('LAB_NAME'), build_id,
                                    build_job, build_server, system_config,
                                    ProjVar.get_var('LOG_DIR'), tc_end_time,
                                    session_str, version_and_patch))
                # Add result summary to beginning of the file
                f.write(
                    '\nSummary:\nPassed: {} ({})\nFailed: {} ({})\nTotal '
                    'Executed: {}\n'.
                    format(TestRes.PASSNUM, pass_rate, TestRes.FAILNUM,
                           fail_rate, total_exec))
                if TestRes.SKIPNUM > 0:
                    f.write('------------\nSkipped: {}'.format(TestRes.SKIPNUM))

            LOG.info("Test Results saved to: {}".format(tc_res_path))
            with open(tc_res_path, 'r') as fin:
                print(fin.read())
    except Exception as e:
        LOG.exception(
            "Failed to add session summary to test_results.py. "
            "\nDetails: {}".format(e.__str__()))
    # Below needs con_ssh to be initialized
    try:
        from utils.clients.ssh import ControllerClient
        con_ssh = ControllerClient.get_active_controller()
    except:
        LOG.warning("No con_ssh found")
        return

    try:
        parse_log.parse_test_steps(ProjVar.get_var('LOG_DIR'))
    except Exception as e:
        LOG.warning(
            "Unable to parse test steps. \nDetails: {}".format(e.__str__()))

    if test_count > 0 and (ProjVar.get_var('ALWAYS_COLLECT') or (
            has_fail and ProjVar.get_var('COLLECT_ALL'))):
        # Collect tis logs if collect all required upon test(s) failure
        # Failure on collect all would not change the result of the last test
        # case.
        try:
            setups.collect_tis_logs(con_ssh)
        except Exception as e:
            LOG.warning("'collect all' failed. {}".format(e.__str__()))

    ssh_list = ControllerClient.get_active_controllers(fail_ok=True,
                                                       current_thread_only=True)
    for con_ssh_ in ssh_list:
        try:
            con_ssh_.close()
        except:
            pass