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 | |
| 8 | from osmo_gsm_tester import template, log |
| 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 = { |
| 22 | 'type': 'val_type', |
| 23 | 'band': 'val_band', |
| 24 | 'location_area_code': 'val_bts.location_area_code', |
| 25 | 'base_station_id_code': 'val_bts.base_station_id_code', |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 26 | 'ipa_unit_id': 'val_bts.unit_id', |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 27 | 'stream_id': 'val_bts.stream_id', |
| 28 | 'trx_list': ( |
| 29 | dict(arfcn='val_trx_arfcn_trx0', |
| 30 | max_power_red='val_trx_max_power_red_trx0', |
| 31 | timeslot_list=mock_timeslot_list), |
| 32 | dict(arfcn='val_trx_arfcn_trx1', |
| 33 | max_power_red='val_trx_max_power_red_trx1', |
| 34 | timeslot_list=mock_timeslot_list), |
| 35 | ) |
| 36 | } |
| 37 | |
| 38 | def clone_mod(d, val_ext): |
| 39 | c = dict(d) |
| 40 | for name in c.keys(): |
| 41 | if isinstance(c[name], str): |
| 42 | c[name] = c[name] + val_ext |
| 43 | elif isinstance(c[name], dict): |
| 44 | c[name] = clone_mod(c[name], val_ext) |
| 45 | return c |
| 46 | |
| 47 | mock_bts0 = clone_mod(mock_bts, '_bts0') |
| 48 | mock_bts1 = clone_mod(mock_bts, '_bts1') |
| 49 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 50 | vals = dict(nitb=dict( |
| 51 | net=dict( |
| 52 | mcc='val_mcc', |
| 53 | mnc='val_mnc', |
| 54 | short_name='val_short_name', |
| 55 | long_name='val_long_name', |
| 56 | auth_policy='val_auth_policy', |
| 57 | encryption='val_encryption', |
| 58 | bts_list=(mock_bts0, mock_bts1) |
| 59 | ), |
| 60 | ), |
| 61 | nitb_iface=dict(addr='val_nitb_iface_addr'), |
| 62 | ) |
Neels Hofmeyr | dae3d3c | 2017-03-28 12:16:58 +0200 | [diff] [blame] | 63 | |
| 64 | print(template.render('osmo-nitb.cfg', vals)) |
| 65 | |
| 66 | print('- Testing: expect to fail on invalid templates dir') |
| 67 | try: |
| 68 | template.set_templates_dir('non-existing dir') |
| 69 | sys.stderr.write('Error: setting non-existing templates dir should raise RuntimeError\n') |
| 70 | assert(False) |
| 71 | except RuntimeError: |
| 72 | # not logging exception to omit non-constant path name from expected output |
| 73 | print('sucess: setting non-existing templates dir raised RuntimeError\n') |
| 74 | pass |
| 75 | |
| 76 | # vim: expandtab tabstop=4 shiftwidth=4 |