aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mchucarr...@apache.org
Subject git commit: Fix error in client "task ssh" command when the job isn't found.
Date Fri, 12 Sep 2014 17:35:35 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master dc69a11ed -> 8b650e71c


Fix error in client "task ssh" command when the job isn't found.

Bugs closed: aurora-706

Reviewed at https://reviews.apache.org/r/25582/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/8b650e71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/8b650e71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/8b650e71

Branch: refs/heads/master
Commit: 8b650e71cd0c23a54021345304efa0faa11f4e56
Parents: dc69a11
Author: Mark Chu-Carroll <mchucarroll@twopensource.com>
Authored: Fri Sep 12 13:21:31 2014 -0400
Committer: Mark Chu-Carroll <mchucarroll@twitter.com>
Committed: Fri Sep 12 13:21:31 2014 -0400

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/task.py     |  4 +++
 .../python/apache/aurora/client/commands/ssh.py |  3 +++
 .../apache/aurora/client/cli/test_task_run.py   | 24 +++++++++++++++++
 .../apache/aurora/client/commands/test_ssh.py   | 27 +++++++++++++++++++-
 4 files changed, 57 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8b650e71/src/main/python/apache/aurora/client/cli/task.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/task.py b/src/main/python/apache/aurora/client/cli/task.py
index 91175fa..5b5710a 100644
--- a/src/main/python/apache/aurora/client/cli/task.py
+++ b/src/main/python/apache/aurora/client/cli/task.py
@@ -114,6 +114,10 @@ class SshCommand(Verb):
     resp = api.query(api.build_query(role, name, set([int(instance)]), env=env))
     context.check_and_log_response(resp,
         err_msg=('Unable to get information about instance: %s' % resp.messageDEPRECATED))
+    if (resp.result.scheduleStatusResult.tasks is None or
+        len(resp.result.scheduleStatusResult.tasks) == 0):
+      raise context.CommandError(EXIT_INVALID_PARAMETER,
+          "Job %s not found" % context.options.task_instance.jobkey)
     first_task = resp.result.scheduleStatusResult.tasks[0]
     remote_cmd = context.options.command or 'bash'
     command = DistributedCommandRunner.substitute(remote_cmd, first_task,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8b650e71/src/main/python/apache/aurora/client/commands/ssh.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/commands/ssh.py b/src/main/python/apache/aurora/client/commands/ssh.py
index 37a9008..afd5ab7 100644
--- a/src/main/python/apache/aurora/client/commands/ssh.py
+++ b/src/main/python/apache/aurora/client/commands/ssh.py
@@ -71,6 +71,9 @@ def ssh(args, options):
   resp = api.query(api.build_query(role, name, set([int(shard)]), env=env))
   check_and_log_response(resp)
 
+  if (resp.result.scheduleStatusResult.tasks is None or
+      len(resp.result.scheduleStatusResult.tasks) == 0):
+    die("Job %s not found" % job_path)
   first_task = resp.result.scheduleStatusResult.tasks[0]
   remote_cmd = 'bash' if not args else ' '.join(args)
   command = DistributedCommandRunner.substitute(remote_cmd, first_task,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8b650e71/src/test/python/apache/aurora/client/cli/test_task_run.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_task_run.py b/src/test/python/apache/aurora/client/cli/test_task_run.py
index 8d9ef05..1ce9a63 100644
--- a/src/test/python/apache/aurora/client/cli/test_task_run.py
+++ b/src/test/python/apache/aurora/client/cli/test_task_run.py
@@ -16,6 +16,7 @@ import contextlib
 
 from mock import Mock, patch
 
+from apache.aurora.client.cli import EXIT_INVALID_PARAMETER
 from apache.aurora.client.cli.client import AuroraCommandLine
 from apache.aurora.client.cli.util import AuroraClientCommandTest
 
@@ -184,6 +185,13 @@ class TestSshCommand(AuroraClientCommandTest):
     return resp
 
   @classmethod
+  def create_nojob_status_response(cls):
+    resp = cls.create_simple_success_response()
+    resp.result.scheduleStatusResult = ScheduleStatusResult()
+    resp.result.scheduleStatusResult.tasks = []
+    return resp
+
+  @classmethod
   def create_failed_status_response(cls):
     return cls.create_blank_response(ResponseCode.INVALID_REQUEST, 'No tasks found for query')
 
@@ -215,3 +223,19 @@ class TestSshCommand(AuroraClientCommandTest):
       mock_subprocess.assert_called_with(['ssh', '-t', 'bozo@slavehost',
           'cd /slaveroot/slaves/*/frameworks/*/executors/thermos-1287391823/runs/'
           'slaverun/sandbox;ls'])
+
+  def test_ssh_job_not_found(self):
+    """Test the ssh command when the jobkey parameter specifies a job that isn't running."""
+    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+    mock_scheduler_proxy.getTasksStatus.return_value = self.create_nojob_status_response()
+    with contextlib.nested(
+        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
+        patch('subprocess.call', return_value=0)) as (
+            mock_scheduler_proxy_class,
+            mock_clusters,
+            mock_subprocess):
+      cmd = AuroraCommandLine()
+      result = cmd.execute(['task', 'ssh', 'west/bozo/test/hello/1', '--command=ls'])
+      assert result == EXIT_INVALID_PARAMETER
+      assert mock_subprocess.call_count == 0

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8b650e71/src/test/python/apache/aurora/client/commands/test_ssh.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_ssh.py b/src/test/python/apache/aurora/client/commands/test_ssh.py
index 4070b71..c5ca66e 100644
--- a/src/test/python/apache/aurora/client/commands/test_ssh.py
+++ b/src/test/python/apache/aurora/client/commands/test_ssh.py
@@ -79,11 +79,18 @@ class TestSshCommand(AuroraClientCommandTest):
   @classmethod
   def create_status_response(cls):
     resp = cls.create_simple_success_response()
-    resp.result.scheduleStatusResult = Mock(spec=ScheduleStatusResult)
+    resp.result.scheduleStatusResult = ScheduleStatusResult()
     resp.result.scheduleStatusResult.tasks = cls.create_mock_scheduled_tasks()
     return resp
 
   @classmethod
+  def create_nojob_status_response(cls):
+    resp = cls.create_simple_success_response()
+    resp.result.scheduleStatusResult = ScheduleStatusResult()
+    resp.result.scheduleStatusResult.tasks = []
+    return resp
+
+  @classmethod
   def create_failed_status_response(cls):
     return cls.create_blank_response(ResponseCode.INVALID_REQUEST, 'No tasks found for query')
 
@@ -115,3 +122,21 @@ class TestSshCommand(AuroraClientCommandTest):
       mock_subprocess.assert_called_with(['ssh', '-t', 'mchucarroll@slavehost',
           'cd /slaveroot/slaves/*/frameworks/*/executors/thermos-1287391823/runs/'
           'slaverun/sandbox;ls'])
+
+  def test_ssh_job_not_found(self):
+    """Test the ssh command when the query returns no tasks."""
+    mock_options = self.setup_mock_options()
+    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+    mock_scheduler_proxy.getTasksStatus.return_value = self.create_nojob_status_response()
+    with contextlib.nested(
+        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
+        patch('twitter.common.app.get_options', return_value=mock_options),
+        patch('subprocess.call', return_value=0)) as (
+            mock_scheduler_proxy_class,
+            mock_clusters,
+            options,
+            mock_subprocess):
+      self.assertRaises(SystemExit, ssh, ['west/mchucarroll/test/hello', '1', 'ls'], mock_options)
+
+      assert mock_subprocess.call_count == 0


Mime
View raw message