def get_status_query_response(cls): query_response = Response() query_response.responseCode = ResponseCode.OK query_response.result = Result() summaries = GetJobUpdateSummariesResult() query_response.result.getJobUpdateSummariesResult = summaries summaries.updateSummaries = [ JobUpdateSummary( updateId="hello", jobKey=AuroraJobKey('west', 'mcc', 'test', 'hello'), user="******", state=JobUpdateState(status=JobUpdateStatus.ROLLING_FORWARD, createdTimestampMs=1411404927, lastModifiedTimestampMs=14114056030)), JobUpdateSummary( updateId="goodbye", jobKey=AuroraJobKey('west', 'mch', 'prod', 'goodbye'), user="******", state=JobUpdateState(status=JobUpdateStatus.ROLLING_BACK, createdTimestampMs=1411300632, lastModifiedTimestampMs=14114092632)), JobUpdateSummary(updateId="gasp", jobKey=AuroraJobKey('west', 'mcq', 'devel', 'gasp'), user="******", state=JobUpdateState( status=JobUpdateStatus.ROLL_FORWARD_PAUSED, createdTimestampMs=1411600891, lastModifiedTimestampMs=1411800891)) ] return query_response
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 get_update_details_response(cls): query_response = Response() query_response.responseCode = ResponseCode.OK query_response.result = Result() details = JobUpdateDetails() query_response.result.getJobUpdateDetailsResult = GetJobUpdateDetailsResult(details=details) details.update = JobUpdate() details.update.summary = JobUpdateSummary( jobKey=AuroraJobKey("west", "mcc", "test", "hello"), updateId="fake-update-identifier", user="******", state=JobUpdateState( status=JobUpdateStatus.ROLLING_FORWARD, createdTimestampMs=1411404927, lastModifiedTimestampMs=14114056030, ), ) details.updateEvents = [ JobUpdateEvent(status=JobUpdateStatus.ROLLING_FORWARD, timestampMs=1411404927), JobUpdateEvent(status=JobUpdateStatus.ROLL_FORWARD_PAUSED, timestampMs=1411405000), JobUpdateEvent(status=JobUpdateStatus.ROLLING_FORWARD, timestampMs=1411405100), ] details.instanceEvents = [ JobInstanceUpdateEvent(instanceId=1, timestampMs=1411404930, action=JobUpdateAction.INSTANCE_UPDATING), JobInstanceUpdateEvent(instanceId=2, timestampMs=1411404940, action=JobUpdateAction.INSTANCE_UPDATING), JobInstanceUpdateEvent(instanceId=1, timestampMs=1411404950, action=JobUpdateAction.INSTANCE_UPDATED), JobInstanceUpdateEvent(instanceId=2, timestampMs=1411404960, action=JobUpdateAction.INSTANCE_UPDATED), ] return query_response
def mock_scheduler(cls, response_code=None): scheduler = create_autospec(spec=SchedulerThriftApiSpec, instance=True) response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message='test')]) resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=cls.create_tasks())) scheduler.getTasksWithoutConfigs.return_value = resp return scheduler
def expect_start(self, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code response = Response(responseCode=response_code, messageDEPRECATED='test', serverInfo=SERVER_INFO) response.result = Result(acquireLockResult=AcquireLockResult(lock=self._lock)) self._scheduler.acquireLock(LockKey(job=self._job_key), self._session_key).AndReturn(response)
def mock_get_tasks(self, tasks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message='test')]) resp.result = Result(scheduleStatusResult=ScheduleStatusResult( tasks=tasks)) self._scheduler.getTasksWithoutConfigs.return_value = resp
def mock_get_quota(self, allocated, consumed, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') resp.result = Result(getQuotaResult=GetQuotaResult( quota=deepcopy(allocated), prodConsumption=deepcopy(consumed))) self._scheduler.getQuota.return_value = resp
def create_response(cls, quota, prod, non_prod, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message='test')]) resp.result = Result(getQuotaResult=GetQuotaResult( quota=quota, prodConsumption=prod, nonProdConsumption=non_prod)) return resp
def expect_populate(self, job_config, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') result = set([deepcopy(job_config.taskConfig)]) resp.result = Result(populateJobResult=PopulateJobResult( populatedDEPRECATED=result)) self._scheduler.populateJobConfig(job_config).AndReturn(resp)
def mock_scheduler(cls, response_code=None): scheduler = Mock() response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=cls.create_tasks())) scheduler.getTasksWithoutConfigs.return_value = resp return scheduler
def expect_start(self, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code response = Response(responseCode=response_code, messageDEPRECATED='test') response.result = Result(acquireLockResult=AcquireLockResult( lock=self._lock)) self._scheduler.acquireLock(LockKey(job=self._job_key), self._session_key).AndReturn(response)
def mock_get_quota(self, allocated, consumed, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message='test')]) resp.result = Result( getQuotaResult=GetQuotaResult( quota=deepcopy(allocated), prodSharedConsumption=deepcopy(consumed))) self._scheduler.getQuota.return_value = resp
def mock_get_quota(self, allocated, consumed, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED="test") resp.result = Result( getQuotaResult=GetQuotaResult(quota=deepcopy(allocated), prodConsumption=deepcopy(consumed)) ) self._scheduler.getQuota.return_value = resp
def expect_get_statuses(self, instance_ids=WATCH_INSTANCES, num_calls=EXPECTED_CYCLES): tasks = [self.create_task(instance_id) for instance_id in instance_ids] response = Response(responseCode=ResponseCode.OK, messageDEPRECATED="test") response.result = Result() response.result.scheduleStatusResult = ScheduleStatusResult(tasks=tasks) query = self.get_tasks_status_query(instance_ids) for _ in range(int(num_calls)): self._scheduler.getTasksWithoutConfigs(query).AndReturn(response)
def mock_scheduler(cls, response_code=None): scheduler = create_autospec(spec=SchedulerThriftApiSpec, instance=True) response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message='test')]) resp.result = Result(scheduleStatusResult=ScheduleStatusResult( tasks=cls.create_tasks())) scheduler.getTasksWithoutConfigs.return_value = resp return scheduler
def expect_get_tasks(self, tasks, ignore_ids=None, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code response = Response(responseCode=response_code, messageDEPRECATED='test', serverInfo=SERVER_INFO) scheduled = [] for index, task in enumerate(tasks): if not ignore_ids or index not in ignore_ids: scheduled.append(ScheduledTask(assignedTask=AssignedTask(task=task, instanceId=index))) response.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=scheduled)) query = TaskQuery(jobKeys=[self._job_key], statuses=ACTIVE_STATES) self._scheduler.getTasksStatus(query).AndReturn(response)
def mock_status_active_tasks(self, instance_ids): tasks = [] for i in instance_ids: tasks.append(ScheduledTask( status=ScheduleStatus.RUNNING, assignedTask=AssignedTask(task=TaskConfig(), instanceId=i) )) response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') response.result = Result() response.result.scheduleStatusResult = ScheduleStatusResult(tasks=tasks) self.mock_scheduler.getTasksWithoutConfigs(IgnoreArg()).AndReturn(response)
def expect_get_statuses(self, instance_ids=WATCH_INSTANCES, num_calls=EXPECTED_CYCLES): tasks = [self.create_task(instance_id) for instance_id in instance_ids] response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') response.result = Result() response.result.scheduleStatusResult = ScheduleStatusResult( tasks=tasks) query = self.get_tasks_status_query(instance_ids) for x in range(int(num_calls)): self._scheduler.getTasksWithoutConfigs(query).AndReturn(response)
def expect_get_tasks(self, tasks, ignore_ids=None, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code response = Response(responseCode=response_code, messageDEPRECATED='test') scheduled = [] for index, task in enumerate(tasks): if not ignore_ids or index not in ignore_ids: scheduled.append(ScheduledTask(assignedTask=AssignedTask(task=task, instanceId=index))) response.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=scheduled)) query = TaskQuery( owner=Identity(role=self._job_key.role), environment=self._job_key.environment, jobName=self._job_key.name, statuses=ACTIVE_STATES) self._scheduler.getTasksStatus(query).AndReturn(response)
def get_status_query_response(self, count=3): query_response = Response() query_response.responseCode = ResponseCode.OK query_response.result = Result() summaries = GetJobUpdateSummariesResult() query_response.result.getJobUpdateSummariesResult = summaries summaries.updateSummaries = [JobUpdateSummary( updateId="%s" % i, jobKey=self.TEST_JOBKEY.to_thrift(), user="******", state=JobUpdateState( status=JobUpdateStatus.ROLLED_FORWARD, createdTimestampMs=1411404927, lastModifiedTimestampMs=14114056030)) for i in range(count)] return query_response
def mock_status_active_tasks(self, instance_ids): tasks = [] for i in instance_ids: tasks.append( ScheduledTask(status=ScheduleStatus.RUNNING, assignedTask=AssignedTask(task=TaskConfig(), instanceId=i))) response = Response(responseCode=ResponseCode.OK, messageDEPRECATED='test') response.result = Result() response.result.scheduleStatusResult = ScheduleStatusResult( tasks=tasks) self.mock_scheduler.getTasksWithoutConfigs( IgnoreArg()).AndReturn(response)
def setUp(self): self.mox = Mox() self.mox.StubOutClassWithMocks(AuroraAdmin, 'Client') self.mox.StubOutClassWithMocks(scheduler_client, 'SchedulerClient') self.mock_scheduler_client = self.mox.CreateMock(scheduler_client.SchedulerClient) self.mock_thrift_client = self.mox.CreateMock(AuroraAdmin.Client) scheduler_client.SchedulerClient.get(IgnoreArg(), verbose=IgnoreArg()).AndReturn( self.mock_scheduler_client) self.mock_scheduler_client.get_thrift_client().AndReturn(self.mock_thrift_client) version_resp = Response(responseCode=ResponseCode.OK) version_resp.result = Result(getVersionResult=CURRENT_API_VERSION) self.mock_thrift_client.getVersion().AndReturn(version_resp)
def expect_get_tasks(self, tasks, ignore_ids=None, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code response = Response(responseCode=response_code, messageDEPRECATED='test') scheduled = [] for index, task in enumerate(tasks): if not ignore_ids or index not in ignore_ids: scheduled.append( ScheduledTask(assignedTask=AssignedTask(task=task, instanceId=index))) response.result = Result(scheduleStatusResult=ScheduleStatusResult( tasks=scheduled)) query = TaskQuery(owner=Identity(role=self._job_key.role), environment=self._job_key.environment, jobName=self._job_key.name, statuses=ACTIVE_STATES) self._scheduler.getTasksStatus(query).AndReturn(response)
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), metadata={ Metadata("issue", "test"), Metadata("country", "America"), Metadata("country", "Canada") })), 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 get_update_details_response(self): query_response = Response() query_response.responseCode = ResponseCode.OK query_response.result = Result() details = JobUpdateDetails( update=JobUpdate( summary=JobUpdateSummary( jobKey=self.TEST_JOBKEY.to_thrift(), updateId="0", user="******", state=JobUpdateState( status=JobUpdateStatus.ROLLING_FORWARD, createdTimestampMs=1411404927, lastModifiedTimestampMs=14114056030))), updateEvents=[ JobUpdateEvent( status=JobUpdateStatus.ROLLING_FORWARD, timestampMs=1411404927), JobUpdateEvent( status=JobUpdateStatus.ROLL_FORWARD_PAUSED, timestampMs=1411405000), JobUpdateEvent( status=JobUpdateStatus.ROLLING_FORWARD, timestampMs=1411405100)], instanceEvents=[ JobInstanceUpdateEvent( instanceId=1, timestampMs=1411404930, action=JobUpdateAction.INSTANCE_UPDATING), JobInstanceUpdateEvent( instanceId=2, timestampMs=1411404940, action=JobUpdateAction.INSTANCE_UPDATING), JobInstanceUpdateEvent( instanceId=1, timestampMs=1411404950, action=JobUpdateAction.INSTANCE_UPDATED), JobInstanceUpdateEvent( instanceId=2, timestampMs=1411404960, action=JobUpdateAction.INSTANCE_UPDATED)]) query_response.result.getJobUpdateDetailsResult = GetJobUpdateDetailsResult(details=details) return query_response
def setUp(self): self.mox = Mox() self.mox.StubOutClassWithMocks(AuroraAdmin, 'Client') self.mox.StubOutClassWithMocks(scheduler_client, 'SchedulerClient') self.mock_scheduler_client = self.mox.CreateMock( scheduler_client.SchedulerClient) self.mock_thrift_client = self.mox.CreateMock(AuroraAdmin.Client) scheduler_client.SchedulerClient.get(IgnoreArg(), verbose=IgnoreArg()).AndReturn( self.mock_scheduler_client) self.mock_scheduler_client.get_thrift_client().AndReturn( self.mock_thrift_client) version_resp = Response(responseCode=ResponseCode.OK) version_resp.result = Result(getVersionResult=CURRENT_API_VERSION) self.mock_thrift_client.getVersion().AndReturn(version_resp)
def get_status_query_response(cls): query_response = Response() query_response.responseCode = ResponseCode.OK query_response.result = Result() summaries = GetJobUpdateSummariesResult() query_response.result.getJobUpdateSummariesResult = summaries summaries.updateSummaries = [ JobUpdateSummary( updateId="hello", jobKey=AuroraJobKey("west", "mcc", "test", "hello"), user="******", state=JobUpdateState( status=JobUpdateStatus.ROLLING_FORWARD, createdTimestampMs=1411404927, lastModifiedTimestampMs=14114056030, ), ), JobUpdateSummary( updateId="goodbye", jobKey=AuroraJobKey("west", "mch", "prod", "goodbye"), user="******", state=JobUpdateState( status=JobUpdateStatus.ROLLING_BACK, createdTimestampMs=1411300632, lastModifiedTimestampMs=14114092632, ), ), JobUpdateSummary( updateId="gasp", jobKey=AuroraJobKey("west", "mcq", "devel", "gasp"), user="******", state=JobUpdateState( status=JobUpdateStatus.ROLL_FORWARD_PAUSED, createdTimestampMs=1411600891, lastModifiedTimestampMs=1411800891, ), ), ] return query_response
def get_update_details_response(cls): query_response = Response() query_response.responseCode = ResponseCode.OK query_response.result = Result() details = JobUpdateDetails() query_response.result.getJobUpdateDetailsResult = GetJobUpdateDetailsResult( details=details) details.update = JobUpdate() details.update.summary = JobUpdateSummary( jobKey=AuroraJobKey('west', 'mcc', 'test', 'hello'), updateId="fake-update-identifier", user="******", state=JobUpdateState(status=JobUpdateStatus.ROLLING_FORWARD, createdTimestampMs=1411404927, lastModifiedTimestampMs=14114056030)) details.updateEvents = [ JobUpdateEvent(status=JobUpdateStatus.ROLLING_FORWARD, timestampMs=1411404927), JobUpdateEvent(status=JobUpdateStatus.ROLL_FORWARD_PAUSED, timestampMs=1411405000), JobUpdateEvent(status=JobUpdateStatus.ROLLING_FORWARD, timestampMs=1411405100) ] details.instanceEvents = [ JobInstanceUpdateEvent(instanceId=1, timestampMs=1411404930, action=JobUpdateAction.INSTANCE_UPDATING), JobInstanceUpdateEvent(instanceId=2, timestampMs=1411404940, action=JobUpdateAction.INSTANCE_UPDATING), JobInstanceUpdateEvent(instanceId=1, timestampMs=1411404950, action=JobUpdateAction.INSTANCE_UPDATED), JobInstanceUpdateEvent(instanceId=2, timestampMs=1411404960, action=JobUpdateAction.INSTANCE_UPDATED) ] return query_response
def get_status_query_response(cls): query_response = Response() query_response.responseCode = ResponseCode.OK query_response.result = Result() summaries = GetJobUpdateSummariesResult() query_response.result.getJobUpdateSummariesResult = summaries summaries.updateSummaries = [ JobUpdateSummary( updateId="hello", jobKey=AuroraJobKey('west', 'mcc', 'test', 'hello'), user="******", state=JobUpdateState(status=JobUpdateStatus.ROLLING_FORWARD, createdTimestampMs=1411404927, lastModifiedTimestampMs=14114056030)), JobUpdateSummary( updateId="goodbye", jobKey=AuroraJobKey('west', 'mch', 'prod', 'goodbye'), user="******", state=JobUpdateState(status=JobUpdateStatus.ROLLING_BACK, createdTimestampMs=1411300632, lastModifiedTimestampMs=14114092632)), JobUpdateSummary( updateId="gasp", jobKey=AuroraJobKey('west', 'mcq', 'devel', 'gasp'), user="******", state=JobUpdateState(status=JobUpdateStatus.ROLL_FORWARD_PAUSED, createdTimestampMs=1411600891, lastModifiedTimestampMs=1411800891))] return query_response
def create_response(cls, quota, prod, non_prod, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message='test')]) resp.result = Result(getQuotaResult=GetQuotaResult( quota=quota, prodConsumption=prod, nonProdConsumption=non_prod)) return resp
def create_response(cls, tasks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') resp.result = Result(scheduleStatusResult=ScheduleStatusResult( tasks=tasks)) return resp
def create_response(cls, tasks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks)) return resp
def create_response(cls, locks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') resp.result = Result(getLocksResult=GetLocksResult(locks=locks)) return resp
def mock_get_tasks(self, tasks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks)) self._scheduler.getTasksWithoutConfigs.return_value = resp
def create_response(cls, locks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') resp.result = Result(getLocksResult=GetLocksResult(locks=locks)) return resp
def expect_populate(self, job_config, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, messageDEPRECATED='test') result = set([deepcopy(job_config.taskConfig)]) resp.result = Result(populateJobResult=PopulateJobResult(populated=result)) self._scheduler.populateJobConfig(job_config).AndReturn(resp)
def mock_get_tasks(self, tasks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message="test")]) resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks)) self._scheduler.getTasksWithoutConfigs.return_value = resp
def create_response(cls, locks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message='test')]) resp.result = Result(getLocksResult=GetLocksResult(locks=locks)) return resp
def create_response(cls, locks, response_code=None): response_code = ResponseCode.OK if response_code is None else response_code resp = Response(responseCode=response_code, details=[ResponseDetail(message='test')]) resp.result = Result(getLocksResult=GetLocksResult(locks=locks)) return resp