From 4fa03be2ba50f65f9eab4857bacf5f77778d0c67 Mon Sep 17 00:00:00 2001
From: Victor Stinner <vstinner@redhat.com>
Date: Mon, 29 Jun 2015 15:11:12 +0200
Subject: [PATCH] Port test_db_api to Python 3

* _dict_from_object(): on dictionaries, call the items() method instead
  of iteritems() method. oslo.db objects have no items() method yet, so
  check the object type to decide which method should be called.
* test_db_api: fix usage of db.quota_reserve(), quotas dictionary values
  must be integers (hard limit of quotas), not Quota instances of
  cinder.db.sqlalchemy.models.
* tox.ini:  add the following tests to Python 3.4

  - cinder.tests.unit.test_db_api
  - cinder.tests.unit.test_quota

Blueprint cinder-python3
Change-Id: I93f5e0f2fe34c9a6c135f34d64ec068c5696032d
---
 cinder/tests/unit/test_db_api.py | 10 +++++++---
 tox.ini                          |  2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/cinder/tests/unit/test_db_api.py b/cinder/tests/unit/test_db_api.py
index 1688759cd..eab6e8181 100644
--- a/cinder/tests/unit/test_db_api.py
+++ b/cinder/tests/unit/test_db_api.py
@@ -51,8 +51,8 @@ def _quota_reserve(context, project_id):
     resources = {}
     deltas = {}
     for i, resource in enumerate(('volumes', 'gigabytes')):
-        quotas[resource] = db.quota_create(context, project_id,
-                                           resource, i + 1)
+        quota_obj = db.quota_create(context, project_id, resource, i + 1)
+        quotas[resource] = quota_obj.hard_limit
         resources[resource] = quota.ReservableResource(resource,
                                                        '_sync_%s' % resource)
         deltas[resource] = i + 1
@@ -67,7 +67,11 @@ class ModelsObjectComparatorMixin(object):
     def _dict_from_object(self, obj, ignored_keys):
         if ignored_keys is None:
             ignored_keys = []
-        return {k: v for k, v in obj.iteritems()
+        if isinstance(obj, dict):
+            items = obj.items()
+        else:
+            items = obj.iteritems()
+        return {k: v for k, v in items
                 if k not in ignored_keys}
 
     def _assertEqualObjects(self, obj1, obj2, ignored_keys=None):
diff --git a/tox.ini b/tox.ini
index 144737a4a..964d1aa6d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -41,6 +41,7 @@ commands =
     cinder.tests.unit.test_conf \
     cinder.tests.unit.test_context \
     cinder.tests.unit.test_create_volume_flow \
+    cinder.tests.unit.test_db_api \
     cinder.tests.unit.test_dellfc \
     cinder.tests.unit.test_dellsc \
     cinder.tests.unit.test_dellscapi \
@@ -60,6 +61,7 @@ commands =
     cinder.tests.unit.test_nimble \
     cinder.tests.unit.test_openvstorage \
     cinder.tests.unit.test_qos_specs \
+    cinder.tests.unit.test_quota \
     cinder.tests.unit.test_rbd \
     cinder.tests.unit.test_remotefs \
     cinder.tests.unit.test_replication \
-- 
2.45.2