blob: 7d35138c8fd004e78baa1269ed5d8307d47b9386 [file] [log] [blame]
Pau Espin Pedrol166dc102020-06-04 18:44:42 +02001#!/usr/bin/env python3
2from osmo_gsm_tester.testenv import *
3
4import os
5import sys
6
7print('- Testing: expect to fail on invalid templates overlay dir')
8try:
9 #stp.configure()
10 tenv.set_overlay_template_dir(os.path.join(os.path.dirname(__file__), 'nonexistent-templatedir'))
11 sys.stderr.write('Error: setting non-existing templates dir should raise RuntimeError\n')
12 assert(False)
13except RuntimeError:
Neels Hofmeyr112da032020-12-04 18:03:22 +010014 print('success: setting non-existing templates dir raised RuntimeError')
Pau Espin Pedrol166dc102020-06-04 18:44:42 +020015 pass
16
17mytemplatedir = os.path.join(os.path.dirname(__file__), 'mytemplatedir')
18tenv.set_overlay_template_dir(mytemplatedir)
19
20stp = tenv.stp()
21print('- Testing: original template')
22stp.configure()
23
24print('- Testing:overlay template')
25mytemplatefile = os.path.join(mytemplatedir, 'osmo-stp.cfg.tmpl')
26try:
27 with open(mytemplatefile, 'w') as f:
28 r = """! Overlay Config file genreated by test
29line vty
30 no login
31 bind ${stp.ip_address.addr}
32 """
33 f.write(r)
34
35 # After creating the new template, it won\'t be used until
36 # set_overlay_template_dir() is called again because the templates are
37 # somehow cached by mako.
38 print('- After creating the new template, still old template is used' )
39 stp.configure()
40 print('- New template is used after re-generating cache with set_overlay_template_dir:')
41 tenv.set_overlay_template_dir(mytemplatedir)
42 stp.configure()
43finally:
44 os.remove(mytemplatefile)