from cinder.db import migration
from cinder.db.sqlalchemy import api as sqla_api
from cinder import i18n
-from cinder import objects
from cinder import rpc
from cinder import service
from cinder.tests.unit import conf_fixture
side_effect=self._get_joined_notifier)
p.start()
- # Import cinder objects for test cases
- objects.register_all()
-
# Unit tests do not need to use lazy gettext
i18n.enable_lazy(False)
import eventlet
from six.moves import builtins
+from cinder import objects
+
eventlet.monkey_patch()
# See http://code.google.com/p/python-nose/issues/detail?id=373
# The code below enables nosetests to work with i18n _() blocks
setattr(builtins, '_', lambda x: x)
+
+# NOTE(alaski): Make sure this is done after eventlet monkey patching otherwise
+# the threading.local() store used in oslo_messaging will be initialized to
+# threadlocal storage rather than greenthread local. This will cause context
+# sets and deletes in that storage to clobber each other.
+# NOTE(comstud): Make sure we have all of the objects loaded. We do this
+# at module import time, because we may be using mock decorators in our
+# tests that run at import time.
+objects.register_all()
-from oslo_versionedobjects.tests import test_objects
+# Copyright 2015 IBM Corp.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
-from cinder import objects
+from oslo_utils import timeutils
+from cinder import context
+from cinder.objects import base as obj_base
+from cinder import test
-class BaseObjectsTestCase(test_objects._LocalTest):
+
+class BaseObjectsTestCase(test.TestCase):
def setUp(self):
super(BaseObjectsTestCase, self).setUp()
- # Import cinder objects for test cases
- objects.register_all()
+ self.user_id = 'fake-user'
+ self.project_id = 'fake-project'
+ self.context = context.RequestContext(self.user_id, self.project_id,
+ is_admin=False)
+ # We only test local right now.
+ # TODO(mriedem): Testing remote would be nice...
+ self.assertIsNone(obj_base.CinderObject.indirection_api)
+
+ # TODO(mriedem): Replace this with
+ # oslo_versionedobjects.fixture.compare_obj when that is in a released
+ # version of o.vo.
+ @staticmethod
+ def _compare(test, db, obj):
+ for field, value in db.items():
+ if not hasattr(obj, field):
+ continue
+
+ if field in ('modified_at', 'created_at',
+ 'updated_at', 'deleted_at') and db[field]:
+ test.assertEqual(db[field],
+ timeutils.normalize_time(obj[field]))
+ elif isinstance(obj[field], obj_base.ObjectListBase):
+ test.assertEqual(db[field], obj[field].objects)
+ else:
+ test.assertEqual(db[field], obj[field])
import mock
-from cinder import context
from cinder import exception
from cinder import objects
from cinder.tests.unit import fake_volume
class TestBackup(test_objects.BaseObjectsTestCase):
- def setUp(self):
- super(TestBackup, self).setUp()
- # NOTE (e0ne): base tests contains original RequestContext from
- # oslo_context. We change it to our RequestContext implementation
- # to have 'elevated' method
- self.context = context.RequestContext(self.user_id, self.project_id,
- is_admin=False)
-
- @staticmethod
- def _compare(test, db, obj):
- for field, value in db.items():
- test.assertEqual(db[field], obj[field])
@mock.patch('cinder.db.backup_get', return_value=fake_backup)
def test_get_by_id(self, backup_get):
import mock
-from cinder import context
from cinder import exception
from cinder import objects
from cinder.tests.unit import objects as test_objects
class TestCGSnapshot(test_objects.BaseObjectsTestCase):
- def setUp(self):
- super(TestCGSnapshot, self).setUp()
- # NOTE (e0ne): base tests contains original RequestContext from
- # oslo_context. We change it to our RequestContext implementation
- # to have 'elevated' method
- self.user_id = 123
- self.project_id = 456
- self.context = context.RequestContext(self.user_id, self.project_id,
- is_admin=False)
-
- @staticmethod
- def _compare(test, db, obj):
- for field, value in db.items():
- test.assertEqual(db[field], getattr(obj, field))
@mock.patch('cinder.db.cgsnapshot_get',
return_value=fake_cgsnapshot)
import mock
-from cinder import context
from cinder import exception
from cinder import objects
from cinder.tests.unit import objects as test_objects
class TestConsistencyGroup(test_objects.BaseObjectsTestCase):
- def setUp(self):
- super(TestConsistencyGroup, self).setUp()
- # NOTE (e0ne): base tests contains original RequestContext from
- # oslo_context. We change it to our RequestContext implementation
- # to have 'elevated' method
- self.user_id = 123
- self.project_id = 456
- self.context = context.RequestContext(self.user_id, self.project_id,
- is_admin=False)
-
- @staticmethod
- def _compare(test, db, obj):
- for field, value in db.items():
- test.assertEqual(db[field], getattr(obj, field))
@mock.patch('cinder.db.consistencygroup_get',
return_value=fake_consistencygroup)
import mock
-from oslo_utils import timeutils
-
-from cinder import context
from cinder import objects
from cinder.tests.unit import fake_service
from cinder.tests.unit import objects as test_objects
class TestService(test_objects.BaseObjectsTestCase):
- def setUp(self):
- super(TestService, self).setUp()
- # NOTE (e0ne): base tests contains original RequestContext from
- # oslo_context. We change it to our RequestContext implementation
- # to have 'elevated' method
- self.context = context.RequestContext(self.user_id, self.project_id,
- is_admin=False)
-
- @staticmethod
- def _compare(test, db, obj):
- for field, value in db.items():
- if field in ('modified_at', 'created_at',
- 'updated_at', 'deleted_at') and db[field]:
- test.assertEqual(db[field],
- timeutils.normalize_time(obj[field]))
- else:
- test.assertEqual(db[field], obj[field])
@mock.patch('cinder.db.service_get')
def test_get_by_id(self, service_get):
class TestSnapshot(test_objects.BaseObjectsTestCase):
- @staticmethod
- def _compare(test, expected, actual):
- for field, value in expected.items():
- test.assertEqual(expected[field], actual[field],
- "Field '%s' is not equal" % field)
@mock.patch('cinder.db.snapshot_get', return_value=fake_db_snapshot)
def test_get_by_id(self, snapshot_get):
class TestVolume(test_objects.BaseObjectsTestCase):
- def setUp(self):
- super(TestVolume, self).setUp()
- # NOTE (e0ne): base tests contains original RequestContext from
- # oslo_context. We change it to our RequestContext implementation
- # to have 'elevated' method
- self.context = context.RequestContext(self.user_id, self.project_id,
- is_admin=False)
-
- @staticmethod
- def _compare(test, db, obj):
- for field, value in db.items():
- if not hasattr(obj, field):
- continue
-
- test.assertEqual(db[field], obj[field])
@mock.patch('cinder.db.volume_glance_metadata_get', return_value={})
@mock.patch('cinder.db.volume_get')
class TestVolumeAttachment(test_objects.BaseObjectsTestCase):
- @staticmethod
- def _compare(test, db, obj):
- for field, value in db.items():
- test.assertEqual(db[field], obj[field])
@mock.patch('cinder.db.volume_attachment_get')
def test_get_by_id(self, volume_attachment_get):
import mock
-from cinder import context
from cinder import objects
from cinder.tests.unit import fake_volume
from cinder.tests.unit import objects as test_objects
class TestVolumeType(test_objects.BaseObjectsTestCase):
- def setUp(self):
- super(TestVolumeType, self).setUp()
- # NOTE (e0ne): base tests contains original RequestContext from
- # oslo_context. We change it to our RequestContext implementation
- # to have 'elevated' method
- self.context = context.RequestContext(self.user_id, self.project_id,
- is_admin=False)
-
- @staticmethod
- def _compare(test, db, obj):
- for field, value in db.items():
- test.assertEqual(db[field], obj[field])
@mock.patch('cinder.db.volume_type_get')
def test_get_by_id(self, volume_type_get):