From 4a7c3884178570327a923a0759c7031b5b7da92c Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Fri, 4 Feb 2022 12:58:45 -0600 Subject: [PATCH] respect bundle defined app channels for charmstore --- shrinkwrap.py | 18 ++++++++---------- tests/unit/test_bundle_downloader.py | 4 +++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/shrinkwrap.py b/shrinkwrap.py index 38eb911..017e63b 100755 --- a/shrinkwrap.py +++ b/shrinkwrap.py @@ -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 @@ -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) @@ -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"] diff --git a/tests/unit/test_bundle_downloader.py b/tests/unit/test_bundle_downloader.py index 4a4fc1a..e39c6ad 100644 --- a/tests/unit/test_bundle_downloader.py +++ b/tests/unit/test_bundle_downloader.py @@ -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)