Skip to content

Commit

Permalink
respect bundle defined app channels for charmstore
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Feb 4, 2022
1 parent db23914 commit 4a7c388
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 8 additions & 10 deletions shrinkwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import argparse
import datetime
from collections import namedtuple, Sequence
from collections import namedtuple
from collections.abc import Sequence
from contextlib import contextmanager
from io import BytesIO
import os
Expand Down Expand Up @@ -173,10 +174,10 @@ def _charmhub_downloader(self, name, target, channel=None):
return zipfile.ZipFile(BytesIO(resp.content)).extractall(rsc_target)

def _charmstore_downloader(self, name, target, channel=None):
with status(f'Downloading "{name}" from charm store'):
_, rsc_target = self.to_args(target, channel=None)
with status(f'Downloading "{name} {channel}" from charm store'):
_, rsc_target = self.to_args(target, channel=channel)
url = f"{self.CS_URL}/{name}/archive"
resp = requests.get(url)
resp = requests.get(url, params={"channel": channel})
return zipfile.ZipFile(BytesIO(resp.content)).extractall(rsc_target)


Expand Down Expand Up @@ -458,12 +459,9 @@ def download(args, root):
check_call(shlx(f"ln -r -s {snaps.empty_snap} {snap_resource}"))
else:
# This isn't a snap, pull the resource from the appropriate store
bundle_resource_revision = app["resources"].get(resources)
if bundle_resource_revision and bundle_resource_revision != resource.revision:
# if the bundle's revision doesn't match the charm's default revision, update from bundle
resource = Resource(
resource.name, resource.type, resource.path, bundle_resource_revision, resource.url_format
)
# use the bundle provided resource revision if available
resource_rev = app["resources"].get(resource.name) or resource.revision
resource = Resource(resource.name, resource.type, resource.path, resource_rev, resource.url_format)
resources.mark_download(app_name, charm, resource)

base_snaps = ["core18", "core20", "lxd", "snapd"]
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_bundle_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def test_charmstore_downloader(mock_zipfile, mock_get, tmpdir):
downloader = BundleDownloader(tmpdir, args)
result = downloader.bundle_download()
assert result is mock_downloaded
mock_get.assert_called_once_with("https://api.jujucharms.com/charmstore/v5/kubernetes-unit-test/archive")
mock_get.assert_called_once_with(
"https://api.jujucharms.com/charmstore/v5/kubernetes-unit-test/archive", params={"channel": args.channel}
)
mock_zipfile.assert_called_once()
assert isinstance(mock_zipfile.call_args.args[0], BytesIO)

Expand Down

0 comments on commit 4a7c388

Please sign in to comment.