def do_package_create(mc, args): """Create an application package.""" if args.template and args.classes_dir: raise exceptions.CommandError( "Provide --template for a HOT-based package, OR" " --classes-dir for a MuranoPL-based package") if not args.template and not args.classes_dir: raise exceptions.CommandError( "Provide --template for a HOT-based package, OR at least" " --classes-dir for a MuranoPL-based package") directory_path = None try: archive_name = args.output if args.output else None if args.template: directory_path = hot_package.prepare_package(args) if not archive_name: archive_name = os.path.basename(args.template) archive_name = os.path.splitext(archive_name)[0] + ".zip" else: directory_path = mpl_package.prepare_package(args) if not archive_name: archive_name = tempfile.mkstemp( prefix="murano_", dir=os.getcwd())[1] + ".zip" _make_archive(archive_name, directory_path) print("Application package is available at " + os.path.abspath(archive_name)) finally: if directory_path: shutil.rmtree(directory_path)
def do_package_create(mc, args): """Create an application package.""" if args.template and args.classes_dir: raise exceptions.CommandError( "Provide --template for a HOT-based package, OR" " --classes-dir for a MuranoPL-based package") if not args.template and not args.classes_dir: raise exceptions.CommandError( "Provide --template for a HOT-based package, OR at least" " --classes-dir for a MuranoPL-based package") directory_path = None try: archive_name = args.output if args.output else None if args.template: directory_path = hot_package.prepare_package(args) if not archive_name: archive_name = os.path.basename(args.template) archive_name = os.path.splitext(archive_name)[0] + ".zip" else: directory_path = mpl_package.prepare_package(args) if not archive_name: archive_name = tempfile.mkstemp(prefix="murano_", dir=os.getcwd())[1] + ".zip" _make_archive(archive_name, directory_path) print("Application package is available at " + os.path.abspath(archive_name)) finally: if directory_path: shutil.rmtree(directory_path)
def test_prepare_mpl_wrong_resources_dir(self): args = TestArgs() args.template = TEMPLATE args.classes_dir = CLASSES_DIR args.resources_dir = '/home/this/path/does/not/exist' args.type = 'Application' args.name = 'Test' args.tags = '' args.ui = UI args.logo = LOGO args.full_name = 'test.full.name.TestName' args.author = 'TestAuthor' args.description = 'Test description' expected = ("'--resources-dir' parameter should be a directory", ) try: mpl_package.prepare_package(args) except exceptions.CommandError as message: self.assertEqual(expected, message.args)
def prepare_mpl_package(): from muranoclient.v1.package_creator import mpl_package import os #FIXTURE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), # 'static-assets')) FIXTURE_DIR = "/home/unameit/Downloads/deployPortal/static-assets/murano_packages" TEMPLATE = os.path.join(FIXTURE_DIR, 'heat-template.yaml') CLASSES_DIR = os.path.join(FIXTURE_DIR, 'test-app', 'Classes') RESOURCES_DIR = os.path.join(FIXTURE_DIR, 'test-app', 'Resources') UI = os.path.join(FIXTURE_DIR, 'test-app', 'ui.yaml') LOGO = os.path.join(FIXTURE_DIR, 'logo.png') args = InitArgs() args.template = TEMPLATE args.classes_dir = CLASSES_DIR args.resources_dir = RESOURCES_DIR args.type = 'Application' args.name = 'ApacheMySql' args.author = 'TestAuthor' args.full_name = 'io.murano.apps.imanage.ApacheMySql' #args.tags = "[HTTP, Server, WebServer, HTML, Apache,Database, MySql, SQL, RDBMS]" args.tags = ["HTTP", "Server", "WebServer", "Apache","Database", "MySql", "SQL", "RDBMS"] args.description = 'Test description' args.ui = UI args.logo = LOGO args.require = 'io.murano.databases' #prepared_files = ['UI', 'Classes', 'manifest.yaml', # 'Resources', 'logo.png'] package_dir = mpl_package.prepare_package(args) ZIP_DIR = "/home/unameit/Downloads/deployPortal/static-assets/murano_packages" zip_files(package_dir,ZIP_DIR+"/zip/"+args.full_name) print package_dir
def test_prepare_mpl_package(self): args = TestArgs() args.template = TEMPLATE args.classes_dir = CLASSES_DIR args.resources_dir = RESOURCES_DIR args.type = 'Application' args.name = 'test_name' args.author = 'TestAuthor' args.full_name = 'test.full.name.TestName' args.tags = 'test, tag, Heat' args.description = 'Test description' args.ui = UI args.logo = LOGO prepared_files = ['UI', 'Classes', 'manifest.yaml', 'Resources', 'logo.png'] package_dir = mpl_package.prepare_package(args) self.assertEqual(sorted(os.listdir(package_dir)), sorted(prepared_files)) shutil.rmtree(package_dir)
def test_prepare_mpl_package(self): args = TestArgs() args.template = TEMPLATE args.classes_dir = CLASSES_DIR args.resources_dir = RESOURCES_DIR args.type = 'Application' args.name = 'test_name' args.author = 'TestAuthor' args.full_name = 'test.full.name.TestName' args.tags = 'test, tag, Heat' args.description = 'Test description' args.ui = UI args.logo = LOGO prepared_files = ['UI', 'Classes', 'manifest.yaml', 'Resources', 'logo.png'] package_dir = mpl_package.prepare_package(args) self.assertEqual(sorted(prepared_files), sorted(os.listdir(package_dir))) shutil.rmtree(package_dir)
def take_action(self, parsed_args): LOG.debug("take_action({0})".format(parsed_args)) parsed_args.os_username = os.getenv('OS_USERNAME') def _make_archive(archive_name, path): zip_file = zipfile.ZipFile(archive_name, 'w') for root, dirs, files in os.walk(path): for f in files: zip_file.write(os.path.join(root, f), arcname=os.path.join( os.path.relpath(root, path), f)) if parsed_args.template and parsed_args.classes_dir: raise exc.CommandError( "Provide --template for a HOT-based package, OR" " --classes-dir for a MuranoPL-based package") if not parsed_args.template and not parsed_args.classes_dir: raise exc.CommandError( "Provide --template for a HOT-based package, OR at least" " --classes-dir for a MuranoPL-based package") directory_path = None try: archive_name = parsed_args.output if parsed_args.output else None if parsed_args.template: directory_path = hot_package.prepare_package(parsed_args) if not archive_name: archive_name = os.path.basename(parsed_args.template) archive_name = os.path.splitext(archive_name)[0] + ".zip" else: directory_path = mpl_package.prepare_package(parsed_args) if not archive_name: archive_name = tempfile.mkstemp( prefix="murano_", dir=os.getcwd())[1] + ".zip" _make_archive(archive_name, directory_path) print("Application package is available at " + os.path.abspath(archive_name)) finally: if directory_path: shutil.rmtree(directory_path)