def test_task_are_in_task_to_json(self, mock_conn): task = Task(mock_conn, "task-name") task.completion_ttl = "4.11:08:06" task.auto_delete = True json_task = task._to_json() # pylint: disable=protected-access assert json_task['completionTimeToLive'] == '4.11:08:06' assert json_task['autoDeleteOnCompletion'] is True
def test_task_are_in_task_to_json(self): task = Task(self.conn, "task-name") task.completion_ttl = "4.11:08:06" task.auto_delete = True json_task = task._to_json() assert json_task['completionTimeToLive'] == '4.11:08:06' assert json_task['autoDeleteOnCompletion'] == True
def test_advance_bucket_in_task_to_json(self, mock_conn): task = Task(mock_conn, "task-name", "profile") bucket = Bucket(mock_conn, "name", False) bucket2 = bucket.with_filtering(BucketPrefixFiltering( "prefix1")).with_resource_transformation(PrefixResourcesTransformation("prefix2")) task.resources.append(bucket2) json_task = task._to_json() json_bucket = json_task["advancedResourceBuckets"][0] assert "name" == json_bucket["bucketName"] assert "prefix1" == json_bucket["filtering"]["prefixFiltering"]["prefix"] assert "prefix2" == json_bucket["resourcesTransformation"]["stripPrefix"]["prefix"]
def test_advance_bucket_in_task_from_json(self, mock_conn): json_bucket = { "bucketName": "name", "filtering": { "prefixFiltering": { "prefix": "prefix1" } }, "resourcesTransformation": { "stripPrefix": { "prefix": "prefix2" } }, "cacheTTLSec": 1000 } json_task = { "name": "taskName", "shortname": "taskShortname", "profile": "profile", "instanceCount": 1, "runningCoreCount": None, "runningInstanceCount": None, "advancedResourceBuckets": [json_bucket], "creationDate": "2019-11-08T10:54:11Z", "uuid": "000", "state": "Submitted", } task = Task.from_json(mock_conn, json_task) task._auto_update = False assert "name" == task.resources[0].uuid assert "prefix1" == task.resources[0]._filtering._filters["prefixFiltering"].prefix assert "prefix2" == task.resources[0]._resources_transformation._resource_transformers["stripPrefix"].prefix assert 1000 == task.resources[0]._cache_ttl_sec
def tasks(self): """Get the list of tasks stored on this cluster for this user. :rtype: List of :class:`~qarnot.task.Task`. :returns: Tasks stored on the cluster owned by the user. :raises qarnot.exceptions.UnauthorizedException: invalid credentials :raises qarnot.exceptions.QarnotGenericException: API general error, see message for details """ response = self._get(get_url('tasks')) raise_on_error(response) return [Task.from_json(self, task) for task in response.json()]
def create_task(self, name, profile, instancecount_or_range=1): """Create a new :class:`~qarnot.task.Task`. :param str name: given name of the task :param str profile: which profile to use with this task :param instancecount_or_range: number of instances, or ranges on which to run task. Defaults to 1. :type instancecount_or_range: int or str :rtype: :class:`~qarnot.task.Task` :returns: The created :class:`~qarnot.task.Task`. .. note:: See available profiles with :meth:`profiles`. """ return Task(self, name, profile, instancecount_or_range)
def test_task_privileges(self, mock_conn): task = Task(mock_conn, "task-name") task.allow_credentials_to_be_exported_to_task_environment() assert task.privileges is not None assert task.privileges._exportApiAndStorageCredentialsInEnvironment == True json_task = task._to_json() assert json_task['privileges'] is not None assert json_task['privileges']['exportApiAndStorageCredentialsInEnvironment'] is True # fields that need to be non null for the deserialization to not fail json_task['creationDate'] = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") json_task['uuid'] = str(uuid.uuid4()) json_task['state'] = 'Submitted' json_task['runningCoreCount'] = 0 json_task['runningInstanceCount'] = 0 pool_from_json = Task(mock_conn, "task-name") pool_from_json._update(json_task) assert pool_from_json.privileges is not None assert pool_from_json.privileges._exportApiAndStorageCredentialsInEnvironment is True
def retrieve_task(self, uuid): """Retrieve a :class:`qarnot.task.Task` from its uuid :param str uuid: Desired task uuid :rtype: :class:`~qarnot.task.Task` :returns: Existing task defined by the given uuid :raises qarnot.exceptions.MissingTaskException: task does not exist :raises qarnot.exceptions.UnauthorizedException: invalid credentials :raises qarnot.exceptions.QarnotGenericException: API general error, see message for details """ response = self._get(get_url('task update', uuid=uuid)) if response.status_code == 404: raise MissingTaskException(response.json()['message']) raise_on_error(response) return Task.from_json(self, response.json())
def test_bucket_in_task_from_json(self, mock_conn): json_bucket = "bucket-name" json_task = { "name": "taskName", "shortname": "taskShortname", "profile": "profile", "instanceCount": 1, "runningCoreCount": None, "runningInstanceCount": None, "resourceBuckets": [json_bucket], "creationDate": "2019-11-08T10:54:11Z", "uuid": "000", "state": "Submitted", } task = Task.from_json(mock_conn, json_task) task._auto_update = False assert "bucket-name" == task.resources[0].uuid
def test_task_autodelete_set_get(self, mock_conn): task = Task(mock_conn, "task-name") task.auto_delete = False assert task.auto_delete is False task.auto_delete = True assert task.auto_delete is True
def test_task_completion_ttl_set_get(self, mock_conn): task = Task(mock_conn, "task-name") task.completion_ttl = datetime.timedelta(days=2, hours=33, minutes=66, seconds=66) assert "3.10:07:06" == task.completion_ttl task.completion_ttl = "4.11:08:06" assert "4.11:08:06" == task.completion_ttl
def test_task_autodelete_default_value(self, mock_conn): task = Task(mock_conn, "task-name") assert task.auto_delete is False
def test_task_completion_ttl_default_value(self, mock_conn): task = Task(mock_conn, "task-name") assert "00:00:00" == task.completion_ttl
def test_task_set_forbidden_property_raise_exception(self, mock_conn, property_name, set_value, exception): task = Task(mock_conn, "task-name") with pytest.raises(exception): setattr(task, property_name, set_value)
def test_execution_attempt_count_in_completed_instances(self, mock_conn): task = Task(mock_conn, "task-name") task._update(default_json_task) assert task.completed_instances[0].execution_attempt_count == 43
def test_task_autodelete_set_get(self): task = Task(self.conn, "task-name") task.auto_delete = False assert False == task.auto_delete task.auto_delete = True assert True == task.auto_delete
def test_task_property_send_to_json_representation(self, mock_conn, property_name, expected_value): task = Task(mock_conn, "task-name") task._update(default_json_task) task_json = task._to_json() assert task_json[property_name] == expected_value
def test_task_set_property_raise_exception_after_submitted(self, mock_conn, property_name, set_value, exception): task = Task(mock_conn, "task-name") self.submit_task(task) with pytest.raises(exception): setattr(task, property_name, set_value)
def test_task_property_update_value(self, mock_conn, property_name, expected_value): task = Task(mock_conn, "task-name") task._update(default_json_task) assert getattr(task, property_name) == expected_value
def test_execution_attempt_count_in_running_instances(self, mock_conn): task = Task(mock_conn, "task-name") task._update(task_with_running_instances) assert len(task.status.running_instances_info.per_running_instance_info) == 2 assert task.status.running_instances_info.per_running_instance_info[0].execution_attempt_count == 1 assert task.status.running_instances_info.per_running_instance_info[1].execution_attempt_count == 2
def test_task_set_property_value(self, mock_conn, property_name, set_value, expected_value): task = Task(mock_conn, "task-name") setattr(task, property_name, set_value) assert getattr(task, property_name) == expected_value
def test_task_autodelete_default_value(self): task = Task(self.conn, "task-name") assert False == task.auto_delete