blob: 314dd8d5ea869d98682084e08ed41f37926658e3 [file] [log] [blame]
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +02001#!/usr/bin/env python3
2
3import _prep
4
5import sys
6import os
7
8from osmo_gsm_tester import template, log
9
10log.set_level(log.C_CNF, log.L_DBG)
11
12print('- Testing: fill a config file with values')
13
14mock_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
21mock_bts = {
Neels Hofmeyr2694a9d2017-04-27 19:48:09 +020022 'osmobsc_bts_type': 'val_type',
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020023 'band': 'val_band',
24 'location_area_code': 'val_bts.location_area_code',
Pau Espin Pedrol4ccce7c2017-11-07 11:13:20 +010025 'cell_identity': 'val_bts.cell_identity',
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020026 'base_station_id_code': 'val_bts.base_station_id_code',
Neels Hofmeyr3531a192017-03-28 14:30:28 +020027 'ipa_unit_id': 'val_bts.unit_id',
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020028 'stream_id': 'val_bts.stream_id',
Pau Espin Pedrolce35d912017-11-23 11:01:24 +010029 'sgsn': (dict(ip_address=dict(addr='val_bts.sgsn_ip_addr'))),
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020030 'trx_list': (
31 dict(arfcn='val_trx_arfcn_trx0',
Pau Espin Pedrolb26f32a2017-09-14 13:52:28 +020032 nominal_power='val_trx_nominal_power_trx0',
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020033 max_power_red='val_trx_max_power_red_trx0',
34 timeslot_list=mock_timeslot_list),
35 dict(arfcn='val_trx_arfcn_trx1',
Pau Espin Pedrolb26f32a2017-09-14 13:52:28 +020036 nominal_power='val_trx_nominal_power_trx1',
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020037 max_power_red='val_trx_max_power_red_trx1',
38 timeslot_list=mock_timeslot_list),
39 )
40}
41
Pau Espin Pedrol2d16f6f2017-05-30 15:33:57 +020042mock_esme = {
43 'system_id': 'val_system_id',
44 'password': 'val_password'
45}
46
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020047def clone_mod(d, val_ext):
48 c = dict(d)
49 for name in c.keys():
50 if isinstance(c[name], str):
51 c[name] = c[name] + val_ext
52 elif isinstance(c[name], dict):
53 c[name] = clone_mod(c[name], val_ext)
54 return c
55
56mock_bts0 = clone_mod(mock_bts, '_bts0')
57mock_bts1 = clone_mod(mock_bts, '_bts1')
58
Pau Espin Pedrol2d16f6f2017-05-30 15:33:57 +020059mock_esme0 = clone_mod(mock_esme, '_esme0')
60mock_esme1 = clone_mod(mock_esme, '_esme1')
61mock_esme1['password'] = ''
62
Neels Hofmeyr3531a192017-03-28 14:30:28 +020063vals = dict(nitb=dict(
64 net=dict(
65 mcc='val_mcc',
66 mnc='val_mnc',
67 short_name='val_short_name',
68 long_name='val_long_name',
69 auth_policy='val_auth_policy',
70 encryption='val_encryption',
71 bts_list=(mock_bts0, mock_bts1)
72 ),
Neels Hofmeyr4f59ba62017-05-22 20:04:05 +020073 ip_address=dict(addr='val_ip_address'),
74 ),
Pau Espin Pedrol2d16f6f2017-05-30 15:33:57 +020075 smsc=dict(
76 policy='val_smsc_policy',
77 esme_list=(mock_esme0, mock_esme1)
78 ),
Neels Hofmeyr3531a192017-03-28 14:30:28 +020079 )
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020080
81print(template.render('osmo-nitb.cfg', vals))
82
83print('- Testing: expect to fail on invalid templates dir')
84try:
85 template.set_templates_dir('non-existing dir')
86 sys.stderr.write('Error: setting non-existing templates dir should raise RuntimeError\n')
87 assert(False)
88except RuntimeError:
89 # not logging exception to omit non-constant path name from expected output
90 print('sucess: setting non-existing templates dir raised RuntimeError\n')
91 pass
92
93# vim: expandtab tabstop=4 shiftwidth=4