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.