Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.58k stars 2.8k forks source link

Update batch job with on_task_failure='performExitOptionsJobAction' always failed #34451

Open maskinoshita opened 7 months ago

maskinoshita commented 7 months ago

used azure related libraries:

Describe the bug

Add job with on_task_failure='performExitOptionsJobAction' is ok, but update the job always fail.

To Reproduce Steps to reproduce the behavior:

  1. Create a JobAddParameter with on_task_failure='performExitOptionsJobAction' and add the job
  2. Create a JobUpdateParamter and update the job
  3. Then it will fail
# 1
from azure.batch import batch_auth, BatchServiceClient, models

batch_creds = batch_auth.SharedKeyCredentials(os.environ["BATCH_ACCOUNT_NAME"], os.environ["BATCH_ACCOUNT_KEY"])
batch_client = BatchServiceClient(batch_creds, batch_url=f'https://{os.environ["BATCH_ACCOUNT_URL"]}')
imr = models.ImageReference(
    publisher="Canonical",
    offer="0001-com-ubuntu-server-jammy",
    sku="22_04-lts-gen2",
    version="latest"
)
vmc = models.VirtualMachineConfiguration(
    image_reference = imr,
    node_agent_sku_id = "batch.node.ubuntu 22.04"
)
pool_info = models.PoolInformation(
    auto_pool_specification=models.AutoPoolSpecification(
        auto_pool_id_prefix = "test-batch",
        pool = models.PoolSpecification(
            vm_size = "Standard_DS11_v2",
            target_dedicated_nodes = 1,
            virtual_machine_configuration = vmc
        ),
        keep_alive = False,
        pool_lifetime_option = models.PoolLifetimeOption.job
    )
)
job = models.JobAddParameter(
    id = generate_unique_name("test-job"),
    pool_info=pool_info,
    on_task_failure='performExitOptionsJobAction'
)
batch_client.job.add(job)

exit_option = models.ExitOptions(
    job_action='terminate'
)
task = models.TaskAddParameter(
    id = "test-task",
    constraints = task_constraints,
    exit_conditions=models.ExitConditions(
        pre_processing_error=exit_option,
        file_upload_error=exit_option,
        default=exit_option
    ),
    command_line = f"/bin/bash -c \"echo test | tee test.txt\""
)
batch_client.task.add(job_id=job.id, task=task)

# 2
new_job_opts = models.JobUpdateParameter(
    pool_info = pool_info,
    on_all_tasks_complete = 'terminateJob',
    on_task_failure='performExitOptionsJobAction' # it fails with or without this.
)
batch_client.job.update(job.id, new_job_opts) # 3

Expected behavior

Job update with on_task_failure done without error.

Error Log

[2024-02-26T09:38:31.192Z] on_task_failure is not a known attribute of class <class 'azure.batch.models._models_py3.JobUpdateParameter'> and will be ignored
[2024-02-26T09:38:31.236Z] Executed 'Functions.test' (Failed, Id=1cb57a6a-5e0d-4c7b-8c18-03872d6c73a4, Duration=323ms)
[2024-02-26T09:38:31.237Z] System.Private.CoreLib: Exception while executing function: Functions.test. System.Private.CoreLib: Result: Failure
[2024-02-26T09:38:31.237Z] Exception: BatchErrorException: Request encountered an exception.
[2024-02-26T09:38:31.237Z] Code: InvalidPropertyValue
[2024-02-26T09:38:31.237Z] Message: {'additional_properties': {}, 'lang': 'en-US', 'value': 'The value provided for one of the properties in the request body is invalid.\nRequestId:f50c8b7b-c5cf-4a58-8728-96fd557afa0a\nTime:2024-02-26T09:38:31.2156154Z'}
[2024-02-26T09:38:31.237Z] PropertyName: onTaskFailure
[2024-02-26T09:38:31.237Z] PropertyValue: NoAction
[2024-02-26T09:38:31.237Z] Reason: The property onTaskFailure cannot be updated
[2024-02-26T09:38:31.237Z] 
[2024-02-26T09:38:31.237Z] Stack:   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py", line 489, in _handle__invocation_request
[2024-02-26T09:38:31.237Z]     call_result = await self._run_async_func(
[2024-02-26T09:38:31.237Z]                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-02-26T09:38:31.237Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py", line 768, in _run_async_func
[2024-02-26T09:38:31.237Z]     return await ExtensionManager.get_async_invocation_wrapper(
[2024-02-26T09:38:31.237Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-02-26T09:38:31.237Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/extension.py", line 147, in get_async_invocation_wrapper
[2024-02-26T09:38:31.237Z]     result = await function(**args)
[2024-02-26T09:38:31.237Z]              ^^^^^^^^^^^^^^^^^^^^^^
[2024-02-26T09:38:31.237Z]   File "/home/mk/repo2/youtube-transcribe/terraform/test/function_app.py", line 149, in test
[2024-02-26T09:38:31.237Z]     job_update_result = batch_client.job.update(job.id, new_job_opts)
[2024-02-26T09:38:31.237Z]                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-02-26T09:38:31.237Z]   File "/home/mk/.pyenv/versions/3.11.7/lib/python3.11/site-packages/azure/batch/operations/_job_operations.py", line 470, in update
[2024-02-26T09:38:31.237Z]     raise models.BatchErrorException(self._deserialize, response)
[2024-02-26T09:38:31.237Z] .
github-actions[bot] commented 7 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @bgklein @cRui861 @dpwatrous @gingi @mksuni @mscurrell @paterasMSFT.

github-actions[bot] commented 7 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @bgklein @cRui861 @dpwatrous @gingi @mksuni @mscurrell @paterasMSFT.