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

devhost: fix fc-devhost-vm-cleanup.service timezone handling #1306

Merged
merged 1 commit into from
Feb 27, 2025
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
17 changes: 17 additions & 0 deletions changelog.d/20250226_145402_PL-133467-fix-devhost-cleanup_scriv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--

A new changelog entry.

Delete placeholder items that do not apply. Empty sections will be removed
automatically during release.

Leave the XX.XX as is: this is a placeholder and will be automatically filled
correctly during the release and helps when backporting over multiple platform
branches.

-->


### NixOS XX.XX platform

- devhost: fix cleanup of old development VMs (PL-133467)
22 changes: 14 additions & 8 deletions nixos/roles/devhost/fc-devhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,23 +428,29 @@ def cleanup(self, location=None):
vm_shut_down = False
for vm_cfg in list_all_vm_configs():
if "last_deploy_date" not in vm_cfg:
vm_cfg["last_deploy_date"] = (
datetime.datetime.utcnow().isoformat()
)
vm_cfg["last_deploy_date"] = datetime.datetime.now(
datetime.UTC
).isoformat()
with open(
CONFIG_DIR / f"{vm_cfg['name']}.json", mode="w"
) as f:
f.write(json.dumps(vm_cfg))

if datetime.datetime.fromisoformat(vm_cfg["last_deploy_date"]) < (
datetime.datetime.utcnow() - datetime.timedelta(days=31)
# existing VMs might have persisted a timezone-naive timestamp
last_deploy_date_parsed = datetime.datetime.fromisoformat(
vm_cfg["last_deploy_date"]
).astimezone(datetime.UTC)
if last_deploy_date_parsed < (
datetime.datetime.now(datetime.UTC)
- datetime.timedelta(days=31)
):
print(f"Deleting VM {vm_cfg['name']}.")
Manager(name=vm_cfg["name"]).destroy()

elif datetime.datetime.fromisoformat(
vm_cfg["last_deploy_date"]
) < (datetime.datetime.utcnow() - datetime.timedelta(days=14)):
elif last_deploy_date_parsed < (
datetime.datetime.now(datetime.UTC)
- datetime.timedelta(days=14)
):
if vm_cfg["online"] == False:
continue
print(f"Shutting down VM {vm_cfg['name']}.")
Expand Down