Hi All,

Please find the patch for pytest-multihost-plugin.

Fixes : https://fedorahosted.org/python-pytest-multihost/ticket/2

Thanks,
Abhijeet Kasurde
From 72dfedf298ed6e27cc10f7c63fa1202a0942c88e Mon Sep 17 00:00:00 2001
From: Abhijeet Kasurde <akasu...@redhat.com>
Date: Wed, 25 Nov 2015 14:30:35 +0530
Subject: [PATCH] Added functions for handling various file operations

Functions are added for removing directory, removing file,
renaming file.

https://fedorahosted.org/python-pytest-multihost/ticket/2

Signed-off-by: Abhijeet Kasurde <akasu...@redhat.com>
---
 pytest_multihost/transport.py | 46 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/pytest_multihost/transport.py b/pytest_multihost/transport.py
index 2b1ccbc32e8ed4b28e263d9bbe2df4bc2c8617de..f85099fd856e461ca68a342050fae61508c34d10 100644
--- a/pytest_multihost/transport.py
+++ b/pytest_multihost/transport.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2013  Red Hat
+# Copyright (C) 2015  Red Hat
 # Copyright (C) 2014  pytest-multihost contributors
 # See COPYING for license
 #
@@ -98,6 +98,18 @@ class Transport(object):
         self._command_index += 1
         return '%s.cmd%s' % (self.host.logger_name, self._command_index)
 
+    def rmdir(self, path):
+        """Remove directory"""
+        raise NotImplementedError('Transport.rmdir')
+
+    def rename_file(self, oldpath, newpath):
+        """Rename file"""
+        raise NotImplementedError('Transport.rename_file')
+
+    def remove_file(self, filepath):
+        """Removes files"""
+        raise NotImplementedError('Transport.remove_file')
+
 
 class Command(object):
     """A Popen-style object representing a remote command
@@ -246,6 +258,18 @@ class ParamikoTransport(Transport):
         self.log.info('PUT %s', remotepath)
         self.sftp.put(localpath, remotepath)
 
+    def rmdir(self, path):
+        self.log.info('RMDIR %s', path)
+        self.sftp.rmdir(path)
+
+    def remove_file(self, filepath):
+        self.log.info('REMOVE FILE %s', filepath)
+        self.sftp.remove(filepath)
+
+    def rename_file(self, oldpath, newpath):
+        self.log.info('RENAME %s to %s', oldpath, newpath)
+        self.sftp.rename(oldpath, newpath)
+
 
 class OpenSSHTransport(Transport):
     """Transport that uses the `ssh` binary"""
@@ -341,6 +365,26 @@ class OpenSSHTransport(Transport):
         else:
             raise IOError('File %r could not be read' % filename)
 
+    def rmdir(self, path):
+        self.log.info('RMDIR %s', path)
+        cmd = self._run(['rmdir', path])
+        cmd.wait()
+
+    def remove_file(self, filepath):
+        self.log.info('REMOVE FILE %s', filepath)
+        cmd = self._run(['rm', filepath])
+        cmd.wait()
+        if cmd.returncode != 0:
+            raise IOError('File %r could not be deleted' % filepath)
+
+    def rename_file(self, oldpath, newpath):
+        self.log.info('RENAME %s TO %s', oldpath, newpath)
+        cmd = self._run(['mv', oldpath, newpath])
+        cmd.wait()
+        if cmd.returncode != 0:
+            raise IOError('File %r could not be renamed to %r '
+                          % (oldpath, newpath))
+
 
 class SSHCallWrapper(object):
     """Adapts a /usr/bin/ssh call to the paramiko.Channel interface
-- 
2.4.3

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to