Skip to content

Commit

Permalink
fix: Task status can be Do.
Browse files Browse the repository at this point in the history
The task status can be `Do` and should not be considered an error.
This status means that the task is ready to start but hasn't started
yet.
  • Loading branch information
Gu1nness committed Dec 12, 2024
1 parent f1952df commit 26bb775
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/charms/operator_libs_linux/v2/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ def _wait(self, change_id: str, timeout=300) -> JSONType:
status = response["status"]
if status == "Done":
return response.get("data")
if status == "Doing":
if status == "Doing" or status == "Do":
time.sleep(0.1)
continue
if status == "Wait":
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ def test_request_raw_bad_response_raises_snapapierror(self):
shutdown()

def test_wait_changes(self):
change_started = False
change_finished = False

def _request_raw(
Expand All @@ -711,6 +712,7 @@ def _request_raw(
data: bytes = None,
) -> typing.IO[bytes]:
nonlocal change_finished
nonlocal change_started
if method == "PUT" and path == "snaps/test/conf":
return io.BytesIO(
json.dumps(
Expand All @@ -723,6 +725,36 @@ def _request_raw(
}
).encode("utf-8")
)
if method == "GET" and path == "changes/97" and not change_started:
change_started = True
return io.BytesIO(
json.dumps(
{
"type": "sync",
"status-code": 200,
"status": "OK",
"result": {
"id": "97",
"kind": "configure-snap",
"summary": 'Change configuration of "test" snap',
"status": "Do",
"tasks": [
{
"id": "1028",
"kind": "run-hook",
"summary": 'Run configure hook of "test" snap',
"status": "Do",
"progress": {"label": "", "done": 0, "total": 1},
"spawn-time": "2024-11-28T20:02:47.498399651+00:00",
"data": {"affected-snaps": ["test"]},
}
],
"ready": False,
"spawn-time": "2024-11-28T20:02:47.49842583+00:00",
},
}
).encode("utf-8")
)
if method == "GET" and path == "changes/97" and not change_finished:
change_finished = True
return io.BytesIO(
Expand Down

0 comments on commit 26bb775

Please sign in to comment.