]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Scality driver:use self.configuration instead of CONF
authorJordanP <jordan.pittier@scality.com>
Thu, 13 Nov 2014 16:14:00 +0000 (17:14 +0100)
committerJordanP <jordan.pittier@scality.com>
Fri, 14 Nov 2014 09:19:20 +0000 (10:19 +0100)
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.

This patch converts the driver and updates tests.

Commit message stolen from Id1a7c583894ac368bdcc61facc6f72300db320c7
Closes-Bug: #1392633
Change-Id: I61b0b6a21628d5629b5f80768e73ee44db05d1ce

cinder/tests/test_scality.py
cinder/volume/drivers/scality.py

index 8c2c5455223edbf9bc7dc7bd2fd480e9216de99d..d46cb43f74508f7a00fcbe75d0acc9a197d1f9fc 100644 (file)
@@ -29,6 +29,7 @@ from cinder.image import image_utils
 from cinder.openstack.common import units
 from cinder import test
 from cinder import utils
+from cinder.volume import configuration as conf
 from cinder.volume.drivers import scality
 
 
@@ -93,10 +94,10 @@ class ScalityDriverTestCase(test.TestCase):
                 raise
 
     def _configure_driver(self):
-        scality.CONF.scality_sofs_config = self.TEST_CONFIG
-        scality.CONF.scality_sofs_mount_point = self.TEST_MOUNT
-        scality.CONF.scality_sofs_volume_dir = self.TEST_VOLDIR
-        scality.CONF.volume_dd_blocksize = '1M'
+        self.configuration.scality_sofs_config = self.TEST_CONFIG
+        self.configuration.scality_sofs_mount_point = self.TEST_MOUNT
+        self.configuration.scality_sofs_volume_dir = self.TEST_VOLDIR
+        self.configuration.volume_dd_blocksize = '1M'
 
     def _execute_wrapper(self, cmd, *args, **kwargs):
         try:
@@ -116,8 +117,6 @@ class ScalityDriverTestCase(test.TestCase):
         self.stubs.Set(os, 'access', _access_wrapper)
 
     def setUp(self):
-        super(ScalityDriverTestCase, self).setUp()
-
         self.tempdir = tempfile.mkdtemp()
         self.addCleanup(shutil.rmtree, self.tempdir)
 
@@ -132,25 +131,26 @@ class ScalityDriverTestCase(test.TestCase):
                                            self.TEST_VOLDIR,
                                            self.TEST_CLONENAME)
 
-        self._driver = scality.ScalityDriver()
-        self._driver.set_execute(self._execute_wrapper)
         self._mox = mox_lib.Mox()
+        self.configuration = mox_lib.MockObject(conf.Configuration)
+        self._configure_driver()
+        super(ScalityDriverTestCase, self).setUp()
 
+        self._driver = scality.ScalityDriver(configuration=self.configuration)
+        self._driver.set_execute(self._execute_wrapper)
         self._create_fake_mount()
         self._create_fake_config()
         self.addCleanup(self._remove_fake_config)
 
-        self._configure_driver()
-
     def test_setup_no_config(self):
         """Missing SOFS configuration shall raise an error."""
-        scality.CONF.scality_sofs_config = None
+        self.configuration.scality_sofs_config = None
         self.assertRaises(exception.VolumeBackendAPIException,
                           self._driver.do_setup, None)
 
     def test_setup_missing_config(self):
         """Non-existent SOFS configuration file shall raise an error."""
-        scality.CONF.scality_sofs_config = 'nonexistent.conf'
+        self.configuration.scality_sofs_config = 'nonexistent.conf'
         self.assertRaises(exception.VolumeBackendAPIException,
                           self._driver.do_setup, None)
 
index 6b9182f42d9a8eb773c4e2dfab832d27951cc612..c272dbd110092a1c3dd52c7858daaafe960d0fc6 100644 (file)
@@ -59,11 +59,15 @@ class ScalityDriver(driver.VolumeDriver):
 
     VERSION = '1.0.0'
 
+    def __init__(self, *args, **kwargs):
+        super(ScalityDriver, self).__init__(*args, **kwargs)
+        self.configuration.append_config_values(volume_opts)
+
     def _check_prerequisites(self):
         """Sanity checks before attempting to mount SOFS."""
 
         # config is mandatory
-        config = CONF.scality_sofs_config
+        config = self.configuration.scality_sofs_config
         if not config:
             msg = _("Value required for 'scality_sofs_config'")
             LOG.warn(msg)
@@ -94,8 +98,8 @@ class ScalityDriver(driver.VolumeDriver):
                 raise
 
     def _mount_sofs(self):
-        config = CONF.scality_sofs_config
-        mount_path = CONF.scality_sofs_mount_point
+        config = self.configuration.scality_sofs_config
+        mount_path = self.configuration.scality_sofs_mount_point
         sysdir = os.path.join(mount_path, 'sys')
 
         self._makedirs(mount_path)
@@ -126,16 +130,16 @@ class ScalityDriver(driver.VolumeDriver):
         """Any initialization the volume driver does while starting."""
         self._check_prerequisites()
         self._mount_sofs()
-        voldir = os.path.join(CONF.scality_sofs_mount_point,
-                              CONF.scality_sofs_volume_dir)
+        voldir = os.path.join(self.configuration.scality_sofs_mount_point,
+                              self.configuration.scality_sofs_volume_dir)
         if not os.path.isdir(voldir):
             self._makedirs(voldir)
 
     def check_for_setup_error(self):
         """Returns an error if prerequisites aren't met."""
         self._check_prerequisites()
-        voldir = os.path.join(CONF.scality_sofs_mount_point,
-                              CONF.scality_sofs_volume_dir)
+        voldir = os.path.join(self.configuration.scality_sofs_mount_point,
+                              self.configuration.scality_sofs_volume_dir)
         if not os.path.isdir(voldir):
             msg = _("Cannot find volume dir for Scality SOFS at '%s'") % voldir
             LOG.warn(msg)
@@ -165,8 +169,8 @@ class ScalityDriver(driver.VolumeDriver):
 
     def create_snapshot(self, snapshot):
         """Creates a snapshot."""
-        volume_path = os.path.join(CONF.scality_sofs_mount_point,
-                                   CONF.scality_sofs_volume_dir,
+        volume_path = os.path.join(self.configuration.scality_sofs_mount_point,
+                                   self.configuration.scality_sofs_volume_dir,
                                    snapshot['volume_name'])
         snapshot_path = self.local_path(snapshot)
         self._create_file(snapshot_path,
@@ -178,11 +182,11 @@ class ScalityDriver(driver.VolumeDriver):
         os.remove(self.local_path(snapshot))
 
     def _sofs_path(self, volume):
-        return os.path.join(CONF.scality_sofs_volume_dir,
+        return os.path.join(self.configuration.scality_sofs_volume_dir,
                             volume['name'])
 
     def local_path(self, volume):
-        return os.path.join(CONF.scality_sofs_mount_point,
+        return os.path.join(self.configuration.scality_sofs_mount_point,
                             self._sofs_path(volume))
 
     def ensure_export(self, context, volume):
@@ -241,7 +245,7 @@ class ScalityDriver(driver.VolumeDriver):
                                  image_service,
                                  image_id,
                                  self.local_path(volume),
-                                 CONF.volume_dd_blocksize,
+                                 self.configuration.volume_dd_blocksize,
                                  size=volume['size'])
         self.create_volume(volume)