Skip to content

Commit

Permalink
chore: refactor for testability
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Oct 2, 2024
1 parent aacdb39 commit 6bde04d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2947,23 +2947,6 @@ async def wait_for_idle(self,
last_log_time = None
log_interval = timedelta(seconds=30)

def _raise_for_status(entities, status):
if not entities:
return
for entity_name, error_type in (("Machine", JujuMachineError),
("Agent", JujuAgentError),
("Unit", JujuUnitError),
("App", JujuAppError)):
errored = entities.get(entity_name, [])
if not errored:
continue
raise error_type("{}{} in {}: {}".format(
entity_name,
"s" if len(errored) > 1 else "",
status,
", ".join(errored),
))

if wait_for_exact_units is not None:
assert isinstance(wait_for_exact_units, int) and wait_for_exact_units >= 0, \
'Invalid value for wait_for_exact_units : %s' % wait_for_exact_units
Expand Down Expand Up @@ -3107,6 +3090,25 @@ def _raise_for_status(entities, status):
await jasyncio.sleep(check_freq)


def _raise_for_status(entities: Dict, status: Any) -> None:
if not entities:
return
for entity_name, error_type in (("Machine", JujuMachineError),
("Agent", JujuAgentError),
("Unit", JujuUnitError),
("App", JujuAppError)):
errored = entities.get(entity_name, [])
if not errored:
continue
raise error_type("{}{} in {}: {}".format(
entity_name,
"s" if len(errored) > 1 else "",
status,
", ".join(errored),
))



def _create_consume_args(offer, macaroon, controller_info):
"""
Convert a typed object that has been normalised to a overrided typed
Expand Down

0 comments on commit 6bde04d

Please sign in to comment.