diff --git a/ceilometer/sample.py b/ceilometer/sample.py index a7114989f5..6654ca784a 100644 --- a/ceilometer/sample.py +++ b/ceilometer/sample.py @@ -144,6 +144,14 @@ class Sample(object): def get_iso_timestamp(self): return timeutils.parse_isotime(self.timestamp) + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other): + return not self.__eq__(other) + def setup(conf): # NOTE(sileht): Instead of passing the cfg.CONF everywhere in ceilometer diff --git a/ceilometer/tests/unit/polling/agentbase.py b/ceilometer/tests/unit/polling/agentbase.py index 7789984c47..0f054a6c40 100644 --- a/ceilometer/tests/unit/polling/agentbase.py +++ b/ceilometer/tests/unit/polling/agentbase.py @@ -31,24 +31,7 @@ from ceilometer import service from ceilometer.tests import base -class TestSample(sample.Sample): - def __init__(self, name, type, unit, volume, user_id, project_id, - resource_id, timestamp=None, resource_metadata=None, - source=None): - super(TestSample, self).__init__(name, type, unit, volume, user_id, - project_id, resource_id, timestamp, - resource_metadata, source) - - def __eq__(self, other): - if isinstance(other, self.__class__): - return self.__dict__ == other.__dict__ - return False - - def __ne__(self, other): - return not self.__eq__(other) - - -default_test_data = TestSample( +default_test_data = sample.Sample( name='test', type=sample.TYPE_CUMULATIVE, unit='', @@ -134,7 +117,7 @@ class BaseAgentManagerTestCase(base.BaseTestCase): class PollsterAnother(TestPollster): samples = [] resources = [] - test_data = TestSample( + test_data = sample.Sample( name='testanother', type=default_test_data.type, unit=default_test_data.unit, @@ -148,7 +131,7 @@ class BaseAgentManagerTestCase(base.BaseTestCase): class PollsterException(TestPollsterException): samples = [] resources = [] - test_data = TestSample( + test_data = sample.Sample( name='testexception', type=default_test_data.type, unit=default_test_data.unit, @@ -162,7 +145,7 @@ class BaseAgentManagerTestCase(base.BaseTestCase): class PollsterExceptionAnother(TestPollsterException): samples = [] resources = [] - test_data = TestSample( + test_data = sample.Sample( name='testexceptionanother', type=default_test_data.type, unit=default_test_data.unit, @@ -258,7 +241,6 @@ class BaseAgentManagerTestCase(base.BaseTestCase): self.mgr.hashrings = mock.MagicMock() self.mgr.hashrings.__getitem__.return_value = self.hashring - self.mgr.tg = mock.MagicMock() self.polling_cfg = { 'sources': [{ 'name': 'test_polling', diff --git a/ceilometer/tests/unit/polling/test_manager.py b/ceilometer/tests/unit/polling/test_manager.py index 477a5caeeb..ce1fa306e1 100644 --- a/ceilometer/tests/unit/polling/test_manager.py +++ b/ceilometer/tests/unit/polling/test_manager.py @@ -23,6 +23,7 @@ from ceilometer.compute import discovery as nova_discover from ceilometer.hardware import discovery from ceilometer.polling import manager from ceilometer.polling import plugin_base +from ceilometer import sample from ceilometer import service from ceilometer.tests.unit.polling import agentbase @@ -166,7 +167,7 @@ class TestRunTasks(agentbase.BaseAgentManagerTestCase): class PollsterKeystone(TestPollsterKeystone): samples = [] resources = [] - test_data = agentbase.TestSample( + test_data = sample.Sample( name='testkeystone', type=agentbase.default_test_data.type, unit=agentbase.default_test_data.unit, @@ -180,7 +181,7 @@ class TestRunTasks(agentbase.BaseAgentManagerTestCase): class PollsterPollingException(TestPollsterPollingException): samples = [] resources = [] - test_data = agentbase.TestSample( + test_data = sample.Sample( name='testpollingexception', type=agentbase.default_test_data.type, unit=agentbase.default_test_data.unit,