azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

az lab vm apply-artifacts error read artifact.json

Open EwertonJordao opened this issue 6 years ago • 11 comments

This is autogenerated. Please review and update as needed.

Describe the bug

When i try to apply an artifact on my vm the exception occour. Command Name az lab vm apply-artifacts

Errors:

Unable to build a model: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'>, DeserializationError: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'>
Traceback (most recent call last):
pip-install-z6h9b3s8\msrest\msrest\serialization.py, ln 578, in body
pip-install-z6h9b3s8\msrest\msrest\serialization.py, ln 1324, in _deserialize
pip-install-z6h9b3s8\msrest\msrest\serialization.py, ln 1333, in _deserialize
...
msrest.exceptions.SerializationError: Unable to build a model: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'>, DeserializationError: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'>

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here... az lab artifact list --artifact-source-name $artifactRepo.name --resource-group $resourceEnv.resourceGroup --lab-name $devtestName --query "[?name=='windows-chocolatey']"

the output is my artifact.json

and i try to run this : az lab vm apply-artifacts --artifacts "@artifacts.json" --lab-name $devtestName --name VMlab01 --resource-group $resourceEnv.resourceGroup

The file is in current folder and is a valid json file

Expected Behavior

Environment Summary

Windows-10-10.0.18362-SP0
Python 3.6.6
Installer: MSI

azure-cli 2.4.0 *

Additional Context

EwertonJordao avatar Apr 30 '20 04:04 EwertonJordao

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Tanmayeekamath.

ghost avatar Apr 30 '20 06:04 ghost

lab

yonzhan avatar Apr 30 '20 06:04 yonzhan

Hello @EwertonJordao, Thanks for reaching out. We are investigating this on our end. Will get back to you once I have an update.

Tanmayee

tanmayeekamath avatar Apr 30 '20 15:04 tanmayeekamath

@EwertonJordao, the query you are doing is to fetch the artifact definition. It is not good to generate an artifacts.json file content.

Here's a sample artifacts.json file content to install Google Chrome using the windows-chocolatey artifact from the Public Repo.

UPDATE: Added missing double quotes for boolean values.

[
  {
    "artifactId": "/artifactSources/public repo/artifacts/windows-chocolatey",
    "parameters": [
      {
        "name": "packages",
        "value": "googlechrome"
      },
      {
        "name": "allowEmptyChecksums",
        "value": "true"
      },
      {
        "name": "ignoreChecksums",
        "value": "false"
      }
    ]
  }
]

leovms avatar Apr 30 '20 16:04 leovms

OK i try to use the same structure in this repo, the first moment I try to use without changes on artificacts.json , i recieve this mesage :

expected a artifactId

list index out of range Traceback (most recent call last): File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\knack\knack\cli.py", line 215, in invoke File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init_.py", line 631, in execute File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init_.py", line 695, in run_jobs_serially File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init.py", line 688, in run_job File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\six\six.py", line 703, in reraise File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init.py", line 665, in run_job File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init.py", line 324, in call File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core_init_.py", line 574, in default_command_handler File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli\azure\cli\command_modules\feedback\custom.py", line 758, in handle_feedback File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli\azure\cli\command_modules\feedback\custom.py", line 740, in _prompt_issue File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli\azure\cli\command_modules\feedback\custom.py", line 528, in _build_issue_info_tup File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli\azure\cli\command_modules\feedback\custom.py", line 590, in _get_minified_issue_url
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli\azure\cli\command_modules\feedback\custom.py", line 366, in set_capacity File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli\azure\cli\command_modules\feedback\custom.py", line 404, in _get_minified_errors File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli\azure\cli\command_modules\feedback\custom.py", line 467, in _minify_by_removing_lines
IndexError: list index out of range

when I change the json file, adding a property artifactId and recover that with this value with this code:

$artifactRepo = (az lab artifact-source show --lab-name $devtestName `
                            --name "Public Repo"`
                            --resource-group $resourceEnv.resourceGroup | convertfrom-json -Depth 5)
$choco = (az lab artifact list --artifact-source-name $artifactRepo.name  --resource-group $resourceEnv.resourceGroup --lab-name $devtestName --query "[?name=='windows-chocolatey']" | ConvertFrom-Json -Depth 6)

execute the cli command: az lab vm apply-artifacts --artifacts '@artifactsChoco.json' --lab-name $labVM.labname --name $labVM.vmName --resource-group $resourceEnv.resourceGroup

Command group 'lab' is in preview. It may be changed/removed in a future release. The command failed with an unexpected error. Here is the traceback:

Unable to build a model: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'>, DeserializationError: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'> Traceback (most recent call last): File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 578, in body File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1324, in _deserialize File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1333, in _deserialize File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1516, in deserialize_data File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1547, in deserialize_iter File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1547, in File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1529, in deserialize_data File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1360, in _deserialize File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1516, in deserialize_data File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1545, in deserialize_iter msrest.exceptions.DeserializationError: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\knack\knack\cli.py", line 215, in invoke File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init_.py", line 631, in execute File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init_.py", line 695, in run_jobs_serially File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init.py", line 688, in run_job File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\six\six.py", line 703, in reraise File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init.py", line 665, in run_job File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core\commands_init.py", line 324, in call File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-cli-core\azure\cli\core_init_.py", line 574, in default_command_handler File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-mgmt-devtestlabs\azure\mgmt\devtestlabs\operations\virtual_machines_operations.py", line 686, in apply_artifacts File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\azure-mgmt-devtestlabs\azure\mgmt\devtestlabs\operations\virtual_machines_operations.py", line 640, in _apply_artifacts_initial File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 581, in body File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\exceptions.py", line 51, in raise_with_traceback File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 578, in body File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1324, in _deserialize File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1333, in _deserialize File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1516, in deserialize_data File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1547, in deserialize_iter File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1547, in File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1529, in deserialize_data File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1360, in _deserialize File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1516, in deserialize_data File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-z6h9b3s8\msrest\msrest\serialization.py", line 1545, in deserialize_iter msrest.exceptions.SerializationError: Unable to build a model: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'>, DeserializationError: Cannot deserialize as [ArtifactParameterProperties] an object of type <class 'dict'>

I use this artifacts.json

{
  "$schema": "https://raw.githubusercontent.com/Azure/azure-devtestlab/master/schemas/2016-11-28/dtlArtifacts.json",
  "title": "Install Chocolatey Packages",
  "publisher": "Microsoft",
  "artifactId":"",
  "description": "Installs the Chocolatey package manager along with a user selected set of packages",
  "tags": [
      "Windows",
      "Chocolatey"
  ],
  "iconUri": "https://github.com/chocolatey/choco/raw/master/docs/logo/chocolateyicon.gif",
  "targetOsType": "Windows",
  "parameters": {
      "packages": {
          "type": "string",
          "displayName": "Packages",
          "description": "Space-, comma- or semicolon-delimited list of package names to be installed, for example: 7Zip,Fiddler4. A complete list of public packages can be found at https://chocolatey.org/packages."
      },
      "allowEmptyChecksums": {
          "type": "bool",
          "defaultValue": true,
          "displayName": "Allow Empty Checksums",
          "description": "Should packages with empty checksums be allowed to be installed? This defaults to true to avoid breaking the behavior of past versions of this artifact and to ease the use of non https sources such as http/ftp, but allowing empty checksums is not recommended by chocolatey (see https://chocolatey.org/docs/commandsupgrade)"
      },
      "ignoreChecksums": {
          "type": "bool",
          "defaultValue": false,
          "displayName": "Ignore Checksums",
          "description": "Should packages that don't match their checksums be allowed to be installed? Setting this to true is not recommended by chocolatey (see https://github.com/chocolatey/choco/issues/112), but may be necessary if you have a dependency on a community maintained package that does not update its checksum to match a software provider's upgrade in a timely manner."
      }
  },
  "runCommand": {
      "commandToExecute": "[concat('powershell.exe -ExecutionPolicy bypass \"& ./install-choco-package.ps1 -Packages ''', parameters('packages'), ''' -AllowEmptyChecksums $', parameters('allowEmptyChecksums'), ' -IgnoreChecksums $', parameters('ignoreChecksums'), '\"')]"
  }
}
]```

EwertonJordao avatar Apr 30 '20 22:04 EwertonJordao

@EwertonJordao, the JSON in your last post is the artifact definition, (i.e. artifactfile.json). This is NOT the format for the payload when requesting to apply the artifact.

The original artifacts.json file contents example I put in my first response is the correct format. But I did find an error. We need to make sure to put double quotes around the values, which I missed. I'll go back and correct the original for others.

You put that content in a file and save it in the same folder from where you execute the command. You can call it artifacts.json. Here's the corrected sample again for clarity.

[
  {
    "artifactId": "/artifactSources/public repo/artifacts/windows-chocolatey",
    "parameters": [
      {
        "name": "packages",
        "value": "googlechrome"
      },
      {
        "name": "allowEmptyChecksums",
        "value": "true"
      },
      {
        "name": "ignoreChecksums",
        "value": "false"
      }
    ]
  }
]

And you execute the command like so, making sure to use double quotes for the --artifacts value. For example, "@artifacts.json".

az lab vm apply-artifacts --artifacts "@artifacts.json" --lab-name "MyLabName" --name "MyLabVMName" --resource-group "MyLabRgName"

leovms avatar May 01 '20 15:05 leovms

I'm sorry my mistake, I use this artifacts.json:

[
    {
      "artifactId": "/artifactSources/public repo/artifacts/windows-chocolatey",
      "parameters": [
        {
          "name": "packages",
          "value": "zip.install,python,vscode,microsoft-edge,powershell-preview"
        },
        {
          "name": "allowEmptyChecksums",
          "value": true
        },
        {
          "name": "ignoreChecksums",
          "value": false
        }
      ]
    }
  ]

and recieve this error: Az cli on my: Deployment failed. Correlation ID: ede388bd-af7a-4258-8a04-da9a477ef699. InternalServerError has occurred with ClientRequestId [ebf386c8-8bd1-11ea-826f-105badfb4d58] Az cli on azure: Deployment failed. Correlation ID: 115df635-9239-4c33-82a8-8a6945519115. InternalServerError has occurred with ClientRequestId [f2b2eb2e-8bd2-11ea-a40f-0a580af47f1a]

In Azure, I try many times and for two times my command work and i saw this: image

The artifacts won't apply in vmlab, but when I deploy from azure portal it works.

Thanks for your attention

EwertonJordao avatar May 01 '20 17:05 EwertonJordao

As I indicated in my response, you are missing double quotes in the boolean values true and false. Change that and it should work. Look at the artifacts.json sample again and you will see it is corrected.

leovms avatar May 01 '20 17:05 leovms

@leovms thanks you.

I forgot the double quotes, who can I suggest implement feedback on artifact results? image Because of status pending in return is insufficient to find what is wrong in the call, not clean about what's happening, no have any log and when I consult log monitor of my subscription, I saw accept the request, but no have returned about the error.

Thanks.

EwertonJordao avatar May 01 '20 18:05 EwertonJordao

We already have a bug in our backlog to fix that. The error you happen to run into is because of JSON parsing (i.e. the missing quotes). If you look at the Activity Logs you can find it, but you have to dig a bit. However, I agree that it is definitely best to bubble up a better message, as that error simply indicates it is unhandled.

leovms avatar May 01 '20 18:05 leovms

Tks for all

EwertonJordao avatar May 25 '20 13:05 EwertonJordao