Skip to content

Commit 5c4910b

Browse files
authored
Merge pull request #812 from cderici/add-destroy-units
#812 #### Description This brings back the separate `model.destroy_units(*units)` as a quality of life feature. Fixes #811 #### QA Steps All the regular tests should pass. Additionally, this also adds a separate integration test for `destroy_units`, so the following should be passing (I tried it on juju 3.1). ``` tox -e integration -- tests/integration/test_model.py::test_destroy_units ``` #### Notes & Discussion As a future reference, this was changed in #791.
2 parents f52ca42 + cb9b4a9 commit 5c4910b

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

juju/model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,13 @@ async def destroy_unit(self, unit_id, destroy_storage=False, dry_run=False, forc
20142014
'max-wait': max_wait,
20152015
'dry-run': dry_run,
20162016
}])
2017-
destroy_units = destroy_unit
2017+
2018+
async def destroy_units(self, *unit_names, destroy_storage=False, dry_run=False, force=False, max_wait=None):
2019+
"""Destroy several units at once.
2020+
2021+
"""
2022+
for u in unit_names:
2023+
await self.destroy_unit(u, destroy_storage, dry_run, force, max_wait)
20182024

20192025
def download_backup(self, archive_id, target_filename=None):
20202026
"""Download a backup archive file.

tests/integration/test_model.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,23 @@ async def test_wait_for_idle_with_exact_units_scale_down_zero(event_loop):
882882
assert (end_time - start_time) > 0.001
883883

884884

885+
@base.bootstrapped
886+
@pytest.mark.asyncio
887+
async def test_destroy_units(event_loop):
888+
async with base.CleanModel() as model:
889+
app = await model.deploy(
890+
'ubuntu',
891+
application_name='ubuntu',
892+
series='jammy',
893+
channel='stable',
894+
num_units=3,
895+
)
896+
await model.wait_for_idle(status='active')
897+
await model.destroy_units(*[u.name for u in app.units])
898+
await model.wait_for_idle(timeout=5 * 60, wait_for_exact_units=0)
899+
assert app.units == []
900+
901+
885902
@base.bootstrapped
886903
@pytest.mark.asyncio
887904
async def test_watcher_reconnect(event_loop):

0 commit comments

Comments
 (0)