Merge "Fix: nfs format info limitation"

This commit is contained in:
Zuul 2021-12-22 18:35:58 +00:00 committed by Gerrit Code Review
commit 1a2b133681
4 changed files with 55 additions and 16 deletions

View File

@ -344,6 +344,23 @@ class Volume(cleanable.CinderCleanableObject, base.CinderObject,
'False!! Fix code here') 'False!! Fix code here')
updates['use_quota'] = use_quota updates['use_quota'] = use_quota
def populate_consistencygroup(self):
"""Populate CG fields based on group fields.
Method assumes that consistencygroup_id and consistencygroup fields
have not already been set.
This is a hack to support backward compatibility of consistencygroup,
where we set the fields but don't want to write them to the DB, so we
mark them as not changed, so they won't be stored on the next save().
"""
self.consistencygroup_id = self.group_id
if self.group_id and self.obj_attr_is_set('group'):
cg = objects.ConsistencyGroup()
cg.from_group(self.group)
self.consistencygroup = cg
self.obj_reset_changes(['consistencygroup', 'consistencygroup_id'])
def create(self): def create(self):
if self.obj_attr_is_set('id'): if self.obj_attr_is_set('id'):
raise exception.ObjectActionError(action='create', raise exception.ObjectActionError(action='create',

View File

@ -29,6 +29,18 @@ from cinder.tests.unit import fake_snapshot
from cinder.tests.unit import fake_volume from cinder.tests.unit import fake_volume
from cinder.tests.unit import objects as test_objects from cinder.tests.unit import objects as test_objects
fake_group = {
'id': fake.GROUP_ID,
'user_id': fake.USER_ID,
'project_id': fake.PROJECT_ID,
'host': 'fake_host',
'availability_zone': 'fake_az',
'name': 'fake_name',
'description': 'fake_description',
'group_type_id': fake.GROUP_TYPE_ID,
'status': fields.GroupStatus.CREATING,
}
@ddt.ddt @ddt.ddt
class TestVolume(test_objects.BaseObjectsTestCase): class TestVolume(test_objects.BaseObjectsTestCase):
@ -710,3 +722,21 @@ class TestVolumeList(test_objects.BaseObjectsTestCase):
include_mock.assert_called_once_with(self.context, cluster, include_mock.assert_called_once_with(self.context, cluster,
mock.sentinel.partial_rename, mock.sentinel.partial_rename,
**filters) **filters)
@mock.patch('cinder.db.group_create',
return_value=fake_group)
def test_populate_consistencygroup(self, mock_db_grp_create):
db_volume = fake_volume.fake_db_volume()
volume = objects.Volume._from_db_object(self.context,
objects.Volume(), db_volume)
fake_grp = fake_group.copy()
del fake_grp['id']
group = objects.Group(context=self.context,
**fake_grp)
group.create()
volume.group_id = group.id
volume.group = group
volume.populate_consistencygroup()
self.assertEqual(volume.group_id, volume.consistencygroup_id)
self.assertEqual(volume.group.id, volume.consistencygroup.id)

View File

@ -324,13 +324,12 @@ class RemoteFSDriver(driver.BaseVD):
self._create_regular_file(volume_path, volume_size) self._create_regular_file(volume_path, volume_size)
self._set_rw_permissions(volume_path) self._set_rw_permissions(volume_path)
if not volume.consistencygroup_id and not volume.group_id: volume.admin_metadata['format'] = self.format
volume.admin_metadata['format'] = self.format # This is done here because when creating a volume from image,
# This is done here because when creating a volume from image, # while encountering other volume.save() method fails for
# while encountering other volume.save() method fails for # non-admins
# non-admins with volume.obj_as_admin():
with volume.obj_as_admin(): volume.save()
volume.save()
def _ensure_shares_mounted(self): def _ensure_shares_mounted(self):
"""Look for remote shares in the flags and mount them locally.""" """Look for remote shares in the flags and mount them locally."""

View File

@ -41,7 +41,6 @@ from cinder.image import image_utils
from cinder.message import api as message_api from cinder.message import api as message_api
from cinder.message import message_field from cinder.message import message_field
from cinder import objects from cinder import objects
from cinder.objects import consistencygroup
from cinder.objects import fields from cinder.objects import fields
from cinder import utils from cinder import utils
from cinder.volume.flows import common from cinder.volume.flows import common
@ -1189,14 +1188,8 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask):
"Volume driver %s not initialized", driver_name) "Volume driver %s not initialized", driver_name)
raise exception.DriverNotInitialized() raise exception.DriverNotInitialized()
# NOTE(xyang): Populate consistencygroup_id and consistencygroup # For backward compatibilty
# fields before passing to the driver. This is to support backward volume.populate_consistencygroup()
# compatibility of consistencygroup.
if volume.group_id:
volume.consistencygroup_id = volume.group_id
cg = consistencygroup.ConsistencyGroup()
cg.from_group(volume.group)
volume.consistencygroup = cg
create_type = volume_spec.pop('type', None) create_type = volume_spec.pop('type', None)
LOG.info("Volume %(volume_id)s: being created as %(create_type)s " LOG.info("Volume %(volume_id)s: being created as %(create_type)s "