You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/09/11 00:19:52 UTC

git commit: Allow user to pass "args" argument to the ScriptDeployment class. This argument tells which command line arguments get passed to the ScriptDeployment script.

Updated Branches:
  refs/heads/trunk 48f1369a8 -> 837f768f9


Allow user to pass "args" argument to the ScriptDeployment class. This
argument tells which command line arguments get passed to the
ScriptDeployment script.

Part of LIBCLOUD-394.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/837f768f
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/837f768f
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/837f768f

Branch: refs/heads/trunk
Commit: 837f768f932050d0546997019e91b0d856c3f26f
Parents: 48f1369
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Sep 11 00:12:28 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Sep 11 00:12:28 2013 +0200

----------------------------------------------------------------------
 CHANGES                                  |  5 +++++
 libcloud/compute/deployment.py           | 17 +++++++++++++++--
 libcloud/test/compute/test_deployment.py | 23 +++++++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/837f768f/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 78c7a6a..042af48 100644
--- a/CHANGES
+++ b/CHANGES
@@ -75,6 +75,11 @@ Changes with Apache Libcloud in development
       extension arguments for handling security groups. (LIBCLOUD-388)
       [sebastien goasguen]
 
+    - Allow user to pass "args" argument to the ScriptDeployment class. This
+      argument tells which arguments get passed to the ScriptDeployment
+      script. (LIBCLOUD-394)
+      [Tomaz Muraus]
+
   *) Storage
 
     - Allow users to filter objects starting with a prefix by passing ex_prefix

http://git-wip-us.apache.org/repos/asf/libcloud/blob/837f768f/libcloud/compute/deployment.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/deployment.py b/libcloud/compute/deployment.py
index d0925b5..3f68d40 100644
--- a/libcloud/compute/deployment.py
+++ b/libcloud/compute/deployment.py
@@ -117,11 +117,15 @@ class ScriptDeployment(Deployment):
     Runs an arbitrary Shell Script task.
     """
 
-    def __init__(self, script, name=None, delete=False):
+    def __init__(self, script, args=None, name=None, delete=False):
         """
         @type script: C{str}
         @keyword script: Contents of the script to run
 
+        @type args: C{list}
+        @keyword args: Optional arguments which get passed to the deployment
+                       script file.
+
         @type name: C{str}
         @keyword name: Name of the script to upload it as, if not specified,
                        a random name will be choosen.
@@ -133,6 +137,7 @@ class ScriptDeployment(Deployment):
                                         argument_value=script)
 
         self.script = script
+        self.args = args or []
         self.stdout = None
         self.stderr = None
         self.exit_status = None
@@ -162,7 +167,15 @@ class ScriptDeployment(Deployment):
         else:
             name = self.name
 
-        self.stdout, self.stderr, self.exit_status = client.run(name)
+        cmd = name
+
+        if self.args:
+            # Append arguments to the command
+            cmd = '%s %s' % (name, ' '.join(self.args))
+        else:
+            cmd = name
+
+        self.stdout, self.stderr, self.exit_status = client.run(cmd)
 
         if self.delete:
             client.delete(self.name)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/837f768f/libcloud/test/compute/test_deployment.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_deployment.py b/libcloud/test/compute/test_deployment.py
index ce729bb..bfe0c36 100644
--- a/libcloud/test/compute/test_deployment.py
+++ b/libcloud/test/compute/test_deployment.py
@@ -145,6 +145,29 @@ class DeploymentTests(unittest.TestCase):
 
         client.run.assert_called_once_with('/root/relative.sh')
 
+    def test_script_deployment_with_arguments(self):
+        client = Mock()
+        client.put.return_value = '/home/ubuntu/relative.sh'
+        client.run.return_value = ('', '', 0)
+
+        args = ['arg1', 'arg2', '--option1=test']
+        sd = ScriptDeployment(script='echo "foo"', args=args,
+                              name='/root/relative.sh')
+        sd.run(self.node, client)
+
+        expected = '/root/relative.sh arg1 arg2 --option1=test'
+        client.run.assert_called_once_with(expected)
+
+        client.reset_mock()
+
+        args = []
+        sd = ScriptDeployment(script='echo "foo"', args=args,
+                              name='/root/relative.sh')
+        sd.run(self.node, client)
+
+        expected = '/root/relative.sh'
+        client.run.assert_called_once_with(expected)
+
     def test_script_deployment_and_sshkey_deployment_argument_types(self):
         class FileObject(object):
             def __init__(self, name):