aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject incubator-aurora git commit: Suppressing redundant client command error messaging.
Date Thu, 11 Dec 2014 20:49:06 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 4c280fff9 -> 07bc3ab25


Suppressing redundant client command error messaging.

Bugs closed: AURORA-965

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


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

Branch: refs/heads/master
Commit: 07bc3ab253923d33ad6ae2946295db4564bf0933
Parents: 4c280ff
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Thu Dec 11 12:48:50 2014 -0800
Committer: -l <maxim@apache.org>
Committed: Thu Dec 11 12:48:50 2014 -0800

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/__init__.py |  6 ++
 .../python/apache/aurora/client/cli/context.py  |  2 +-
 .../apache/aurora/client/cli/test_update.py     | 67 +++++++++++++-------
 3 files changed, 51 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/07bc3ab2/src/main/python/apache/aurora/client/cli/__init__.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/__init__.py b/src/main/python/apache/aurora/client/cli/__init__.py
index c2eb89c..0e6e40a 100644
--- a/src/main/python/apache/aurora/client/cli/__init__.py
+++ b/src/main/python/apache/aurora/client/cli/__init__.py
@@ -82,6 +82,10 @@ class Context(object):
       self.msg = msg
       self.code = code
 
+  class CommandErrorLogged(CommandError):
+    def __init__(self, code, msg):
+      super(Context.CommandErrorLogged, self).__init__(code, msg)  # noqa:T800
+
   def __init__(self):
     self._options = None
 
@@ -374,6 +378,8 @@ class CommandLine(AbstractClass):
         logging.info("Command terminated with error code %s", result)
       self._run_post_plugins(context, result)
       return result
+    except Context.CommandErrorLogged as c:
+      return c.code
     except Context.CommandError as c:
       self.print_err("Error executing command: %s" % c.msg)
       return c.code

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/07bc3ab2/src/main/python/apache/aurora/client/cli/context.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/context.py b/src/main/python/apache/aurora/client/cli/context.py
index ad27eb5..b1ffc05 100644
--- a/src/main/python/apache/aurora/client/cli/context.py
+++ b/src/main/python/apache/aurora/client/cli/context.py
@@ -152,7 +152,7 @@ class AuroraCommandContext(Context):
       self.print_err(err_msg)
     self.log_response(resp)
     if resp.responseCode != ResponseCode.OK:
-      raise self.CommandError(err_code, err_msg)
+      raise self.CommandErrorLogged(err_code, err_msg)
 
   @classmethod
   def parse_partial_jobkey(cls, key):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/07bc3ab2/src/test/python/apache/aurora/client/cli/test_update.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_update.py b/src/test/python/apache/aurora/client/cli/test_update.py
index 1f061a3..044e609 100644
--- a/src/test/python/apache/aurora/client/cli/test_update.py
+++ b/src/test/python/apache/aurora/client/cli/test_update.py
@@ -13,7 +13,6 @@
 #
 import contextlib
 import functools
-import unittest
 
 import pytest
 from mock import create_autospec, Mock, patch
@@ -27,7 +26,6 @@ from apache.aurora.client.cli import Context, EXIT_INVALID_CONFIGURATION,
EXIT_O
 from apache.aurora.client.cli.client import AuroraCommandLine
 from apache.aurora.client.cli.jobs import UpdateCommand
 from apache.aurora.client.cli.options import TaskInstanceKey
-from apache.aurora.common.aurora_job_key import AuroraJobKey
 from apache.aurora.config import AuroraConfig
 
 from .util import AuroraClientCommandTest, FakeAuroraCommandContext, IOMock, mock_verb_options
@@ -50,33 +48,56 @@ from gen.apache.aurora.api.ttypes import (
 )
 
 
-class TestJobUpdateCommand(unittest.TestCase):
+class TestJobUpdateCommand(AuroraClientCommandTest):
 
-  def test_update_with_lock(self):
-    command = UpdateCommand()
-
-    jobkey = AuroraJobKey("cluster", "role", "env", "job")
-    mock_options = mock_verb_options(command)
-    mock_options.instance_spec = TaskInstanceKey(jobkey, [])
-    mock_options.force = True
-
-    fake_context = FakeAuroraCommandContext()
-    fake_context.set_options(mock_options)
+  def setUp(self):
+    self._command = UpdateCommand()
+    self._mock_options = mock_verb_options(self._command)
+    self._mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, [])
+    self._mock_options.force = True
+    self._fake_context = FakeAuroraCommandContext()
+    self._fake_context.set_options(self._mock_options)
+    self._mock_api = self._fake_context.get_api("test")
 
+  @classmethod
+  def create_mock_config(cls, is_cron=False):
     mock_config = create_autospec(spec=AuroraConfig, spec_set=True, instance=True)
-    fake_context.get_job_config = Mock(return_value=mock_config)
+    mock_raw_config = Mock()
+    mock_raw_config.has_cron_schedule.return_value = is_cron
+    mock_config.raw = Mock(return_value=mock_raw_config)
+    return mock_config
 
-    mock_api = fake_context.get_api("test")
-    mock_api.update_job.return_value = AuroraClientCommandTest.create_blank_response(
-      ResponseCode.LOCK_ERROR, "Error.")
+  def test_update_with_lock(self):
+    mock_config = self.create_mock_config()
+    self._fake_context.get_job_config = Mock(return_value=mock_config)
+    self._mock_api.update_job.return_value = AuroraClientCommandTest.create_blank_response(
+        ResponseCode.LOCK_ERROR, "Error.")
 
     with pytest.raises(Context.CommandError):
-      command.execute(fake_context)
-
-    mock_api.update_job.assert_called_once_with(mock_config,
-      mock_options.healthcheck_interval_seconds,
-      mock_options.instance_spec.instance)
-    assert fake_context.get_err()[0] == fake_context.LOCK_ERROR_MSG
+      self._command.execute(self._fake_context)
+
+    self._mock_api.update_job.assert_called_once_with(
+      mock_config,
+      self._mock_options.healthcheck_interval_seconds,
+      self._mock_options.instance_spec.instance)
+    assert self._fake_context.get_err()[0] == self._fake_context.LOCK_ERROR_MSG
+
+  def test_update_print_error_once(self):
+    mock_config = self.create_mock_config()
+    self._fake_context.get_job_config = Mock(return_value=mock_config)
+    error = "Error printed once."
+    self._mock_api.update_job.return_value = AuroraClientCommandTest.create_blank_response(
+        ResponseCode.INVALID_REQUEST,
+        error)
+
+    with pytest.raises(Context.CommandErrorLogged):
+      self._command.execute(self._fake_context)
+
+    self._mock_api.update_job.assert_called_once_with(
+      mock_config,
+      self._mock_options.healthcheck_interval_seconds,
+      self._mock_options.instance_spec.instance)
+    assert self._fake_context.get_err() == ["Update failed due to error:", "\t%s" % error]
 
 
 class TestUpdateCommand(AuroraClientCommandTest):


Mime
View raw message