summaryrefslogtreecommitdiff
path: root/nova/tests/unit/objects/test_quotas.py
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-04-01 17:49:02 +0100
committerStephen Finucane <stephenfin@redhat.com>2021-08-09 15:34:40 +0100
commit100b9dc62c0ec9f7b38739837c06646122c818d5 (patch)
tree461ffc78155a8ff058796c522b983a47a946717e /nova/tests/unit/objects/test_quotas.py
parent84b61790763f91e12eebb96d955e2f83abc00d56 (diff)
downloadnova-100b9dc62c0ec9f7b38739837c06646122c818d5.tar.gz
db: Unify 'nova.db.api', 'nova.db.sqlalchemy.api'
Merge these, removing an unnecessary layer of abstraction, and place them in the new 'nova.db.main' directory. The resulting change is huge, but it's mainly the result of 's/sqlalchemy import api/main import api/' and 's/nova.db.api/nova.db.main.api/' with some necessary cleanup. We also need to rework how we do the blocking of API calls since we no longer have a 'DBAPI' object that we can monkey patch as we were doing before. This is now done via a global variable that is set by the 'main' function of 'nova.cmd.compute'. The main impact of this change is that it's no longer possible to set '[database] use_db_reconnect' and have all APIs automatically wrapped in a DB retry. Seeing as this behavior is experimental, isn't applied to any of the API DB methods (which don't use oslo.db's 'DBAPI' helper), and is used explicitly in what would appear to be the critical cases (via the explicit 'oslo_db.api.wrap_db_retry' decorator), this doesn't seem like a huge loss. Change-Id: Iad2e4da4546b80a016e477577d23accb2606a6e4 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'nova/tests/unit/objects/test_quotas.py')
-rw-r--r--nova/tests/unit/objects/test_quotas.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/nova/tests/unit/objects/test_quotas.py b/nova/tests/unit/objects/test_quotas.py
index 1314b1de83..154c9f278a 100644
--- a/nova/tests/unit/objects/test_quotas.py
+++ b/nova/tests/unit/objects/test_quotas.py
@@ -15,7 +15,7 @@
import mock
from nova import context
-from nova.db.sqlalchemy import api as db_api
+from nova.db.main import api as db_api
from nova import exception
from nova.objects import quotas as quotas_obj
from nova import quota
@@ -54,7 +54,8 @@ class _TestQuotasObject(object):
self.instance = fake_instance.fake_db_instance(
project_id='fake_proj2', user_id='fake_user2')
- @mock.patch('nova.db.api.quota_get', side_effect=exception.QuotaNotFound)
+ @mock.patch(
+ 'nova.db.main.api.quota_get', side_effect=exception.QuotaNotFound)
@mock.patch('nova.objects.Quotas._create_limit_in_db')
def test_create_limit(self, mock_create, mock_get):
quotas_obj.Quotas.create_limit(self.context, 'fake-project',
@@ -62,7 +63,7 @@ class _TestQuotasObject(object):
mock_create.assert_called_once_with(self.context, 'fake-project',
'foo', 10, user_id='user')
- @mock.patch('nova.db.api.quota_get')
+ @mock.patch('nova.db.main.api.quota_get')
@mock.patch('nova.objects.Quotas._create_limit_in_db')
def test_create_limit_exists_in_main(self, mock_create, mock_get):
self.assertRaises(exception.QuotaExists,
@@ -203,7 +204,7 @@ class _TestQuotasObject(object):
@mock.patch('nova.objects.Quotas._update_limit_in_db',
side_effect=exception.QuotaNotFound)
- @mock.patch('nova.db.api.quota_update')
+ @mock.patch('nova.db.main.api.quota_update')
def test_update_limit_main(self, mock_update_main, mock_update):
quotas_obj.Quotas.update_limit(self.context, 'fake-project',
'foo', 10, user_id='user')
@@ -223,7 +224,7 @@ class _TestQuotasObject(object):
@mock.patch('nova.objects.Quotas._get_from_db',
side_effect=exception.QuotaNotFound)
- @mock.patch('nova.db.api.quota_get')
+ @mock.patch('nova.db.main.api.quota_get')
def test_get_main(self, mock_get_main, mock_get):
quotas_obj.Quotas.get(self.context, 'fake-project', 'foo',
user_id='user')
@@ -233,7 +234,7 @@ class _TestQuotasObject(object):
'foo', user_id='user')
@mock.patch('nova.objects.Quotas._get_all_from_db')
- @mock.patch('nova.db.api.quota_get_all')
+ @mock.patch('nova.db.main.api.quota_get_all')
def test_get_all(self, mock_get_all_main, mock_get_all):
mock_get_all.return_value = ['api1']
mock_get_all_main.return_value = ['main1', 'main2']
@@ -243,7 +244,7 @@ class _TestQuotasObject(object):
self.assertEqual(['api1', 'main1', 'main2'], quotas)
@mock.patch('nova.objects.Quotas._get_all_from_db_by_project')
- @mock.patch('nova.db.api.quota_get_all_by_project')
+ @mock.patch('nova.db.main.api.quota_get_all_by_project')
def test_get_all_by_project(self, mock_get_all_main, mock_get_all):
mock_get_all.return_value = {'project_id': 'fake-project',
'fixed_ips': 20, 'floating_ips': 5}
@@ -258,7 +259,7 @@ class _TestQuotasObject(object):
self.assertEqual(expected, quotas_dict)
@mock.patch('nova.objects.Quotas._get_all_from_db_by_project_and_user')
- @mock.patch('nova.db.api.quota_get_all_by_project_and_user')
+ @mock.patch('nova.db.main.api.quota_get_all_by_project_and_user')
def test_get_all_by_project_and_user(self, mock_get_all_main,
mock_get_all):
mock_get_all.return_value = {'project_id': 'fake-project',
@@ -285,7 +286,7 @@ class _TestQuotasObject(object):
@mock.patch('nova.objects.Quotas._destroy_all_in_db_by_project',
side_effect=exception.ProjectQuotaNotFound(
project_id='fake-project'))
- @mock.patch('nova.db.api.quota_destroy_all_by_project')
+ @mock.patch('nova.db.main.api.quota_destroy_all_by_project')
def test_destroy_all_by_project_main(self, mock_destroy_all_main,
mock_destroy_all):
quotas_obj.Quotas.destroy_all_by_project(self.context, 'fake-project')
@@ -304,7 +305,7 @@ class _TestQuotasObject(object):
@mock.patch('nova.objects.Quotas._destroy_all_in_db_by_project_and_user',
side_effect=exception.ProjectUserQuotaNotFound(
user_id='user', project_id='fake-project'))
- @mock.patch('nova.db.api.quota_destroy_all_by_project_and_user')
+ @mock.patch('nova.db.main.api.quota_destroy_all_by_project_and_user')
def test_destroy_all_by_project_and_user_main(self, mock_destroy_all_main,
mock_destroy_all):
quotas_obj.Quotas.destroy_all_by_project_and_user(self.context,
@@ -323,7 +324,7 @@ class _TestQuotasObject(object):
@mock.patch('nova.objects.Quotas._get_class_from_db',
side_effect=exception.QuotaClassNotFound(class_name='class'))
- @mock.patch('nova.db.api.quota_class_get')
+ @mock.patch('nova.db.main.api.quota_class_get')
def test_get_class_main(self, mock_get_main, mock_get):
qclass = quotas_obj.Quotas.get_class(self.context, 'class', 'resource')
mock_get.assert_called_once_with(self.context, 'class', 'resource')
@@ -340,7 +341,7 @@ class _TestQuotasObject(object):
@mock.patch('nova.objects.Quotas._get_all_class_from_db_by_name',
side_effect=exception.QuotaClassNotFound(class_name='class'))
- @mock.patch('nova.db.api.quota_class_get_default')
+ @mock.patch('nova.db.main.api.quota_class_get_default')
def test_get_default_class_main(self, mock_get_default_main, mock_get_all):
qclass = quotas_obj.Quotas.get_default_class(self.context)
mock_get_all.assert_called_once_with(self.context,
@@ -349,7 +350,7 @@ class _TestQuotasObject(object):
self.assertEqual(mock_get_default_main.return_value, qclass)
@mock.patch('nova.objects.Quotas._get_all_class_from_db_by_name')
- @mock.patch('nova.db.api.quota_class_get_all_by_name')
+ @mock.patch('nova.db.main.api.quota_class_get_all_by_name')
def test_get_class_by_name(self, mock_get_all_main, mock_get_all):
mock_get_all.return_value = {'class_name': 'foo', 'cores': 10,
'instances': 5}
@@ -363,7 +364,7 @@ class _TestQuotasObject(object):
'fixed_ips': 10}
self.assertEqual(expected, quotas_dict)
- @mock.patch('nova.db.api.quota_class_get',
+ @mock.patch('nova.db.main.api.quota_class_get',
side_effect=exception.QuotaClassNotFound(class_name='class'))
@mock.patch('nova.objects.Quotas._create_class_in_db')
def test_create_class(self, mock_create, mock_get):
@@ -372,7 +373,7 @@ class _TestQuotasObject(object):
mock_create.assert_called_once_with(self.context, 'class', 'resource',
'limit')
- @mock.patch('nova.db.api.quota_class_get')
+ @mock.patch('nova.db.main.api.quota_class_get')
@mock.patch('nova.objects.Quotas._create_class_in_db')
def test_create_class_exists_in_main(self, mock_create, mock_get):
self.assertRaises(exception.QuotaClassExists,
@@ -388,7 +389,7 @@ class _TestQuotasObject(object):
@mock.patch('nova.objects.Quotas._update_class_in_db',
side_effect=exception.QuotaClassNotFound(class_name='class'))
- @mock.patch('nova.db.api.quota_class_update')
+ @mock.patch('nova.db.main.api.quota_class_update')
def test_update_class_main(self, mock_update_main, mock_update):
quotas_obj.Quotas.update_class(self.context, 'class', 'resource',
'limit')