local test run complete

This commit is contained in:
David Lenwell 2013-10-29 20:36:43 -07:00
parent de403151a9
commit 69eb2fccfd
2 changed files with 51 additions and 57 deletions

View File

@ -109,57 +109,31 @@ def start(args):
clouds(args) clouds(args)
sys.exit(1) sys.exit(1)
# run the damn test
t = Tester(args.cloud_id)
results = t.run_local()
# store the results
test = db.query(Test).filter_by(cloud_id=args.cloud_id).first() test = db.query(Test).filter_by(cloud_id=args.cloud_id).first()
# if cloud doesn't have a test id already or the test id isn't specified
if test is None:
# creat a new test # creat a new test
print 'Adding a new test.' print 'Adding a new test.'
test = Test(args.cloud_id) test = Test(args.cloud_id)
test.config = t.config
#test.config =
db.add(test) db.add(test)
# TODO tie in config generation here
db.commit() db.commit()
print 'test added with id: %s' % test.id print 'test added with id: %s' % test.id
else:
print 'existing test.. loaded it has id: %s ' % test.id
# weather we already have a test or we just loaded it .. we can now check its status # do cleanup and then mark the last status to 'canceled'
# what is the current status? test_result = TestResults()
test_status = db.query(TestStatus).filter_by(test_id=test.id).order_by(TestStatus.id.desc()).first() test_result.test_id = test.id
test_result.blob = result
if test_status is None:
# no entries in the status log.. add 'new' db.add(test_result)
test_status = TestStatus(test.id, 'new')
db.add(test_status)
db.commit() db.commit()
print 'status is: %s' % test_status.message
if test_status.message in ('stalled','failed'):
# stalled: clean up , trigger clean start new test run
print 'Test has stalled or failed and needs to be kicked'
status(args)
elif test_status.message in ('ready','finished','new','canceled'):
#finished, new, canceled: trigger clean start new test run
print 'start clean and run'
test_status = TestStatus(test.id, 'running')
db.add(test_status)
db.commit()
t = Tester(args.cloud_id)
t.run()
elif test_status.message in ('running'):
# running: report the current status
print 'already running '
status(args)
def status(args): def status(args):
"""get the status of a running test """get the status of a running test

View File

@ -16,13 +16,14 @@
import os import os
import sys import sys
import errno import errno
from subprocess import call
from textwrap import dedent from textwrap import dedent
from refstack.common.tempest_config import TempestConfig from refstack.common.tempest_config import TempestConfig
import testrepository.repository.file import testrepository.repository.file
from testrepository import ui from testrepository import ui
from testrepository.commands import run #from testrepository.commands import run
from testrepository.commands import init from testrepository.commands import init
from fabric.api import run
class TestRepositoryUI(ui.AbstractUI): class TestRepositoryUI(ui.AbstractUI):
"""nothing""" """nothing"""
@ -75,10 +76,8 @@ class TestRepositorySource(object):
self._ui.c = self.testr_directory+'tempest.conf' self._ui.c = self.testr_directory+'tempest.conf'
cmd = run.run(self._ui) cmd = run.run(self._ui)
try:
res = cmd.execute() res = cmd.execute()
finally:
os.chdir(here)
def testrepository_last_stream(self): def testrepository_last_stream(self):
@ -133,23 +132,40 @@ class Tester(object):
# setup the repo wrapper.. this creates the repo if its not already there # setup the repo wrapper.. this creates the repo if its not already there
tr = TestRepositorySource(self.test_path) tr = TestRepositorySource(self.test_path)
"""TODO: So this is supposed to use the testr wrapper to trigger a run.. however..
I am completly blocked on how to make it work the right way.. so I am moving on
for now once the congigs are setup and repo initiated it will call a subprocess
run the command .. THEN query the repo for the last set of results and store the
subunit stream.
# run tests # run tests
tr.run() #tr.run()
"""
print "starting test"
call([self.test_path+'runtests.sh']) # replace this
print "finished with tests"
# get back the results # get back the results
result = tr.testrepository_last_stream() result = tr.testrepository_last_stream()
# write results to database maybe .. or return them .. not sure which .. # write results to database maybe .. or return them .. not sure which ..
return result.read() return result.read()
#return None
def write_config(self, path): def write_config(self, path):
"""writes config to path specified""" """writes config to path specified"""
# get the config # get the config
print "writing configs %s" % path print "writing configs %s" % path
output = self.tempest_config.build_config_from_keystone() self.config = self.tempest_config.build_config_from_keystone()
runtests_script = """#!/bin/bash
cd %s
testr run
exit $?""" % path
"""TODO make this cleaner"""
testr_output = """[DEFAULT] testr_output = """[DEFAULT]
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
@ -159,9 +175,13 @@ test_id_option=--load-list $IDFILE
test_list_option=--list test_list_option=--list
group_regex=([^\.]*\.)*""" group_regex=([^\.]*\.)*"""
with open(path+"runtests.sh", "w") as runtests_script_file:
runtests_script_file.write(runtests_script)
os.chmod(path+"runtests.sh", 0744)
with open(path+"tempest.conf", "w") as config_file: with open(path+"tempest.conf", "w") as config_file:
config_file.write(output) config_file.write(self.config)
with open(path+".testr.conf", "w") as testr_config_file: with open(path+".testr.conf", "w") as testr_config_file:
testr_config_file.write(testr_output) testr_config_file.write(testr_output)