diff --git a/src/command_modules/azure-cli-profile/HISTORY.rst b/src/command_modules/azure-cli-profile/HISTORY.rst index 74629443968..3bc53b5383e 100644 --- a/src/command_modules/azure-cli-profile/HISTORY.rst +++ b/src/command_modules/azure-cli-profile/HISTORY.rst @@ -4,6 +4,7 @@ Release History =============== 2.0.24 ++++++ +* `disk create`: fix a bug that source detection is not accurate * BREAKING CHANGE: remove --msi-port/--identity-port as they are no longer used 2.0.23 diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_validators.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_validators.py index d3fe6f35739..a3b179b98d1 100644 --- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_validators.py +++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_validators.py @@ -1145,10 +1145,15 @@ def process_image_create_namespace(cmd, namespace): def _figure_out_storage_source(cli_ctx, resource_group_name, source): from msrestazure.azure_exceptions import CloudError + try: + from urllib.parse import urlparse + except ImportError: + from urlparse import urlparse # pylint: disable=import-error + source_blob_uri = None source_disk = None source_snapshot = None - if source.lower().endswith('.vhd'): + if urlparse(source).scheme: # an exiting scheme means a blob uri, as ':' isn't allowed in a disk name source_blob_uri = source elif '/disks/' in source.lower(): source_disk = source diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/latest/test_vm_actions.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/latest/test_vm_actions.py index a7da479cf28..3a5230f9e83 100644 --- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/latest/test_vm_actions.py +++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/latest/test_vm_actions.py @@ -75,6 +75,12 @@ def test_figure_out_storage_source(self): self.assertFalse(src_snapshot) self.assertEqual(src_blob_uri, test_data) + test_data = '/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/JAVACSMRG6017/providers/Microsoft.Compute/disks/ex.vhd' + src_blob_uri, src_disk, src_snapshot = _figure_out_storage_source(TestCli(), 'tg1', test_data) + self.assertEqual(src_disk, test_data) + self.assertFalse(src_snapshot) + self.assertFalse(src_blob_uri) + def test_source_storage_account_err_case(self): np = mock.MagicMock() cmd = mock.MagicMock()