Skip to content

Commit 93a27fd

Browse files
committed
Add block parameter to unit.run for using it synchronously
Useful with older versions of juju, i.e. getting the result without having to call ``action.wait()`` separately.
1 parent 17faa00 commit 93a27fd

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

juju/unit.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,15 @@ async def detach_storage(self, *storage_ids, force=False):
186186
if ret.results[0].error:
187187
raise JujuError(ret.results[0].error.message)
188188

189-
async def run(self, command, timeout=None):
189+
async def run(self, command, timeout=None, block=False):
190190
"""Run command on this unit.
191191
192192
:param str command: The command to run
193193
:param int timeout: Time, in seconds, to wait before command is
194194
considered failed
195+
:param bool block: A flag to use this function in synchronized fashion.
196+
Useful with older versions of juju, i.e. getting the result without
197+
having to call ``action.wait()`` separately.
195198
:returns: A :class:`juju.action.Action` instance.
196199
197200
Note that this is very similarly to unit.run_action only enqueues the action.
@@ -233,7 +236,10 @@ async def run(self, command, timeout=None):
233236
if error:
234237
raise JujuError("Action error - {} : {}".format(error.code, error.message))
235238

236-
return await self.model._wait_for_new('action', action_id)
239+
action = await self.model._wait_for_new('action', action_id)
240+
if block:
241+
return await action.wait()
242+
return action
237243

238244
async def run_action(self, action_name, **params):
239245
"""Run an action on this unit.

0 commit comments

Comments
 (0)