Beispiel #1
0
 def setUp(self):
     self._command = UpdateInfo()
     self._mock_options = mock_verb_options(self._command)
     self._mock_options.jobspec = self.TEST_JOBKEY
     self._mock_options.id = None
     self._fake_context = FakeAuroraCommandContext()
     self._fake_context.set_options(self._mock_options)
     self._mock_api = self._fake_context.get_api('UNUSED')
Beispiel #2
0
 def setUp(self):
   self._command = UpdateInfo()
   self._mock_options = mock_verb_options(self._command)
   self._mock_options.jobspec = self.TEST_JOBKEY
   self._mock_options.id = None
   self._fake_context = FakeAuroraCommandContext()
   self._fake_context.set_options(self._mock_options)
   self._mock_api = self._fake_context.get_api('UNUSED')
Beispiel #3
0
class TestUpdateStatus(AuroraClientCommandTest):
    def setUp(self):
        self._command = UpdateInfo()
        self._mock_options = mock_verb_options(self._command)
        self._mock_options.jobspec = self.TEST_JOBKEY
        self._mock_options.id = None
        self._fake_context = FakeAuroraCommandContext()
        self._fake_context.set_options(self._mock_options)
        self._mock_api = self._fake_context.get_api("UNUSED")

    def test_status_fails_no_updates(self):
        response = self.create_simple_success_response()
        response.result = Result(getJobUpdateSummariesResult=GetJobUpdateSummariesResult(updateSummaries=[]))

        self._mock_api.query_job_updates.return_value = response

        assert EXIT_INVALID_PARAMETER == self._command.execute(self._fake_context)
        assert self._fake_context.get_err() == ["There is no active update for this job."]
Beispiel #4
0
class TestUpdateStatus(AuroraClientCommandTest):
  def setUp(self):
    self._command = UpdateInfo()
    self._mock_options = mock_verb_options(self._command)
    self._mock_options.jobspec = self.TEST_JOBKEY
    self._mock_options.id = None
    self._fake_context = FakeAuroraCommandContext()
    self._fake_context.set_options(self._mock_options)
    self._mock_api = self._fake_context.get_api('UNUSED')

  def test_status_fails_no_updates(self):
    response = self.create_simple_success_response()
    response.result = Result(
        getJobUpdateSummariesResult=GetJobUpdateSummariesResult(updateSummaries=[]))

    self._mock_api.query_job_updates.return_value = response

    assert EXIT_INVALID_PARAMETER == self._command.execute(self._fake_context)
    assert self._fake_context.get_err() == ["There is no active update for this job."]
Beispiel #5
0
class TestUpdateInfo(AuroraClientCommandTest):
  def setUp(self):
    self._command = UpdateInfo()
    self._mock_options = mock_verb_options(self._command)
    self._mock_options.jobspec = self.TEST_JOBKEY
    self._mock_options.id = None
    self._fake_context = FakeAuroraCommandContext()
    self._fake_context.set_options(self._mock_options)
    self._mock_api = self._fake_context.get_api('UNUSED')

  @classmethod
  def get_update_details_response(cls):
    query_response = Response()
    query_response.responseCode = ResponseCode.OK
    query_response.result = Result()
    details = JobUpdateDetails(
        update=JobUpdate(
            summary=JobUpdateSummary(
                key=UPDATE_KEY,
                user="******",
                state=JobUpdateState(
                  status=JobUpdateStatus.ROLLING_FORWARD,
                  createdTimestampMs=1000,
                  lastModifiedTimestampMs=2000))),
        updateEvents=[
            JobUpdateEvent(
                status=JobUpdateStatus.ROLLING_FORWARD,
                timestampMs=3000),
            JobUpdateEvent(
                status=JobUpdateStatus.ROLL_FORWARD_PAUSED,
                message="Investigating issues",
                timestampMs=4000),
            JobUpdateEvent(
                status=JobUpdateStatus.ROLLING_FORWARD,
                timestampMs=5000)],
        instanceEvents=[
            JobInstanceUpdateEvent(
                instanceId=1,
                timestampMs=6000,
                action=JobUpdateAction.INSTANCE_UPDATING),
            JobInstanceUpdateEvent(
                instanceId=2,
                timestampMs=7000,
                action=JobUpdateAction.INSTANCE_UPDATING),
            JobInstanceUpdateEvent(
                instanceId=1,
                timestampMs=8000,
                action=JobUpdateAction.INSTANCE_UPDATED),
            JobInstanceUpdateEvent(
                instanceId=2,
                timestampMs=9000,
                action=JobUpdateAction.INSTANCE_UPDATED)])
    query_response.result.getJobUpdateDetailsResult = GetJobUpdateDetailsResult(details=details)
    return query_response

  def test_active_update_info(self):
    self._mock_api.query_job_updates.return_value = get_status_query_response(count=1)
    self._mock_api.get_job_update_details.return_value = self.get_update_details_response()
    assert self._command.execute(self._fake_context) == EXIT_OK
    assert self._fake_context.get_api(self.TEST_CLUSTER).query_job_updates.mock_calls == [
        call(update_statuses=ACTIVE_JOB_UPDATE_STATES, job_key=self.TEST_JOBKEY)
    ]
    assert '\n'.join(self._fake_context.get_out()) == """\
Job: west/bozo/test/hello, UpdateID: update_id
Started 1970-01-01T00:00:01, last activity: 1970-01-01T00:00:02
Current status: ROLLING_FORWARD
Update events:
  Status: ROLLING_FORWARD at 1970-01-01T00:00:03
  Status: ROLL_FORWARD_PAUSED at 1970-01-01T00:00:04
      message: Investigating issues
  Status: ROLLING_FORWARD at 1970-01-01T00:00:05
Instance events:
  Instance 1 at 1970-01-01T00:00:06: INSTANCE_UPDATING
  Instance 2 at 1970-01-01T00:00:07: INSTANCE_UPDATING
  Instance 1 at 1970-01-01T00:00:08: INSTANCE_UPDATED
  Instance 2 at 1970-01-01T00:00:09: INSTANCE_UPDATED"""

  def test_update_info(self):
    self._mock_options.id = 'update_id'
    self._mock_api.query_job_updates.return_value = get_status_query_response(count=1)
    self._mock_api.get_job_update_details.return_value = self.get_update_details_response()
    assert self._command.execute(self._fake_context) == EXIT_OK

  def test_update_info_json(self):
    self._mock_options.write_json = True
    update_status_response = get_status_query_response(count=1)
    self._mock_api.query_job_updates.return_value = update_status_response
    self._mock_api.get_job_update_details.return_value = self.get_update_details_response()
    assert self._command.execute(self._fake_context) == EXIT_OK

    assert self._mock_api.query_job_updates.mock_calls == [
        call(update_statuses=ACTIVE_JOB_UPDATE_STATES, job_key=self.TEST_JOBKEY)
    ]
    assert self._mock_api.get_job_update_details.mock_calls == [
        call(update_status_response.result.getJobUpdateSummariesResult.updateSummaries[0].key)
    ]
    assert json.loads(self._fake_context.get_out_str()) == {
        "status": "ROLLING_FORWARD",
        "last_modified": "1970-01-01T00:00:02",
        "started": 1000,
        "update_events": [
            {
                "status": "ROLLING_FORWARD",
                "timestampMs": 3000
            },
            {
                "status": "ROLL_FORWARD_PAUSED",
                "message": "Investigating issues",
                "timestampMs": 4000
            },
            {
                "status": "ROLLING_FORWARD",
                "timestampMs": 5000
            }
        ],
        "job": "west/bozo/test/hello",
        "updateId": "update_id",
        "instance_update_events": [
            {
                "action": "INSTANCE_UPDATING",
                "instance": 1,
                "timestamp": 6000
            },
            {
                "action": "INSTANCE_UPDATING",
                "instance": 2,
                "timestamp": 7000
            },
            {
                "action": "INSTANCE_UPDATED",
                "instance": 1,
                "timestamp": 8000
            },
            {
                "action": "INSTANCE_UPDATED",
                "instance": 2,
                "timestamp": 9000
            }
        ]
    }
Beispiel #6
0
class TestUpdateInfo(AuroraClientCommandTest):
    def setUp(self):
        self._command = UpdateInfo()
        self._mock_options = mock_verb_options(self._command)
        self._mock_options.jobspec = self.TEST_JOBKEY
        self._mock_options.id = None
        self._fake_context = FakeAuroraCommandContext()
        self._fake_context.set_options(self._mock_options)
        self._mock_api = self._fake_context.get_api('UNUSED')

    @classmethod
    def get_update_details_response(cls):
        query_response = Response()
        query_response.responseCode = ResponseCode.OK
        query_response.result = Result()
        details = JobUpdateDetails(
            update=JobUpdate(summary=JobUpdateSummary(
                key=UPDATE_KEY,
                user="******",
                state=JobUpdateState(status=JobUpdateStatus.ROLLING_FORWARD,
                                     createdTimestampMs=1000,
                                     lastModifiedTimestampMs=2000))),
            updateEvents=[
                JobUpdateEvent(status=JobUpdateStatus.ROLLING_FORWARD,
                               timestampMs=3000),
                JobUpdateEvent(status=JobUpdateStatus.ROLL_FORWARD_PAUSED,
                               message="Investigating issues",
                               timestampMs=4000),
                JobUpdateEvent(status=JobUpdateStatus.ROLLING_FORWARD,
                               timestampMs=5000)
            ],
            instanceEvents=[
                JobInstanceUpdateEvent(
                    instanceId=1,
                    timestampMs=6000,
                    action=JobUpdateAction.INSTANCE_UPDATING),
                JobInstanceUpdateEvent(
                    instanceId=2,
                    timestampMs=7000,
                    action=JobUpdateAction.INSTANCE_UPDATING),
                JobInstanceUpdateEvent(
                    instanceId=1,
                    timestampMs=8000,
                    action=JobUpdateAction.INSTANCE_UPDATED),
                JobInstanceUpdateEvent(instanceId=2,
                                       timestampMs=9000,
                                       action=JobUpdateAction.INSTANCE_UPDATED)
            ])
        query_response.result.getJobUpdateDetailsResult = GetJobUpdateDetailsResult(
            detailsList=[details])
        return query_response

    def test_active_update_info(self):
        self._mock_api.query_job_updates.return_value = get_status_query_response(
            count=1)
        self._mock_api.get_job_update_details.return_value = self.get_update_details_response(
        )
        assert self._command.execute(self._fake_context) == EXIT_OK
        assert self._fake_context.get_api(
            self.TEST_CLUSTER).query_job_updates.mock_calls == [
                call(update_statuses=ACTIVE_JOB_UPDATE_STATES,
                     job_key=self.TEST_JOBKEY)
            ]
        assert '\n'.join(self._fake_context.get_out()) == """\
Job: west/bozo/test/hello, UpdateID: update_id
Started 1970-01-01T00:00:01, last activity: 1970-01-01T00:00:02
Current status: ROLLING_FORWARD
Update events:
  Status: ROLLING_FORWARD at 1970-01-01T00:00:03
  Status: ROLL_FORWARD_PAUSED at 1970-01-01T00:00:04
      message: Investigating issues
  Status: ROLLING_FORWARD at 1970-01-01T00:00:05
Instance events:
  Instance 1 at 1970-01-01T00:00:06: INSTANCE_UPDATING
  Instance 2 at 1970-01-01T00:00:07: INSTANCE_UPDATING
  Instance 1 at 1970-01-01T00:00:08: INSTANCE_UPDATED
  Instance 2 at 1970-01-01T00:00:09: INSTANCE_UPDATED"""

    def test_update_info(self):
        self._mock_options.id = 'update_id'
        self._mock_api.query_job_updates.return_value = get_status_query_response(
            count=1)
        self._mock_api.get_job_update_details.return_value = self.get_update_details_response(
        )
        assert self._command.execute(self._fake_context) == EXIT_OK

    def test_update_info_json(self):
        self._mock_options.write_json = True
        update_status_response = get_status_query_response(count=1)
        self._mock_api.query_job_updates.return_value = update_status_response
        self._mock_api.get_job_update_details.return_value = self.get_update_details_response(
        )
        assert self._command.execute(self._fake_context) == EXIT_OK

        assert self._mock_api.query_job_updates.mock_calls == [
            call(update_statuses=ACTIVE_JOB_UPDATE_STATES,
                 job_key=self.TEST_JOBKEY)
        ]
        assert self._mock_api.get_job_update_details.mock_calls == [
            call(update_status_response.result.getJobUpdateSummariesResult.
                 updateSummaries[0].key)
        ]
        assert json.loads(self._fake_context.get_out_str()) == {
            "status":
            "ROLLING_FORWARD",
            "last_modified":
            "1970-01-01T00:00:02",
            "started":
            1000,
            "update_events": [{
                "status": "ROLLING_FORWARD",
                "timestampMs": 3000
            }, {
                "status": "ROLL_FORWARD_PAUSED",
                "message": "Investigating issues",
                "timestampMs": 4000
            }, {
                "status": "ROLLING_FORWARD",
                "timestampMs": 5000
            }],
            "job":
            "west/bozo/test/hello",
            "updateId":
            "update_id",
            "instance_update_events": [{
                "action": "INSTANCE_UPDATING",
                "instance": 1,
                "timestamp": 6000
            }, {
                "action": "INSTANCE_UPDATING",
                "instance": 2,
                "timestamp": 7000
            }, {
                "action": "INSTANCE_UPDATED",
                "instance": 1,
                "timestamp": 8000
            }, {
                "action": "INSTANCE_UPDATED",
                "instance": 2,
                "timestamp": 9000
            }]
        }