github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/acceptancetests/assess_bundle_export.py (about) 1 #!/usr/bin/env python 2 """ Test Export Bundle functionality. 3 4 - Exporting current model configuration feature is verified. 5 - Deploy mediawikisimple bundle. 6 - verify if the bundle is created and the content of the file as well by deploying to another model. 7 """ 8 9 from __future__ import print_function 10 11 import argparse 12 import logging 13 import sys 14 import os 15 import filecmp 16 17 from deploy_stack import ( 18 BootstrapManager, 19 ) 20 from jujucharm import local_charm_path 21 from utility import ( 22 add_basic_testing_arguments, 23 configure_logging, 24 JujuAssertionError, 25 add_model 26 ) 27 28 __metaclass__ = type 29 export_one = "bundleone.yaml" 30 export_two = "bundletwo.yaml" 31 32 log = logging.getLogger("assess_bundle_export") 33 34 def assess_bundle_export(client, args): 35 bundle_source = local_charm_path('mediawiki-simple.yaml', 36 repository=os.environ['JUJU_REPOSITORY'], 37 juju_ver='2') 38 log.info("Deploying {}".format("mediawiki-simple bundle...")) 39 client.deploy(bundle_source) 40 client.wait_for_started() 41 42 log.info("Exporting bundle to {}".format(export_one)) 43 client.juju('export-bundle', ('--filename', export_one)) 44 45 if not os.path.exists(export_one): 46 raise JujuAssertionError('export bundle command failed to create bundle file.') 47 48 new_client = add_model(client) 49 log.info("Deploying bundle {} to new model".format(export_one)) 50 new_client.deploy(export_one) 51 new_client.wait_for_started() 52 log.info("Exporting bundle to {}".format(export_two)) 53 new_client.juju('export-bundle', ('--filename', export_two)) 54 55 #compare the contents of the file. 56 log.info("Comparing {} to {}".format(export_one, export_two)) 57 if not filecmp.cmp(export_one, export_two): 58 raise JujuAssertionError('bundle files created mismatch error.') 59 60 os.remove(export_one) 61 os.remove(export_two) 62 63 def parse_args(argv): 64 """Parse all arguments.""" 65 parser = argparse.ArgumentParser(description="Test the export-bundle functionality.") 66 add_basic_testing_arguments(parser) 67 parser.add_argument('--filename', help='file to write the model configuration') 68 return parser.parse_args(argv) 69 70 71 def main(argv=None): 72 args = parse_args(argv) 73 configure_logging(args.verbose) 74 bs_manager = BootstrapManager.from_args(args) 75 with bs_manager.booted_context(args.upload_tools): 76 assess_bundle_export(bs_manager.client, args) 77 return 0 78 79 80 if __name__ == '__main__': 81 sys.exit(main())