Add fake_cgsnapshot for unittest use
This patch add the missing fake object generator for CG snapshot. Change-Id: Ifee32b2d649d6a37813d116ac981cd89aeb52237 Cloese-bug: #1563770
This commit is contained in:
parent
657943b0cb
commit
0e5e631087
|
@ -0,0 +1,51 @@
|
|||
# Copyright 2016 EMC Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_versionedobjects import fields
|
||||
|
||||
from cinder import objects
|
||||
from cinder.tests.unit import fake_constants as fake
|
||||
|
||||
|
||||
def fake_db_cgsnapshot(**updates):
|
||||
db_values = {
|
||||
'id': fake.cgsnapshot_id,
|
||||
'consistencygroup_id': fake.consistency_group_id,
|
||||
'user_id': fake.user_id,
|
||||
'project_id': fake.project_id,
|
||||
}
|
||||
for name, field in objects.CGSnapshot.fields.items():
|
||||
if name in db_values:
|
||||
continue
|
||||
if field.nullable:
|
||||
db_values[name] = None
|
||||
elif field.default != fields.UnspecifiedDefault:
|
||||
db_values[name] = field.default
|
||||
else:
|
||||
raise Exception('fake_db_snapshot needs help with %s' %
|
||||
name)
|
||||
|
||||
if updates:
|
||||
db_values.update(updates)
|
||||
|
||||
return db_values
|
||||
|
||||
|
||||
def fake_cgsnapshot_obj(context, **updates):
|
||||
expected_attrs = updates.pop('expected_attrs', None)
|
||||
return objects.CGSnapshot._from_db_object(context,
|
||||
objects.CGSnapshot(),
|
||||
fake_db_cgsnapshot(
|
||||
**updates),
|
||||
expected_attrs=expected_attrs)
|
|
@ -25,6 +25,7 @@ from cinder import context
|
|||
from cinder import exception
|
||||
from cinder.objects import fields
|
||||
from cinder import test
|
||||
from cinder.tests.unit import fake_cgsnapshot
|
||||
from cinder.tests.unit import fake_consistencygroup
|
||||
from cinder.tests.unit import fake_snapshot
|
||||
from cinder.tests.unit import fake_volume
|
||||
|
@ -2776,6 +2777,7 @@ Time Remaining: 0 second(s)
|
|||
def test_create_volume_snapshot_failed(self):
|
||||
test_snapshot = EMCVNXCLIDriverTestData.convert_snapshot(
|
||||
self.testData.test_snapshot1)
|
||||
|
||||
commands = [self.testData.SNAP_CREATE_CMD(test_snapshot.name)]
|
||||
results = [FAKE_ERROR_RETURN]
|
||||
fake_cli = self.driverSetup(commands, results)
|
||||
|
@ -4236,7 +4238,9 @@ Time Remaining: 0 second(s)
|
|||
snapshot_obj = fake_snapshot.fake_snapshot_obj(
|
||||
self.testData.SNAPS_IN_SNAP_GROUP())
|
||||
snapshot_obj.consistencygroup_id = cg_name
|
||||
self.driver.create_cgsnapshot(None, self.testData.test_cgsnapshot,
|
||||
cgsnap = fake_cgsnapshot.fake_cgsnapshot_obj(
|
||||
None, **self.testData.test_cgsnapshot)
|
||||
self.driver.create_cgsnapshot(None, cgsnap,
|
||||
[snapshot_obj])
|
||||
expect_cmd = [
|
||||
mock.call(
|
||||
|
@ -4257,7 +4261,9 @@ Time Remaining: 0 second(s)
|
|||
snapshot_obj = fake_snapshot.fake_snapshot_obj(
|
||||
self.testData.SNAPS_IN_SNAP_GROUP())
|
||||
snapshot_obj.consistencygroup_id = cg_name
|
||||
self.driver.create_cgsnapshot(None, self.testData.test_cgsnapshot,
|
||||
cgsnap = fake_cgsnapshot.fake_cgsnapshot_obj(
|
||||
None, **self.testData.test_cgsnapshot)
|
||||
self.driver.create_cgsnapshot(None, cgsnap,
|
||||
[snapshot_obj])
|
||||
expect_cmd = [
|
||||
mock.call(
|
||||
|
@ -4278,8 +4284,10 @@ Time Remaining: 0 second(s)
|
|||
self.testData.SNAPS_IN_SNAP_GROUP())
|
||||
cg_name = self.testData.test_cgsnapshot['consistencygroup_id']
|
||||
snapshot_obj.consistencygroup_id = cg_name
|
||||
cg_snap = fake_cgsnapshot.fake_cgsnapshot_obj(
|
||||
None, **self.testData.test_cgsnapshot)
|
||||
self.driver.delete_cgsnapshot(None,
|
||||
self.testData.test_cgsnapshot,
|
||||
cg_snap,
|
||||
[snapshot_obj])
|
||||
expect_cmd = [
|
||||
mock.call(
|
||||
|
@ -4497,7 +4505,8 @@ Time Remaining: 0 second(s)
|
|||
'id': '222222',
|
||||
'consistencygroup_id': 'new_cg_id',
|
||||
'provider_location': None})
|
||||
src_cgsnap = self.testData.test_cgsnapshot
|
||||
src_cgsnap = fake_cgsnapshot.fake_cgsnapshot_obj(
|
||||
None, **self.testData.test_cgsnapshot)
|
||||
|
||||
snap1_in_src_cgsnap = EMCVNXCLIDriverTestData.convert_snapshot(
|
||||
self.testData.test_member_cgsnapshot)
|
||||
|
@ -4616,7 +4625,8 @@ Time Remaining: 0 second(s)
|
|||
new_cg = fake_consistencygroup.fake_consistencyobject_obj(
|
||||
None, **self.testData.test_cg)
|
||||
vol1_in_new_cg = self.testData.test_volume_cg
|
||||
src_cgsnap = self.testData.test_cgsnapshot
|
||||
src_cgsnap = fake_cgsnapshot.fake_cgsnapshot_obj(
|
||||
None, **self.testData.test_cgsnapshot)
|
||||
snap1_in_src_cgsnap = fake_snapshot.fake_snapshot_obj(
|
||||
None, **self.testData.test_member_cgsnapshot)
|
||||
src_cg = fake_consistencygroup.fake_consistencyobject_obj(
|
||||
|
@ -4634,7 +4644,8 @@ Time Remaining: 0 second(s)
|
|||
def test_create_cg_from_src_failed_with_invalid_source(self):
|
||||
new_cg = fake_consistencygroup.fake_consistencyobject_obj(
|
||||
None, **self.testData.test_cg)
|
||||
src_cgsnap = self.testData.test_cgsnapshot
|
||||
src_cgsnap = fake_cgsnapshot.fake_cgsnapshot_obj(
|
||||
None, **self.testData.test_cgsnapshot)
|
||||
vol1_in_new_cg = self.testData.test_volume_cg
|
||||
|
||||
src_cg = fake_consistencygroup.fake_consistencyobject_obj(
|
||||
|
@ -4663,7 +4674,8 @@ Time Remaining: 0 second(s)
|
|||
'id': '222222',
|
||||
'consistencygroup_id': 'new_cg_id',
|
||||
'provider_location': None})
|
||||
src_cgsnap = self.testData.test_cgsnapshot
|
||||
src_cgsnap = fake_cgsnapshot.fake_cgsnapshot_obj(
|
||||
None, **self.testData.test_cgsnapshot)
|
||||
snap1_in_src_cgsnap = EMCVNXCLIDriverTestData.convert_snapshot(
|
||||
self.testData.test_member_cgsnapshot)
|
||||
snap2_in_src_cgsnap = EMCVNXCLIDriverTestData.convert_snapshot(
|
||||
|
|
Loading…
Reference in New Issue