Skip to content

Commit dc8499c

Browse files
authored
Merge pull request #943 from cderici/nested-assumes-on-3x
#943 #### Description This forward ports the fix for nested assume expressions from #940 into the master branch. Fixes #938 for `3.x`. #### QA Steps Same QA steps can be followed from #940, so copy/pasting the manual QA steps below: ----- Unfortunately it's not trivial to write an integration test for this, as the code that's been changed is part of the facade api. So we'll use the `mysql-k8s` charm that's been used in #938. ``` $ juju version 3.x $ juju bootstrap microk8s micro28 $ juju add-model assumes-test ``` ```python $ python -m asyncio asyncio REPL 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux Use "await" directly instead of "asyncio.run()". Type "help", "copyright", "credits" or "license" for more information. >>> import asyncio >>> from juju import model;m=model.Model();await m.connect();await m.deploy("mysql-k8s", channel="8.0/edge", trust=True) <Application entity_id="mysql-k8s"> >>> exiting asyncio REPL... ``` #### Notes & Discussion JUJU-4562
2 parents 0f577e2 + ca6dffb commit dc8499c

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

juju/client/facade.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,26 @@ async def rpc(self, msg):
661661

662662
@classmethod
663663
def from_json(cls, data):
664+
def _parse_nested_list_entry(expr, result_dict):
665+
if isinstance(expr, str):
666+
if '>' in expr or '>=' in expr:
667+
# something like juju >= 2.9.31
668+
i = expr.index('>')
669+
_key = expr[:i].strip()
670+
_value = expr[i:].strip()
671+
result_dict[_key] = _value
672+
else:
673+
# this is a simple entry
674+
result_dict[expr] = ''
675+
elif isinstance(expr, dict):
676+
for _, v in expr.items():
677+
_parse_nested_list_entry(v, result_dict)
678+
elif isinstance(expr, list):
679+
for v in expr:
680+
_parse_nested_list_entry(v, result_dict)
681+
else:
682+
raise TypeError(f"Unexpected type of entry in assumes expression: {expr}")
683+
664684
if isinstance(data, cls):
665685
return data
666686
if isinstance(data, str):
@@ -680,16 +700,7 @@ def from_json(cls, data):
680700
# check: https://juju.is/docs/sdk/assumes
681701
# assumes are in the form of a list
682702
d = {}
683-
for entry in data:
684-
if '>' in entry or '>=' in entry:
685-
# something like juju >= 2.9.31
686-
i = entry.index('>')
687-
key = entry[:i].strip()
688-
value = entry[i:].strip()
689-
d[key] = value
690-
else:
691-
# this is a simple entry
692-
d[entry] = ''
703+
_parse_nested_list_entry(data, d)
693704
return cls(**d)
694705
return None
695706

juju/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,13 @@ def should_upgrade_resource(available_resource, existing_resources):
546546
"""
547547
# should upgrade resource?
548548
res_name = available_resource.get('Name', available_resource.get('name'))
549-
# no, if it's upload
550-
if existing_resources[res_name].origin == 'upload':
551-
return False
552549

553-
# no, if we already have it (and upstream doesn't have a newer res available)
550+
# do we have it already?
554551
if res_name in existing_resources:
552+
# no upgrade, if it's upload
553+
if existing_resources[res_name].origin == 'upload':
554+
return False
555+
# no upgrade, if upstream doesn't have a newer revision of the resource available
555556
available_rev = available_resource.get('Revision', available_resource.get('revision', -1))
556557
u_fields = existing_resources[res_name].unknown_fields
557558
existing_rev = u_fields.get('Revision', u_fields.get('revision', -1))

0 commit comments

Comments
 (0)