From 71ff2adb6dab0d86560f8cb24e5bfc006d5b7364 Mon Sep 17 00:00:00 2001 From: Isaac Beckman Date: Sun, 23 Jul 2017 18:30:47 +0300 Subject: [PATCH] IBM storage: check pyxcli version on initialize The IBM storage driver is using a python client called pyxcli. the client is: https://github.com/IBM/pyxcli Upon initialization of IBM Storage driver need to check if the required client version is installed. Change-Id: I664c0419b91952bc046c28d2474f52266bdbc351 Closes-Bug: 1696470 --- .../unit/volume/drivers/ibm/fake_pyxcli.py | 1 + .../unit/volume/drivers/ibm/test_xiv_proxy.py | 17 ++++++++++++++++ .../drivers/ibm/ibm_storage/xiv_proxy.py | 20 +++++++++++++++++++ driver-requirements.txt | 2 +- 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/volume/drivers/ibm/fake_pyxcli.py b/cinder/tests/unit/volume/drivers/ibm/fake_pyxcli.py index 18e148750c0..7f447326042 100644 --- a/cinder/tests/unit/volume/drivers/ibm/fake_pyxcli.py +++ b/cinder/tests/unit/volume/drivers/ibm/fake_pyxcli.py @@ -26,6 +26,7 @@ pyxcli_client.events = mock.Mock() pyxcli_client.mirroring = mock.Mock() pyxcli_client.transports = fake_pyxcli_exceptions pyxcli_client.mirroring.cg_recovery_manager = mock.Mock() +pyxcli_client.version = '1.1.5' sys.modules['pyxcli'] = pyxcli_client sys.modules['pyxcli.events'] = pyxcli_client.events diff --git a/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py b/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py index c280993fde3..04d3397e10b 100644 --- a/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py +++ b/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py @@ -150,6 +150,23 @@ class XIVProxyTest(test.TestCase): 'san_password': REPLICA_PASSWORD, } + @mock.patch("cinder.volume.drivers.ibm.ibm_storage." + "xiv_proxy.pyxcli") + def test_wrong_pyxcli(self, mock_pyxcli): + + driver = mock.MagicMock() + driver.VERSION = "VERSION" + + p = self.proxy( + self.default_storage_info, + mock.MagicMock(), + test_mock.cinder.exception, + driver) + + mock_pyxcli.version = '1.1.4' + self.assertRaises(test_mock.cinder.exception.CinderException, + p.setup, {}) + @mock.patch("cinder.volume.drivers.ibm.ibm_storage" ".xiv_proxy.socket.getfqdn", new=mock.MagicMock( return_value='test_hostname')) diff --git a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py index 1ca3fc33969..d8060e97e73 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py +++ b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py @@ -57,6 +57,7 @@ SYNC = 'sync' ASYNC = 'async' SYNC_TIMEOUT = 300 SYNCHED_STATES = ['synchronized', 'rpo ok'] +PYXCLI_VERSION = '1.1.5' LOG = logging.getLogger(__name__) @@ -95,6 +96,9 @@ DELETE_VOLUME_BASE_ERROR = ("Unable to delete volume '%(volume)s': " MANAGE_VOLUME_BASE_ERROR = _("Unable to manage the volume '%(volume)s': " "%(error)s.") +INCOMPATIBLE_PYXCLI = _('Incompatible pyxcli found. Required: %(required)s ' + 'Found: %(found)s') + class XIVProxy(proxy.IBMStorageProxy): """Proxy between the Cinder Volume and Spectrum Accelerate Storage. @@ -132,6 +136,22 @@ class XIVProxy(proxy.IBMStorageProxy): @proxy._trace_time def setup(self, context): + msg = '' + if pyxcli: + if pyxcli.version != PYXCLI_VERSION: + msg = (INCOMPATIBLE_PYXCLI % + {'required': PYXCLI_VERSION, + 'found': pyxcli.version + }) + else: + msg = (SETUP_BASE_ERROR % + {'title': strings.TITLE, + 'details': "IBM Python XCLI Client (pyxcli) not found" + }) + if msg != '': + LOG.error(msg) + raise self._get_exception()(msg) + """Connect ssl client.""" LOG.info("Setting up connection to %(title)s...\n" "Active backend_id: '%(id)s'.", diff --git a/driver-requirements.txt b/driver-requirements.txt index 694d7709263..299a2c4b7c5 100644 --- a/driver-requirements.txt +++ b/driver-requirements.txt @@ -25,7 +25,7 @@ python-lefthandclient>=2.0.0 # Apache-2.0 pywbem>=0.7.0 # LGPLv2.1+ # IBM XIV -pyxcli>=1.1.0 # Apache-2.0 +pyxcli>=1.1.5 # Apache-2.0 # RBD rados # LGPLv2.1