diff --git a/cloudkitty/orchestrator.py b/cloudkitty/orchestrator.py index 52d293dd..33ef0017 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 dce6dc31..c2af444c 100644 --- a/cloudkitty/storage_state/__init__.py +++ b/cloudkitty/storage_state/__init__.py @@ -228,14 +228,6 @@ class StateManager(object): session.add(state_object) session.commit() - 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 e4453a26..bf6581d4 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 cd371909..6a7d21fb 100644 --- a/cloudkitty/tests/test_storage_state.py +++ b/cloudkitty/tests/test_storage_state.py @@ -77,8 +77,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.session_for_write'): @@ -98,8 +99,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.session_for_write'): 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.