From c885f33c311ca88a141b7a138036a3a2b9974b82 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 11 Feb 2013 17:29:31 +0100 Subject: [PATCH] Code cleanup, remove useless import This is a massive removal of all useless import that are all over the code and unit tests. There's also some simple dead code removal or move. Change-Id: Ida1208b47f38e552219e3b909f8d7c4f22ba3273 Signed-off-by: Julien Danjou --- ceilometer/api/middleware.py | 2 -- ceilometer/energy/kwapi.py | 1 - ceilometer/pipeline.py | 1 - ceilometer/plugin.py | 5 ++-- ceilometer/storage/impl_sqlalchemy.py | 4 ++- .../versions/001_add_meter_table.py | 1 - .../versions/003_set_utf8_charset.py | 2 -- ceilometer/storage/sqlalchemy/models.py | 2 +- ceilometer/storage/sqlalchemy/session.py | 1 - ceilometer/tests/api.py | 4 --- ceilometer/tests/skip.py | 1 - tests/api/v1/test_list_sources.py | 6 ---- tests/central/test_manager.py | 1 - tests/collector/test_manager.py | 1 - tests/compute/test_manager.py | 1 - tests/compute/test_pollsters.py | 2 -- tests/compute/virt/libvirt/test_inspector.py | 4 --- tests/image/test_notifications.py | 30 +++++++++++-------- tests/objectstore/test_swift_middleware.py | 1 - tests/storage/base.py | 4 --- tests/storage/test_impl_mongodb.py | 2 -- tests/storage/test_impl_sqlalchemy.py | 4 +-- tests/test_pipeline.py | 3 -- tests/utils.py | 21 ------------- 24 files changed, 24 insertions(+), 80 deletions(-) delete mode 100644 tests/utils.py diff --git a/ceilometer/api/middleware.py b/ceilometer/api/middleware.py index 22786b61c..76676613d 100644 --- a/ceilometer/api/middleware.py +++ b/ceilometer/api/middleware.py @@ -23,8 +23,6 @@ Based on pecan.middleware.errordocument import json -from webob import exc - class ParsableErrorMiddleware(object): """Replace error body with something the client can parse. diff --git a/ceilometer/energy/kwapi.py b/ceilometer/energy/kwapi.py index 95c4da151..803902473 100644 --- a/ceilometer/energy/kwapi.py +++ b/ceilometer/energy/kwapi.py @@ -20,7 +20,6 @@ import requests from ceilometer import counter from ceilometer.central import plugin -from ceilometer.openstack.common import cfg class KwapiClient(object): diff --git a/ceilometer/pipeline.py b/ceilometer/pipeline.py index cfce6680e..d9677f322 100644 --- a/ceilometer/pipeline.py +++ b/ceilometer/pipeline.py @@ -21,7 +21,6 @@ import os from stevedore import extension import yaml -from ceilometer import extension_manager from ceilometer.openstack.common import cfg from ceilometer.openstack.common import log diff --git a/ceilometer/plugin.py b/ceilometer/plugin.py index 3ee34b699..1513fe38f 100644 --- a/ceilometer/plugin.py +++ b/ceilometer/plugin.py @@ -21,10 +21,9 @@ import abc from collections import namedtuple -from ceilometer.openstack.common import cfg -# Import rabbit_notifier to register notification_topics flag so that +# Import rpc_notifier to register notification_topics flag so that # plugins can use it -import ceilometer.openstack.common.notifier.rabbit_notifier +import ceilometer.openstack.common.notifier.rpc_notifier ExchangeTopics = namedtuple('ExchangeTopics', ['exchange', 'topics']) diff --git a/ceilometer/storage/impl_sqlalchemy.py b/ceilometer/storage/impl_sqlalchemy.py index cf758a8e8..3ce7ca512 100644 --- a/ceilometer/storage/impl_sqlalchemy.py +++ b/ceilometer/storage/impl_sqlalchemy.py @@ -16,14 +16,16 @@ """SQLAlchemy storage backend """ +from __future__ import absolute_import + import copy import datetime +from sqlalchemy import func from ceilometer.openstack.common import log from ceilometer.storage import base from ceilometer.storage.sqlalchemy.models import Meter, Project, Resource from ceilometer.storage.sqlalchemy.models import Source, User -from ceilometer.storage.sqlalchemy.session import func import ceilometer.storage.sqlalchemy.session as sqlalchemy_session from ceilometer.storage.sqlalchemy import migration diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/001_add_meter_table.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/001_add_meter_table.py index f5d02fb83..1dfdbcae9 100644 --- a/ceilometer/storage/sqlalchemy/migrate_repo/versions/001_add_meter_table.py +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/001_add_meter_table.py @@ -15,7 +15,6 @@ # under the License. from sqlalchemy import * -from ceilometer.openstack.common import timeutils meta = MetaData() diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/003_set_utf8_charset.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/003_set_utf8_charset.py index 347ef51f9..14a9fee37 100644 --- a/ceilometer/storage/sqlalchemy/migrate_repo/versions/003_set_utf8_charset.py +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/003_set_utf8_charset.py @@ -14,8 +14,6 @@ # License for the specific language governing permissions and limitations # under the License. -from sqlalchemy import MetaData - def upgrade(migrate_engine): diff --git a/ceilometer/storage/sqlalchemy/models.py b/ceilometer/storage/sqlalchemy/models.py index c6eba7e77..930e70699 100644 --- a/ceilometer/storage/sqlalchemy/models.py +++ b/ceilometer/storage/sqlalchemy/models.py @@ -22,7 +22,7 @@ import json from sqlalchemy import Column, Integer, String, Table from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import ForeignKey, DateTime -from sqlalchemy.orm import relationship, backref +from sqlalchemy.orm import relationship from sqlalchemy.types import TypeDecorator, VARCHAR from urlparse import urlparse diff --git a/ceilometer/storage/sqlalchemy/session.py b/ceilometer/storage/sqlalchemy/session.py index ad955367a..8742f3591 100644 --- a/ceilometer/storage/sqlalchemy/session.py +++ b/ceilometer/storage/sqlalchemy/session.py @@ -22,7 +22,6 @@ import re import time import sqlalchemy -from sqlalchemy import func from sqlalchemy.exc import DisconnectionError, OperationalError import sqlalchemy.orm from sqlalchemy.pool import NullPool, StaticPool diff --git a/ceilometer/tests/api.py b/ceilometer/tests/api.py index 20dd832ae..3c240a7fb 100644 --- a/ceilometer/tests/api.py +++ b/ceilometer/tests/api.py @@ -26,13 +26,9 @@ import flask from pecan import set_config from pecan.testing import load_test_app -import mox -import stubout - from ceilometer import storage from ceilometer.api.v1 import app as v1_app from ceilometer.api.v1 import blueprint as v1_blueprint -from ceilometer.api.controllers import v2 from ceilometer.openstack.common import cfg from ceilometer.tests import db as db_test_base from ceilometer.tests import base diff --git a/ceilometer/tests/skip.py b/ceilometer/tests/skip.py index da58b6c59..7985dc05d 100644 --- a/ceilometer/tests/skip.py +++ b/ceilometer/tests/skip.py @@ -24,7 +24,6 @@ inline callbacks. """ import functools -import unittest import nose.plugins.skip diff --git a/tests/api/v1/test_list_sources.py b/tests/api/v1/test_list_sources.py index 49d15a08f..399f7e455 100644 --- a/tests/api/v1/test_list_sources.py +++ b/tests/api/v1/test_list_sources.py @@ -18,12 +18,6 @@ """Test listing users. """ -import datetime -import logging - -from ceilometer.collector import meter -from ceilometer import counter - from ceilometer.tests import api as tests_api diff --git a/tests/central/test_manager.py b/tests/central/test_manager.py index c8f059180..3767f7c01 100644 --- a/tests/central/test_manager.py +++ b/tests/central/test_manager.py @@ -24,7 +24,6 @@ from stevedore import extension from ceilometer.central import manager from ceilometer import counter -from ceilometer import pipeline from ceilometer.tests import base from ceilometer.openstack.common import cfg diff --git a/tests/collector/test_manager.py b/tests/collector/test_manager.py index 9d5ddda6e..89b3ffebf 100644 --- a/tests/collector/test_manager.py +++ b/tests/collector/test_manager.py @@ -29,7 +29,6 @@ from stevedore.tests import manager as test_manager from ceilometer.collector import meter from ceilometer.collector import service from ceilometer.openstack.common import cfg -from ceilometer import pipeline from ceilometer.storage import base from ceilometer.tests import base as tests_base from ceilometer.compute import notifications diff --git a/tests/compute/test_manager.py b/tests/compute/test_manager.py index 86118f21e..2fc15b621 100644 --- a/tests/compute/test_manager.py +++ b/tests/compute/test_manager.py @@ -25,7 +25,6 @@ from stevedore import extension from ceilometer import nova_client from ceilometer.compute import manager from ceilometer import counter -from ceilometer import pipeline from ceilometer.tests import base from ceilometer.openstack.common import cfg diff --git a/tests/compute/test_pollsters.py b/tests/compute/test_pollsters.py index 3cc114cf1..65b64a3cc 100644 --- a/tests/compute/test_pollsters.py +++ b/tests/compute/test_pollsters.py @@ -28,8 +28,6 @@ from ceilometer.compute import manager from ceilometer.compute.virt import inspector as virt_inspector from ceilometer.tests import base as test_base -import mox - class TestPollsterBase(test_base.TestCase): diff --git a/tests/compute/virt/libvirt/test_inspector.py b/tests/compute/virt/libvirt/test_inspector.py index 1be2ad026..853cc29f3 100644 --- a/tests/compute/virt/libvirt/test_inspector.py +++ b/tests/compute/virt/libvirt/test_inspector.py @@ -19,13 +19,9 @@ """Tests for libvirt inspector. """ -import time - from ceilometer.compute.virt.libvirt import inspector as libvirt_inspector from ceilometer.tests import base as test_base -import mox - class TestLibvirtInspection(test_base.TestCase): diff --git a/tests/image/test_notifications.py b/tests/image/test_notifications.py index e4ae8f118..0aba1aabe 100644 --- a/tests/image/test_notifications.py +++ b/tests/image/test_notifications.py @@ -22,22 +22,26 @@ import unittest from ceilometer.image import notifications from ceilometer import counter -from tests import utils + + +def fake_uuid(x): + return '%s-%s-%s-%s' % (x * 8, x * 4, x * 4, x * 12) + NOW = datetime.isoformat(datetime.utcnow()) NOTIFICATION_SEND = { u'event_type': u'image.send', u'timestamp': NOW, - u'message_id': utils.fake_uuid('a'), + u'message_id': fake_uuid('a'), u'priority': u'INFO', u'publisher_id': u'images.example.com', - u'payload': {u'receiver_tenant_id': utils.fake_uuid('b'), + u'payload': {u'receiver_tenant_id': fake_uuid('b'), u'destination_ip': u'1.2.3.4', u'bytes_sent': 42, - u'image_id': utils.fake_uuid('c'), - u'receiver_user_id': utils.fake_uuid('d'), - u'owner_id': utils.fake_uuid('e')} + u'image_id': fake_uuid('c'), + u'receiver_user_id': fake_uuid('d'), + u'owner_id': fake_uuid('e')} } IMAGE_META = {u'status': u'saving', @@ -51,7 +55,7 @@ IMAGE_META = {u'status': u'saving', u'key1': u'value1'}, u'min_disk': 0, u'protected': False, - u'id': utils.fake_uuid('c'), + u'id': fake_uuid('c'), u'location': None, u'checksum': u'd990432ef91afef3ad9dbf4a975d3365', u'owner': "fake", @@ -90,7 +94,7 @@ class TestNotification(unittest.TestCase): def _verify_common_counter(self, c, name, volume): self.assertFalse(c is None) self.assertEqual(c.name, name) - self.assertEqual(c.resource_id, utils.fake_uuid('c')) + self.assertEqual(c.resource_id, fake_uuid('c')) self.assertEqual(c.timestamp, NOW) self.assertEqual(c.volume, volume) metadata = c.resource_metadata @@ -102,8 +106,8 @@ class TestNotification(unittest.TestCase): self.assertEqual(len(counters), 1) download = counters[0] self._verify_common_counter(download, 'image.download', 42) - self.assertEqual(download.user_id, utils.fake_uuid('d')) - self.assertEqual(download.project_id, utils.fake_uuid('b')) + self.assertEqual(download.user_id, fake_uuid('d')) + self.assertEqual(download.project_id, fake_uuid('b')) self.assertEqual(download.type, counter.TYPE_DELTA) def test_image_serve(self): @@ -112,11 +116,11 @@ class TestNotification(unittest.TestCase): self.assertEqual(len(counters), 1) serve = counters[0] self._verify_common_counter(serve, 'image.serve', 42) - self.assertEqual(serve.project_id, utils.fake_uuid('e')) + self.assertEqual(serve.project_id, fake_uuid('e')) self.assertEquals(serve.resource_metadata.get('receiver_user_id'), - utils.fake_uuid('d')) + fake_uuid('d')) self.assertEquals(serve.resource_metadata.get('receiver_tenant_id'), - utils.fake_uuid('b')) + fake_uuid('b')) self.assertEqual(serve.type, counter.TYPE_DELTA) def test_image_crud_on_update(self): diff --git a/tests/objectstore/test_swift_middleware.py b/tests/objectstore/test_swift_middleware.py index a018e2e28..439a9fbbe 100644 --- a/tests/objectstore/test_swift_middleware.py +++ b/tests/objectstore/test_swift_middleware.py @@ -22,7 +22,6 @@ from webob import Request from ceilometer.tests import base from ceilometer.objectstore import swift_middleware -from ceilometer.openstack.common import rpc from ceilometer import pipeline diff --git a/tests/storage/base.py b/tests/storage/base.py index ad5bff2ca..11f8893d6 100644 --- a/tests/storage/base.py +++ b/tests/storage/base.py @@ -33,9 +33,6 @@ from ceilometer.tests import base as test_base class DBEngineBase(object): __metaclass__ = abc.ABCMeta - def __init__(self): - super(DBEngineBase, self).__init__() - @abc.abstractmethod def get_connection(self): """Return an open connection to the DB @@ -75,7 +72,6 @@ class DBTestBase(test_base.TestCase): '''Return an instance of the class which implements the DBEngineTestBase abstract class ''' - return None def __setup_engine(self): if self.engine is None: diff --git a/tests/storage/test_impl_mongodb.py b/tests/storage/test_impl_mongodb.py index c6300a7a9..8b9b34381 100644 --- a/tests/storage/test_impl_mongodb.py +++ b/tests/storage/test_impl_mongodb.py @@ -46,11 +46,9 @@ """ - import mox from tests.storage import base -from ceilometer import storage from ceilometer.tests.db import TestConnection, require_map_reduce diff --git a/tests/storage/test_impl_sqlalchemy.py b/tests/storage/test_impl_sqlalchemy.py index ab1e5ba96..595e3f89b 100644 --- a/tests/storage/test_impl_sqlalchemy.py +++ b/tests/storage/test_impl_sqlalchemy.py @@ -19,13 +19,11 @@ import logging import os import sqlalchemy -import re from tests.storage import base from ceilometer.openstack.common import cfg -from ceilometer import storage from ceilometer.storage import impl_sqlalchemy -from ceilometer.storage.sqlalchemy.models import Meter, Project, Resource, User +from ceilometer.storage.sqlalchemy.models import Project, User from ceilometer.storage.sqlalchemy.models import table_args diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 10bb1eefe..e3fe59957 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -16,13 +16,10 @@ # License for the specific language governing permissions and limitations # under the License. -import copy - from stevedore import dispatch from stevedore import extension from ceilometer import counter -from ceilometer import extension_manager as act_extension from ceilometer.openstack.common import timeutils from ceilometer import pipeline from ceilometer.tests import base diff --git a/tests/utils.py b/tests/utils.py deleted file mode 100644 index f019f14d4..000000000 --- a/tests/utils.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- encoding: utf-8 -*- -# -# Copyright © 2012 Red Hat Inc. -# -# Author: Eoghan Glynn -# -# 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. - - -def fake_uuid(x): - return '%s-%s-%s-%s' % (x * 8, x * 4, x * 4, x * 12)