]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port test_db_api to Python 3
authorVictor Stinner <vstinner@redhat.com>
Mon, 29 Jun 2015 13:11:12 +0000 (15:11 +0200)
committerVictor Stinner <vstinner@redhat.com>
Tue, 30 Jun 2015 13:32:08 +0000 (15:32 +0200)
* _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
tox.ini

index 1688759cda3e66f30d92baa8f9d49821faa0ced7..eab6e8181718501e0e5b09cdba060e43b2eaf7bf 100644 (file)
@@ -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 144737a4ad56bfb204ac04f18dfb1f7a0770c745..964d1aa6d452dff50f9135e303f5c93662ad723d 100644 (file)
--- 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 \