Tests for the IBM Storwize family and SVC volume driver.
"""
-import mox
import random
import re
import socket
from cinder import context
from cinder import exception
-from cinder import flags
from cinder.openstack.common import excutils
from cinder.openstack.common import log as logging
from cinder import test
from cinder.volume.drivers import storwize_svc
from cinder.volume import volume_types
-FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)
super(StorwizeSVCDriverTestCase, self).setUp()
self.USESIM = True
if self.USESIM:
+ self.driver = StorwizeSVCFakeDriver(
+ configuration=conf.Configuration(None))
self._def_flags = {'san_ip': 'hostname',
'san_login': 'user',
'san_password': 'pass',
str(random.randint(0, 9999999999999999)).zfill(16)]
self._iscsi_name = ('test.initiator.%s' %
str(random.randint(10000, 99999)))
- self._reset_flags()
self.sim = StorwizeSVCManagementSimulator('volpool')
- configuration = mox.MockObject(conf.Configuration)
- configuration.san_is_local = False
- configuration.append_config_values(mox.IgnoreArg())
-
- self.driver = StorwizeSVCFakeDriver(configuration=configuration)
self.driver.set_fake_storage(self.sim)
else:
+ self.driver = storwize_svc.StorwizeSVCDriver(
+ configuration=conf.Configuration(None))
self._def_flags = {'san_ip': '1.111.11.11',
'san_login': 'user',
'san_password': 'password',
if l.startswith('InitiatorName='):
self._iscsi_name = l[l.index('=') + 1:].strip()
- self._reset_flags()
- self.driver = storwize_svc.StorwizeSVCDriver()
-
+ self._reset_flags()
self.driver.db = StorwizeSVCFakeDB()
self.driver.do_setup(None)
self.driver.check_for_setup_error()
self.stubs.Set(storwize_svc.time, 'sleep', lambda s: None)
+ def _set_flag(self, flag, value):
+ group = self.driver.configuration.config_group
+ self.driver.configuration.set_override(flag, value, group)
+
def _reset_flags(self):
- FLAGS.reset()
- self.flags(**self._def_flags)
+ self.driver.configuration.local_conf.reset()
+ for k, v in self._def_flags.iteritems():
+ self._set_flag(k, v)
def _assert_vol_exists(self, name, exists):
is_vol_defined = self.driver._is_vdisk_defined(name)
def test_storwize_svc_connectivity(self):
# Make sure we detect if the pool doesn't exist
no_exist_pool = 'i-dont-exist-%s' % random.randint(10000, 99999)
- self.flags(storwize_svc_volpool_name=no_exist_pool)
+ self._set_flag('storwize_svc_volpool_name', no_exist_pool)
self.assertRaises(exception.InvalidInput,
self.driver.do_setup, None)
self._reset_flags()
self.driver.do_setup, None)
# Check with bad parameters
- self.flags(san_ip='')
+ self._set_flag('san_ip', '')
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
- self.flags(san_password=None)
- self.flags(san_private_key=None)
+ self._set_flag('san_password', None)
+ self._set_flag('san_private_key', None)
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
- self.flags(storwize_svc_vol_rsize=101)
+ self._set_flag('storwize_svc_vol_rsize', 101)
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
- self.flags(storwize_svc_vol_warning=101)
+ self._set_flag('storwize_svc_vol_warning', 101)
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
- self.flags(storwize_svc_vol_grainsize=42)
+ self._set_flag('storwize_svc_vol_grainsize', 42)
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
- self.flags(storwize_svc_flashcopy_timeout=601)
+ self._set_flag('storwize_svc_flashcopy_timeout', 601)
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
- self.flags(storwize_svc_vol_compression=True)
- self.flags(storwize_svc_vol_rsize=-1)
+ self._set_flag('storwize_svc_vol_compression', True)
+ self._set_flag('storwize_svc_vol_rsize', -1)
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
- self.flags(storwize_svc_connection_protocol='foo')
+ self._set_flag('storwize_svc_connection_protocol', 'foo')
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
- self.flags(storwize_svc_connection_protocol='iSCSI')
- self.flags(storwize_svc_multipath_enabled=True)
+ self._set_flag('storwize_svc_connection_protocol', 'iSCSI')
+ self._set_flag('storwize_svc_multipath_enabled', True)
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
self._reset_flags()
if self.USESIM:
self.sim.error_injection('lslicense', 'no_compression')
- self.flags(storwize_svc_vol_compression=True)
+ self._set_flag('storwize_svc_vol_compression', True)
self.driver.do_setup(None)
self.assertRaises(exception.InvalidInput,
self.driver.check_for_setup_error)
snap1 = self._generate_vol_info(vol1['name'], vol1['id'])
# Test timeout and volume cleanup
- self.flags(storwize_svc_flashcopy_timeout=1)
+ self._set_flag('storwize_svc_flashcopy_timeout', 1)
self.assertRaises(exception.InvalidSnapshot,
self.driver.create_snapshot, snap1)
self._assert_vol_exists(snap1['name'], False)
attributes = self.driver._get_vdisk_attributes(volume['name'])
attr_size = float(attributes['capacity']) / (1024 ** 3) # bytes to GB
self.assertEqual(attr_size, float(volume['size']))
- pool = storwize_svc.FLAGS.storwize_svc_volpool_name
+ pool = self.driver.configuration.local_conf.storwize_svc_volpool_name
self.assertEqual(attributes['mdisk_grp_name'], pool)
# Try to create the volume again (should fail)
for idx in range(len(opts_list)):
attrs = self._create_test_vol(opts_list[idx])
for k, v in chck_list[idx].iteritems():
- print k + ' ' + v
try:
if k[0] == '-':
k = k[1:]
def test_storwize_svc_unicode_host_and_volume_names(self):
# We'll check with iSCSI only - nothing protocol-dependednt here
- self.flags(storwize_svc_connection_protocol='iSCSI')
+ self._set_flag('storwize_svc_connection_protocol', 'iSCSI')
self.driver.do_setup(None)
rand_id = random.randint(10000, 99999)
from cinder import context
from cinder import exception
-from cinder import flags
from cinder.openstack.common import excutils
from cinder.openstack.common import log as logging
from cinder import utils
help='Connect with multipath (currently FC-only)'),
]
-FLAGS = flags.FLAGS
-FLAGS.register_opts(storwize_svc_opts)
-
class StorwizeSVCDriver(san.SanISCSIDriver):
"""IBM Storwize V7000 and SVC iSCSI/FC volume driver.
def __init__(self, *args, **kwargs):
super(StorwizeSVCDriver, self).__init__(*args, **kwargs)
+ self.configuration.append_config_values(storwize_svc_opts)
self._storage_nodes = {}
self._enabled_protocols = set()
self._compression_enabled = False
out, err = self._run_ssh(ssh_cmd)
self._assert_ssh_return(len(out.strip()), 'do_setup',
ssh_cmd, out, err)
- search_text = '!%s!' % FLAGS.storwize_svc_volpool_name
+ search_text = '!%s!' % self.configuration.storwize_svc_volpool_name
if search_text not in out:
raise exception.InvalidInput(
reason=(_('pool %s doesn\'t exist')
- % FLAGS.storwize_svc_volpool_name))
+ % self.configuration.storwize_svc_volpool_name))
# Check if compression is supported
ssh_cmd = 'lslicense -delim !'
def _build_default_opts(self):
# Ignore capitalization
- protocol = FLAGS.storwize_svc_connection_protocol
+ protocol = self.configuration.storwize_svc_connection_protocol
if protocol.lower() == 'fc':
protocol = 'FC'
elif protocol.lower() == 'iscsi':
protocol = 'iSCSI'
- opts = {'rsize': FLAGS.storwize_svc_vol_rsize,
- 'warning': FLAGS.storwize_svc_vol_warning,
- 'autoexpand': FLAGS.storwize_svc_vol_autoexpand,
- 'grainsize': FLAGS.storwize_svc_vol_grainsize,
- 'compression': FLAGS.storwize_svc_vol_compression,
- 'easytier': FLAGS.storwize_svc_vol_easytier,
- 'protocol': protocol,
- 'multipath': FLAGS.storwize_svc_multipath_enabled}
- return opts
+ opt = {'rsize': self.configuration.storwize_svc_vol_rsize,
+ 'warning': self.configuration.storwize_svc_vol_warning,
+ 'autoexpand': self.configuration.storwize_svc_vol_autoexpand,
+ 'grainsize': self.configuration.storwize_svc_vol_grainsize,
+ 'compression': self.configuration.storwize_svc_vol_compression,
+ 'easytier': self.configuration.storwize_svc_vol_easytier,
+ 'protocol': protocol,
+ 'multipath': self.configuration.storwize_svc_multipath_enabled}
+ return opt
def check_for_setup_error(self):
"""Ensure that the flags are set properly."""
required_flags = ['san_ip', 'san_ssh_port', 'san_login',
'storwize_svc_volpool_name']
for flag in required_flags:
- if not getattr(FLAGS, flag, None):
+ if not self.configuration.safe_get(flag):
raise exception.InvalidInput(reason=_('%s is not set') % flag)
# Ensure that either password or keyfile were set
- if not (FLAGS.san_password or FLAGS.san_private_key):
+ if not (self.configuration.san_password or
+ self.configuration.san_private_key):
raise exception.InvalidInput(
reason=_('Password or SSH private key is required for '
'authentication: set either san_password or '
'san_private_key option'))
# Check that flashcopy_timeout is not more than 10 minutes
- flashcopy_timeout = FLAGS.storwize_svc_flashcopy_timeout
+ flashcopy_timeout = self.configuration.storwize_svc_flashcopy_timeout
if not (flashcopy_timeout > 0 and flashcopy_timeout <= 600):
raise exception.InvalidInput(
reason=_('Illegal value %d specified for '
'-iogrp 0 -size %(size)s -unit '
'%(unit)s %(easytier)s %(ssh_cmd_se_opt)s'
% {'name': name,
- 'mdiskgrp': FLAGS.storwize_svc_volpool_name,
+ 'mdiskgrp': self.configuration.storwize_svc_volpool_name,
'size': size, 'unit': units, 'easytier': easytier,
'ssh_cmd_se_opt': ssh_cmd_se_opt})
out, err = self._run_ssh(ssh_cmd)
mapping_ready = False
wait_time = 5
# Allow waiting of up to timeout (set as parameter)
- max_retries = (FLAGS.storwize_svc_flashcopy_timeout / wait_time) + 1
+ timeout = self.configuration.storwize_svc_flashcopy_timeout
+ max_retries = (timeout / wait_time) + 1
for try_number in range(1, max_retries):
- mapping_attributes = self._get_flashcopy_mapping_attributes(
- fc_map_id)
- if (mapping_attributes is None or
- 'status' not in mapping_attributes):
+ mapping_attrs = self._get_flashcopy_mapping_attributes(fc_map_id)
+ if (mapping_attrs is None or
+ 'status' not in mapping_attrs):
break
- if mapping_attributes['status'] == 'prepared':
+ if mapping_attrs['status'] == 'prepared':
mapping_ready = True
break
- elif mapping_attributes['status'] == 'stopped':
+ elif mapping_attrs['status'] == 'stopped':
self._call_prepare_fc_map(fc_map_id, source, target)
- elif mapping_attributes['status'] != 'preparing':
+ elif mapping_attrs['status'] != 'preparing':
# Unexpected mapping status
exception_msg = (_('Unexecpted mapping status %(status)s '
'for mapping %(id)s. Attributes: '
'%(attr)s')
- % {'status': mapping_attributes['status'],
+ % {'status': mapping_attrs['status'],
'id': fc_map_id,
- 'attr': mapping_attributes})
+ 'attr': mapping_attrs})
raise exception.VolumeBackendAPIException(data=exception_msg)
# Need to wait for mapping to be prepared, wait a few seconds
time.sleep(wait_time)
if not mapping_ready:
exception_msg = (_('Mapping %(id)s prepare failed to complete '
- 'within the alloted %(to)d seconds timeout. '
+ 'within the allotted %(to)d seconds timeout. '
'Terminating.')
% {'id': fc_map_id,
- 'to': FLAGS.storwize_svc_flashcopy_timeout})
+ 'to': timeout})
LOG.error(_('_prepare_fc_map: Failed to start FlashCopy '
'from %(source)s to %(target)s with '
'exception %(ex)s')
LOG.debug(_("Updating volume status"))
data = {}
- data['volume_backend_name'] = 'IBM_STORWIZE_SVC' # To be overwritten
data['vendor_name'] = 'IBM'
data['driver_version'] = '1.1'
data['storage_protocol'] = list(self._enabled_protocols)
data['reserved_percentage'] = 0
data['QoS_support'] = False
- pool = FLAGS.storwize_svc_volpool_name
+ data['compression_enabled'] = self._compression_enabled
+
+ pool = self.configuration.storwize_svc_volpool_name
#Get storage system name
ssh_cmd = 'lssystem -delim !'
attributes = self._execute_command_and_parse_attributes(ssh_cmd)
'Could not get system name'))
raise exception.VolumeBackendAPIException(data=exception_message)
- data['volume_backend_name'] = '%s_%s' % (attributes['name'], pool)
+ backend_name = self.configuration.safe_get('volume_backend_name')
+ if not backend_name:
+ backend_name = '%s_%s' % (attributes['name'], pool)
+ data['volume_backend_name'] = backend_name
ssh_cmd = 'lsmdiskgrp -bytes -delim ! %s' % pool
attributes = self._execute_command_and_parse_attributes(ssh_cmd)