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

Automatically release and power-off maas nodes at the end of a job #382

Merged
merged 2 commits into from
Nov 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ AGENT=$(echo $agent_id | sed 's/-\([0-9]*\)$/\1/g')
PROVISION_TYPE="$provision_type"

echo Cleaning up container if it exists... && docker rm -f $AGENT || /bin/true
. /srv/testflinger-agent/$AGENT/env/bin/activate && PYTHONUNBUFFERED=1 testflinger-device-connector $PROVISION_TYPE cleanup -c /srv/testflinger-agent/$AGENT/default.yaml testflinger.json

Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ def provision(self, args):
except ProvisioningError as err:
logger.error("Provisioning failed: %s", str(err))
raise
except Exception as e:
raise e
finally:
serial_proc.stop()
logger.info("END provision")
logger.info("END provision")

def cleanup(self, args):
device = Maas2(args.config, args.job_data)
try:
device.cleanup()
except ProvisioningError as err:
logger.error("Provisioning failed: %s", str(err))
raise
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def _logger_critical(self, message):
def recover(self):
self._logger_info("Releasing node {}".format(self.agent_name))
self.node_release()
self._logger_info(
"Successfully released node {}".format(self.agent_name)
)

def provision(self):
if self.config.get("reset_efi"):
Expand All @@ -83,6 +86,10 @@ def provision(self):
storage_data = provision_data.get("disks")
self.deploy_node(distro, kernel, user_data, storage_data)

def cleanup(self):
"""Try to release the node in maas at the end of the job."""
self.recover()

def _install_efitools_snap(self):
cmd = [
"ssh",
Expand Down Expand Up @@ -391,8 +398,8 @@ def node_release(self):
cmd = ["maas", self.maas_user, "machine", "release", self.node_id]
subprocess.run(cmd, check=False)
# Make sure the device is available before returning
for _ in range(0, 10):
time.sleep(5)
for _ in range(0, 30):
time.sleep(10)
status = self.node_status()
if status == "Ready":
return
Expand Down