Commit 54e74797 authored by Xavier Thompson's avatar Xavier Thompson

software/end-to-end-testing: Switch to nxdtest

parent b527abd1
[instance.cfg]
filename = instance.cfg.in
md5sum = 562e123cefa9e39cbc78300e4643f7b3
md5sum = 0e49345c3b7b7988adf2aaa7c666a415
[runTestSuite.in]
filename = runTestSuite.in
md5sum = 3fab881b3baba3c398b4d89b5ce26542
[test_test.py]
filename = test_test.py
md5sum = c074373dbb4154aa924ef5781dade7a0
[test_kvm.py]
filename = test_kvm.py
md5sum = b6773d5ed283f94d20f38c34b47976da
......@@ -2,11 +2,11 @@
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
extends =
${nxdtest-instance.cfg:output}
parts =
runTestSuite
client.crt
client.key
slapos-client.cfg
.nxdtest
[slap-configuration]
......@@ -25,15 +25,8 @@ bin = $${buildout:directory}/bin
etc = $${buildout:directory}/etc
var = $${buildout:directory}/var
cfg = $${buildout:directory}/.slapos
tmp = $${buildout:directory}/tmp
nxdtest = $${:var}/nxdtest
[runTestSuite]
recipe = slapos.recipe.template
output = $${directory:bin}/runTestSuite
url = ${runTestSuite.in:target}
python_for_test = ${python_for_test:executable}
testdir = $${:var}/tests
nxdtestdir = $${:var}/nxdtest
[client.crt]
......@@ -58,3 +51,52 @@ inline =
[slapconsole]
cert_file = $${client.crt:output}
key_file = $${client.key:output}
[env.sh]
recipe = slapos.recipe.template:jinja2
output = $${directory:cfg}/env.sh
inline =
export HOME=$${directory:home}
[runTestSuite]
# extended from stack/nxdtest
env.sh = $${env.sh:output}
workdir = $${directory:nxdtestdir}
[.nxdtest]
recipe = slapos.recipe.template:jinja2
output = $${runTestSuite:workdir}/.nxdtest
python_for_test = ${python_for_test:executable}
tests =
$${test_test.py:output}
$${test_kvm.py:output}
context =
key tests :tests
key python_for_test :python_for_test
inline =
import os
tests = {{ repr(tests) }}
for test in tests.splitlines():
directory, filename = os.path.split(test)
name, _ = os.path.splitext(filename)
TestCase(
name,
[{{ repr(python_for_test) }} , '-m', 'unittest', '-v', name],
cwd=directory,
summaryf=UnitTest.summary,
)
[test_test.py]
recipe = slapos.recipe.template
output = $${directory:testdir}/test_test.py
url = ${test_test.py:target}
[test_kvm.py]
recipe = slapos.recipe.template
output = $${directory:testdir}/test_kvm.py
url = ${test_kvm.py:target}
[buildout]
extends =
../../component/pygolang/buildout.cfg
../../stack/slapos.cfg
../../stack/nxdtest.cfg
buildout.hash.cfg
parts =
......@@ -14,24 +16,23 @@ output = ${buildout:directory}/instance.cfg
url = ${:_profile_base_location_}/${:filename}
[runTestSuite.in]
[test_test.py]
recipe = slapos.recipe.build:download
output = ${buildout:directory}/${:filename}
url = ${:_profile_base_location_}/${:filename}
[test_one.py]
[test_kvm.py]
recipe = slapos.recipe.build:download
output = ${buildout:directory}/${:filename}
url = ${:_profile_base_location_}/${:filename}
[python_for_test]
recipe = zc.recipe.egg
<= python-interpreter
interpreter = python_for_test
scripts = ${:interpreter}
executable = ${buildout:bin-directory}/${:interpreter}
depends = ${lxml-python:egg}
eggs =
${pygolang:egg}
slapos.core
erp5.util
#!${:python_for_test}
import argparse
import configparser
import importlib
import json
import logging
import time
import unittest
import erp5.util.taskdistribution
import slapos.client
class EndToEndResult(unittest.TextTestResult):
def __init__(self, stream, descriptions, verbosity):
self.durations = []
super().__init__(stream, descriptions, verbosity)
def startTest(self, test):
self._startTime = time.perf_counter()
def stopTest(self, test):
stopTime = time.perf_counter()
self.durations.append((test, stopTime - self._startTime))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--test_suite')
parser.add_argument('--test_suite_title')
parser.add_argument('--test_node_title')
parser.add_argument('--project_title')
parser.add_argument('--revision')
parser.add_argument('--master_url')
args, _ = parser.parse_known_args() # ignore other arguments
if not args.master_url:
unittest.main() # exits
module = importlib.import_module(__name__)
suite = unittest.defaultTestLoader.loadTestsFromModule(module)
all_tests = [t for s in suite for t in s]
runner = unittest.TextTestRunner(resultclass=EndToEndResult)
result = runner.run(suite)
errors = dict(result.errors)
failures = dict(result.failures)
skipped = dict(result.skipped)
# TODO: unexpected successes and expected failures
durations = dict(result.durations)
print(errors)
print(failures)
print(skipped)
print(durations)
# Create test lines at the end to reduce race conditions on multiple testnodes
task_distributor = erp5.util.taskdistribution.TaskDistributor(
portal_url=args.master_url
)
test_result = task_distributor.createTestResult(
revision = args.revision,
test_name_list = [t.id() for t in all_tests],
node_title = args.test_node_title,
test_title = args.test_suite_title,
project_title = args.project_title,
)
if test_result is None:
print("A test result has already been completed")
print("Nothing to do")
return
for t in all_tests:
kind = [errors, failures, skipped]
count = [0, 0, 0]
output = 'OK'
for i in range(len(kind)):
try:
output = kind[i][t]
count[i] = 1
break
except KeyError:
pass
print(t.id())
print(count)
print(output)
test_result_line = test_result.start()
if test_result_line is None:
print("A test result line has already been completed")
print("Nothing to do")
break
test_result_line.stop(
test_count = 1,
error_count = count[0],
failure_count = count[1],
skip_count = count[2],
duration = durations[t],
command = '',
stdout = output,
stderr = '',
html_test_result = '',
)
class EndToEndTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
......@@ -197,14 +96,6 @@ class EndToEndTestCase(unittest.TestCase):
time.sleep(60)
class Test(EndToEndTestCase):
def test_fail(self):
self.assertEqual(0, 1)
def test_succeed(self):
self.assertEqual(0, 0)
class KvmTest(EndToEndTestCase):
def test(self):
# instance_name = time.strftime('e2e-test-kvm-%Y-%B-%d-%H:%M:%S')
......@@ -213,7 +104,3 @@ class KvmTest(EndToEndTestCase):
self.waitUntilGreen(instance_name)
connection_dict = self.request(self.product.kvm, instance_name)
self.assertIn('url', connection_dict)
if __name__ == '__main__':
main()
import unittest
class Test(unittest.TestCase):
def test_fail(self):
self.assertEqual(0, 1)
def test_succeed(self):
self.assertEqual(0, 0)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment