|
1 | 1 | from pathlib import Path |
2 | 2 |
|
3 | 3 | import pytest |
| 4 | +import logging |
4 | 5 |
|
5 | 6 | from .. import base |
6 | | -from juju import jasyncio |
| 7 | +from juju import jasyncio, errors |
| 8 | +from juju.url import URL, Schema |
7 | 9 |
|
8 | 10 | MB = 1 |
9 | 11 |
|
| 12 | +logger = logging.getLogger(__name__) |
| 13 | + |
10 | 14 |
|
11 | 15 | @base.bootstrapped |
12 | 16 | @pytest.mark.asyncio |
@@ -167,6 +171,41 @@ async def test_upgrade_charm_channel(event_loop): |
167 | 171 | assert app.data['charm-url'] != 'cs:ubuntu-0' |
168 | 172 |
|
169 | 173 |
|
| 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 | + |
170 | 209 | @base.bootstrapped |
171 | 210 | @pytest.mark.asyncio |
172 | 211 | async def test_upgrade_charm_revision(event_loop): |
|
0 commit comments