Merge "tests: Don't (always) auto-create snapshot instances"

This commit is contained in:
Zuul 2024-04-09 18:56:41 +00:00 committed by Gerrit Code Review
commit 28bb87ff77
3 changed files with 14 additions and 9 deletions

View File

@ -691,9 +691,10 @@ def share_snapshot_instance_delete(context, snapshot_instance_id):
####################
def share_snapshot_create(context, values):
def share_snapshot_create(context, values, create_snapshot_instance=True):
"""Create a snapshot from the values dictionary."""
return IMPL.share_snapshot_create(context, values)
return IMPL.share_snapshot_create(
context, values, create_snapshot_instance=create_snapshot_instance)
def share_snapshot_get(context, snapshot_id, project_only=True):

View File

@ -1829,8 +1829,9 @@ class ShareSnapshotDatabaseAPITestCase(test.TestCase):
'status': expected_status,
'metadata': {'foo': 'bar'}
}
snapshots = db_api.share_snapshot_get_all(
self.ctxt, filters=filters)
snapshots = db_api.share_snapshot_get_all(self.ctxt, filters=filters)
self.assertEqual(1, len(snapshots))
for snapshot in snapshots:
s = snapshot.get('share_snapshot_metadata')
@ -1842,8 +1843,6 @@ class ShareSnapshotDatabaseAPITestCase(test.TestCase):
self.assertEqual(s[0]['key'], filter_meta_key)
self.assertEqual(s[0]['value'], filter_meta_val)
self.assertEqual(1, len(snapshots))
def test_share_snapshot_get_latest_for_share(self):
share = db_utils.create_share(size=1)
@ -1890,7 +1889,7 @@ class ShareSnapshotDatabaseAPITestCase(test.TestCase):
def test_share_snapshot_instance_get_all_with_filters_some(self, status):
expected_status = status or (constants.STATUS_CREATING,
constants.STATUS_DELETING)
expected_number = 1 if status else 3
expected_number = 1 if status else 2
filters = {
'snapshot_ids': 'fake_snapshot_id_1',
'statuses': expected_status
@ -1925,7 +1924,7 @@ class ShareSnapshotDatabaseAPITestCase(test.TestCase):
}
instances = db_api.share_snapshot_instance_get_all_with_filters(
self.ctxt, filters)
self.assertEqual(6, len(instances))
self.assertEqual(4, len(instances))
def test_share_snapshot_instance_create(self):
snapshot = db_utils.create_snapshot(with_share=True)

View File

@ -156,7 +156,12 @@ def create_snapshot(**kwargs):
'provider_location': 'fake',
}
snapshot.update(kwargs)
return db.share_snapshot_create(context.get_admin_context(), snapshot)
return db.share_snapshot_create(
context.get_admin_context(),
snapshot,
create_snapshot_instance='instances' not in snapshot,
)
def create_snapshot_instance(snapshot_id, **kwargs):