nodelist = filter(this_plc, self.config.nodes.values())
slicelist = filter(this_plc, self.config.slices.values())
personlist = filter(this_plc, self.config.persons.values())
+ nodegrouplist = filter(this_plc, self.config.nodegroups.values())
# Add Test site
for site in sitelist:
site_id = api.AddSite(auth, dict(site))
site['site_id'] = site_id
if self.config.verbose:
- utils.header("Added site: %s" % site['name'])
+ utils.header("Added site: %s" % site['name'], logfile = self.config.logfile)
else:
site.update(sites[0])
if self.config.verbose:
- utils.header("Site %s found" % site['name'])
+ utils.header("Site %s found" % site['name'], logfile = self.config.logfile)
+
+ # Add Nodegroups
+ for nodegroup in nodegrouplist:
+ nodegroups = api.GetNodeGroups(auth, [nodegroup['name']])
+ if not nodegroups:
+ nodegroup_id = api.AddNodeGroup(auth, dict(nodegroup))
+ nodegroup['nodegroup_id'] = nodegroup_id
+ if self.config.verbose:
+ utils.header("Added Nodegroup: %s " % nodegroup['name'], logfile = self.config.logfile)
+ else:
+ nodegroup.update(nodegroups[0])
+ if self.config.verbose:
+ utils.header("Nodegroup %s found" % nodegroup['name'], logfile = self.config.logfile)
# Add Test nodes
for node in nodelist:
node_id = api.AddNode(auth, node['site'], dict(node))
node['node_id'] = node_id
if self.config.verbose:
- utils.header("Added node: %s" % node['hostname'])
+ utils.header("Added node: %s" % node['hostname'], logfile = self.config.logfile)
else:
node.update(nodes[0])
if self.config.verbose:
- utils.header("Node %s found" % node['hostname'])
+ utils.header("Node %s found" % node['hostname'], logfile = self.config.logfile)
# Add node network
if 'nodenetwork_ids' not in node or not node['nodenetwork_ids']:
for nodenetwork in node['nodenetworks']:
nodenetwork_id = api.AddNodeNetwork(auth, node['hostname'], dict(nodenetwork))
if self.config.verbose:
- utils.header("Added nodenetwork to %s" % node['hostname'])
+ utils.header("Added nodenetwork to %s" % node['hostname'], logfile = self.config.logfile)
else:
if self.config.verbose:
- utils.header("Nodenetwork found on node %s" % node['hostname'])
+ utils.header("Nodenetwork found on node %s" % node['hostname'], logfile = self.config.logfile)
+ # Add node to nodegroups
+ if 'nodegroups' in node:
+ for nodegroup in node['nodegroups']:
+ api.AddNodeToNodeGroup(auth, node['hostname'], nodegroup)
+ if self.config.verbose:
+ utils.header("Added %s to nodegroup %s" % (node['hostname'], node['nodegroups']))
# Add Test slice
for slice in slicelist:
slice_id = api.AddSlice(auth, dict(slice))
slice['slice_id'] = slice_id
if self.config.verbose:
- utils.header("Added slice: %s" % slice['name'])
+ utils.header("Added slice: %s" % slice['name'], logfile = self.config.logfile)
else:
slice.update(slices[0])
if self.config.verbose:
- utils.header("Slice %s found" % slice['name'])
+ utils.header("Slice %s found" % slice['name'], logfile = self.config.logfile)
# Add slice to nodes
for node in slice['nodes']:
api.AddSliceToNodes(auth, slice['name'], [node])
if self.config.verbose:
- utils.header("Added slice to %s" % node)
+ utils.header("Added slice to %s" % node, logfile = self.config.logfile)
# Add test person
for person in personlist:
person['person_id'] = person_id
api.UpdatePerson(auth, person_id, {'enabled': True})
if self.config.verbose:
- utils.header("Added person: %s" % person['email'])
+ utils.header("Added person: %s" % person['email'], logfile = self.config.logfile)
else:
person.update(persons[0])
if self.config.verbose:
- utils.header("Person %s found" % person['email'])
+ utils.header("Person %s found" % person['email'], logfile = self.config.logfile)
# Add roles to person
for role in roles:
api.AddRoleToPerson(auth, role, person['email'])
if self.config.verbose:
- utils.header("Added %s to %s" % (role, person['email']))
+ utils.header("Added %s to %s" % (role, person['email']), logfile = self.config.logfile)
# Add person to site
for site in person['sites']:
api.AddPersonToSite(auth, person['email'], site)
if self.config.verbose:
- utils.header("Added %s to %s" % (person['email'], site))
+ utils.header("Added %s to %s" % (person['email'], site), logfile = self.config.logfile)
# Add person to slice
for slice in person['slices']:
api.AddPersonToSlice(auth, person['email'], slice)
if self.config.verbose:
- utils.header("Added %s to %s" % (person['email'], slice))
+ utils.header("Added %s to %s" % (person['email'], slice), logfile = self.config.logfile)
return 1
if __name__ == '__main__':
node = nodes[0]
boot_state = node['boot_state']
if True or self.config.verbose:
- utils.header("%(hostname)s boot_state is %(boot_state)s" % locals(), False)
+ utils.header("%(hostname)s boot_state is %(boot_state)s" % locals(), False, self.config.logfile)
if boot_state in ['boot']:
self.exit = True
if self.config.verbose:
if boot_state in ['boot']:
- utils.header("%(hostname)s correctly installed and booted" % locals(), False)
+ utils.header("%(hostname)s correctly installed and booted" % locals(), False, self.config.logfile)
else:
- utils.header("%(hostname)s not fully booted" % locals(), False)
+ utils.header("%(hostname)s not fully booted" % locals(), False, self.config.logfile)
self.boot_state = boot_state
return self.exit
# for now just print it out
for line in lines:
print line
- utils.header(line)
+ utils.header(line, logfile = self.config.logfile)
# should be parsing for special strings that indicate whether
# we've reached a particular state within the boot sequence
# try reinstalling the node if it is in debug state
if node['boot_state'] in ['dbg']:
if self.config.verbose:
- utils.header("%(hostname)s is in debug state. Attempting a re-install" % locals())
+ utils.header("%(hostname)s is in debug state. Attempting a re-install" % locals(), logfile = self.config.logfiile)
api.UpdateNode(auth, node['node_id'], {'boot_state': 'rins'})
# Create boot image
if self.config.verbose:
- utils.header("Creating bootcd for %(hostname)s at %(bootimage_path)s" % locals())
+ utils.header("Creating bootcd for %(hostname)s at %(bootimage_path)s" % locals(), logfile = self.config.logfile)
nodeimage = api.GetBootMedium(auth, hostname, image_type, '', ['serial'])
fp = open(bootimage_tmppath, 'w')
fp.write(base64.b64decode(nodeimage))
# Move the boot image to the nodes home directory
node.host_commands("mkdir -p %(homedir)s" % locals())
node.scp_to_host(bootimage_tmppath, "%(remote_bootimage_path)s" % locals())
+
+ # If node is vm (qemu) try installing kqemu
+ node.host_commands("yum -y install kqemu", False)
+ node.host_commands("modprobe kqemu")
# Create a temporary disk image if it doesnt already exist or we are reinstalling
img_check_cmd = "ls -ld %(diskimage)s" % locals()
if self.config.verbose:
- utils.header("Booting %(hostname)s" % locals())
+ utils.header("Booting %(hostname)s" % locals(), logfile = self.config.logfile)
# Attempt to boot this node image
# occured, or we've reached our totaltime out
def catch(sig, frame):
self.totaltime = self.totaltime -1
- utils.header("beep %d\n" %self.totaltime, False)
+ utils.header("beep %d\n" %self.totaltime, False, logfile = self.config.logfile )
total = self.totaltime
if (total == 0) or \
(((total % 60)==0) and self.state_nanny()):
object['plc'] == None
sitelist = filter(this_plc, self.config.sites.values())
+ nodegrouplist = filter(this_plc, self.config.nodegroups.values())
# Deleting the site should delete everything associated with it
# including nodes, persons
try:
api.DeleteSite(auth, site['login_base'])
if self.config.verbose:
- utils.header("Test data deleted")
+ utils.header("Test data deleted", logfile = self.config.logfile)
except:
if self.config.verbose:
- utils.header("Error deleting %s" % site['login_base'])
+ utils.header("Error deleting %s" % site['login_base'], logfile = self.config.logfile)
+ # Delete nodegroups
+ for nodegroup in nodegrouplist:
+ try:
+ api.DeleteNodeGroup(auth, nodegroup['name'])
+ if self.config.verbose:
+ utils.header("NodeGroups deleted", logfile = self.config.logfile)
+ except:
+ if self.config.verbose:
+ utils.header("Error deleting %s" % nodegroup['name'], logfile = self.config.logfile)
return 1
if __name__ == '__main__':
import os, sys
from Test import Test
from qa import utils
+from qa.TestScripts import TestScript, TestScripts
+from qa.logger import Logfile
class node_run_tests(Test):
"""
- Attempt to copy the specified node test files onto a node using
- the plc root key and execute them. If no test files are specified,
+ Attempt to download and execute the specified test scripts onto a node
+ and execute them run them. If no test files are specified,
then all are used.
"""
def call(self, hostname, plcname, tests = None):
-
+
+ node = self.config.get_node(hostname)
+ plc = self.config.get_plc(plcname)
+ plc_ip = plc.update_ip()
node_tests = ['node_cpu_sched.py', 'pf2test.pl']
node_tests_path = self.config.node_tests_path
node_test_files = self.config.node_tests_path
- archive_name = 'tests.tar.gz'
- archive_path = '/tmp/'
- tests_path = '/usr/share/'
- tests_dir = 'tests/'
-
- node = self.config.get_node(hostname)
- plc = self.config.get_plc(plcname)
- plc_ip = plc.update_ip()
+ tests_dir = node['tests_dir']
print >> node.logfile, "Running Node Tests"
# Create tests archive
- if self.config.verbose:
- utils.header("Updating tests archive at %(archive_path)s" % locals())
- utils.commands("mkdir -p %(archive_path)s/%(tests_dir)s" % locals())
- utils.commands("cp -Rf %(node_tests_path)s/* %(archive_path)s/%(tests_dir)s" % locals())
- tar_cmd = "cd %(archive_path)s && tar -czf /%(archive_path)s/%(archive_name)s %(tests_dir)s" % locals()
- print >> node.logfile, tar_cmd
- (status, output) = utils.commands(tar_cmd)
+ (archive_filename, archive_filepath) = self.config.archive_node_tests()
+ archive_dir = archive_filename.split('.tar')[0]
# Copy tests archive to plc's webroot
- if self.config.verbose:
- utils.header("Copying tests archive onto %(plcname)s webroot" % locals())
- plc.scp_to("%(archive_path)s/%(archive_name)s" % locals(), "/var/www/html/")
+ plc.scp_to_webroot("%(archive_filepath)s" % locals())
- if self.config.verbose:
- utils.header("Downloading tests archive onto %(hostname)s" % locals())
- cleanup_cmd = "rm -f %(tests_path)s/%(archive_name)s" % locals()
- print >> node.logfile, cleanup_cmd
- node.commands(cleanup_cmd, False)
- wget_cmd = "wget -nH -P %(tests_path)s http://%(plc_ip)s/%(archive_name)s" % locals()
- print >> node.logfile, wget_cmd
- # Download tests onto
- node.commands(wget_cmd)
-
+ # Download url onto node
+ url = "http://%(plc_ip)s/%(archive_filename)s" % locals()
+ node.wget(url, tests_dir)
+
# Extract tests archive
- tarx_cmd = "cd %(tests_path)s && tar -xzm -f %(archive_name)s" % locals()
+ tarx_cmd = "cd %(tests_dir)s && tar -xzm -f %(archive_filename)s" % locals()
print >> node.logfile, tarx_cmd
node.popen(tarx_cmd)
# Make tests executable
# XX Should find a better way to do this
- chmod_cmd = "cd %s/tests && chmod 755 %s " % (tests_path, " ".join(node_tests) )
+ chmod_cmd = "cd %s/%s && chmod 755 %s " % (tests_dir, archive_dir, " ".join(node_tests) )
print >> node.logfile, chmod_cmd
node.popen(chmod_cmd)
else:
tests = node_tests
+ #tests = self.config.get_node_tests(tests)
# Add full path to test files
- test_files_abs = [node_tests_path + os.sep + file for file in tests]
+ #test_files_abs = [node_tests_path + os.sep + file for file in tests]
results = {}
for test in tests:
if self.config.verbose:
- utils.header("Running %(test)s test on %(hostname)s" % locals())
- command = "cd %(tests_path)s/tests && ./%(test)s" % locals()
- print >> node.logfile, command
- (stdout, stderr) = node.popen(command, False)
- print >> node.logfile, "".join(stdout)
+ utils.header("Running %(test)s test on %(hostname)s" % locals(), logfile = self.config.logfile)
+ script = self.config.get_node_test(test)
- if self.config.verbose:
- if status == 0:
- utils.header("%(test)s Susccessful " % locals())
- else:
- utils.header("%(test)s Failed " % locals())
- utils.header(output)
- results[test] = (stdout, stderr)
+ exe_pre, exe_script, exe_post = None, script['name'], None
+ if script['pre']: exe_pre = script['exe_pre']
+ if script['args']: exe_script = "%s %s" % (script['name'], script['args'])
+ if script['post']: exe_post = script['exe_post']
+
+ # Create a separate logfile for this script
+ logfile = Logfile(self.config.logfile.dir + script['name'] + ".log")
+ for command in [exe_pre, exe_script, exe_post]:
+ if command:
+ command = "cd %(tests_dir)s/%(archive_dir)s && ./%(command)s" % locals()
+ print >> node.logfile, command
+ print >> logfile, command
+
+ # Execute script on node
+ (stdout, stderr) = node.popen(command, False)
+ print >> node.logfile, "".join(stdout)
+ print >> logfile, "".join(stdout)
+ if self.config.verbose:
+ utils.header(stdout, logfile = self.config.logfile)
+ results[test] = (stdout, stderr)
return 1
# Turn off plc (for good measure)
command = "/sbin/service plc stop"
- if self.config.verbose: utils.header(command)
+ if self.config.verbose: utils.header(command, logfile = self.config.logfile)
(status, output) = plc.commands(command)
# mount plc
command = "/sbin/service plc mount"
- if self.config.verbose: utils.header(command)
+ if self.config.verbose: utils.header(command, logfile = self.config.logfile)
(status, output) = plc.commands(command)
# Get plc configuration variables
tmpfconf, tmpfname = tempfile.mkstemp(".config","plc-config-tty", '/usr/tmp/')
tmpfname_parts = tmpfname.split(os.sep)
if self.config.verbose:
- utils.header("generating temporary config file %(tmpfname)s"%locals())
+ utils.header("generating temporary config file %(tmpfname)s"%locals(), logfile = self.config.logfile)
for (option, value) in plc_options:
os.write(tmpfconf, 'e %s\n%s\n' % (option, value))
os.write(tmpfconf,'w\nq\n')
# configure plc
command = "plc-config-tty < %(tmpfname)s" % locals()
- if self.config.verbose: utils.header(command)
+ if self.config.verbose: utils.header(command, logfile = self.config.logfile)
(status, output) = plc.commands(command)
# clean up temporary conf file
# XX use plc instance to copy file
- if self.config.verbose: utils.header("removing %(tmpfname)s"%locals())
+ if self.config.verbose: utils.header("removing %(tmpfname)s"%locals(), logfile = self.config.logfile)
os.unlink(tmpfname)
# umount plc (need to do this optionally, as we do not want this for myplc-native)
command = "/sbin/service plc umount"
- if self.config.verbose: utils.header(command)
+ if self.config.verbose: utils.header(command, logfile = self.config.logfile)
(status, output) = plc.commands(command)
return 1
# Save url
if self.config.verbose:
- utils.header('Saving current myplc url into %s/URL' % url_path)
+ utils.header('Saving current myplc url into %s/URL' % url_path, logfile = self.config.logfile)
fsave=open('%s/URL' % url_path, "w")
fsave.write(url+'\n')
fsave.close()
# Instal myplc from url
if self.config.verbose:
- utils.header('Downloading myplc from url %s' % url)
+ utils.header('Downloading myplc from url %s' % url, logfile = self.config.logfile )
# build commands
url_parts = url.split(os.sep)
yum_install = "yum -y localinstall /tmp/%(rpm_file)s" % locals()
if self.config.verbose:
- utils.header("Trying: %(rpm_install)s" % locals())
+ utils.header("Trying: %(rpm_install)s" % locals(), logfile = self.config.logfile)
try:
(status, output) = plc.commands(rpm_install)
except:
if self.config.verbose:
- utils.header("Trying %(yum_install)s" % locals())
+ utils.header("Trying %(yum_install)s" % locals(), logfile = self.config.logfile)
(status, output) = plc.commands(download_cmd)
(status, output) = plc.commands(yum_install)
plc = self.config.get_plc(plc_name)
command = "/sbin/service plc start "
if self.config.verbose:
- utils.header(command)
+ utils.header(command, logfile = self.config.logfile)
(status, output) = plc.commands(command)
if self.config.verbose:
- utils.header(output)
+ utils.header(output, logfile = self.config.logfile)
return 1
plc = self.config.get_plc(plc_name)
command = " /sbin/service plc stop "
if self.config.verbose:
- utils.header(command)
+ utils.header(command, logfile = self.config.logfile)
(status, output) = plc.commands(command)
if self.config.verbose:
- utils.header(output)
+ utils.header(output, logfile = self.config.logfile)
return 1
command += " && rm -rf /plc/data"
if self.config.verbose:
- utils.header("Removing myplc")
- utils.header("\n".join(command))
+ utils.header("Removing myplc", logfile = self.config.logfile)
+ utils.header("\n".join(command), logfile = self.config.logfile)
(status, output) = plc.commands(command)