Пример #1
0
def main():
    parser, args = cli()
    os_conf = Configuration(conf_file=args.config, conf_section=args.config_section, cli_args=args)
    build_conf = Configuration(conf_file=args.config, conf_section=args.config_section, cli_args=args)

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

    osbs = OSBS(os_conf, build_conf)

    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.")
        pass
    except HTTPError as ex:
        logger.error("HTTP error: %d", ex.getcode())
    except Exception as ex:
        if args.verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
Пример #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 is_verbose:
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    elif args.quiet:
        set_logging(level=logging.WARNING)
    else:
        set_logging(level=logging.INFO)

    osbs = OSBS(os_conf, build_conf)

    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 Exception as ex:  # pylint: disable=broad-except
        if is_verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
            return -1
Пример #3
0
def _process_global_args(args: dict) -> dict:
    """Process global arguments, return non-global arguments (task arguments)."""
    task_args = args.copy()

    verbose = task_args.pop("verbose")
    quiet = task_args.pop("quiet")
    # Note: the version argument is not stored by argparse (because it has the 'version' action)

    if verbose:
        atomic_reactor.set_logging(level=logging.DEBUG)
        osbs.set_logging(level=logging.DEBUG)
    elif quiet:
        atomic_reactor.set_logging(level=logging.WARNING)
        osbs.set_logging(level=logging.WARNING)
    else:
        atomic_reactor.set_logging(level=logging.INFO)
        osbs.set_logging(level=logging.INFO)

    return task_args
Пример #4
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
Пример #5
0
    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
Пример #6
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
Пример #7
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
Пример #8
0
"""
Copyright (c) 2015 Red Hat, Inc
All rights reserved.

This software may be modified and distributed under the terms
of the BSD license. See the LICENSE file for details.
"""
from __future__ import absolute_import

import logging
from osbs import set_logging
set_logging(name="osbs.tests", level=logging.DEBUG)
set_logging(name="osbs", level=logging.DEBUG)
Пример #9
0
"""
Copyright (c) 2015 Red Hat, Inc
All rights reserved.

This software may be modified and distributed under the terms
of the BSD license. See the LICENSE file for details.
"""
import logging
from osbs import set_logging
set_logging(name="osbs.tests", level=logging.DEBUG)
set_logging(name="osbs", level=logging.DEBUG)