@Name: createConnection @Desc: Creates an ssh connection for retries mentioned,along with sleep mentioned @Output: SUCCESS on successful connection FAILED If connection through ssh failed
(self)
| 98 | return results |
| 99 | |
| 100 | def createConnection(self): |
| 101 | ''' |
| 102 | @Name: createConnection |
| 103 | @Desc: Creates an ssh connection for |
| 104 | retries mentioned,along with sleep mentioned |
| 105 | @Output: SUCCESS on successful connection |
| 106 | FAILED If connection through ssh failed |
| 107 | ''' |
| 108 | ret = FAILED |
| 109 | except_msg = '' |
| 110 | while self.retryCnt >= 0: |
| 111 | try: |
| 112 | self.logger.debug("====Trying SSH Connection: Host:%s User:%s\ |
| 113 | Port:%s RetryCnt:%s===" % |
| 114 | (self.host, self.user, str(self.port), |
| 115 | str(self.retryCnt))) |
| 116 | if self.keyPairFiles is None: |
| 117 | self.ssh.connect(hostname=self.host, |
| 118 | port=self.port, |
| 119 | username=self.user, |
| 120 | password=self.passwd, |
| 121 | timeout=self.timeout, |
| 122 | allow_agent=False) |
| 123 | else: |
| 124 | self.ssh.connect(hostname=self.host, |
| 125 | port=self.port, |
| 126 | username=self.user, |
| 127 | password=self.passwd, |
| 128 | key_filename=self.keyPairFiles, |
| 129 | timeout=self.timeout, |
| 130 | look_for_keys=False |
| 131 | ) |
| 132 | self.logger.debug("===SSH to Host %s port : %s SUCCESSFUL===" |
| 133 | % (str(self.host), str(self.port))) |
| 134 | ret = SUCCESS |
| 135 | break |
| 136 | except BadHostKeyException as e: |
| 137 | except_msg = GetDetailExceptionInfo(e) |
| 138 | except AuthenticationException as e: |
| 139 | except_msg = GetDetailExceptionInfo(e) |
| 140 | except SSHException as e: |
| 141 | except_msg = GetDetailExceptionInfo(e) |
| 142 | except socket.error as e: |
| 143 | except_msg = GetDetailExceptionInfo(e) |
| 144 | except Exception as e: |
| 145 | except_msg = GetDetailExceptionInfo(e) |
| 146 | finally: |
| 147 | if self.retryCnt == 0 or ret == SUCCESS: |
| 148 | break |
| 149 | if except_msg != '': |
| 150 | self.logger.\ |
| 151 | exception("SshClient: Exception under " |
| 152 | "createConnection: %s" % except_msg) |
| 153 | self.retryCnt -= 1 |
| 154 | time.sleep(self.delay) |
| 155 | return ret |
| 156 | |
| 157 | def runCommand(self, command): |
no test coverage detected