Skip to content

Commit

Permalink
Allow push package by hash (#790)
Browse files Browse the repository at this point in the history
## 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 d261ff4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions compiler/quilt/test/test_cli.py
Expand Up @@ -178,6 +178,7 @@
[0, 'push', '--public'],
[0, 'push', '--team'],
[0, 'push', '--reupload'],
[0, 'push', '-x'],
[0, 'push', 0],
[0, 'rm'],
[0, 'rm', '-f'],
Expand Down Expand Up @@ -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..
Expand All @@ -707,6 +709,7 @@ def test_cli_command_push(self):
'is_public': True,
'package': 'fakeuser/fakepackage',
'is_team': False,
'hash' : None,
}

# team (without reupload)
Expand All @@ -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):
Expand Down
11 changes: 9 additions & 2 deletions compiler/quilt/test/test_push.py
Expand Up @@ -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]
Expand All @@ -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)
Expand All @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions compiler/quilt/tools/command.py
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions compiler/quilt/tools/main.py
Expand Up @@ -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
Expand Down

0 comments on commit d261ff4

Please sign in to comment.