def test_pack_dir(self, mock_zip_file, mock_walk): mock_walk.side_effect = [ [("foo_root", [], ["file1", "file2", "file3"])]] fileutils.pack_dir("rally-jobs/extra/murano/HelloReporter", "fake_dir/package.zip") mock_zip_file.assert_called_once_with("fake_dir/package.zip", mode="w") mock_walk.assert_called_once_with( "rally-jobs/extra/murano/HelloReporter") mock_zip_file.return_value.assert_has_calls( [mock.call.write("foo_root/file1", "../../../../foo_root/file1"), mock.call.write("foo_root/file2", "../../../../foo_root/file2"), mock.call.write("foo_root/file3", "../../../../foo_root/file3"), mock.call.close()])
def setup(self): is_config_app_dir = False pckg_path = os.path.expanduser(self.config["app_package"]) if zipfile.is_zipfile(pckg_path): zip_name = pckg_path elif os.path.isdir(pckg_path): is_config_app_dir = True zip_name = fileutils.pack_dir(pckg_path) else: msg = (_LE("There is no zip archive or directory by this path:" " %s") % pckg_path) raise exceptions.ContextSetupFailure(msg=msg, ctx_name=self.get_name()) for user, tenant_id in utils.iterate_per_tenants( self.context["users"]): clients = osclients.Clients(user["endpoint"]) self.context["tenants"][tenant_id]["packages"] = [] if is_config_app_dir: self.context["tenants"][tenant_id]["murano_ctx"] = zip_name package = clients.murano().packages.create( { "categories": ["Web"], "tags": ["tag"] }, {"file": open(zip_name)}) self.context["tenants"][tenant_id]["packages"].append(package)
def _prepare_package(self, package_path): """Check whether the package path is path to zip archive or not. If package_path is not a path to zip archive but path to Murano application folder, than method prepares zip archive with Murano application. It copies directory with Murano app files to temporary folder, changes manifest.yaml and class file (to avoid '409 Conflict' errors in Murano) and prepares zip package. :param package_path: path to zip archive or directory with package components :returns: path to zip archive with Murano application """ if not zipfile.is_zipfile(package_path): tmp_dir = tempfile.mkdtemp() pkg_dir = os.path.join(tmp_dir, "package/") try: shutil.copytree(os.path.expanduser(package_path), pkg_dir) self._change_app_fullname(pkg_dir) package_path = fileutils.pack_dir(pkg_dir) finally: shutil.rmtree(tmp_dir) return package_path
def _prepare_package(self, package_path): """Check whether the package path is path to zip archive or not. If package_path is not a path to zip archive but path to Murano application folder, than method prepares zip archive with Murano application. It copies directory with Murano app files to temporary folder, changes manifest.yaml and class file (to avoid '409 Conflict' errors in Murano) and prepares zip package. :param package_path: path to zip archive or directory with package components :returns: path to zip archive with Murano application """ if not zipfile.is_zipfile(package_path): tmp_dir = tempfile.mkdtemp() pkg_dir = os.path.join(tmp_dir, "package/") try: shutil.copytree(package_path, pkg_dir) self._change_app_fullname(pkg_dir) package_path = fileutils.pack_dir(pkg_dir) finally: shutil.rmtree(tmp_dir) return package_path
def setup(self): is_config_app_dir = False pckg_path = os.path.expanduser(self.config["app_package"]) if zipfile.is_zipfile(pckg_path): zip_name = pckg_path elif os.path.isdir(pckg_path): is_config_app_dir = True zip_name = fileutils.pack_dir(pckg_path) else: msg = "There is no zip archive or directory by this path: %s" raise exceptions.ContextSetupFailure(msg=msg % pckg_path, ctx_name=self.get_name()) for user, tenant_id in utils.iterate_per_tenants( self.context["users"]): clients = osclients.Clients(user["credential"]) self.context["tenants"][tenant_id]["packages"] = [] if is_config_app_dir: self.context["tenants"][tenant_id]["murano_ctx"] = zip_name # TODO(astudenov): use self.generate_random_name() package = clients.murano().packages.create( {"categories": ["Web"], "tags": ["tag"]}, {"file": open(zip_name)}) self.context["tenants"][tenant_id]["packages"].append(package)
def setup(self): is_config_app_dir = False if zipfile.is_zipfile(self.config["app_package"]): zip_name = self.config["app_package"] elif os.path.isdir(self.config["app_package"]): is_config_app_dir = True zip_name = fileutils.pack_dir(self.config["app_package"]) else: msg = _LE("There is no zip archive or directory by this path:" " %s") % self.config["app_package"] raise exceptions.ContextSetupFailure(msg=msg, ctx="murano_packages") for user, tenant_id in utils.iterate_per_tenants(self.context["users"]): clients = osclients.Clients(user["endpoint"]) self.context["tenants"][tenant_id]["packages"] = [] if is_config_app_dir: self.context["tenants"][tenant_id]["murano_ctx"] = zip_name package = clients.murano().packages.create( {"categories": ["Web"], "tags": ["tag"]}, {"file": open(zip_name)} ) self.context["tenants"][tenant_id]["packages"].append(package)