Skip to content

Commit 08a7de1

Browse files
committed
Add test_upgrade_charm_switch_channel in integration/test_application
1 parent d789714 commit 08a7de1

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

tests/integration/test_application.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from pathlib import Path
22

33
import pytest
4+
import logging
45

56
from .. import base
6-
from juju import jasyncio
7+
from juju import jasyncio, errors
8+
from juju.url import URL, Schema
79

810
MB = 1
911

12+
logger = logging.getLogger(__name__)
13+
1014

1115
@base.bootstrapped
1216
@pytest.mark.asyncio
@@ -167,6 +171,41 @@ async def test_upgrade_charm_channel(event_loop):
167171
assert app.data['charm-url'] != 'cs:ubuntu-0'
168172

169173

174+
@base.bootstrapped
175+
@pytest.mark.asyncio
176+
async def test_upgrade_charm_switch_channel(event_loop):
177+
# Note for future:
178+
# This test requires a charm that has different
179+
# revisions in channels 'stable' and 'candidate'.
180+
# Currently, we use mongodb, but eventually
181+
# (when the 'candidate' moves to 'stable') this test
182+
# will be testing nothing (if not failing).
183+
184+
async with base.CleanModel() as model:
185+
app = await model.deploy('mongodb', channel='stable')
186+
await model.wait_for_idle(status='active')
187+
188+
charm_url = URL.parse(app.data['charm-url'])
189+
assert Schema.CHARM_HUB.matches(charm_url.schema)
190+
still76 = False
191+
try:
192+
assert charm_url.revision == 76
193+
still76 = True
194+
except AssertionError:
195+
logger.warning("Charm used in test_upgrade_charm_switch_channel "
196+
"seems to have been updated, revise the test")
197+
198+
await app.upgrade_charm(channel='candidate')
199+
await model.wait_for_idle(status='active')
200+
201+
if still76:
202+
try:
203+
assert charm_url.revision == 75
204+
except AssertionError:
205+
raise errors.JujuError("Either the upgrade has failed, or the charm used moved "
206+
"the candidate channel to stable, so no upgrade took place")
207+
208+
170209
@base.bootstrapped
171210
@pytest.mark.asyncio
172211
async def test_upgrade_charm_revision(event_loop):

0 commit comments

Comments
 (0)