Specify a user-agent in Pure volume drivers
Previously we were just using the default user-agent that the python requests module would send. With newer versions of the pure storage python module you can now specify a custom one. This will help to identify on the backend what requests are being sent by the VolumeDriver vs other python scripts running against the same array. As part of this we will also remove support for the older version of the python module. The newer versions are released and easily upgraded to. Change-Id: Icf8595843e38381c6704fd6a9c66b752f91337a5 Closes-Bug: #1579194
This commit is contained in:
parent
8c3abfdfb0
commit
925ee611d5
@ -382,6 +382,16 @@ class PureDriverTestCase(test.TestCase):
|
||||
func, *args, **kwargs)
|
||||
mock_func.side_effect = original_side_effect
|
||||
|
||||
@mock.patch('platform.platform')
|
||||
def test_for_user_agent(self, mock_platform):
|
||||
mock_platform.return_value = 'MyFavoritePlatform'
|
||||
driver = pure.PureBaseVolumeDriver(configuration=self.mock_config)
|
||||
expected_agent = "OpenStack Cinder %s/%s (MyFavoritePlatform)" % (
|
||||
driver.__class__.__name__,
|
||||
driver.VERSION
|
||||
)
|
||||
self.assertEqual(expected_agent, driver._user_agent)
|
||||
|
||||
|
||||
class PureBaseSharedDriverTestCase(PureDriverTestCase):
|
||||
def setUp(self):
|
||||
@ -1888,14 +1898,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
|
||||
remvollist=[VOLUME_PURITY_NAME]
|
||||
)
|
||||
|
||||
@ddt.data(
|
||||
dict(version='1.5.0'),
|
||||
dict(version='2.0.0'),
|
||||
dict(version='1.4.1'),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_get_flasharray_verify_https(self, version):
|
||||
self.purestorage_module.VERSION = version
|
||||
def test_get_flasharray_verify_https(self):
|
||||
san_ip = '1.2.3.4'
|
||||
api_token = 'abcdef'
|
||||
cert_path = '/my/ssl/certs'
|
||||
@ -1910,38 +1913,8 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
|
||||
api_token=api_token,
|
||||
rest_version=None,
|
||||
verify_https=True,
|
||||
ssl_cert=cert_path
|
||||
)
|
||||
|
||||
def test_get_flasharray_dont_verify_https_version_too_old(self):
|
||||
self.purestorage_module.VERSION = '1.4.0'
|
||||
san_ip = '1.2.3.4'
|
||||
api_token = 'abcdef'
|
||||
self.purestorage_module.FlashArray.return_value = mock.MagicMock()
|
||||
|
||||
self.driver._get_flasharray(san_ip,
|
||||
api_token,
|
||||
verify_https=False,
|
||||
ssl_cert_path=None)
|
||||
self.purestorage_module.FlashArray.assert_called_with(
|
||||
san_ip,
|
||||
api_token=api_token,
|
||||
rest_version=None
|
||||
)
|
||||
|
||||
def test_get_flasharray_verify_https_version_too_old(self):
|
||||
self.purestorage_module.VERSION = '1.4.0'
|
||||
san_ip = '1.2.3.4'
|
||||
api_token = 'abcdef'
|
||||
self.purestorage_module.FlashArray.return_value = mock.MagicMock()
|
||||
|
||||
self.assertRaises(
|
||||
exception.PureDriverException,
|
||||
self.driver._get_flasharray,
|
||||
san_ip,
|
||||
api_token,
|
||||
verify_https=True,
|
||||
ssl_cert_path='/my/ssl/certs'
|
||||
ssl_cert=cert_path,
|
||||
user_agent=self.driver._user_agent,
|
||||
)
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@ This driver requires Purity version 4.0.0 or later.
|
||||
"""
|
||||
|
||||
import math
|
||||
import platform
|
||||
import re
|
||||
import uuid
|
||||
|
||||
@ -102,7 +103,6 @@ EXTRA_SPECS_REPL_ENABLED = "replication_enabled"
|
||||
|
||||
CONNECT_LOCK_NAME = 'PureVolumeDriver_connect'
|
||||
|
||||
|
||||
UNMANAGED_SUFFIX = '-unmanaged'
|
||||
MANAGE_SNAP_REQUIRED_API_VERSIONS = ['1.4', '1.5']
|
||||
REPLICATION_REQUIRED_API_VERSIONS = ['1.3', '1.4', '1.5']
|
||||
@ -110,6 +110,8 @@ REPLICATION_REQUIRED_API_VERSIONS = ['1.3', '1.4', '1.5']
|
||||
REPL_SETTINGS_PROPAGATE_RETRY_INTERVAL = 5 # 5 seconds
|
||||
REPL_SETTINGS_PROPAGATE_MAX_RETRIES = 36 # 36 * 5 = 180 seconds
|
||||
|
||||
USER_AGENT_BASE = 'OpenStack Cinder'
|
||||
|
||||
|
||||
def pure_driver_debug_trace(f):
|
||||
"""Log the method entrance and exit including active backend name.
|
||||
@ -156,6 +158,12 @@ class PureBaseVolumeDriver(san.SanDriver):
|
||||
self._is_replication_enabled = False
|
||||
self._active_backend_id = kwargs.get('active_backend_id', None)
|
||||
self._failed_over_primary_array = None
|
||||
self._user_agent = '%(base)s %(class)s/%(version)s (%(platform)s)' % {
|
||||
'base': USER_AGENT_BASE,
|
||||
'class': self.__class__.__name__,
|
||||
'version': self.VERSION,
|
||||
'platform': platform.platform()
|
||||
}
|
||||
|
||||
def parse_replication_configs(self):
|
||||
self._replication_interval = (
|
||||
@ -959,26 +967,13 @@ class PureBaseVolumeDriver(san.SanDriver):
|
||||
|
||||
def _get_flasharray(self, san_ip, api_token, rest_version=None,
|
||||
verify_https=None, ssl_cert_path=None):
|
||||
# Older versions of the module (1.4.0) do not support setting ssl certs
|
||||
# TODO(patrickeast): In future releases drop support for 1.4.0
|
||||
if self._client_version_greater_than([1, 4, 0]):
|
||||
array = purestorage.FlashArray(san_ip,
|
||||
api_token=api_token,
|
||||
rest_version=rest_version,
|
||||
verify_https=verify_https,
|
||||
ssl_cert=ssl_cert_path)
|
||||
else:
|
||||
if verify_https or ssl_cert_path is not None:
|
||||
msg = _('HTTPS certificate verification was requested '
|
||||
'but cannot be enabled with purestorage '
|
||||
'module version %(version)s. Upgrade to a '
|
||||
'newer version to enable this feature.') % {
|
||||
'version': purestorage.VERSION
|
||||
}
|
||||
raise exception.PureDriverException(reason=msg)
|
||||
array = purestorage.FlashArray(san_ip,
|
||||
api_token=api_token,
|
||||
rest_version=rest_version)
|
||||
|
||||
array = purestorage.FlashArray(san_ip,
|
||||
api_token=api_token,
|
||||
rest_version=rest_version,
|
||||
verify_https=verify_https,
|
||||
ssl_cert=ssl_cert_path,
|
||||
user_agent=self._user_agent)
|
||||
array_info = array.get()
|
||||
array.array_name = array_info["array_name"]
|
||||
array.array_id = array_info["id"]
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
upgrade:
|
||||
- Pure volume drivers will need 'purestorage' python module v1.6.0 or newer.
|
||||
Support for 1.4.x has been removed.
|
Loading…
Reference in New Issue
Block a user