Cleanup unused DB APIs, part I

There are unused DB APIs, some of them were leftovers of other features
removal, some are purely added without being used.  This change removes
these unused DB APIs.

Note that there are some DB APIs only used by unit tests, in other words
they are used in unit tests where they are not the unit of code being
tested. Those will be cleaned up in follow-up patch(es).

Change-Id: I456e64445dc8a258fdcc3c1b309f59f8adcc23e3
This commit is contained in:
Zhiteng Huang
2015-01-14 11:54:40 +08:00
parent ea64e3584a
commit aa681d40bf
3 changed files with 0 additions and 131 deletions

View File

@@ -108,20 +108,6 @@ def service_get_all_by_topic(context, topic, disabled=None):
return IMPL.service_get_all_by_topic(context, topic, disabled=disabled)
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_volume_sorted(context):
"""Get all volume services sorted by volume count.
:returns: a list of (Service, volume_count) tuples.
"""
return IMPL.service_get_all_volume_sorted(context)
def service_get_by_args(context, host, binary):
"""Get the state of an service by node name and binary."""
return IMPL.service_get_by_args(context, host, binary)
@@ -162,10 +148,6 @@ def iscsi_target_create_safe(context, values):
###############
def volume_allocate_iscsi_target(context, volume_id, host):
"""Atomically allocate a free iscsi_target from the pool."""
return IMPL.volume_allocate_iscsi_target(context, volume_id, host)
def volume_attached(context, volume_id, instance_id, host_name, mountpoint):
"""Ensure that a volume is set as attached."""
@@ -863,11 +845,6 @@ def consistencygroup_get_all(context):
return IMPL.consistencygroup_get_all(context)
def consistencygroup_get_all_by_host(context, host):
"""Get all consistencygroups belonging to a host."""
return IMPL.consistencygroup_get_all_by_host(context, host)
def consistencygroup_create(context, values):
"""Create a consistencygroup from the values dictionary."""
return IMPL.consistencygroup_create(context, values)
@@ -904,11 +881,6 @@ def cgsnapshot_get_all(context):
return IMPL.cgsnapshot_get_all(context)
def cgsnapshot_get_all_by_host(context, host):
"""Get all cgsnapshots belonging to a host."""
return IMPL.cgsnapshot_get_all_by_host(context, host)
def cgsnapshot_create(context, values):
"""Create a cgsnapshot from the values dictionary."""
return IMPL.cgsnapshot_create(context, values)

View File

@@ -386,14 +386,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)
@@ -407,24 +399,6 @@ def _service_get_all_topic_subquery(context, session, topic, subq, label):
all()
@require_admin_context
def service_get_all_volume_sorted(context):
session = get_session()
with session.begin():
topic = CONF.volume_topic
label = 'volume_gigabytes'
subq = model_query(context, models.Volume.host,
func.sum(models.Volume.size).label(label),
session=session, read_deleted="no").\
group_by(models.Volume.host).\
subquery()
return _service_get_all_topic_subquery(context,
session,
topic,
subq,
label)
@require_admin_context
def service_get_by_args(context, host, binary):
result = model_query(context, models.Service).\
@@ -997,29 +971,6 @@ def reservation_expire(context):
###################
@require_admin_context
@_retry_on_deadlock
def volume_allocate_iscsi_target(context, volume_id, host):
session = get_session()
with session.begin():
iscsi_target_ref = model_query(context, models.IscsiTarget,
session=session, read_deleted="no").\
filter_by(volume=None).\
filter_by(host=host).\
with_lockmode('update').\
first()
# NOTE(vish): if with_lockmode isn't supported, as in sqlite,
# then this has concurrency issues
if not iscsi_target_ref:
raise exception.NoMoreTargets()
iscsi_target_ref.volume_id = volume_id
session.add(iscsi_target_ref)
return iscsi_target_ref.target_num
@require_admin_context
def volume_attached(context, volume_id, instance_uuid, host_name, mountpoint):
if instance_uuid and not uuidutils.is_uuid_like(instance_uuid):
@@ -3141,12 +3092,6 @@ def consistencygroup_get_all(context):
return model_query(context, models.ConsistencyGroup).all()
@require_admin_context
def consistencygroup_get_all_by_host(context, host):
return model_query(context, models.ConsistencyGroup).\
filter_by(host=host).all()
@require_context
def consistencygroup_get_all_by_project(context, project_id):
authorize_project_context(context, project_id)
@@ -3225,11 +3170,6 @@ def cgsnapshot_get_all(context):
return model_query(context, models.Cgsnapshot).all()
@require_admin_context
def cgsnapshot_get_all_by_host(context, host):
return model_query(context, models.Cgsnapshot).filter_by(host=host).all()
@require_admin_context
def cgsnapshot_get_all_by_group(context, group_id):
return model_query(context, models.Cgsnapshot).\

View File

@@ -196,19 +196,6 @@ class DBAPIServiceTestCase(BaseTest):
real = db.service_get_all_by_topic(self.ctxt, 't1')
self._assertEqualListsOfObjects(expected, real)
def test_service_get_all_by_host(self):
values = [
{'host': 'host1', 'topic': 't1'},
{'host': 'host1', 'topic': 't1'},
{'host': 'host2', 'topic': 't1'},
{'host': 'host3', 'topic': 't2'}
]
services = [self._create_service(vals) for vals in values]
expected = services[:2]
real = db.service_get_all_by_host(self.ctxt, 'host1')
self._assertEqualListsOfObjects(expected, real)
def test_service_get_by_args(self):
values = [
{'host': 'host1', 'binary': 'a'},
@@ -227,22 +214,6 @@ class DBAPIServiceTestCase(BaseTest):
db.service_get_by_args,
self.ctxt, 'non-exists-host', 'a')
def test_service_get_all_volume_sorted(self):
values = [
({'host': 'h1', 'binary': 'a', 'topic': CONF.volume_topic},
100),
({'host': 'h2', 'binary': 'b', 'topic': CONF.volume_topic},
200),
({'host': 'h3', 'binary': 'b', 'topic': CONF.volume_topic},
300)]
services = []
for vals, size in values:
services.append(self._create_service(vals))
db.volume_create(self.ctxt, {'host': vals['host'], 'size': size})
for service, size in db.service_get_all_volume_sorted(self.ctxt):
self._assertEqualObjects(services.pop(0), service)
self.assertEqual(values.pop(0)[1], size)
class DBAPIVolumeTestCase(BaseTest):
@@ -253,20 +224,6 @@ class DBAPIVolumeTestCase(BaseTest):
self.assertTrue(uuidutils.is_uuid_like(volume['id']))
self.assertEqual(volume.host, 'host1')
def test_volume_allocate_iscsi_target_no_more_targets(self):
self.assertRaises(exception.NoMoreTargets,
db.volume_allocate_iscsi_target,
self.ctxt, 42, 'host1')
def test_volume_allocate_iscsi_target(self):
host = 'host1'
volume = db.volume_create(self.ctxt, {'host': host})
db.iscsi_target_create_safe(self.ctxt, {'host': host,
'target_num': 42})
target_num = db.volume_allocate_iscsi_target(self.ctxt, volume['id'],
host)
self.assertEqual(target_num, 42)
def test_volume_attached_invalid_uuid(self):
self.assertRaises(exception.InvalidUUID, db.volume_attached, self.ctxt,
42, 'invalid-uuid', None, '/tmp')