Creating snapshot on NFS backend fails

Fixed an issue with creating a snapshot on an NFS backend
if the snapshot name is not specified.

Closes-Bug: 1886222
Change-Id: I33da9c65ef56b3e4967170e3a0fb25f12e067876
This commit is contained in:
Alex Deiter 2020-07-03 18:32:54 +00:00
parent be4a682890
commit 11b5c9d97b
3 changed files with 14 additions and 8 deletions

View File

@ -314,7 +314,7 @@ class RemoteFsSnapDriverTestCase(test.TestCase):
mock.call(*command3, run_as_root=True)] mock.call(*command3, run_as_root=True)]
self._driver._execute.assert_has_calls(calls) self._driver._execute.assert_has_calls(calls)
def _test_create_snapshot(self, volume_in_use=False, tmp_snap=False, def _test_create_snapshot(self, display_name=None, volume_in_use=False,
encryption=False): encryption=False):
fake_snapshot_info = {} fake_snapshot_info = {}
if encryption: if encryption:
@ -329,6 +329,7 @@ class RemoteFsSnapDriverTestCase(test.TestCase):
snapshot = self._fake_snapshot snapshot = self._fake_snapshot
snapshot_path = self._fake_snapshot_path snapshot_path = self._fake_snapshot_path
snapshot.display_name = display_name
self._driver._local_path_volume_info = mock.Mock( self._driver._local_path_volume_info = mock.Mock(
return_value=mock.sentinel.fake_info_path) return_value=mock.sentinel.fake_info_path)
self._driver._read_info_file = mock.Mock( self._driver._read_info_file = mock.Mock(
@ -347,18 +348,15 @@ class RemoteFsSnapDriverTestCase(test.TestCase):
snapshot.id: fake_snapshot_file_name snapshot.id: fake_snapshot_file_name
} }
exp_acceptable_states = ['available', 'in-use', 'backing-up'] exp_acceptable_states = ['available', 'in-use', 'backing-up']
if tmp_snap: if display_name and display_name.startswith('tmp-snap-'):
exp_acceptable_states.append('downloading') exp_acceptable_states.append('downloading')
self._fake_snapshot.volume.status = 'downloading' self._fake_snapshot.volume.status = 'downloading'
display_name = 'tmp-snap-%s' % self._fake_snapshot.id
self._fake_snapshot.display_name = display_name
if volume_in_use: if volume_in_use:
snapshot.volume.status = 'backing-up' snapshot.volume.status = 'backing-up'
snapshot.volume.attach_status = 'attached' snapshot.volume.attach_status = 'attached'
expected_method_called = '_create_snapshot_online' expected_method_called = '_create_snapshot_online'
else: else:
snapshot.volume.status = 'available'
expected_method_called = '_do_create_snapshot' expected_method_called = '_do_create_snapshot'
self._driver._create_snapshot(snapshot) self._driver._create_snapshot(snapshot)
@ -389,8 +387,9 @@ class RemoteFsSnapDriverTestCase(test.TestCase):
self._driver._create_snapshot, self._driver._create_snapshot,
self._fake_snapshot) self._fake_snapshot)
def test_create_snapshot_w_image_caching(self): @ddt.data(None, 'test', 'tmp-snap-404f-404')
self._test_create_snapshot(tmp_snap=True) def test_create_snapshot_names(self, display_name):
self._test_create_snapshot(display_name=display_name)
@mock.patch('cinder.db.snapshot_get') @mock.patch('cinder.db.snapshot_get')
@mock.patch('time.sleep') @mock.patch('time.sleep')

View File

@ -1623,7 +1623,8 @@ class RemoteFSSnapDriverBase(RemoteFSDriver):
status = snapshot.volume.status status = snapshot.volume.status
acceptable_states = ['available', 'in-use', 'backing-up'] acceptable_states = ['available', 'in-use', 'backing-up']
if snapshot.display_name.startswith('tmp-snap-'): if (snapshot.display_name and
snapshot.display_name.startswith('tmp-snap-')):
# This is an internal volume snapshot. In order to support # This is an internal volume snapshot. In order to support
# image caching, we'll allow creating/deleting such snapshots # image caching, we'll allow creating/deleting such snapshots
# while having volumes in 'downloading' state. # while having volumes in 'downloading' state.

View File

@ -0,0 +1,6 @@
---
fixes:
- |
`Bug #1886222 <https://bugs.launchpad.net/cinder/+bug/1886222>`_:
Fixed an issue with creating a snapshot on an NFS backend
if the snapshot name is not specified.