def test_copy_logs_closes_sftp(self, mock_copy_logs_sftp, mock_get_ssh): mock_ssh = mock.Mock() mock_sftp = mock.Mock() mock_get_ssh.return_value = mock_ssh mock_ssh.open_sftp.return_value = mock_sftp utils.copy_logs(None, None, None, None, None, None) mock_ssh.close.assert_called_with() mock_sftp.close.assert_called_with()
def retrieveResults(self, dest_path): if not self.node_ip: self.log.error('Attempting to retrieve results for %s but no node IP address'%self) return constants.NO_IP try: code, stdout, stderr = utils.execute_command( 'ssh -q -o BatchMode=yes -o UserKnownHostsFile=/dev/null' ' -o StrictHostKeyChecking=no -i %s %s@%s cat result.txt' % ( Configuration().NODE_KEY, Configuration().NODE_USERNAME, self.node_ip), silent=True, return_streams=True ) self.log.info('Result: %s (Err: %s)'%(stdout, stderr)) self.log.info('Downloading logs for %s'%self) utils.copy_logs( [ '/home/jenkins/workspace/testing/logs/*', '/home/jenkins/run_test*', '/etc/nova/*', '/etc/swift/*', '/etc/cinder/*', '/etc/keystone/*', ], dest_path, self.node_ip, Configuration().NODE_USERNAME, Configuration().NODE_KEY, upload=False ) self.log.info('Downloading dom0 logs for %s'%self) utils.copy_dom0_logs( self.node_ip, Configuration().NODE_USERNAME, Configuration().NODE_KEY, dest_path ) if code != 0: # This node is broken somehow... Mark it as aborted if self.result and self.result.startswith('Aborted: '): return self.result return constants.NORESULT return stdout.splitlines()[0] except Exception, e: self.log.exception(e) return constants.COPYFAIL