X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=scripts%2Fupdate_bios_settings.py;h=a7d6ff12de5f2aa9db9b36d3a03756e75ae7c38f;hb=740cac3c8faefd15997c52531a6d6376d3287b81;hp=3b7f522df2ab7ca6c4b2abf3d7fd727760a9470e;hpb=1049394d7d08b2ac26f2aebd86493a73ce1345eb;p=yaml_builds.git diff --git a/scripts/update_bios_settings.py b/scripts/update_bios_settings.py index 3b7f522..a7d6ff1 100644 --- a/scripts/update_bios_settings.py +++ b/scripts/update_bios_settings.py @@ -1,3 +1,4 @@ + ############################################################################## # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. # # # @@ -24,13 +25,16 @@ def create_node_rcfile(nodes, defaults, j2template, rcfile_suffix): env = jinja2.Environment() env.trim_blocks = True env.lstrip_blocks = True - + with open(j2template) as fd: template = env.from_string(fd.read()) - + if type(nodes) is list: for node in nodes: newnode = dict( defaults.items() + node.items() ) + if not "bios_template" in newnode or not newnode["bios_template"]: + print 'Skipping host {} because of missing or empty key [bios_template]'.format(newnode['name']) + continue data = template.render(yaml=newnode) rcfile = "server-config/"+newnode['name']+rcfile_suffix print rcfile @@ -50,8 +54,9 @@ def create_node_rcfile(nodes, defaults, j2template, rcfile_suffix): if newnode['vendor'] == "HP" or newnode['vendor'] == "HPE": command = '/opt/akraino/redfish/apply_hpejson.sh --rc {0} --template {1} --no-confirm'.format(rcfile, newnode["bios_template"]) if command: - print 'command: {0}'.format(command) - os.system(command) + p=subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, preexec_fn=os.setsid) + print 'process: {} command: {}'.format(p.pid, command) + plist.append(p) ### MAIN ### if len(sys.argv) != 2: @@ -61,13 +66,15 @@ if len(sys.argv) != 2: with open(sys.argv[1]) as f: siteyaml = yaml.safe_load(f) +# list of background processes created +plist = [] + # create set of defaults based on top level ipmi_admin and hardware key/value pairs defaults = dict( siteyaml["ipmi_admin"].items() + siteyaml["hardware"].items() ) # add keys for backward compatibility defaults = dict( [('oob_user',siteyaml['ipmi_admin']['username'])] + defaults.items()) defaults = dict( [('oob_password',siteyaml['ipmi_admin']['password'])] + defaults.items()) -defaults = dict( [('oem',siteyaml['hardware']['vendor'])] + defaults.items()) print 'Using defaults:' for line in yaml.dump(defaults,default_flow_style=False).split('\n'): @@ -79,3 +86,10 @@ if 'masters' in siteyaml: if 'workers' in siteyaml: create_node_rcfile(siteyaml["workers"], defaults, "tools/j2/serverrc_raid.j2", "rc.raid") +# print output from background processes +for p in plist: + print "waiting for process {}".format(p.pid) + exitcode=p.wait() + print 'Process {0} ended with exit code {1}'.format(p.pid, p.returncode) + print p.communicate()[0] +