Ejemplo n.º 1
0
 def setUp(self):
     self._command = UpdateWait(clock=mock.create_autospec(spec=time))
     self._mock_options = mock_verb_options(self._command)
     self._mock_options.jobspec = self.TEST_JOBKEY
     self._mock_options.id = 'update_id'
     self._fake_context = FakeAuroraCommandContext()
     self._fake_context.set_options(self._mock_options)
     self._mock_api = self._fake_context.get_api('UNUSED')
     self._fetch_call = call(update_key=JobUpdateKey(
         job=self.TEST_JOBKEY.to_thrift(), id=self._mock_options.id))
Ejemplo n.º 2
0
 def setUp(self):
     self._command = UpdateWait(clock=mock.create_autospec(spec=time))
     self._mock_options = mock_verb_options(self._command)
     self._mock_options.jobspec = self.TEST_JOBKEY
     self._mock_options.id = "update_id"
     self._fake_context = FakeAuroraCommandContext()
     self._fake_context.set_options(self._mock_options)
     self._mock_api = self._fake_context.get_api("UNUSED")
     self._fetch_call = call(update_key=JobUpdateKey(job=self.TEST_JOBKEY.to_thrift(), id=self._mock_options.id))
Ejemplo n.º 3
0
class TestUpdateWait(AuroraClientCommandTest):
  def setUp(self):
    self._command = UpdateWait(clock=mock.create_autospec(spec=time))
    self._mock_options = mock_verb_options(self._command)
    self._mock_options.jobspec = self.TEST_JOBKEY
    self._mock_options.id = 'update_id'
    self._fake_context = FakeAuroraCommandContext()
    self._fake_context.set_options(self._mock_options)
    self._mock_api = self._fake_context.get_api('UNUSED')
    self._fetch_call = call(
        update_key=JobUpdateKey(job=self.TEST_JOBKEY.to_thrift(), id=self._mock_options.id))

  def test_wait(self):
    updating_response = get_status_query_response(status=JobUpdateStatus.ROLLING_FORWARD)
    updated_response = get_status_query_response(status=JobUpdateStatus.ROLLED_FORWARD)

    self._mock_api.query_job_updates.side_effect = [updating_response, updated_response]

    assert self._command.execute(self._fake_context) == EXIT_OK
    assert self._fake_context.get_out() == ['Current state ROLLING_FORWARD',
                                            'Current state ROLLED_FORWARD']

    assert self._mock_api.query_job_updates.mock_calls == [self._fetch_call, self._fetch_call]

  def test_wait_non_ok_response(self):
    self._mock_api.query_job_updates.return_value = Response(
        responseCode=ResponseCode.INVALID_REQUEST)

    with pytest.raises(Context.CommandError) as e:
      self._command.execute(self._fake_context)
    assert e.value.code == EXIT_API_ERROR

    assert self._fake_context.get_out() == []
    assert self._mock_api.query_job_updates.mock_calls == [self._fetch_call]

  def test_update_wait_not_found(self):
    self._mock_api.query_job_updates.return_value = Response(
        responseCode=ResponseCode.OK,
        result=Result(getJobUpdateSummariesResult=GetJobUpdateSummariesResult(updateSummaries=[])))

    with pytest.raises(Context.CommandError) as e:
      self._command.execute(self._fake_context)
    assert e.value.code == EXIT_INVALID_PARAMETER

    assert self._fake_context.get_out() == []
    assert self._mock_api.query_job_updates.mock_calls == [self._fetch_call]

  def test_wait_scheduler_returns_multiple_summaries(self):
    self._mock_api.query_job_updates.return_value = get_status_query_response(count=2)

    with pytest.raises(Context.CommandError) as e:
      self._command.execute(self._fake_context)
    assert e.value.code == EXIT_API_ERROR

    assert self._fake_context.get_out() == []
    assert self._mock_api.query_job_updates.mock_calls == [self._fetch_call]
Ejemplo n.º 4
0
class TestUpdateWait(AuroraClientCommandTest):
    def setUp(self):
        self._command = UpdateWait(clock=mock.create_autospec(spec=time))
        self._mock_options = mock_verb_options(self._command)
        self._mock_options.jobspec = self.TEST_JOBKEY
        self._mock_options.id = 'update_id'
        self._fake_context = FakeAuroraCommandContext()
        self._fake_context.set_options(self._mock_options)
        self._mock_api = self._fake_context.get_api('UNUSED')
        self._fetch_call = call(update_key=JobUpdateKey(
            job=self.TEST_JOBKEY.to_thrift(), id=self._mock_options.id))

    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)

        self._mock_api.query_job_updates.side_effect = [
            updating_response, updated_response
        ]

        assert self._command.execute(self._fake_context) == EXIT_OK
        assert self._fake_context.get_out() == [
            'Current state ROLLING_FORWARD', 'Current state ROLLED_FORWARD'
        ]

        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)

        with pytest.raises(Context.CommandError) as e:
            self._command.execute(self._fake_context)
        assert e.value.code == EXIT_API_ERROR

        assert self._fake_context.get_out() == []
        assert self._mock_api.query_job_updates.mock_calls == [
            self._fetch_call
        ]

    def test_update_wait_not_found(self):
        self._mock_api.query_job_updates.return_value = Response(
            responseCode=ResponseCode.OK,
            result=Result(
                getJobUpdateSummariesResult=GetJobUpdateSummariesResult(
                    updateSummaries=[])))

        with pytest.raises(Context.CommandError) as e:
            self._command.execute(self._fake_context)
        assert e.value.code == EXIT_INVALID_PARAMETER

        assert self._fake_context.get_out() == []
        assert self._mock_api.query_job_updates.mock_calls == [
            self._fetch_call
        ]

    def test_wait_scheduler_returns_multiple_summaries(self):
        self._mock_api.query_job_updates.return_value = get_status_query_response(
            count=2)

        with pytest.raises(Context.CommandError) as e:
            self._command.execute(self._fake_context)
        assert e.value.code == EXIT_API_ERROR

        assert self._fake_context.get_out() == []
        assert self._mock_api.query_job_updates.mock_calls == [
            self._fetch_call
        ]