From 75d672b2a03f7cf98af8c1f3e29802e8bad72494 Mon Sep 17 00:00:00 2001 From: Dawud Date: Thu, 29 Aug 2024 13:45:18 +0100 Subject: [PATCH] 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 --- cloudkitty/orchestrator.py | 2 +- cloudkitty/storage_state/__init__.py | 13 ------------- cloudkitty/tests/gabbi/fixtures.py | 2 +- cloudkitty/tests/test_orchestrator.py | 3 ++- cloudkitty/tests/test_storage_state.py | 16 ++++++++++++---- .../deprecate-set-state-3eea30afd43647ab.yaml | 5 +++++ 6 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 releasenotes/notes/deprecate-set-state-3eea30afd43647ab.yaml diff --git a/cloudkitty/orchestrator.py b/cloudkitty/orchestrator.py index 33ef0017..ddf2238f 100644 --- a/cloudkitty/orchestrator.py +++ b/cloudkitty/orchestrator.py @@ -446,7 +446,7 @@ class Worker(BaseWorker): return frame 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): diff --git a/cloudkitty/storage_state/__init__.py b/cloudkitty/storage_state/__init__.py index c2af444c..ed897ca1 100644 --- a/cloudkitty/storage_state/__init__.py +++ b/cloudkitty/storage_state/__init__.py @@ -148,19 +148,6 @@ class StateManager(object): session.commit() 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( self, identifier, last_processed_timestamp, fetcher=None, collector=None, scope_key=None): diff --git a/cloudkitty/tests/gabbi/fixtures.py b/cloudkitty/tests/gabbi/fixtures.py index 8c94f3a0..f8d66309 100644 --- a/cloudkitty/tests/gabbi/fixtures.py +++ b/cloudkitty/tests/gabbi/fixtures.py @@ -403,7 +403,7 @@ class ScopeStateFixture(fixture.GabbiFixture): ('hhhh', datetime.datetime(2019, 6, 6), 'fet2', 'col2', 'key2'), ] 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]) def stop_fixture(self): diff --git a/cloudkitty/tests/test_orchestrator.py b/cloudkitty/tests/test_orchestrator.py index bf6581d4..468f1336 100644 --- a/cloudkitty/tests/test_orchestrator.py +++ b/cloudkitty/tests/test_orchestrator.py @@ -237,7 +237,8 @@ class WorkerTest(tests.TestCase): super(WorkerTest, self).setUp() 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.state_manager_set_state_mock = \ patcher_state_manager_set_state.start() diff --git a/cloudkitty/tests/test_storage_state.py b/cloudkitty/tests/test_storage_state.py index 6a7d21fb..212fa168 100644 --- a/cloudkitty/tests/test_storage_state.py +++ b/cloudkitty/tests/test_storage_state.py @@ -84,7 +84,10 @@ class StateManagerTest(tests.TestCase): def test_set_state_does_update_columns(self): with mock.patch('cloudkitty.db.session_for_write'): 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): r_mock = self._get_r_mock( @@ -106,7 +109,10 @@ class StateManagerTest(tests.TestCase): def test_set_state_no_column_update(self): with mock.patch('cloudkitty.db.session_for_write'): 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): state = datetime(2042, 1, 1) @@ -118,7 +124,7 @@ class StateManagerTest(tests.TestCase): 'cloudkitty.db.session_for_write') as sm: sm.return_value.__enter__.return_value = session_mock = \ 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.add.assert_not_called() @@ -133,7 +139,9 @@ class StateManagerTest(tests.TestCase): sm.return_value.__enter__.return_value = session_mock = \ mock.MagicMock() 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) session_mock.commit.assert_called_once() session_mock.add.assert_not_called() diff --git a/releasenotes/notes/deprecate-set-state-3eea30afd43647ab.yaml b/releasenotes/notes/deprecate-set-state-3eea30afd43647ab.yaml new file mode 100644 index 00000000..55f43c8a --- /dev/null +++ b/releasenotes/notes/deprecate-set-state-3eea30afd43647ab.yaml @@ -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.