Skip to content
Permalink
Browse files

Allow push package by hash (#790)

## Allow push package by hash

Adding a hash argument to push to allow pushing package instances other than `latest`. Adding the new argument (hash) as the last argument to avoid breaking any existing code that passed args positionally.
  • Loading branch information...
kevinemoore committed Dec 20, 2018
1 parent a2b0472 commit d261ff40c1a61535d7756033b45a61be8a347968
@@ -178,6 +178,7 @@
[0, 'push', '--public'],
[0, 'push', '--team'],
[0, 'push', '--reupload'],
[0, 'push', '-x'],
[0, 'push', 0],
[0, 'rm'],
[0, 'rm', '-f'],
@@ -695,6 +696,7 @@ def test_cli_command_push(self):
'is_public': False,
'package': 'fakeuser/fakepackage',
'is_team': False,
'hash' : None,
}

## Test the flags as well..
@@ -707,6 +709,7 @@ def test_cli_command_push(self):
'is_public': True,
'package': 'fakeuser/fakepackage',
'is_team': False,
'hash' : None,
}

# team (without reupload)
@@ -718,6 +721,7 @@ def test_cli_command_push(self):
'is_public': False,
'package': 'blah:fakeuser/fakepackage',
'is_team': True,
'hash' : None,
}

def test_cli_command_export(self):
@@ -43,7 +43,7 @@ def test_push(self):
) for blob_hash in all_hashes
}

# We will push the package twice, so we're mocking all responses twice.
# We will push the package 3 times, so we're mocking all responses 3 times.

for blob_hash in all_hashes:
urls = upload_urls[blob_hash]
@@ -52,7 +52,8 @@ def test_push(self):
self.requests_mock.add(responses.HEAD, urls['head'], status=404)
self.requests_mock.add(responses.PUT, urls['put'])

# Second time, s3 HEAD succeeds, and we're not expecting a PUT.
# Second and third times, s3 HEAD succeeds, and we're not expecting a PUT.
self.requests_mock.add(responses.HEAD, urls['head'])
self.requests_mock.add(responses.HEAD, urls['head'])

self._mock_put_package('foo/bar', pkg_hash, contents, upload_urls)
@@ -61,12 +62,18 @@ def test_push(self):
self._mock_put_package('foo/bar', pkg_hash, contents, upload_urls)
self._mock_put_tag('foo/bar', 'latest')

self._mock_put_package('foo/bar', pkg_hash, contents, upload_urls)
self._mock_put_tag('foo/bar', 'latest')

# Push a new package.
command.push('foo/bar')

# Push it again; this time, we're verifying that there are no s3 uploads.
command.push('foo/bar')

# Push the package by its hash
command.push('foo/bar', hash=pkg_hash)

def test_push_subpackage(self):
mydir = os.path.dirname(__file__)
build_path = os.path.join(mydir, './build.yml')
@@ -648,19 +648,21 @@ def log(package):
str(entry.get('tags', [])), str(entry.get('versions', []))))
_print_table(table)

def push(package, is_public=False, is_team=False, reupload=False):
def push(package, is_public=False, is_team=False, reupload=False, hash=None):
"""
Push a Quilt data package to the server
"""
team, owner, pkg, subpath = parse_package(package, allow_subpath=True)
_check_team_id(team)
session = _get_session(team)

store, pkgroot = PackageStore.find_package(team, owner, pkg)
store, pkgroot = PackageStore.find_package(team, owner, pkg, pkghash=hash)
if pkgroot is None:
raise CommandException("Package {package} not found.".format(package=package))

pkghash = hash_contents(pkgroot)
if hash is not None:
assert pkghash == hash
contents = pkgroot

for component in subpath:
@@ -218,6 +218,7 @@ def check_hash(group, hashstr):
"(fails if the package exists and is private)"))
push_p.add_argument("--reupload", action="store_true",
help="Re-upload all fragments, even if fragment is already in registry")
push_p.add_argument("-x", "--hash", help="Package hash", type=str)
push_p.set_defaults(func=command.push)

# quilt rm

0 comments on commit d261ff4

Please sign in to comment.
You can’t perform that action at this time.