From edb4e17131b66f63fbacecea68de95ffabf60dae Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Thu, 19 Oct 2017 15:30:50 +0300 Subject: [PATCH] Add SAN policy setter/getter This change adds a setter and getter for the SAN policy, controlling the way in which new disks will be handled (brought online or not). Validating this policy will help prevent common vm disk attachment issues when dealing with passthrough disks. Related-Bug: #1727257 Change-Id: I25033c15b77f494a417c9cd01d194a8bfb3cfe13 --- os_win/constants.py | 6 ++++++ os_win/tests/unit/utils/storage/test_diskutils.py | 15 +++++++++++++++ os_win/utils/storage/diskutils.py | 15 +++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/os_win/constants.py b/os_win/constants.py index c45ac66c..ae10aec2 100644 --- a/os_win/constants.py +++ b/os_win/constants.py @@ -233,3 +233,9 @@ SUPPORTED_SCSI_UID_FORMATS = [ SCSI_UID_VENDOR_ID, SCSI_UID_VENDOR_SPECIFIC ] + +DISK_POLICY_UNKNOWN = 0 +DISK_POLICY_ONLINE_ALL = 1 +DISK_POLICY_OFFLINE_SHARED = 2 +DISK_POLICY_OFFLINE_ALL = 3 +DISK_POLICY_OFFLINE_INTERNAL = 4 diff --git a/os_win/tests/unit/utils/storage/test_diskutils.py b/os_win/tests/unit/utils/storage/test_diskutils.py index 499a168c..b72424be 100644 --- a/os_win/tests/unit/utils/storage/test_diskutils.py +++ b/os_win/tests/unit/utils/storage/test_diskutils.py @@ -369,3 +369,18 @@ class DiskUtilsTestCase(test_base.OsWinBaseTestCase): result = self._diskutils._select_supported_scsi_identifiers( identifiers) self.assertEqual(expected_identifiers, result) + + def test_get_new_disk_policy(self): + mock_setting_obj = mock.Mock() + setting_cls = self._diskutils._conn_storage.MSFT_StorageSetting + setting_cls.Get.return_value = (0, mock_setting_obj) + + policy = self._diskutils.get_new_disk_policy() + self.assertEqual(mock_setting_obj.NewDiskPolicy, policy) + + def test_set_new_disk_policy(self): + self._diskutils.set_new_disk_policy(mock.sentinel.policy) + + setting_cls = self._diskutils._conn_storage.MSFT_StorageSetting + setting_cls.Set.assert_called_once_with( + NewDiskPolicy=mock.sentinel.policy) diff --git a/os_win/utils/storage/diskutils.py b/os_win/utils/storage/diskutils.py index c4d25b56..e5c6d3c4 100644 --- a/os_win/utils/storage/diskutils.py +++ b/os_win/utils/storage/diskutils.py @@ -301,3 +301,18 @@ class DiskUtils(baseutils.BaseUtils): selected_identifiers.append(identifier) return selected_identifiers + + def get_new_disk_policy(self): + # This policy is also known as the 'SAN policy', describing + # how new disks will be handled. + storsetting = self._conn_storage.MSFT_StorageSetting.Get()[1] + return storsetting.NewDiskPolicy + + def set_new_disk_policy(self, policy): + """Sets the new disk policy, also known as SAN policy. + + :param policy: an integer value, one of the DISK_POLICY_* + values defined in os_win.constants. + """ + self._conn_storage.MSFT_StorageSetting.Set( + NewDiskPolicy=policy)