Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import _prep |
| 4 | |
| 5 | import sys |
| 6 | import os |
| 7 | |
Pau Espin Pedrol | e8bbcbf | 2020-04-10 19:51:31 +0200 | [diff] [blame] | 8 | from osmo_gsm_tester.core import template, log |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 9 | |
| 10 | log.set_level(log.C_CNF, log.L_DBG) |
| 11 | |
| 12 | print('- Testing: fill a config file with values') |
| 13 | |
| 14 | mock_timeslot_list=( |
| 15 | { 'phys_chan_config': 'val_phys_chan_config_0' }, |
| 16 | { 'phys_chan_config': 'val_phys_chan_config_1' }, |
| 17 | { 'phys_chan_config': 'val_phys_chan_config_2' }, |
| 18 | { 'phys_chan_config': 'val_phys_chan_config_3' }, |
| 19 | ) |
| 20 | |
| 21 | mock_bts = { |
Neels Hofmeyr | 2694a9d | 2017-04-27 19:48:09 +0200 | [diff] [blame] | 22 | 'osmobsc_bts_type': 'val_type', |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 23 | 'band': 'val_band', |
| 24 | 'location_area_code': 'val_bts.location_area_code', |
Pau Espin Pedrol | 8a3a7b5 | 2017-11-28 15:50:02 +0100 | [diff] [blame] | 25 | 'routing_area_code': 'val_bts.routing_area_code', |
Pau Espin Pedrol | 4ccce7c | 2017-11-07 11:13:20 +0100 | [diff] [blame] | 26 | 'cell_identity': 'val_bts.cell_identity', |
Pau Espin Pedrol | 8a3a7b5 | 2017-11-28 15:50:02 +0100 | [diff] [blame] | 27 | 'bvci': 'val_bts.bvci', |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 28 | 'base_station_id_code': 'val_bts.base_station_id_code', |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 29 | 'ipa_unit_id': 'val_bts.unit_id', |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 30 | 'stream_id': 'val_bts.stream_id', |
Pau Espin Pedrol | ce35d91 | 2017-11-23 11:01:24 +0100 | [diff] [blame] | 31 | 'sgsn': (dict(ip_address=dict(addr='val_bts.sgsn_ip_addr'))), |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 32 | 'trx_list': ( |
| 33 | dict(arfcn='val_trx_arfcn_trx0', |
Pau Espin Pedrol | b26f32a | 2017-09-14 13:52:28 +0200 | [diff] [blame] | 34 | nominal_power='val_trx_nominal_power_trx0', |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 35 | max_power_red='val_trx_max_power_red_trx0', |
| 36 | timeslot_list=mock_timeslot_list), |
| 37 | dict(arfcn='val_trx_arfcn_trx1', |
Pau Espin Pedrol | b26f32a | 2017-09-14 13:52:28 +0200 | [diff] [blame] | 38 | nominal_power='val_trx_nominal_power_trx1', |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 39 | max_power_red='val_trx_max_power_red_trx1', |
| 40 | timeslot_list=mock_timeslot_list), |
| 41 | ) |
| 42 | } |
| 43 | |
Pau Espin Pedrol | 2d16f6f | 2017-05-30 15:33:57 +0200 | [diff] [blame] | 44 | mock_esme = { |
| 45 | 'system_id': 'val_system_id', |
| 46 | 'password': 'val_password' |
| 47 | } |
| 48 | |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 49 | def clone_mod(d, val_ext): |
| 50 | c = dict(d) |
| 51 | for name in c.keys(): |
| 52 | if isinstance(c[name], str): |
| 53 | c[name] = c[name] + val_ext |
| 54 | elif isinstance(c[name], dict): |
| 55 | c[name] = clone_mod(c[name], val_ext) |
| 56 | return c |
| 57 | |
| 58 | mock_bts0 = clone_mod(mock_bts, '_bts0') |
| 59 | mock_bts1 = clone_mod(mock_bts, '_bts1') |
| 60 | |
Pau Espin Pedrol | 2d16f6f | 2017-05-30 15:33:57 +0200 | [diff] [blame] | 61 | mock_esme0 = clone_mod(mock_esme, '_esme0') |
| 62 | mock_esme1 = clone_mod(mock_esme, '_esme1') |
| 63 | mock_esme1['password'] = '' |
| 64 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 65 | vals = dict(nitb=dict( |
| 66 | net=dict( |
| 67 | mcc='val_mcc', |
| 68 | mnc='val_mnc', |
| 69 | short_name='val_short_name', |
| 70 | long_name='val_long_name', |
| 71 | auth_policy='val_auth_policy', |
| 72 | encryption='val_encryption', |
| 73 | bts_list=(mock_bts0, mock_bts1) |
| 74 | ), |
Neels Hofmeyr | 4f59ba6 | 2017-05-22 20:04:05 +0200 | [diff] [blame] | 75 | ip_address=dict(addr='val_ip_address'), |
| 76 | ), |
Pau Espin Pedrol | 2d16f6f | 2017-05-30 15:33:57 +0200 | [diff] [blame] | 77 | smsc=dict( |
| 78 | policy='val_smsc_policy', |
| 79 | esme_list=(mock_esme0, mock_esme1) |
| 80 | ), |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 81 | ) |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 82 | |
| 83 | print(template.render('osmo-nitb.cfg', vals)) |
| 84 | |
| 85 | print('- Testing: expect to fail on invalid templates dir') |
| 86 | try: |
| 87 | template.set_templates_dir('non-existing dir') |
| 88 | sys.stderr.write('Error: setting non-existing templates dir should raise RuntimeError\n') |
| 89 | assert(False) |
| 90 | except RuntimeError: |
| 91 | # not logging exception to omit non-constant path name from expected output |
| 92 | print('sucess: setting non-existing templates dir raised RuntimeError\n') |
| 93 | pass |
| 94 | |
Pau Espin Pedrol | 4ddcdaf | 2020-06-04 17:23:23 +0200 | [diff] [blame] | 95 | mytemplatedir = os.path.join(os.path.dirname(__file__), 'mytemplatedir') |
| 96 | template.set_templates_dir(mytemplatedir, template.default_templates_dir()) |
| 97 | print('- Testing: template directory overlay (still can find default one?)') |
| 98 | print(template.render('osmo-nitb.cfg', vals)) |
| 99 | print('- Testing: template directory overlay (present in both dirs)') |
| 100 | print(template.render('osmo-bsc.cfg', dict(foo=dict(bar=dict(works='yes'))))) |
| 101 | print('- Testing: template directory overlay (present only on overlay dir)') |
| 102 | print(template.render('mytemplate.cfg', dict(one=dict(two=dict(works='yes'))))) |
| 103 | |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 104 | # vim: expandtab tabstop=4 shiftwidth=4 |