From eee6da857fe49007c08059b7080db309796fb77d Mon Sep 17 00:00:00 2001 From: Anil Kumar Muraleedharan Date: Sat, 26 Aug 2017 23:08:00 +0530 Subject: [PATCH] Update CNOS.py to fix error in image download on devices (#28589) * Update CNOS.py to fix error in image download on devices * Fixing Bug on Swaping of character indexes of error strings --- lib/ansible/module_utils/cnos.py | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/ansible/module_utils/cnos.py b/lib/ansible/module_utils/cnos.py index 98ae618fc68..d3088f27dbb 100644 --- a/lib/ansible/module_utils/cnos.py +++ b/lib/ansible/module_utils/cnos.py @@ -2986,13 +2986,15 @@ def doImageTransfer( else: return "Error-110" # debugOutput(command) - retVal = retVal + waitForDeviceResponse(command, "[n]", 3, obj) + response = waitForDeviceResponse(command, "[n]", 3, obj) + if(response.lower().find("error-101")): + retVal = retVal + else: + retVal = retVal + response + # Confirmation command happens here command = "y\n" # debugOutput(command) - # retVal = retVal+ waitForDeviceResponse(command, "(yes/no)?", 3, obj) - # command = "Yes \n" - # debugOutput(command) if(protocol == "ftp"): retVal = retVal + waitForDeviceResponse(command, "Password:", 3, obj) # Password entry happens here Only for FTP @@ -3034,12 +3036,20 @@ def doSecureImageTransfer( command = "cp " + protocol + " " + protocol + "://" + username + "@" + \ server + "/" + imgPath + " system-image " + type + " vrf management \n" # debugOutput(command) - retVal = retVal + waitForDeviceResponse(command, "[n]", 3, obj) + response = waitForDeviceResponse(command, "[n]", 3, obj) + if(response.lower().find("error-101")): + retVal = retVal + else: + retVal = retVal + response # Confirmation command happens here if(protocol == "scp"): command = "y\n" # debugOutput(command) - retVal = retVal + waitForDeviceResponse(command, "(yes/no)?", 3, obj) + response = waitForDeviceResponse(command, "(yes/no)?", 3, obj) + if(response.lower().find("error-101")): + retVal = retVal + else: + retVal = retVal + response command = "Yes\n" # debugOutput(command) retVal = retVal + waitForDeviceResponse(command, "timeout:", 3, obj) @@ -3049,7 +3059,12 @@ def doSecureImageTransfer( elif(protocol == "sftp"): command = "y\n" # debugOutput(command) - retVal = retVal + waitForDeviceResponse(command, "(yes/no)?", 3, obj) + response = waitForDeviceResponse(command, "(yes/no)?", 3, obj) + if(response.lower().find("error-101")): + retVal = retVal + else: + retVal = retVal + response + command = "Yes\n" # debugOutput(command) retVal = retVal + waitForDeviceResponse(command, "Password:", 3, obj) @@ -3160,13 +3175,16 @@ def checkOutputForError(output): index = output.lower().find("invalid") startIndex = index + 8 if(index == -1): - index = output.lower().find("incorrect") - startIndex = index + 9 + index = output.lower().find("Cannot be enabled in L2 Interface") + startIndex = index + 34 if(index == -1): - index = output.lower().find("failure") - startIndex = index + 8 + index = output.lower().find("incorrect") + startIndex = index + 10 if(index == -1): - return None + index = output.lower().find("failure") + startIndex = index + 8 + if(index == -1): + return None endIndex = startIndex + 3 errorCode = output[startIndex:endIndex]