Repository: Azure/azure-cli-extensions

Issue:
az image copy failed with error
### **This is autogenerated. Please review and update as needed.**

## Describe the bug

**Command Name**
`az image copy
Extension Name: image-copy-extension. Version: 0.2.9.`

**Errors:**
```
The command failed with an unexpected error. Here is the traceback:
expected str, bytes or os.PathLike object, not NoneType
Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 231, 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 "/root/.azure/cliextensions/image-copy-extension/azext_imagecopy/custom.py", line 108, in imagecopy
    run_cli_command(cli_cmd)
  File "/root/.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 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/opt/az/lib/python3.10/subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/az/lib/python3.10/subprocess.py", line 1778, in _execute_child
    self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not NoneType

```

## 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 image copy --source-resource-group {} --source-object-name {} --target-location {} --target-resource-group {} --source-type {}`

## Expected Behavior

## Environment Summary
```
Linux-5.13.0-30-generic-x86_64-with-glibc2.31, Ubuntu 20.04.4 LTS
Python 3.10.5
Installer: DEB

azure-cli 2.39.0

Extensions:
image-copy-extension 0.2.9

Dependencies:
msal 1.18.0b1
azure-mgmt-resource 21.1.0b1
```
## Additional Context

<!--Please don't remove this:-->
<!--auto-generated-->




Discussion:
@zhoxing-ms for awareness
@vinaykumar-rm Could you please send me the debug log *(Add `--debug` parameter)* by email? My email address is Zhou.Xing@microsoft.com, thanks~

Resolving patch:
diff --git a/src/image-copy/azext_imagecopy/create_target.py b/src/image-copy/azext_imagecopy/create_target.py
--- a/src/image-copy/azext_imagecopy/create_target.py
+++ b/src/image-copy/azext_imagecopy/create_target.py
@@ -118,14 +118,14 @@ def create_target_image(cmd, location, transient_resource_group_name, source_typ
                                                                       transient_resource_group_name,
                                                                       target_subscription)
 
-    cli_cmd = prepare_cli_command(['snapshot', 'create',
-                                   '--resource-group', snapshot_resource_group_name,
-                                   '--name', target_snapshot_name,
-                                   '--location', location,
-                                   '--source', target_blob_path,
-                                   '--source-storage-account-id', source_storage_account_id,
-                                   '--hyper-v-generation', hyper_v_generation],
-                                  subscription=target_subscription)
+    cmd_content = ['snapshot', 'create',
+                   '--resource-group', snapshot_resource_group_name,
+                   '--name', target_snapshot_name,
+                   '--location', location,
+                   '--source', target_blob_path,
+                   '--source-storage-account-id', source_storage_account_id,
+                   '--hyper-v-generation', hyper_v_generation]
+    cli_cmd = prepare_cli_command(cmd_content, subscription=target_subscription)
 
     json_output = run_cli_command(cli_cmd, return_as_json=True)
     target_snapshot_id = json_output['id']
@@ -143,13 +143,14 @@ def create_target_image(cmd, location, transient_resource_group_name, source_typ
         else:
             target_image_name = target_name
 
-        cli_cmd = prepare_cli_command(['image', 'create',
-                                       '--resource-group', target_resource_group_name,
-                                       '--name', target_image_name,
-                                       '--location', location,
-                                       '--os-type', source_os_type,
-                                       '--source', target_snapshot_id,
-                                       '--hyper-v-generation', hyper_v_generation],
+        cmd_content = ['image', 'create',
+                       '--resource-group', target_resource_group_name,
+                       '--name', target_image_name,
+                       '--location', location,
+                       '--os-type', source_os_type,
+                       '--source', target_snapshot_id,
+                       '--hyper-v-generation', hyper_v_generation]
+        cli_cmd = prepare_cli_command(cmd_content,
                                       tags=tags,
                                       subscription=target_subscription)
 
diff --git a/src/image-copy/azext_imagecopy/custom.py b/src/image-copy/azext_imagecopy/custom.py
--- a/src/image-copy/azext_imagecopy/custom.py
+++ b/src/image-copy/azext_imagecopy/custom.py
@@ -90,21 +90,21 @@ def imagecopy(cmd, source_resource_group_name, source_object_name, target_locati
         source_storage_account_id = get_storage_account_id_from_blob_path(cmd,
                                                                           source_os_disk_id,
                                                                           source_resource_group_name)
-        cli_cmd = prepare_cli_command(['snapshot', 'create',
-                                       '--name', source_os_disk_snapshot_name,
-                                       '--location', snapshot_location,
-                                       '--resource-group', source_resource_group_name,
-                                       '--source', source_os_disk_id,
-                                       '--source-storage-account-id', source_storage_account_id,
-                                       '--hyper-v-generation', hyper_v_generation])
+        cmd_content = ['snapshot', 'create',
+                       '--name', source_os_disk_snapshot_name,
+                       '--location', snapshot_location,
+                       '--resource-group', source_resource_group_name,
+                       '--source', source_os_disk_id,
+                       '--source-storage-account-id', source_storage_account_id]
     else:
-        cli_cmd = prepare_cli_command(['snapshot', 'create',
-                                       '--name', source_os_disk_snapshot_name,
-                                       '--location', snapshot_location,
-                                       '--resource-group', source_resource_group_name,
-                                       '--source', source_os_disk_id,
-                                       '--hyper-v-generation', hyper_v_generation])
-
+        cmd_content = ['snapshot', 'create',
+                       '--name', source_os_disk_snapshot_name,
+                       '--location', snapshot_location,
+                       '--resource-group', source_resource_group_name,
+                       '--source', source_os_disk_id]
+    if hyper_v_generation:
+        cmd_content = cmd_content + ['--hyper-v-generation', hyper_v_generation]
+    cli_cmd = prepare_cli_command(cmd_content)
     run_cli_command(cli_cmd)
 
     # Get SAS URL for the snapshotName
@@ -169,11 +169,13 @@ def imagecopy(cmd, source_resource_group_name, source_object_name, target_locati
             tasks = []
             for location in target_location:
                 location = location.strip()
-                tasks.append((location, transient_resource_group_name, source_type,
-                              source_object_name, source_os_disk_snapshot_name, source_os_disk_snapshot_url,
-                              source_os_type, target_resource_group_name, azure_pool_frequency,
-                              tags, target_name, target_subscription, export_as_snapshot, timeout,
-                              hyper_v_generation))
+                task_content = (location, transient_resource_group_name, source_type,
+                                source_object_name, source_os_disk_snapshot_name, source_os_disk_snapshot_url,
+                                source_os_type, target_resource_group_name, azure_pool_frequency,
+                                tags, target_name, target_subscription, export_as_snapshot, timeout)
+                if hyper_v_generation:
+                    task_content = task_content + tuple(hyper_v_generation)
+                tasks.append(task_content)
 
             logger.warning("Starting async process for all locations")
 
diff --git a/src/image-copy/setup.py b/src/image-copy/setup.py
--- a/src/image-copy/setup.py
+++ b/src/image-copy/setup.py
@@ -8,7 +8,7 @@
 from codecs import open
 from setuptools import setup, find_packages
 
-VERSION = "0.2.9"
+VERSION = "0.2.10"
 
 CLASSIFIERS = [
     'Development Status :: 4 - Beta',


Test patch: