Make methods static where possible (except openstack.common)

Change-Id: I68b3eef29359e39755f3f62debc06918635d73b2
This commit is contained in:
Dina Belova 2014-12-10 15:53:29 +03:00
parent d68f8afcc9
commit b2ff3259a8
23 changed files with 68 additions and 34 deletions

View File

@ -1540,7 +1540,8 @@ class Resource(_Base):
class ResourcesController(rest.RestController):
"""Works on resources."""
def _resource_links(self, resource_id, meter_links=1):
@staticmethod
def _resource_links(resource_id, meter_links=1):
links = [_make_link('self', pecan.request.host_url, 'resources',
resource_id)]
if meter_links:
@ -2175,7 +2176,8 @@ class AlarmsController(rest.RestController):
def _lookup(self, alarm_id, *remainder):
return AlarmController(alarm_id), remainder
def _record_creation(self, conn, data, alarm_id, now):
@staticmethod
def _record_creation(conn, data, alarm_id, now):
if not cfg.CONF.alarm.record_history:
return
type = alarm_models.AlarmChange.CREATION

View File

@ -30,7 +30,8 @@ class ConfigHook(hooks.PecanHook):
That allows controllers to get it.
"""
def before(self, state):
@staticmethod
def before(state):
state.request.cfg = cfg.CONF

View File

@ -143,7 +143,8 @@ class UtilsV2(object):
'host_resource': host_resource
}
def _sum_metric_values(self, metrics):
@staticmethod
def _sum_metric_values(metrics):
tot_metric_val = 0
for metric in metrics:
tot_metric_val += long(metric.MetricValue)
@ -160,7 +161,8 @@ class UtilsV2(object):
metric_values.append(0)
return metric_values
def _get_metric_value_instances(self, elements, result_class):
@staticmethod
def _get_metric_value_instances(elements, result_class):
instances = []
for el in elements:
associators = el.associators(wmi_result_class=result_class)
@ -190,7 +192,8 @@ class UtilsV2(object):
element.associators(
wmi_association_class=self._METRICS_ME), metric_def)
def _filter_metrics(self, all_metrics, metric_def):
@staticmethod
def _filter_metrics(all_metrics, metric_def):
return [v for v in all_metrics if
v.MetricDefinitionId == metric_def.Id]

View File

@ -408,7 +408,8 @@ class SNMPInspector(base.Inspector):
metadata.update(ip=ip_addr)
return value
def _get_auth_strategy(self, host):
@staticmethod
def _get_auth_strategy(host):
if host.password:
auth_strategy = cmdgen.UsmUserData(host.username,
authKey=host.password)

View File

@ -95,7 +95,8 @@ class SensorNotification(plugin_base.NotificationBase):
except KeyError:
return []
def _package_payload(self, message, payload):
@staticmethod
def _package_payload(message, payload):
# NOTE(chdent): How much of the payload should we keep?
payload['node'] = message['payload']['node_uuid']
info = {'publisher_id': message['publisher_id'],

View File

@ -41,7 +41,8 @@ class SensorPollster(plugin_base.PollsterBase):
def default_discovery(self):
return None
def _get_sensor_types(self, data, sensor_type):
@staticmethod
def _get_sensor_types(data, sensor_type):
try:
return (sensor_type_data for _, sensor_type_data
in data[sensor_type].items())

View File

@ -35,7 +35,8 @@ cfg.CONF.import_group('service_types', 'ceilometer.nova_client')
class FloatingIPPollster(plugin_base.PollsterBase):
def _get_floating_ips(self, ksclient, endpoint):
@staticmethod
def _get_floating_ips(ksclient, endpoint):
nv = nova_client.Client(
auth_token=ksclient.auth_token, bypass_url=endpoint)
return nv.floating_ip_get_all()

View File

@ -35,7 +35,8 @@ class BaseServicesPollster(plugin_base.PollsterBase):
FIELDS = []
nc = neutron_client.Client()
def _iter_cache(self, cache, meter_name, method):
@staticmethod
def _iter_cache(cache, meter_name, method):
if meter_name not in cache:
cache[meter_name] = list(method())
return iter(cache[meter_name])

View File

@ -263,7 +263,8 @@ class MConnection(object):
def __exit__(self, exc_type, exc_val, exc_tb):
pass
def open(self):
@staticmethod
def open():
LOG.debug(_("Opening in-memory HBase connection"))
def create_table(self, n, families=None):

View File

@ -507,7 +507,8 @@ class Connection(base.Connection):
source=row.source_id,
user_id=row.user_id)
def _retrieve_samples(self, query):
@staticmethod
def _retrieve_samples(query):
samples = query.all()
for s in samples:

View File

@ -41,12 +41,14 @@ class JSONEncodedDict(TypeDecorator):
impl = String
def process_bind_param(self, value, dialect):
@staticmethod
def process_bind_param(value, dialect):
if value is not None:
value = json.dumps(value)
return value
def process_result_value(self, value, dialect):
@staticmethod
def process_result_value(value, dialect):
if value is not None:
value = json.loads(value)
return value
@ -64,14 +66,16 @@ class PreciseTimestamp(TypeDecorator):
asdecimal=True))
return self.impl
def process_bind_param(self, value, dialect):
@staticmethod
def process_bind_param(value, dialect):
if value is None:
return value
elif dialect.name == 'mysql':
return utils.dt_to_decimal(value)
return value
def process_result_value(self, value, dialect):
@staticmethod
def process_result_value(value, dialect):
if value is None:
return value
elif dialect.name == 'mysql':

View File

@ -250,7 +250,8 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
self.useFixture(mockpatch.PatchObject(
publisher, 'get_publisher', side_effect=self.get_publisher))
def get_publisher(self, url, namespace=''):
@staticmethod
def get_publisher(url, namespace=''):
fake_drivers = {'test://': test_publisher.TestPublisher,
'new://': test_publisher.TestPublisher,
'rpc://': test_publisher.TestPublisher}

View File

@ -96,7 +96,8 @@ class NotificationBaseTestCase(base.BaseTestCase):
'compute.instance.start', ['compute.*.*.foobar', 'compute.*']))
class FakePlugin(plugin_base.NotificationBase):
def get_exchange_topics(self, conf):
@staticmethod
def get_exchange_topics(conf):
return [plugin_base.ExchangeTopics(exchange="exchange1",
topics=["t1", "t2"]),
plugin_base.ExchangeTopics(exchange="exchange2",

View File

@ -47,10 +47,12 @@ class TestLibvirtInspection(base.BaseTestCase):
def test_inspect_instances(self):
class FakeDomain(object):
def name(self):
@staticmethod
def name():
return 'fake_name'
def UUIDString(self):
@staticmethod
def UUIDString():
return 'uuid'
fake_domain = FakeDomain()
@ -307,6 +309,7 @@ class TestLibvirtInspectionWithError(base.BaseTestCase):
libvirt_inspector.libvirt = mock.Mock()
libvirt_inspector.libvirt.libvirtError = self.fakeLibvirtError
@staticmethod
def _dummy_get_connection(*args, **kwargs):
raise Exception('dummy')

View File

@ -28,7 +28,8 @@ from ceilometer.tests import base
class ConverterBase(base.BaseTestCase):
def _create_test_notification(self, event_type, message_id, **kw):
@staticmethod
def _create_test_notification(event_type, message_id, **kw):
return dict(event_type=event_type,
message_id=message_id,
priority="INFO",

View File

@ -95,8 +95,8 @@ class TestSNMPInspector(test_base.BaseTestCase):
'test_exact',
{})
def _fake_post_op(self, host, cache, meter_def,
value, metadata, extra, suffix):
@staticmethod
def _fake_post_op(host, cache, meter_def, value, metadata, extra, suffix):
metadata.update(post_op_meta=4)
extra.update(project_id=2)
return value

View File

@ -52,6 +52,7 @@ class FakeInspector(inspector_base.Inspector):
class TestPollsterBase(test_base.BaseTestCase):
@staticmethod
def faux_get_inspector(url, namespace=None):
return FakeInspector()

View File

@ -127,7 +127,8 @@ class TestManager(manager.AgentManager):
class TestImagePollsterPageSize(base.BaseTestCase):
def fake_get_glance_client(self, ksclient, endpoint):
@staticmethod
def fake_get_glance_client(ksclient, endpoint):
glanceclient = FakeGlanceClient()
glanceclient.images.list = mock.MagicMock(return_value=IMAGE_LIST)
return glanceclient
@ -165,7 +166,8 @@ class TestImagePollsterPageSize(base.BaseTestCase):
class TestImagePollster(base.BaseTestCase):
def fake_get_glance_client(self, ksclient, endpoint):
@staticmethod
def fake_get_glance_client(ksclient, endpoint):
glanceclient = _BaseObject()
setattr(glanceclient, "images", _BaseObject())
setattr(glanceclient.images,

View File

@ -19,7 +19,8 @@ from ceilometer.network.statistics import driver
class TestDriver(base.BaseTestCase):
def test_driver_ok(self):
@staticmethod
def test_driver_ok():
class OkDriver(driver.Driver):

View File

@ -25,7 +25,8 @@ from ceilometer import sample
class TestBase(base.BaseTestCase):
def test_subclass_ok(self):
@staticmethod
def test_subclass_ok():
class OkSubclass(statistics._Base):
@ -76,7 +77,8 @@ class TestBaseGetSamples(base.BaseTestCase):
statistics._Base.drivers = {}
super(TestBaseGetSamples, self).tearDown()
def _setup_ext_mgr(self, **drivers):
@staticmethod
def _setup_ext_mgr(**drivers):
statistics._Base.drivers = drivers
def _make_fake_driver(self, *return_values):
@ -93,7 +95,8 @@ class TestBaseGetSamples(base.BaseTestCase):
yield retval
return FakeDriver
def _make_timestamps(self, count):
@staticmethod
def _make_timestamps(count):
now = timeutils.utcnow()
return [timeutils.isotime(now + datetime.timedelta(seconds=i))
for i in range(count)]

View File

@ -40,7 +40,8 @@ from ceilometer.transformer import conversions
@six.add_metaclass(abc.ABCMeta)
class BasePipelineTestCase(base.BaseTestCase):
def fake_tem_init(self):
@staticmethod
def fake_tem_init():
"""Fake a transformerManager for pipeline.
The faked entry point setting is below:
@ -115,7 +116,8 @@ class BasePipelineTestCase(base.BaseTestCase):
self.__class__.samples.append(counter)
class TransformerClassException(object):
def handle_sample(self, ctxt, counter):
@staticmethod
def handle_sample(ctxt, counter):
raise Exception()
def setUp(self):

View File

@ -97,7 +97,8 @@ class TestUDPPublisher(base.BaseTestCase):
),
]
def _make_fake_socket(self, published):
@staticmethod
def _make_fake_socket(published):
def _fake_socket_socket(family, type):
def record_data(msg, dest):
published.append((msg, dest))

View File

@ -22,7 +22,8 @@ from ceilometer.storage import impl_log
class ConnectionTest(base.BaseTestCase):
def test_get_connection(self):
@staticmethod
def test_get_connection():
conn = impl_log.Connection(None)
conn.record_metering_data({'counter_name': 'test',
'resource_id': __name__,