Restore original time override in test_archive_task_logs
Change I9b16a3a849937aba5b90ed1ab9a80b7f0103f673 attempted to fix a non-determinstic failure in the test_archive_task_logs functional test by adding a time override. That fix however missed that the osloutils_fixture.TimeFixture clears the time override when it exits and that does not mean a previous time override will be restored. This removes usage of the osloutils_fixture.TimeFixture and instead sets time overrides and restores previous time overrides. Restoration of the original time overrides also made an adjustment to the --before option value necessary in order to pick up the first task_log record. Closes-Bug: #1934519 Change-Id: Ic28d2e53d5f50e89635e19df08699f2b8c5cea84
This commit is contained in:
parent
5a56ac42ad
commit
39ef1ad774
|
@ -17,7 +17,6 @@ import mock
|
|||
import fixtures
|
||||
from neutronclient.common import exceptions as neutron_client_exc
|
||||
import os_resource_classes as orc
|
||||
from oslo_utils import fixture as osloutils_fixture
|
||||
from oslo_utils.fixture import uuidsentinel
|
||||
from oslo_utils import timeutils
|
||||
|
||||
|
@ -1696,10 +1695,10 @@ class TestDBArchiveDeletedRowsTaskLog(integrated_helpers._IntegratedTestBase):
|
|||
def setUp(self):
|
||||
# Override time to ensure we cross audit period boundaries in a
|
||||
# predictable way.
|
||||
faketoday = datetime.datetime(2021, 7, 1)
|
||||
self.faketoday = datetime.datetime(2021, 7, 1)
|
||||
# This needs to be done before setUp() starts services, else they will
|
||||
# be considered "down" by the ComputeFilter.
|
||||
self.useFixture(test.TimeOverride(override_time=faketoday))
|
||||
self.useFixture(test.TimeOverride(override_time=self.faketoday))
|
||||
super(TestDBArchiveDeletedRowsTaskLog, self).setUp()
|
||||
self.enforce_fk_constraints()
|
||||
self.cli = manage.DbCommands()
|
||||
|
@ -1712,7 +1711,7 @@ class TestDBArchiveDeletedRowsTaskLog(integrated_helpers._IntegratedTestBase):
|
|||
self.flags(instance_usage_audit=True)
|
||||
compute = self.computes['compute']
|
||||
|
||||
# Create a few servers so the for the periodic task to process.
|
||||
# Create a few servers for the periodic task to process.
|
||||
for i in range(0, 3):
|
||||
self._create_server()
|
||||
|
||||
|
@ -1727,17 +1726,19 @@ class TestDBArchiveDeletedRowsTaskLog(integrated_helpers._IntegratedTestBase):
|
|||
# July has 31 days, August has 31 days, September has 30 days.
|
||||
for days in (31, 31 + 31, 31 + 31 + 30):
|
||||
future = timeutils.utcnow() + datetime.timedelta(days=days)
|
||||
with osloutils_fixture.TimeFixture(future):
|
||||
# task_log records are generated by the _instance_usage_audit
|
||||
# periodic task.
|
||||
compute.manager._instance_usage_audit(ctxt)
|
||||
# Audit period defaults to 1 month, the last audit period will
|
||||
# be the previous calendar month.
|
||||
begin, end = nova_utils.last_completed_audit_period()
|
||||
# Verify that we have 1 task_log record per audit period.
|
||||
task_logs = objects.TaskLogList.get_all(
|
||||
ctxt, 'instance_usage_audit', begin, end)
|
||||
self.assertEqual(1, len(task_logs))
|
||||
timeutils.set_time_override(future)
|
||||
# task_log records are generated by the _instance_usage_audit
|
||||
# periodic task.
|
||||
compute.manager._instance_usage_audit(ctxt)
|
||||
# Audit period defaults to 1 month, the last audit period will
|
||||
# be the previous calendar month.
|
||||
begin, end = nova_utils.last_completed_audit_period()
|
||||
# Verify that we have 1 task_log record per audit period.
|
||||
task_logs = objects.TaskLogList.get_all(
|
||||
ctxt, 'instance_usage_audit', begin, end)
|
||||
self.assertEqual(1, len(task_logs))
|
||||
# Restore original time override.
|
||||
timeutils.set_time_override(self.faketoday)
|
||||
|
||||
# First try archiving without --task-log. Expect no task_log entries in
|
||||
# the results.
|
||||
|
@ -1746,7 +1747,10 @@ class TestDBArchiveDeletedRowsTaskLog(integrated_helpers._IntegratedTestBase):
|
|||
# Next try archiving with --task-log and --before.
|
||||
# We'll archive records that were last updated before the second audit
|
||||
# period.
|
||||
before = timeutils.utcnow() + datetime.timedelta(days=31)
|
||||
# The task_log records were created/updated on 2021-08-01, 2021-09-01,
|
||||
# and 2021-10-01. So to archive one record, we need to use
|
||||
# before > 2021-08-01. 2021-07-01 + 31 + 1 = 2021-08-02
|
||||
before = timeutils.utcnow() + datetime.timedelta(days=31 + 1)
|
||||
self.cli.archive_deleted_rows(
|
||||
task_log=True, before=before.isoformat(), verbose=True)
|
||||
# Verify that only 1 task_log record was archived.
|
||||
|
@ -1876,10 +1880,10 @@ class TestDBArchiveDeletedRowsMultiCellTaskLog(
|
|||
def setUp(self):
|
||||
# Override time to ensure we cross audit period boundaries in a
|
||||
# predictable way.
|
||||
faketoday = datetime.datetime(2021, 7, 1)
|
||||
self.faketoday = datetime.datetime(2021, 7, 1)
|
||||
# This needs to be done before setUp() starts services, else they will
|
||||
# be considered "down" by the ComputeFilter.
|
||||
self.useFixture(test.TimeOverride(override_time=faketoday))
|
||||
self.useFixture(test.TimeOverride(override_time=self.faketoday))
|
||||
super(TestDBArchiveDeletedRowsMultiCellTaskLog, self).setUp()
|
||||
self.enforce_fk_constraints()
|
||||
self.useFixture(nova_fixtures.NeutronFixture(self))
|
||||
|
@ -1910,7 +1914,7 @@ class TestDBArchiveDeletedRowsMultiCellTaskLog(
|
|||
# nova-compute periodic task.
|
||||
self.flags(instance_usage_audit=True)
|
||||
|
||||
# Create servers so the for the periodic task to process.
|
||||
# Create servers for the periodic task to process.
|
||||
# Boot a server to cell1
|
||||
server = self._build_server(az='nova:host1')
|
||||
created_server = self.api.post_server({'server': server})
|
||||
|
@ -1931,18 +1935,20 @@ class TestDBArchiveDeletedRowsMultiCellTaskLog(
|
|||
# July has 31 days, August has 31 days, September has 30 days.
|
||||
for days in (31, 31 + 31, 31 + 31 + 30):
|
||||
future = timeutils.utcnow() + datetime.timedelta(days=days)
|
||||
with osloutils_fixture.TimeFixture(future):
|
||||
# task_log records are generated by the _instance_usage_audit
|
||||
# periodic task.
|
||||
with context.target_cell(
|
||||
ctxt, self.cell_mappings['cell1']) as cctxt:
|
||||
self.compute1.manager._instance_usage_audit(cctxt)
|
||||
with context.target_cell(
|
||||
ctxt, self.cell_mappings['cell2']) as cctxt:
|
||||
self.compute2.manager._instance_usage_audit(ctxt)
|
||||
# Audit period defaults to 1 month, the last audit period will
|
||||
# be the previous calendar month.
|
||||
begin, end = nova_utils.last_completed_audit_period()
|
||||
timeutils.set_time_override(future)
|
||||
# task_log records are generated by the _instance_usage_audit
|
||||
# periodic task.
|
||||
with context.target_cell(
|
||||
ctxt, self.cell_mappings['cell1']) as cctxt:
|
||||
self.compute1.manager._instance_usage_audit(cctxt)
|
||||
with context.target_cell(
|
||||
ctxt, self.cell_mappings['cell2']) as cctxt:
|
||||
self.compute2.manager._instance_usage_audit(ctxt)
|
||||
# Audit period defaults to 1 month, the last audit period will
|
||||
# be the previous calendar month.
|
||||
begin, end = nova_utils.last_completed_audit_period()
|
||||
# Restore original time override.
|
||||
timeutils.set_time_override(self.faketoday)
|
||||
|
||||
for cell_name in ('cell1', 'cell2'):
|
||||
with context.target_cell(
|
||||
|
@ -1958,7 +1964,10 @@ class TestDBArchiveDeletedRowsMultiCellTaskLog(
|
|||
# Next try archiving with --task-log and --before.
|
||||
# We'll archive records that were last updated before the second audit
|
||||
# period.
|
||||
before = timeutils.utcnow() + datetime.timedelta(days=31)
|
||||
# The task_log records were created/updated on 2021-08-01, 2021-09-01,
|
||||
# and 2021-10-01. So to archive one record, we need to use
|
||||
# before > 2021-08-01. 2021-07-01 + 31 + 1 = 2021-08-02
|
||||
before = timeutils.utcnow() + datetime.timedelta(days=31 + 1)
|
||||
self.cli.archive_deleted_rows(
|
||||
all_cells=True, task_log=True, before=before.isoformat(),
|
||||
verbose=True)
|
||||
|
|
Loading…
Reference in New Issue