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

Delete LXD instance if LXD failed to remove ephemeral instance #57

Merged
merged 4 commits into from
May 12, 2023
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
1 change: 1 addition & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parts:
charm-python-packages:
- setuptools # for jinja2
build-packages:
- git # for installing git source of pylxd
- libffi-dev # for cffi
- libssl-dev # for cryptography
- rust-all # for cryptography
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ ops
requests
jinja2
ghapi
pylxd
pylxd @ git+https://github.com/lxc/pylxd
# Newer version does not work with default OpenSSL version on jammy.
cryptography <= 38.0.4
12 changes: 12 additions & 0 deletions src/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ def remove(self, remove_token: str) -> None:
self.instance.stop(force=True)
except LxdError as err:
raise RunnerRemoveError(f"Unable to remove {self.config.name}") from err
else:
# Delete ephemeral instances that are in error status or stopped status that LXD
# failed to clean up.
logger.warning(
"Found runner %s in status %s, forcing deletion",
self.config.name,
self.instance.status,
)
try:
self.instance.delete(wait=True)
except LxdError as err:
raise RunnerRemoveError(f"Unable to remove {self.config.name}") from err

# The runner should cleanup itself. Cleanup on GitHub in case of runner cleanup error.
if isinstance(self.config.path, GitHubRepo):
Expand Down
4 changes: 2 additions & 2 deletions src/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def retry_decorator(
"""Decorate function with retry.

Args:
fn (Callable[..., R]): The function to decorate.
fn: The function to decorate.

Returns:
Callable[..., R]: The resulting function with retry added.
The resulting function with retry added.
"""

@functools.wraps(func)
Expand Down