Bug 1494091: [mozharness] Remove unused rsync support from mozharness; r=Callek
authorTom Prince <mozilla@hocat.ca>
Tue, 02 Oct 2018 18:29:19 +0000
changeset 439277 7b4f5573b9bb2c4b55814054936822dd42dcc0ed
parent 439276 d210ac107dd7211e53e12762ccfd14078b718ee1
child 439278 2c0c424f36e49b166abd758bda037ecda709f379
push id34760
push userdvarga@mozilla.com
push dateWed, 03 Oct 2018 04:19:01 +0000
treeherdermozilla-central@9e0a27bf253e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCallek
bugs1494091
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494091: [mozharness] Remove unused rsync support from mozharness; r=Callek Differential Revision: https://phabricator.services.mozilla.com/D6836
testing/mozharness/mozharness/base/transfer.py
testing/mozharness/test/test_base_transfer.py
--- a/testing/mozharness/mozharness/base/transfer.py
+++ b/testing/mozharness/mozharness/base/transfer.py
@@ -22,99 +22,16 @@ from mozharness.base.log import DEBUG, E
 
 # TransferMixin {{{1
 class TransferMixin(object):
     """
     Generic transfer methods.
 
     Dependent on BaseScript.
     """
-    def rsync_upload_directory(self, local_path, ssh_key, ssh_user,
-                               remote_host, remote_path,
-                               rsync_options=None,
-                               error_level=ERROR,
-                               create_remote_directory=True,
-                               ):
-        """
-        Create a remote directory and upload the contents of
-        a local directory to it via rsync+ssh.
-
-        Returns:
-            None: on success
-              -1: if local_path is not a directory
-              -2: if the remote_directory cannot be created
-                  (it only makes sense if create_remote_directory is True)
-              -3: rsync fails to copy to the remote directory
-        """
-        dirs = self.query_abs_dirs()
-        self.info("Uploading the contents of %s to %s:%s" % (local_path, remote_host, remote_path))
-        rsync = self.query_exe("rsync")
-        ssh = self.query_exe("ssh")
-        if rsync_options is None:
-            rsync_options = ['-azv']
-        if not os.path.isdir(local_path):
-            self.log("%s isn't a directory!" % local_path,
-                     level=ERROR)
-            return -1
-        if create_remote_directory:
-            mkdir_error_list = [{
-                'substr': r'''exists but is not a directory''',
-                'level': ERROR
-            }] + SSHErrorList
-            if self.run_command([ssh, '-oIdentityFile=%s' % ssh_key,
-                                 '%s@%s' % (ssh_user, remote_host),
-                                 'mkdir', '-p', remote_path],
-                                cwd=dirs['abs_work_dir'],
-                                return_type='num_errors',
-                                error_list=mkdir_error_list):
-                self.log("Unable to create remote directory %s:%s!" % (remote_host, remote_path), level=error_level)
-                return -2
-        if self.run_command([rsync, '-e',
-                             '%s -oIdentityFile=%s' % (ssh, ssh_key)
-                             ] + rsync_options + ['.',
-                            '%s@%s:%s/' % (ssh_user, remote_host, remote_path)],
-                            cwd=local_path,
-                            return_type='num_errors',
-                            error_list=SSHErrorList):
-            self.log("Unable to rsync %s to %s:%s!" % (local_path, remote_host, remote_path), level=error_level)
-            return -3
-
-    def rsync_download_directory(self, ssh_key, ssh_user, remote_host,
-                                 remote_path, local_path,
-                                 rsync_options=None,
-                                 error_level=ERROR,
-                                 ):
-        """
-        rsync+ssh the content of a remote directory to local_path
-
-        Returns:
-            None: on success
-              -1: if local_path is not a directory
-              -3: rsync fails to download from the remote directory
-        """
-        self.info("Downloading the contents of %s:%s to %s" % (remote_host, remote_path, local_path))
-        rsync = self.query_exe("rsync")
-        ssh = self.query_exe("ssh")
-        if rsync_options is None:
-            rsync_options = ['-azv']
-        if not os.path.isdir(local_path):
-            self.log("%s isn't a directory!" % local_path,
-                     level=error_level)
-            return -1
-        if self.run_command([rsync, '-e',
-                             '%s -oIdentityFile=%s' % (ssh, ssh_key)
-                             ] + rsync_options + [
-                            '%s@%s:%s/' % (ssh_user, remote_host, remote_path),
-                            '.'],
-                            cwd=local_path,
-                            return_type='num_errors',
-                            error_list=SSHErrorList):
-            self.log("Unable to rsync %s:%s to %s!" % (remote_host, remote_path, local_path), level=error_level)
-            return -3
-
     def load_json_from_url(self, url, timeout=30, log_level=DEBUG):
         self.log("Attempting to download %s; timeout=%i" % (url, timeout),
                  level=log_level)
         try:
             r = urllib2.urlopen(url, timeout=timeout)
             j = json.load(r)
             self.log(pprint.pformat(j), level=log_level)
         except:
deleted file mode 100644
--- a/testing/mozharness/test/test_base_transfer.py
+++ /dev/null
@@ -1,127 +0,0 @@
-import unittest
-import mock
-
-from mozharness.base.transfer import TransferMixin
-
-
-class GoodMockMixin(object):
-    def query_abs_dirs(self):
-        return {'abs_work_dir': ''}
-
-    def query_exe(self, exe):
-        return exe
-
-    def info(self, msg):
-        pass
-
-    def log(self, msg, level):
-        pass
-
-    def run_command(*args, **kwargs):
-        return 0
-
-
-class BadMockMixin(GoodMockMixin):
-    def run_command(*args, **kwargs):
-        return 1
-
-
-class GoodTransferMixin(TransferMixin, GoodMockMixin):
-    pass
-
-
-class BadTransferMixin(TransferMixin, BadMockMixin):
-    pass
-
-
-class TestTranferMixin(unittest.TestCase):
-    @mock.patch('mozharness.base.transfer.os')
-    def test_rsync_upload_dir_not_a_dir(self, os_mock):
-        # simulates upload dir but dir is a file
-        os_mock.path.isdir.return_value = False
-        tm = GoodTransferMixin()
-        self.assertEqual(tm.rsync_upload_directory(
-                         local_path='',
-                         ssh_key='my ssh key',
-                         ssh_user='my ssh user',
-                         remote_host='remote host',
-                         remote_path='remote path',), -1)
-
-    @mock.patch('mozharness.base.transfer.os')
-    def test_rsync_upload_fails_create_remote_dir(self, os_mock):
-        # we cannot create the remote directory
-        os_mock.path.isdir.return_value = True
-        tm = BadTransferMixin()
-        self.assertEqual(tm.rsync_upload_directory(
-                         local_path='',
-                         ssh_key='my ssh key',
-                         ssh_user='my ssh user',
-                         remote_host='remote host',
-                         remote_path='remote path',
-                         create_remote_directory=True), -2)
-
-    @mock.patch('mozharness.base.transfer.os')
-    def test_rsync_upload_fails_do_not_create_remote_dir(self, os_mock):
-        # upload fails, remote directory is not created
-        os_mock.path.isdir.return_value = True
-        tm = BadTransferMixin()
-        self.assertEqual(tm.rsync_upload_directory(
-                         local_path='',
-                         ssh_key='my ssh key',
-                         ssh_user='my ssh user',
-                         remote_host='remote host',
-                         remote_path='remote path',
-                         create_remote_directory=False), -3)
-
-    @mock.patch('mozharness.base.transfer.os')
-    def test_rsync_upload(self, os_mock):
-        # simulates an upload with no errors
-        os_mock.path.isdir.return_value = True
-        tm = GoodTransferMixin()
-        self.assertEqual(tm.rsync_upload_directory(
-                         local_path='',
-                         ssh_key='my ssh key',
-                         ssh_user='my ssh user',
-                         remote_host='remote host',
-                         remote_path='remote path',
-                         create_remote_directory=False), None)
-
-    @mock.patch('mozharness.base.transfer.os')
-    def test_rsync_download_in_not_a_dir(self, os_mock):
-        # local path is not a directory
-        os_mock.path.isdir.return_value = False
-        tm = GoodTransferMixin()
-        self.assertEqual(tm.rsync_download_directory(
-                         local_path='',
-                         ssh_key='my ssh key',
-                         ssh_user='my ssh user',
-                         remote_host='remote host',
-                         remote_path='remote path',), -1)
-
-    @mock.patch('mozharness.base.transfer.os')
-    def test_rsync_download(self, os_mock):
-        # successful rsync
-        os_mock.path.isdir.return_value = True
-        tm = GoodTransferMixin()
-        self.assertEqual(tm.rsync_download_directory(
-                         local_path='',
-                         ssh_key='my ssh key',
-                         ssh_user='my ssh user',
-                         remote_host='remote host',
-                         remote_path='remote path',), None)
-
-    @mock.patch('mozharness.base.transfer.os')
-    def test_rsync_download_fail(self, os_mock):
-        # ops download has failed
-        os_mock.path.isdir.return_value = True
-        tm = BadTransferMixin()
-        self.assertEqual(tm.rsync_download_directory(
-                         local_path='',
-                         ssh_key='my ssh key',
-                         ssh_user='my ssh user',
-                         remote_host='remote host',
-                         remote_path='remote path',), -3)
-
-
-if __name__ == '__main__':
-    unittest.main()