From f927118f5b1cc748c17e4b681a4aed441a65a6d3 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 8 Jul 2022 19:19:29 +0000 Subject: [PATCH] Refactor completion of cluster configuration Instead of rebooting one final time before shutting down, just shut it down directly after performing hooks. This allows hooks to prestage things like the `--autostart` flag of a VM properly. --- bootstrap-daemon/pvcbootstrapd/lib/hooks.py | 9 --------- bootstrap-daemon/pvcbootstrapd/lib/lib.py | 18 ++++-------------- bootstrap-daemon/pvcbootstrapd/lib/redfish.py | 2 +- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/bootstrap-daemon/pvcbootstrapd/lib/hooks.py b/bootstrap-daemon/pvcbootstrapd/lib/hooks.py index 3b68145..f1591bb 100755 --- a/bootstrap-daemon/pvcbootstrapd/lib/hooks.py +++ b/bootstrap-daemon/pvcbootstrapd/lib/hooks.py @@ -354,13 +354,4 @@ def run_hooks(config, cspec, cluster, nodes): # Wait 5s between hooks sleep(5) - # Restart nodes to complete setup - hook_functions["script"]( - config, - cluster_nodes, - { - "script": "#!/usr/bin/env bash\necho bootstrapped | sudo tee /etc/pvc-install.hooks\nsudo reboot" - }, - ) - notifications.send_webhook(config, "success", f"Cluster {cluster.name}: Completed post-setup hook tasks") diff --git a/bootstrap-daemon/pvcbootstrapd/lib/lib.py b/bootstrap-daemon/pvcbootstrapd/lib/lib.py index 8f78954..7af4807 100755 --- a/bootstrap-daemon/pvcbootstrapd/lib/lib.py +++ b/bootstrap-daemon/pvcbootstrapd/lib/lib.py @@ -140,21 +140,11 @@ def host_checkin(config, data): hooks.run_hooks(config, cspec, cluster, ready_nodes) - elif data["action"] in ["system-boot_completed"]: - # Node has been fully configured and can be shut down for the final time - logger.info(f"Registering post-hooks boot for host {cspec_fqdn}") - notifications.send_webhook(config, "info", f"Cluster {cspec_cluster}: Registering post-hooks boot for host {cspec_fqdn}") - target_state = "booted-completed" + target_state = "completed" + for node in all_nodes: + host.set_boot_state(config, cspec, data, target_state) - host.set_boot_state(config, cspec, data, target_state) - sleep(1) - - all_nodes = db.get_nodes_in_cluster(config, cspec_cluster) - ready_nodes = [node for node in all_nodes if node.state == target_state] - - logger.info(f"Ready: {len(ready_nodes)} All: {len(all_nodes)}") - if len(ready_nodes) >= len(all_nodes): # Hosts will now power down ready for real activation in production - sleep(30) + sleep(60) cluster = db.update_cluster_state(config, cspec_cluster, "completed") notifications.send_webhook(config, "completed", f"Cluster {cspec_cluster}: PVC bootstrap deployment completed") diff --git a/bootstrap-daemon/pvcbootstrapd/lib/redfish.py b/bootstrap-daemon/pvcbootstrapd/lib/redfish.py index 1b81b82..3139272 100755 --- a/bootstrap-daemon/pvcbootstrapd/lib/redfish.py +++ b/bootstrap-daemon/pvcbootstrapd/lib/redfish.py @@ -895,7 +895,7 @@ def redfish_init(config, cspec, data): logger.info("Waiting for completion of node and cluster installation...") # Wait for the system to install and be configured - while node.state != "booted-completed": + while node.state != "completed": sleep(60) # Keep the Redfish session alive session.get(redfish_base_root)