class OrloLiveServerTest(LiveServerTestCase):
    """
    Test the Orlo client against the Orlo server

    This is testing integration with the Orlo server, for tests that limit the scope to
    the client code see test_orloclient.py
    """

    def create_app(self):
        app = orlo.app
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
        app.config['TESTING'] = True
        app.config['TRAP_HTTP_EXCEPTIONS'] = True
        app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
        app.config['LIVESERVER_PORT'] = 7767
        # app.config['DEBUG'] = True

        orlo.orm.db.create_all()

        return orlo.app

    def setUp(self):
        self.orlo_client = OrloClient(
            uri='http://localhost:7767'
        )

    def tearDown(self):
        orlo.orm.db.session.remove()
        orlo.orm.db.drop_all()

    def _create_release(self):
        return self.orlo_client.create_release('testuser', ['testplatform'])

    def _create_package(self, release):
        return self.orlo_client.create_package(release, 'package_one', '1.2.3')

    def _package_start(self, package):
        return self.orlo_client.package_start(package)

    def _package_stop(self, package, success=True):
        return self.orlo_client.package_stop(package, success)

    def _release_stop(self, release):
        return self.orlo_client.release_stop(release)
class OrloLiveServerTest(LiveServerTestCase):
    """
    Test the Orlo client against the Orlo server

    This is testing integration with the Orlo server, for tests that limit the scope to
    the client code see test_orloclient.py
    """

    def create_app(self):
        app = orlo.app
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
        app.config['TESTING'] = True
        app.config['TRAP_HTTP_EXCEPTIONS'] = True
        app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
        app.config['LIVESERVER_PORT'] = 7767
        # app.config['DEBUG'] = True

        orlo.orm.db.create_all()

        return orlo.app

    def setUp(self):
        self.orlo_client = OrloClient(
            uri='http://localhost:7767'
        )

    def tearDown(self):
        orlo.orm.db.session.remove()
        orlo.orm.db.drop_all()

    def _create_release(self):
        return self.orlo_client.create_release('testuser', ['testplatform'])

    def _create_package(self, release):
        return self.orlo_client.create_package(release, 'package_one', '1.2.3')

    def _package_start(self, package):
        return self.orlo_client.package_start(package)

    def _package_stop(self, package, success=True):
        return self.orlo_client.package_stop(package, success)

    def _release_stop(self, release):
        return self.orlo_client.release_stop(release)
 def setUp(self):
     self.orlo_client = OrloClient(
         uri='http://localhost:7767'
     )
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--version', '-v', action='version',
                        version='%(prog)s {}'.format(__version__))
    parser.add_argument('--uri', '-u', dest='uri',
                        default=config.get('client', 'uri'),
                        help="Address of orlo server")
    parser.add_argument('--debug', '-d', help='Enable debug logging',
                        action='store_true')
    parser.add_argument(
        '--insecure', '-I', action='store_true',
        default=False if config.getboolean('client', 'verify_ssl') else True,
        help='Do not verify SSL/TLS connections')

    subparsers = parser.add_subparsers(dest='object')
    pp_package = argparse.ArgumentParser(add_help=False)
    pp_package.add_argument(
        'package', help='ID of the package to operate on',
    )

    pp_release = argparse.ArgumentParser(add_help=False)
    pp_release.add_argument(
        'release', help='ID of the release to operate on',
    )

    pp_create_release = argparse.ArgumentParser(add_help=False)
    pp_create_release.add_argument(
        '-p', '--platform', help='Platforms field value', nargs='+',
        dest='platforms', required=True,
    )
    pp_create_release.add_argument(
        '-u', '--user', help='Username field value', required=True,
    )
    pp_create_release.add_argument(
        '-t', '--team', help='Team field value', required=False
    )
    pp_create_release.add_argument(
        '-r', '--references', help='References field value', nargs='+',
    )
    pp_create_release.add_argument(
        '-n', '--note', help='Note field value',
    )

    pp_list = argparse.ArgumentParser(add_help=False)
    pp_list.add_argument(
        'filter', nargs='*',
        help="Filters in the form parameter=value. See "
             "http://orlo.readthedocs.io/en/latest/rest.html#get--releases "
             "for valid parameters"
    )
    pp_list.add_argument(
        '-p', '--packages', action='store_true',
        help="By default we list releases, this switches to listing "
             "packages instead"
    )
    pp_list.add_argument(
        '-i', '--id-only', action='store_true',
       help="Only print id values, not full release json"
    )

    pp_info = argparse.ArgumentParser(add_help=False)
    pp_info.add_argument('field', help='Field to report on',
                         choices=('users', 'teams', 'packages', 'platforms'))
    pp_info.add_argument('--name', help='The subject or field entry, e.g if '
                                        'field is user, name could be "alex"')
    pp_info.add_argument('--platform', help='Platform to filter on.')

    pp_stats = argparse.ArgumentParser(add_help=False)
    pp_stats.add_argument('--field', help='Field to report on',
                          choices=('user', 'team', 'package', 'platform'))
    pp_stats.add_argument('--name', help='The subject or field entry, e.g if '
                                         'field is user, name could be "alex"')
    pp_stats.add_argument('--platform', help='Platform to filter on.')
    pp_stats.add_argument('--time-before', metavar='TIME',
                          help='Filter by releases started before this time')
    pp_stats.add_argument('--time-after', metavar='TIME',
                          help='Filter by releases started after this time'
                          '(both time-before and time-after filter on the '
                          '"stime" [start time] field).')


    pp_versions = argparse.ArgumentParser(add_help=False)
    pp_versions.add_argument('--platform', help='Platform to filter on')

    pp_create_package = argparse.ArgumentParser(add_help=False)
    pp_create_package.add_argument('name', help='Package name')
    pp_create_package.add_argument('version', help='Package version')

    subparsers.add_parser(
        'create-release', help='Create a release',
        parents=[pp_create_release]
    ).set_defaults(func=action_create_release)
    subparsers.add_parser(
        'create-package', help='Create a package',
        parents=[pp_release, pp_create_package]
    ).set_defaults(func=action_create_package)
    subparsers.add_parser(
        'get-release', help='Fetch a release by ID',
        parents=[pp_release]
    ).set_defaults(func=action_get_release)
    subparsers.add_parser(
        'get-package', help='Fetch a package by id',
        parents=[pp_package]
    ).set_defaults(func=action_get_package)
    subparsers.add_parser(
        'start', help='Start a package',
        parents=[pp_package]
    ).set_defaults(func=action_start)
    subparsers.add_parser(
        'stop', help='Stop a package',
        parents=[pp_package]
    ).set_defaults(func=action_stop)
    subparsers.add_parser(
        'list', help='List releases, filters optional',
        parents=[pp_list]
    ).set_defaults(func=action_list)
    subparsers.add_parser(
        'stats', help='Fetch release stats',
        parents=[pp_stats]
    ).set_defaults(func=action_stats)
    subparsers.add_parser(
        'info', help='Fetch release info',
        parents=[pp_info]
    ).set_defaults(func=action_info)
    subparsers.add_parser(
        'versions', help='Fetch current package versions',
        parents=[pp_versions]
    ).set_defaults(func=action_versions)

    args = parser.parse_args()
    if args.debug:
        logger.setLevel(logging.DEBUG)
    logger.debug(args)

    client = OrloClient(
        uri=args.uri,
        verify_ssl=False if args.insecure else True,
    )
    args.func(client, args)
 def setUp(self):
     self.orlo_client = OrloClient(
         uri='http://localhost:7767'
     )
Exemplo n.º 6
0
if __name__ == "__main__":
    if os.getenv('ORLO_URL'):
        orlo_url = os.environ['ORLO_URL']
    else:
        # This deployer is only every supposed to accept releases from Orlo
        # Other deployers could use this to detect whether they are being invoked by Orlo
        raise DeployerError("Could not detect ORLO_URL from environment")

    if os.getenv('ORLO_RELEASE'):
        orlo_release = os.environ['ORLO_RELEASE']
    else:
        raise DeployerError("Could not detect ORLO_RELEASE in environment")

    packages, metadata = get_params()

    orlo_client = OrloClient(uri=orlo_url)
    # The release is created in Orlo before being handed to the deployer
    # So fetch it here
    release = orlo_client.get_release(orlo_release)

    # TODO - using package info from arguments makes no sense when we could fetch from Orlo
    orlo_packages = []
    for p, v in packages.items():
        info("Creating Package {}:{}".format(p, v))
        pkg = orlo_client.create_package(release, p, v)
        orlo_packages.append(pkg)

    info("Starting Release")
    for pkg in orlo_packages:
        info("Deploying {}".format(pkg.name))
        deploy(pkg, meta=metadata)
Exemplo n.º 7
0
 def setUp(self):
     self.orlo = OrloClient(self.URI)