Merge "NetApp: E-Series driver using invalid host-types"

This commit is contained in:
Jenkins 2016-05-28 00:44:36 +00:00 committed by Gerrit Code Review
commit 0378d68a8d
4 changed files with 160 additions and 44 deletions

View File

@ -1262,25 +1262,105 @@ class FakeEseriesClient(object):
def list_host_types(self): def list_host_types(self):
return [ return [
{ {
'id': '4', 'name': 'FactoryDefault',
'code': 'AIX', 'index': 0,
'name': 'AIX', 'code': 'FactoryDefault',
'index': 4
}, },
{ {
'id': '5', 'name': 'Windows 2000/Server 2003/Server 2008 Non-Clustered',
'code': 'IRX', 'index': 1,
'name': 'IRX', 'code': 'W2KNETNCL',
'index': 5 },
{
'name': 'Solaris',
'index': 2,
'code': 'SOL',
},
{
'name': 'ONTAP_RDAC',
'index': 4,
'code': 'ONTAP_RDAC',
},
{
'name': 'AVT_4M',
'index': 5,
'code': 'AVT_4M',
},
{
'name': 'Linux',
'index': 6,
'code': 'LNX',
}, },
{ {
'id': '6',
'code': 'LnxALUA',
'name': 'LnxALUA', 'name': 'LnxALUA',
'index': 6 'index': 7,
'code': 'LnxALUA',
},
{
'name': 'Windows 2000/Server 2003/Server 2008 Clustered',
'index': 8,
'code': 'W2KNETCL',
},
{
'name': 'AIX MPIO',
'index': 9,
'code': 'AIX MPIO',
},
{
'name': 'VmwTPGSALUA',
'index': 10,
'code': 'VmwTPGSALUA',
},
{
'name': 'HP-UX TPGS',
'index': 15,
'code': 'HPXTPGS',
},
{
'name': 'SolTPGSALUA',
'index': 17,
'code': 'SolTPGSALUA',
},
{
'name': 'SVC',
'index': 18,
'code': 'SVC',
},
{
'name': 'MacTPGSALUA',
'index': 22,
'code': 'MacTPGSALUA',
},
{
'name': 'WinTPGSALUA',
'index': 23,
'code': 'WinTPGSALUA',
},
{
'name': 'LnxTPGSALUA',
'index': 24,
'code': 'LnxTPGSALUA',
},
{
'name': 'LnxTPGSALUA_PM',
'index': 25,
'code': 'LnxTPGSALUA_PM',
},
{
'name': 'ONTAP_ALUA',
'index': 26,
'code': 'ONTAP_ALUA',
},
{
'name': 'LnxTPGSALUA_SF',
'index': 27,
'code': 'LnxTPGSALUA_SF',
} }
] ]
def update_host_type(self, *args, **kwargs):
pass
def list_hardware_inventory(self): def list_hardware_inventory(self):
return HARDWARE_INVENTORY return HARDWARE_INVENTORY

View File

@ -273,19 +273,6 @@ class NetAppESeriesDriverTestCase(object):
self.library._get_iscsi_portal_for_vol, self.library._get_iscsi_portal_for_vol,
vol_nomatch, portals, False) vol_nomatch, portals, False)
def test_setup_error_unsupported_host_type(self):
configuration = self._set_config(self.create_configuration())
configuration.netapp_host_type = 'garbage'
driver = common.NetAppDriver(configuration=configuration)
self.assertRaises(exception.NetAppDriverException,
driver.library.check_for_setup_error)
def test_check_host_type_default(self):
configuration = self._set_config(self.create_configuration())
driver = common.NetAppDriver(configuration=configuration)
driver.library._check_host_type()
self.assertEqual('LnxALUA', driver.library.host_type)
def test_do_setup_all_default(self): def test_do_setup_all_default(self):
configuration = self._set_config(self.create_configuration()) configuration = self._set_config(self.create_configuration())
driver = common.NetAppDriver(configuration=configuration) driver = common.NetAppDriver(configuration=configuration)

View File

@ -99,6 +99,51 @@ class NetAppEseriesLibraryTestCase(test.TestCase):
self.assertTrue(mock_check_flags.called) self.assertTrue(mock_check_flags.called)
@ddt.data('linux_dm_mp', 'linux_atto', 'linux_mpp_rdac',
'linux_pathmanager', 'linux_sf', 'ontap', 'ontap_rdac',
'vmware', 'windows_atto', 'windows_clustered',
'factoryDefault', 'windows', None)
def test_check_host_type(self, host_type):
config = mock.Mock()
default_host_type = self.library.host_type
config.netapp_host_type = host_type
self.mock_object(self.library, 'configuration', config)
result = self.library._check_host_type()
self.assertIsNone(result)
if host_type:
self.assertEqual(self.library.HOST_TYPES.get(host_type),
self.library.host_type)
else:
self.assertEqual(default_host_type, self.library.host_type)
def test_check_host_type_invalid(self):
config = mock.Mock()
config.netapp_host_type = 'invalid'
self.mock_object(self.library, 'configuration', config)
self.assertRaises(exception.NetAppDriverException,
self.library._check_host_type)
def test_check_host_type_new(self):
config = mock.Mock()
config.netapp_host_type = 'new_host_type'
expected = 'host_type'
self.mock_object(self.library, 'configuration', config)
host_types = [{
'name': 'new_host_type',
'index': 0,
'code': expected,
}]
self.mock_object(self.library._client, 'list_host_types',
mock.Mock(return_value=host_types))
result = self.library._check_host_type()
self.assertIsNone(result)
self.assertEqual(expected, self.library.host_type)
@ddt.data(('optimal', True), ('offline', False), ('needsAttn', True), @ddt.data(('optimal', True), ('offline', False), ('needsAttn', True),
('neverContacted', False), ('newKey', True), (None, True)) ('neverContacted', False), ('newKey', True), (None, True))
@ddt.unpack @ddt.unpack

View File

@ -61,25 +61,18 @@ class NetAppESeriesLibrary(object):
REQUIRED_FLAGS = ['netapp_server_hostname', 'netapp_controller_ips', REQUIRED_FLAGS = ['netapp_server_hostname', 'netapp_controller_ips',
'netapp_login', 'netapp_password'] 'netapp_login', 'netapp_password']
SLEEP_SECS = 5 SLEEP_SECS = 5
HOST_TYPES = {'aix': 'AIX MPIO', HOST_TYPES = {'factoryDefault': 'FactoryDefault',
'avt': 'AVT_4M',
'factoryDefault': 'FactoryDefault',
'hpux': 'HP-UX TPGS',
'linux_atto': 'LnxTPGSALUA', 'linux_atto': 'LnxTPGSALUA',
'linux_dm_mp': 'LnxALUA', 'linux_dm_mp': 'LnxALUA',
'linux_mpp_rdac': 'Linux', 'linux_mpp_rdac': 'LNX',
'linux_pathmanager': 'LnxTPGSALUA_PM', 'linux_pathmanager': 'LnxTPGSALUA_PM',
'macos': 'MacTPGSALUA', 'linux_sf': 'LnxTPGSALUA_SF',
'ontap': 'ONTAP', 'ontap': 'ONTAP_ALUA',
'svc': 'SVC', 'ontap_rdac': 'ONTAP_RDAC',
'solaris_v11': 'SolTPGSALUA',
'solaris_v10': 'Solaris',
'vmware': 'VmwTPGSALUA', 'vmware': 'VmwTPGSALUA',
'windows': 'windows': 'W2KNETNCL',
'Windows 2000/Server 2003/Server 2008 Non-Clustered',
'windows_atto': 'WinTPGSALUA', 'windows_atto': 'WinTPGSALUA',
'windows_clustered': 'windows_clustered': 'W2KNETCL',
'Windows 2000/Server 2003/Server 2008 Clustered'
} }
# NOTE(ameade): This maps what is reported by the e-series api to a # NOTE(ameade): This maps what is reported by the e-series api to a
# consistent set of values that are reported by all NetApp drivers # consistent set of values that are reported by all NetApp drivers
@ -209,12 +202,23 @@ class NetAppESeriesLibrary(object):
self._start_periodic_tasks() self._start_periodic_tasks()
def _check_host_type(self): def _check_host_type(self):
host_type = (self.configuration.netapp_host_type """Validate that the configured host-type is available for the array.
Not all host-types are available on every firmware version.
"""
requested_host_type = (self.configuration.netapp_host_type
or self.DEFAULT_HOST_TYPE) or self.DEFAULT_HOST_TYPE)
self.host_type = self.HOST_TYPES.get(host_type) actual_host_type = (
if not self.host_type: self.HOST_TYPES.get(requested_host_type, requested_host_type))
raise exception.NetAppDriverException(
_('Configured host type is not supported.')) for host_type in self._client.list_host_types():
if(host_type.get('code') == actual_host_type or
host_type.get('name') == actual_host_type):
self.host_type = host_type.get('code')
return
exc_msg = _("The host-type '%s' is not supported on this storage "
"system.")
raise exception.NetAppDriverException(exc_msg % requested_host_type)
def _check_multipath(self): def _check_multipath(self):
if not self.configuration.use_multipath_for_image_xfer: if not self.configuration.use_multipath_for_image_xfer: