diff --git a/manila/api/v1/share_snapshots.py b/manila/api/v1/share_snapshots.py index a879fbf75a..ddacef681b 100644 --- a/manila/api/v1/share_snapshots.py +++ b/manila/api/v1/share_snapshots.py @@ -19,9 +19,9 @@ import webob from webob import exc from manila.api import common -from manila.api.v1 import shares from manila.api import extensions from manila.api.openstack import wsgi +from manila.api.v1 import shares from manila.api.views import share_snapshots as snapshot_views from manila.api import xmlutil from manila import exception diff --git a/manila/db/sqlalchemy/api.py b/manila/db/sqlalchemy/api.py index 3773443e1c..93cfa23882 100644 --- a/manila/db/sqlalchemy/api.py +++ b/manila/db/sqlalchemy/api.py @@ -274,7 +274,6 @@ def _service_get_all_topic_subquery(context, session, topic, subq, label): all() - @require_admin_context def service_get_all_share_sorted(context): session = get_session() @@ -973,19 +972,19 @@ def share_snapshot_create(context, values): @require_admin_context def snapshot_data_get_for_project(context, project_id, session=None): - # TODO: Add + # TODO(yportnova): Uncomment when snapshot size implemented raise NotImplementedError() - - query = model_query(context, - func.count(models.ShareSnapshot.id), - func.sum(models.ShareSnapshot.share.size), - read_deleted="no", - session=session).\ - filter_by(project_id=project_id) - - result = query.first() - - return (result[0] or 0, result[1] or 0) + # + # query = model_query(context, + # func.count(models.ShareSnapshot.id), + # func.sum(models.ShareSnapshot.size), + # read_deleted="no", + # session=session).\ + # filter_by(project_id=project_id) + # + # result = query.first() + # + # return (result[0] or 0, result[1] or 0) @require_admin_context diff --git a/manila/exception.py b/manila/exception.py index 4da695415a..12395665c9 100644 --- a/manila/exception.py +++ b/manila/exception.py @@ -460,6 +460,3 @@ class InvalidShareSnapshot(ManilaException): class SwiftConnectionFailed(ManilaException): message = _("Connection to swift failed") + ": %(reason)s" - - - diff --git a/manila/image/image_utils.py b/manila/image/image_utils.py index 07b6bbd28d..39fe90c195 100644 --- a/manila/image/image_utils.py +++ b/manila/image/image_utils.py @@ -248,5 +248,3 @@ def fetch_to_raw(context, image_service, reason=_("Converted to raw, but format is now %s") % data.file_format) os.unlink(tmp) - - diff --git a/manila/quota.py b/manila/quota.py index 574dc9971f..311845549c 100644 --- a/manila/quota.py +++ b/manila/quota.py @@ -795,7 +795,7 @@ def _sync_gigabytes(context, project_id, session): if FLAGS.no_snapshot_gb_quota: return {'gigabytes': share_gigs} - # TODO: Uncomment when Snapshot size is implemented + # TODO(yportnova): Uncomment when Snapshot size is implemented # (_junk, snap_gigs) = db.snapshot_data_get_for_project(context, # project_id, # session=session) @@ -808,7 +808,7 @@ QUOTAS = QuotaEngine() resources = [ ReservableResource('shares', _sync_shares, 'quota_shares'), - # TODO: Uncomment when Snapshot size is implemented + # TODO(yportnova): Uncomment when Snapshot size is implemented # ReservableResource('snapshots', _sync_snapshots, 'quota_snapshots'), ReservableResource('gigabytes', _sync_gigabytes, 'quota_gigabytes'), ] diff --git a/manila/scheduler/host_manager.py b/manila/scheduler/host_manager.py index a79ba84cf2..d2290a003c 100644 --- a/manila/scheduler/host_manager.py +++ b/manila/scheduler/host_manager.py @@ -132,6 +132,7 @@ class HostState(object): self.updated = capability['timestamp'] + class HostManager(object): """Base HostManager class.""" diff --git a/manila/share/api.py b/manila/share/api.py index b46dd0d277..5a4bc38be3 100644 --- a/manila/share/api.py +++ b/manila/share/api.py @@ -187,7 +187,7 @@ class API(base.Base): project_id = share['project_id'] else: project_id = context.project_id - + share_id = share['id'] if not share['host']: try: diff --git a/manila/share/manager.py b/manila/share/manager.py index eb00d6b74c..8835621d92 100644 --- a/manila/share/manager.py +++ b/manila/share/manager.py @@ -30,8 +30,8 @@ from manila.openstack.common import excutils from manila.openstack.common import importutils from manila.openstack.common import log as logging from manila.openstack.common import timeutils -from manila.share.configuration import Configuration from manila import quota +from manila.share.configuration import Configuration from oslo.config import cfg diff --git a/manila/tests/api/contrib/test_admin_actions.py b/manila/tests/api/contrib/test_admin_actions.py index 086dc8fcfc..c06cf3c4cf 100644 --- a/manila/tests/api/contrib/test_admin_actions.py +++ b/manila/tests/api/contrib/test_admin_actions.py @@ -29,4 +29,3 @@ class AdminActionsTest(test.TestCase): def tearDown(self): shutil.rmtree(self.tempdir) - diff --git a/manila/tests/api/contrib/test_services.py b/manila/tests/api/contrib/test_services.py index 3fb65b270e..b4caac53ce 100644 --- a/manila/tests/api/contrib/test_services.py +++ b/manila/tests/api/contrib/test_services.py @@ -14,6 +14,7 @@ # under the License. +from datetime import datetime from manila.api.contrib import services from manila import context from manila import db @@ -22,7 +23,6 @@ from manila.openstack.common import timeutils from manila import policy from manila import test from manila.tests.api import fakes -from datetime import datetime fake_services_list = [{'binary': 'manila-scheduler', diff --git a/manila/tests/api/test_router.py b/manila/tests/api/test_router.py index a2b0fad80f..776d2ef5ae 100644 --- a/manila/tests/api/test_router.py +++ b/manila/tests/api/test_router.py @@ -117,4 +117,3 @@ class VolumeRouterTestCase(test.TestCase): result = resource.dispatch(resource.index, req, {}) ids = [v['id'] for v in result['versions']] self.assertEqual(set(ids), set(['v1.0'])) - diff --git a/manila/tests/image/fake.py b/manila/tests/image/fake.py index 0b336cc260..7ad4accfaa 100644 --- a/manila/tests/image/fake.py +++ b/manila/tests/image/fake.py @@ -41,7 +41,7 @@ class _FakeImageService(object): self.images = {} # NOTE(justinsb): The OpenStack API can't upload an image? # So, make sure we've got one.. - timestamp = datetime.datetime(2011, 01, 01, 01, 02, 03) + timestamp = datetime.datetime(2011, 0o1, 0o1, 0o1, 0o2, 0o3) image1 = {'id': '155d900f-4e14-4e4c-a73d-069cbf4541e6', 'name': 'fakeimage123456', diff --git a/manila/tests/image/test_glance.py b/manila/tests/image/test_glance.py index 76f249a0f0..c2c08552e4 100644 --- a/manila/tests/image/test_glance.py +++ b/manila/tests/image/test_glance.py @@ -21,6 +21,7 @@ import random import time import glanceclient.exc +from glanceclient.v2.client import Client as glanceclient_v2 from manila import context from manila import exception @@ -28,7 +29,6 @@ from manila import flags from manila.image import glance from manila import test from manila.tests.glance import stubs as glance_stubs -from glanceclient.v2.client import Client as glanceclient_v2 FLAGS = flags.FLAGS diff --git a/manila/tests/integrated/test_xml.py b/manila/tests/integrated/test_xml.py index 6618a7617f..8097e94071 100644 --- a/manila/tests/integrated/test_xml.py +++ b/manila/tests/integrated/test_xml.py @@ -27,7 +27,7 @@ LOG = logging.getLogger(__name__) class XmlTests(integrated_helpers._IntegratedTestBase): """"Some basic XML sanity checks.""" - + def test_namespace_volumes(self): """/servers should have v1.1 namespace (has changed in 1.1).""" headers = {} diff --git a/manila/tests/scheduler/test_host_manager.py b/manila/tests/scheduler/test_host_manager.py index 8001868a5e..3b214bbbde 100644 --- a/manila/tests/scheduler/test_host_manager.py +++ b/manila/tests/scheduler/test_host_manager.py @@ -163,7 +163,6 @@ class HostManagerTestCase(test.TestCase): class HostStateTestCase(test.TestCase): """Test case for HostState class.""" - def test_update_from_share_capability(self): fake_host = host_manager.HostState('host1') self.assertEqual(fake_host.free_capacity_gb, None) diff --git a/manila/tests/test_migrations.py b/manila/tests/test_migrations.py index f7a9fceb82..c542763612 100644 --- a/manila/tests/test_migrations.py +++ b/manila/tests/test_migrations.py @@ -370,261 +370,3 @@ class TestMigrations(test.TestCase): (version, engine)) raise - # migration 004 - change volume types to UUID - @test.skip_test("migrations fix") - def _prerun_004(self, engine): - data = { - 'volumes': [{'id': str(uuid.uuid4()), 'host': 'test1', - 'volume_type_id': 1}, - {'id': str(uuid.uuid4()), 'host': 'test2', - 'volume_type_id': 1}, - {'id': str(uuid.uuid4()), 'host': 'test3', - 'volume_type_id': 3}, - ], - 'volume_types': [{'name': 'vtype1'}, - {'name': 'vtype2'}, - {'name': 'vtype3'}, - ], - 'volume_type_extra_specs': [{'volume_type_id': 1, - 'key': 'v1', - 'value': 'hotep', - }, - {'volume_type_id': 1, - 'key': 'v2', - 'value': 'bending rodrigez', - }, - {'volume_type_id': 2, - 'key': 'v3', - 'value': 'bending rodrigez', - }, - ]} - - volume_types = get_table(engine, 'volume_types') - for vtype in data['volume_types']: - r = volume_types.insert().values(vtype).execute() - vtype['id'] = r.inserted_primary_key[0] - - volume_type_es = get_table(engine, 'volume_type_extra_specs') - for vtes in data['volume_type_extra_specs']: - r = volume_type_es.insert().values(vtes).execute() - vtes['id'] = r.inserted_primary_key[0] - - volumes = get_table(engine, 'volumes') - for vol in data['volumes']: - r = volumes.insert().values(vol).execute() - vol['id'] = r.inserted_primary_key[0] - - return data - - def _check_004(self, engine, data): - volumes = get_table(engine, 'volumes') - v1 = volumes.select(volumes.c.id == - data['volumes'][0]['id'] - ).execute().first() - v2 = volumes.select(volumes.c.id == - data['volumes'][1]['id'] - ).execute().first() - v3 = volumes.select(volumes.c.id == - data['volumes'][2]['id'] - ).execute().first() - - volume_types = get_table(engine, 'volume_types') - vt1 = volume_types.select(volume_types.c.name == - data['volume_types'][0]['name'] - ).execute().first() - vt2 = volume_types.select(volume_types.c.name == - data['volume_types'][1]['name'] - ).execute().first() - vt3 = volume_types.select(volume_types.c.name == - data['volume_types'][2]['name'] - ).execute().first() - - vtes = get_table(engine, 'volume_type_extra_specs') - vtes1 = vtes.select(vtes.c.key == - data['volume_type_extra_specs'][0]['key'] - ).execute().first() - vtes2 = vtes.select(vtes.c.key == - data['volume_type_extra_specs'][1]['key'] - ).execute().first() - vtes3 = vtes.select(vtes.c.key == - data['volume_type_extra_specs'][2]['key'] - ).execute().first() - - self.assertEqual(v1['volume_type_id'], vt1['id']) - self.assertEqual(v2['volume_type_id'], vt1['id']) - self.assertEqual(v3['volume_type_id'], vt3['id']) - - self.assertEqual(vtes1['volume_type_id'], vt1['id']) - self.assertEqual(vtes2['volume_type_id'], vt1['id']) - self.assertEqual(vtes3['volume_type_id'], vt2['id']) - @test.skip_test("migrations fix") - def test_migration_005(self): - """Test that adding source_volid column works correctly.""" - for (key, engine) in self.engines.items(): - migration_api.version_control(engine, - TestMigrations.REPOSITORY, - migration.INIT_VERSION) - migration_api.upgrade(engine, TestMigrations.REPOSITORY, 4) - metadata = sqlalchemy.schema.MetaData() - metadata.bind = engine - - migration_api.upgrade(engine, TestMigrations.REPOSITORY, 5) - volumes = sqlalchemy.Table('volumes', - metadata, - autoload=True) - self.assertTrue(isinstance(volumes.c.source_volid.type, - sqlalchemy.types.VARCHAR)) - - def _metadatas(self, upgrade_to, downgrade_to=None): - for (key, engine) in self.engines.items(): - migration_api.version_control(engine, - TestMigrations.REPOSITORY, - migration.INIT_VERSION) - migration_api.upgrade(engine, - TestMigrations.REPOSITORY, - upgrade_to) - - if downgrade_to is not None: - migration_api.downgrade( - engine, TestMigrations.REPOSITORY, downgrade_to) - - metadata = sqlalchemy.schema.MetaData() - metadata.bind = engine - yield metadata - - def metadatas_upgraded_to(self, revision): - return self._metadatas(revision) - - def metadatas_downgraded_from(self, revision): - return self._metadatas(revision, revision - 1) - @test.skip_test("migrations fix") - def test_upgrade_006_adds_provider_location(self): - for metadata in self.metadatas_upgraded_to(6): - snapshots = sqlalchemy.Table('snapshots', metadata, autoload=True) - self.assertTrue(isinstance(snapshots.c.provider_location.type, - sqlalchemy.types.VARCHAR)) - @test.skip_test("migrations fix") - def test_downgrade_006_removes_provider_location(self): - for metadata in self.metadatas_downgraded_from(6): - snapshots = sqlalchemy.Table('snapshots', metadata, autoload=True) - - self.assertTrue('provider_location' not in snapshots.c) - @test.skip_test("migrations fix") - def test_upgrade_007_adds_fk(self): - for metadata in self.metadatas_upgraded_to(7): - snapshots = sqlalchemy.Table('snapshots', metadata, autoload=True) - volumes = sqlalchemy.Table('volumes', metadata, autoload=True) - - fkey, = snapshots.c.volume_id.foreign_keys - - self.assertEquals(volumes.c.id, fkey.column) - @test.skip_test("migrations fix") - def test_downgrade_007_removes_fk(self): - for metadata in self.metadatas_downgraded_from(7): - snapshots = sqlalchemy.Table('snapshots', metadata, autoload=True) - - self.assertEquals(0, len(snapshots.c.volume_id.foreign_keys)) - @test.skip_test("migrations fix") - def test_migration_008(self): - """Test that adding and removing the backups table works correctly""" - for (key, engine) in self.engines.items(): - migration_api.version_control(engine, - TestMigrations.REPOSITORY, - migration.INIT_VERSION) - migration_api.upgrade(engine, TestMigrations.REPOSITORY, 7) - metadata = sqlalchemy.schema.MetaData() - metadata.bind = engine - - migration_api.upgrade(engine, TestMigrations.REPOSITORY, 8) - - self.assertTrue(engine.dialect.has_table(engine.connect(), - "backups")) - backups = sqlalchemy.Table('backups', - metadata, - autoload=True) - - self.assertTrue(isinstance(backups.c.created_at.type, - sqlalchemy.types.DATETIME)) - self.assertTrue(isinstance(backups.c.updated_at.type, - sqlalchemy.types.DATETIME)) - self.assertTrue(isinstance(backups.c.deleted_at.type, - sqlalchemy.types.DATETIME)) - self.assertTrue(isinstance(backups.c.deleted.type, - sqlalchemy.types.BOOLEAN)) - self.assertTrue(isinstance(backups.c.id.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.volume_id.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.user_id.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.project_id.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.host.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.availability_zone.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.display_name.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.display_description.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.container.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.status.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.fail_reason.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.service_metadata.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.service.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(backups.c.size.type, - sqlalchemy.types.INTEGER)) - self.assertTrue(isinstance(backups.c.object_count.type, - sqlalchemy.types.INTEGER)) - - migration_api.downgrade(engine, TestMigrations.REPOSITORY, 7) - - self.assertFalse(engine.dialect.has_table(engine.connect(), - "backups")) - @test.skip_test("migrations fix") - def test_migration_009(self): - """Test adding snapshot_metadata table works correctly.""" - for (key, engine) in self.engines.items(): - migration_api.version_control(engine, - TestMigrations.REPOSITORY, - migration.INIT_VERSION) - migration_api.upgrade(engine, TestMigrations.REPOSITORY, 8) - metadata = sqlalchemy.schema.MetaData() - metadata.bind = engine - - migration_api.upgrade(engine, TestMigrations.REPOSITORY, 9) - - self.assertTrue(engine.dialect.has_table(engine.connect(), - "snapshot_metadata")) - snapshot_metadata = sqlalchemy.Table('snapshot_metadata', - metadata, - autoload=True) - - self.assertTrue(isinstance(snapshot_metadata.c.created_at.type, - sqlalchemy.types.DATETIME)) - self.assertTrue(isinstance(snapshot_metadata.c.updated_at.type, - sqlalchemy.types.DATETIME)) - self.assertTrue(isinstance(snapshot_metadata.c.deleted_at.type, - sqlalchemy.types.DATETIME)) - self.assertTrue(isinstance(snapshot_metadata.c.deleted.type, - sqlalchemy.types.BOOLEAN)) - self.assertTrue(isinstance(snapshot_metadata.c.deleted.type, - sqlalchemy.types.BOOLEAN)) - self.assertTrue(isinstance(snapshot_metadata.c.id.type, - sqlalchemy.types.INTEGER)) - self.assertTrue(isinstance(snapshot_metadata.c.snapshot_id.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(snapshot_metadata.c.key.type, - sqlalchemy.types.VARCHAR)) - self.assertTrue(isinstance(snapshot_metadata.c.value.type, - sqlalchemy.types.VARCHAR)) - - migration_api.downgrade(engine, TestMigrations.REPOSITORY, 8) - - self.assertFalse(engine.dialect.has_table(engine.connect(), - "snapshot_metadata")) diff --git a/manila/tests/test_share_api.py b/manila/tests/test_share_api.py index ad39eb5e32..d4213d9f47 100644 --- a/manila/tests/test_share_api.py +++ b/manila/tests/test_share_api.py @@ -24,14 +24,13 @@ from manila import context from manila import db as db_driver from manila import exception from manila.openstack.common import timeutils -from manila.context import RequestContext +from manila import quota from manila.scheduler import rpcapi as scheduler_rpcapi from manila import share from manila.share import api as share_api from manila.share import rpcapi as share_rpcapi from manila import test from manila.tests.db import fakes as db_fakes -from manila import quota def fake_share(id, **kwargs): @@ -106,7 +105,7 @@ class ShareAPITestCase(test.TestCase): self.stubs.Set(self.api, 'scheduler_rpcapi', self.scheduler_rpcapi) self.stubs.Set(self.api, 'share_rpcapi', self.share_rpcapi) - self.stubs.Set(quota.QUOTAS, 'reserve', lambda *args, **kwargs : None) + self.stubs.Set(quota.QUOTAS, 'reserve', lambda *args, **kwargs: None) def tearDown(self): super(ShareAPITestCase, self).tearDown() @@ -317,7 +316,7 @@ class ShareAPITestCase(test.TestCase): share['host'] = None self.mox.StubOutWithMock(db_driver, 'share_delete') - db_driver.share_delete(mox.IsA(RequestContext), 'fakeid') + db_driver.share_delete(mox.IsA(context.RequestContext), 'fakeid') self.mox.ReplayAll() self.api.delete(self.context, share) diff --git a/manila/tests/test_utils.py b/manila/tests/test_utils.py index b89aaded73..0ed779083f 100644 --- a/manila/tests/test_utils.py +++ b/manila/tests/test_utils.py @@ -65,7 +65,7 @@ echo $runs > "$1" exit 1 ''') fp.close() - os.chmod(tmpfilename, 0755) + os.chmod(tmpfilename, 0o755) self.assertRaises(exception.ProcessExecutionError, utils.execute, tmpfilename, tmpfilename2, attempts=10, @@ -110,7 +110,7 @@ echo foo > "$1" grep foo ''') fp.close() - os.chmod(tmpfilename, 0755) + os.chmod(tmpfilename, 0o755) utils.execute(tmpfilename, tmpfilename2, process_input='foo', diff --git a/manila/tests/windows/basetestcase.py b/manila/tests/windows/basetestcase.py index 4157e325f1..3bc3c642b0 100644 --- a/manila/tests/windows/basetestcase.py +++ b/manila/tests/windows/basetestcase.py @@ -18,8 +18,8 @@ TestCase for MockProxy based tests and related classes. """ -import manila.test import gzip +import manila.test import os import pickle diff --git a/tools/conf/extract_opts.py b/tools/conf/extract_opts.py index 5455fcd245..53fa50ed04 100644 --- a/tools/conf/extract_opts.py +++ b/tools/conf/extract_opts.py @@ -49,6 +49,7 @@ PY_EXT = ".py" BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")) WORDWRAP_WIDTH = 60 + def main(srcfiles): print('\n'.join(['#' * 20, '# manila.conf sample #', '#' * 20, '', '[DEFAULT]', '']))