Changeset 14025 in genesis for tools/syntax-checker.py
- Timestamp:
- Jan 22, 2018, 12:49:48 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/syntax-checker.py
r13987 r14025 6 6 import gformat 7 7 import sys 8 import ipaddress 8 9 9 10 from collections import defaultdict … … 11 12 __version__ = '$Id$' 12 13 13 allowed_multi_use = ['0.0.0.0', '192.168.1.', '192.168.178.'] 14 allowed_multi_use = map(lambda x: ipaddress.ip_network(x, strict=True), [ 15 u'192.168.0.0/22', 16 u'192.168.0.0/16', 17 u'192.168.0.0/24', 18 u'192.168.1.0/24', 19 u'192.168.178.0/24', 20 ]) 21 22 23 24 14 25 15 26 def check_double_ip(): … … 19 30 print "## Processing host %-25s: " % host, 20 31 datadump = gformat.get_yaml(host,add_version_info=False) 32 masterip_addr = ipaddress.IPv4Interface(unicode(datadump['masterip'])) 33 masterip_is_used = False 34 21 35 # Check syntax of defined variables 22 36 _ = gformat.generate_wleiden_yaml(datadump) … … 25 39 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)] 26 40 for iface_key in iface_keys: 27 # Virtual interfaces bridge interfaces do not have IP addreses28 if not datadump[iface_key].has_key('ip'):41 # Extra (descriptive entries) are ignored 42 if '_extra' in iface_key: 29 43 continue 30 44 31 l = datadump[iface_key]['ip'] 32 addr, mask = l.split('/') 45 # Process actual and virtual IP (avoiding clashes with nanostation IP) 46 for entry in ['ip', 'ns_ip']: 47 if entry in datadump[iface_key]: 48 addr = ipaddress.IPv4Interface(unicode(datadump[iface_key][entry])) 49 if masterip_addr in addr.network: 50 masterip_is_used = True 51 pool[addr.network].append((host, iface_key, entry, addr)) 33 52 34 pool[addr].append((host, iface_key))35 53 36 iface_key = 'masterip'37 addr = datadump['masterip']38 54 # Add masterip to the list if IP has not been defined at interface 39 if not host in [x[0] for x in pool[addr]]:40 pool[addr].append((host, 'masterip'))55 if not masterip_is_used: 56 pool[masterip_addr.network].append((host, 'masterip', '', masterip_addr)) 41 57 42 58 print "OK" … … 48 64 sys.exit(1) 49 65 50 error = False 51 for addr,leden in pool.iteritems(): 52 if len(leden) > 1: 53 if not any(map(lambda x: addr.startswith(x), allowed_multi_use)): 54 print "[ERROR] Multiple usages of IP %s:" % (addr) 55 for host, key in leden: 56 print " - %s - %s" % (host, key) 57 error = True 66 errors = 0 67 keys = sorted(pool.keys(),reverse=True) 58 68 59 if error: 60 print "# Errors found" 69 for i,network in enumerate(keys): 70 if not network in allowed_multi_use: 71 for network2 in keys[i+1:]: 72 if not network2 in allowed_multi_use and network2.overlaps(network): 73 errors += 1 74 print "[ERROR#%i] network %s overlaps with %s:" % (errors, network, network2) 75 for (host, key, entry, addr) in sorted(pool[network] + pool[network2]): 76 print " - %-20s - %-20s - %-5s - %s" % (host, key, entry, addr) 77 78 leden = sorted(pool[network]) 79 for i,lid in enumerate(leden): 80 for lid2 in leden[i+1:]: 81 if lid[3] == lid2[3]: 82 errors += 1 83 print "[ERROR#%i] Multiple usages of IP %s:" % (errors, lid[3]) 84 print " - %-20s - %-20s - %-5s" % (lid[0], lid[1], lid[2]) 85 print " - %-20s - %-20s - %-5s" % (lid2[0], lid2[1], lid2[2]) 86 87 if errors > 0: 88 print "# %i Errors found" % errors 61 89 return 1 62 90 else:
Note:
See TracChangeset
for help on using the changeset viewer.