Skip to content

Commit fd0c6e1

Browse files
technowhizzpriteau
authored andcommitted
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 e3e55d2)
1 parent 7197677 commit fd0c6e1

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

cloudkitty/orchestrator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def quote(self, res_data):
272272

273273

274274
def _check_state(obj, period, tenant_id):
275-
timestamp = obj._state.get_state(tenant_id)
275+
timestamp = obj._state.get_last_processed_timestamp(tenant_id)
276276
return ck_utils.check_time_state(timestamp,
277277
period,
278278
CONF.collect.wait_periods)
@@ -387,7 +387,7 @@ def execute_worker_processing(self):
387387
LOG.debug("Worker [%s] finished processing storage scope [%s].",
388388
self._worker_id, self._tenant_id)
389389
return False
390-
if self._state.get_state(self._tenant_id):
390+
if self._state.get_last_processed_timestamp(self._tenant_id):
391391
if not self._state.is_storage_scope_active(self._tenant_id):
392392
LOG.debug("Skipping processing for storage scope [%s] "
393393
"because it is marked as inactive.",

cloudkitty/storage_state/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,6 @@ def create_scope(self, identifier, last_processed_timestamp, fetcher=None,
228228
session.add(state_object)
229229
session.commit()
230230

231-
def get_state(self, identifier,
232-
fetcher=None, collector=None, scope_key=None):
233-
LOG.warning("The method 'get_state' is deprecated. "
234-
"Consider using the new method "
235-
"'get_last_processed_timestamp'.")
236-
return self.get_last_processed_timestamp(
237-
identifier, fetcher, collector, scope_key)
238-
239231
def get_last_processed_timestamp(self, identifier, fetcher=None,
240232
collector=None, scope_key=None):
241233
"""Get the last processed timestamp of a scope.

cloudkitty/tests/test_orchestrator.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ def test_do_execute_scope_processing_with_usage_data(
416416
])
417417
self.assertTrue(update_scope_processing_state_db_mock.called)
418418

419-
@mock.patch("cloudkitty.storage_state.StateManager.get_state")
419+
@mock.patch("cloudkitty.storage_state.StateManager"
420+
".get_last_processed_timestamp")
420421
@mock.patch("cloudkitty.storage_state.StateManager"
421422
".is_storage_scope_active")
422423
@mock.patch("cloudkitty.orchestrator.Worker.do_execute_scope_processing")
@@ -438,7 +439,8 @@ def test_execute_worker_processing_no_next_timestamp(
438439
self.assertFalse(do_execute_scope_processing_mock.called)
439440
self.assertTrue(next_timestamp_to_process_mock.called)
440441

441-
@mock.patch("cloudkitty.storage_state.StateManager.get_state")
442+
@mock.patch("cloudkitty.storage_state.StateManager"
443+
".get_last_processed_timestamp")
442444
@mock.patch("cloudkitty.storage_state.StateManager"
443445
".is_storage_scope_active")
444446
@mock.patch("cloudkitty.orchestrator.Worker.do_execute_scope_processing")
@@ -468,7 +470,8 @@ def test_execute_worker_processing_scope_not_processed_yet(
468470
self.assertFalse(state_manager_is_storage_scope_active_mock.called)
469471
self.assertTrue(next_timestamp_to_process_mock.called)
470472

471-
@mock.patch("cloudkitty.storage_state.StateManager.get_state")
473+
@mock.patch("cloudkitty.storage_state.StateManager"
474+
".get_last_processed_timestamp")
472475
@mock.patch("cloudkitty.storage_state.StateManager"
473476
".is_storage_scope_active")
474477
@mock.patch("cloudkitty.orchestrator.Worker.do_execute_scope_processing")
@@ -503,7 +506,8 @@ def test_execute_worker_processing_scope_already_processed_active(
503506

504507
self.assertTrue(next_timestamp_to_process_mock.called)
505508

506-
@mock.patch("cloudkitty.storage_state.StateManager.get_state")
509+
@mock.patch("cloudkitty.storage_state.StateManager"
510+
".get_last_processed_timestamp")
507511
@mock.patch("cloudkitty.storage_state.StateManager"
508512
".is_storage_scope_active")
509513
@mock.patch("cloudkitty.orchestrator.Worker.do_execute_scope_processing")
@@ -588,7 +592,8 @@ def test_check_state(self, check_time_state_mock):
588592
state_mock = mock.Mock()
589593

590594
timestamp_now = tzutils.localized_now()
591-
state_mock._state.get_state.return_value = timestamp_now
595+
state_mock._state.get_last_processed_timestamp.return_value = \
596+
timestamp_now
592597

593598
expected_time = timestamp_now + datetime.timedelta(hours=1)
594599
check_time_state_mock.return_value = \
@@ -599,7 +604,7 @@ def test_check_state(self, check_time_state_mock):
599604

600605
self.assertEqual(expected_time, return_of_method)
601606

602-
state_mock._state.get_state.assert_has_calls([
607+
state_mock._state.get_last_processed_timestamp.assert_has_calls([
603608
mock.call(self._tenant_id)])
604609
check_time_state_mock.assert_has_calls([
605610
mock.call(timestamp_now, 3600, 2)])

cloudkitty/tests/test_storage_state.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ def _test_x_state_does_update_columns(self, func):
7777
self.assertEqual(r_mock.scope_key, 'scope_key')
7878
self.assertEqual(r_mock.fetcher, 'fetcher1')
7979

80-
def test_get_state_does_update_columns(self):
81-
self._test_x_state_does_update_columns(self._state.get_state)
80+
def test_get_last_processed_timestamp_does_update_columns(self):
81+
self._test_x_state_does_update_columns(
82+
self._state.get_last_processed_timestamp)
8283

8384
def test_set_state_does_update_columns(self):
8485
with mock.patch('cloudkitty.db.session_for_write'):
@@ -98,8 +99,9 @@ def _test_x_state_no_column_update(self, func):
9899
self.assertEqual(r_mock.scope_key, 'scope_key')
99100
self.assertEqual(r_mock.fetcher, 'fetcher1')
100101

101-
def test_get_state_no_column_update(self):
102-
self._test_x_state_no_column_update(self._state.get_state)
102+
def test_get_last_processed_timestamp_no_column_update(self):
103+
self._test_x_state_no_column_update(
104+
self._state.get_last_processed_timestamp)
103105

104106
def test_set_state_no_column_update(self):
105107
with mock.patch('cloudkitty.db.session_for_write'):

cloudkitty/write_orchestrator.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _commit_data(self):
134134

135135
def reset_state(self):
136136
self._load_state_manager_data()
137-
self.usage_end = self._storage_state.get_state()
137+
self.usage_end = self._storage_state.get_last_processed_timestamp()
138138
self._update_state_manager_data()
139139

140140
def restart_month(self):
@@ -145,7 +145,8 @@ def restart_month(self):
145145

146146
def process(self):
147147
self._load_state_manager_data()
148-
storage_state = self._storage_state.get_state(self._tenant_id)
148+
storage_state = self._storage_state.get_last_processed_timestamp(
149+
self._tenant_id)
149150
if not self.usage_start:
150151
self.usage_start = storage_state
151152
self.usage_end = self.usage_start + self._period
@@ -154,5 +155,6 @@ def process(self):
154155
self._commit_data()
155156
self._update_state_manager_data()
156157
self._load_state_manager_data()
157-
storage_state = self._storage_state.get_state(self._tenant_id)
158+
storage_state = self._storage_state.get_last_processed_timestamp(
159+
self._tenant_id)
158160
self.close()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
upgrade:
3+
- |
4+
The ``storage_state.get_state`` method has been removed in favor of the
5+
``storage_state.get_last_processed_timestamp`` method.

0 commit comments

Comments
 (0)