You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by mc...@apache.org on 2014/05/12 19:13:55 UTC
git commit: Bugfix: make "restart" command generate a correct error
message in some cases.
Repository: incubator-aurora
Updated Branches:
refs/heads/master dfebd7ad3 -> 41eb1e9e2
Bugfix: make "restart" command generate a correct error message in some cases.
Bugs closed: aurora-400
Reviewed at https://reviews.apache.org/r/21223/
Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/41eb1e9e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/41eb1e9e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/41eb1e9e
Branch: refs/heads/master
Commit: 41eb1e9e272060b63faea2a95e52484a0b51e9cc
Parents: dfebd7a
Author: Mark Chu-Carroll <mc...@twopensource.com>
Authored: Mon May 12 13:08:49 2014 -0400
Committer: Mark Chu-Carroll <mc...@twitter.com>
Committed: Mon May 12 13:08:49 2014 -0400
----------------------------------------------------------------------
.../apache/aurora/client/api/restarter.py | 14 ++++----
.../apache/aurora/client/api/test_restarter.py | 2 ++
.../apache/aurora/client/cli/test_restart.py | 35 ++++++++++++++++++--
.../aurora/client/commands/test_restart.py | 2 --
4 files changed, 42 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/41eb1e9e/src/main/python/apache/aurora/client/api/restarter.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/api/restarter.py b/src/main/python/apache/aurora/client/api/restarter.py
index ddaec5c..d7945bf 100644
--- a/src/main/python/apache/aurora/client/api/restarter.py
+++ b/src/main/python/apache/aurora/client/api/restarter.py
@@ -44,18 +44,18 @@ class Restarter(object):
health_check_interval_seconds)
def restart(self, instances):
+ # Verify that this operates on a valid job.
+ query = self._job_key.to_thrift_query()
+ query.statuses = ACTIVE_STATES
+ status = self._scheduler.getTasksStatus(query)
+ if status.responseCode != ResponseCode.OK:
+ return status
+
failure_threshold = FailureThreshold(
self._update_config.max_per_instance_failures,
self._update_config.max_total_failures)
if not instances:
- query = self._job_key.to_thrift_query()
- query.statuses = ACTIVE_STATES
- status = self._scheduler.getTasksStatus(query)
-
- if status.responseCode != ResponseCode.OK:
- return status
-
tasks = status.result.scheduleStatusResult.tasks
instances = sorted(task.assignedTask.instanceId for task in tasks)
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/41eb1e9e/src/test/python/apache/aurora/client/api/test_restarter.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_restarter.py b/src/test/python/apache/aurora/client/api/test_restarter.py
index d5dfa39..b0e092b 100644
--- a/src/test/python/apache/aurora/client/api/test_restarter.py
+++ b/src/test/python/apache/aurora/client/api/test_restarter.py
@@ -66,6 +66,7 @@ class TestRestarter(MoxTestBase):
self.mock_instance_watcher.watch(instances).AndReturn([])
def test_restart_one_iteration(self):
+ self.mock_status_active_tasks([0, 1, 3, 4, 5])
self.mock_restart_instances([0, 1])
self.mox.ReplayAll()
@@ -78,6 +79,7 @@ class TestRestarter(MoxTestBase):
self.mock_restart_instances([5])
def test_rolling_restart(self):
+ self.mock_status_active_tasks([0, 1, 3, 4, 5])
self.mock_three_iterations()
self.mox.ReplayAll()
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/41eb1e9e/src/test/python/apache/aurora/client/cli/test_restart.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_restart.py b/src/test/python/apache/aurora/client/cli/test_restart.py
index 03fdcd2..7749580 100644
--- a/src/test/python/apache/aurora/client/cli/test_restart.py
+++ b/src/test/python/apache/aurora/client/cli/test_restart.py
@@ -115,8 +115,6 @@ class TestRestartCommand(AuroraClientCommandTest):
assert mock_scheduler_proxy.restartShards.call_count == 0
def test_restart_failed_status(self):
- # Test the client-side updater logic in its simplest case: everything succeeds, and no rolling
- # updates.
(mock_api, mock_scheduler_proxy) = self.create_mock_api()
mock_health_check = self.setup_health_checks(mock_api)
self.setup_mock_scheduler_for_simple_restart(mock_api)
@@ -137,6 +135,39 @@ class TestRestartCommand(AuroraClientCommandTest):
assert mock_scheduler_proxy.restartShards.call_count == 0
assert result == EXIT_API_ERROR
+ def test_restart_no_such_job_with_instances(self):
+ (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+ mock_health_check = self.setup_health_checks(mock_api)
+ self.setup_mock_scheduler_for_simple_restart(mock_api)
+ # Make getTasksStatus return an error, which is what happens when a job is not found.
+ mock_scheduler_proxy.getTasksStatus.return_value = self.create_error_response()
+ mock_logger = Mock()
+ with contextlib.nested(
+ patch('apache.aurora.client.cli.print_aurora_log'),
+ patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+ patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
+ patch('apache.aurora.client.api.instance_watcher.StatusHealthCheck',
+ return_value=mock_health_check),
+ patch('time.time', side_effect=functools.partial(self.fake_time, self)),
+ patch('time.sleep', return_value=None)) as (mock_log, _, _, _, _, _):
+ with temporary_file() as fp:
+ fp.write(self.get_valid_config())
+ fp.flush()
+ cmd = AuroraCommandLine()
+ result = cmd.execute(['job', 'restart', '--batch-size=5', 'west/bozo/test/hello/1-3', fp.name])
+ # We need to check tat getTasksStatus was called, but that restartShards wasn't.
+ # In older versions of the client, if shards were specified, but the job didn't
+ # exist, the error wouldn't be detected unti0 restartShards was called, which generated
+ # the wrong error message.
+ assert mock_scheduler_proxy.getTasksStatus.call_count == 1
+ assert mock_scheduler_proxy.restartShards.call_count == 0
+ assert result == EXIT_API_ERROR
+ # Error message should be written to log, and it should be what was returned
+ # by the getTasksStatus call.
+ mock_log.assert_called_with(20, 'Error executing command: %s', 'Damn')
+
+
+
def test_restart_failed_restart(self):
# Test the client-side updater logic in its simplest case: everything succeeds, and no rolling
# updates.
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/41eb1e9e/src/test/python/apache/aurora/client/commands/test_restart.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_restart.py b/src/test/python/apache/aurora/client/commands/test_restart.py
index 9af6334..29da5ac 100644
--- a/src/test/python/apache/aurora/client/commands/test_restart.py
+++ b/src/test/python/apache/aurora/client/commands/test_restart.py
@@ -134,8 +134,6 @@ class TestRestartCommand(AuroraClientCommandTest):
role=self.TEST_ROLE, name=self.TEST_JOB), [15, 16, 17, 18, 19], None)
def test_restart_failed_status(self):
- # Test the client-side updater logic in its simplest case: everything succeeds, and no rolling
- # updates.
mock_options = self.setup_mock_options()
(mock_api, mock_scheduler_proxy) = self.create_mock_api()
mock_health_check = self.setup_health_checks(mock_api)