Skip to content

Commit 0860682

Browse files
committed
Avoid trying to pass revision unless provided by user in app refresh
Fixes #955 This also implements functionality that allows passing resources argument to application refresh.
1 parent 078f060 commit 0860682

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

juju/application.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,25 @@ async def refresh(
736736
err = charm_origin_result.error
737737
raise JujuError(f'{err.code} : {err.message}')
738738

739+
<<<<<<< HEAD
740+
=======
741+
# Now take care of the resources:
742+
743+
# user supplied resources to be used in refresh,
744+
# will override the default values if there's any
745+
arg_resources = resources or {}
746+
747+
# need to process the given resources, as they can be
748+
# paths or revisions
749+
_arg_res_filenames = {}
750+
_arg_res_revisions = {}
751+
for res, filename_or_rev in arg_resources.items():
752+
if isinstance(filename_or_rev, int):
753+
_arg_res_revisions[res] = filename_or_rev
754+
else:
755+
_arg_res_filenames[res] = filename_or_rev
756+
757+
>>>>>>> 5fbf5bc (Avoid trying to pass revision unless provided by user in app refresh)
739758
# Already prepped the charm_resources
740759
# Now get the existing resources from the ResourcesFacade
741760
request_data = [client.Entity(self.tag)]
@@ -749,23 +768,27 @@ async def refresh(
749768
# Compute the difference btw resources needed and the existing resources
750769
resources_to_update = []
751770
for resource in charm_resources:
752-
if utils.should_upgrade_resource(resource, existing_resources):
771+
if utils.should_upgrade_resource(resource, existing_resources, arg_resources):
753772
resources_to_update.append(resource)
754773

755774
# Update the resources
756775
if resources_to_update:
757776
request_data = []
758777
for resource in resources_to_update:
778+
res_name = resource.get('Name', resource.get('name'))
759779
request_data.append(client.CharmResource(
760780
description=resource.get('Description', resource.get('description')),
761-
fingerprint=resource.get('Fingerprint', resource.get('fingerprint')),
762-
name=resource.get('Name', resource.get('name')),
763-
path=resource.get('Path', resource.get('filename')),
764-
revision=resource.get('Revision', resource.get('revision', -1)),
765-
size=resource.get('Size', resource.get('size')),
781+
fingerprint=resource.get('Fingerprint', resource.get('fingerprint', [])),
782+
name=res_name,
783+
path=_arg_res_filenames.get(res_name,
784+
resource.get('Path',
785+
resource.get('filename', ''))),
786+
revision=_arg_res_revisions.get(res_name, -1),
787+
size=resource.get('Size', resource.get('size', 0)),
766788
type_=resource.get('Type', resource.get('type')),
767789
origin='store',
768790
))
791+
769792
response = await resources_facade.AddPendingResources(
770793
application_tag=self.tag,
771794
charm_url=charm_url,

juju/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,20 +532,25 @@ def series_selector(series_arg='', charm_url=None, model_config=None, supported_
532532
return DEFAULT_SUPPORTED_LTS
533533

534534

535-
def should_upgrade_resource(available_resource, existing_resources):
535+
def should_upgrade_resource(available_resource, existing_resources, arg_resources):
536536
"""Called in the context of upgrade_charm. Given a resource R, takes a look at the resources we
537537
already have and decides if we need to refresh R.
538538
539539
:param dict[str] available_resource: The dict representing the client.Resource coming from the
540540
charmhub api. We're considering if we need to refresh this during upgrade_charm.
541541
:param dict[str] existing_resources: The dict coming from resources_facade.ListResources
542542
representing the resources of the currently deployed charm.
543+
:param dict[str] arg_resources: user provided resources to be refreshed
543544
544545
:result bool: The decision to refresh the given resource
545546
"""
547+
546548
# should upgrade resource?
547549
res_name = available_resource.get('Name', available_resource.get('name'))
548550

551+
if res_name in arg_resources:
552+
return True
553+
549554
# do we have it already?
550555
if res_name in existing_resources:
551556
# no upgrade, if it's upload

0 commit comments

Comments
 (0)