question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

python IMPORT_ENUM keyError on az image copy between subscriptions

See original GitHub issue

Describe the bug

I was trying to copy an image from one subscription to another subscription using az image copy. It failed while creating a snapshot after the image copy.

Command Name Actual command:

$ az image copy --source-resource-group mnv-cybermod-rg --source-object-name CYBERMOD-GNS3-2022-09-3 --target-location eastus --target-resource-group DMSNV-CYBERMOD4-RG --target-subscription b7885811-f6ab-4fb3-9984-1a66ffbf3e36 --source-type image --timeout 86400

az feedback generated command: az snapshot create

Errors: Actual command output

Getting OS disk ID of the source VM/image
Creating source snapshot
Getting sas url for the source snapshot with timeout: 86400 seconds
Target location count: 1
eastus - Creating target storage account (can be slow sometimes)
eastus - Creating container in the target storage account
eastus - Copying blob to target storage account
eastus - Copy progress: 0%
eastus - Copy progress: 1%
eastus - Copy progress: 2%
eastus - Copy progress: 3%
eastus - Copy progress: 4%
   <snip>
eastus - Copy progress: 98%
eastus - Copy progress: 99%
eastus - Copy progress: 100%
eastus - Copy time: 1:11:07.379144
eastus - Creating snapshot in target region from the copied blob
command failed: ['/usr/bin/../../opt/az/bin/python3', '-m', 'azure.cli', 'snapshot', 'create', '--resource-group', 'image-copy-rg', '--name', 'CYBERMOD-GNS3-2022-09-3_os_disk_snapshot-eastus', '--location', 'eastus', '--source', 'https://eastus3wlar7zk0qlrendwa5.blob.core.windows.net/snapshots/CYBERMOD-GNS3-2022-09-3_os_disk_snapshot.vhd', '--source-storage-account-id', '/subscriptions/b7885811-f6ab-4fb3-9984-1a66ffbf3e36/resourceGroups/image-copy-rg/providers/Microsoft.Storage/storageAccounts/eastus3wlar7zk0qlrendwa5', '--output', 'json', '--subscription', 'b7885811-f6ab-4fb3-9984-1a66ffbf3e36', '--tags', 'created_by=image-copy-extension']
output: ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: import_enum
Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/azure/core/_enum_meta.py", line 59, in __getattr__
    return cls._member_map_[name.upper()]
KeyError: 'IMPORT_ENUM'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/command_modules/vm/custom.py", line 702, in create_snapshot
    option = DiskCreateOption.import_enum
  File "/opt/az/lib/python3.10/site-packages/azure/core/_enum_meta.py", line 61, in __getattr__
    raise AttributeError(name)
AttributeError: import_enum
To open an issue, please run: 'az feedback'

The command failed with an unexpected error. Here is the traceback:
Command '['/usr/bin/../../opt/az/bin/python3', '-m', 'azure.cli', 'snapshot', 'create', '--resource-group', 'image-copy-rg', '--name', 'CYBERMOD-GNS3-2022-09-3_os_disk_snapshot-eastus', '--location', 'eastus', '--source', 'https://eastus3wlar7zk0qlrendwa5.blob.core.windows.net/snapshots/CYBERMOD-GNS3-2022-09-3_os_disk_snapshot.vhd', '--source-storage-account-id', '/subscriptions/b7885811-f6ab-4fb3-9984-1a66ffbf3e36/resourceGroups/image-copy-rg/providers/Microsoft.Storage/storageAccounts/eastus3wlar7zk0qlrendwa5', '--output', 'json', '--subscription', 'b7885811-f6ab-4fb3-9984-1a66ffbf3e36', '--tags', 'created_by=image-copy-extension']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/home/dh/.azure/cliextensions/image-copy-extension/azext_imagecopy/custom.py", line 155, in imagecopy
    create_target_image(cmd, location, transient_resource_group_name, source_type,
  File "/home/dh/.azure/cliextensions/image-copy-extension/azext_imagecopy/create_target.py", line 129, in create_target_image
    json_output = run_cli_command(cli_cmd, return_as_json=True)
  File "/home/dh/.azure/cliextensions/image-copy-extension/azext_imagecopy/cli_utils.py", line 45, in run_cli_command
    raise ex
  File "/home/dh/.azure/cliextensions/image-copy-extension/azext_imagecopy/cli_utils.py", line 21, in run_cli_command
    cmd_output = check_output(cmd, stderr=STDOUT, universal_newlines=True)
  File "/opt/az/lib/python3.10/subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/opt/az/lib/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/bin/../../opt/az/bin/python3', '-m', 'azure.cli', 'snapshot', 'create', '--resource-group', 'image-copy-rg', '--name', 'CYBERMOD-GNS3-2022-09-3_os_disk_snapshot-eastus', '--location', 'eastus', '--source', 'https://eastus3wlar7zk0qlrendwa5.blob.core.windows.net/snapshots/CYBERMOD-GNS3-2022-09-3_os_disk_snapshot.vhd', '--source-storage-account-id', '/subscriptions/b7885811-f6ab-4fb3-9984-1a66ffbf3e36/resourceGroups/image-copy-rg/providers/Microsoft.Storage/storageAccounts/eastus3wlar7zk0qlrendwa5', '--output', 'json', '--subscription', 'b7885811-f6ab-4fb3-9984-1a66ffbf3e36', '--tags', 'created_by=image-copy-extension']' returned non-zero exit status 1.
To open an issue, please run: 'az feedback'

az feedback generated:

The command failed with an unexpected error. Here is the traceback:
import_enum
Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/azure/core/_enum_meta.py", line 59, in __getattr__
    return cls._member_map_[name.upper()]
KeyError: 'IMPORT_ENUM'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)_Put any pre-requisite steps here..._
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/command_modules/vm/custom.py", line 702, in create_snapshot
    option = DiskCreateOption.import_enum
  File "/opt/az/lib/python3.10/site-packages/azure/core/_enum_meta.py", line 61, in __getattr__
    raise AttributeError(name)
AttributeError: import_enum

To Reproduce:

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

  • I had copied the original image to the current subscription, modified it (grew the disk as well), and now trying to copy it back to the original subscription.
  • $ az image copy --source-resource-group mnv-cybermod-rg --source-object-name CYBERMOD-GNS3-2022-09-3 --target-location eastus --target-resource-group DMSNV-CYBERMOD4-RG --target-subscription b7885811-f6ab-4fb3-9984-1a66ffbf3e36 --source-type image --timeout 86400

Expected Behavior

This same command worked for me when copying the other direction when I was first setting up image in the new subscription. I would expect it to work going back the other way.

Environment Summary

Linux-5.15.0-50-generic-x86_64-with-glibc2.35, Ubuntu 22.04.1 LTS
Python 3.10.5
Installer: DEB

azure-cli 2.41.0

Extensions:
image-copy-extension 0.2.8
account 0.2.1
storage-preview 0.2.10

Dependencies:
msal 1.20.0b1
azure-mgmt-resource 21.1.0b1

Additional Context

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bjbennetcommented, Oct 20, 2022

+1 to seeing the same error while running az snapshot create

0reactions
zhoxing-mscommented, Oct 26, 2022

You need to uninstall the CLI before installing the old version of CLI (or private CLI package).

Read more comments on GitHub >

github_iconTop Results From Across the Web

AZ image copy between different EA subscription ( same ...
Throws error while copying the image from one EA subscription to another subscription. Tried with same location also different location.
Read more >
Python: Getting key error in though key exist, Azure API
I'm trying to use Azure API and get resources. The response is a big JSON. { ... { "id": "/subscriptions/<subscription_name>/resourceGroups ...
Read more >
mozilla-central: changeset 557380 ...
+ + By subscribing to Tidelift you will help me (`Giampaolo Rodola`_) ... + except KeyError: + raise ValueError("invalid color %r; choose between...
Read more >
Move resources to a new subscription or resource group
To check that both subscriptions have the same tenant ID, use Azure PowerShell or Azure CLI. For Azure PowerShell, use: Azure PowerShell. Copy....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found