def test_multiple_top_level_entries(self): self.load_words() paths = ["path/one.txt", "another/two.txt"] (_f, src_zip) = tempfile.mkstemp(suffix=".zip") self.write_zip(src_zip, paths) outdir = tempfile.mkdtemp() try: archive.create_partitioned_zips_from_zip(src_zip, outdir) self.fail("RuntimeError not raised") except RuntimeError as exc: self.assertIn("multiple top-level entries", str(exc))
def test_size_rollover(self): self.load_words() paths = ["path/one.txt", "path/to/two.txt", "path/to/stuff/three.txt"] src = "This is a test of the system" (_f, src_zip) = tempfile.mkstemp(suffix=".zip") self.write_zip(src_zip, paths, content=src) outdir = tempfile.mkdtemp() zips = archive.create_partitioned_zips_from_zip(src_zip, outdir, max_size=2 * len(src) + 1) self.assertEqual(len(zips), 2) self.assertEqual( sorted(info.filename for info in zipfile.ZipFile(zips[0]).infolist()), sorted(os.path.join(*path.split("/")[1:]) for path in paths[:2]), ) self.assertEqual( sorted(info.filename for info in zipfile.ZipFile(zips[1]).infolist()), sorted(os.path.join(*path.split("/")[1:]) for path in paths[2:]), )
def test_small(self): self.load_words() paths = ["path/one.txt", "path/to/two.txt", "path/to/stuff/three.txt"] (_f, src_zip) = tempfile.mkstemp(suffix=".zip") self.write_zip(src_zip, paths) outdir = tempfile.mkdtemp() zips = archive.create_partitioned_zips_from_zip(src_zip, outdir) self.assertEqual(len(zips), 1) self.assertEqual( sorted(info.filename for info in zipfile.ZipFile(zips[0]).infolist()), sorted(os.path.join(*path.split("/")[1:]) for path in paths), )
def test_small(self): self.load_words() paths = ['path/one.txt', 'path/to/two.txt', 'path/to/stuff/three.txt'] (_f, src_zip) = tempfile.mkstemp(suffix='.zip') self.write_zip(src_zip, paths) outdir = tempfile.mkdtemp() zips = archive.create_partitioned_zips_from_zip(src_zip, outdir) self.assertEqual(len(zips), 1) print zips z = zips[0] zf = zipfile.ZipFile(z) for info in zf.infolist(): print "%s contains: %s" % (z, info.filename) self.assertEqual(info.filename in paths, True)
def test_trim_maven_dir(self): self.load_words() paths = ["path/one.txt", "path/to/two.txt", "path/to/stuff/three.txt"] maven_paths = [ "top-level/maven-repository/%s" % path for path in paths ] (_f, src_zip) = tempfile.mkstemp(suffix=".zip") self.write_zip(src_zip, maven_paths) outdir = tempfile.mkdtemp() zips = archive.create_partitioned_zips_from_zip(src_zip, outdir) self.assertEqual(len(zips), 1) self.assertEqual( sorted(info.filename for info in zipfile.ZipFile(zips[0]).infolist()), sorted(paths), )
def test_size_rollover(self): self.load_words() paths = ['path/one.txt', 'path/to/two.txt', 'path/to/stuff/three.txt'] src = "This is a test of the system" (_f, src_zip) = tempfile.mkstemp(suffix='.zip') self.write_zip(src_zip, paths, content=src) outdir = tempfile.mkdtemp() zips = archive.create_partitioned_zips_from_zip(src_zip, outdir, max_size=2 * len(src) + 1) self.assertEqual(len(zips), 2) print zips for z in zips: zf = zipfile.ZipFile(z) for info in zf.infolist(): print "%s contains: %s" % (z, info.filename) self.assertEqual(info.filename in paths, True)
def push(repo, environment, product, version, ga=False, debug=False): """Push Apache Maven repository content to a Nexus staging repository, then add the staging repository to appropriate content groups. More Information: https://mojo.redhat.com/docs/DOC-1132234 """ nexus_config = config.load(environment, debug=debug) if ga: groups = [RELEASE_GROUP_NAME, TECHPREVIEW_GROUP_NAME] else: groups = [PRERELEASE_GROUP_NAME] session = Session(nexus_config, debug=debug) try: print "Pushing: %s content to: %s" % (repo, environment) # produce a set of clean repository zips for PUT upload. zips_dir = tempfile.mkdtemp() print "Creating ZIP archives in: %s" % zips_dir if os.path.isdir(repo): print "Processing repository directory: %s" % repo # Walk the directory tree, and create a zip. zip_paths = archive.create_partitioned_zips_from_dir( repo, zips_dir) else: print "Processing repository zip archive: %s" % repo # Open the zip, walk the entries and normalize the structure to clean zip (if necessary) zip_paths = archive.create_partitioned_zips_from_zip( repo, zips_dir) # Open new staging repository with description staging_repo_id = staging.start_staging_repo(session, nexus_config, product, version, ga) # HTTP PUT clean repository zips to Nexus. delete_first = True for zipfile in zip_paths: repo.push_zip(session, staging_repo_id, zipfile, delete_first) delete_first = False # Close staging repository staging.finish_staging_repo(session, nexus_config, staging_repo_id, product, version, ga) for group_id in groups: group = groups.load(session, group_id, ignore_missing=True) if group is not None: print "Adding %s to group: %s" % (staging_repo_id, group_id) group.append_member(session, staging_repo_id).save(session) else: print "No such group: %s" % group_id raise Exception("No such group: %s" % group_id) finally: if session is not None: session.close()
def push(repo, environment, product, version, ga=False, debug=False): """Push Apache Maven repository content to a Nexus staging repository, then add the staging repository to appropriate content groups. More information: https://mojo.redhat.com/docs/DOC-1199638 """ nexus_config = config.load(environment) npm_archive_type = npm.detect_npm_archive(repo) if npm_archive_type != npm.NpmArchiveType.NOT_NPM: # if any npm archive types.... npm.push(nexus_config, repo, npm_archive_type, product, debug=debug) else: if nexus_config.get_profile_type(product) != config.ProfileType.JAVA: print(product + " is not a java product!", file=sys.stderr) exit(1) session = Session(nexus_config, debug=debug) print("Pushing: %s content to: %s" % (repo, environment)) zips_dir = None try: # produce a set of clean repository zips for PUT upload. zips_dir = tempfile.mkdtemp() print("Creating ZIP archives in: %s" % zips_dir) if os.path.isdir(repo): print("Processing repository directory: %s" % repo) # Walk the directory tree, and create a zip. zip_paths = archive.create_partitioned_zips_from_dir( repo, zips_dir) else: print("Processing repository zip archive: %s" % repo) # Open the zip, walk the entries and normalize the structure to # clean zip zip_paths = archive.create_partitioned_zips_from_zip( repo, zips_dir, debug=debug) # Open new staging repository with description staging_repo_id = staging.start_staging_repo( session, nexus_config, product, version, ga) # HTTP PUT clean repository zips to Nexus. delete_first = True for idx, zipfile in enumerate(zip_paths, start=1): print("Uploading zip %s out of %s" % (idx, len(zip_paths))) repos.push_zip(session, staging_repo_id, zipfile, delete_first) delete_first = False # Close staging repository staging.finish_staging_repo(session, nexus_config, staging_repo_id, product, version, ga) if staging.verify_action(session, staging_repo_id, "close"): sys.exit(1) print("Promoting repo") profiles = nexus_config.get_promote_profile_ids(product, ga) promote_entity = None for promote_profile in profiles: if not promote_entity: # First iteration, promote staging repo directly. promote_entity = staging_repo_id else: # On every other iteration promote the group created by # previous promotion. promote_entity = staging.get_next_promote_entity( session, promote_entity) staging.promote(session, promote_profile, promote_entity, product, version, ga) if staging.verify_action(session, promote_entity, "promote"): sys.exit(1) except RuntimeError as exc: if debug: raise print("Error: %s" % exc, file=sys.stderr) sys.exit(1) except requests.exceptions.HTTPError as exc: if debug: raise print("Network error: %s" % exc, file=sys.stderr) sys.exit(1) finally: if session is not None: session.close() if zips_dir: shutil.rmtree(zips_dir) print("Deployment successfully finished.")