Repository: aurora Updated Branches: refs/heads/master 5c4c42ccf -> d9dac92d3
Client: when waiting for a job update, use helpful exit codes. Bugs closed: AURORA-1399 Reviewed at https://reviews.apache.org/r/36478/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/d9dac92d Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/d9dac92d Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/d9dac92d Branch: refs/heads/master Commit: d9dac92d38154f132722f0bf2869c6ac0ab45522 Parents: 5c4c42c Author: Bill Farner <[email protected]> Authored: Tue Jul 14 13:58:17 2015 -0700 Committer: Bill Farner <[email protected]> Committed: Tue Jul 14 13:58:17 2015 -0700 ---------------------------------------------------------------------- .../python/apache/aurora/client/cli/update.py | 13 +++-- .../apache/aurora/client/cli/test_supdate.py | 50 ++++++++++++++++++-- 2 files changed, 56 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/d9dac92d/src/main/python/apache/aurora/client/cli/update.py ---------------------------------------------------------------------- diff --git a/src/main/python/apache/aurora/client/cli/update.py b/src/main/python/apache/aurora/client/cli/update.py index 2dcc8f3..eb7e9b0 100644 --- a/src/main/python/apache/aurora/client/cli/update.py +++ b/src/main/python/apache/aurora/client/cli/update.py @@ -28,6 +28,7 @@ from apache.aurora.client.cli import ( EXIT_INVALID_CONFIGURATION, EXIT_INVALID_PARAMETER, EXIT_OK, + EXIT_UNKNOWN_ERROR, Noun, Verb ) @@ -185,7 +186,7 @@ class StartUpdate(Verb): context.print_out(self.UPDATE_MSG_TEMPLATE % url) if context.options.wait: - wait_for_update(context, self._clock, api, update_key) + return wait_for_update(context, self._clock, api, update_key) else: context.print_out(combine_messages(resp)) @@ -205,7 +206,12 @@ def wait_for_update(context, clock, api, update_key): cur_state = new_state context.print_out('Current state %s' % JobUpdateStatus._VALUES_TO_NAMES[cur_state]) if cur_state not in ACTIVE_JOB_UPDATE_STATES: - break + if cur_state == JobUpdateStatus.ROLLED_FORWARD: + return EXIT_OK + elif cur_state == JobUpdateStatus.ROLLED_BACK: + return EXIT_COMMAND_FAILURE + else: + return EXIT_UNKNOWN_ERROR clock.sleep(5) elif len(summaries) == 0: raise context.CommandError(EXIT_INVALID_PARAMETER, 'Job update not found.') @@ -239,12 +245,11 @@ class UpdateWait(Verb): return 'Block until an update has entered a terminal state.' def execute(self, context): - wait_for_update( + return wait_for_update( context, self._clock, context.get_api(context.options.jobspec.cluster), JobUpdateKey(job=context.options.jobspec.to_thrift(), id=context.options.id)) - return EXIT_OK class PauseUpdate(Verb): http://git-wip-us.apache.org/repos/asf/aurora/blob/d9dac92d/src/test/python/apache/aurora/client/cli/test_supdate.py ---------------------------------------------------------------------- diff --git a/src/test/python/apache/aurora/client/cli/test_supdate.py b/src/test/python/apache/aurora/client/cli/test_supdate.py index 2d7d496..21bea70 100644 --- a/src/test/python/apache/aurora/client/cli/test_supdate.py +++ b/src/test/python/apache/aurora/client/cli/test_supdate.py @@ -19,7 +19,14 @@ import pytest from mock import ANY, Mock, call, create_autospec from pystachio import Empty -from apache.aurora.client.cli import EXIT_API_ERROR, EXIT_INVALID_PARAMETER, EXIT_OK, Context +from apache.aurora.client.cli import ( + EXIT_API_ERROR, + EXIT_COMMAND_FAILURE, + EXIT_INVALID_PARAMETER, + EXIT_OK, + EXIT_UNKNOWN_ERROR, + Context +) from apache.aurora.client.cli.options import TaskInstanceKey from apache.aurora.client.cli.update import ( AbortUpdate, @@ -155,7 +162,7 @@ class TestStartUpdate(AuroraClientCommandTest): ] assert self._fake_context.get_err() == [] - def test_start_update_and_wait(self): + def test_start_update_and_wait_success(self): mock_config = self.create_mock_config() self._fake_context.get_job_config = Mock(return_value=mock_config) self._mock_options.wait = True @@ -181,6 +188,36 @@ class TestStartUpdate(AuroraClientCommandTest): ] assert self._fake_context.get_err() == [] + def test_start_update_and_wait_rollback(self): + mock_config = self.create_mock_config() + self._fake_context.get_job_config = Mock(return_value=mock_config) + self._mock_options.wait = True + + resp = self.create_simple_success_response() + resp.result = Result(startJobUpdateResult=StartJobUpdateResult( + key=JobUpdateKey(job=JobKey(role="role", environment="env", name="name"), id="id"))) + self._mock_api.start_job_update.return_value = resp + self._mock_api.query_job_updates.side_effect = [ + get_status_query_response(status=JobUpdateStatus.ROLLED_BACK) + ] + + assert self._command.execute(self._fake_context) == EXIT_COMMAND_FAILURE + + def test_start_update_and_wait_error(self): + mock_config = self.create_mock_config() + self._fake_context.get_job_config = Mock(return_value=mock_config) + self._mock_options.wait = True + + resp = self.create_simple_success_response() + resp.result = Result(startJobUpdateResult=StartJobUpdateResult( + key=JobUpdateKey(job=JobKey(role="role", environment="env", name="name"), id="id"))) + self._mock_api.start_job_update.return_value = resp + self._mock_api.query_job_updates.side_effect = [ + get_status_query_response(status=JobUpdateStatus.ERROR) + ] + + assert self._command.execute(self._fake_context) == EXIT_UNKNOWN_ERROR + def test_start_update_command_line_succeeds_noop_update(self): resp = self.create_simple_success_response() resp.details = [ResponseDetail(message="Noop update.")] @@ -586,7 +623,7 @@ class TestUpdateWait(AuroraClientCommandTest): self._fetch_call = call( update_key=JobUpdateKey(job=self.TEST_JOBKEY.to_thrift(), id=self._mock_options.id)) - def test_wait(self): + def test_wait_success(self): updating_response = get_status_query_response(status=JobUpdateStatus.ROLLING_FORWARD) updated_response = get_status_query_response(status=JobUpdateStatus.ROLLED_FORWARD) @@ -598,6 +635,13 @@ class TestUpdateWait(AuroraClientCommandTest): assert self._mock_api.query_job_updates.mock_calls == [self._fetch_call, self._fetch_call] + def test_wait_rolled_back(self): + response = get_status_query_response(status=JobUpdateStatus.ROLLED_BACK) + + self._mock_api.query_job_updates.side_effect = [response] + + assert self._command.execute(self._fake_context) == EXIT_COMMAND_FAILURE + def test_wait_non_ok_response(self): self._mock_api.query_job_updates.return_value = Response( responseCode=ResponseCode.INVALID_REQUEST)
