Files
zaza-openstack-tests/zaza/charm_lifecycle/deploy.py
Liam Young cb5d9caf66 Misc fixes to functional testing code
* Add calls to asyncio.get_event_loop().close() to close loop. libjuju does
  not do this for you and needs to be done just before exiting.
* Require model to be explicitly set when running command line tools. This is
  part of the drive to ensure that eventually multiple runs can be performed
  concurrently.
* Add set_juju_model/get_juju_model functions to manage which model is in
  focus
2018-03-28 11:48:53 +00:00

64 lines
1.8 KiB
Python
Executable File

import argparse
import logging
import subprocess
import sys
import juju_wait
def deploy_bundle(bundle, model):
"""Deploy the given bundle file in the specified model
:param bundle: Path to bundle file
:type bundle: str
:param model: Name of model to deploy bundle in
:type model: str
"""
logging.info("Deploying bundle {}".format(bundle))
subprocess.check_call(['juju', 'deploy', '-m', model, bundle])
def deploy(bundle, model, wait=True):
"""Run all steps to complete deployment
:param bundle: Path to bundle file
:type bundle: str
:param model: Name of model to deploy bundle in
:type model: str
:param wait: Whether to wait until deployment completes
:type model: bool
"""
deploy_bundle(bundle, model)
if wait:
logging.info("Waiting for environment to settle")
juju_wait.wait()
def parse_args(args):
"""Parse command line arguments
:param args: List of configure functions functions
:type list: [str1, str2,...] List of command line arguments
:returns: Parsed arguments
:rtype: Namespace
"""
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--model',
help='Model to deploy to',
required=True)
parser.add_argument('-b', '--bundle',
help='Bundle name (excluding file ext)',
required=True)
parser.add_argument('--no-wait', dest='wait',
help='Do not wait for deployment to settle',
action='store_false')
parser.set_defaults(wait=True)
return parser.parse_args(args)
def main():
"""Deploy bundle"""
logging.basicConfig(level=logging.INFO)
args = parse_args(sys.argv[1:])
deploy(args.bundle, args.model, wait=args.wait)