def expect_add(self, instance_ids, task_config, response_code=ResponseCode.OK): for i in instance_ids: add_config = AddInstancesConfig( key=self._job_key, taskConfig=task_config, instanceIds=frozenset([int(i)])) self._scheduler.addInstances( add_config, self._lock, self._session_key).InAnyOrder().AndReturn(make_response(response_code))
def expect_add(self, instance_ids, task_config, response_code=None): for i in instance_ids: response_code = ResponseCode.OK if response_code is None else response_code response = Response(responseCode=response_code, messageDEPRECATED='test') add_config = AddInstancesConfig(key=self._job_key, taskConfig=task_config, instanceIds=frozenset([int(i)])) self._scheduler.addInstances( add_config, self._lock, self._session_key).InAnyOrder().AndReturn(response)
def _add_instances(self, instance_data): """Instructs the scheduler to batch-add instances. Arguments: instance_data -- list of InstanceData to add. """ instance_ids = [data.instance_id for data in instance_data] to_config = instance_data[0].operation_configs.to_config log.debug('Batch adding instances: %s' % instance_ids) add_config = AddInstancesConfig( key=self._job_key, taskConfig=to_config[instance_ids[0]], # instance_ids will always have at least 1 item. instanceIds=frozenset(int(s) for s in instance_ids)) self._check_and_log_response(self._scheduler.addInstances(add_config, self._lock)) log.debug('Done batch adding instances: %s' % instance_ids)