Pau Espin Pedrol | 166dc10 | 2020-06-04 18:44:42 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | from osmo_gsm_tester.testenv import * |
| 3 | |
| 4 | import os |
| 5 | import sys |
| 6 | |
| 7 | print('- Testing: expect to fail on invalid templates overlay dir') |
| 8 | try: |
| 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) |
| 13 | except RuntimeError: |
| 14 | print('sucess: setting non-existing templates dir raised RuntimeError\n') |
| 15 | pass |
| 16 | |
| 17 | mytemplatedir = os.path.join(os.path.dirname(__file__), 'mytemplatedir') |
| 18 | tenv.set_overlay_template_dir(mytemplatedir) |
| 19 | |
| 20 | stp = tenv.stp() |
| 21 | print('- Testing: original template') |
| 22 | stp.configure() |
| 23 | |
| 24 | print('- Testing:overlay template') |
| 25 | mytemplatefile = os.path.join(mytemplatedir, 'osmo-stp.cfg.tmpl') |
| 26 | try: |
| 27 | with open(mytemplatefile, 'w') as f: |
| 28 | r = """! Overlay Config file genreated by test |
| 29 | line 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() |
| 43 | finally: |
| 44 | os.remove(mytemplatefile) |