Crispin Wellington avatar Crispin Wellington committed e0080bf Merge

merged downstream

Comments (0)

Files changed (5)

             run("rm '%s'"%filename)
             print green(os.path.basename(filename))
 
+
+
 # the distribution module instances
 debian = Debian()
 ubuntu = Ubuntu()
     command.append('rsync')
     command.append('-av')
 
-    if env.key_filename is not None:
+    custom_port = int(env.port) if env.port is not None and env.port != '22' else None
+    if env.key_filename is not None or custom_port is not None:
+        ssh_arguments = []
+
+        # use specified port if it is a non-standard port
+        if custom_port is not None:
+            ssh_arguments.append("-p {0.port}".format(env))
+
         # use specified identity file to connect
+        keyfiles = []
         if type(env.key_filename) in (str, unicode): 
-            ssh_command = "'ssh -l {0.user} -i \"{0.key_filename}\"'".format(env)
-        else:
+            keyfiles = [env.key_filename]
+        elif env.key_filename:
             assert type(env.key_filename) in (list, tuple), "malformed env.key_filename: %r"%(env.key_filename)
-            ssh_command = "'ssh -l {0} {1}'".format(env.user, ' '.join(
-                ['-i "{0}"'.format(keyfile) 
-                 for keyfile in env.key_filename]))
+            keyfiles = env.key_filename
+        if keyfiles:
+            ssh_arguments.append("-l {0}".format(env.user))
+            ssh_arguments += ['-i "{0}"'.format(keyfile) for keyfile in keyfiles]
+
+        ssh_command = "'ssh {0}'".format(" ".join(ssh_arguments))
         command.extend(['-e',ssh_command])
 
     command.extend("'%s'"%s for s in sources)

tests/test_deploy.py

-import sys
 import os
 import unittest2 as unittest
-from functools import partial
 import shutil
-import mock
 from mock import patch
 
 from parcel.deploy import Deployment
-from parcel.distro import Debian, Centos, centos
+from parcel.distro import centos
 from parcel.versions import Version
 from parcel_mocks import (run, rsync, version_mock, update_packages,
                           build_deps, mock_put, mock_get, lcd, mock_local)
     def setUp(self):
         self.app_name = "testapp"
         self.deploy = TestDeploy(self.app_name)
-        
+
     def tearDown(self):
-        test_build_dir = os.path.join(os.path.expanduser('~/'), '.parcel_test') 
+        test_build_dir = os.path.join(os.path.expanduser('~/'), '.parcel_test')
         shutil.rmtree(test_build_dir, True)
         for m in mocks_to_reset:
             m.reset_mock()
-        
+
     def test_write_prerm_template(self):
         prerm_template = "Test rm template {app_name} and {lines}"
 
 
     def setUp(self):
         pass
-    
+
     def tearDown(self):
-        test_build_dir = os.path.join(os.path.expanduser('~/'), '.parcel_test') 
+        test_build_dir = os.path.join(os.path.expanduser('~/'), '.parcel_test')
         shutil.rmtree(test_build_dir, True)
         for m in mocks_to_reset:
             m.reset_mock()
-            
+
         # remove the deb we may have built
-        deb = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.2_all.deb")
+        deb = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.2_all.deb")
         if os.path.exists(deb):
             os.unlink(deb)
 
         basepath = os.path.join(os.path.expanduser('~/'))
         d = Deployment('testapp', base=basepath)
         d.prepare_app()
-        
+
         # version
         self.assertEquals(d.version.version, Version('0.1.2').version)
 
         # now check with no basepath
         d = Deployment('testapp')
         self.assertTrue(basepath in d.build_path)
-        
+
         # now check with basepath without initial slash
         basepath = os.path.join(os.path.dirname(__file__))
         d = Deployment('testapp', base=basepath[1:])
         self.assertTrue(basepath in d.build_path)
-        
+
     @patch('parcel.deploy.deploy.run', mock_local())
     @patch.multiple('parcel.tools', run=mock_local(), rsync=rsync)
     @patch('parcel.distro.run', mock_local())
         # if we supply build_deps then this should be called
         build_deps.assert_called_once()
 
-
     @patch('parcel.deploy.deploy.run', mock_local())
     @patch.multiple('parcel.tools', run=mock_local(), rsync=rsync)
     @patch('parcel.distro.run', mock_local())
         ve_path = os.path.join(d.build_path, d.virtual)
         self.assertTrue(os.path.exists(ve_path))
 
-
     @patch.multiple('parcel.deploy.deploy', run=mock_local(), put=mock_put, cd=lcd, get=mock_get)
     @patch.multiple('parcel.tools', run=mock_local(), rsync=rsync, put=mock_put)
     @patch('parcel.distro.run', mock_local())
         self.assertTrue(os.path.exists(ve_path))
 
         # check we can add a file
-        test_file = os.path.join(os.path.dirname(__file__),"data", "tip.tar.gz")
+        test_file = os.path.join(os.path.dirname(__file__), "data", "tip.tar.gz")
         d.add_to_root_fs(test_file, 'tip.tar.gz')
         dest_file = os.path.join(d.root_path, "tip.tar.gz")
         self.assertTrue(os.path.exists(dest_file))
             self.assertEquals(data, f.read())
 
         # check we can compile python files
+        test_file = os.path.join(os.path.dirname(__file__), "data", "hello.py")
+        d.add_to_root_fs(test_file, 'hello.py')
         d.compile_python()
-        dest_file = os.path.join(d.build_path, 'data', 'hello.pyc')
+        dest_file = os.path.join(d.build_path, 'hello.pyc')
         self.assertTrue(os.path.exists(dest_file))
 
         # check we can clear .py and just leave .pyc files
         dest_file = os.path.join(d.build_path, 'data', 'hello.py')
         self.assertFalse(os.path.exists(dest_file))
 
-
     @patch.multiple('parcel.deploy.deploy', run=mock_local(), put=mock_put, cd=lcd, get=mock_get)
     @patch.multiple('parcel.tools', run=mock_local(), rsync=rsync, put=mock_put)
     @patch.multiple('parcel.distro', run=mock_local(), get=mock_get)
         d = Deployment('testapp', base=basepath)
         d.root_path = os.path.join(basepath, '.parcel')
         d.prepare_app()
-        
+
         # test build, will not actually call fpm
         d.build_package()
-        dest_file = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.2_all.deb")
+        dest_file = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.2_all.deb")
         self.assertTrue(os.path.exists(dest_file))
         os.unlink(dest_file)
 
         d = Deployment('testapp', base=basepath)
         d.root_path = os.path.join(basepath, '.parcel_test')
         d.build_package(templates=False)
-        dest_file = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.2_all.deb")
+        dest_file = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.2_all.deb")
         self.assertTrue(os.path.exists(dest_file))
         os.unlink(dest_file)
 
         d.preinst = " ".join(lines)
         d.postinst = " ".join(lines)
         d.build_package()
-        dest_file = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.2_all.deb")
+        dest_file = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.2_all.deb")
         self.assertTrue(os.path.exists(dest_file))
         os.unlink(dest_file)
 
-
     @patch('parcel.deploy.deploy.run', run)
     @patch('parcel.distro.run', mock_local())
     @patch.multiple('parcel.distro.Debian', version=version_mock, update_packages=update_packages)
     def test_add_venv_with_requirements(self):
         basepath = os.path.join(os.path.expanduser('~/'))
         d = Deployment('testapp', base=basepath)
-        req_file = os.path.join(os.path.dirname(__file__),"data", "requirements_test")
+        req_file = os.path.join(os.path.dirname(__file__), "data", "requirements_test")
 
         # call _add_venv directly so we can just mock that run out
         d._add_venv(requirements=req_file)
 
     def setUp(self):
         pass
-    
+
     def tearDown(self):
-        test_build_dir = os.path.join(os.path.expanduser('~/'), '.parcel_test') 
+        test_build_dir = os.path.join(os.path.expanduser('~/'), '.parcel_test')
         shutil.rmtree(test_build_dir, True)
         for m in mocks_to_reset:
             m.reset_mock()
-            
+
         # remove the deb we may have built
-        deb = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.1-1.noarch.rpm")
+        deb = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.1-1.noarch.rpm")
         if os.path.exists(deb):
             os.unlink(deb)
 
-
     # centos tests
     @patch.multiple('parcel.deploy.deploy', run=mock_local(), put=mock_put, cd=lcd, get=mock_get)
     @patch.multiple('parcel.tools', run=mock_local(), rsync=rsync, put=mock_put)
         d = Deployment('testapp', base=basepath, arch=centos)
         d.root_path = os.path.join(basepath, '.parcel')
         d.prepare_app()
-        
+
         # test build, will not actually call fpm
         d.build_package()
-        dest_file = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.1-1.noarch.rpm")
+        dest_file = os.path.join(os.path.dirname(__file__), "data", "testapp_0.1.1-1.noarch.rpm")
         print dest_file
         self.assertTrue(os.path.exists(dest_file))
         os.unlink(dest_file)
-

tests/test_distro.py

 
     @patch.multiple('parcel.distro', with_settings=with_settings, run=run, put=put, cd=distro_cd)
     @patch('parcel.distro.cache.get', distro_cache)
-    @patch('parcel.distro.Debian.mkdir', distro_mkdir)    
+    @patch('parcel.distro.Debian.mkdir', distro_mkdir)
     def test_setup(self):
         distro_cache.return_value = '/a/test/path/file.gz'
         distro_mkdir.side_effect = ['.parcel-build-temp', '.parcel-build-temp/src', '.parcel-build-temp/build']
 
     @patch.multiple('parcel.distro', with_settings=with_settings, run=run, put=put, cd=distro_cd)
     @patch('parcel.distro.cache.get', distro_cache)
-    @patch('parcel.distro.Debian.mkdir', distro_mkdir)    
+    @patch('parcel.distro.Debian.mkdir', distro_mkdir)
     def test_setup_ubuntu(self):
         distro_cache.return_value = '/a/test/path/file.gz'
         distro_mkdir.side_effect = ['.parcel-build-temp', '.parcel-build-temp/src', '.parcel-build-temp/build']
         ubuntu.setup()
 
-        self.assertTrue(run.call_args_list[0][0][0] == 'apt-get install rubygems -y')
+        self.assertTrue(run.call_args_list[0][0][0] == 'apt-get install -qq rubygems python-virtualenv python-dev')
         self.assertTrue(run.call_args_list[1][0][0] == 'gem install fpm')
 
 

tests/test_tools.py

 
         # call with single fabric env.key_filename
         from fabric.state import env
-        env.key_filename = "/some/path/to/a/keyfile.pub"
-        rsync(test_file, 'test.tar.gz')
+        from fabric.api import settings
+        with settings(key_filename="/some/path/to/a/keyfile.pub"):
+            rsync(test_file, 'test.tar.gz')
         
-        # rsync command should specify ssh command
-        self.assertIn("rsync -av -e 'ssh -l {0.user} -i \"{0.key_filename}\"'".format(env), rsync_local.call_args[0][0])
+            # rsync command should specify ssh command
+            self.assertIn("rsync -av -e 'ssh -l {0.user} -i \"{0.key_filename}\"'".format(env), rsync_local.call_args[0][0])
 
         # call with multiple fabric env.key_filename
-        env.key_filename = ["keyfile1.pub","keyfile2.pub"]
-        rsync(test_file, 'test.tar.gz')
+        with settings(key_filename=["keyfile1.pub","keyfile2.pub"]):
+            rsync(test_file, 'test.tar.gz')
         
-        # rsync command should specify ssh command
-        self.assertIn("rsync -av -e 'ssh -l {0.user} -i \"{0.key_filename[0]}\" -i \"{0.key_filename[1]}\"'".format(env), rsync_local.call_args[0][0])
+            # rsync command should specify ssh command
+            self.assertIn("rsync -av -e 'ssh -l {0.user} -i \"{0.key_filename[0]}\" -i \"{0.key_filename[1]}\"'".format(env), rsync_local.call_args[0][0])
 
+        # call with nonstandard ssh port
+        with settings(port=2222):
+            rsync(test_file, 'test.tar.gz')
+
+            # rsync command should specify ssh command
+            self.assertIn("rsync -av -e 'ssh -p 2222'".format(env), rsync_local.call_args[0][0])
+
+        # combine keyfile and port
+        with settings(key_filename="/some/path/to/a/keyfile.pub", port=3232):
+            rsync(test_file, 'test.tar.gz')
         
+            # rsync command should specify ssh command
+            self.assertIn("rsync -av -e 'ssh -p 3232 -l {0.user} -i \"{0.key_filename}\"'".format(env), rsync_local.call_args[0][0])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.