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