From 1af8f46ea1c8e2a33ca554fa6ef3262d055c54ed Mon Sep 17 00:00:00 2001 From: Navneet Singh Date: Tue, 30 Jul 2013 17:37:44 +0530 Subject: [PATCH] NetApp check for 7 mode controller version Queries the filer api version and raises error if the version is unsupported. Closes-Bug:#1223474 Change-Id: I430a41d63a2541891fdbdb20dacab9f69fa44291 --- cinder/tests/test_netapp.py | 18 ++++++++++++++++-- cinder/tests/test_netapp_nfs.py | 20 ++++++++++++++++---- cinder/volume/drivers/netapp/api.py | 6 +++--- cinder/volume/drivers/netapp/iscsi.py | 18 ++++++++++++++++-- cinder/volume/drivers/netapp/nfs.py | 15 ++++++++++++++- 5 files changed, 65 insertions(+), 12 deletions(-) diff --git a/cinder/tests/test_netapp.py b/cinder/tests/test_netapp.py index 252d749b6..3ce185b61 100644 --- a/cinder/tests/test_netapp.py +++ b/cinder/tests/test_netapp.py @@ -1066,7 +1066,7 @@ class NetAppDirect7modeISCSIDriverTestCase_NV( FakeDirect7modeHTTPConnection) driver.do_setup(context='') client = driver.client - client.set_api_version(1, 7) + client.set_api_version(1, 9) self.driver = driver def _set_config(self, configuration): @@ -1098,6 +1098,20 @@ class NetAppDirect7modeISCSIDriverTestCase_NV( if not success: raise AssertionError('Failed creating on selected volumes') + def test_check_for_setup_error_version(self): + drv = self.driver + delattr(drv.client, '_api_version') + + # check exception raises when version not found + self.assertRaises(exception.VolumeBackendAPIException, + drv.check_for_setup_error) + + drv.client.set_api_version(1, 8) + + # check exception raises when not supported version + self.assertRaises(exception.VolumeBackendAPIException, + drv.check_for_setup_error) + class NetAppDirect7modeISCSIDriverTestCase_WV( NetAppDirect7modeISCSIDriverTestCase_NV): @@ -1114,7 +1128,7 @@ class NetAppDirect7modeISCSIDriverTestCase_WV( FakeDirect7modeHTTPConnection) driver.do_setup(context='') client = driver.client - client.set_api_version(1, 7) + client.set_api_version(1, 9) self.driver = driver def _set_config(self, configuration): diff --git a/cinder/tests/test_netapp_nfs.py b/cinder/tests/test_netapp_nfs.py index 4bdf855d2..5301d2b90 100644 --- a/cinder/tests/test_netapp_nfs.py +++ b/cinder/tests/test_netapp_nfs.py @@ -216,12 +216,10 @@ class NetappDirectCmodeNfsDriverTestCase(test.TestCase): drv = self._driver mox.StubOutWithMock(netapp_nfs.NetAppNFSDriver, 'do_setup') - mox.StubOutWithMock(drv, 'check_for_setup_error') mox.StubOutWithMock(drv, '_get_client') mox.StubOutWithMock(drv, '_do_custom_setup') netapp_nfs.NetAppNFSDriver.do_setup(IgnoreArg()) - drv.check_for_setup_error() drv._get_client() drv._do_custom_setup(IgnoreArg()) @@ -797,9 +795,25 @@ class NetappDirect7modeNfsDriverTestCase(NetappDirectCmodeNfsDriverTestCase): self._driver = netapp_nfs.NetAppDirect7modeNfsDriver( configuration=create_configuration()) + def test_check_for_setup_error_version(self): + drv = self._driver + drv._client = api.NaServer("127.0.0.1") + + # check exception raises when version not found + self.assertRaises(exception.VolumeBackendAPIException, + drv.check_for_setup_error) + + drv._client.set_api_version(1, 8) + + # check exception raises when not supported version + self.assertRaises(exception.VolumeBackendAPIException, + drv.check_for_setup_error) + def test_check_for_setup_error(self): mox = self.mox drv = self._driver + drv._client = api.NaServer("127.0.0.1") + drv._client.set_api_version(1, 9) required_flags = [ 'netapp_transport_type', 'netapp_login', @@ -832,11 +846,9 @@ class NetappDirect7modeNfsDriverTestCase(NetappDirectCmodeNfsDriverTestCase): mox = self.mox drv = self._driver mox.StubOutWithMock(netapp_nfs.NetAppNFSDriver, 'do_setup') - mox.StubOutWithMock(drv, 'check_for_setup_error') mox.StubOutWithMock(drv, '_get_client') mox.StubOutWithMock(drv, '_do_custom_setup') netapp_nfs.NetAppNFSDriver.do_setup(IgnoreArg()) - drv.check_for_setup_error() drv._get_client() drv._do_custom_setup(IgnoreArg()) diff --git a/cinder/volume/drivers/netapp/api.py b/cinder/volume/drivers/netapp/api.py index 4212601d5..5d0716092 100644 --- a/cinder/volume/drivers/netapp/api.py +++ b/cinder/volume/drivers/netapp/api.py @@ -125,10 +125,10 @@ class NaServer(object): self._refresh_conn = True def get_api_version(self): - """Gets the api version.""" + """Gets the api version tuple.""" if hasattr(self, '_api_version'): - return self._api_version - return self._api_version + return (self._api_major_version, self._api_minor_version) + return None def set_port(self, port): """Set the server communication port.""" diff --git a/cinder/volume/drivers/netapp/iscsi.py b/cinder/volume/drivers/netapp/iscsi.py index da9859092..d21177e9a 100644 --- a/cinder/volume/drivers/netapp/iscsi.py +++ b/cinder/volume/drivers/netapp/iscsi.py @@ -903,11 +903,25 @@ class NetAppDirect7modeISCSIDriver(NetAppDirectISCSIDriver): if self.volume_list: self.volume_list = self.volume_list.split(',') self.volume_list = [el.strip() for el in self.volume_list] + (major, minor) = self._get_ontapi_version() + self.client.set_api_version(major, minor) if self.vfiler: - (major, minor) = self._get_ontapi_version() - self.client.set_api_version(major, minor) self.client.set_vfiler(self.vfiler) + def check_for_setup_error(self): + """Check that the driver is working and can communicate.""" + api_version = self.client.get_api_version() + if api_version: + major, minor = api_version + if major == 1 and minor < 9: + msg = _("Unsupported ONTAP version." + " ONTAP version 7.3.1 and above is supported.") + raise exception.VolumeBackendAPIException(data=msg) + else: + msg = _("Api version could not be determined.") + raise exception.VolumeBackendAPIException(data=msg) + super(NetAppDirect7modeISCSIDriver, self).check_for_setup_error() + def _create_lun_on_eligible_vol(self, name, size, metadata, extra_specs=None): """Creates an actual lun on filer.""" diff --git a/cinder/volume/drivers/netapp/nfs.py b/cinder/volume/drivers/netapp/nfs.py index e5599a3fe..209abb8e7 100644 --- a/cinder/volume/drivers/netapp/nfs.py +++ b/cinder/volume/drivers/netapp/nfs.py @@ -594,7 +594,6 @@ class NetAppDirectNfsDriver (NetAppNFSDriver): def do_setup(self, context): super(NetAppDirectNfsDriver, self).do_setup(context) self._context = context - self.check_for_setup_error() self._client = self._get_client() self._do_custom_setup(self._client) @@ -996,6 +995,20 @@ class NetAppDirect7modeNfsDriver (NetAppDirectNfsDriver): (major, minor) = self._get_ontapi_version() client.set_api_version(major, minor) + def check_for_setup_error(self): + """Checks if setup occured properly.""" + api_version = self._client.get_api_version() + if api_version: + major, minor = api_version + if major == 1 and minor < 9: + msg = _("Unsupported ONTAP version." + " ONTAP version 7.3.1 and above is supported.") + raise exception.VolumeBackendAPIException(data=msg) + else: + msg = _("Api version could not be determined.") + raise exception.VolumeBackendAPIException(data=msg) + super(NetAppDirect7modeNfsDriver, self).check_for_setup_error() + def _invoke_successfully(self, na_element, vfiler=None): """Invoke the api for successful result. -- 2.45.2