def emit_type_val(t, fd): if t.i_is_derived == False and t.i_typedef != None: return emit_type_val(t.i_typedef.search_one('type'), fd) inttype = statements.has_type(t, [ 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64' ]) enum = t.search('enum') range = t.search_one('range') if enum != []: enum = pick(enum) fd.write(enum.arg) elif statements.has_type(t, ['empty']) != None: pass elif range != None: (lo, hi) = pick(t.i_ranges) ts = types.yang_type_specs[inttype.arg] if lo == 'min': lo = ts.min if hi == 'max': hi = ts.max if hi == None: hi = lo val = randint(lo, hi) fd.write(str(val)) elif statements.has_type(t, ['boolean']) != None: val = pick(['true', 'false']) fd.write(val) elif inttype != None: ts = types.yang_type_specs[inttype.arg] val = randint(ts.min, ts.max) fd.write(str(val)) elif statements.has_type(t, ['ipv4-address']) != None: fd.write('10.0.0.1') else: length = t.search_one('length') pattern = t.search('pattern') if length != None: # pick a length (lo, hi) = pick(t.i_lengths) if hi == None: hi = lo lentgh = randint(lo, hi) if pattern != []: # oh boy pass fd.write('__foo__')
def emit_type_val(t, fd): if t.i_is_derived == False and t.i_typedef != None: return emit_type_val(t.i_typedef.search_one('type'), fd) inttype = statements.has_type(t, ['int8','int16','int32','int64', 'uint8','uint16','uint32','uint64']) enum = t.search('enum') range = t.search_one('range') if enum != []: enum = pick(enum) fd.write(enum.arg) elif statements.has_type(t, ['empty']) != None: pass elif range != None: (lo,hi) = pick(t.i_ranges) ts = types.yang_type_specs[inttype.arg] if lo == 'min': lo = ts.min if hi == 'max': hi = ts.max if hi == None: hi = lo val = randint(lo,hi) fd.write(str(val)) elif statements.has_type(t, ['boolean']) != None: val = pick(['true','false']) fd.write(val) elif inttype != None: ts = types.yang_type_specs[inttype.arg] val = randint(ts.min, ts.max) fd.write(str(val)) elif statements.has_type(t, ['ipv4-address']) != None: fd.write('10.0.0.1') else: length = t.search_one('length') pattern = t.search('pattern') if length != None: # pick a length (lo,hi) = pick(t.i_lengths) if hi == None: hi = lo lentgh = randint(lo,hi) if pattern != []: # oh boy pass fd.write('__foo__')
def close_object(stmt, top): if statements.has_type(stmt, ["enumeration"]): print("}") return if is_last(stmt): print("}") return print("},")
def emit_leaf(stmt, fd, ind, attrs): do_print = True if ((stmt.search_one('mandatory') != None) and (stmt.search_one('mandatory').arg == 'false') or (stmt.search_one('default') != None) or (statements.has_type(stmt.search_one('type'), ['empty']) != None)): if random() < 0.3: do_print = False if do_print == True: fd.write(ind + '<%s%s>' % (stmt.arg, attrs)) emit_type_val(stmt.search_one('type'), fd) fd.write('</%s>\n' % stmt.arg)
def v_reference_complex_type(ctx, stmt): """Validate the key of the complex type""" key = stmt.search_one('key') if key is not None: # check that the key has not been defined in the base type basetype = stmt.i_base_type while basetype is not None: basekey = basetype.search_one('key') if basekey is not None: err_add(ctx.errors, key.pos, "REDEFINED_KEY", (stmt.arg, basetype.arg, basekey.pos)) return basetype = basetype.i_base_type # check the references to the leafs # this part is based on the source code for the list's key validation stmt.i_key = [] if key is not None: found = [] for x in key.arg.split(): if x == '': continue if x.find(":") == -1: name = x else: [prefix, name] = x.split(':', 1) if prefix != stmt.i_module.i_prefix: err_add(ctx.errors, key.pos, 'BAD_KEY', x) return ptr = attrsearch(name, 'arg', stmt.i_children) if x in found: err_add(ctx.errors, key.pos, 'DUPLICATE_KEY', x) return elif ((ptr is None) or (ptr.keyword != 'leaf')): err_add(ctx.errors, key.pos, 'BAD_KEY', x) return type = ptr.search_one('type') if type is not None: t = statements.has_type(type, ['empty']) if t is not None: err_add(ctx.errors, key.pos, 'BAD_TYPE_IN_KEY', (t.arg, x)) return default = ptr.search_one('default') if default is not None: err_add(ctx.errors, default.pos, 'KEY_HAS_DEFAULT', ()) stmt.i_key.append(ptr) found.append(x)