17
17
import fixtures
18
18
from neutronclient .common import exceptions as neutron_client_exc
19
19
import os_resource_classes as orc
20
- from oslo_utils import fixture as osloutils_fixture
21
20
from oslo_utils .fixture import uuidsentinel
22
21
from oslo_utils import timeutils
23
22
@@ -1696,10 +1695,10 @@ class TestDBArchiveDeletedRowsTaskLog(integrated_helpers._IntegratedTestBase):
1696
1695
def setUp (self ):
1697
1696
# Override time to ensure we cross audit period boundaries in a
1698
1697
# predictable way.
1699
- faketoday = datetime .datetime (2021 , 7 , 1 )
1698
+ self . faketoday = datetime .datetime (2021 , 7 , 1 )
1700
1699
# This needs to be done before setUp() starts services, else they will
1701
1700
# be considered "down" by the ComputeFilter.
1702
- self .useFixture (test .TimeOverride (override_time = faketoday ))
1701
+ self .useFixture (test .TimeOverride (override_time = self . faketoday ))
1703
1702
super (TestDBArchiveDeletedRowsTaskLog , self ).setUp ()
1704
1703
self .enforce_fk_constraints ()
1705
1704
self .cli = manage .DbCommands ()
@@ -1712,7 +1711,7 @@ def test_archive_task_logs(self):
1712
1711
self .flags (instance_usage_audit = True )
1713
1712
compute = self .computes ['compute' ]
1714
1713
1715
- # Create a few servers so the for the periodic task to process.
1714
+ # Create a few servers for the periodic task to process.
1716
1715
for i in range (0 , 3 ):
1717
1716
self ._create_server ()
1718
1717
@@ -1727,17 +1726,19 @@ def test_archive_task_logs(self):
1727
1726
# July has 31 days, August has 31 days, September has 30 days.
1728
1727
for days in (31 , 31 + 31 , 31 + 31 + 30 ):
1729
1728
future = timeutils .utcnow () + datetime .timedelta (days = days )
1730
- with osloutils_fixture .TimeFixture (future ):
1731
- # task_log records are generated by the _instance_usage_audit
1732
- # periodic task.
1733
- compute .manager ._instance_usage_audit (ctxt )
1734
- # Audit period defaults to 1 month, the last audit period will
1735
- # be the previous calendar month.
1736
- begin , end = nova_utils .last_completed_audit_period ()
1737
- # Verify that we have 1 task_log record per audit period.
1738
- task_logs = objects .TaskLogList .get_all (
1739
- ctxt , 'instance_usage_audit' , begin , end )
1740
- self .assertEqual (1 , len (task_logs ))
1729
+ timeutils .set_time_override (future )
1730
+ # task_log records are generated by the _instance_usage_audit
1731
+ # periodic task.
1732
+ compute .manager ._instance_usage_audit (ctxt )
1733
+ # Audit period defaults to 1 month, the last audit period will
1734
+ # be the previous calendar month.
1735
+ begin , end = nova_utils .last_completed_audit_period ()
1736
+ # Verify that we have 1 task_log record per audit period.
1737
+ task_logs = objects .TaskLogList .get_all (
1738
+ ctxt , 'instance_usage_audit' , begin , end )
1739
+ self .assertEqual (1 , len (task_logs ))
1740
+ # Restore original time override.
1741
+ timeutils .set_time_override (self .faketoday )
1741
1742
1742
1743
# First try archiving without --task-log. Expect no task_log entries in
1743
1744
# the results.
@@ -1746,7 +1747,10 @@ def test_archive_task_logs(self):
1746
1747
# Next try archiving with --task-log and --before.
1747
1748
# We'll archive records that were last updated before the second audit
1748
1749
# period.
1749
- before = timeutils .utcnow () + datetime .timedelta (days = 31 )
1750
+ # The task_log records were created/updated on 2021-08-01, 2021-09-01,
1751
+ # and 2021-10-01. So to archive one record, we need to use
1752
+ # before > 2021-08-01. 2021-07-01 + 31 + 1 = 2021-08-02
1753
+ before = timeutils .utcnow () + datetime .timedelta (days = 31 + 1 )
1750
1754
self .cli .archive_deleted_rows (
1751
1755
task_log = True , before = before .isoformat (), verbose = True )
1752
1756
# Verify that only 1 task_log record was archived.
@@ -1876,10 +1880,10 @@ class TestDBArchiveDeletedRowsMultiCellTaskLog(
1876
1880
def setUp (self ):
1877
1881
# Override time to ensure we cross audit period boundaries in a
1878
1882
# predictable way.
1879
- faketoday = datetime .datetime (2021 , 7 , 1 )
1883
+ self . faketoday = datetime .datetime (2021 , 7 , 1 )
1880
1884
# This needs to be done before setUp() starts services, else they will
1881
1885
# be considered "down" by the ComputeFilter.
1882
- self .useFixture (test .TimeOverride (override_time = faketoday ))
1886
+ self .useFixture (test .TimeOverride (override_time = self . faketoday ))
1883
1887
super (TestDBArchiveDeletedRowsMultiCellTaskLog , self ).setUp ()
1884
1888
self .enforce_fk_constraints ()
1885
1889
self .useFixture (nova_fixtures .NeutronFixture (self ))
@@ -1910,7 +1914,7 @@ def test_archive_task_logs(self):
1910
1914
# nova-compute periodic task.
1911
1915
self .flags (instance_usage_audit = True )
1912
1916
1913
- # Create servers so the for the periodic task to process.
1917
+ # Create servers for the periodic task to process.
1914
1918
# Boot a server to cell1
1915
1919
server = self ._build_server (az = 'nova:host1' )
1916
1920
created_server = self .api .post_server ({'server' : server })
@@ -1931,18 +1935,20 @@ def test_archive_task_logs(self):
1931
1935
# July has 31 days, August has 31 days, September has 30 days.
1932
1936
for days in (31 , 31 + 31 , 31 + 31 + 30 ):
1933
1937
future = timeutils .utcnow () + datetime .timedelta (days = days )
1934
- with osloutils_fixture .TimeFixture (future ):
1935
- # task_log records are generated by the _instance_usage_audit
1936
- # periodic task.
1937
- with context .target_cell (
1938
- ctxt , self .cell_mappings ['cell1' ]) as cctxt :
1939
- self .compute1 .manager ._instance_usage_audit (cctxt )
1940
- with context .target_cell (
1941
- ctxt , self .cell_mappings ['cell2' ]) as cctxt :
1942
- self .compute2 .manager ._instance_usage_audit (ctxt )
1943
- # Audit period defaults to 1 month, the last audit period will
1944
- # be the previous calendar month.
1945
- begin , end = nova_utils .last_completed_audit_period ()
1938
+ timeutils .set_time_override (future )
1939
+ # task_log records are generated by the _instance_usage_audit
1940
+ # periodic task.
1941
+ with context .target_cell (
1942
+ ctxt , self .cell_mappings ['cell1' ]) as cctxt :
1943
+ self .compute1 .manager ._instance_usage_audit (cctxt )
1944
+ with context .target_cell (
1945
+ ctxt , self .cell_mappings ['cell2' ]) as cctxt :
1946
+ self .compute2 .manager ._instance_usage_audit (ctxt )
1947
+ # Audit period defaults to 1 month, the last audit period will
1948
+ # be the previous calendar month.
1949
+ begin , end = nova_utils .last_completed_audit_period ()
1950
+ # Restore original time override.
1951
+ timeutils .set_time_override (self .faketoday )
1946
1952
1947
1953
for cell_name in ('cell1' , 'cell2' ):
1948
1954
with context .target_cell (
@@ -1958,7 +1964,10 @@ def test_archive_task_logs(self):
1958
1964
# Next try archiving with --task-log and --before.
1959
1965
# We'll archive records that were last updated before the second audit
1960
1966
# period.
1961
- before = timeutils .utcnow () + datetime .timedelta (days = 31 )
1967
+ # The task_log records were created/updated on 2021-08-01, 2021-09-01,
1968
+ # and 2021-10-01. So to archive one record, we need to use
1969
+ # before > 2021-08-01. 2021-07-01 + 31 + 1 = 2021-08-02
1970
+ before = timeutils .utcnow () + datetime .timedelta (days = 31 + 1 )
1962
1971
self .cli .archive_deleted_rows (
1963
1972
all_cells = True , task_log = True , before = before .isoformat (),
1964
1973
verbose = True )
0 commit comments