Skip to content

Commit

Permalink
NetApp check for 7 mode controller version
Browse files Browse the repository at this point in the history
Queries the filer api version and raises error
if the version is unsupported.

Closes-Bug:#1223474

Change-Id: I430a41d63a2541891fdbdb20dacab9f69fa44291
  • Loading branch information
singn committed Jul 31, 2013
1 parent 1f563d6 commit 1af8f46
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
18 changes: 16 additions & 2 deletions cinder/tests/test_netapp.py
Expand Up @@ -1066,7 +1066,7 @@ def _custom_setup(self):
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):
Expand Down Expand Up @@ -1098,6 +1098,20 @@ def test_create_fail_on_select_vol(self):
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):
Expand All @@ -1114,7 +1128,7 @@ def _custom_setup(self):
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):
Expand Down
20 changes: 16 additions & 4 deletions cinder/tests/test_netapp_nfs.py
Expand Up @@ -216,12 +216,10 @@ def test_do_setup(self):
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())

Expand Down Expand Up @@ -797,9 +795,25 @@ def _custom_setup(self):
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',
Expand Down Expand Up @@ -832,11 +846,9 @@ def test_do_setup(self):
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())

Expand Down
6 changes: 3 additions & 3 deletions cinder/volume/drivers/netapp/api.py
Expand Up @@ -125,10 +125,10 @@ def set_api_version(self, major, minor):
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."""
Expand Down
18 changes: 16 additions & 2 deletions cinder/volume/drivers/netapp/iscsi.py
Expand Up @@ -903,11 +903,25 @@ def _do_custom_setup(self):
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."""
Expand Down
15 changes: 14 additions & 1 deletion cinder/volume/drivers/netapp/nfs.py
Expand Up @@ -594,7 +594,6 @@ def __init__(self, *args, **kwargs):
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)

Expand Down Expand Up @@ -996,6 +995,20 @@ def _do_custom_setup(self, client):
(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.
Expand Down

0 comments on commit 1af8f46

Please sign in to comment.