Skip to content

Commit

Permalink
Sweep abandoned jails from temporary test pools
Browse files Browse the repository at this point in the history
  • Loading branch information
jonct committed Aug 10, 2024
1 parent 977f9f7 commit 5ec22c1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
from pathlib import Path
from subprocess import run, PIPE, STDOUT, CalledProcessError
from tempfile import NamedTemporaryFile, TemporaryDirectory
from time import sleep

SUDO = '/usr/bin/sudo'
ZPOOL = '/sbin/zpool'
ZFS = '/sbin/zfs'
MACHINECTL = '/usr/bin/machinectl'


class TemporaryPool(AbstractContextManager):
Expand Down Expand Up @@ -52,8 +54,30 @@ def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
for straggler in self.find_running_stragglers():
print(f'⚠️ Terminating {straggler}', file=sys.stderr)
run([SUDO, MACHINECTL, 'terminate', straggler], check=False)
for tries in range(10):
attempt = run([MACHINECTL, 'show', straggler],
capture_output=True, check=False)
if not attempt.stdout:
break
sleep(0.5)
run([SUDO, ZFS, 'destroy', '-r', self.name], check=False)

def find_running_stragglers(self):
machinelist = run([MACHINECTL, 'list', '--no-legend'],
capture_output=True, check=False)
for listing in machinelist.stdout.decode().splitlines():
machinename = listing.partition(' ')[0]
lookup = run([MACHINECTL, 'show',
'-p', 'RootDirectory', '--value',
machinename],
capture_output=True, check=False)
machinepath = lookup.stdout.decode()
if machinepath.startswith(str(self.path)):
yield machinename


def run_test(path):
with (
Expand Down

0 comments on commit 5ec22c1

Please sign in to comment.