aboutsummaryrefslogtreecommitdiffstats
path: root/selftest
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-06-04 18:44:42 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2020-06-04 20:03:07 +0200
commit166dc10769b9df7c0ea21a9f08e608ad6a56e560 (patch)
tree51c51554a92ece6a77b347ff9be1acfbfbe596f0 /selftest
parent4ddcdaf62cde56137fd096d122b9bccdd7466cc3 (diff)
testenv: Support test overlaying a directory to look for templates
This way tests which require a very specific config file can override specific template files used by object classes. Change-Id: I65d1b1e826d2d430ee83810d998b98d0ccaa07cd
Diffstat (limited to 'selftest')
-rw-r--r--selftest/suite_test/suite_test.ok104
-rw-r--r--selftest/suite_test/suite_test.ok.ign1
-rwxr-xr-xselftest/suite_test/suite_test.py7
-rw-r--r--selftest/suite_test/suitedirB/suiteC/mytemplatedir/.gitignore6
-rw-r--r--selftest/suite_test/suitedirB/suiteC/suite.conf6
-rw-r--r--selftest/suite_test/suitedirB/suiteC/test_template_overlay.py44
6 files changed, 168 insertions, 0 deletions
diff --git a/selftest/suite_test/suite_test.ok b/selftest/suite_test/suite_test.ok
index fee07d0..a7c6422 100644
--- a/selftest/suite_test/suite_test.ok
+++ b/selftest/suite_test/suite_test.ok
@@ -619,5 +619,109 @@ PASS: test_suite (pass: 1, skip: 6)
skip: test_fail.py
skip: test_fail_raise.py
pass: test_suite_params.py (N.N sec)
+- test with template overlay
+cnf suiteC: DBG: reading suite.conf [suite.py:[LINENR]]
+
+---------------------------------------------------------------------
+trial suiteC
+---------------------------------------------------------------------
+tst suiteC: reserving resources in [PATH]/selftest/suite_test/test_work/state_dir ... [suite.py:[LINENR]]
+tst suiteC: DBG: {combining='resources'} [suite.py:[LINENR]]
+tst {combining_scenarios='resources'}: DBG: {definition_conf={ip_address=[{'addr': '10.42.42.2'}]}} [suiteC↪{combining_scenarios='resources'}] [suite.py:[LINENR]]
+tst suiteC: DBG: {combining='modifiers'} [suite.py:[LINENR]]
+tst {combining_scenarios='modifiers'}: DBG: {definition_conf={}} [suiteC↪{combining_scenarios='modifiers'}] [suite.py:[LINENR]]
+tst suiteC: Reserving 1 x ip_address (candidates: 3) [resource.py:[LINENR]]
+tst suiteC: DBG: Picked - _hash: fd103b22c7cf2480d609150e06f4bbd92ac78d8c
+ addr: 10.42.42.2
+ [resource.py:[LINENR]]
+
+----------------------------------------------
+trial suiteC test_template_overlay.py
+----------------------------------------------
+tst test_template_overlay.py:[LINENR]: - Testing: expect to fail on invalid templates overlay dir [suiteC↪test_template_overlay.py:[LINENR]] [test_template_overlay.py:[LINENR]]
+tst test_template_overlay.py:[LINENR]: sucess: setting non-existing templates dir raised RuntimeError [suiteC↪test_template_overlay.py:[LINENR]] [test_template_overlay.py:[LINENR]]
+tst test_template_overlay.py:[LINENR]: [suiteC↪test_template_overlay.py:[LINENR]] [test_template_overlay.py:[LINENR]]
+--- ReservedResources: DBG: requesting use of ip_address {specifics={}} [resource.py:[LINENR]]
+tst suiteC: Using 1 x ip_address (candidates: 1) [resource.py:[LINENR]]
+tst suiteC: DBG: Picked - _hash: fd103b22c7cf2480d609150e06f4bbd92ac78d8c
+ _reserved_by: suiteC-[ID_NUM]-[ID_NUM]
+ addr: 10.42.42.2
+ [resource.py:[LINENR]]
+--- ReservedResources: DBG: {available=1} [resource.py:[LINENR]]
+--- ReservedResources: DBG: {using={_hash='fd103b22c7cf2480d609150e06f4bbd92ac78d8c', _reserved_by='suiteC-[ID_NUM]-[ID_NUM]', addr='10.42.42.2'}} [resource.py:[LINENR]]
+tst test_template_overlay.py:[LINENR]: - Testing: original template [suiteC↪test_template_overlay.py:[LINENR]] [test_template_overlay.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: {config_file='test_trial_tmp/test_run_6/suiteC/test_template_overlay.py/osmo-stp_10.42.42.2/osmo-stp.cfg'} [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+tst suiteC: DBG: {combining='config'} [suite.py:[LINENR]]
+tst {combining_scenarios='config'}: DBG: {definition_conf={}} [suiteC↪{combining_scenarios='config'}] [suite.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: STP CONFIG:
+{'stp': {'ip_address': {'_hash': 'fd103b22c7cf2480d609150e06f4bbd92ac78d8c',
+ '_reserved_by': 'suiteC-[ID_NUM]-[ID_NUM]',
+ '_used': True,
+ 'addr': '10.42.42.2'}}} [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+cnf Templates: DBG: rendering osmo-stp.cfg.tmpl [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪Templates] [template.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: ! Configuration rendered by osmo-gsm-tester
+log stderr
+ logging filter all 1
+ logging color 1
+ logging print category 1
+ logging print extended-timestamp 1
+ logging level set-all debug
+line vty
+ no login
+ bind 10.42.42.2
+!ctrl
+! bind 10.42.42.2
+cs7 instance 0
+ xua rkm routing-key-allocation dynamic-permitted
+ listen m3ua 2905
+ accept-asp-connections dynamic-permitted
+ local-ip 10.42.42.2
+ [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+tst test_template_overlay.py:[LINENR]: - Testing:overlay template [suiteC↪test_template_overlay.py:[LINENR]] [test_template_overlay.py:[LINENR]]
+tst test_template_overlay.py:[LINENR]: - After creating the new template, still old template is used [suiteC↪test_template_overlay.py:[LINENR]] [test_template_overlay.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: {config_file='test_trial_tmp/test_run_6/suiteC/test_template_overlay.py/osmo-stp_10.42.42_2.2/osmo-stp.cfg'} [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: STP CONFIG:
+{'stp': {'ip_address': {'_hash': 'fd103b22c7cf2480d609150e06f4bbd92ac78d8c',
+ '_reserved_by': 'suiteC-[ID_NUM]-[ID_NUM]',
+ '_used': True,
+ 'addr': '10.42.42.2'}}} [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+cnf Templates: DBG: rendering osmo-stp.cfg.tmpl [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪Templates] [template.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: ! Configuration rendered by osmo-gsm-tester
+log stderr
+ logging filter all 1
+ logging color 1
+ logging print category 1
+ logging print extended-timestamp 1
+ logging level set-all debug
+line vty
+ no login
+ bind 10.42.42.2
+!ctrl
+! bind 10.42.42.2
+cs7 instance 0
+ xua rkm routing-key-allocation dynamic-permitted
+ listen m3ua 2905
+ accept-asp-connections dynamic-permitted
+ local-ip 10.42.42.2
+ [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+tst test_template_overlay.py:[LINENR]: - New template is used after re-generating cache with set_overlay_template_dir: [suiteC↪test_template_overlay.py:[LINENR]] [test_template_overlay.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: {config_file='test_trial_tmp/test_run_6/suiteC/test_template_overlay.py/osmo-stp_10.42.42_3.2/osmo-stp.cfg'} [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: STP CONFIG:
+{'stp': {'ip_address': {'_hash': 'fd103b22c7cf2480d609150e06f4bbd92ac78d8c',
+ '_reserved_by': 'suiteC-[ID_NUM]-[ID_NUM]',
+ '_used': True,
+ 'addr': '10.42.42.2'}}} [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+cnf Templates: DBG: rendering osmo-stp.cfg.tmpl [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪Templates] [template.py:[LINENR]]
+run osmo-stp_10.42.42.2: DBG: ! Overlay Config file genreated by test
+line vty
+ no login
+ bind 10.42.42.2
+ [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2] [stp_osmo.py:[LINENR]]
+tst test_template_overlay.py:[LINENR] Test passed (N.N sec) [suiteC↪test_template_overlay.py] [test.py:[LINENR]]
+---------------------------------------------------------------------
+trial suiteC PASS
+---------------------------------------------------------------------
+PASS: suiteC (pass: 1)
+ pass: test_template_overlay.py (N.N sec)
- graceful exit.
diff --git a/selftest/suite_test/suite_test.ok.ign b/selftest/suite_test/suite_test.ok.ign
index 9bd168f..460da92 100644
--- a/selftest/suite_test/suite_test.ok.ign
+++ b/selftest/suite_test/suite_test.ok.ign
@@ -3,3 +3,4 @@
\([0-9.]+ sec\) (N.N sec)
{combining_scenarios='resources', scenario='foo'}:.* {combining_scenarios='resources', scenario='foo'}: [RESOURCE_DICT]
test_suite-[0-9]*-[0-9]* test_suite-[ID_NUM]-[ID_NUM]
+suiteC-[0-9]*-[0-9]* suiteC-[ID_NUM]-[ID_NUM]
diff --git a/selftest/suite_test/suite_test.py b/selftest/suite_test/suite_test.py
index 4b32439..260b9c4 100755
--- a/selftest/suite_test/suite_test.py
+++ b/selftest/suite_test/suite_test.py
@@ -105,6 +105,13 @@ print(repr(s.reserved_resources))
results = s.run_tests('test_suite_params.py')
print(report.suite_to_text(s))
+print('- test with template overlay')
+trial = FakeTrial()
+s_def = suite.load('suiteC')
+s = suite.SuiteRun(trial, 'suiteC', s_def)
+results = s.run_tests('test_template_overlay.py')
+print(report.suite_to_text(s))
+
print('\n- graceful exit.')
#deleting generated tmp trial dir:
shutil.rmtree(example_trial_dir, ignore_errors=True)
diff --git a/selftest/suite_test/suitedirB/suiteC/mytemplatedir/.gitignore b/selftest/suite_test/suitedirB/suiteC/mytemplatedir/.gitignore
new file mode 100644
index 0000000..1e2640b
--- /dev/null
+++ b/selftest/suite_test/suitedirB/suiteC/mytemplatedir/.gitignore
@@ -0,0 +1,6 @@
+# For 'test_template_overlay.py', it's fine having this directory completely
+# empy. However, we need a file in this directory so it can be stored in git.
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
diff --git a/selftest/suite_test/suitedirB/suiteC/suite.conf b/selftest/suite_test/suitedirB/suiteC/suite.conf
new file mode 100644
index 0000000..44be3fc
--- /dev/null
+++ b/selftest/suite_test/suitedirB/suiteC/suite.conf
@@ -0,0 +1,6 @@
+resources:
+ ip_address:
+ - addr: 10.42.42.2 # stp
+
+defaults:
+ timeout: 60s
diff --git a/selftest/suite_test/suitedirB/suiteC/test_template_overlay.py b/selftest/suite_test/suitedirB/suiteC/test_template_overlay.py
new file mode 100644
index 0000000..2dd9378
--- /dev/null
+++ b/selftest/suite_test/suitedirB/suiteC/test_template_overlay.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+from osmo_gsm_tester.testenv import *
+
+import os
+import sys
+
+print('- Testing: expect to fail on invalid templates overlay dir')
+try:
+ #stp.configure()
+ tenv.set_overlay_template_dir(os.path.join(os.path.dirname(__file__), 'nonexistent-templatedir'))
+ sys.stderr.write('Error: setting non-existing templates dir should raise RuntimeError\n')
+ assert(False)
+except RuntimeError:
+ print('sucess: setting non-existing templates dir raised RuntimeError\n')
+ pass
+
+mytemplatedir = os.path.join(os.path.dirname(__file__), 'mytemplatedir')
+tenv.set_overlay_template_dir(mytemplatedir)
+
+stp = tenv.stp()
+print('- Testing: original template')
+stp.configure()
+
+print('- Testing:overlay template')
+mytemplatefile = os.path.join(mytemplatedir, 'osmo-stp.cfg.tmpl')
+try:
+ with open(mytemplatefile, 'w') as f:
+ r = """! Overlay Config file genreated by test
+line vty
+ no login
+ bind ${stp.ip_address.addr}
+ """
+ f.write(r)
+
+ # After creating the new template, it won\'t be used until
+ # set_overlay_template_dir() is called again because the templates are
+ # somehow cached by mako.
+ print('- After creating the new template, still old template is used' )
+ stp.configure()
+ print('- New template is used after re-generating cache with set_overlay_template_dir:')
+ tenv.set_overlay_template_dir(mytemplatedir)
+ stp.configure()
+finally:
+ os.remove(mytemplatefile)