Compare commits

...

6 Commits

Author SHA1 Message Date
1a9bd09788 Fix completion for all nodes 2022-10-27 15:31:05 +00:00
b7859189eb Add check if node is registered
Avoids reprovisioning existing nodes until they are manually removed
from the database.
2022-10-26 18:10:30 +00:00
ddccc91645 Revert incorrect reference call and use right data 2022-10-26 14:53:04 +00:00
2b180bd5c4 Correct returns for copy and script execution 2022-10-26 14:41:06 +00:00
c0b868896e Fix incorrect class reference 2022-10-26 13:54:39 +00:00
f02b128284 Handle return codes from paramiko commands 2022-10-25 21:17:12 +00:00
3 changed files with 57 additions and 21 deletions

View File

@@ -69,6 +69,7 @@ def run_hook_osddb(config, targets, args):
stdin, stdout, stderr = c.exec_command(pvc_cmd_string) stdin, stdout, stderr = c.exec_command(pvc_cmd_string)
logger.debug(stdout.readlines()) logger.debug(stdout.readlines())
logger.debug(stderr.readlines()) logger.debug(stderr.readlines())
return stdout.channel.recv_exit_status()
def run_hook_osd(config, targets, args): def run_hook_osd(config, targets, args):
@@ -98,6 +99,7 @@ def run_hook_osd(config, targets, args):
stdin, stdout, stderr = c.exec_command(pvc_cmd_string) stdin, stdout, stderr = c.exec_command(pvc_cmd_string)
logger.debug(stdout.readlines()) logger.debug(stdout.readlines())
logger.debug(stderr.readlines()) logger.debug(stderr.readlines())
return stdout.channel.recv_exit_status()
def run_hook_pool(config, targets, args): def run_hook_pool(config, targets, args):
@@ -127,7 +129,7 @@ def run_hook_pool(config, targets, args):
logger.debug(stderr.readlines()) logger.debug(stderr.readlines())
# This only runs once on whatever the first node is # This only runs once on whatever the first node is
break return stdout.channel.recv_exit_status()
def run_hook_network(config, targets, args): def run_hook_network(config, targets, args):
@@ -191,7 +193,7 @@ def run_hook_network(config, targets, args):
logger.debug(stderr.readlines()) logger.debug(stderr.readlines())
# This only runs once on whatever the first node is # This only runs once on whatever the first node is
break return stdout.channel.recv_exit_status()
def run_hook_copy(config, targets, args): def run_hook_copy(config, targets, args):
@@ -217,11 +219,14 @@ def run_hook_copy(config, targets, args):
tc.chmod(dfile, int(dmode, 8)) tc.chmod(dfile, int(dmode, 8))
tc.close() tc.close()
return 0
def run_hook_script(config, targets, args): def run_hook_script(config, targets, args):
""" """
Run a script on the targets Run a script on the targets
""" """
return_status = 0
for node in targets: for node in targets:
node_name = node.name node_name = node.name
node_address = node.host_ipaddr node_address = node.host_ipaddr
@@ -272,6 +277,10 @@ def run_hook_script(config, targets, args):
stdin, stdout, stderr = c.exec_command(remote_command) stdin, stdout, stderr = c.exec_command(remote_command)
logger.debug(stdout.readlines()) logger.debug(stdout.readlines())
logger.debug(stderr.readlines()) logger.debug(stderr.readlines())
if stdout.channel.recv_exit_status() != 0:
return_status = stdout.channel.recv_exit_status()
return return_status
def run_hook_webhook(config, targets, args): def run_hook_webhook(config, targets, args):
@@ -345,7 +354,9 @@ def run_hooks(config, cspec, cluster, nodes):
# Run the hook function # Run the hook function
try: try:
notifications.send_webhook(config, "begin", f"Cluster {cluster.name}: Running hook task '{hook_name}'") notifications.send_webhook(config, "begin", f"Cluster {cluster.name}: Running hook task '{hook_name}'")
hook_functions[hook_type](config, target_nodes, hook_args) retcode = hook_functions[hook_type](config, target_nodes, hook_args)
if retcode > 0:
raise Exception(f"Hook returned with code {retcode}")
notifications.send_webhook(config, "success", f"Cluster {cluster.name}: Completed hook task '{hook_name}'") notifications.send_webhook(config, "success", f"Cluster {cluster.name}: Completed hook task '{hook_name}'")
except Exception as e: except Exception as e:
logger.warning(f"Error running hook: {e}") logger.warning(f"Error running hook: {e}")

View File

@@ -84,3 +84,16 @@ def set_boot_state(config, cspec, data, state):
db.update_node_state(config, cspec_cluster, cspec_hostname, state) db.update_node_state(config, cspec_cluster, cspec_hostname, state)
node = db.get_node(config, cspec_cluster, name=cspec_hostname) node = db.get_node(config, cspec_cluster, name=cspec_hostname)
logger.debug(node) logger.debug(node)
def set_completed(config, cspec, cluster):
nodes = list()
for bmc_macaddr in cspec["bootstrap"]:
if cspec["bootstrap"][bmc_macaddr]["node"]["cluster"] == cluster:
nodes.append(cspec["bootstrap"][bmc_macaddr])
for node in nodes:
cspec_cluster = node["node"]["cluster"]
cspec_hostname = node["node"]["hostname"]
db.update_node_state(config, cspec_cluster, cspec_hostname, "completed")
node = db.get_node(config, cspec_cluster, name=cspec_hostname)
logger.debug(node)

View File

@@ -50,7 +50,23 @@ def dnsmasq_checkin(config, data):
) )
cspec = git.load_cspec_yaml(config) cspec = git.load_cspec_yaml(config)
is_in_bootstrap_map = True if data["macaddr"] in cspec["bootstrap"] else False is_in_bootstrap_map = True if data["macaddr"] in cspec["bootstrap"] else False
try:
if is_in_bootstrap_map: if is_in_bootstrap_map:
cspec_cluster = cspec["bootstrap"][data["macaddr"]]["node"]["cluster"]
is_registered = True if data["macaddr"] in [x.bmc_macaddr for x in db.get_nodes_in_cluster(config, cspec_cluster)] else False
else:
is_registered = False
except Exception:
is_registered = False
if not is_in_bootstrap_map:
logger.warn(f"Device '{data['macaddr']}' not in bootstrap map; ignoring.")
return
if is_registered:
logger.info(f"Device '{data['macaddr']}' has already been bootstrapped; ignoring.")
return
notifications.send_webhook(config, "info", f"New host checkin from MAC {data['macaddr']} as host {cspec['bootstrap'][data['macaddr']]['node']['fqdn']} in cluster {cspec['bootstrap'][data['macaddr']]['node']['cluster']}") notifications.send_webhook(config, "info", f"New host checkin from MAC {data['macaddr']} as host {cspec['bootstrap'][data['macaddr']]['node']['fqdn']} in cluster {cspec['bootstrap'][data['macaddr']]['node']['cluster']}")
if ( if (
cspec["bootstrap"][data["macaddr"]]["bmc"].get("redfish", None) cspec["bootstrap"][data["macaddr"]]["bmc"].get("redfish", None)
@@ -66,8 +82,6 @@ def dnsmasq_checkin(config, data):
logger.info(f"Is device '{data['macaddr']}' Redfish capable? {is_redfish}") logger.info(f"Is device '{data['macaddr']}' Redfish capable? {is_redfish}")
if is_redfish: if is_redfish:
redfish.redfish_init(config, cspec, data) redfish.redfish_init(config, cspec, data)
else:
logger.warn(f"Device '{data['macaddr']}' not in bootstrap map; ignoring.")
return return
@@ -140,9 +154,7 @@ def host_checkin(config, data):
hooks.run_hooks(config, cspec, cluster, ready_nodes) hooks.run_hooks(config, cspec, cluster, ready_nodes)
target_state = "completed" host.set_completed(config, cspec, cluster)
for node in all_nodes:
host.set_boot_state(config, cspec, data, target_state)
# Hosts will now power down ready for real activation in production # Hosts will now power down ready for real activation in production
sleep(60) sleep(60)