From b3d8bf7e202b706c83af3f81d7044b2dfea070fb Mon Sep 17 00:00:00 2001 From: Dawud Date: Fri, 29 Dec 2023 11:16:11 +0000 Subject: [PATCH] Remove get_state function and its references Change all functions to use ``get_last_processed_timestamp`` instead of ``get_state``, update the tests and remove the ``get_state`` function. Change-Id: Iea704fc594f4b5201a1fff7d38a6c0bafb9be6f1 (cherry picked from commit e3e55d2cf6c264be69d548e4f8e5efd28101986e) --- cloudkitty/orchestrator.py | 4 ++-- cloudkitty/storage_state/__init__.py | 8 -------- cloudkitty/tests/test_orchestrator.py | 17 +++++++++++------ cloudkitty/tests/test_storage_state.py | 10 ++++++---- cloudkitty/write_orchestrator.py | 8 +++++--- .../deprecate-get-state-2932a4e6a74295ce.yaml | 5 +++++ 6 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 releasenotes/notes/deprecate-get-state-2932a4e6a74295ce.yaml diff --git a/cloudkitty/orchestrator.py b/cloudkitty/orchestrator.py index 87391411..8dcfb5b6 100644 --- a/cloudkitty/orchestrator.py +++ b/cloudkitty/orchestrator.py @@ -272,7 +272,7 @@ class APIWorker(BaseWorker): def _check_state(obj, period, tenant_id): - timestamp = obj._state.get_state(tenant_id) + timestamp = obj._state.get_last_processed_timestamp(tenant_id) return ck_utils.check_time_state(timestamp, period, CONF.collect.wait_periods) @@ -387,7 +387,7 @@ class Worker(BaseWorker): LOG.debug("Worker [%s] finished processing storage scope [%s].", self._worker_id, self._tenant_id) return False - if self._state.get_state(self._tenant_id): + if self._state.get_last_processed_timestamp(self._tenant_id): if not self._state.is_storage_scope_active(self._tenant_id): LOG.debug("Skipping processing for storage scope [%s] " "because it is marked as inactive.", diff --git a/cloudkitty/storage_state/__init__.py b/cloudkitty/storage_state/__init__.py index 6e9e25b5..12b20f5b 100644 --- a/cloudkitty/storage_state/__init__.py +++ b/cloudkitty/storage_state/__init__.py @@ -239,14 +239,6 @@ class StateManager(object): if not is_session_reused: session.close() - def get_state(self, identifier, - fetcher=None, collector=None, scope_key=None): - LOG.warning("The method 'get_state' is deprecated. " - "Consider using the new method " - "'get_last_processed_timestamp'.") - return self.get_last_processed_timestamp( - identifier, fetcher, collector, scope_key) - def get_last_processed_timestamp(self, identifier, fetcher=None, collector=None, scope_key=None): """Get the last processed timestamp of a scope. diff --git a/cloudkitty/tests/test_orchestrator.py b/cloudkitty/tests/test_orchestrator.py index 6e28024c..95a28431 100644 --- a/cloudkitty/tests/test_orchestrator.py +++ b/cloudkitty/tests/test_orchestrator.py @@ -416,7 +416,8 @@ class WorkerTest(tests.TestCase): ]) self.assertTrue(update_scope_processing_state_db_mock.called) - @mock.patch("cloudkitty.storage_state.StateManager.get_state") + @mock.patch("cloudkitty.storage_state.StateManager" + ".get_last_processed_timestamp") @mock.patch("cloudkitty.storage_state.StateManager" ".is_storage_scope_active") @mock.patch("cloudkitty.orchestrator.Worker.do_execute_scope_processing") @@ -438,7 +439,8 @@ class WorkerTest(tests.TestCase): self.assertFalse(do_execute_scope_processing_mock.called) self.assertTrue(next_timestamp_to_process_mock.called) - @mock.patch("cloudkitty.storage_state.StateManager.get_state") + @mock.patch("cloudkitty.storage_state.StateManager" + ".get_last_processed_timestamp") @mock.patch("cloudkitty.storage_state.StateManager" ".is_storage_scope_active") @mock.patch("cloudkitty.orchestrator.Worker.do_execute_scope_processing") @@ -468,7 +470,8 @@ class WorkerTest(tests.TestCase): self.assertFalse(state_manager_is_storage_scope_active_mock.called) self.assertTrue(next_timestamp_to_process_mock.called) - @mock.patch("cloudkitty.storage_state.StateManager.get_state") + @mock.patch("cloudkitty.storage_state.StateManager" + ".get_last_processed_timestamp") @mock.patch("cloudkitty.storage_state.StateManager" ".is_storage_scope_active") @mock.patch("cloudkitty.orchestrator.Worker.do_execute_scope_processing") @@ -503,7 +506,8 @@ class WorkerTest(tests.TestCase): self.assertTrue(next_timestamp_to_process_mock.called) - @mock.patch("cloudkitty.storage_state.StateManager.get_state") + @mock.patch("cloudkitty.storage_state.StateManager" + ".get_last_processed_timestamp") @mock.patch("cloudkitty.storage_state.StateManager" ".is_storage_scope_active") @mock.patch("cloudkitty.orchestrator.Worker.do_execute_scope_processing") @@ -588,7 +592,8 @@ class WorkerTest(tests.TestCase): state_mock = mock.Mock() timestamp_now = tzutils.localized_now() - state_mock._state.get_state.return_value = timestamp_now + state_mock._state.get_last_processed_timestamp.return_value = \ + timestamp_now expected_time = timestamp_now + datetime.timedelta(hours=1) check_time_state_mock.return_value = \ @@ -599,7 +604,7 @@ class WorkerTest(tests.TestCase): self.assertEqual(expected_time, return_of_method) - state_mock._state.get_state.assert_has_calls([ + state_mock._state.get_last_processed_timestamp.assert_has_calls([ mock.call(self._tenant_id)]) check_time_state_mock.assert_has_calls([ mock.call(timestamp_now, 3600, 2)]) diff --git a/cloudkitty/tests/test_storage_state.py b/cloudkitty/tests/test_storage_state.py index 85cf942a..960a5bc6 100644 --- a/cloudkitty/tests/test_storage_state.py +++ b/cloudkitty/tests/test_storage_state.py @@ -76,8 +76,9 @@ class StateManagerTest(tests.TestCase): self.assertEqual(r_mock.scope_key, 'scope_key') self.assertEqual(r_mock.fetcher, 'fetcher1') - def test_get_state_does_update_columns(self): - self._test_x_state_does_update_columns(self._state.get_state) + def test_get_last_processed_timestamp_does_update_columns(self): + self._test_x_state_does_update_columns( + self._state.get_last_processed_timestamp) def test_set_state_does_update_columns(self): with mock.patch('cloudkitty.db.get_session'): @@ -97,8 +98,9 @@ class StateManagerTest(tests.TestCase): self.assertEqual(r_mock.scope_key, 'scope_key') self.assertEqual(r_mock.fetcher, 'fetcher1') - def test_get_state_no_column_update(self): - self._test_x_state_no_column_update(self._state.get_state) + def test_get_last_processed_timestamp_no_column_update(self): + self._test_x_state_no_column_update( + self._state.get_last_processed_timestamp) def test_set_state_no_column_update(self): with mock.patch('cloudkitty.db.get_session'): diff --git a/cloudkitty/write_orchestrator.py b/cloudkitty/write_orchestrator.py index 14dd464d..b41d5a31 100644 --- a/cloudkitty/write_orchestrator.py +++ b/cloudkitty/write_orchestrator.py @@ -134,7 +134,7 @@ class WriteOrchestrator(object): def reset_state(self): self._load_state_manager_data() - self.usage_end = self._storage_state.get_state() + self.usage_end = self._storage_state.get_last_processed_timestamp() self._update_state_manager_data() def restart_month(self): @@ -145,7 +145,8 @@ class WriteOrchestrator(object): def process(self): self._load_state_manager_data() - storage_state = self._storage_state.get_state(self._tenant_id) + storage_state = self._storage_state.get_last_processed_timestamp( + self._tenant_id) if not self.usage_start: self.usage_start = storage_state self.usage_end = self.usage_start + self._period @@ -154,5 +155,6 @@ class WriteOrchestrator(object): self._commit_data() self._update_state_manager_data() self._load_state_manager_data() - storage_state = self._storage_state.get_state(self._tenant_id) + storage_state = self._storage_state.get_last_processed_timestamp( + self._tenant_id) self.close() diff --git a/releasenotes/notes/deprecate-get-state-2932a4e6a74295ce.yaml b/releasenotes/notes/deprecate-get-state-2932a4e6a74295ce.yaml new file mode 100644 index 00000000..0a0e1380 --- /dev/null +++ b/releasenotes/notes/deprecate-get-state-2932a4e6a74295ce.yaml @@ -0,0 +1,5 @@ +--- +upgrade: + - | + The ``storage_state.get_state`` method has been removed in favor of the + ``storage_state.get_last_processed_timestamp`` method.