From 851a4d45a065ad06808098eadf52d3c7663d7bf6 Mon Sep 17 00:00:00 2001 From: Marc Olivier Bergeron Date: Sat, 21 Feb 2026 22:16:01 -0500 Subject: [PATCH] Fixing destroy bug with network name. Decreased timer for VM and changed it a bit. --- ctf/deploy.py | 25 ++++++------------------- ctf/destroy.py | 25 ++++++++++++++----------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/ctf/deploy.py b/ctf/deploy.py index da89e94..bd21f83 100644 --- a/ctf/deploy.py +++ b/ctf/deploy.py @@ -199,16 +199,11 @@ def deploy( # Waiting for virtual machine to be up and running # Starting with a minute - if start_timer > time.time() - (seconds := 60.0): - LOG.info( - f"Waiting for the virtual machine to be ready. Remaining {(seconds - (time.time() - start_timer)):.1f} seconds..." - ) - + if start_timer > time.time() - (seconds := 30): for machine in incus_list: if machine["type"] != "virtual-machine": continue - rebooting: bool = False cmd: str = "whoami" # Should works on most OS while start_timer > time.time() - seconds: # Avoid spamming too much, sleeping for a second between each request. @@ -236,20 +231,12 @@ def deploy( ) start_timer = time.time() case 0: - if not rebooting: - LOG.debug( - f"Remaining {(seconds - (time.time() - start_timer)):.1f} seconds..." - ) - else: - LOG.info("Agent is up and running!") - break + LOG.info("Agent is up and running!") + break case _: - # Once the virtual machine rebooted once, set the timer to 30 minutes. - if not rebooting: - LOG.info( - "Virtual machine is most likely rebooting. Once the agent is back up, let's move on." - ) - rebooting = True + LOG.info( + f"Waiting for the virtual machine to be ready. Remaining {(seconds - (time.time() - start_timer)):.1f} seconds..." + ) run_ansible_playbook( remote=remote, production=production, track=track.name, path=path diff --git a/ctf/destroy.py b/ctf/destroy.py index cca05e4..dda8fa7 100644 --- a/ctf/destroy.py +++ b/ctf/destroy.py @@ -3,6 +3,7 @@ import subprocess import typer +from pydantic import ValidationError from typing_extensions import Annotated from ctf import ENV @@ -138,17 +139,19 @@ def destroy( ) } - networks = { - Track(name=network["name"]) - for network in json.loads( - s=subprocess.run( - args=["incus", "network", "list", "--format=json"], - check=False, - capture_output=True, - env=ENV, - ).stdout.decode() - ) - } + networks = set() + for network in json.loads( + s=subprocess.run( + args=["incus", "network", "list", "--format=json"], + check=False, + capture_output=True, + env=ENV, + ).stdout.decode() + ): + try: + networks.add(Track(name=network["name"])) + except ValidationError: + pass network_acls = { Track(name=network_acl["name"])