Remove set_state function and its references
Change all functions to use ``set_last_processed_timestamp`` instead of ``set_state``, update the tests and remove the ``set_state`` function. Change-Id: I3ff5a8932165a8a1780ca7e3084a9819bba281ec
This commit is contained in:
parent
d1c962a96f
commit
75d672b2a0
@ -446,7 +446,7 @@ class Worker(BaseWorker):
|
|||||||
return frame
|
return frame
|
||||||
|
|
||||||
def update_scope_processing_state_db(self, timestamp):
|
def update_scope_processing_state_db(self, timestamp):
|
||||||
self._state.set_state(self._tenant_id, timestamp)
|
self._state.set_last_processed_timestamp(self._tenant_id, timestamp)
|
||||||
|
|
||||||
|
|
||||||
class ReprocessingWorker(Worker):
|
class ReprocessingWorker(Worker):
|
||||||
|
@ -148,19 +148,6 @@ class StateManager(object):
|
|||||||
session.commit()
|
session.commit()
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def set_state(self, identifier, state,
|
|
||||||
fetcher=None, collector=None, scope_key=None):
|
|
||||||
"""Set the last processed timestamp of a scope.
|
|
||||||
|
|
||||||
This method is deprecated, consider using
|
|
||||||
"set_last_processed_timestamp".
|
|
||||||
"""
|
|
||||||
LOG.warning("The method 'set_state' is deprecated. "
|
|
||||||
"Consider using the new method "
|
|
||||||
"'set_last_processed_timestamp'.")
|
|
||||||
self.set_last_processed_timestamp(
|
|
||||||
identifier, state, fetcher, collector, scope_key)
|
|
||||||
|
|
||||||
def set_last_processed_timestamp(
|
def set_last_processed_timestamp(
|
||||||
self, identifier, last_processed_timestamp, fetcher=None,
|
self, identifier, last_processed_timestamp, fetcher=None,
|
||||||
collector=None, scope_key=None):
|
collector=None, scope_key=None):
|
||||||
|
@ -403,7 +403,7 @@ class ScopeStateFixture(fixture.GabbiFixture):
|
|||||||
('hhhh', datetime.datetime(2019, 6, 6), 'fet2', 'col2', 'key2'),
|
('hhhh', datetime.datetime(2019, 6, 6), 'fet2', 'col2', 'key2'),
|
||||||
]
|
]
|
||||||
for d in data:
|
for d in data:
|
||||||
self.sm.set_state(
|
self.sm.set_last_processed_timestamp(
|
||||||
d[0], d[1], fetcher=d[2], collector=d[3], scope_key=d[4])
|
d[0], d[1], fetcher=d[2], collector=d[3], scope_key=d[4])
|
||||||
|
|
||||||
def stop_fixture(self):
|
def stop_fixture(self):
|
||||||
|
@ -237,7 +237,8 @@ class WorkerTest(tests.TestCase):
|
|||||||
super(WorkerTest, self).setUp()
|
super(WorkerTest, self).setUp()
|
||||||
|
|
||||||
patcher_state_manager_set_state = mock.patch(
|
patcher_state_manager_set_state = mock.patch(
|
||||||
"cloudkitty.storage_state.StateManager.set_state")
|
"cloudkitty.storage_state."
|
||||||
|
"StateManager.set_last_processed_timestamp")
|
||||||
self.addCleanup(patcher_state_manager_set_state.stop)
|
self.addCleanup(patcher_state_manager_set_state.stop)
|
||||||
self.state_manager_set_state_mock = \
|
self.state_manager_set_state_mock = \
|
||||||
patcher_state_manager_set_state.start()
|
patcher_state_manager_set_state.start()
|
||||||
|
@ -84,7 +84,10 @@ class StateManagerTest(tests.TestCase):
|
|||||||
def test_set_state_does_update_columns(self):
|
def test_set_state_does_update_columns(self):
|
||||||
with mock.patch('cloudkitty.db.session_for_write'):
|
with mock.patch('cloudkitty.db.session_for_write'):
|
||||||
self._test_x_state_does_update_columns(
|
self._test_x_state_does_update_columns(
|
||||||
lambda x: self._state.set_state(x, datetime(2042, 1, 1)))
|
lambda x: self._state.set_last_processed_timestamp(
|
||||||
|
x, datetime(2042, 1, 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _test_x_state_no_column_update(self, func):
|
def _test_x_state_no_column_update(self, func):
|
||||||
r_mock = self._get_r_mock(
|
r_mock = self._get_r_mock(
|
||||||
@ -106,7 +109,10 @@ class StateManagerTest(tests.TestCase):
|
|||||||
def test_set_state_no_column_update(self):
|
def test_set_state_no_column_update(self):
|
||||||
with mock.patch('cloudkitty.db.session_for_write'):
|
with mock.patch('cloudkitty.db.session_for_write'):
|
||||||
self._test_x_state_no_column_update(
|
self._test_x_state_no_column_update(
|
||||||
lambda x: self._state.set_state(x, datetime(2042, 1, 1)))
|
lambda x: self._state.set_last_processed_timestamp(
|
||||||
|
x, datetime(2042, 1, 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def test_set_state_does_not_duplicate_entries(self):
|
def test_set_state_does_not_duplicate_entries(self):
|
||||||
state = datetime(2042, 1, 1)
|
state = datetime(2042, 1, 1)
|
||||||
@ -118,7 +124,7 @@ class StateManagerTest(tests.TestCase):
|
|||||||
'cloudkitty.db.session_for_write') as sm:
|
'cloudkitty.db.session_for_write') as sm:
|
||||||
sm.return_value.__enter__.return_value = session_mock = \
|
sm.return_value.__enter__.return_value = session_mock = \
|
||||||
mock.MagicMock()
|
mock.MagicMock()
|
||||||
self._state.set_state('fake_identifier', state)
|
self._state.set_last_processed_timestamp('fake_identifier', state)
|
||||||
session_mock.commit.assert_not_called()
|
session_mock.commit.assert_not_called()
|
||||||
session_mock.add.assert_not_called()
|
session_mock.add.assert_not_called()
|
||||||
|
|
||||||
@ -133,7 +139,9 @@ class StateManagerTest(tests.TestCase):
|
|||||||
sm.return_value.__enter__.return_value = session_mock = \
|
sm.return_value.__enter__.return_value = session_mock = \
|
||||||
mock.MagicMock()
|
mock.MagicMock()
|
||||||
self.assertNotEqual(r_mock.state, new_state)
|
self.assertNotEqual(r_mock.state, new_state)
|
||||||
self._state.set_state('fake_identifier', new_state)
|
self._state.set_last_processed_timestamp(
|
||||||
|
'fake_identifier', new_state
|
||||||
|
)
|
||||||
self.assertEqual(r_mock.last_processed_timestamp, new_state)
|
self.assertEqual(r_mock.last_processed_timestamp, new_state)
|
||||||
session_mock.commit.assert_called_once()
|
session_mock.commit.assert_called_once()
|
||||||
session_mock.add.assert_not_called()
|
session_mock.add.assert_not_called()
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
upgrade:
|
||||||
|
- |
|
||||||
|
The ``storage_state.set_state`` method has been removed in favor of the
|
||||||
|
``storage_state.set_last_processed_timestamp`` method.
|
Loading…
Reference in New Issue
Block a user