From ed69db62249811661392570d15c3ca093d2777e4 Mon Sep 17 00:00:00 2001 From: Julia Varlamova Date: Thu, 29 Aug 2013 11:56:17 +0400 Subject: [PATCH] Remove _create_volume function from several tests Remove _create_volume function from - db/test_transfers.py - api/contrib/test_backups.py - test_gpfs.py - test_volume_transfer.py - test_volume.py And use create_volume from tests/utils.py instead Change-Id: I446220d0cfaa2850a5262a968ed35b7827b90a03 --- cinder/tests/api/contrib/test_backups.py | 91 +++++-------- cinder/tests/db/test_transfers.py | 29 +--- cinder/tests/test_gpfs.py | 50 +++---- cinder/tests/test_volume.py | 160 +++++++++++++---------- cinder/tests/test_volume_transfer.py | 31 ++--- 5 files changed, 161 insertions(+), 200 deletions(-) diff --git a/cinder/tests/api/contrib/test_backups.py b/cinder/tests/api/contrib/test_backups.py index fdc57aabc..06c563639 100644 --- a/cinder/tests/api/contrib/test_backups.py +++ b/cinder/tests/api/contrib/test_backups.py @@ -31,6 +31,7 @@ from cinder.openstack.common import log as logging from cinder.openstack.common import timeutils from cinder import test from cinder.tests.api import fakes +from cinder.tests import utils # needed for stubs to work import cinder.volume @@ -45,6 +46,9 @@ class BackupsAPITestCase(test.TestCase): super(BackupsAPITestCase, self).setUp() self.volume_api = cinder.volume.API() self.backup_api = cinder.backup.API() + self.context = context.get_admin_context() + self.context.project_id = 'fake' + self.context.user_id = 'fake' def tearDown(self): super(BackupsAPITestCase, self).tearDown() @@ -77,33 +81,14 @@ class BackupsAPITestCase(test.TestCase): return db.backup_get(context.get_admin_context(), backup_id)[attrib_name] - @staticmethod - def _create_volume(display_name='test_volume', - display_description='this is a test volume', - status='creating', - availability_zone='fake_az', - host='fake_host', - size=1): - """Create a volume object.""" - vol = {} - vol['size'] = size - vol['user_id'] = 'fake' - vol['project_id'] = 'fake' - vol['status'] = status - vol['display_name'] = display_name - vol['display_description'] = display_description - vol['attach_status'] = 'detached' - vol['availability_zone'] = availability_zone - vol['host'] = host - return db.volume_create(context.get_admin_context(), vol)['id'] - @staticmethod def _stub_service_get_all_by_topic(context, topic): - return [{'availability_zone': "fake_az", 'host': 'fake_host', + return [{'availability_zone': "fake_az", 'host': 'test_host', 'disabled': 0, 'updated_at': timeutils.utcnow()}] def test_show_backup(self): - volume_id = self._create_volume(size=5) + volume_id = utils.create_volume(self.context, size=5, + status='creating')['id'] backup_id = self._create_backup(volume_id) LOG.debug('Created backup with id %s' % backup_id) req = webob.Request.blank('/v2/fake/backups/%s' % @@ -129,7 +114,8 @@ class BackupsAPITestCase(test.TestCase): db.volume_destroy(context.get_admin_context(), volume_id) def test_show_backup_xml_content_type(self): - volume_id = self._create_volume(size=5) + volume_id = utils.create_volume(self.context, size=5, + status='creating')['id'] backup_id = self._create_backup(volume_id) req = webob.Request.blank('/v2/fake/backups/%s' % backup_id) req.method = 'GET' @@ -357,7 +343,9 @@ class BackupsAPITestCase(test.TestCase): def test_create_backup_json(self): self.stubs.Set(cinder.db, 'service_get_all_by_topic', self._stub_service_get_all_by_topic) - volume_id = self._create_volume(status='available', size=5) + + volume_id = utils.create_volume(self.context, size=5)['id'] + body = {"backup": {"display_name": "nightly001", "display_description": "Nightly Backup 03-Sep-2012", @@ -382,8 +370,7 @@ class BackupsAPITestCase(test.TestCase): def test_create_backup_xml(self): self.stubs.Set(cinder.db, 'service_get_all_by_topic', self._stub_service_get_all_by_topic) - volume_size = 2 - volume_id = self._create_volume(status='available', size=volume_size) + volume_id = utils.create_volume(self.context, size=2)['id'] req = webob.Request.blank('/v2/fake/backups') req.body = ('