-
Notifications
You must be signed in to change notification settings - Fork 1.6k
vm-repair: select a compatible repair VM disk controller #10305
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
Merged
Julie Zhu (yanzhudd)
merged 4 commits into
Azure:main
from
EdwinBernal1:edwin/vmrepair-disk-controller-type
Sep 7, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/vm-repair/azext_vm_repair/tests/latest/test_disk_controller_type.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| # pylint: disable=protected-access | ||
| import unittest | ||
| from unittest import mock | ||
|
|
||
| from knack.util import CLIError | ||
|
|
||
| from azext_vm_repair._validators import validate_create | ||
| from azext_vm_repair.repair_utils import ( | ||
| _fetch_sku_disk_controller_types, | ||
| _fetch_source_disk_controller_type, | ||
| _select_repair_disk_controller_type, | ||
| ) | ||
|
|
||
|
|
||
| class SelectRepairDiskControllerTypeTest(unittest.TestCase): | ||
|
|
||
| def test_scsi_source_no_flag(self): | ||
| controller, level, _ = _select_repair_disk_controller_type('SCSI', ['SCSI', 'NVMe']) | ||
| self.assertIsNone(controller) | ||
| self.assertEqual('debug', level) | ||
|
|
||
| def test_nvme_source_pins_scsi(self): | ||
| controller, level, message = _select_repair_disk_controller_type('NVMe', ['SCSI', 'NVMe']) | ||
| self.assertEqual('SCSI', controller) | ||
| self.assertEqual('info', level) | ||
| self.assertIn('enumerate', message) | ||
|
|
||
| def test_nvme_only_size_warns(self): | ||
| controller, level, message = _select_repair_disk_controller_type('NVMe', ['NVMe']) | ||
| self.assertIsNone(controller) | ||
| self.assertEqual('warning', level) | ||
| self.assertIn('only supports NVMe', message) | ||
|
|
||
| def test_explicit_override_wins(self): | ||
| controller, level, _ = _select_repair_disk_controller_type('SCSI', ['SCSI', 'NVMe'], 'NVMe') | ||
| self.assertEqual('NVMe', controller) | ||
| self.assertEqual('info', level) | ||
|
|
||
| def test_unknown_capability_no_flag(self): | ||
| controller, level, _ = _select_repair_disk_controller_type('NVMe', []) | ||
| self.assertIsNone(controller) | ||
| self.assertEqual('debug', level) | ||
|
|
||
|
|
||
| class FetchDiskControllerTypeTest(unittest.TestCase): | ||
|
|
||
| def test_source_controller_uses_sdk_value(self): | ||
| source_vm = mock.MagicMock() | ||
| source_vm.storage_profile.disk_controller_type = 'NVMe' | ||
| self.assertEqual('NVMe', _fetch_source_disk_controller_type(source_vm)) | ||
|
|
||
| def test_source_controller_uses_sdk_enum_value(self): | ||
| controller = mock.MagicMock(value='NVMe') | ||
| controller.__str__.return_value = 'DiskControllerTypes.NVME' | ||
| source_vm = mock.MagicMock() | ||
| source_vm.storage_profile.disk_controller_type = controller | ||
| self.assertEqual('NVMe', _fetch_source_disk_controller_type(source_vm)) | ||
|
|
||
| @mock.patch('azext_vm_repair.repair_utils._call_az_command', return_value='SCSI\n') | ||
| def test_source_controller_falls_back_to_cli(self, mock_call): | ||
| source_vm = mock.MagicMock() | ||
| source_vm.storage_profile = mock.MagicMock(spec=[]) | ||
| source_vm.id = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm' | ||
| self.assertEqual('SCSI', _fetch_source_disk_controller_type(source_vm)) | ||
| self.assertIn('storageProfile.diskControllerType', mock_call.call_args[0][0]) | ||
|
|
||
| @mock.patch('azext_vm_repair.repair_utils._call_az_command', return_value='NVMe\n') | ||
| def test_missing_storage_profile_falls_back_to_cli(self, mock_call): | ||
| source_vm = mock.MagicMock(spec=['id']) | ||
| source_vm.id = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm' | ||
| self.assertEqual('NVMe', _fetch_source_disk_controller_type(source_vm)) | ||
| mock_call.assert_called_once() | ||
|
|
||
| @mock.patch('azext_vm_repair.repair_utils._call_az_command') | ||
| def test_missing_vm_id_returns_none(self, mock_call): | ||
| source_vm = mock.MagicMock(spec=[]) | ||
| self.assertIsNone(_fetch_source_disk_controller_type(source_vm)) | ||
| mock_call.assert_not_called() | ||
|
|
||
| @mock.patch('azext_vm_repair.repair_utils._call_az_command', return_value='SCSI,NVMe\n') | ||
| def test_sku_capabilities_are_parsed(self, _): | ||
| self.assertEqual(['SCSI', 'NVMe'], _fetch_sku_disk_controller_types('Standard_E2bds_v5', 'westus2')) | ||
|
|
||
|
|
||
| class ValidateDiskControllerTypeTest(unittest.TestCase): | ||
|
|
||
| def _validate(self, value): | ||
| namespace = mock.MagicMock() | ||
| namespace.disk_controller_type = value | ||
| with mock.patch('azext_vm_repair._validators.check_extension_version', side_effect=RuntimeError): | ||
| with self.assertRaises(RuntimeError): | ||
| validate_create(mock.MagicMock(), namespace) | ||
| return namespace.disk_controller_type | ||
|
|
||
| def test_scsi_is_normalized(self): | ||
| self.assertEqual('SCSI', self._validate(' scsi ')) | ||
|
|
||
| def test_nvme_is_normalized(self): | ||
| self.assertEqual('NVMe', self._validate('nvme')) | ||
|
|
||
| def test_invalid_value_is_rejected_before_network_call(self): | ||
| namespace = mock.MagicMock(disk_controller_type='SCSI; rm -rf') | ||
| with mock.patch('azext_vm_repair._validators.check_extension_version') as mock_version: | ||
| with self.assertRaises(CLIError): | ||
| validate_create(mock.MagicMock(), namespace) | ||
| mock_version.assert_not_called() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.