Merge "Improve DB method naming consistency"

This commit is contained in:
Jenkins 2017-01-13 17:53:31 +00:00 committed by Gerrit Code Review
commit 17b374a9a0
12 changed files with 122 additions and 107 deletions

View File

@ -106,9 +106,9 @@ def main():
'audit_period_ending': str(end),
}
volumes = objects.VolumeList.get_active_by_window(admin_context,
begin,
end)
volumes = objects.VolumeList.get_all_active_by_window(admin_context,
begin,
end)
LOG.info(_LI("Found %d volumes"), len(volumes))
for volume_ref in volumes:
try:
@ -178,8 +178,8 @@ def main():
LOG.exception(_LE("Delete volume notification failed: %s"),
exc_msg, resource=volume_ref)
snapshots = objects.SnapshotList.get_active_by_window(admin_context,
begin, end)
snapshots = objects.SnapshotList.get_all_active_by_window(admin_context,
begin, end)
LOG.info(_LI("Found %d snapshots"), len(snapshots))
for snapshot_ref in snapshots:
try:
@ -248,8 +248,8 @@ def main():
LOG.exception(_LE("Delete snapshot notification failed: %s"),
exc_msg, resource=snapshot_ref)
backups = objects.BackupList.get_active_by_window(admin_context,
begin, end)
backups = objects.BackupList.get_all_active_by_window(admin_context,
begin, end)
LOG.info(_LI("Found %d backups"), len(backups))
for backup_ref in backups:

View File

@ -433,13 +433,13 @@ def snapshot_get_all_by_project(context, project_id, filters=None, marker=None,
sort_dirs, offset)
def snapshot_get_by_host(context, host, filters=None):
def snapshot_get_all_by_host(context, host, filters=None):
"""Get all snapshots belonging to a host.
:param host: Include include snapshots only for specified host.
:param filters: Filters for the query in the form of key/value.
"""
return IMPL.snapshot_get_by_host(context, host, filters)
return IMPL.snapshot_get_all_by_host(context, host, filters)
def snapshot_get_all_for_cgsnapshot(context, project_id):
@ -473,12 +473,14 @@ def snapshot_data_get_for_project(context, project_id, volume_type_id=None):
volume_type_id)
def snapshot_get_active_by_window(context, begin, end=None, project_id=None):
def snapshot_get_all_active_by_window(context, begin, end=None,
project_id=None):
"""Get all the snapshots inside the window.
Specifying a project_id will filter for a certain project.
"""
return IMPL.snapshot_get_active_by_window(context, begin, end, project_id)
return IMPL.snapshot_get_all_active_by_window(context, begin, end,
project_id)
####################
@ -643,12 +645,13 @@ def volume_type_destroy(context, id):
return IMPL.volume_type_destroy(context, id)
def volume_get_active_by_window(context, begin, end=None, project_id=None):
def volume_get_all_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)
return IMPL.volume_get_all_active_by_window(context, begin, end,
project_id)
def volume_type_access_get_all(context, type_id):
@ -1053,9 +1056,9 @@ def quota_class_get(context, class_name, resource):
return IMPL.quota_class_get(context, class_name, resource)
def quota_class_get_default(context):
def quota_class_get_defaults(context):
"""Retrieve all default quotas."""
return IMPL.quota_class_get_default(context)
return IMPL.quota_class_get_defaults(context)
def quota_class_get_all_by_name(context, class_name):
@ -1178,12 +1181,13 @@ def backup_get_all_by_volume(context, volume_id, filters=None):
filters=filters)
def backup_get_active_by_window(context, begin, end=None, project_id=None):
def backup_get_all_active_by_window(context, begin, end=None, project_id=None):
"""Get all the backups inside the window.
Specifying a project_id will filter for a certain project.
"""
return IMPL.backup_get_active_by_window(context, begin, end, project_id)
return IMPL.backup_get_all_active_by_window(context, begin, end,
project_id)
def backup_update(context, backup_id, values):

View File

@ -817,7 +817,7 @@ def quota_allocated_get_all_by_project(context, project_id):
@require_context
def _quota_get_by_resource(context, resource, session=None):
def _quota_get_all_by_resource(context, resource, session=None):
rows = model_query(context, models.Quota,
session=session,
read_deleted='no').filter_by(
@ -853,7 +853,7 @@ def quota_update(context, project_id, resource, limit):
def quota_update_resource(context, old_res, new_res):
session = get_session()
with session.begin():
quotas = _quota_get_by_resource(context, old_res, session=session)
quotas = _quota_get_all_by_resource(context, old_res, session=session)
for quota in quotas:
quota.resource = new_res
@ -897,7 +897,7 @@ def quota_class_get(context, class_name, resource):
return _quota_class_get(context, class_name, resource)
def quota_class_get_default(context):
def quota_class_get_defaults(context):
rows = model_query(context, models.QuotaClass,
read_deleted="no").\
filter_by(class_name=_DEFAULT_QUOTA_NAME).all()
@ -2849,7 +2849,7 @@ def snapshot_get_all_for_volume(context, volume_id):
@require_context
def snapshot_get_by_host(context, host, filters=None):
def snapshot_get_all_by_host(context, host, filters=None):
if filters and not is_valid_model_filters(models.Snapshot, filters):
return []
@ -2968,7 +2968,8 @@ def snapshot_data_get_for_project(context, project_id, volume_type_id=None):
@require_context
def snapshot_get_active_by_window(context, begin, end=None, project_id=None):
def snapshot_get_all_active_by_window(context, begin, end=None,
project_id=None):
"""Return snapshots that were active during window."""
query = model_query(context, models.Snapshot, read_deleted="yes")
@ -3853,10 +3854,10 @@ def group_type_destroy(context, id):
@require_context
def volume_get_active_by_window(context,
begin,
end=None,
project_id=None):
def volume_get_all_active_by_window(context,
begin,
end=None,
project_id=None):
"""Return volumes that were active during window."""
query = model_query(context, models.Volume, read_deleted="yes")
query = query.filter(or_(models.Volume.deleted_at == None, # noqa
@ -4161,7 +4162,7 @@ def qos_specs_create(context, values):
session = get_session()
with session.begin():
try:
_qos_specs_get_by_name(context, values['name'], session)
_qos_specs_get_all_by_name(context, values['name'], session)
raise exception.QoSSpecsExists(specs_id=values['name'])
except exception.QoSSpecsNotFound:
pass
@ -4205,7 +4206,7 @@ def qos_specs_create(context, values):
@require_admin_context
def _qos_specs_get_by_name(context, name, session=None, inactive=False):
def _qos_specs_get_all_by_name(context, name, session=None, inactive=False):
read_deleted = 'yes' if inactive else 'no'
results = model_query(context, models.QualityOfServiceSpecs,
read_deleted=read_deleted, session=session). \
@ -4220,7 +4221,8 @@ def _qos_specs_get_by_name(context, name, session=None, inactive=False):
@require_admin_context
def _qos_specs_get_ref(context, qos_specs_id, session=None, inactive=False):
def _qos_specs_get_all_ref(context, qos_specs_id, session=None,
inactive=False):
read_deleted = 'yes' if inactive else 'no'
result = model_query(context, models.QualityOfServiceSpecs,
read_deleted=read_deleted, session=session). \
@ -4266,7 +4268,8 @@ def _dict_with_qos_specs(rows):
@require_admin_context
def qos_specs_get(context, qos_specs_id, inactive=False):
rows = _qos_specs_get_ref(context, qos_specs_id, None, inactive)
rows = _qos_specs_get_all_ref(context, qos_specs_id, None, inactive)
return _dict_with_qos_specs(rows)[0]
@ -4344,7 +4347,7 @@ def _qos_specs_get(context, qos_spec_id, session=None):
@require_admin_context
def qos_specs_get_by_name(context, name, inactive=False):
rows = _qos_specs_get_by_name(context, name, None, inactive)
rows = _qos_specs_get_all_by_name(context, name, None, inactive)
return _dict_with_qos_specs(rows)[0]
@ -4403,7 +4406,7 @@ def qos_specs_item_delete(context, qos_specs_id, key):
def qos_specs_delete(context, qos_specs_id):
session = get_session()
with session.begin():
_qos_specs_get_ref(context, qos_specs_id, session)
_qos_specs_get_all_ref(context, qos_specs_id, session)
updated_values = {'deleted': True,
'deleted_at': timeutils.utcnow(),
'updated_at': literal_column('updated_at')}
@ -4443,7 +4446,7 @@ def qos_specs_update(context, qos_specs_id, updates):
session = get_session()
with session.begin():
# make sure qos specs exists
_qos_specs_get_ref(context, qos_specs_id, session)
_qos_specs_get_all_ref(context, qos_specs_id, session)
specs = updates.get('specs', {})
if 'consumer' in updates:
@ -4885,7 +4888,7 @@ def backup_get_all_by_volume(context, volume_id, filters=None):
@require_context
def backup_get_active_by_window(context, begin, end=None, project_id=None):
def backup_get_all_active_by_window(context, begin, end=None, project_id=None):
"""Return backups that were active during window."""
query = model_query(context, models.Backup, read_deleted="yes")

View File

@ -192,8 +192,8 @@ class BackupList(base.ObjectListBase, base.CinderObject):
backups)
@classmethod
def get_active_by_window(cls, context, begin, end):
backups = db.backup_get_active_by_window(context, begin, end)
def get_all_active_by_window(cls, context, begin, end):
backups = db.backup_get_all_active_by_window(context, begin, end)
return base.obj_make_list(context, cls(context), objects.Backup,
backups)

View File

@ -288,7 +288,7 @@ class SnapshotList(base.ObjectListBase, base.CinderObject):
@classmethod
def get_by_host(cls, context, host, filters=None):
snapshots = db.snapshot_get_by_host(context, host, filters)
snapshots = db.snapshot_get_all_by_host(context, host, filters)
expected_attrs = Snapshot._get_expected_attrs(context)
return base.obj_make_list(context, cls(context), objects.Snapshot,
snapshots, expected_attrs=expected_attrs)
@ -312,8 +312,8 @@ class SnapshotList(base.ObjectListBase, base.CinderObject):
snapshots, expected_attrs=expected_attrs)
@classmethod
def get_active_by_window(cls, context, begin, end):
snapshots = db.snapshot_get_active_by_window(context, begin, end)
def get_all_active_by_window(cls, context, begin, end):
snapshots = db.snapshot_get_all_active_by_window(context, begin, end)
expected_attrs = Snapshot._get_expected_attrs(context)
return base.obj_make_list(context, cls(context), objects.Snapshot,
snapshots, expected_attrs=expected_attrs)

View File

@ -629,8 +629,8 @@ class VolumeList(base.ObjectListBase, base.CinderObject):
return volumes
@classmethod
def get_active_by_window(cls, context, begin, end):
volumes = db.volume_get_active_by_window(context, begin, end)
def get_all_active_by_window(cls, context, begin, end):
volumes = db.volume_get_all_active_by_window(context, begin, end)
expected_attrs = cls._get_expected_attrs(context)
return base.obj_make_list(context, cls(context), objects.Volume,
volumes, expected_attrs=expected_attrs)

View File

@ -103,7 +103,7 @@ class DbQuotaDriver(object):
def get_default(self, context, resource, project_id):
"""Get a specific default quota for a resource."""
default_quotas = db.quota_class_get_default(context)
default_quotas = db.quota_class_get_defaults(context)
return default_quotas.get(resource.name, resource.default)
def get_defaults(self, context, resources, project_id=None):
@ -120,7 +120,7 @@ class DbQuotaDriver(object):
quotas = {}
default_quotas = {}
if CONF.use_default_quota_class:
default_quotas = db.quota_class_get_default(context)
default_quotas = db.quota_class_get_defaults(context)
for resource in resources.values():
if default_quotas:
@ -152,7 +152,7 @@ class DbQuotaDriver(object):
default_quotas = {}
class_quotas = db.quota_class_get_all_by_name(context, quota_class)
if defaults:
default_quotas = db.quota_class_get_default(context)
default_quotas = db.quota_class_get_defaults(context)
for resource in resources.values():
if resource.name in class_quotas:
quotas[resource.name] = class_quotas[resource.name]

View File

@ -241,7 +241,7 @@ class TestSnapshotList(test_objects.BaseObjectsTestCase):
None, None, None, None, None)
@mock.patch('cinder.objects.Volume.get_by_id')
@mock.patch('cinder.db.snapshot_get_by_host',
@mock.patch('cinder.db.snapshot_get_all_by_host',
return_value=[fake_db_snapshot])
def test_get_by_host(self, get_by_host, volume_get_by_id):
fake_volume_obj = fake_volume.fake_volume_obj(self.context)
@ -282,14 +282,14 @@ class TestSnapshotList(test_objects.BaseObjectsTestCase):
TestSnapshot._compare(self, fake_snapshot_obj, snapshots[0])
@mock.patch('cinder.objects.volume.Volume.get_by_id')
@mock.patch('cinder.db.snapshot_get_active_by_window',
@mock.patch('cinder.db.snapshot_get_all_active_by_window',
return_value=[fake_db_snapshot])
def test_get_active_by_window(self, get_active_by_window,
volume_get_by_id):
def test_get_all_active_by_window(self, get_all_active_by_window,
volume_get_by_id):
fake_volume_obj = fake_volume.fake_volume_obj(self.context)
volume_get_by_id.return_value = fake_volume_obj
snapshots = objects.SnapshotList.get_active_by_window(
snapshots = objects.SnapshotList.get_all_active_by_window(
self.context, mock.sentinel.begin, mock.sentinel.end)
self.assertEqual(1, len(snapshots))
TestSnapshot._compare(self, fake_snapshot_obj, snapshots[0])

View File

@ -1565,7 +1565,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
last_completed_audit_period.assert_called_once_with()
@mock.patch('cinder.volume.utils.notify_about_volume_usage')
@mock.patch('cinder.objects.volume.VolumeList.get_active_by_window')
@mock.patch('cinder.objects.volume.VolumeList.get_all_active_by_window')
@mock.patch('cinder.utils.last_completed_audit_period')
@mock.patch('cinder.rpc.init')
@mock.patch('cinder.version.version_string')
@ -1576,7 +1576,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
get_logger, version_string,
rpc_init,
last_completed_audit_period,
volume_get_active_by_window,
volume_get_all_active_by_window,
notify_about_volume_usage):
CONF.set_override('send_actions', True)
CONF.set_override('start_time', '2014-01-01 01:00:00')
@ -1593,7 +1593,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
volume1 = mock.MagicMock(id=fake.VOLUME_ID, project_id=fake.PROJECT_ID,
created_at=volume1_created,
deleted_at=volume1_deleted)
volume_get_active_by_window.return_value = [volume1]
volume_get_all_active_by_window.return_value = [volume1]
extra_info = {
'audit_period_beginning': str(begin),
'audit_period_ending': str(end),
@ -1620,7 +1620,8 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
get_logger.assert_called_once_with('cinder')
rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
volume_get_all_active_by_window.assert_called_once_with(ctxt, begin,
end)
notify_about_volume_usage.assert_has_calls([
mock.call(ctxt, volume1, 'exists', extra_usage_info=extra_info),
mock.call(ctxt, volume1, 'create.start',
@ -1630,7 +1631,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
])
@mock.patch('cinder.volume.utils.notify_about_volume_usage')
@mock.patch('cinder.objects.volume.VolumeList.get_active_by_window')
@mock.patch('cinder.objects.volume.VolumeList.get_all_active_by_window')
@mock.patch('cinder.utils.last_completed_audit_period')
@mock.patch('cinder.rpc.init')
@mock.patch('cinder.version.version_string')
@ -1641,7 +1642,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
get_logger, version_string,
rpc_init,
last_completed_audit_period,
volume_get_active_by_window,
volume_get_all_active_by_window,
notify_about_volume_usage):
CONF.set_override('send_actions', True)
CONF.set_override('start_time', '2014-01-01 01:00:00')
@ -1658,7 +1659,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
volume1 = mock.MagicMock(id=fake.VOLUME_ID, project_id=fake.PROJECT_ID,
created_at=volume1_created,
deleted_at=volume1_deleted)
volume_get_active_by_window.return_value = [volume1]
volume_get_all_active_by_window.return_value = [volume1]
extra_info = {
'audit_period_beginning': str(begin),
'audit_period_ending': str(end),
@ -1689,7 +1690,8 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
get_logger.assert_called_once_with('cinder')
rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
volume_get_all_active_by_window.assert_called_once_with(ctxt, begin,
end)
notify_about_volume_usage.assert_has_calls([
mock.call(ctxt, volume1, 'exists', extra_usage_info=extra_info),
mock.call(ctxt, volume1, 'create.start',
@ -1703,9 +1705,10 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
])
@mock.patch('cinder.volume.utils.notify_about_snapshot_usage')
@mock.patch('cinder.objects.snapshot.SnapshotList.get_active_by_window')
@mock.patch('cinder.objects.snapshot.SnapshotList.'
'get_all_active_by_window')
@mock.patch('cinder.volume.utils.notify_about_volume_usage')
@mock.patch('cinder.objects.volume.VolumeList.get_active_by_window')
@mock.patch('cinder.objects.volume.VolumeList.get_all_active_by_window')
@mock.patch('cinder.utils.last_completed_audit_period')
@mock.patch('cinder.rpc.init')
@mock.patch('cinder.version.version_string')
@ -1716,9 +1719,9 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
log_setup, get_logger,
version_string, rpc_init,
last_completed_audit_period,
volume_get_active_by_window,
volume_get_all_active_by_window,
notify_about_volume_usage,
snapshot_get_active_by_window,
snapshot_get_all_active_by_window,
notify_about_snapshot_usage):
CONF.set_override('send_actions', True)
CONF.set_override('start_time', '2014-01-01 01:00:00')
@ -1736,8 +1739,8 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
project_id=fake.PROJECT_ID,
created_at=snapshot1_created,
deleted_at=snapshot1_deleted)
volume_get_active_by_window.return_value = []
snapshot_get_active_by_window.return_value = [snapshot1]
volume_get_all_active_by_window.return_value = []
snapshot_get_all_active_by_window.return_value = [snapshot1]
extra_info = {
'audit_period_beginning': str(begin),
'audit_period_ending': str(end),
@ -1767,7 +1770,8 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
get_logger.assert_called_once_with('cinder')
rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
volume_get_all_active_by_window.assert_called_once_with(ctxt, begin,
end)
self.assertFalse(notify_about_volume_usage.called)
notify_about_snapshot_usage.assert_has_calls([
mock.call(ctxt, snapshot1, 'exists', extra_info),
@ -1778,9 +1782,9 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
])
@mock.patch('cinder.volume.utils.notify_about_backup_usage')
@mock.patch('cinder.objects.backup.BackupList.get_active_by_window')
@mock.patch('cinder.objects.backup.BackupList.get_all_active_by_window')
@mock.patch('cinder.volume.utils.notify_about_volume_usage')
@mock.patch('cinder.objects.volume.VolumeList.get_active_by_window')
@mock.patch('cinder.objects.volume.VolumeList.get_all_active_by_window')
@mock.patch('cinder.utils.last_completed_audit_period')
@mock.patch('cinder.rpc.init')
@mock.patch('cinder.version.version_string')
@ -1788,9 +1792,9 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
def test_main_send_backup_error(self, get_admin_context,
version_string, rpc_init,
last_completed_audit_period,
volume_get_active_by_window,
volume_get_all_active_by_window,
notify_about_volume_usage,
backup_get_active_by_window,
backup_get_all_active_by_window,
notify_about_backup_usage):
CONF.set_override('send_actions', True)
CONF.set_override('start_time', '2014-01-01 01:00:00')
@ -1808,8 +1812,8 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
project_id=fake.PROJECT_ID,
created_at=backup1_created,
deleted_at=backup1_deleted)
volume_get_active_by_window.return_value = []
backup_get_active_by_window.return_value = [backup1]
volume_get_all_active_by_window.return_value = []
backup_get_all_active_by_window.return_value = [backup1]
extra_info = {
'audit_period_beginning': str(begin),
'audit_period_ending': str(end),
@ -1832,7 +1836,8 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
self.assertEqual(CONF.version, version.version_string())
rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
volume_get_all_active_by_window.assert_called_once_with(ctxt,
begin, end)
self.assertFalse(notify_about_volume_usage.called)
notify_about_backup_usage.assert_any_call(ctxt, backup1, 'exists',
extra_info)
@ -1844,11 +1849,12 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
extra_usage_info=local_extra_info_delete)
@mock.patch('cinder.volume.utils.notify_about_backup_usage')
@mock.patch('cinder.objects.backup.BackupList.get_active_by_window')
@mock.patch('cinder.objects.backup.BackupList.get_all_active_by_window')
@mock.patch('cinder.volume.utils.notify_about_snapshot_usage')
@mock.patch('cinder.objects.snapshot.SnapshotList.get_active_by_window')
@mock.patch('cinder.objects.snapshot.SnapshotList.'
'get_all_active_by_window')
@mock.patch('cinder.volume.utils.notify_about_volume_usage')
@mock.patch('cinder.objects.volume.VolumeList.get_active_by_window')
@mock.patch('cinder.objects.volume.VolumeList.get_all_active_by_window')
@mock.patch('cinder.utils.last_completed_audit_period')
@mock.patch('cinder.rpc.init')
@mock.patch('cinder.version.version_string')
@ -1857,9 +1863,10 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
@mock.patch('cinder.context.get_admin_context')
def test_main(self, get_admin_context, log_setup, get_logger,
version_string, rpc_init, last_completed_audit_period,
volume_get_active_by_window, notify_about_volume_usage,
snapshot_get_active_by_window, notify_about_snapshot_usage,
backup_get_active_by_window, notify_about_backup_usage):
volume_get_all_active_by_window, notify_about_volume_usage,
snapshot_get_all_active_by_window,
notify_about_snapshot_usage, backup_get_all_active_by_window,
notify_about_backup_usage):
CONF.set_override('send_actions', True)
CONF.set_override('start_time', '2014-01-01 01:00:00')
CONF.set_override('end_time', '2014-02-02 02:00:00')
@ -1876,7 +1883,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
volume1 = mock.MagicMock(id=fake.VOLUME_ID, project_id=fake.PROJECT_ID,
created_at=volume1_created,
deleted_at=volume1_deleted)
volume_get_active_by_window.return_value = [volume1]
volume_get_all_active_by_window.return_value = [volume1]
extra_info = {
'audit_period_beginning': str(begin),
'audit_period_ending': str(end),
@ -1898,7 +1905,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
project_id=fake.PROJECT_ID,
created_at=snapshot1_created,
deleted_at=snapshot1_deleted)
snapshot_get_active_by_window.return_value = [snapshot1]
snapshot_get_all_active_by_window.return_value = [snapshot1]
extra_info_snapshot_create = {
'audit_period_beginning': str(snapshot1.created_at),
'audit_period_ending': str(snapshot1.created_at),
@ -1916,7 +1923,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
project_id=fake.PROJECT_ID,
created_at=backup1_created,
deleted_at=backup1_deleted)
backup_get_active_by_window.return_value = [backup1]
backup_get_all_active_by_window.return_value = [backup1]
extra_info_backup_create = {
'audit_period_beginning': str(backup1.created_at),
'audit_period_ending': str(backup1.created_at),
@ -1935,7 +1942,8 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
get_logger.assert_called_once_with('cinder')
rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
volume_get_all_active_by_window.assert_called_once_with(ctxt,
begin, end)
notify_about_volume_usage.assert_has_calls([
mock.call(ctxt, volume1, 'exists', extra_usage_info=extra_info),
mock.call(ctxt, volume1, 'create.start',

View File

@ -1543,7 +1543,7 @@ class DBAPISnapshotTestCase(BaseTest):
self.assertSetEqual({s.id for s in snapshots[:i + 1]},
{s.id for s in result})
def test_snapshot_get_by_host(self):
def test_snapshot_get_all_by_host(self):
db.volume_create(self.ctxt, {'id': 1, 'host': 'host1'})
db.volume_create(self.ctxt, {'id': 2, 'host': 'host2'})
snapshot1 = db.snapshot_create(self.ctxt, {'id': 1, 'volume_id': 1})
@ -1554,33 +1554,33 @@ class DBAPISnapshotTestCase(BaseTest):
fields.SnapshotStatus.ERROR})
self._assertEqualListsOfObjects([snapshot1],
db.snapshot_get_by_host(
db.snapshot_get_all_by_host(
self.ctxt,
'host1'),
ignored_keys='volume')
self._assertEqualListsOfObjects([snapshot2],
db.snapshot_get_by_host(
db.snapshot_get_all_by_host(
self.ctxt,
'host2'),
ignored_keys='volume')
self._assertEqualListsOfObjects(
[], db.snapshot_get_by_host(self.ctxt, 'host2', {
[], db.snapshot_get_all_by_host(self.ctxt, 'host2', {
'status': fields.SnapshotStatus.AVAILABLE}),
ignored_keys='volume')
self._assertEqualListsOfObjects(
[snapshot2], db.snapshot_get_by_host(self.ctxt, 'host2', {
[snapshot2], db.snapshot_get_all_by_host(self.ctxt, 'host2', {
'status': fields.SnapshotStatus.ERROR}),
ignored_keys='volume')
self._assertEqualListsOfObjects([],
db.snapshot_get_by_host(
db.snapshot_get_all_by_host(
self.ctxt,
'host2', {'fake_key': 'fake'}),
ignored_keys='volume')
# If host is None or empty string, empty list should be returned.
self.assertEqual([], db.snapshot_get_by_host(self.ctxt, None))
self.assertEqual([], db.snapshot_get_by_host(self.ctxt, ''))
self.assertEqual([], db.snapshot_get_all_by_host(self.ctxt, None))
self.assertEqual([], db.snapshot_get_all_by_host(self.ctxt, ''))
def test_snapshot_get_by_host_with_pools(self):
def test_snapshot_get_all_by_host_with_pools(self):
db.volume_create(self.ctxt, {'id': 1, 'host': 'host1#pool1'})
db.volume_create(self.ctxt, {'id': 2, 'host': 'host1#pool2'})
@ -1588,18 +1588,18 @@ class DBAPISnapshotTestCase(BaseTest):
snapshot2 = db.snapshot_create(self.ctxt, {'id': 2, 'volume_id': 2})
self._assertEqualListsOfObjects([snapshot1, snapshot2],
db.snapshot_get_by_host(
db.snapshot_get_all_by_host(
self.ctxt,
'host1'),
ignored_keys='volume')
self._assertEqualListsOfObjects([snapshot1],
db.snapshot_get_by_host(
db.snapshot_get_all_by_host(
self.ctxt,
'host1#pool1'),
ignored_keys='volume')
self._assertEqualListsOfObjects([],
db.snapshot_get_by_host(
db.snapshot_get_all_by_host(
self.ctxt,
'host1#pool0'),
ignored_keys='volume')

View File

@ -928,14 +928,14 @@ class DbQuotaDriverBaseTestCase(test.TestCase):
def _mock_quota_class_get_default(self):
# Mock quota_class_get_default
def fake_qcgd(context):
self.calls.append('quota_class_get_default')
self.calls.append('quota_class_get_defaults')
return dict(volumes=10,
snapshots=10,
gigabytes=1000,
backups=10,
backup_gigabytes=1000
)
self.mock_object(db, 'quota_class_get_default', fake_qcgd)
self.mock_object(db, 'quota_class_get_defaults', fake_qcgd)
def _mock_volume_type_get_all(self):
def fake_vtga(context, inactive=False, filters=None):
@ -1044,7 +1044,7 @@ class DbQuotaDriverTestCase(DbQuotaDriverBaseTestCase):
'quota_usage_get_all_by_project',
'quota_allocated_get_all_by_project',
'quota_class_get_all_by_name',
'quota_class_get_default', ], self.calls)
'quota_class_get_defaults', ], self.calls)
self.assertEqual(dict(volumes=dict(limit=10,
in_use=2,
reserved=0, ),
@ -1066,7 +1066,7 @@ class DbQuotaDriverTestCase(DbQuotaDriverBaseTestCase):
), result)
@mock.patch('cinder.quota.db.quota_get_all_by_project')
@mock.patch('cinder.quota.db.quota_class_get_default')
@mock.patch('cinder.quota.db.quota_class_get_defaults')
def test_get_project_quotas_lazy_load_defaults(
self, mock_defaults, mock_quotas):
mock_quotas.return_value = self._default_quotas_non_child
@ -1094,7 +1094,7 @@ class DbQuotaDriverTestCase(DbQuotaDriverBaseTestCase):
self.assertEqual(['quota_get_all_by_project',
'quota_usage_get_all_by_project',
'quota_allocated_get_all_by_project',
'quota_class_get_default', ], self.calls)
'quota_class_get_defaults', ], self.calls)
self.assertEqual(dict(volumes=dict(limit=10,
in_use=2,
reserved=0,
@ -1130,7 +1130,7 @@ class DbQuotaDriverTestCase(DbQuotaDriverBaseTestCase):
self.assertEqual(['quota_get_all_by_project',
'quota_usage_get_all_by_project',
'quota_class_get_default', ], self.calls)
'quota_class_get_defaults', ], self.calls)
self.assertEqual(dict(volumes=dict(limit=10,
in_use=2,
reserved=0, ),
@ -1161,7 +1161,7 @@ class DbQuotaDriverTestCase(DbQuotaDriverBaseTestCase):
self.assertEqual(['quota_get_all_by_project',
'quota_usage_get_all_by_project',
'quota_class_get_all_by_name',
'quota_class_get_default', ], self.calls)
'quota_class_get_defaults', ], self.calls)
self.assertEqual(dict(volumes=dict(limit=10,
in_use=2,
reserved=0, ),
@ -1219,7 +1219,7 @@ class DbQuotaDriverTestCase(DbQuotaDriverBaseTestCase):
self.assertEqual(['quota_get_all_by_project',
'quota_class_get_all_by_name',
'quota_class_get_default', ], self.calls)
'quota_class_get_defaults', ], self.calls)
self.assertEqual(dict(volumes=dict(limit=10, ),
snapshots=dict(limit=10, ),
backups=dict(limit=10, ),

View File

@ -6197,7 +6197,7 @@ class GetActiveByWindowTestCase(base.BaseVolumeTestCase):
},
]
def test_volume_get_active_by_window(self):
def test_volume_get_all_active_by_window(self):
# Find all all volumes valid within a timeframe window.
# Not in window
@ -6215,7 +6215,7 @@ class GetActiveByWindowTestCase(base.BaseVolumeTestCase):
# Not of window.
db.volume_create(self.context, self.db_vol_attrs[4])
volumes = db.volume_get_active_by_window(
volumes = db.volume_get_all_active_by_window(
self.context,
datetime.datetime(1, 3, 1, 1, 1, 1),
datetime.datetime(1, 4, 1, 1, 1, 1),
@ -6225,7 +6225,7 @@ class GetActiveByWindowTestCase(base.BaseVolumeTestCase):
self.assertEqual(fake.VOLUME3_ID, volumes[1].id)
self.assertEqual(fake.VOLUME4_ID, volumes[2].id)
def test_snapshot_get_active_by_window(self):
def test_snapshot_get_all_active_by_window(self):
# Find all all snapshots valid within a timeframe window.
db.volume_create(self.context, {'id': fake.VOLUME_ID})
for i in range(5):
@ -6256,7 +6256,7 @@ class GetActiveByWindowTestCase(base.BaseVolumeTestCase):
snap5 = objects.Snapshot(self.ctx, **self.db_snap_attrs[4])
snap5.create()
snapshots = objects.SnapshotList.get_active_by_window(
snapshots = objects.SnapshotList.get_all_active_by_window(
self.context,
datetime.datetime(1, 3, 1, 1, 1, 1),
datetime.datetime(1, 4, 1, 1, 1, 1)).objects
@ -6268,7 +6268,7 @@ class GetActiveByWindowTestCase(base.BaseVolumeTestCase):
self.assertEqual(snap4.id, snapshots[2].id)
self.assertEqual(fake.VOLUME_ID, snapshots[2].volume_id)
def test_backup_get_active_by_window(self):
def test_backup_get_all_active_by_window(self):
# Find all backups valid within a timeframe window.
db.volume_create(self.context, {'id': fake.VOLUME_ID})
for i in range(5):
@ -6289,7 +6289,7 @@ class GetActiveByWindowTestCase(base.BaseVolumeTestCase):
# Not of window
db.backup_create(self.ctx, self.db_back_attrs[4])
backups = db.backup_get_active_by_window(
backups = db.backup_get_all_active_by_window(
self.context,
datetime.datetime(1, 3, 1, 1, 1, 1),
datetime.datetime(1, 4, 1, 1, 1, 1),