blob: 89c449400942401df49354c5c7ac7271173ec353 [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001# osmo_gsm_tester: validate dict structures
2#
3# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Neels Hofmeyr <neels@hofmeyr.de>
6#
7# This program is free software: you can redistribute it and/or modify
Harald Welte27205342017-06-03 09:51:45 +02008# it under the terms of the GNU General Public License as
Neels Hofmeyr3531a192017-03-28 14:30:28 +02009# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte27205342017-06-03 09:51:45 +020015# GNU General Public License for more details.
Neels Hofmeyr3531a192017-03-28 14:30:28 +020016#
Harald Welte27205342017-06-03 09:51:45 +020017# You should have received a copy of the GNU General Public License
Neels Hofmeyr3531a192017-03-28 14:30:28 +020018# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import re
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020021import os
Neels Hofmeyr3531a192017-03-28 14:30:28 +020022
23from . import log
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020024from . import util
Neels Hofmeyr3531a192017-03-28 14:30:28 +020025
Pau Espin Pedrole0b89902020-05-06 16:28:01 +020026KEY_RE = re.compile('[a-zA-Z0-9][a-zA-Z0-9_]*')
Neels Hofmeyr3531a192017-03-28 14:30:28 +020027IPV4_RE = re.compile('([0-9]{1,3}.){3}[0-9]{1,3}')
28HWADDR_RE = re.compile('([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}')
29IMSI_RE = re.compile('[0-9]{6,15}')
30KI_RE = re.compile('[0-9a-fA-F]{32}')
Pau Espin Pedrol0f7f2652020-07-13 12:01:10 +020031OPC_RE = re.compile('[0-9a-fA-F]{32}')
Neels Hofmeyr3531a192017-03-28 14:30:28 +020032MSISDN_RE = re.compile('[0-9]{1,15}')
33
34def match_re(name, regex, val):
35 while True:
36 if not isinstance(val, str):
37 break;
38 if not regex.fullmatch(val):
39 break;
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020040 return True
Neels Hofmeyr3531a192017-03-28 14:30:28 +020041 raise ValueError('Invalid %s: %r' % (name, val))
42
43def band(val):
Pau Espin Pedrol05a838e2018-03-27 19:15:41 +020044 if val in ('GSM-900', 'GSM-1800', 'GSM-1900'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020045 return True
Neels Hofmeyr3531a192017-03-28 14:30:28 +020046 raise ValueError('Unknown GSM band: %r' % val)
47
48def ipv4(val):
49 match_re('IPv4 address', IPV4_RE, val)
50 els = [int(el) for el in val.split('.')]
51 if not all([el >= 0 and el <= 255 for el in els]):
52 raise ValueError('Invalid IPv4 address: %r' % val)
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020053 return True
Neels Hofmeyr3531a192017-03-28 14:30:28 +020054
55def hwaddr(val):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020056 return match_re('hardware address', HWADDR_RE, val)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020057
58def imsi(val):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020059 return match_re('IMSI', IMSI_RE, val)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020060
61def ki(val):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020062 return match_re('KI', KI_RE, val)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020063
Pau Espin Pedrol0f7f2652020-07-13 12:01:10 +020064def opc(val):
65 return match_re('OPC', OPC_RE, val)
66
Neels Hofmeyr3531a192017-03-28 14:30:28 +020067def msisdn(val):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020068 return match_re('MSISDN', MSISDN_RE, val)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020069
Pau Espin Pedrol713ce2c2017-08-24 16:57:17 +020070def auth_algo(val):
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020071 if val not in util.ENUM_OSMO_AUTH_ALGO:
Neels Hofmeyr0af893c2017-12-14 15:18:05 +010072 raise ValueError('Unknown Authentication Algorithm: %r' % val)
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020073 return True
Pau Espin Pedrol713ce2c2017-08-24 16:57:17 +020074
Pau Espin Pedrolfa9a6d32017-09-12 15:13:21 +020075def uint(val):
76 n = int(val)
77 if n < 0:
78 raise ValueError('Positive value expected instead of %d' % n)
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020079 return True
Pau Espin Pedrolfa9a6d32017-09-12 15:13:21 +020080
Pau Espin Pedrol8a3a7b52017-11-28 15:50:02 +010081def uint8(val):
82 n = int(val)
83 if n < 0:
84 raise ValueError('Positive value expected instead of %d' % n)
85 if n > 255: # 2^8 - 1
86 raise ValueError('Value %d too big, max value is 255' % n)
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020087 return True
Pau Espin Pedrol8a3a7b52017-11-28 15:50:02 +010088
Pau Espin Pedrol5e0c2512017-11-06 18:40:23 +010089def uint16(val):
90 n = int(val)
91 if n < 0:
92 raise ValueError('Positive value expected instead of %d' % n)
93 if n > 65535: # 2^16 - 1
94 raise ValueError('Value %d too big, max value is 65535' % n)
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020095 return True
96
97def bool_str(val):
98 # str2bool will raise an exception if unable to parse it
99 util.str2bool(val)
100 return True
Pau Espin Pedrol5e0c2512017-11-06 18:40:23 +0100101
Pau Espin Pedrolead79ac2017-09-12 15:19:18 +0200102def times(val):
103 n = int(val)
104 if n < 1:
105 raise ValueError('Positive value >0 expected instead of %d' % n)
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200106 return True
Pau Espin Pedrolead79ac2017-09-12 15:19:18 +0200107
Pau Espin Pedrol57497a62017-08-28 14:21:15 +0200108def cipher(val):
109 if val in ('a5_0', 'a5_1', 'a5_2', 'a5_3', 'a5_4', 'a5_5', 'a5_6', 'a5_7'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200110 return True
Pau Espin Pedrol57497a62017-08-28 14:21:15 +0200111 raise ValueError('Unknown Cipher value: %r' % val)
112
Pau Espin Pedrolac18fd32017-08-31 18:49:47 +0200113def modem_feature(val):
Andre Puschmann3166b632020-11-16 12:39:43 +0100114 if val in ('sms', 'gprs', 'voice', 'ussd', 'sim', '2g', '3g', '4g', 'dl_qam256', 'ul_qam64'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200115 return True
Pau Espin Pedrolac18fd32017-08-31 18:49:47 +0200116 raise ValueError('Unknown Modem Feature: %r' % val)
117
Pau Espin Pedrolc9b63762018-05-07 01:57:01 +0200118def phy_channel_config(val):
119 if val in ('CCCH', 'CCCH+SDCCH4', 'TCH/F', 'TCH/H', 'SDCCH8', 'PDCH',
120 'TCH/F_PDCH', 'CCCH+SDCCH4+CBCH', 'SDCCH8+CBCH','TCH/F_TCH/H_PDCH'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200121 return True
Pau Espin Pedrolc9b63762018-05-07 01:57:01 +0200122 raise ValueError('Unknown Physical channel config: %r' % val)
123
Pau Espin Pedrol722e94e2018-08-22 11:01:32 +0200124def channel_allocator(val):
125 if val in ('ascending', 'descending'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200126 return True
Pau Espin Pedrol722e94e2018-08-22 11:01:32 +0200127 raise ValueError('Unknown Channel Allocator Policy %r' % val)
128
Pau Espin Pedrol4f23ab52018-10-29 11:30:00 +0100129def gprs_mode(val):
130 if val in ('none', 'gprs', 'egprs'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200131 return True
Pau Espin Pedrol4f23ab52018-10-29 11:30:00 +0100132 raise ValueError('Unknown GPRS mode %r' % val)
133
Pau Espin Pedrol5dc24592018-08-27 12:53:41 +0200134def codec(val):
135 if val in ('hr1', 'hr2', 'hr3', 'fr1', 'fr2', 'fr3'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200136 return True
Pau Espin Pedrol5dc24592018-08-27 12:53:41 +0200137 raise ValueError('Unknown Codec value: %r' % val)
138
Pau Espin Pedrol0d455042018-08-27 17:07:41 +0200139def osmo_trx_clock_ref(val):
140 if val in ('internal', 'external', 'gspdo'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200141 return True
Pau Espin Pedrol0d455042018-08-27 17:07:41 +0200142 raise ValueError('Unknown OsmoTRX clock reference value: %r' % val)
143
Pau Espin Pedrolb6937712020-02-27 18:02:20 +0100144def lte_transmission_mode(val):
145 n = int(val)
146 if n <= 4:
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200147 return True
Pau Espin Pedrolb6937712020-02-27 18:02:20 +0100148 raise ValueError('LTE Transmission Mode %d not in expected range' % n)
149
Andre Puschmann2dcc4312020-03-28 15:34:00 +0100150def duration(val):
151 if val.isdecimal() or val.endswith('m') or val.endswith('h'):
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200152 return True
Andre Puschmann2dcc4312020-03-28 15:34:00 +0100153 raise ValueError('Invalid duration value: %r' % val)
154
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200155INT = 'int'
156STR = 'str'
Pau Espin Pedrolfa9a6d32017-09-12 15:13:21 +0200157UINT = 'uint'
Pau Espin Pedrol404e1502017-08-22 11:17:43 +0200158BOOL_STR = 'bool_str'
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200159BAND = 'band'
160IPV4 = 'ipv4'
161HWADDR = 'hwaddr'
162IMSI = 'imsi'
163KI = 'ki'
Pau Espin Pedrol0f7f2652020-07-13 12:01:10 +0200164OPC = 'opc'
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200165MSISDN = 'msisdn'
Pau Espin Pedrol713ce2c2017-08-24 16:57:17 +0200166AUTH_ALGO = 'auth_algo'
Pau Espin Pedrolead79ac2017-09-12 15:19:18 +0200167TIMES='times'
Pau Espin Pedrol57497a62017-08-28 14:21:15 +0200168CIPHER = 'cipher'
Pau Espin Pedrolac18fd32017-08-31 18:49:47 +0200169MODEM_FEATURE = 'modem_feature'
Pau Espin Pedrolc9b63762018-05-07 01:57:01 +0200170PHY_CHAN = 'chan'
Pau Espin Pedrol722e94e2018-08-22 11:01:32 +0200171CHAN_ALLOCATOR = 'chan_allocator'
Pau Espin Pedrol4f23ab52018-10-29 11:30:00 +0100172GPRS_MODE = 'gprs_mode'
Pau Espin Pedrol5dc24592018-08-27 12:53:41 +0200173CODEC = 'codec'
Pau Espin Pedrol0d455042018-08-27 17:07:41 +0200174OSMO_TRX_CLOCK_REF = 'osmo_trx_clock_ref'
Pau Espin Pedrolb6937712020-02-27 18:02:20 +0100175LTE_TRANSMISSION_MODE = 'lte_transmission_mode'
Andre Puschmann2dcc4312020-03-28 15:34:00 +0100176DURATION = 'duration'
Pau Espin Pedrolac18fd32017-08-31 18:49:47 +0200177
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200178SCHEMA_TYPES = {
179 INT: int,
180 STR: str,
Pau Espin Pedrolfa9a6d32017-09-12 15:13:21 +0200181 UINT: uint,
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200182 BOOL_STR: bool_str,
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200183 BAND: band,
184 IPV4: ipv4,
185 HWADDR: hwaddr,
186 IMSI: imsi,
187 KI: ki,
Pau Espin Pedrol0f7f2652020-07-13 12:01:10 +0200188 OPC: opc,
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200189 MSISDN: msisdn,
Pau Espin Pedrol713ce2c2017-08-24 16:57:17 +0200190 AUTH_ALGO: auth_algo,
Pau Espin Pedrolead79ac2017-09-12 15:19:18 +0200191 TIMES: times,
Pau Espin Pedrol57497a62017-08-28 14:21:15 +0200192 CIPHER: cipher,
Pau Espin Pedrolac18fd32017-08-31 18:49:47 +0200193 MODEM_FEATURE: modem_feature,
Pau Espin Pedrolc9b63762018-05-07 01:57:01 +0200194 PHY_CHAN: phy_channel_config,
Pau Espin Pedrol722e94e2018-08-22 11:01:32 +0200195 CHAN_ALLOCATOR: channel_allocator,
Pau Espin Pedrol4f23ab52018-10-29 11:30:00 +0100196 GPRS_MODE: gprs_mode,
Pau Espin Pedrol5dc24592018-08-27 12:53:41 +0200197 CODEC: codec,
Pau Espin Pedrol0d455042018-08-27 17:07:41 +0200198 OSMO_TRX_CLOCK_REF: osmo_trx_clock_ref,
Pau Espin Pedrolb6937712020-02-27 18:02:20 +0100199 LTE_TRANSMISSION_MODE: lte_transmission_mode,
Andre Puschmann2dcc4312020-03-28 15:34:00 +0100200 DURATION: duration,
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200201 }
202
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200203def add(dest, src):
204 if util.is_dict(dest):
205 if not util.is_dict(src):
206 raise ValueError('cannot add to dict a value of type: %r' % type(src))
207
208 for key, val in src.items():
209 dest_val = dest.get(key)
210 if dest_val is None:
211 dest[key] = val
212 else:
213 log.ctx(key=key)
214 add(dest_val, val)
215 return
216 if util.is_list(dest):
217 if not util.is_list(src):
218 raise ValueError('cannot add to list a value of type: %r' % type(src))
219 dest.extend(src)
220 return
221 if dest == src:
222 return
223 raise ValueError('cannot add dicts, conflicting items (values %r and %r)'
224 % (dest, src))
225
226def combine(dest, src):
227 if util.is_dict(dest):
228 if not util.is_dict(src):
229 raise ValueError('cannot combine dict with a value of type: %r' % type(src))
230
231 for key, val in src.items():
232 log.ctx(key=key)
233 dest_val = dest.get(key)
234 if dest_val is None:
235 dest[key] = val
236 else:
237 combine(dest_val, val)
238 return
239 if util.is_list(dest):
240 if not util.is_list(src):
241 raise ValueError('cannot combine list with a value of type: %r' % type(src))
242 # Validate that all elements in both lists are of the same type:
243 t = util.list_validate_same_elem_type(src + dest)
244 if t is None:
245 return # both lists are empty, return
246 # For lists of complex objects, we expect them to be sorted lists:
247 if t in (dict, list, tuple):
248 for i in range(len(dest)):
249 log.ctx(idx=i)
250 src_it = src[i] if i < len(src) else util.empty_instance_type(t)
251 combine(dest[i], src_it)
252 for i in range(len(dest), len(src)):
253 log.ctx(idx=i)
254 dest.append(src[i])
255 else: # for lists of basic elements, we handle them as unsorted sets:
256 for elem in src:
257 if elem not in dest:
258 dest.append(elem)
259 return
260 if dest == src:
261 return
262 raise ValueError('cannot combine dicts, conflicting items (values %r and %r)'
263 % (dest, src))
264
265def replicate_times(d):
266 '''
267 replicate items that have a "times" > 1
268
269 'd' is a dict matching WANT_SCHEMA, which is the same as
270 the RESOURCES_SCHEMA, except each entity that can be reserved has a 'times'
271 field added, to indicate how many of those should be reserved.
272 '''
273 d = copy.deepcopy(d)
274 for key, item_list in d.items():
275 idx = 0
276 while idx < len(item_list):
277 item = item_list[idx]
278 times = int(item.pop('times', 1))
279 for j in range(1, times):
280 item_list.insert(idx + j, copy.deepcopy(item))
281 idx += times
282 return d
283
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200284def validate(config, schema):
285 '''Make sure the given config dict adheres to the schema.
286 The schema is a dict of 'dict paths' in dot-notation with permitted
287 value type. All leaf nodes are validated, nesting dicts are implicit.
288
289 validate( { 'a': 123, 'b': { 'b1': 'foo', 'b2': [ 1, 2, 3 ] } },
290 { 'a': int,
291 'b.b1': str,
292 'b.b2[]': int } )
293
294 Raise a ValueError in case the schema is violated.
295 '''
296
297 def validate_item(path, value, schema):
298 want_type = schema.get(path)
299
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200300 if util.is_list(value):
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200301 if want_type:
302 raise ValueError('config item is a list, should be %r: %r' % (want_type, path))
303 path = path + '[]'
304 want_type = schema.get(path)
305
306 if not want_type:
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200307 if util.is_dict(value):
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200308 nest(path, value, schema)
309 return
Andre Puschmann635edb32020-11-11 16:58:35 +0100310 if util.is_list(value):
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200311 for list_v in value:
312 validate_item(path, list_v, schema)
313 return
314 raise ValueError('config item not known: %r' % path)
315
316 if want_type not in SCHEMA_TYPES:
317 raise ValueError('unknown type %r at %r' % (want_type, path))
318
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200319 if util.is_dict(value):
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200320 raise ValueError('config item is dict but should be a leaf node of type %r: %r'
321 % (want_type, path))
322
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200323 if util.is_list(value):
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200324 for list_v in value:
325 validate_item(path, list_v, schema)
326 return
327
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200328 log.ctx(path)
329 type_validator = SCHEMA_TYPES.get(want_type)
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200330 valid = type_validator(value)
331 if not valid:
332 raise ValueError('Invalid value %r for schema type \'%s\' (validator: %s)' % (value, want_type, type_validator.__name__))
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200333
334 def nest(parent_path, config, schema):
335 if parent_path:
336 parent_path = parent_path + '.'
337 else:
338 parent_path = ''
339 for k,v in config.items():
340 if not KEY_RE.fullmatch(k):
341 raise ValueError('invalid config key: %r' % k)
342 path = parent_path + k
343 validate_item(path, v, schema)
344
345 nest(None, config, schema)
346
Pau Espin Pedrol30637302020-05-06 21:11:02 +0200347def config_to_schema_def(src, key_prefix):
348 'Converts a yaml parsed config into a schema dictionary used by validate()'
349 if util.is_dict(src):
350 out_dict = {}
351 for key, val in src.items():
352 list_token = ''
353 dict_token = ''
354 if util.is_list(val):
355 list_token = '[]'
356 assert len(val) == 1
357 val = val[0]
358 if util.is_dict(val):
359 dict_token = '.'
360 tmp_out = config_to_schema_def(val, "%s%s%s%s" %(key_prefix, key, list_token, dict_token))
361 out_dict = {**out_dict, **tmp_out}
362 return out_dict
363
364 # base case: string
365 return {key_prefix: str(src)}
366
367
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200368def generate_schemas():
369 "Generate supported schemas dynamically from objects"
370 obj_dir = '%s/../obj/' % os.path.dirname(os.path.abspath(__file__))
371 for filename in os.listdir(obj_dir):
372 if not filename.endswith(".py"):
373 continue
374 module_name = 'osmo_gsm_tester.obj.%s' % filename[:-3]
375 util.run_python_file_method(module_name, 'on_register_schemas', False)
376
377
Neels Hofmeyrecce4022020-11-28 19:54:43 +0100378_RESOURCE_TYPES = ['ip_address',]
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200379
380_RESOURCES_SCHEMA = {
381 'ip_address[].addr': IPV4,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200382 }
383
384_CONFIG_SCHEMA = {}
385
386_WANT_SCHEMA = None
387_ALL_SCHEMA = None
388
Pau Espin Pedrold79e7192020-05-21 15:40:57 +0200389def register_schema_types(schema_type_attr):
390 """Register schema types to be used by schema attributes.
391 For instance: register_resource_schema_attributes({ 'fruit': lambda val: val in ('banana', 'apple') })
392 """
393 global SCHEMA_TYPES
394 combine(SCHEMA_TYPES, schema_type_attr)
395
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200396def register_resource_schema(obj_class_str, obj_attr_dict):
397 """Register schema attributes for a resource type.
398 For instance: register_resource_schema_attributes('modem', {'type': schema.STR, 'ki': schema.KI})
399 """
400 global _RESOURCES_SCHEMA
401 global _RESOURCE_TYPES
402 tmpdict = {}
403 for key, val in obj_attr_dict.items():
404 new_key = '%s[].%s' % (obj_class_str, key)
405 tmpdict[new_key] = val
406 combine(_RESOURCES_SCHEMA, tmpdict)
407 if obj_class_str not in _RESOURCE_TYPES:
408 _RESOURCE_TYPES.append(obj_class_str)
409
410def register_config_schema(obj_class_str, obj_attr_dict):
411 """Register schema attributes to configure all instances of an object class.
412 For instance: register_resource_schema_attributes('bsc', {'net.codec_list[]': schema.CODEC})
413 """
Pau Espin Pedrol30637302020-05-06 21:11:02 +0200414 global _CONFIG_SCHEMA, _ALL_SCHEMA
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200415 tmpdict = {}
416 for key, val in obj_attr_dict.items():
417 new_key = '%s.%s' % (obj_class_str, key)
418 tmpdict[new_key] = val
419 combine(_CONFIG_SCHEMA, tmpdict)
Pau Espin Pedrol30637302020-05-06 21:11:02 +0200420 _ALL_SCHEMA = None # reset _ALL_SCHEMA so it is re-generated next time it's requested.
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200421
422def get_resources_schema():
423 return _RESOURCES_SCHEMA;
424
425def get_want_schema():
426 global _WANT_SCHEMA
427 if _WANT_SCHEMA is None:
428 _WANT_SCHEMA = util.dict_add(
429 dict([('%s[].times' % r, TIMES) for r in _RESOURCE_TYPES]),
430 get_resources_schema())
431 return _WANT_SCHEMA
432
433def get_all_schema():
434 global _ALL_SCHEMA
435 if _ALL_SCHEMA is None:
436 want_schema = get_want_schema()
Pau Espin Pedrol8cfb5d02020-06-12 16:12:40 +0200437 _ALL_SCHEMA = util.dict_add(
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +0200438 dict([('config.%s' % key, val) for key, val in _CONFIG_SCHEMA.items()]),
439 dict([('resources.%s' % key, val) for key, val in want_schema.items()]),
440 dict([('modifiers.%s' % key, val) for key, val in want_schema.items()]))
441 return _ALL_SCHEMA
442
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200443# vim: expandtab tabstop=4 shiftwidth=4