Skip to content

Commit

Permalink
fix: Task status can be Do and should not raise an error. (canonica…
Browse files Browse the repository at this point in the history
…l#140)

Resolves canonical#139

* fix: Task status can be Do.

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.

* chore: Bump libpatch
  • Loading branch information
Gu1nness authored Dec 15, 2024
1 parent f1952df commit d58cced
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/charms/operator_libs_linux/v2/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 8
LIBPATCH = 9


# Regex to locate 7-bit C1 ANSI sequences
Expand Down 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 d58cced

Please sign in to comment.