Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:StackIQ/stacki into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybruno committed Jun 3, 2016
2 parents 4a08c27 + 73471a3 commit 1cf26d9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/stack/pylib/stack/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def handle_pre(self, node):
(roll, nodefile, color) = self.get_context(node)
pre_attrs = {}
# Collect arguments to the pre section
for this_attr in ['interpreter', 'arg']:
for this_attr in ['interpreter', 'notify', 'arg', 'wait']:
if attr.getNamedItem((None, this_attr)):
pre_attrs[this_attr] = attr.getNamedItem((None, this_attr)).value
self.ks['pre'].append((pre_attrs, self.getChildText(node), roll, nodefile, color))
Expand All @@ -712,7 +712,7 @@ def handle_post(self, node):
(roll, nodefile, color) = self.get_context(node)
post_attrs = {}
# Collect arguments to the post section
for this_attr in ['interpreter', 'arg']:
for this_attr in ['interpreter', 'notify', 'arg', 'wait']:
if attr.getNamedItem((None, this_attr)):
post_attrs[this_attr] = attr.getNamedItem((None, this_attr)).value
self.ks['post'].append((post_attrs, self.getChildText(node), roll, nodefile, color))
Expand Down Expand Up @@ -777,6 +777,28 @@ def generate_pre(self):
log_line = ' --log=/tmp/ks-pre.log %s' % args['arg']
else:
log_line = ' --log=%s' % self.log
if 'wait' in args:
# to be polite, send a notification that we're waiting
notify_script = '/opt/stack/lib/python2.6/site-packages/stack/notify.py'
wait_string = '\n%%pre\nchmod a+x %s\n' % notify_script
waitfile = '/tmp/wait.txt'
msg = 'waiting for %s in %s' % (waitfile, os.path.basename(nodefile))
wait_string += '%s %s\n\n' % (notify_script, msg)
wait_string += 'touch %s\n' % waitfile
wait_string += 'while [ -f %s ]; do\n' % waitfile
wait_string += '\tsleep 2;\ndone\n'
wait_string += '%end\n'
pre_list.append((wait_string, roll, nodefile, color))
# if there's a notify argument, prepend it to text
if 'notify' in args:
msg = args['notify']
# if notify='' --> just use the node.xml filename w/o extension
if not msg:
msg = os.path.splitext(os.path.basename(nodefile))[0]
notify_script = '/opt/stack/lib/python2.6/site-packages/stack/notify.py'
notify_cmd = '\n%%pre\nchmod a+x %s\n' % notify_script
notify_cmd += '%s %s\n\n%%end\n\n' % (notify_script, msg)
pre_list.append((notify_cmd, roll, nodefile, color))
pre_list.append(('%s %s' % (pre_header, log_line), roll, nodefile, color))
pre_list.append((text + '\n',roll, nodefile, color))
pre_list.append(('%end'))
Expand All @@ -803,6 +825,28 @@ def generate_post(self):
log_line = ' %s --log=/mnt/sysimage%s' % (args['arg'], self.log)
else:
log_line = ' --log=%s' % self.log
if 'wait' in args:
# to be polite, send a notification that we're waiting
notify_script = '/opt/stack/lib/python2.6/site-packages/stack/notify.py'
wait_string = '\n%%post --nochroot\nchmod a+x %s\n' % notify_script
waitfile = '/tmp/wait.txt'
msg = 'waiting for %s in %s' % (waitfile, os.path.basename(nodefile))
wait_string += '%s %s\n\n' % (notify_script, msg)
wait_string += 'touch %s\n' % waitfile
wait_string += 'while [ -f %s ]; do\n' % waitfile
wait_string += '\tsleep 2;\ndone\n'
wait_string += '%end\n'
post_list.append((wait_string, roll, nodefile, color))
# if there's a notify argument, prepend the notification code to the text
if 'notify' in args:
msg = args['notify']
# if notify='' --> just use the node.xml filename w/o extension
if not msg:
msg = os.path.splitext(os.path.basename(nodefile))[0]
notify_script = '/opt/stack/lib/python2.6/site-packages/stack/notify.py'
notify_cmd = '\n%%post --nochroot\nchmod a+x %s\n' % notify_script
notify_cmd += '%s %s\n\n%%end\n\n' % (notify_script, msg)
post_list.append((notify_cmd, roll, nodefile, color))
post_list.append(('%s %s' % (post_header, log_line), roll, nodefile, color))
post_list.append((text + '\n',roll, nodefile, color))
post_list.append(('%end'))
Expand Down
16 changes: 16 additions & 0 deletions src/stack/pylib/stack/notify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /opt/stack/bin/python

import sys

def notify(msg):
''' generate some code to collect the contents of notify xml attrs as they are run
TODO: make this code do something useful intead of just append to a file :)
'''
filename = '/tmp/notifications.txt'
with open(filename, "a") as fi:
fi.write(msg + "\n")

if __name__ == '__main__':
# Allow the script to be called from the shell
msg = ' '.join(sys.argv[1:])
notify(msg)

0 comments on commit 1cf26d9

Please sign in to comment.