Skip to content

Commit a01c820

Browse files
authored
Merge pull request #671 from cderici/get-series-from-app-instead-of-metadata
[JUJU-981] Get series from deployed app instead of metadata when charm upgrade #### Description Charmhub is modeling the charm data separately from where the charm is deployed, therefore the series is not a part of the metadata anymore. So instead of getting the series from the metadata we now get it from the deployed application first, then we try the model config, if everything fails then we look at the metadata as a last resort (mostly to keep backwards ompatibility). Fixes #668 #### QA Steps The charm used for the integration test `test_upgrade_local_charm` has been updated to simulate what's happening in #668 (now it has multiple series where the first one is not the one that the charm was initially deployed on), so along with the rest of the CI tests, the following should pass with this change (which fails without the change): ```sh tox -e integration -- tests/integration/test_application.py::test_upgrade_local_charm ``` #### Notes & Discussion I initially thought that this would be a breaking change (needs a version bump), however, we're still keeping the old way of getting the series in case the new ways fail, so this shouldn't break anything.
2 parents 768d7ff + 580f231 commit a01c820

5 files changed

Lines changed: 31 additions & 21 deletions

File tree

juju/application.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,18 @@ async def unexpose(self, exposed_endpoints=None):
339339
log.debug("Unexposing %s", self.name)
340340
return await app_facade.Unexpose(application=self.name)
341341

342+
async def get_series(self):
343+
"""Return the series on which the application is deployed
344+
345+
:return: str series
346+
"""
347+
app_facade = self._facade()
348+
349+
log.debug(
350+
'Getting series for %s', self.name)
351+
352+
return (await app_facade.Get(application=self.name)).series
353+
342354
async def get_config(self):
343355
"""Return the configuration settings dict for this application.
344356
"""
@@ -728,9 +740,12 @@ async def local_refresh(
728740
charm_dir = path.expanduser().resolve()
729741
model_config = await self.get_config()
730742

731-
series = await get_charm_series(charm_dir, self.model)
743+
series = (
744+
await self.get_series() or
745+
self.model.info.get('default-series', '') or
746+
await get_charm_series(charm_dir, self.model)
747+
)
732748
if not series:
733-
model_config = await self.get_config()
734749
default_series = model_config.get("default-series")
735750
if default_series:
736751
series = default_series.value
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
name: simple
22
summary: A simple example charm with the new operator framework
33
description: |
4-
Simple is an example charm
5-
series:
6-
- xenial
7-
- bionic
4+
Simple is an example charm
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
series: bionic
21
saas:
3-
mysql:
4-
url: admin/{}.mysql
2+
influxdb:
3+
url: admin/{}.influxdb
54
applications:
6-
wordpress:
7-
charm: wordpress
5+
grafana:
6+
charm: grafana
87
channel: stable
98
num_units: 1
109
relations:
11-
- - wordpress:db
12-
- mysql:db
10+
- - grafana:grafana-source
11+
- influxdb:grafana-source

tests/integration/test_crossmodel.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,19 @@ async def test_add_bundle(event_loop):
165165
raise
166166

167167
await model_1.deploy(
168-
'mysql',
169-
application_name='mysql',
170-
series='xenial',
168+
'influxdb',
169+
application_name='influxdb',
171170
channel='stable',
172171
)
173-
assert 'mysql' in model_1.applications
172+
assert 'influxdb' in model_1.applications
174173
await model_1.wait_for_idle(status="active")
175174

176-
await model_1.create_offer("mysql:db")
175+
await model_1.create_offer("influxdb:grafana-source")
177176

178177
offers = await model_1.list_offers()
179178

180179
await model_1.block_until(
181-
lambda: all(offer.application_name == 'mysql'
180+
lambda: all(offer.application_name == 'influxdb'
182181
for offer in offers.results),
183182
timeout=60 * wait_for_min)
184183

@@ -187,4 +186,4 @@ async def test_add_bundle(event_loop):
187186
await model_2.deploy('local:{}'.format(tmp_path))
188187
await model_2.wait_for_idle(status="active")
189188

190-
await model_1.remove_offer("admin/{}.mysql".format(model_1.info.name), force=True)
189+
await model_1.remove_offer("admin/{}.influxdb".format(model_1.info.name), force=True)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: ubuntu
2-
series: ["focal"]
2+
series: ["bionic", "focal"]
33
summary: "test"
44
description: "test"
55
maintainers: ["test"]

0 commit comments

Comments
 (0)