Exemple #1
0
def osbs_for_capture(tmpdir):
    kwargs = {
        'build_json_dir': 'inputs',
        'openshift_url': OPENSHIFT_URL,
        'namespace': TEST_OCP_NAMESPACE
    }

    with NamedTemporaryFile(mode="wt") as fp:
        config = dedent("""\
            [general]
            build_json_dir = {build_json_dir}

            [default]
            openshift_url = {openshift_url}
            use_auth = false
            namespace = {namespace}
            """)

        fp.write(config.format(**kwargs))
        fp.flush()
        dummy_config = Configuration(fp.name, conf_section='default')
        osbs = OSBS(dummy_config)

    setup_json_capture(osbs, osbs.os_conf, str(tmpdir))
    return osbs
Exemple #2
0
def main():
    parser, args = cli()
    try:
        os_conf = Configuration(conf_file=args.config,
                                conf_section=args.instance,
                                cli_args=args)
        build_conf = Configuration(conf_file=args.config,
                                   conf_section=args.instance,
                                   cli_args=args)
    except OsbsException as ex:
        logger.error("Configuration error: %s", ex.message)
        return -1

    is_verbose = os_conf.get_verbosity()

    if args.quiet:
        set_logging(level=logging.WARNING)
    elif is_verbose:
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    else:
        set_logging(level=logging.INFO)

    osbs = OSBS(os_conf, build_conf)

    if args.capture_dir is not None:
        setup_json_capture(osbs, os_conf, args.capture_dir)

    try:
        args.func(args, osbs)
    except AttributeError as ex:
        if hasattr(args, 'func'):
            raise
        else:
            parser.print_help()
    except KeyboardInterrupt:
        print("Quitting on user request.")
        return -1
    except OsbsNetworkException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Network error at %s (%d): %s", ex.url,
                         ex.status_code, ex.message)
            return -1
    except OsbsAuthException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Authentication failure: %s", ex.message)
            return -1
    except OsbsResponseException as ex:
        if is_verbose:
            raise
        else:
            if isinstance(ex.json, dict) and 'message' in ex.json:
                msg = ex.json['message']
            else:
                msg = ex.message
            logger.error("Server returned error %s: %s", ex.status_code, msg)
            return -1
    except Exception as ex:  # pylint: disable=broad-except
        if is_verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
            return -1
    def __init__(self):
        parser = argparse.ArgumentParser(
            description="osbs test harness mock JSON creator")

        parser.add_argument(
            "user",
            action='store',
            help="name of user to use for Basic Authentication in OSBS")
        parser.add_argument("--config",
                            action='store',
                            metavar="PATH",
                            help="path to configuration file",
                            default=DEFAULT_CONFIGURATION_FILE)
        parser.add_argument(
            "--instance",
            "-i",
            action='store',
            metavar="SECTION_NAME",
            help="section within config for requested instance",
            default="stage")
        parser.add_argument(
            "--password",
            action='store',
            help="password to use for Basic Authentication in OSBS")
        parser.add_argument("--mock-dir",
                            metavar="DIR",
                            action="store",
                            default=DEFAULT_DIR,
                            help="mock JSON responses are stored in DIR")
        parser.add_argument(
            "--imagestream",
            metavar="IMAGESTREAM",
            action="store",
            default=DEFAULT_IMAGESTREAM_FILE,
            help="Image name for image stream import. Defaults to " +
            DEFAULT_IMAGESTREAM_FILE)
        parser.add_argument(
            "--image_server",
            metavar="IMAGESERVER",
            action="store",
            default=DEFAULT_IMAGESTREAM_SERVER,
            help="Server for image stream import. Defaults to " +
            DEFAULT_IMAGESTREAM_SERVER)
        parser.add_argument(
            "--image_tags",
            metavar="IMAGETAGS",
            action="store",
            nargs=3,
            default=DEFAULT_IMAGESTREAM_TAGS,
            help="Image stream tags as 3 space separated values.")
        parser.add_argument("--os-version",
                            metavar="OS_VER",
                            action="store",
                            default=OS_VERSION,
                            help="OpenShift version of the mock JSONs")

        args = parser.parse_args()
        self.user = args.user
        self.password = args.password

        mock_path = args.mock_dir
        self.mock_dir = "/".join([mock_path, args.os_version])
        find_or_make_dir(self.mock_dir)

        self.capture_dir = tempfile.mkdtemp()

        args.git_url = "https://github.com/TomasTomecek/docker-hello-world.git"
        args.git_branch = "master"
        args.git_commit = "HEAD"

        os_conf = Configuration(conf_file=args.config,
                                conf_section=args.instance,
                                cli_args=args)
        build_conf = Configuration(conf_file=args.config,
                                   conf_section=args.instance,
                                   cli_args=args)

        set_logging(level=logging.INFO)

        self.osbs = OSBS(os_conf, build_conf)
        setup_json_capture(self.osbs, os_conf, self.capture_dir)

        self.imagestream_file = args.imagestream
        self.imagestream_server = args.image_server
        self.imagestream_tags = args.image_tags
        self.rh_pattern = re.template("redhat.com")
        self.ex_pattern = "(\S+\.)*redhat.com"  # noqa:W605
Exemple #4
0
def main():
    parser, args = cli()
    # OSBS2 TBD if we remove setup_json_capture, we can just create configuration without instance
    # as verbosity is read from general section
    # also we could even just read verbosity from args and create configurations only in
    # cmd functions
    try:
        if args.instance:
            os_conf = Configuration(conf_file=args.config,
                                    conf_section=args.instance,
                                    cli_args=args)
        else:
            os_conf = Configuration(conf_file=args.config, cli_args=args)
    except OsbsException as ex:
        logger.error("Configuration error: %s", ex.message)
        return -1

    is_verbose = os_conf.get_verbosity()

    if args.quiet:
        set_logging(level=logging.WARNING)
    elif is_verbose:
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    else:
        set_logging(level=logging.INFO)

    # required just for setup_json_capture, if we don't need it anymore we could just remove it
    # OSBS2 TBD
    osbs = OSBS(os_conf)

    if args.capture_dir is not None:
        setup_json_capture(osbs, os_conf, args.capture_dir)

    return_value = -1
    try:
        # OSBS2 TBD
        # this breaks all other commands which require 2nd osbs arg, which have to be cleaned,
        # also if we will still use some, like login/token, we would have to require
        # instance name, as we can't choose default since we have now 2 defaults
        # one for binary and another for source
        return_value = args.func(args)
    except AttributeError:
        if hasattr(args, 'func'):
            raise
        else:
            parser.print_help()
    except KeyboardInterrupt:
        print("Quitting on user request.")
        return -1
    except OsbsNetworkException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Network error at %s (%d): %s", ex.url,
                         ex.status_code, ex)
            return -1
    except OsbsAuthException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Authentication failure: %s", ex)
            return -1
    except OsbsResponseException as ex:
        if is_verbose:
            raise
        else:
            if isinstance(ex.json, dict) and 'message' in ex.json:
                msg = ex.json['message']
            else:
                msg = str(ex)
            logger.error("Server returned error %s: %s", ex.status_code, msg)
            return -1
    except Exception as ex:  # pylint: disable=broad-except
        if is_verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
            return -1
    return return_value
Exemple #5
0
def osbs_with_capture(osbs, tmpdir):
    setup_json_capture(osbs, osbs.os_conf, str(tmpdir))
    return osbs
Exemple #6
0
def main():
    parser, args = cli()
    try:
        os_conf = Configuration(conf_file=args.config,
                                conf_section=args.instance,
                                cli_args=args)
        build_conf = Configuration(conf_file=args.config,
                                   conf_section=args.instance,
                                   cli_args=args)
    except OsbsException as ex:
        logger.error("Configuration error: %s", ex.message)
        return -1

    is_verbose = os_conf.get_verbosity()

    if args.quiet:
        set_logging(level=logging.WARNING)
    elif is_verbose:
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    else:
        set_logging(level=logging.INFO)

    osbs = OSBS(os_conf, build_conf)

    if args.capture_dir is not None:
        setup_json_capture(osbs, os_conf, args.capture_dir)

    try:
        args.func(args, osbs)
    except AttributeError as ex:
        if hasattr(args, 'func'):
            raise
        else:
            parser.print_help()
    except KeyboardInterrupt:
        print("Quitting on user request.")
        return -1
    except OsbsNetworkException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Network error at %s (%d): %s",
                         ex.url, ex.status_code, ex.message)
            return -1
    except OsbsAuthException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Authentication failure: %s",
                         ex.message)
            return -1
    except OsbsResponseException as ex:
        if is_verbose:
            raise
        else:
            if isinstance(ex.json, dict) and 'message' in ex.json:
                msg = ex.json['message']
            else:
                msg = ex.message
            logger.error("Server returned error %s: %s", ex.status_code, msg)
            return -1
    except Exception as ex:  # pylint: disable=broad-except
        if is_verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
            return -1
def osbs_with_capture(osbs, tmpdir):
    setup_json_capture(osbs, osbs.os_conf, str(tmpdir))
    return osbs