Merge "Cleanup unused DB APIs"

This commit is contained in:
Jenkins 2016-07-01 19:42:26 +00:00 committed by Gerrit Code Review
commit 982cb6ceb1
4 changed files with 1 additions and 246 deletions

View File

@ -105,11 +105,6 @@ def service_get_all_by_topic(context, topic):
return IMPL.service_get_all_by_topic(context, topic)
def service_get_all_by_host(context, host):
"""Get all services for a given host."""
return IMPL.service_get_all_by_host(context, host)
def service_get_all_share_sorted(context):
"""Get all share services sorted by share count.
@ -236,21 +231,6 @@ def quota_usage_update(context, project_id, user_id, resource, **kwargs):
###################
def reservation_create(context, uuid, usage, project_id, user_id, resource,
delta, expire):
"""Create a reservation for the given project and resource."""
return IMPL.reservation_create(context, uuid, usage, project_id,
user_id, resource, delta, expire)
def reservation_get(context, uuid):
"""Retrieve a reservation or raise if it does not exist."""
return IMPL.reservation_get(context, uuid)
###################
def quota_reserve(context, resources, quotas, user_quotas, deltas, expire,
until_refresh, max_age, project_id=None, user_id=None):
"""Check quotas and create appropriate reservations."""
@ -354,11 +334,6 @@ def share_create(context, share_values, create_share_instance=True):
create_share_instance=create_share_instance)
def share_data_get_for_project(context, project_id, session=None):
"""Get (share_count, gigabytes) for project."""
return IMPL.share_data_get_for_project(context, project_id)
def share_update(context, share_id, values):
"""Update share fields."""
return IMPL.share_update(context, share_id, values)
@ -440,11 +415,6 @@ def share_access_get_all_for_share(context, share_id):
return IMPL.share_access_get_all_for_share(context, share_id)
def share_instance_access_get_all(context, access_id, session=None):
"""Get access rules to all share instances."""
return IMPL.share_instance_access_get_all(context, access_id, session=None)
def share_access_get_all_for_instance(context, instance_id, session=None):
"""Get all access rules related to a certain share instance."""
return IMPL.share_access_get_all_for_instance(
@ -517,16 +487,6 @@ def share_snapshot_create(context, values):
return IMPL.share_snapshot_create(context, values)
def snapshot_data_get_for_project(context, project_id, session=None):
"""Get (snapshot_count, gigabytes) for project."""
return IMPL.snapshot_data_get_for_project(context, project_id)
def share_snapshot_destroy(context, snapshot_id):
"""Destroy the snapshot or raise if it does not exist."""
return IMPL.share_snapshot_destroy(context, snapshot_id)
def share_snapshot_get(context, snapshot_id):
"""Get a snapshot or raise if it does not exist."""
return IMPL.share_snapshot_get(context, snapshot_id)
@ -566,13 +526,6 @@ def share_snapshot_update(context, snapshot_id, values):
return IMPL.share_snapshot_update(context, snapshot_id, values)
def share_snapshot_data_get_for_project(context, project_id, session=None):
"""Get count and gigabytes used for snapshots for specified project."""
return IMPL.share_snapshot_data_get_for_project(context,
project_id,
session=None)
###################
def security_service_create(context, values):
"""Create security service DB record."""
@ -874,14 +827,6 @@ def share_type_destroy(context, id):
return IMPL.share_type_destroy(context, id)
def volume_get_active_by_window(context, begin, end=None, project_id=None):
"""Get all the volumes inside the window.
Specifying a project_id will filter for a certain project.
"""
return IMPL.volume_get_active_by_window(context, begin, end, project_id)
####################
@ -948,12 +893,6 @@ def consistency_group_get_all(context, detailed=True):
return IMPL.consistency_group_get_all(context, detailed=detailed)
def consistency_group_get_all_by_host(context, host, detailed=True):
"""Get all consistency groups belonging to a host."""
return IMPL.consistency_group_get_all_by_host(context, host,
detailed=detailed)
def consistency_group_create(context, values):
"""Create a consistency group from the values dictionary."""
return IMPL.consistency_group_create(context, values)
@ -1087,15 +1026,6 @@ def share_replicas_get_available_active_replica(context, share_id,
with_share_data=with_share_data)
def share_replicas_get_active_replicas_by_share(context, share_id,
with_share_server=False,
with_share_data=False):
"""Returns all active replicas for a given share."""
return IMPL.share_replicas_get_active_replicas_by_share(
context, share_id, with_share_server=with_share_server,
with_share_data=with_share_data)
def share_replica_get(context, replica_id, with_share_server=False,
with_share_data=False):
"""Get share replica by id."""

View File

@ -370,14 +370,6 @@ def service_get_by_host_and_topic(context, host, topic):
return result
@require_admin_context
def service_get_all_by_host(context, host):
return model_query(
context, models.Service, read_deleted="no").\
filter_by(host=host).\
all()
@require_admin_context
def _service_get_all_topic_subquery(context, session, topic, subq, label):
sort_value = getattr(subq.c, label)
@ -735,25 +727,6 @@ def quota_usage_update(context, project_id, user_id, resource, **kwargs):
###################
@require_context
def reservation_get(context, uuid, session=None):
result = model_query(context, models.Reservation, session=session,
read_deleted="no").\
filter_by(uuid=uuid).first()
if not result:
raise exception.ReservationNotFound(uuid=uuid)
return result
@require_admin_context
def reservation_create(context, uuid, usage, project_id, user_id, resource,
delta, expire):
return _reservation_create(context, uuid, usage, project_id, user_id,
resource, delta, expire)
def _reservation_create(context, uuid, usage, project_id, user_id, resource,
delta, expire, session=None):
reservation_ref = models.Reservation()
@ -1393,24 +1366,6 @@ def share_replicas_get_available_active_replica(context, share_id,
return result
@require_context
def share_replicas_get_active_replicas_by_share(context, share_id,
with_share_data=False,
with_share_server=False,
session=None):
"""Returns all active replicas for a given share."""
session = session or get_session()
result = _share_replica_get_with_filters(
context, with_share_server=with_share_server, share_id=share_id,
replica_state=constants.REPLICA_STATE_ACTIVE, session=session).all()
if with_share_data:
result = _set_replica_share_data(context, result, session)
return result
@require_context
def share_replica_get(context, replica_id, with_share_data=False,
with_share_server=False, session=None):
@ -2084,21 +2039,6 @@ def snapshot_data_get_for_project(context, project_id, user_id, session=None):
return (result[0] or 0, result[1] or 0)
@require_context
def share_snapshot_destroy(context, snapshot_id):
session = get_session()
with session.begin():
snapshot_ref = share_snapshot_get(context, snapshot_id,
session=session)
if len(snapshot_ref.instances) > 0:
msg = _("Snapshot %(id)s has %(count)s snapshot instances.") % {
'id': snapshot_id, 'count': len(snapshot_ref.instances)}
raise exception.InvalidShareSnapshot(msg)
snapshot_ref.soft_delete(session=session)
@require_context
def share_snapshot_get(context, snapshot_id, session=None):
result = model_query(context, models.ShareSnapshot, session=session,
@ -2193,21 +2133,6 @@ def share_snapshot_get_all_for_share(context, share_id, filters=None,
)
@require_context
def share_snapshot_data_get_for_project(context, project_id, session=None):
authorize_project_context(context, project_id)
result = model_query(context, models.ShareSnapshot,
func.count(models.ShareSnapshot.id),
func.sum(models.ShareSnapshot.share_size),
read_deleted="no",
session=session).\
filter_by(project_id=project_id).\
first()
# NOTE(vish): convert None to 0
return (result[0] or 0, result[1] or 0)
@require_context
@oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True)
def share_snapshot_update(context, snapshot_id, values):
@ -3521,21 +3446,6 @@ def consistency_group_get_all(context, detailed=True):
return values
@require_admin_context
def consistency_group_get_all_by_host(context, host, detailed=True):
query = _consistency_group_get_all_query(context).filter_by(host=host)
if detailed:
return query.options(joinedload('share_types')).all()
else:
query = query.with_entities(models.ConsistencyGroup.id,
models.ConsistencyGroup.name)
values = []
for item in query.all():
id, name = item
values.append({"id": id, "name": name})
return values
@require_context
def consistency_group_get_all_by_project(context, project_id, detailed=True):
authorize_project_context(context, project_id)

View File

@ -398,53 +398,6 @@ class ShareDatabaseAPITestCase(test.TestCase):
expected_share_keys.issubset(replica_share_2.keys()))
self.assertIsNone(replica_share_3)
def test_share_replicas_get_active_replicas_by_share(self):
db_utils.create_share_replica(
id='Replica1',
share_id='FAKE_SHARE_ID1',
status=constants.STATUS_AVAILABLE,
replica_state=constants.REPLICA_STATE_ACTIVE)
db_utils.create_share_replica(
id='Replica2',
status=constants.STATUS_AVAILABLE,
share_id='FAKE_SHARE_ID1',
replica_state=constants.REPLICA_STATE_ACTIVE)
db_utils.create_share_replica(
id='Replica3',
status=constants.STATUS_AVAILABLE,
share_id='FAKE_SHARE_ID2',
replica_state=constants.REPLICA_STATE_ACTIVE)
db_utils.create_share_replica(
id='Replica4',
status=constants.STATUS_ERROR,
share_id='FAKE_SHARE_ID2',
replica_state=constants.REPLICA_STATE_ACTIVE)
db_utils.create_share_replica(
id='Replica5',
status=constants.STATUS_AVAILABLE,
share_id='FAKE_SHARE_ID2',
replica_state=constants.REPLICA_STATE_IN_SYNC)
db_utils.create_share_replica(
id='Replica6',
share_id='FAKE_SHARE_ID3',
status=constants.STATUS_AVAILABLE,
replica_state=constants.REPLICA_STATE_IN_SYNC)
def get_active_replica_ids(share_id):
active_replicas = (
db_api.share_replicas_get_active_replicas_by_share(
self.ctxt, share_id)
)
return [r['id'] for r in active_replicas]
active_ids_shr1 = get_active_replica_ids('FAKE_SHARE_ID1')
active_ids_shr2 = get_active_replica_ids('FAKE_SHARE_ID2')
active_ids_shr3 = get_active_replica_ids('FAKE_SHARE_ID3')
self.assertEqual(active_ids_shr1, ['Replica1', 'Replica2'])
self.assertEqual(active_ids_shr2, ['Replica3', 'Replica4'])
self.assertEqual([], active_ids_shr3)
def test_share_replica_get_exception(self):
replica = db_utils.create_share_replica(share_id='FAKE_SHARE_ID')
@ -608,34 +561,6 @@ class ConsistencyGroupDatabaseAPITestCase(test.TestCase):
cg = cgs[0]
self.assertDictMatch(dict(expected_cg), dict(cg))
def test_consistency_group_get_all_by_host(self):
fake_host = 'my_fake_host'
expected_cg = db_utils.create_consistency_group(host=fake_host)
db_utils.create_consistency_group()
cgs = db_api.consistency_group_get_all_by_host(self.ctxt, fake_host,
detailed=False)
self.assertEqual(1, len(cgs))
cg = cgs[0]
self.assertEqual(2, len(dict(cg).keys()))
self.assertEqual(expected_cg['id'], cg['id'])
self.assertEqual(expected_cg['name'], cg['name'])
def test_consistency_group_get_all_by_host_with_details(self):
fake_host = 'my_fake_host'
expected_cg = db_utils.create_consistency_group(host=fake_host)
db_utils.create_consistency_group()
cgs = db_api.consistency_group_get_all_by_host(self.ctxt,
fake_host,
detailed=True)
self.assertEqual(1, len(cgs))
cg = cgs[0]
self.assertDictMatch(dict(expected_cg), dict(cg))
self.assertEqual(fake_host, cg['host'])
def test_consistency_group_get_all_by_project(self):
fake_project = 'fake_project'
expected_cg = db_utils.create_consistency_group(
@ -1044,14 +969,6 @@ class ShareSnapshotDatabaseAPITestCase(test.TestCase):
self.assertEqual(1, len(snapshot['instances']))
self.assertEqual(first_instance_id, snapshot['instance']['id'])
def test_share_snapshot_destroy_has_instances(self):
snapshot = db_utils.create_snapshot(with_share=True)
self.assertRaises(exception.InvalidShareSnapshot,
db_api.share_snapshot_destroy,
context.get_admin_context(),
snapshot['id'])
class ShareExportLocationsDatabaseAPITestCase(test.TestCase):

View File

@ -1764,7 +1764,7 @@ class ShareAPITestCase(test.TestCase):
db_api.share_get.return_value = share
access = db_utils.create_access(share_id=share['id'])
share_instance = share.instances[0]
db_api.share_instance_access_get_all.return_value = [share_instance, ]
self.api.deny_access(self.context, share, access)
db_api.share_get.assert_called_once_with(self.context, share['id'])
share_api.policy.check_policy.assert_called_once_with(
@ -1773,13 +1773,11 @@ class ShareAPITestCase(test.TestCase):
self.context, share_instance, access)
@mock.patch.object(db_api, 'share_get', mock.Mock())
@mock.patch.object(db_api, 'share_instance_access_get_all', mock.Mock())
@mock.patch.object(db_api, 'share_access_delete', mock.Mock())
def test_deny_access_error_no_share_instance_mapping(self):
share = db_utils.create_share(status=constants.STATUS_AVAILABLE)
db_api.share_get.return_value = share
access = db_utils.create_access(share_id=share['id'])
db_api.share_instance_access_get_all.return_value = []
self.api.deny_access(self.context, share, access)