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
This commit is contained in:
parent
b611e60954
commit
e3e55d2cf6
@ -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.",
|
||||
|
@ -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.
|
||||
|
@ -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)])
|
||||
|
@ -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'):
|
||||
|
@ -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()
|
||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user