Skip to content

Commit ce43e34

Browse files
committed
Log boot.py exceptions
If boot.py fails with an exception, log it to syslog. In case the exception is failing to remove the hostname file, it just means the node isn't marked for reinstallation, so in this case log severity is INFO. In case some other exception occurs, it's probably a more serious error, and in that case the severity is ERR.
1 parent ced836c commit ce43e34

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

files/boot.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@
33
import os
44
import socket
55
import json
6+
import syslog
67
sys.stderr = sys.stdout
78
print "Content-Type: text/plain"
89
print
910

11+
def pxe_abort():
12+
"""Abort the PXE boot, continue with the next boot device in the BIOS boot order"""
13+
print "#!ipxe"
14+
print "exit"
15+
sys.exit(0)
16+
1017
try:
1118
# from the name, e.g. c1-3 take c1-3
1219
hostname = socket.gethostbyaddr(os.environ["REMOTE_ADDR"])[0].split(".")[0]
1320

14-
os.remove("/var/www/provision/reinstall/" + hostname)
21+
try:
22+
os.remove("/var/www/provision/reinstall/" + hostname)
23+
except OSError as e:
24+
syslog.syslog(syslog.LOG_INFO, str(e))
25+
pxe_abort()
26+
1527
with open('/var/www/provision/nodes/pxe_nodes.json') as f:
1628
j = json.load(f)
1729
nodesettings = j[hostname]
@@ -25,6 +37,6 @@
2537
print "initrd http://" + nodesettings["kickstart_server_ip"] + "/ks/initrd.img"
2638
print "boot"
2739

28-
except:
29-
print "#!ipxe"
30-
print "exit"
40+
except Exception as e:
41+
syslog.syslog(syslog.LOG_ERR, str(e))
42+
pxe_abort()

0 commit comments

Comments
 (0)