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
This commit is contained in:
Lucian Petrut 2017-10-19 15:30:50 +03:00
parent 8eea07d9dc
commit edb4e17131
3 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)