Example #1
0
def normalize_collect_args(args):
    """Normalize COLLECT arguments.

    @param args: parsed args
    @return_value: updated args, or None if errors occurred
    """
    # platform should default to all supported
    if len(args.platform) == 0:
        args.platform = config.ENABLED_PLATFORMS
    args.platform = util.sorted_unique(args.platform)

    # os name should default to all enabled
    # if os name is provided ensure that all provided are supported
    if len(args.os_name) == 0:
        args.os_name = config.ENABLED_DISTROS
    else:
        supported = config.ENABLED_DISTROS
        invalid = [
            os_name for os_name in args.os_name if os_name not in supported
        ]
        if len(invalid) != 0:
            LOG.error('invalid os name(s): %s', invalid)
            return None
    args.os_name = util.sorted_unique(args.os_name)

    # test configs should default to all enabled
    # if test configs are provided, ensure that all provided are valid
    if len(args.test_config) == 0:
        args.test_config = config.list_test_configs()
    else:
        valid = []
        invalid = []
        for name in args.test_config:
            if os.path.exists(name):
                valid.append(name)
            elif os.path.exists(config.name_to_path(name)):
                valid.append(config.name_to_path(name))
            else:
                invalid.append(name)
        if len(invalid) != 0:
            LOG.error('invalid test config(s): %s', invalid)
            return None
        else:
            args.test_config = valid
    args.test_config = util.sorted_unique(args.test_config)

    # parse feature flag overrides and ensure all are valid
    if args.feature_override:
        overrides = args.feature_override
        args.feature_override = util.parse_conf_list(
            overrides, boolean=True, valid=config.list_feature_flags())
        if not args.feature_override:
            LOG.error('invalid feature flag override(s): %s', overrides)
            return None
    else:
        args.feature_override = {}

    return args
Example #2
0
def normalize_collect_args(args):
    """Normalize COLLECT arguments.

    @param args: parsed args
    @return_value: updated args, or None if errors occurred
    """
    # platform should default to lxd
    if len(args.platform) == 0:
        args.platform = ['lxd']
    args.platform = util.sorted_unique(args.platform)

    # os name should default to all enabled
    # if os name is provided ensure that all provided are supported
    if len(args.os_name) == 0:
        args.os_name = config.ENABLED_DISTROS
    else:
        supported = config.ENABLED_DISTROS
        invalid = [os_name for os_name in args.os_name
                   if os_name not in supported]
        if len(invalid) != 0:
            LOG.error('invalid os name(s): %s', invalid)
            return None
    args.os_name = util.sorted_unique(args.os_name)

    # test configs should default to all enabled
    # if test configs are provided, ensure that all provided are valid
    if len(args.test_config) == 0:
        args.test_config = config.list_test_configs()
    else:
        valid = []
        invalid = []
        for name in args.test_config:
            if os.path.exists(name):
                valid.append(name)
            elif os.path.exists(config.name_to_path(name)):
                valid.append(config.name_to_path(name))
            else:
                invalid.append(name)
        if len(invalid) != 0:
            LOG.error('invalid test config(s): %s', invalid)
            return None
        else:
            args.test_config = valid
    args.test_config = util.sorted_unique(args.test_config)

    # parse feature flag overrides and ensure all are valid
    if args.feature_override:
        overrides = args.feature_override
        args.feature_override = util.parse_conf_list(
            overrides, boolean=True, valid=config.list_feature_flags())
        if not args.feature_override:
            LOG.error('invalid feature flag override(s): %s', overrides)
            return None
    else:
        args.feature_override = {}

    return args
Example #3
0
def normalize_create_args(args):
    """Normalize CREATE arguments.

    @param args: parsed args
    @return_value: updated args, or None if errors occurred
    """
    # ensure valid name for new test
    if len(args.name.split('/')) != 2:
        LOG.error('invalid test name: %s', args.name)
        return None
    if os.path.exists(config.name_to_path(args.name)):
        msg = 'test: {} already exists'.format(args.name)
        if args.force:
            LOG.warning('%s but ignoring due to --force', msg)
        else:
            LOG.error(msg)
            return None

    # ensure test config valid if specified
    if isinstance(args.config, str) and len(args.config) == 0:
        LOG.error('test config cannot be empty if specified')
        return None

    # ensure description valid if specified
    if (isinstance(args.description, str)
            and (len(args.description) > 70 or len(args.description) == 0)):
        LOG.error('test description must be between 1 and 70 characters')
        return None

    return args
Example #4
0
def normalize_create_args(args):
    """Normalize CREATE arguments.

    @param args: parsed args
    @return_value: updated args, or None if errors occurred
    """
    # ensure valid name for new test
    if len(args.name.split('/')) != 2:
        LOG.error('invalid test name: %s', args.name)
        return None
    if os.path.exists(config.name_to_path(args.name)):
        msg = 'test: {} already exists'.format(args.name)
        if args.force:
            LOG.warning('%s but ignoring due to --force', msg)
        else:
            LOG.error(msg)
            return None

    # ensure test config valid if specified
    if isinstance(args.config, str) and len(args.config) == 0:
        LOG.error('test config cannot be empty if specified')
        return None

    # ensure description valid if specified
    if (isinstance(args.description, str) and
            (len(args.description) > 70 or len(args.description) == 0)):
        LOG.error('test description must be between 1 and 70 characters')
        return None

    return args
Example #5
0
def normalize_collect_args(args):
    """
    normalize COLLECT arguments
    args: parsed args
    return_value: updated args, or None if errors occurred
    """
    # platform should default to all supported
    if len(args.platform) == 0:
        args.platform = config.list_enabled_platforms()
    args.platform = util.sorted_unique(args.platform)

    # os name should default to all enabled
    # if os name is provided ensure that all provided are supported
    if len(args.os_name) == 0:
        args.os_name = config.list_enabled_distros()
    else:
        supported = config.list_enabled_distros()
        invalid = [
            os_name for os_name in args.os_name if os_name not in supported
        ]
        if len(invalid) != 0:
            LOG.error('invalid os name(s): %s', invalid)
            return None
    args.os_name = util.sorted_unique(args.os_name)

    # test configs should default to all enabled
    # if test configs are provided, ensure that all provided are valid
    if len(args.test_config) == 0:
        args.test_config = config.list_test_configs()
    else:
        valid = []
        invalid = []
        for name in args.test_config:
            if os.path.exists(name):
                valid.append(name)
            elif os.path.exists(config.name_to_path(name)):
                valid.append(config.name_to_path(name))
            else:
                invalid.append(name)
        if len(invalid) != 0:
            LOG.error('invalid test config(s): %s', invalid)
            return None
        else:
            args.test_config = valid
    args.test_config = util.sorted_unique(args.test_config)

    return args
Example #6
0
def create(args):
    """Create a new testcase."""
    (test_category, test_name) = args.name.split('/')
    fmt_args = {'test_name': test_name, 'test_category': test_category,
                'test_description': str(args.description)}

    testcase_file = config.name_to_path(args.name)
    verifier_file = os.path.join(
        TESTCASES_DIR, test_category,
        config.name_sanitize(test_name) + VERIFY_EXT)

    write_testcase_config(args, fmt_args, testcase_file)
    write_verifier(args, fmt_args, verifier_file)

    return 0
Example #7
0
def create(args):
    """
    create a new testcase
    """
    (test_category, test_name) = args.name.split('/')
    fmt_args = {'test_name': test_name, 'test_category': test_category,
                'test_description': str(args.description)}

    testcase_file = config.name_to_path(args.name)
    verifier_file = os.path.join(
        TESTCASES_DIR, test_category,
        config.name_sanatize(test_name) + VERIFY_EXT)

    write_testcase_config(args, fmt_args, testcase_file)
    write_verifier(args, fmt_args, verifier_file)

    return 0