Merge "[Pure] Add missing FC host personality support"

This commit is contained in:
Zuul 2021-03-10 03:15:48 +00:00 committed by Gerrit Code Review
commit fa8d89bc83
3 changed files with 59 additions and 25 deletions

View File

@ -3631,6 +3631,22 @@ class PureFCDriverTestCase(PureBaseSharedDriverTestCase):
self.array.create_host],
self.driver._connect, self.array, vol_name, FC_CONNECTOR)
self.mock_config.safe_get.return_value = 'oracle-vm-server'
# Branch where we fail due to invalid version for setting personality
self.assertRaises(pure.PureDriverException, self.driver._connect,
self.array, vol_name, FC_CONNECTOR)
self.assertTrue(self.array.create_host.called)
self.assertFalse(self.array.set_host.called)
self.array.get_rest_version.return_value = '1.14'
# Branch where personality is set
self.driver._connect(self.array, vol_name, FC_CONNECTOR)
self.assertDictEqual(result, real_result)
self.array.set_host.assert_called_with(PURE_HOST_NAME,
personality='oracle-vm-server')
@mock.patch(FC_DRIVER_OBJ + "._get_host", autospec=True)
def test_connect_already_connected(self, mock_host):
vol, vol_name = self.new_fake_vol()

View File

@ -1904,6 +1904,38 @@ class PureBaseVolumeDriver(san.SanDriver):
return secondary_array.backend_id, model_updates, []
@pure_driver_debug_trace
def get_check_personality(self, array):
personality = self.configuration.safe_get('pure_host_personality')
if personality:
api_version = array.get_rest_version()
if api_version not in PERSONALITY_REQUIRED_API_VERSIONS:
# Continuing here would mean creating a host not according
# to specificiations, possibly leading to unexpected
# behavior later on.
msg = _('Unable to set host personality with Purity REST '
'API version %(api_version)s, requires '
'%(required_versions)s.') % {
'api_version': api_version,
'required_versions': PERSONALITY_REQUIRED_API_VERSIONS
}
raise PureDriverException(reason=msg)
return personality
@pure_driver_debug_trace
def set_personality(self, array, host_name, personality):
try:
array.set_host(host_name, personality=personality)
except purestorage.PureHTTPError as err:
if (err.code == 400 and
ERR_MSG_HOST_NOT_EXIST in err.text):
# If the host disappeared out from under us that's
# ok, we will just retry and snag a new host.
LOG.debug('Unable to set host personality: %s',
err.text)
raise PureRetryableException()
return
def _swap_replication_state(self, current_array, secondary_array,
failback=False):
# After failover we want our current array to be swapped for the
@ -2539,21 +2571,7 @@ class PureISCSIDriver(PureBaseVolumeDriver, san.SanISCSIDriver):
reason=_("Unable to re-use host with unknown CHAP "
"credentials configured."))
else:
personality = self.configuration.safe_get('pure_host_personality')
if personality:
api_version = array.get_rest_version()
if api_version not in PERSONALITY_REQUIRED_API_VERSIONS:
# Continuing here would mean creating a host not according
# to specificiations, possibly leading to unexpected
# behavior later on.
msg = _('Unable to set host personality with Purity REST '
'API version %(api_version)s, requires '
'%(required_versions)s.') % {
'api_version': api_version,
'required_versions': PERSONALITY_REQUIRED_API_VERSIONS
}
raise PureDriverException(reason=msg)
personality = self.get_check_personality(array)
host_name = self._generate_purity_host_name(connector["host"])
LOG.info("Creating host object %(host_name)r with IQN:"
" %(iqn)s.", {"host_name": host_name, "iqn": iqn})
@ -2569,16 +2587,7 @@ class PureISCSIDriver(PureBaseVolumeDriver, san.SanISCSIDriver):
raise PureRetryableException()
if personality:
try:
array.set_host(host_name, personality=personality)
except purestorage.PureHTTPError as err:
if (err.code == 400 and
ERR_MSG_HOST_NOT_EXIST in err.text):
# If the host disappeared out from under us that's
# ok, we will just retry and snag a new host.
LOG.debug('Unable to set host personality: %s',
err.text)
raise PureRetryableException()
self.set_personality(array, host_name, personality)
if self.configuration.use_chap_auth:
try:
@ -2694,6 +2703,7 @@ class PureFCDriver(PureBaseVolumeDriver, driver.FibreChannelDriver):
LOG.info("Re-using existing purity host %(host_name)r",
{"host_name": host_name})
else:
personality = self.get_check_personality(array)
host_name = self._generate_purity_host_name(connector["host"])
LOG.info("Creating host object %(host_name)r with WWN:"
" %(wwn)s.", {"host_name": host_name, "wwn": wwns})
@ -2708,6 +2718,9 @@ class PureFCDriver(PureBaseVolumeDriver, driver.FibreChannelDriver):
LOG.debug('Unable to create host: %s', err.text)
raise PureRetryableException()
if personality:
self.set_personality(array, host_name, personality)
# TODO(patrickeast): Ensure that the host has the correct preferred
# arrays configured for it.

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Pure Storage driver: Add missing support for ``host_personality`` setting
for FC-based hosts