Skip to content

Commit 2868736

Browse files
committed
Add test_upgrade_charm_switch_channel in integration/test_application
1 parent 009e9c3 commit 2868736

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

tests/integration/test_application.py

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

33
import pytest
4+
import logging
45

56
from .. import base
7+
from juju import jasyncio, errors
8+
from juju.url import URL, Schema
69

710
MB = 1
811

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

1015
@base.bootstrapped
1116
@pytest.mark.asyncio
@@ -164,6 +169,41 @@ async def test_upgrade_charm_channel(event_loop):
164169
assert app.data['charm-url'] != 'cs:ubuntu-0'
165170

166171

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

0 commit comments

Comments
 (0)