Skip to content

Commit 9da79d9

Browse files
authored
Merge pull request #894 from cderici/pass-through-local-refresh-if-resources
#894 #### Description This patches a bug that 5d843ec introduced, where if `--path` is given (i.e., refreshing with a local charm), it errors with NYI if `--resources` is given (instead of falling through the `local_refresh`). Should fix #881 #### QA Steps Adds an integration test, so the following should pass: ```sh tox -e integration -- tests/integration/test_application.py::test_upgrade_local_charm_with_resource ```
2 parents 521b5ef + e747ce5 commit 9da79d9

4 files changed

Lines changed: 50 additions & 22 deletions

File tree

juju/application.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ async def set_constraints(self, constraints):
623623

624624
async def refresh(
625625
self, channel=None, force=False, force_series=False, force_units=False,
626-
path=None, resources=None, revision=None, switch=None):
626+
local_charm_path=None, resources=None, revision=None, switch=None):
627627
"""Refresh the charm for this application.
628628
629629
:param str channel: Channel to use when getting the charm from the
@@ -632,17 +632,17 @@ async def refresh(
632632
application is not supported by the new charm
633633
:param bool force_units: Refresh all units immediately, even if in
634634
error state
635-
:param str path: Refresh to a charm located at path
635+
:param str local_charm_path: Refresh to a charm located at path
636636
:param dict resources: Dictionary of resource name/filepath pairs
637637
:param int revision: Explicit refresh revision
638638
:param str switch: Crossgrade charm url
639639
640640
"""
641-
if resources is not None:
642-
raise NotImplementedError("resources option is not implemented")
641+
if local_charm_path is None and resources is not None:
642+
raise NotImplementedError("refreshing a non-local charm with resources option is not yet implemented")
643643

644644
if switch is not None and revision is not None:
645-
raise ValueError("switch and revision are mutually exclusive")
645+
raise ValueError("switch and revision parameters are mutually exclusive in application refresh")
646646

647647
app_facade = self._facade()
648648
resources_facade = client.ResourcesFacade.from_connection(self.connection)
@@ -660,9 +660,9 @@ async def refresh(
660660
charm_url = switch or charm_url_origin_result.url
661661
origin = charm_url_origin_result.charm_origin
662662

663-
if path is not None:
663+
if local_charm_path is not None:
664664
await self.local_refresh(origin, force, force_series,
665-
force_units, path, resources)
665+
force_units, local_charm_path, resources)
666666
return
667667

668668
parsed_url = URL.parse(charm_url)

tests/integration/test_application.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55

66
from .. import base
7+
from ..utils import INTEGRATION_TEST_DIR
78
from juju import errors
89
from juju.url import URL, Schema
910

@@ -237,6 +238,28 @@ async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
237238
assert ress['policyd-override'].fingerprint == ress2['policyd-override'].fingerprint
238239

239240

241+
@base.bootstrapped
242+
@pytest.mark.asyncio
243+
async def test_upgrade_local_charm_with_resource(event_loop):
244+
charm_path = INTEGRATION_TEST_DIR / 'file-resource-charm'
245+
async with base.CleanModel() as model:
246+
app = await model.deploy(str(charm_path))
247+
assert 'file-resource-charm' in model.applications
248+
249+
await model.wait_for_idle()
250+
assert app.units[0].agent_status == 'idle'
251+
252+
resources = {"file-res": "test.file"}
253+
await app.refresh(local_charm_path=str(charm_path), resources=resources)
254+
255+
await model.wait_for_idle()
256+
assert app.units[0].agent_status == 'idle'
257+
258+
ress = await app.get_resources()
259+
assert 'file-res' in ress
260+
assert ress['file-res']
261+
262+
240263
@base.bootstrapped
241264
@pytest.mark.asyncio
242265
async def test_trusted(event_loop):

tests/integration/test_model.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import time
66
import uuid
77
from concurrent.futures import ThreadPoolExecutor
8-
from pathlib import Path
98

109
import mock
1110
import paramiko
@@ -19,13 +18,7 @@
1918
from juju.utils import block_until, run_with_interrupt, wait_for_bundle
2019

2120
from .. import base
22-
23-
MB = 1
24-
GB = 1024
25-
SSH_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsYMJGNGG74HAJha3n2CFmWYsOOaORnJK6VqNy86pj0MIpvRXBzFzVy09uPQ66GOQhTEoJHEqE77VMui7+62AcMXT+GG7cFHcnU8XVQsGM6UirCcNyWNysfiEMoAdZScJf/GvoY87tMEszhZIUV37z8PUBx6twIqMdr31W1J0IaPa+sV6FEDadeLaNTvancDcHK1zuKsL39jzAg7+LYjKJfEfrsQP+lj/EQcjtKqlhVS5kzsJVfx8ZEd0xhW5G7N6bCdKNalS8mKCMaBXJpijNQ82AiyqCIDCRrre2To0/i7pTjRiL0U9f9mV3S4NJaQaokR050w/ZLySFf6F7joJT mathijs@Qrama-Mathijs' # noqa
26-
HERE_DIR = Path(__file__).absolute().parent # tests/integration
27-
TESTS_DIR = HERE_DIR.parent # tests/
28-
OVERLAYS_DIR = HERE_DIR / 'bundle' / 'test-overlays'
21+
from ..utils import MB, GB, TESTS_DIR, OVERLAYS_DIR, SSH_KEY, INTEGRATION_TEST_DIR
2922

3023

3124
@base.bootstrapped
@@ -68,7 +61,7 @@ async def test_deploy_local_bundle_file(event_loop):
6861
@base.bootstrapped
6962
@pytest.mark.asyncio
7063
async def test_deploy_bundle_local_resource_relative_path(event_loop):
71-
bundle_file_path = HERE_DIR / 'bundle-file-resource.yaml'
64+
bundle_file_path = INTEGRATION_TEST_DIR / 'bundle-file-resource.yaml'
7265

7366
async with base.CleanModel() as model:
7467
await model.deploy(str(bundle_file_path))
@@ -82,7 +75,7 @@ async def test_deploy_bundle_local_resource_relative_path(event_loop):
8275
@base.bootstrapped
8376
@pytest.mark.asyncio
8477
async def test_deploy_local_bundle_include_file(event_loop):
85-
bundle_dir = TESTS_DIR / 'integration' / 'bundle'
78+
bundle_dir = INTEGRATION_TEST_DIR / 'bundle'
8679
bundle_yaml_path = bundle_dir / 'bundle-include-file.yaml'
8780

8881
async with base.CleanModel() as model:
@@ -99,7 +92,7 @@ async def test_deploy_local_bundle_include_file(event_loop):
9992
@base.bootstrapped
10093
@pytest.mark.asyncio
10194
async def test_deploy_local_bundle_include_base64(event_loop):
102-
bundle_dir = TESTS_DIR / 'integration' / 'bundle'
95+
bundle_dir = INTEGRATION_TEST_DIR / 'bundle'
10396
bundle_yaml_path = bundle_dir / 'bundle-include-base64.yaml'
10497

10598
async with base.CleanModel() as model:
@@ -115,7 +108,7 @@ async def test_deploy_local_bundle_include_base64(event_loop):
115108
@base.bootstrapped
116109
@pytest.mark.asyncio
117110
async def test_deploy_bundle_local_charms(event_loop):
118-
bundle_path = TESTS_DIR / 'integration' / 'bundle' / 'local.yaml'
111+
bundle_path = INTEGRATION_TEST_DIR / 'bundle' / 'local.yaml'
119112

120113
async with base.CleanModel() as model:
121114
await model.deploy(bundle_path)
@@ -678,7 +671,7 @@ async def test_local_oci_image_resource_charm(event_loop):
678671
@base.bootstrapped
679672
@pytest.mark.asyncio
680673
async def test_local_file_resource_charm(event_loop):
681-
charm_path = TESTS_DIR / 'integration' / 'file-resource-charm'
674+
charm_path = INTEGRATION_TEST_DIR / 'file-resource-charm'
682675
async with base.CleanModel() as model:
683676
resources = {"file-res": "test.file"}
684677
app = await model.deploy(str(charm_path), resources=resources)
@@ -716,7 +709,7 @@ async def test_attach_resource(event_loop):
716709
async def test_store_resources_bundle(event_loop):
717710
pytest.skip('test_store_resources_bundle intermittent test failure')
718711
async with base.CleanModel() as model:
719-
bundle = str(Path(__file__).parent / 'bundle')
712+
bundle = INTEGRATION_TEST_DIR / 'bundle'
720713
await model.deploy(bundle)
721714
assert 'ghost' in model.applications
722715
ghost = model.applications['ghost']
@@ -738,7 +731,7 @@ async def test_store_resources_bundle(event_loop):
738731
async def test_store_resources_bundle_revs(event_loop):
739732
pytest.skip('test_store_resources_bundle_revs intermittent test failure')
740733
async with base.CleanModel() as model:
741-
bundle = str(Path(__file__).parent / 'bundle/bundle-resource-rev.yaml')
734+
bundle = INTEGRATION_TEST_DIR / 'bundle/bundle-resource-rev.yaml'
742735
await model.deploy(bundle)
743736
assert 'ghost' in model.applications
744737
ghost = model.applications['ghost']

tests/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pathlib import Path
2+
3+
# Utilities for tests
4+
5+
MB = 1
6+
GB = 1024
7+
SSH_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsYMJGNGG74HAJha3n2CFmWYsOOaORnJK6VqNy86pj0MIpvRXBzFzVy09uPQ66GOQhTEoJHEqE77VMui7+62AcMXT+GG7cFHcnU8XVQsGM6UirCcNyWNysfiEMoAdZScJf/GvoY87tMEszhZIUV37z8PUBx6twIqMdr31W1J0IaPa+sV6FEDadeLaNTvancDcHK1zuKsL39jzAg7+LYjKJfEfrsQP+lj/EQcjtKqlhVS5kzsJVfx8ZEd0xhW5G7N6bCdKNalS8mKCMaBXJpijNQ82AiyqCIDCRrre2To0/i7pTjRiL0U9f9mV3S4NJaQaokR050w/ZLySFf6F7joJT mathijs@Qrama-Mathijs' # noqa
8+
HERE_DIR = Path(__file__).absolute() # tests/integration
9+
TESTS_DIR = HERE_DIR.parent # tests/
10+
INTEGRATION_TEST_DIR = TESTS_DIR / 'integration'
11+
UNIT_TEST_DIR = TESTS_DIR / 'unit'
12+
OVERLAYS_DIR = INTEGRATION_TEST_DIR / 'bundle' / 'test-overlays'

0 commit comments

Comments
 (0)