Skip to content

Commit 76698a5

Browse files
authored
Merge branch 'master' into JUJU-4829_fix_refresh_bug-master
2 parents 67188f4 + a677a64 commit 76698a5

3 files changed

Lines changed: 47 additions & 23 deletions

File tree

juju/model.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,32 +2157,35 @@ async def destroy_unit(self, unit_id, destroy_storage=False, dry_run=False, forc
21572157
"""Destroy units by name.
21582158
21592159
"""
2160-
connection = self.connection()
2161-
app_facade = client.ApplicationFacade.from_connection(connection)
2162-
2163-
# Get the corresponding unit tag
2164-
unit_tag = tag.unit(unit_id)
2165-
if unit_tag is None:
2166-
log.error("Error converting %s to a valid unit tag", unit_id)
2167-
return JujuUnitError("Error converting %s to a valid unit tag", unit_id)
2168-
2169-
log.debug(
2170-
'Destroying unit %s', unit_id)
2171-
2172-
return await app_facade.DestroyUnit(units=[{
2173-
'unit-tag': unit_tag,
2174-
'destroy-storage': destroy_storage,
2175-
'force': force,
2176-
'max-wait': max_wait,
2177-
'dry-run': dry_run,
2178-
}])
2160+
return await self.destroy_units(unit_id,
2161+
destroy_storage=destroy_storage,
2162+
dry_run=dry_run,
2163+
force=force,
2164+
max_wait=max_wait
2165+
)
21792166

21802167
async def destroy_units(self, *unit_names, destroy_storage=False, dry_run=False, force=False, max_wait=None):
21812168
"""Destroy several units at once.
21822169
21832170
"""
2184-
for u in unit_names:
2185-
await self.destroy_unit(u, destroy_storage, dry_run, force, max_wait)
2171+
connection = self.connection()
2172+
app_facade = client.ApplicationFacade.from_connection(connection)
2173+
2174+
units_to_destroy = []
2175+
for unit_id in unit_names:
2176+
unit_tag = tag.unit(unit_id)
2177+
if unit_tag is None:
2178+
log.error("Error converting %s to a valid unit tag", unit_id)
2179+
raise JujuUnitError("Error converting %s to a valid unit tag", unit_id)
2180+
units_to_destroy.append({
2181+
'unit-tag': unit_tag,
2182+
'destroy-storage': destroy_storage,
2183+
'force': force,
2184+
'max-wait': max_wait,
2185+
'dry-run': dry_run,
2186+
})
2187+
log.debug('Destroying units %s', unit_names)
2188+
return await app_facade.DestroyUnit(units=units_to_destroy)
21862189

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

juju/unit.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def get_subordinates(self):
102102
return [u for u_name, u in self.model.units.items() if u.is_subordinate and
103103
u.principal_unit == self.name]
104104

105-
async def destroy(self):
105+
async def destroy(self, destroy_storage=False, dry_run=False, force=False, max_wait=None):
106106
"""Destroy this unit.
107107
108108
"""
@@ -111,7 +111,12 @@ async def destroy(self):
111111
log.debug(
112112
'Destroying %s', self.name)
113113

114-
return await app_facade.DestroyUnit(units=[{"unit-tag": self.name}])
114+
return await app_facade.DestroyUnit(units=[{"unit-tag": self.tag,
115+
'destroy-storage': destroy_storage,
116+
'force': force,
117+
'max-wait': max_wait,
118+
'dry-run': dry_run,
119+
}])
115120
remove = destroy
116121

117122
async def get_public_address(self):

tests/integration/test_unit.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,19 @@ async def test_subordinate_units(event_loop):
280280
assert n_unit.principal_unit == 'ubuntu/0'
281281
assert u_unit.principal_unit == ''
282282
assert [u.name for u in u_unit.get_subordinates()] == [n_unit.name]
283+
284+
285+
@base.bootstrapped
286+
async def test_destroy_unit(event_loop):
287+
async with base.CleanModel() as model:
288+
app = await model.deploy(
289+
'juju-qa-test',
290+
application_name='test',
291+
num_units=3,
292+
)
293+
# wait for the units to come up
294+
await model.block_until(lambda: app.units, timeout=480)
295+
296+
await app.units[0].destroy()
297+
await asyncio.sleep(5)
298+
assert len(app.units) == 2

0 commit comments

Comments
 (0)