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

fix: Task status can be Do and should not raise an error. #140

Merged
Merged
Show file tree
Hide file tree
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
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