mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
commit
40c570b426
@ -137,12 +137,28 @@ def validateNetworkAndDevices():
|
|||||||
devicesValidatedOrNot = False
|
devicesValidatedOrNot = False
|
||||||
with open('network.json') as file:
|
with open('network.json') as file:
|
||||||
try:
|
try:
|
||||||
temporaryVariable = json.load(file) # put JSON-data to a variable
|
data = json.load(file) # put JSON-data to a variable
|
||||||
|
if data != {}:
|
||||||
|
#Traverse
|
||||||
|
observedNodes = {} # Will not be used later
|
||||||
|
def traverseToVerifyValidity(data):
|
||||||
|
for elem in data:
|
||||||
|
if isinstance(elem, str):
|
||||||
|
if (isinstance(data[elem], dict)) and (elem != 'children'):
|
||||||
|
if elem not in observedNodes:
|
||||||
|
observedNodes[elem] = {'downloadBandwidthMbps': data[elem]['uploadBandwidthMbps'], 'downloadBandwidthMbps': data[elem]['uploadBandwidthMbps']}
|
||||||
|
if 'children' in data[elem]:
|
||||||
|
traverseToVerifyValidity(data[elem]['children'])
|
||||||
|
else:
|
||||||
|
warnings.warn("Non-unique Node name in network.json: " + elem, stacklevel=2)
|
||||||
|
networkValidatedOrNot = False
|
||||||
|
traverseToVerifyValidity(data)
|
||||||
|
if len(observedNodes) < 1:
|
||||||
|
warnings.warn("network.json had 0 valid nodes. Only {} is accepted for that scenario.", stacklevel=2)
|
||||||
|
networkValidatedOrNot = False
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
warnings.warn("network.json is an invalid JSON file", stacklevel=2) # in case json is invalid
|
warnings.warn("network.json is an invalid JSON file", stacklevel=2) # in case json is invalid
|
||||||
networkValidatedOrNot
|
networkValidatedOrNot = False
|
||||||
if networkValidatedOrNot == True:
|
|
||||||
print("network.json passed validation")
|
|
||||||
rowNum = 2
|
rowNum = 2
|
||||||
with open('ShapedDevices.csv') as csv_file:
|
with open('ShapedDevices.csv') as csv_file:
|
||||||
csv_reader = csv.reader(csv_file, delimiter=',')
|
csv_reader = csv.reader(csv_file, delimiter=',')
|
||||||
@ -255,8 +271,11 @@ def validateNetworkAndDevices():
|
|||||||
print("ShapedDevices.csv passed validation")
|
print("ShapedDevices.csv passed validation")
|
||||||
else:
|
else:
|
||||||
print("ShapedDevices.csv failed validation")
|
print("ShapedDevices.csv failed validation")
|
||||||
|
if networkValidatedOrNot == True:
|
||||||
if (devicesValidatedOrNot == True) and (devicesValidatedOrNot == True):
|
print("network.json passed validation")
|
||||||
|
else:
|
||||||
|
print("network.json failed validation")
|
||||||
|
if (devicesValidatedOrNot == True) and (networkValidatedOrNot == True):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user