From: JordanP Date: Thu, 13 Nov 2014 16:14:00 +0000 (+0100) Subject: Scality driver:use self.configuration instead of CONF X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=044c753b0429f2cdb8b99b040cc69480e2593b52;p=openstack-build%2Fcinder-build.git Scality driver:use self.configuration instead of CONF 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 --- diff --git a/cinder/tests/test_scality.py b/cinder/tests/test_scality.py index 8c2c54552..d46cb43f7 100644 --- a/cinder/tests/test_scality.py +++ b/cinder/tests/test_scality.py @@ -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) diff --git a/cinder/volume/drivers/scality.py b/cinder/volume/drivers/scality.py index 6b9182f42..c272dbd11 100644 --- a/cinder/volume/drivers/scality.py +++ b/cinder/volume/drivers/scality.py @@ -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)