From 8d5653730c8fcd2effc2587bb6148ba988ec267f Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Thu, 26 May 2016 11:28:17 +0200 Subject: [PATCH] Improve DB method naming consistency Some of our DB methods have names that are not consistent with the general naming we use to differentiate between methods that return a single value -_get_- and those that return a list of values -_get_all_-. This patch renames some of these methods to make them reflect whether they are returning a single entity or a list of entities. Change-Id: I3d32d65e573f71cf58c8956ef86debd4824d9f02 --- cinder/cmd/volume_usage_audit.py | 14 ++--- cinder/db/api.py | 24 +++++--- cinder/db/sqlalchemy/api.py | 37 ++++++----- cinder/objects/backup.py | 4 +- cinder/objects/snapshot.py | 6 +- cinder/objects/volume.py | 4 +- cinder/quota.py | 6 +- cinder/tests/unit/objects/test_snapshot.py | 10 +-- cinder/tests/unit/test_cmd.py | 72 ++++++++++++---------- cinder/tests/unit/test_db_api.py | 24 ++++---- cinder/tests/unit/test_quota.py | 16 ++--- cinder/tests/unit/test_volume.py | 12 ++-- 12 files changed, 122 insertions(+), 107 deletions(-) diff --git a/cinder/cmd/volume_usage_audit.py b/cinder/cmd/volume_usage_audit.py index 2f8c15e7a33..4cf687e514a 100644 --- a/cinder/cmd/volume_usage_audit.py +++ b/cinder/cmd/volume_usage_audit.py @@ -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: diff --git a/cinder/db/api.py b/cinder/db/api.py index a674b9c11ed..e3f34b360c2 100644 --- a/cinder/db/api.py +++ b/cinder/db/api.py @@ -409,13 +409,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): @@ -449,12 +449,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) #################### @@ -619,12 +621,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): @@ -1029,9 +1032,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): @@ -1154,12 +1157,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): diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 60a1f778d97..9fd51ac2f8f 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -795,7 +795,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( @@ -831,7 +831,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 @@ -875,7 +875,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() @@ -2693,7 +2693,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 [] @@ -2812,7 +2812,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") @@ -3697,10 +3698,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 @@ -4005,7 +4006,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 @@ -4049,7 +4050,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). \ @@ -4064,7 +4065,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). \ @@ -4110,7 +4112,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] @@ -4188,7 +4191,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] @@ -4247,7 +4250,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')} @@ -4287,7 +4290,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: @@ -4729,7 +4732,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") diff --git a/cinder/objects/backup.py b/cinder/objects/backup.py index e183b9a9290..f89a11f329b 100644 --- a/cinder/objects/backup.py +++ b/cinder/objects/backup.py @@ -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) diff --git a/cinder/objects/snapshot.py b/cinder/objects/snapshot.py index a53f8f6b0e6..7f9cd98e250 100644 --- a/cinder/objects/snapshot.py +++ b/cinder/objects/snapshot.py @@ -283,7 +283,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) @@ -307,8 +307,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) diff --git a/cinder/objects/volume.py b/cinder/objects/volume.py index 836610c581e..9bb9d15a0dc 100644 --- a/cinder/objects/volume.py +++ b/cinder/objects/volume.py @@ -635,8 +635,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) diff --git a/cinder/quota.py b/cinder/quota.py index df077d5379a..ee88d21b49d 100644 --- a/cinder/quota.py +++ b/cinder/quota.py @@ -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] diff --git a/cinder/tests/unit/objects/test_snapshot.py b/cinder/tests/unit/objects/test_snapshot.py index 3b2547a943c..9ca51aae47a 100644 --- a/cinder/tests/unit/objects/test_snapshot.py +++ b/cinder/tests/unit/objects/test_snapshot.py @@ -226,7 +226,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) @@ -267,14 +267,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]) diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index f0cef49e8fb..443b4e69ea5 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -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', diff --git a/cinder/tests/unit/test_db_api.py b/cinder/tests/unit/test_db_api.py index fd5b2ad7f07..5066adec07b 100644 --- a/cinder/tests/unit/test_db_api.py +++ b/cinder/tests/unit/test_db_api.py @@ -1497,7 +1497,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}) @@ -1508,33 +1508,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'}) @@ -1542,18 +1542,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') diff --git a/cinder/tests/unit/test_quota.py b/cinder/tests/unit/test_quota.py index a6ac0ec04f0..f322e385af8 100644 --- a/cinder/tests/unit/test_quota.py +++ b/cinder/tests/unit/test_quota.py @@ -923,14 +923,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): @@ -1039,7 +1039,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, ), @@ -1061,7 +1061,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 @@ -1089,7 +1089,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, @@ -1125,7 +1125,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, ), @@ -1156,7 +1156,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, ), @@ -1214,7 +1214,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, ), diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index 6f949e1bfb8..ea0896faf10 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -6060,7 +6060,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 @@ -6078,7 +6078,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), @@ -6088,7 +6088,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): @@ -6119,7 +6119,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 @@ -6131,7 +6131,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): @@ -6152,7 +6152,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),