Fix hacking rule 302 and enable it
H302: import only modules. Change-Id: I9f18abdc5f52f0a2ee3b8dbb7479dac8de3a0a7a
This commit is contained in:
parent
a2139d8518
commit
18eec72865
@ -53,10 +53,11 @@ except ImportError:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Swift > 1.7.5 ... module exists but doesn't contain class.
|
# Swift > 1.7.5 ... module exists but doesn't contain class.
|
||||||
from swift.common.utils import InputProxy
|
InputProxy = utils.InputProxy
|
||||||
except ImportError:
|
except AttributeError:
|
||||||
# Swift <= 1.7.5 ... module exists and has class.
|
# Swift <= 1.7.5 ... module exists and has class.
|
||||||
from swift.common.middleware.proxy_logging import InputProxy
|
from swift.common.middleware import proxy_logging
|
||||||
|
InputProxy = proxy_logging.InputProxy
|
||||||
|
|
||||||
from ceilometer.openstack.common import context
|
from ceilometer.openstack.common import context
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
|
@ -27,7 +27,7 @@ from ceilometer.openstack.common import timeutils
|
|||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests import api as acl
|
from ceilometer.tests import api as acl
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
VALID_TOKEN = '4562138218392831'
|
VALID_TOKEN = '4562138218392831'
|
||||||
@ -71,7 +71,7 @@ class FakeMemcache(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestAPIACL(FunctionalTest,
|
class TestAPIACL(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -29,11 +29,11 @@ from six import moves
|
|||||||
|
|
||||||
from ceilometer.alarm.storage import models
|
from ceilometer.alarm.storage import models
|
||||||
from ceilometer import messaging
|
from ceilometer import messaging
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class TestListEmptyAlarms(FunctionalTest,
|
class TestListEmptyAlarms(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
@ -41,7 +41,7 @@ class TestListEmptyAlarms(FunctionalTest,
|
|||||||
self.assertEqual([], data)
|
self.assertEqual([], data)
|
||||||
|
|
||||||
|
|
||||||
class TestAlarms(FunctionalTest,
|
class TestAlarms(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -29,7 +29,7 @@ from ceilometer.openstack.common.fixture import config
|
|||||||
from ceilometer.openstack.common import gettextutils
|
from ceilometer.openstack.common import gettextutils
|
||||||
from ceilometer import service
|
from ceilometer import service
|
||||||
from ceilometer.tests import api as acl
|
from ceilometer.tests import api as acl
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import base
|
from ceilometer.tests import base
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class TestApp(base.BaseTestCase):
|
|||||||
os.unlink(tmpfile)
|
os.unlink(tmpfile)
|
||||||
|
|
||||||
|
|
||||||
class TestPecanApp(FunctionalTest):
|
class TestPecanApp(v2.FunctionalTest):
|
||||||
|
|
||||||
def test_pecan_extension_guessing_unset(self):
|
def test_pecan_extension_guessing_unset(self):
|
||||||
# check Pecan does not assume .jpg is an extension
|
# check Pecan does not assume .jpg is an extension
|
||||||
@ -86,7 +86,7 @@ class TestPecanApp(FunctionalTest):
|
|||||||
self.assertEqual('application/json', response.content_type)
|
self.assertEqual('application/json', response.content_type)
|
||||||
|
|
||||||
|
|
||||||
class TestApiMiddleware(FunctionalTest):
|
class TestApiMiddleware(v2.FunctionalTest):
|
||||||
|
|
||||||
no_lang_translated_error = 'No lang translated error'
|
no_lang_translated_error = 'No lang translated error'
|
||||||
en_US_translated_error = 'en-US translated error'
|
en_US_translated_error = 'en-US translated error'
|
||||||
|
@ -23,11 +23,11 @@ import mock
|
|||||||
|
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer.storage import models
|
from ceilometer.storage import models
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class TestComputeDurationByResource(FunctionalTest,
|
class TestComputeDurationByResource(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -18,13 +18,13 @@ import datetime
|
|||||||
|
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer.storage import models
|
from ceilometer.storage import models
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
headers = {"X-Roles": "admin"}
|
headers = {"X-Roles": "admin"}
|
||||||
|
|
||||||
|
|
||||||
class EventTestBase(FunctionalTest,
|
class EventTestBase(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -25,11 +25,11 @@ import webtest.app
|
|||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class TestListEvents(FunctionalTest,
|
class TestListEvents(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -25,11 +25,11 @@ import webtest.app
|
|||||||
|
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class TestListEmptyMeters(FunctionalTest,
|
class TestListEmptyMeters(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
@ -37,7 +37,7 @@ class TestListEmptyMeters(FunctionalTest,
|
|||||||
self.assertEqual([], data)
|
self.assertEqual([], data)
|
||||||
|
|
||||||
|
|
||||||
class TestValidateUserInput(FunctionalTest,
|
class TestValidateUserInput(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def test_list_meters_query_float_metadata(self):
|
def test_list_meters_query_float_metadata(self):
|
||||||
@ -61,7 +61,7 @@ class TestValidateUserInput(FunctionalTest,
|
|||||||
'type': 'integer'}])
|
'type': 'integer'}])
|
||||||
|
|
||||||
|
|
||||||
class TestListMeters(FunctionalTest,
|
class TestListMeters(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -25,11 +25,11 @@ import six
|
|||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class TestListResources(FunctionalTest,
|
class TestListResources(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
|
@ -24,11 +24,11 @@ import mock
|
|||||||
|
|
||||||
from ceilometer.openstack.common.fixture import mockpatch
|
from ceilometer.openstack.common.fixture import mockpatch
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class TestPostSamples(FunctionalTest,
|
class TestPostSamples(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
def fake_cast(self, ctxt, target, data):
|
def fake_cast(self, ctxt, target, data):
|
||||||
for m in data:
|
for m in data:
|
||||||
|
@ -21,7 +21,7 @@ import mock
|
|||||||
import wsme
|
import wsme
|
||||||
|
|
||||||
from ceilometer.api.controllers import v2 as api
|
from ceilometer.api.controllers import v2 as api
|
||||||
from ceilometer.openstack.common.fixture.mockpatch import PatchObject
|
from ceilometer.openstack.common.fixture import mockpatch
|
||||||
from ceilometer.openstack.common import test
|
from ceilometer.openstack.common import test
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer import storage
|
from ceilometer import storage
|
||||||
@ -175,10 +175,10 @@ class TestValidateGroupByFields(test.BaseTestCase):
|
|||||||
class TestQueryToKwArgs(tests_base.BaseTestCase):
|
class TestQueryToKwArgs(tests_base.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestQueryToKwArgs, self).setUp()
|
super(TestQueryToKwArgs, self).setUp()
|
||||||
self.useFixture(PatchObject(api, '_sanitize_query',
|
self.useFixture(mockpatch.PatchObject(
|
||||||
side_effect=lambda x, y, **z: x))
|
api, '_sanitize_query', side_effect=lambda x, y, **z: x))
|
||||||
self.useFixture(PatchObject(api, '_verify_query_segregation',
|
self.useFixture(mockpatch.PatchObject(
|
||||||
side_effect=lambda x, **z: x))
|
api, '_verify_query_segregation', side_effect=lambda x, **z: x))
|
||||||
|
|
||||||
def test_sample_filter_single(self):
|
def test_sample_filter_single(self):
|
||||||
q = [api.Query(field='user_id',
|
q = [api.Query(field='user_id',
|
||||||
|
@ -20,11 +20,11 @@ import datetime
|
|||||||
|
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api import v2
|
||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class TestMaxProjectVolume(FunctionalTest,
|
class TestMaxProjectVolume(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
PATH = '/meters/volume.size/statistics'
|
PATH = '/meters/volume.size/statistics'
|
||||||
@ -122,7 +122,7 @@ class TestMaxProjectVolume(FunctionalTest,
|
|||||||
self.assertEqual(1, data[0]['count'])
|
self.assertEqual(1, data[0]['count'])
|
||||||
|
|
||||||
|
|
||||||
class TestMaxResourceVolume(FunctionalTest,
|
class TestMaxResourceVolume(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
PATH = '/meters/volume.size/statistics'
|
PATH = '/meters/volume.size/statistics'
|
||||||
@ -243,7 +243,7 @@ class TestMaxResourceVolume(FunctionalTest,
|
|||||||
self.assertEqual(1, data[0]['count'])
|
self.assertEqual(1, data[0]['count'])
|
||||||
|
|
||||||
|
|
||||||
class TestSumProjectVolume(FunctionalTest,
|
class TestSumProjectVolume(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
PATH = '/meters/volume.size/statistics'
|
PATH = '/meters/volume.size/statistics'
|
||||||
@ -343,7 +343,7 @@ class TestSumProjectVolume(FunctionalTest,
|
|||||||
self.assertEqual(1, data[0]['count'])
|
self.assertEqual(1, data[0]['count'])
|
||||||
|
|
||||||
|
|
||||||
class TestSumResourceVolume(FunctionalTest,
|
class TestSumResourceVolume(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
PATH = '/meters/volume.size/statistics'
|
PATH = '/meters/volume.size/statistics'
|
||||||
@ -469,7 +469,7 @@ class TestSumResourceVolume(FunctionalTest,
|
|||||||
self.assertEqual(1, data[0]['count'])
|
self.assertEqual(1, data[0]['count'])
|
||||||
|
|
||||||
|
|
||||||
class TestGroupByInstance(FunctionalTest,
|
class TestGroupByInstance(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
PATH = '/meters/instance/statistics'
|
PATH = '/meters/instance/statistics'
|
||||||
@ -1214,7 +1214,7 @@ class TestGroupByInstance(FunctionalTest,
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb', 'hbase', 'db2')
|
@tests_db.run_with('mongodb', 'hbase', 'db2')
|
||||||
class TestGroupBySource(FunctionalTest,
|
class TestGroupBySource(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
# FIXME(terriyu): We have to put test_group_by_source in its own class
|
# FIXME(terriyu): We have to put test_group_by_source in its own class
|
||||||
@ -1318,7 +1318,7 @@ class TestGroupBySource(FunctionalTest,
|
|||||||
self.assertEqual(4, r['avg'])
|
self.assertEqual(4, r['avg'])
|
||||||
|
|
||||||
|
|
||||||
class TestSelectableAggregates(FunctionalTest,
|
class TestSelectableAggregates(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
PATH = '/meters/instance/statistics'
|
PATH = '/meters/instance/statistics'
|
||||||
@ -1562,7 +1562,7 @@ class TestSelectableAggregates(FunctionalTest,
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb', 'hbase', 'db2')
|
@tests_db.run_with('mongodb', 'hbase', 'db2')
|
||||||
class TestUnparameterizedAggregates(FunctionalTest,
|
class TestUnparameterizedAggregates(v2.FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
# We put the stddev test case in a separate class so that we
|
# We put the stddev test case in a separate class so that we
|
||||||
|
@ -22,7 +22,7 @@ import mock
|
|||||||
from ceilometer.central import manager
|
from ceilometer.central import manager
|
||||||
from ceilometer.energy import kwapi
|
from ceilometer.energy import kwapi
|
||||||
from ceilometer.openstack.common import context
|
from ceilometer.openstack.common import context
|
||||||
from ceilometer.openstack.common.fixture.mockpatch import PatchObject
|
from ceilometer.openstack.common.fixture import mockpatch
|
||||||
from ceilometer.openstack.common import test
|
from ceilometer.openstack.common import test
|
||||||
|
|
||||||
|
|
||||||
@ -67,8 +67,8 @@ class TestKwapi(test.BaseTestCase):
|
|||||||
raise exceptions.EndpointNotFound("fake keystone exception")
|
raise exceptions.EndpointNotFound("fake keystone exception")
|
||||||
|
|
||||||
def test_endpoint_not_exist(self):
|
def test_endpoint_not_exist(self):
|
||||||
with PatchObject(kwapi._Base, 'get_kwapi_client',
|
with mockpatch.PatchObject(kwapi._Base, 'get_kwapi_client',
|
||||||
side_effect=self.fake_get_kwapi_client):
|
side_effect=self.fake_get_kwapi_client):
|
||||||
pollster = kwapi.EnergyPollster()
|
pollster = kwapi.EnergyPollster()
|
||||||
samples = list(pollster.get_samples(self.manager, {}))
|
samples = list(pollster.get_samples(self.manager, {}))
|
||||||
|
|
||||||
@ -82,8 +82,8 @@ class TestEnergyPollster(test.BaseTestCase):
|
|||||||
super(TestEnergyPollster, self).setUp()
|
super(TestEnergyPollster, self).setUp()
|
||||||
self.context = context.get_admin_context()
|
self.context = context.get_admin_context()
|
||||||
self.manager = TestManager()
|
self.manager = TestManager()
|
||||||
self.useFixture(PatchObject(kwapi._Base, '_iter_probes',
|
self.useFixture(mockpatch.PatchObject(
|
||||||
side_effect=self.fake_iter_probes))
|
kwapi._Base, '_iter_probes', side_effect=self.fake_iter_probes))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fake_iter_probes(ksclient, cache):
|
def fake_iter_probes(ksclient, cache):
|
||||||
@ -142,8 +142,8 @@ class TestPowerPollster(test.BaseTestCase):
|
|||||||
super(TestPowerPollster, self).setUp()
|
super(TestPowerPollster, self).setUp()
|
||||||
self.context = context.get_admin_context()
|
self.context = context.get_admin_context()
|
||||||
self.manager = TestManager()
|
self.manager = TestManager()
|
||||||
self.useFixture(PatchObject(kwapi._Base, '_iter_probes',
|
self.useFixture(mockpatch.PatchObject(
|
||||||
side_effect=self.fake_iter_probes))
|
kwapi._Base, '_iter_probes', side_effect=self.fake_iter_probes))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fake_iter_probes(ksclient, cache):
|
def fake_iter_probes(ksclient, cache):
|
||||||
|
@ -25,7 +25,7 @@ import testscenarios.testcase
|
|||||||
|
|
||||||
from ceilometer.central import manager
|
from ceilometer.central import manager
|
||||||
from ceilometer.objectstore import swift
|
from ceilometer.objectstore import swift
|
||||||
from ceilometer.openstack.common.fixture.mockpatch import PatchObject
|
from ceilometer.openstack.common.fixture import mockpatch
|
||||||
from ceilometer.openstack.common import test
|
from ceilometer.openstack.common import test
|
||||||
|
|
||||||
HEAD_ACCOUNTS = [('tenant-000', {'x-account-object-count': 12,
|
HEAD_ACCOUNTS = [('tenant-000', {'x-account-object-count': 12,
|
||||||
@ -100,8 +100,8 @@ class TestSwiftPollster(testscenarios.testcase.WithScenarios,
|
|||||||
|
|
||||||
def test_iter_accounts_no_cache(self):
|
def test_iter_accounts_no_cache(self):
|
||||||
cache = {}
|
cache = {}
|
||||||
with PatchObject(self.factory, '_get_account_info',
|
with mockpatch.PatchObject(self.factory, '_get_account_info',
|
||||||
return_value=[]):
|
return_value=[]):
|
||||||
data = list(self.pollster._iter_accounts(mock.Mock(), cache))
|
data = list(self.pollster._iter_accounts(mock.Mock(), cache))
|
||||||
|
|
||||||
self.assertTrue(self.pollster.CACHE_KEY_TENANT in cache)
|
self.assertTrue(self.pollster.CACHE_KEY_TENANT in cache)
|
||||||
@ -118,8 +118,8 @@ class TestSwiftPollster(testscenarios.testcase.WithScenarios,
|
|||||||
)
|
)
|
||||||
|
|
||||||
api_method = '%s_account' % self.pollster.METHOD
|
api_method = '%s_account' % self.pollster.METHOD
|
||||||
with PatchObject(swift_client, api_method, new=ksclient):
|
with mockpatch.PatchObject(swift_client, api_method, new=ksclient):
|
||||||
with PatchObject(self.factory, '_neaten_url'):
|
with mockpatch.PatchObject(self.factory, '_neaten_url'):
|
||||||
Tenant = collections.namedtuple('Tenant', 'id')
|
Tenant = collections.namedtuple('Tenant', 'id')
|
||||||
cache = {
|
cache = {
|
||||||
self.pollster.CACHE_KEY_TENANT: [
|
self.pollster.CACHE_KEY_TENANT: [
|
||||||
@ -148,23 +148,24 @@ class TestSwiftPollster(testscenarios.testcase.WithScenarios,
|
|||||||
self.assertEqual(standard_url, url)
|
self.assertEqual(standard_url, url)
|
||||||
|
|
||||||
def test_metering(self):
|
def test_metering(self):
|
||||||
with PatchObject(self.factory, '_iter_accounts',
|
with mockpatch.PatchObject(self.factory, '_iter_accounts',
|
||||||
side_effect=self.fake_iter_accounts):
|
side_effect=self.fake_iter_accounts):
|
||||||
samples = list(self.pollster.get_samples(self.manager, {}))
|
samples = list(self.pollster.get_samples(self.manager, {}))
|
||||||
|
|
||||||
self.assertEqual(2, len(samples))
|
self.assertEqual(2, len(samples))
|
||||||
|
|
||||||
def test_get_meter_names(self):
|
def test_get_meter_names(self):
|
||||||
with PatchObject(self.factory, '_iter_accounts',
|
with mockpatch.PatchObject(self.factory, '_iter_accounts',
|
||||||
side_effect=self.fake_iter_accounts):
|
side_effect=self.fake_iter_accounts):
|
||||||
samples = list(self.pollster.get_samples(self.manager, {}))
|
samples = list(self.pollster.get_samples(self.manager, {}))
|
||||||
|
|
||||||
self.assertEqual(set([samples[0].name]),
|
self.assertEqual(set([samples[0].name]),
|
||||||
set([s.name for s in samples]))
|
set([s.name for s in samples]))
|
||||||
|
|
||||||
def test_endpoint_notfound(self):
|
def test_endpoint_notfound(self):
|
||||||
with PatchObject(self.manager.keystone.service_catalog, 'url_for',
|
with mockpatch.PatchObject(
|
||||||
side_effect=self.fake_ks_service_catalog_url_for):
|
self.manager.keystone.service_catalog, 'url_for',
|
||||||
|
side_effect=self.fake_ks_service_catalog_url_for):
|
||||||
samples = list(self.pollster.get_samples(self.manager, {}))
|
samples = list(self.pollster.get_samples(self.manager, {}))
|
||||||
|
|
||||||
self.assertEqual(0, len(samples))
|
self.assertEqual(0, len(samples))
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
running the tests. Make sure the Thrift server is running on that server.
|
running the tests. Make sure the Thrift server is running on that server.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from mock import patch
|
import mock
|
||||||
|
|
||||||
from ceilometer.storage.hbase import inmemory as hbase_inmemory
|
from ceilometer.storage.hbase import inmemory as hbase_inmemory
|
||||||
from ceilometer.storage import impl_hbase as hbase
|
from ceilometer.storage import impl_hbase as hbase
|
||||||
@ -50,8 +50,8 @@ class ConnectionTest(tests_db.TestBase,
|
|||||||
def get_connection_pool(conf):
|
def get_connection_pool(conf):
|
||||||
return TestConn(conf['host'], conf['port'])
|
return TestConn(conf['host'], conf['port'])
|
||||||
|
|
||||||
with patch.object(hbase.Connection, '_get_connection_pool',
|
with mock.patch.object(hbase.Connection, '_get_connection_pool',
|
||||||
side_effect=get_connection_pool):
|
side_effect=get_connection_pool):
|
||||||
conn = hbase.Connection('hbase://test_hbase:9090')
|
conn = hbase.Connection('hbase://test_hbase:9090')
|
||||||
self.assertIsInstance(conn.conn_pool, TestConn)
|
self.assertIsInstance(conn.conn_pool, TestConn)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import repr
|
import repr
|
||||||
|
|
||||||
from mock import patch
|
import mock
|
||||||
|
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer.storage import impl_sqlalchemy
|
from ceilometer.storage import impl_sqlalchemy
|
||||||
@ -154,7 +154,7 @@ class EventTest(tests_db.TestBase):
|
|||||||
m = [models.Event("1", "Foo", now, []),
|
m = [models.Event("1", "Foo", now, []),
|
||||||
models.Event("2", "Zoo", now, [])]
|
models.Event("2", "Zoo", now, [])]
|
||||||
|
|
||||||
with patch.object(self.conn, "_record_event") as mock_save:
|
with mock.patch.object(self.conn, "_record_event") as mock_save:
|
||||||
mock_save.side_effect = MyException("Boom")
|
mock_save.side_effect = MyException("Boom")
|
||||||
problem_events = self.conn.record_events(m)
|
problem_events = self.conn.record_events(m)
|
||||||
self.assertEqual(2, len(problem_events))
|
self.assertEqual(2, len(problem_events))
|
||||||
@ -177,7 +177,7 @@ class RelationshipTest(scenarios.DBTestBase):
|
|||||||
# Note: Do not derive from SQLAlchemyEngineTestBase, since we
|
# Note: Do not derive from SQLAlchemyEngineTestBase, since we
|
||||||
# don't want to automatically inherit all the Meter setup.
|
# don't want to automatically inherit all the Meter setup.
|
||||||
|
|
||||||
@patch.object(timeutils, 'utcnow')
|
@mock.patch.object(timeutils, 'utcnow')
|
||||||
def test_clear_metering_data_meta_tables(self, mock_utcnow):
|
def test_clear_metering_data_meta_tables(self, mock_utcnow):
|
||||||
mock_utcnow.return_value = datetime.datetime(2012, 7, 2, 10, 45)
|
mock_utcnow.return_value = datetime.datetime(2012, 7, 2, 10, 45)
|
||||||
self.conn.clear_expired_metering_data(3 * 60)
|
self.conn.clear_expired_metering_data(3 * 60)
|
||||||
|
@ -16,8 +16,7 @@ import contextlib
|
|||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from mock import call
|
import mock
|
||||||
from mock import patch
|
|
||||||
import pymongo
|
import pymongo
|
||||||
|
|
||||||
from ceilometer.openstack.common.gettextutils import _
|
from ceilometer.openstack.common.gettextutils import _
|
||||||
@ -72,8 +71,8 @@ class CompatibilityTest(test_storage_scenarios.DBTestBase,
|
|||||||
self.db.meter.insert(record)
|
self.db.meter.insert(record)
|
||||||
|
|
||||||
# Stubout with the old version DB schema, the one w/o 'counter_unit'
|
# Stubout with the old version DB schema, the one w/o 'counter_unit'
|
||||||
with patch.object(self.conn, 'record_metering_data',
|
with mock.patch.object(self.conn, 'record_metering_data',
|
||||||
side_effect=old_record_metering_data):
|
side_effect=old_record_metering_data):
|
||||||
self.counters = []
|
self.counters = []
|
||||||
c = sample.Sample(
|
c = sample.Sample(
|
||||||
'volume.size',
|
'volume.size',
|
||||||
@ -187,15 +186,16 @@ class CompatibilityTest(test_storage_scenarios.DBTestBase,
|
|||||||
|
|
||||||
pool = pymongo_utils.ConnectionPool()
|
pool = pymongo_utils.ConnectionPool()
|
||||||
with contextlib.nested(
|
with contextlib.nested(
|
||||||
patch('pymongo.MongoClient',
|
mock.patch(
|
||||||
side_effect=pymongo.errors.ConnectionFailure('foo')),
|
'pymongo.MongoClient',
|
||||||
patch.object(pymongo_utils.LOG, 'error'),
|
side_effect=pymongo.errors.ConnectionFailure('foo')),
|
||||||
patch.object(pymongo_utils.LOG, 'warn'),
|
mock.patch.object(pymongo_utils.LOG, 'error'),
|
||||||
patch.object(pymongo_utils.time, 'sleep')
|
mock.patch.object(pymongo_utils.LOG, 'warn'),
|
||||||
|
mock.patch.object(pymongo_utils.time, 'sleep')
|
||||||
) as (MockMongo, MockLOGerror, MockLOGwarn, Mocksleep):
|
) as (MockMongo, MockLOGerror, MockLOGwarn, Mocksleep):
|
||||||
self.assertRaises(pymongo.errors.ConnectionFailure,
|
self.assertRaises(pymongo.errors.ConnectionFailure,
|
||||||
pool.connect, self.CONF.database.connection)
|
pool.connect, self.CONF.database.connection)
|
||||||
Mocksleep.assert_has_calls([call(retry_interval)
|
Mocksleep.assert_has_calls([mock.call(retry_interval)
|
||||||
for i in range(max_retries)])
|
for i in range(max_retries)])
|
||||||
MockLOGwarn.assert_any_call(
|
MockLOGwarn.assert_any_call(
|
||||||
_('Unable to connect to the database server: %(errmsg)s.'
|
_('Unable to connect to the database server: %(errmsg)s.'
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from mock import patch
|
import mock
|
||||||
|
|
||||||
from ceilometer import neutron_client
|
from ceilometer import neutron_client
|
||||||
from ceilometer.openstack.common import test
|
from ceilometer.openstack.common import test
|
||||||
@ -42,8 +42,8 @@ class TestNeutronClient(test.BaseTestCase):
|
|||||||
]}
|
]}
|
||||||
|
|
||||||
def test_port_get_all(self):
|
def test_port_get_all(self):
|
||||||
with patch.object(self.nc.client, 'list_ports',
|
with mock.patch.object(self.nc.client, 'list_ports',
|
||||||
side_effect=self.fake_ports_list):
|
side_effect=self.fake_ports_list):
|
||||||
ports = self.nc.port_get_all()
|
ports = self.nc.port_get_all()
|
||||||
|
|
||||||
self.assertEqual(1, len(ports))
|
self.assertEqual(1, len(ports))
|
||||||
@ -67,8 +67,8 @@ class TestNeutronClient(test.BaseTestCase):
|
|||||||
]}
|
]}
|
||||||
|
|
||||||
def test_network_get_all(self):
|
def test_network_get_all(self):
|
||||||
with patch.object(self.nc.client, 'list_networks',
|
with mock.patch.object(self.nc.client, 'list_networks',
|
||||||
side_effect=self.fake_networks_list):
|
side_effect=self.fake_networks_list):
|
||||||
networks = self.nc.network_get_all()
|
networks = self.nc.network_get_all()
|
||||||
|
|
||||||
self.assertEqual(1, len(networks))
|
self.assertEqual(1, len(networks))
|
||||||
@ -94,8 +94,8 @@ class TestNeutronClient(test.BaseTestCase):
|
|||||||
]}
|
]}
|
||||||
|
|
||||||
def test_pool_list(self):
|
def test_pool_list(self):
|
||||||
with patch.object(self.nc.client, 'list_pools',
|
with mock.patch.object(self.nc.client, 'list_pools',
|
||||||
side_effect=self.fake_pool_list):
|
side_effect=self.fake_pool_list):
|
||||||
pools = self.nc.pool_get_all()
|
pools = self.nc.pool_get_all()
|
||||||
|
|
||||||
self.assertEqual(1, len(pools))
|
self.assertEqual(1, len(pools))
|
||||||
@ -122,8 +122,8 @@ class TestNeutronClient(test.BaseTestCase):
|
|||||||
]}
|
]}
|
||||||
|
|
||||||
def test_vip_list(self):
|
def test_vip_list(self):
|
||||||
with patch.object(self.nc.client, 'list_vips',
|
with mock.patch.object(self.nc.client, 'list_vips',
|
||||||
side_effect=self.fake_vip_list):
|
side_effect=self.fake_vip_list):
|
||||||
vips = self.nc.vip_get_all()
|
vips = self.nc.vip_get_all()
|
||||||
|
|
||||||
self.assertEqual(1, len(vips))
|
self.assertEqual(1, len(vips))
|
||||||
@ -144,8 +144,8 @@ class TestNeutronClient(test.BaseTestCase):
|
|||||||
]}
|
]}
|
||||||
|
|
||||||
def test_member_list(self):
|
def test_member_list(self):
|
||||||
with patch.object(self.nc.client, 'list_members',
|
with mock.patch.object(self.nc.client, 'list_members',
|
||||||
side_effect=self.fake_member_list):
|
side_effect=self.fake_member_list):
|
||||||
members = self.nc.member_get_all()
|
members = self.nc.member_get_all()
|
||||||
|
|
||||||
self.assertEqual(1, len(members))
|
self.assertEqual(1, len(members))
|
||||||
@ -166,8 +166,8 @@ class TestNeutronClient(test.BaseTestCase):
|
|||||||
}]}
|
}]}
|
||||||
|
|
||||||
def test_monitor_list(self):
|
def test_monitor_list(self):
|
||||||
with patch.object(self.nc.client, 'list_health_monitors',
|
with mock.patch.object(self.nc.client, 'list_health_monitors',
|
||||||
side_effect=self.fake_monitors_list):
|
side_effect=self.fake_monitors_list):
|
||||||
monitors = self.nc.health_monitor_get_all()
|
monitors = self.nc.health_monitor_get_all()
|
||||||
|
|
||||||
self.assertEqual(1, len(monitors))
|
self.assertEqual(1, len(monitors))
|
||||||
@ -184,8 +184,8 @@ class TestNeutronClient(test.BaseTestCase):
|
|||||||
}]}
|
}]}
|
||||||
|
|
||||||
def test_pool_stats(self):
|
def test_pool_stats(self):
|
||||||
with patch.object(self.nc.client, 'retrieve_pool_stats',
|
with mock.patch.object(self.nc.client, 'retrieve_pool_stats',
|
||||||
side_effect=self.fake_pool_stats):
|
side_effect=self.fake_pool_stats):
|
||||||
stats = self.nc.pool_stats('fake_pool')['stats']
|
stats = self.nc.pool_stats('fake_pool')['stats']
|
||||||
|
|
||||||
self.assertEqual(1, len(stats))
|
self.assertEqual(1, len(stats))
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from mock import patch
|
|
||||||
import novaclient
|
import novaclient
|
||||||
|
|
||||||
from ceilometer import nova_client
|
from ceilometer import nova_client
|
||||||
@ -85,8 +84,8 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
return [a, b]
|
return [a, b]
|
||||||
|
|
||||||
def test_instance_get_all_by_host(self):
|
def test_instance_get_all_by_host(self):
|
||||||
with patch.object(self.nv.nova_client.servers, 'list',
|
with mock.patch.object(self.nv.nova_client.servers, 'list',
|
||||||
side_effect=self.fake_servers_list):
|
side_effect=self.fake_servers_list):
|
||||||
instances = self.nv.instance_get_all_by_host('foobar')
|
instances = self.nv.instance_get_all_by_host('foobar')
|
||||||
|
|
||||||
self.assertEqual(2, len(instances))
|
self.assertEqual(2, len(instances))
|
||||||
@ -104,8 +103,9 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
return [a]
|
return [a]
|
||||||
|
|
||||||
def test_instance_get_all_by_host_unknown_flavor(self):
|
def test_instance_get_all_by_host_unknown_flavor(self):
|
||||||
with patch.object(self.nv.nova_client.servers, 'list',
|
with mock.patch.object(
|
||||||
side_effect=self.fake_servers_list_unknown_flavor):
|
self.nv.nova_client.servers, 'list',
|
||||||
|
side_effect=self.fake_servers_list_unknown_flavor):
|
||||||
instances = self.nv.instance_get_all_by_host('foobar')
|
instances = self.nv.instance_get_all_by_host('foobar')
|
||||||
|
|
||||||
self.assertEqual(1, len(instances))
|
self.assertEqual(1, len(instances))
|
||||||
@ -136,8 +136,9 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
return [a]
|
return [a]
|
||||||
|
|
||||||
def test_instance_get_all_by_host_unknown_image(self):
|
def test_instance_get_all_by_host_unknown_image(self):
|
||||||
with patch.object(self.nv.nova_client.servers, 'list',
|
with mock.patch.object(
|
||||||
side_effect=self.fake_servers_list_unknown_image):
|
self.nv.nova_client.servers, 'list',
|
||||||
|
side_effect=self.fake_servers_list_unknown_image):
|
||||||
instances = self.nv.instance_get_all_by_host('foobar')
|
instances = self.nv.instance_get_all_by_host('foobar')
|
||||||
|
|
||||||
self.assertEqual(1, len(instances))
|
self.assertEqual(1, len(instances))
|
||||||
|
3
tox.ini
3
tox.ini
@ -37,8 +37,7 @@ commands = python setup.py build_sphinx
|
|||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# TODO fix H302
|
ignore = None
|
||||||
ignore = H302
|
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude=.venv,.git,.tox,dist,doc,./ceilometer/openstack/common,*lib/python*,*egg,tools,nova_tests,build
|
exclude=.venv,.git,.tox,dist,doc,./ceilometer/openstack/common,*lib/python*,*egg,tools,nova_tests,build
|
||||||
show-source = True
|
show-source = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user