]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Storwize/SVC driver fix for multibackend scenario.
authorAvishay Traeger <avishay@il.ibm.com>
Tue, 5 Mar 2013 09:23:01 +0000 (11:23 +0200)
committerAvishay Traeger <avishay@il.ibm.com>
Mon, 11 Mar 2013 21:34:11 +0000 (23:34 +0200)
In order for the Filter scheduler to be used to it's full advantage
Cinder drivers need to move away from using FLAGS directly and switch
to appending their specific options to self.configuration.

Fixes bug: 1135391

Change-Id: I8d07346c03d1cf2479738f7161ee0a0cb9f518a0

cinder/tests/test_storwize_svc.py
cinder/volume/drivers/storwize_svc.py

index 1d142d06f143c0c77d6e18786a161b4249802c9b..958613d052688a38bade1094587fb4f0037904e2 100644 (file)
 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
@@ -40,7 +38,6 @@ from cinder.volume import configuration as conf
 from cinder.volume.drivers import storwize_svc
 from cinder.volume import volume_types
 
-FLAGS = flags.FLAGS
 
 LOG = logging.getLogger(__name__)
 
@@ -1242,6 +1239,8 @@ class StorwizeSVCDriverTestCase(test.TestCase):
         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',
@@ -1256,16 +1255,12 @@ class StorwizeSVCDriverTestCase(test.TestCase):
                     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',
@@ -1293,17 +1288,20 @@ class StorwizeSVCDriverTestCase(test.TestCase):
                 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)
@@ -1312,7 +1310,7 @@ class StorwizeSVCDriverTestCase(test.TestCase):
     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()
@@ -1345,57 +1343,57 @@ class StorwizeSVCDriverTestCase(test.TestCase):
                               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)
@@ -1443,7 +1441,7 @@ class StorwizeSVCDriverTestCase(test.TestCase):
         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)
@@ -1560,7 +1558,7 @@ class StorwizeSVCDriverTestCase(test.TestCase):
         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)
@@ -1616,7 +1614,6 @@ class StorwizeSVCDriverTestCase(test.TestCase):
         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:]
@@ -1629,7 +1626,7 @@ class StorwizeSVCDriverTestCase(test.TestCase):
 
     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)
index 9dc5421754a0808b84edc43a2c0a925c0a7c8ffa..95cf1088187ed0b7461e6f7a982dd0d1e539b7a8 100644 (file)
@@ -49,7 +49,6 @@ from oslo.config import cfg
 
 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
@@ -97,9 +96,6 @@ storwize_svc_opts = [
                 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.
@@ -117,6 +113,7 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
 
     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
@@ -189,11 +186,11 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
         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 !'
@@ -269,21 +266,21 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
 
     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."""
@@ -292,18 +289,19 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
         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 '
@@ -893,7 +891,7 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
                    '-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)
@@ -986,36 +984,36 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
         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')
@@ -1306,7 +1304,6 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
         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)
@@ -1316,7 +1313,9 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
         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)
@@ -1325,7 +1324,10 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
                                    '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)