Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible solution for unit run inconsistencies #711

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion juju/unit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging

import pyrfc3339
import shlex
from subprocess import CompletedProcess

from juju.errors import JujuAPIError, JujuError

Expand All @@ -11,6 +13,18 @@
log = logging.getLogger(__name__)


def _wrapped_run_response(command:str, action):
"""Wrap API results into a consistent CompletedProcess added to the action."""
results = action.results
action.completed = CompletedProcess(
args=shlex.split(command),
returncode=int(results.get("Code") or results.get("return-code")),
stdout=str(results.get("Stdout") or results.get("stdout") or ""),
stderr=str(results.get("Stderr") or results.get("stderr") or ""),
)
return action


class Unit(model.ModelEntity):
@property
def agent_status(self):
Expand Down Expand Up @@ -212,7 +226,9 @@ async def run(self, command, timeout=None):
units=[self.name],
)
the_action = res.results[0] if self.connection.is_using_old_client else res.actions[0]
return await self.model.wait_for_action(the_action.action.tag)
action = await self.model.wait_for_action(the_action.action.tag)
await action.wait()
return _wrapped_run_response(command, action)

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