From f40a428bdbf0b820ed44a3784a7ac4b2f71aeb98 Mon Sep 17 00:00:00 2001 From: LinPeiWen <591171850@qq.com> Date: Thu, 1 Apr 2021 02:56:36 +0000 Subject: [PATCH] [Glusterfs] Fix create share from snapshot failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、After performing a snapshot clone of the glusterfs vol, the status of the vol is'Created', and the parameter "gluster volume set nfs.rpc-auth-reject'*'" is required for the vol in the'Started' state. 2、The cloned volume needs to activate the snapshot, if the snapshot is already activated, you need to skip the activation step Closes-Bug: #1922075 Change-Id: I304bf59b3f8c0d5b847078a5752bac8ac4f21690 (cherry picked from commit 63e255248b7072c92c084a0cea269a27bd47f813) (cherry picked from commit 3635ade670cce08525c946eb9029940d86fcafa8) (cherry picked from commit a04e13196c125b7d748ffdacc226b97104498cdd) --- .../share/drivers/glusterfs/layout_volume.py | 33 ++++++++++++++++--- .../drivers/glusterfs/test_layout_volume.py | 13 ++++---- ...from-snapshot-failed-053a583522a6fc0e.yaml | 6 ++++ 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/bug-1922075-fix-Glusterfs-create-share-from-snapshot-failed-053a583522a6fc0e.yaml diff --git a/manila/share/drivers/glusterfs/layout_volume.py b/manila/share/drivers/glusterfs/layout_volume.py index 27cd083778..3f3ca87699 100644 --- a/manila/share/drivers/glusterfs/layout_volume.py +++ b/manila/share/drivers/glusterfs/layout_volume.py @@ -491,9 +491,32 @@ class GlusterfsVolumeMappedLayout(layout.GlusterfsShareLayoutBase): backend_snapshot_name = self._find_actual_backend_snapshot_name( old_gmgr, snapshot) volume = ''.join(['manila-', share['id']]) - args_tuple = (('snapshot', 'activate', backend_snapshot_name, - 'force', '--mode=script'), - ('snapshot', 'clone', volume, backend_snapshot_name)) + + # Query the status of the snapshot, if it is Started, the activate + # step will be skipped + args = ('snapshot', 'info', backend_snapshot_name) + out, err = old_gmgr.gluster_call( + *args, + log=("Query the status of the snapshot")) + + gfs_snapshot_state = "" + for gfs_snapshot_info in out.split('\t'): + gfs_snapshot_states = re.search(r'Started', gfs_snapshot_info, + re.I) + if gfs_snapshot_states: + gfs_snapshot_state = "Started" + + if gfs_snapshot_state == "Started": + args_tuple = (('snapshot', 'clone', + volume, backend_snapshot_name), + ('volume', 'start', volume)) + else: + args_tuple = (('snapshot', 'activate', backend_snapshot_name, + 'force', '--mode=script'), + ('snapshot', 'clone', volume, + backend_snapshot_name), + ('volume', 'start', volume)) + for args in args_tuple: out, err = old_gmgr.gluster_call( *args, @@ -507,10 +530,10 @@ class GlusterfsVolumeMappedLayout(layout.GlusterfsShareLayoutBase): {'share': share, 'manager': gmgr}, {'share': snapshot['share_instance'], 'manager': old_gmgr}) + export = [export, ] argseq = (('set', [USER_CLONED_FROM, snapshot['share_id']]), - ('set', [USER_MANILA_SHARE, share['id']]), - ('start', [])) + ('set', [USER_MANILA_SHARE, share['id']])) for op, opargs in argseq: args = ['volume', op, gmgr.volume] + opargs gmgr.gluster_call(*args, log=("Creating share from snapshot")) diff --git a/manila/tests/share/drivers/glusterfs/test_layout_volume.py b/manila/tests/share/drivers/glusterfs/test_layout_volume.py index 2afbb0b09b..06857c5a05 100644 --- a/manila/tests/share/drivers/glusterfs/test_layout_volume.py +++ b/manila/tests/share/drivers/glusterfs/test_layout_volume.py @@ -818,9 +818,10 @@ class GlusterfsVolumeMappedLayoutTestCase(test.TestCase): self._layout.gluster_used_vols = set([glusterfs_target]) self._layout.glusterfs_versions = {glusterfs_server: ('3', '7')} self.mock_object(old_gmgr, 'gluster_call', - mock.Mock(side_effect=[('', ''), ('', '')])) + mock.Mock(side_effect=[ + ('', ''), ('', ''), ('', ''), ('', '')])) self.mock_object(new_gmgr, 'gluster_call', - mock.Mock(side_effect=[('', ''), ('', ''), ('', '')])) + mock.Mock(side_effect=[('', ''), ('', '')])) self.mock_object(new_gmgr, 'get_vol_option', mock.Mock()) new_gmgr.get_vol_option.return_value = ( @@ -841,11 +842,11 @@ class GlusterfsVolumeMappedLayoutTestCase(test.TestCase): assert_called_once_with(old_gmgr, snapshot)) args = (('snapshot', 'activate', 'fake_snap_id_xyz', 'force', '--mode=script'), - ('snapshot', 'clone', volume, 'fake_snap_id_xyz')) + ('snapshot', 'clone', volume, 'fake_snap_id_xyz'), + ('volume', 'start', volume)) old_gmgr.gluster_call.assert_has_calls( [mock.call(*a, log=mock.ANY) for a in args]) - args = (('volume', 'start', volume), - ('volume', 'set', volume, 'user.manila-share', share['id']), + args = (('volume', 'set', volume, 'user.manila-share', share['id']), ('volume', 'set', volume, 'user.manila-cloned-from', snapshot['share_id'])) new_gmgr.gluster_call.assert_has_calls( @@ -862,7 +863,7 @@ class GlusterfsVolumeMappedLayoutTestCase(test.TestCase): self.assertIn( new_vol_addr, self._layout.gluster_used_vols) - self.assertEqual('host1:/gv1', ret) + self.assertEqual(['host1:/gv1'], ret) def test_create_share_from_snapshot_error_unsupported_gluster_version( self): diff --git a/releasenotes/notes/bug-1922075-fix-Glusterfs-create-share-from-snapshot-failed-053a583522a6fc0e.yaml b/releasenotes/notes/bug-1922075-fix-Glusterfs-create-share-from-snapshot-failed-053a583522a6fc0e.yaml new file mode 100644 index 0000000000..109e79fe0c --- /dev/null +++ b/releasenotes/notes/bug-1922075-fix-Glusterfs-create-share-from-snapshot-failed-053a583522a6fc0e.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixed `bug #1922075 `_ + Fixed the problem that "gluster volume set nfs.rpc-auth-reject '*'" + failed when the glusterfs driver created an instance from a snapshot.