From 3f0ab888d3e3d649ace2401df84f8d64e41479c1 Mon Sep 17 00:00:00 2001 From: vponomaryov <vponomaryov@mirantis.com> Date: Thu, 5 Jun 2014 16:13:29 +0300 Subject: [PATCH] Fix lvm driver to be compatible with share manager After last changes to share manager, LVM driver became incompatible. Change-Id: I335afd8ba7f4d0e73c7f179290608b2b873651c7 --- manila/share/drivers/lvm.py | 17 +++++++++-------- manila/tests/test_share_lvm.py | 31 +++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/manila/share/drivers/lvm.py b/manila/share/drivers/lvm.py index 2296491515..a7da48cbc7 100644 --- a/manila/share/drivers/lvm.py +++ b/manila/share/drivers/lvm.py @@ -192,7 +192,7 @@ class LVMShareDriver(driver.ExecuteMixin, driver.ShareDriver): self._stats = data - def create_share(self, context, share): + def create_share(self, context, share, share_server=None): self._allocate_container(share) #create file system device_name = self._local_path(share) @@ -203,7 +203,8 @@ class LVMShareDriver(driver.ExecuteMixin, driver.ShareDriver): #TODO(rushiagr): what is the provider_location? realy needed? return location - def create_share_from_snapshot(self, context, share, snapshot): + def create_share_from_snapshot(self, context, share, snapshot, + share_server=None): """Is called to create share from snapshot.""" self._allocate_container(share) device_name = self._local_path(snapshot) @@ -216,7 +217,7 @@ class LVMShareDriver(driver.ExecuteMixin, driver.ShareDriver): #TODO(rushiagr): what is the provider_location? realy needed? return location - def delete_share(self, context, share): + def delete_share(self, context, share, share_server=None): self._remove_export(context, share) self._delete_share(context, share) self._deallocate_container(share['name']) @@ -239,7 +240,7 @@ class LVMShareDriver(driver.ExecuteMixin, driver.ShareDriver): except OSError: LOG.info('Unable to delete %s', mount_path) - def create_snapshot(self, context, snapshot): + def create_snapshot(self, context, snapshot, share_server=None): """Creates a snapshot.""" orig_lv_name = "%s/%s" % (self.configuration.share_volume_group, snapshot['share_name']) @@ -247,7 +248,7 @@ class LVMShareDriver(driver.ExecuteMixin, driver.ShareDriver): '--name', snapshot['name'], '--snapshot', orig_lv_name, run_as_root=True) - def ensure_share(self, ctx, share): + def ensure_share(self, ctx, share, share_server=None): """Ensure that storage are mounted and exported.""" device_name = self._local_path(share) location = self._mount_device(share, device_name) @@ -264,18 +265,18 @@ class LVMShareDriver(driver.ExecuteMixin, driver.ShareDriver): except exception.InvalidShare as exc: LOG.info(exc.message) - def delete_snapshot(self, context, snapshot): + def delete_snapshot(self, context, snapshot, share_server=None): """Deletes a snapshot.""" self._deallocate_container(snapshot['name']) - def allow_access(self, ctx, share, access): + def allow_access(self, ctx, share, access, share_server=None): """Allow access to the share.""" location = self._get_mount_path(share) self._get_helper(share).allow_access(location, share['name'], access['access_type'], access['access_to']) - def deny_access(self, ctx, share, access): + def deny_access(self, ctx, share, access, share_server=None): """Allow access to the share.""" location = self._get_mount_path(share) self._get_helper(share).deny_access(location, share['name'], diff --git a/manila/tests/test_share_lvm.py b/manila/tests/test_share_lvm.py index 4a530b5552..3099b9688b 100644 --- a/manila/tests/test_share_lvm.py +++ b/manila/tests/test_share_lvm.py @@ -101,6 +101,9 @@ class LVMShareDriverTestCase(test.TestCase): self.access = fake_access() self.snapshot = fake_snapshot() + # Used only to test compatibility with share manager + self.share_server = "fake_share_server" + def tearDown(self): super(LVMShareDriverTestCase, self).tearDown() fake_utils.fake_execute_set_repliers([]) @@ -160,7 +163,8 @@ class LVMShareDriverTestCase(test.TestCase): def test_create_share(self): self._helper_nfs.create_export.return_value = 'fakelocation' self._driver._mount_device = mock.Mock() - ret = self._driver.create_share(self._context, self.share) + ret = self._driver.create_share(self._context, self.share, + self.share_server) CONF.set_default('share_lvm_mirrors', 0) self._driver._mount_device.assert_called_with( self.share, '/dev/mapper/fakevg-fakename') @@ -180,8 +184,9 @@ class LVMShareDriverTestCase(test.TestCase): mount_path = self._get_mount_path(self.share) ret = self._driver.create_share_from_snapshot(self._context, - self.share, - self.snapshot) + self.share, + self.snapshot, + self.share_server) self._driver._mount_device.assert_called_with(self.share, mount_snapshot) @@ -201,7 +206,8 @@ class LVMShareDriverTestCase(test.TestCase): CONF.set_default('share_lvm_mirrors', 2) self._helper_nfs.create_export.return_value = 'fakelocation' self._driver._mount_device = mock.Mock() - ret = self._driver.create_share(self._context, share) + ret = self._driver.create_share(self._context, share, + self.share_server) self._driver._mount_device.assert_called_with( share, '/dev/mapper/fakevg-fakename') expected_exec = [ @@ -304,7 +310,8 @@ class LVMShareDriverTestCase(test.TestCase): self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) def test_create_snapshot(self): - self._driver.create_snapshot(self._context, self.snapshot) + self._driver.create_snapshot(self._context, self.snapshot, + self.share_server) expected_exec = [ ("lvcreate -L 1G --name fakesnapshotname --snapshot %s/fakename" % (CONF.share_volume_group,)), @@ -317,7 +324,8 @@ class LVMShareDriverTestCase(test.TestCase): with mock.patch.object(self._driver, '_mount_device', mock.Mock(return_value=location)): - self._driver.ensure_share(self._context, self.share) + self._driver.ensure_share(self._context, self.share, + self.share_server) self._driver._mount_device.assert_called_with(self.share, device_name) self._helper_nfs.create_export.assert_called_once_with( @@ -330,13 +338,14 @@ class LVMShareDriverTestCase(test.TestCase): def test_delete_snapshot(self): expected_exec = ['lvremove -f fakevg/fakesnapshotname'] - self._driver.delete_snapshot(self._context, self.snapshot) + self._driver.delete_snapshot(self._context, self.snapshot, + self.share_server) self.assertEqual(fake_utils.fake_execute_get_log(), expected_exec) def test_delete_share_invalid_share(self): self._driver._get_helper = mock.Mock( side_effect=exception.InvalidShare(reason='fake')) - self._driver.delete_share(self._context, self.share) + self._driver.delete_share(self._context, self.share, self.share_server) def test_allow_access(self): mount_path = self._get_mount_path(self.share) @@ -344,7 +353,8 @@ class LVMShareDriverTestCase(test.TestCase): self.share['name'], self.access['access_type'], self.access['access_to']) - self._driver.allow_access(self._context, self.share, self.access) + self._driver.allow_access(self._context, self.share, self.access, + self.share_server) def test_deny_access(self): mount_path = self._get_mount_path(self.share) @@ -352,7 +362,8 @@ class LVMShareDriverTestCase(test.TestCase): self.share['name'], self.access['access_type'], self.access['access_to']) - self._driver.deny_access(self._context, self.share, self.access) + self._driver.deny_access(self._context, self.share, self.access, + self.share_server) def test_mount_device(self): mount_path = self._get_mount_path(self.share)