mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-09-03 20:52:56 -05:00
Allow freeipa-tests to work with older paramiko versions
The integration testing framework used Paramiko SFTP files as context managers. This feature is only available in Paramiko 1.10+. Use an explicit context manager so that we don't rely on the feature.
This commit is contained in:
committed by
Martin Kosek
parent
b1474a53c0
commit
a8d2ec6677
+4
-1
@@ -304,7 +304,7 @@ Requires: python-nose
|
||||
Requires: python-paste
|
||||
Requires: python-coverage
|
||||
Requires: python-polib
|
||||
Requires: python-paramiko >= 1.10.1
|
||||
Requires: python-paramiko >= 1.7.7
|
||||
|
||||
%description tests
|
||||
IPA is an integrated solution to provide centrally managed Identity (machine,
|
||||
@@ -833,6 +833,9 @@ fi
|
||||
%endif # ONLY_CLIENT
|
||||
|
||||
%changelog
|
||||
* Mon Aug 12 2013 Petr Viktorin <pviktori@redhat.com> - 3.3.90-1
|
||||
- Downgrade required version of python-paramiko for the tests subpackage
|
||||
|
||||
* Thu Aug 8 2013 Martin Kosek <mkosek@redhat.com> - 3.2.99-13
|
||||
- Require slapi-nis 0.47.7 and sssd 1.11.0-0.1.beta2 required for core
|
||||
features of 3.3.0 release
|
||||
|
||||
@@ -23,6 +23,7 @@ import os
|
||||
import socket
|
||||
import threading
|
||||
import subprocess
|
||||
from contextlib import contextmanager
|
||||
import errno
|
||||
|
||||
import paramiko
|
||||
@@ -118,6 +119,21 @@ class RemoteCommand(object):
|
||||
return thread
|
||||
|
||||
|
||||
@contextmanager
|
||||
def sftp_open(sftp, filename, mode='r'):
|
||||
"""Context manager that provides a file-like object over a SFTP channel
|
||||
|
||||
This provides compatibility with older Paramiko versions.
|
||||
(In Paramiko 1.10+, file objects from `sftp.open` are directly usable as
|
||||
context managers).
|
||||
"""
|
||||
file = sftp.open(filename, mode)
|
||||
try:
|
||||
yield file
|
||||
finally:
|
||||
file.close()
|
||||
|
||||
|
||||
class Host(object):
|
||||
"""Representation of a remote IPA host"""
|
||||
def __init__(self, domain, hostname, role, index, ip=None):
|
||||
@@ -314,13 +330,13 @@ class Host(object):
|
||||
def get_file_contents(self, filename):
|
||||
"""Read the named remote file and return the contents as a string"""
|
||||
self.log.debug('READ %s', filename)
|
||||
with self.sftp.open(filename) as f:
|
||||
with sftp_open(self.sftp, filename) as f:
|
||||
return f.read()
|
||||
|
||||
def put_file_contents(self, filename, contents):
|
||||
"""Write the given string to the named remote file"""
|
||||
self.log.info('WRITE %s', filename)
|
||||
with self.sftp.open(filename, 'w') as f:
|
||||
with sftp_open(self.sftp, filename, 'w') as f:
|
||||
f.write(contents)
|
||||
|
||||
def file_exists(self, filename):
|
||||
|
||||
Reference in New Issue
Block a user