def _main()

in appengine/integration_tests/testsuite/driver.py [0:0]


def _main():
    logging.getLogger().setLevel(logging.INFO)

    parser = argparse.ArgumentParser()
    parser.add_argument('--image', '-i',
                        help='Newly-constructed base ' +
                        'image to build sample app on')
    parser.add_argument('--directory', '-d',
                        help='Root directory of sample app')
    parser.add_argument('--skip-standard-logging-tests',
                        action='store_false',
                        dest='standard_logging',
                        help='Flag to skip standard logging tests')
    parser.add_argument('--skip-custom-logging-tests',
                        action='store_false',
                        dest='custom_logging',
                        help='Flag to skip custom logging tests')
    parser.add_argument('--skip-monitoring-tests',
                        action='store_false',
                        dest='monitoring',
                        help='Flag to skip monitoring tests')
    parser.add_argument('--skip-exception-tests',
                        action='store_false',
                        dest='exception',
                        help='Flag to skip error reporting tests')
    parser.add_argument('--skip-custom-tests',
                        action='store_false',
                        dest='custom',
                        help='Flag to skip custom integration tests')
    parser.add_argument('--url', '-u',
                        help='URL where deployed app is ' +
                        'exposed (if applicable)')
    parser.add_argument('--verbose', '-v', action='store_true')
    parser.add_argument('--builder', '-b',
                        help='builder file to template')
    parser.add_argument('--yaml', '-y',
                        help='optional path to app.yaml file',
                        required=False)
    parser.add_argument('--environment', '-e',
                        help='environment to deploy sample application '
                        '(GAE, GKE)',
                        required=False,
                        choices=constants.ENVS,
                        default=constants.GAE)
    args = parser.parse_args()

    if args.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    application_url = ''

    if not args.url:
        if args.image is None and args.builder is None:
            logging.error('Please specify base image or builder image name.')
            sys.exit(1)

        if args.directory is None:
            logging.error('Please specify at least one application to deploy.')
            sys.exit(1)

        logging.debug('Deploying app to %s', args.environment)
        try:
            (version_or_namespace,
             url) = deploy_app.deploy_app(appdir=args.directory,
                                          environment=args.environment,
                                          base_image=args.image,
                                          builder_image=args.builder,
                                          yaml=args.yaml)
        except Exception as e:
            logging.error('Application not successfully deployed: %s', e)
            sys.exit(1)

    application_url = args.url or url

    code = _test_app(application_url, args)

    if not args.url:
        if args.environment == constants.GAE:
            deploy_app.stop_version(version_or_namespace)
        elif args.environment == constants.GKE:
            deploy_app.stop_deployment(version_or_namespace)

    return code