Fix undefined vars in cnos module_utils
Fixing undefined vars across the codebase so that we can have pylint catch them on every commit. Some of the changes to this module_utils file are Python3 related => The identifiers exist on python2 but not on Python3. The changes should be portable to both py2 (2.6+) and py3. References #27193
This commit is contained in:
parent
84285a741c
commit
59fa35446b
1 changed files with 17 additions and 26 deletions
|
@ -1950,7 +1950,7 @@ def bgpConfig(
|
||||||
|
|
||||||
elif(bgpArg1 == "log-neighbor-changes"):
|
elif(bgpArg1 == "log-neighbor-changes"):
|
||||||
# debugOutput(bgpArg1)
|
# debugOutput(bgpArg1)
|
||||||
command = command + bgpArg1f
|
command = command + bgpArg1
|
||||||
|
|
||||||
elif(bgpArg1 == "maxas-limit"):
|
elif(bgpArg1 == "maxas-limit"):
|
||||||
# debugOutput(bgpArg1)
|
# debugOutput(bgpArg1)
|
||||||
|
@ -3257,15 +3257,14 @@ def checkSanityofVariable(deviceType, variableId, variableValue):
|
||||||
def getRuleStringForVariable(deviceType, ruleFile, variableId):
|
def getRuleStringForVariable(deviceType, ruleFile, variableId):
|
||||||
retVal = ""
|
retVal = ""
|
||||||
try:
|
try:
|
||||||
# with open(ruleFile, 'r') as f:
|
with open(ruleFile, 'r') as f:
|
||||||
f = open(errorFile, 'r')
|
for line in f:
|
||||||
for line in f:
|
# debugOutput(line)
|
||||||
# debugOutput(line)
|
if(':' in line):
|
||||||
if(':' in line):
|
data = line.split(':')
|
||||||
data = line.split(':')
|
# debugOutput(data[0])
|
||||||
# debugOutput(data[0])
|
if(data[0].strip() == variableId):
|
||||||
if(data[0].strip() == variableId):
|
retVal = line
|
||||||
retVal = line
|
|
||||||
except Exception:
|
except Exception:
|
||||||
ruleString = cnos_devicerules.getRuleString(deviceType, variableId)
|
ruleString = cnos_devicerules.getRuleString(deviceType, variableId)
|
||||||
retVal = ruleString.strip()
|
retVal = ruleString.strip()
|
||||||
|
@ -3342,7 +3341,7 @@ def validateValueAgainstRule(ruleString, variableValue):
|
||||||
return "Error-115"
|
return "Error-115"
|
||||||
|
|
||||||
elif(variableType == "LONG"):
|
elif(variableType == "LONG"):
|
||||||
result = checkLong(variableValue)
|
result = checkInteger(variableValue)
|
||||||
if(result is True):
|
if(result is True):
|
||||||
return "ok"
|
return "ok"
|
||||||
else:
|
else:
|
||||||
|
@ -3350,11 +3349,11 @@ def validateValueAgainstRule(ruleString, variableValue):
|
||||||
|
|
||||||
elif(variableType == "LONG_VALUE"):
|
elif(variableType == "LONG_VALUE"):
|
||||||
long_range = varRange.split('-')
|
long_range = varRange.split('-')
|
||||||
r = range(long(long_range[0].strip()), long(long_range[1].strip()))
|
r = range(int(long_range[0].strip()), int(long_range[1].strip()))
|
||||||
if(checkLong(variableValue) is not True):
|
if(checkInteger(variableValue) is not True):
|
||||||
# debugOutput(variableValue)
|
# debugOutput(variableValue)
|
||||||
return "Error-116"
|
return "Error-116"
|
||||||
result = long(variableValue) in r
|
result = int(variableValue) in r
|
||||||
if(result is True):
|
if(result is True):
|
||||||
return "ok"
|
return "ok"
|
||||||
else:
|
else:
|
||||||
|
@ -3362,10 +3361,10 @@ def validateValueAgainstRule(ruleString, variableValue):
|
||||||
|
|
||||||
elif(variableType == "LONG_VALUE_RANGE"):
|
elif(variableType == "LONG_VALUE_RANGE"):
|
||||||
long_range = varRange.split('-')
|
long_range = varRange.split('-')
|
||||||
r = range(long(long_range[0].strip()), long(long_range[1].strip()))
|
r = range(int(long_range[0].strip()), int(long_range[1].strip()))
|
||||||
val_range = variableValue.split('-')
|
val_range = variableValue.split('-')
|
||||||
if((checkLong(val_range[0]) is not True) or
|
if((checkInteger(val_range[0]) is not True) or
|
||||||
(checkLong(val_range[1]) is not True)):
|
(checkInteger(val_range[1]) is not True)):
|
||||||
return "Error-117"
|
return "Error-117"
|
||||||
result = (val_range[0] in r) and (
|
result = (val_range[0] in r) and (
|
||||||
val_range[1] in r) and (val_range[0] < val_range[1])
|
val_range[1] in r) and (val_range[0] < val_range[1])
|
||||||
|
@ -3375,7 +3374,7 @@ def validateValueAgainstRule(ruleString, variableValue):
|
||||||
return "Error-113"
|
return "Error-113"
|
||||||
elif(variableType == "LONG_OPTIONS"):
|
elif(variableType == "LONG_OPTIONS"):
|
||||||
long_options = varRange.split(',')
|
long_options = varRange.split(',')
|
||||||
if(checkLong(variableValue) is not True):
|
if(checkInteger(variableValue) is not True):
|
||||||
return "Error-116"
|
return "Error-116"
|
||||||
for opt in long_options:
|
for opt in long_options:
|
||||||
if(opt.strip() == variableValue):
|
if(opt.strip() == variableValue):
|
||||||
|
@ -3531,14 +3530,6 @@ def checkFloat(s):
|
||||||
# EOM
|
# EOM
|
||||||
|
|
||||||
|
|
||||||
def checkLong(s):
|
|
||||||
try:
|
|
||||||
long(s)
|
|
||||||
return True
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def debugOutput(command):
|
def debugOutput(command):
|
||||||
f = open('debugOuput.txt', 'a')
|
f = open('debugOuput.txt', 'a')
|
||||||
f.write(str(command)) # python will convert \n to os.linesep
|
f.write(str(command)) # python will convert \n to os.linesep
|
||||||
|
|
Loading…
Reference in a new issue