Skip to content

Commit ff3fccd

Browse files
authored
Merge pull request #653 from cderici/add-unit-auto-switch-to-scale
#653 #### Description This is a quality of life feature that automatically uses `scale` function when `add_unit` is used on a container based model (instead of failing with `JujuError` as it's current behavior). Fixes #651 #### QA Steps For this you're gonna need a container based model, like: ```sh juju bootstrap microk8s test juju add-model test-model ``` Then: ```sh python examples/charmhub_deploy_k8s.py ``` should complete wihtout an error. #### Notes & Discussion
2 parents fc93ad5 + 9ee7e0b commit ff3fccd

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

examples/charmhub_deploy_k8s.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ async def main():
2424
)
2525

2626
print('Waiting for active')
27-
await model.block_until(
28-
lambda: all(unit.workload_status == 'active'
29-
for unit in application.units))
27+
await model.wait_for_idle(status="active")
28+
29+
# when run on a container based model it should auto-switch to
30+
# scale instead of failing with JujuError
31+
await application.add_unit(count=2)
32+
await application.destroy()
3033

3134
finally:
3235
print('Disconnecting from model')

juju/application.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ async def add_unit(self, count=1, to=None):
131131
If None, a new machine is provisioned.
132132
133133
"""
134+
135+
if self.model.info.type_ == 'caas':
136+
log.warning('adding units to a container-based model not supported, auto-switching to scale')
137+
return await self.scale(scale_change=count)
138+
134139
app_facade = self._facade()
135140

136141
log.debug(

tests/integration/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ async def test_local_oci_image_resource_charm(event_loop):
623623
lambda: (
624624
len(charm.units) > 0 and
625625
charm.units[0].workload_status in terminal_statuses),
626-
timeout=60 * 4,
626+
timeout=60 * 10,
627627
)
628628
assert charm.units[0].workload_status == 'active'
629629

0 commit comments

Comments
 (0)