Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] VirtualMachineRunCommands_Update PATCH method will update whole resource #28173

Open
teowa opened this issue Mar 8, 2024 · 2 comments
Open
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Mgmt This issue is related to a management-plane library.

Comments

@teowa
Copy link
Contributor

teowa commented Mar 8, 2024

API Spec link

API Spec version

2023-03-01

Describe the bug

The REST API PATCH method is supposed to update part of the resource, in other words, if you send a PATCH request to update a resource, the server will only update the specified fields in the existing resource. However the VirtualMachineRunCommands_Update method will update the whole resource.
If omit properties.source in PATCH request payload, send payload like below one, the properties.source is updated to empty.

{
    "location": "westeurope",
    "properties": {
        "protectedParameters": [
            {
                "name": "a",
                "value": "1"
            }
        ],
        "parameters": [
            {
                "name": "b",
                "value": "1"
            }
        ],
        "timeoutInSeconds": 0,
        "asyncExecution": false,
        "treatFailureAsDeploymentFailure": true
    }
}

Expected behavior

if omit properties.source in PATCH request payload, the properties.source should be kept.

Actual behavior

if omit properties.source in PATCH request payload, send payload like below one, the properties.source is updated to empty.

{
    "location": "westeurope",
    "properties": {
        "protectedParameters": [
            {
                "name": "a",
                "value": "1"
            }
        ],
        "parameters": [
            {
                "name": "b",
                "value": "1"
            }
        ],
        "timeoutInSeconds": 0,
        "asyncExecution": false,
        "treatFailureAsDeploymentFailure": true
    }
}

Reproduction Steps

STEP 1 -- PUT https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc?api-version=2023-03-01&$expand=instanceView

x-ms-request-id: 30ae8dcc-b6d3-47fa-8190-1af1a787ebf8
x-ms-correlation-request-id: c5313ffc-2c9b-4b84-9285-ee6e3ed84646

request:

{
    "location": "westeurope",
    "properties": {
        "source": {
            "script": "echo 'hello'"
        },
        "protectedParameters": [
            {
                "name": "a",
                "value": "1"
            }
        ],
        "parameters": [
            {
                "name": "b",
                "value": "1"
            }
        ],
        "timeoutInSeconds": 0,
        "asyncExecution": false,
        "treatFailureAsDeploymentFailure": true
    }
}

STEP 2 -- GET https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc?api-version=2023-03-01&$expand=instanceView

x-ms-request-id: 576eb9e5-6dd6-4049-a882-9ed356b9e70e
x-ms-correlation-request-id: 5fb94928-3779-4f81-8e56-30a01836272b

note that protectedParameters is by design not returned.

response:

{
    "name": "example1-vmrc",
    "id": "/subscriptions/xxx/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc",
    "type": "Microsoft.Compute/virtualMachines/runCommands",
    "location": "westeurope",
    "properties": {
        "source": {
            "script": "echo 'hello'"
        },
        "parameters": [
            {
                "name": "b",
                "value": "1"
            }
        ],
        "timeoutInSeconds": 0,
        "provisioningState": "Succeeded",
        "asyncExecution": false,
        "instanceView": {
            "exitCode": 0,
            "executionState": "Succeeded",
            "executionMessage": "Execution completed",
            "output": "hello\n",
            "error": "",
            "startTime": "2024-03-08T09:22:43+00:00",
            "endTime": "2024-03-08T09:22:43+00:00"
        },
        "treatFailureAsDeploymentFailure": true
    }
}

STEP 3 -- PATCH https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc?api-version=2023-03-01&$expand=instanceView

x-ms-request-id: ddd68723-7ca8-4748-b375-ce2d79c2908f
x-ms-correlation-request-id: fbf162da-e91f-4517-851e-a123d07a6b2e

request:

{
    "location": "westeurope",
    "properties": {
        "protectedParameters": [
            {
                "name": "a",
                "value": "3"
            }
        ],
        "timeoutInSeconds": 0,
        "asyncExecution": false,
        "treatFailureAsDeploymentFailure": true
    }
}

STEP 4 -- GET https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc?api-version=2023-03-01&$expand=instanceView

x-ms-request-id: f927a894-1ee3-4e3d-a26c-716b1f7f4c1e
x-ms-correlation-request-id: 46827455-b8e7-43aa-beab-3a11f3f9d60e

we can see the source and parameters are updated to empty

response:

{
    "name": "example1-vmrc",
    "id": "/subscriptions/xxx/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc",
    "type": "Microsoft.Compute/virtualMachines/runCommands",
    "location": "westeurope",
    "properties": {
        "source": {},
        "timeoutInSeconds": 0,
        "provisioningState": "Succeeded",
        "asyncExecution": false,
        "instanceView": {
            "exitCode": -202,
            "executionState": "Failed",
            "executionMessage": "Execution failed: failed to get configuration: invalid configuration: Either 'source.script' or 'source.scriptUri' has to be specified",
            "output": "",
            "error": "",
            "startTime": "2024-03-08T09:27:49+00:00",
            "endTime": "2024-03-08T09:27:49+00:00"
        },
        "treatFailureAsDeploymentFailure": true
    }
}

Environment

No response

@teowa teowa added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Mar 8, 2024
@zzhxiaofeng
Copy link

@grizzlytheodore Please help have a look, thank you.

@zzhxiaofeng zzhxiaofeng added the Mgmt This issue is related to a management-plane library. label Mar 14, 2024
@grizzlytheodore
Copy link
Member

this needs to go to CRP
@Drewm3 could you please direct this to CRP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Mgmt This issue is related to a management-plane library.
Projects
None yet
Development

No branches or pull requests

3 participants