Remove unused context parameter from db.archive_deleted_rows* methods

Commit 316a94dd03 removed the usage of
the @require_admin_context decorator from the DB API methods and the
context parameter was only used for that decorator, so we can remove
the context parameter now.

Change-Id: Ib55b69c5bf00957e26f728892b3c842e9bab7b2f
This commit is contained in:
Matt Riedemann
2015-10-07 07:29:35 -07:00
parent 67c5e882e3
commit 55ce4c38f9
4 changed files with 22 additions and 25 deletions

View File

@@ -949,8 +949,7 @@ class DbCommands(object):
if max_rows < 0: if max_rows < 0:
print(_("Must supply a positive value for max_rows")) print(_("Must supply a positive value for max_rows"))
return(1) return(1)
admin_context = context.get_admin_context() db.archive_deleted_rows(max_rows)
db.archive_deleted_rows(admin_context, max_rows)
@args('--delete', action='store_true', dest='delete', @args('--delete', action='store_true', dest='delete',
help='If specified, automatically delete any records found where ' help='If specified, automatically delete any records found where '

View File

@@ -1895,22 +1895,22 @@ def task_log_get(context, task_name, period_beginning,
#################### ####################
def archive_deleted_rows(context, max_rows=None): def archive_deleted_rows(max_rows=None):
"""Move up to max_rows rows from production tables to corresponding shadow """Move up to max_rows rows from production tables to corresponding shadow
tables. tables.
:returns: number of rows archived. :returns: number of rows archived.
""" """
return IMPL.archive_deleted_rows(context, max_rows=max_rows) return IMPL.archive_deleted_rows(max_rows=max_rows)
def archive_deleted_rows_for_table(context, tablename, max_rows=None): def archive_deleted_rows_for_table(tablename, max_rows=None):
"""Move up to max_rows rows from tablename to corresponding shadow """Move up to max_rows rows from tablename to corresponding shadow
table. table.
:returns: number of rows archived. :returns: number of rows archived.
""" """
return IMPL.archive_deleted_rows_for_table(context, tablename, return IMPL.archive_deleted_rows_for_table(tablename,
max_rows=max_rows) max_rows=max_rows)

View File

@@ -5964,9 +5964,9 @@ def task_log_end_task(context, task_name, period_beginning, period_ending,
raise exception.TaskNotRunning(task_name=task_name, host=host) raise exception.TaskNotRunning(task_name=task_name, host=host)
def archive_deleted_rows_for_table(context, tablename, max_rows): def archive_deleted_rows_for_table(tablename, max_rows):
"""Move up to max_rows rows from one tables to the corresponding """Move up to max_rows rows from one tables to the corresponding
shadow table. The context argument is only used for the decorator. shadow table.
:returns: number of rows archived :returns: number of rows archived
""" """
@@ -6032,20 +6032,19 @@ def archive_deleted_rows_for_table(context, tablename, max_rows):
return rows_archived return rows_archived
def archive_deleted_rows(context, max_rows=None): def archive_deleted_rows(max_rows=None):
"""Move up to max_rows rows from production tables to the corresponding """Move up to max_rows rows from production tables to the corresponding
shadow tables. shadow tables.
:returns: Number of rows archived. :returns: Number of rows archived.
""" """
# The context argument is only used for the decorator.
tablenames = [] tablenames = []
for model_class in six.itervalues(models.__dict__): for model_class in six.itervalues(models.__dict__):
if hasattr(model_class, "__tablename__"): if hasattr(model_class, "__tablename__"):
tablenames.append(model_class.__tablename__) tablenames.append(model_class.__tablename__)
rows_archived = 0 rows_archived = 0
for tablename in tablenames: for tablename in tablenames:
rows_archived += archive_deleted_rows_for_table(context, tablename, rows_archived += archive_deleted_rows_for_table(tablename,
max_rows=max_rows - rows_archived) max_rows=max_rows - rows_archived)
if rows_archived >= max_rows: if rows_archived >= max_rows:
break break

View File

@@ -8026,7 +8026,6 @@ class ArchiveTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(ArchiveTestCase, self).setUp() super(ArchiveTestCase, self).setUp()
self.context = context.get_admin_context()
self.engine = get_engine() self.engine = get_engine()
self.conn = self.engine.connect() self.conn = self.engine.connect()
self.instance_id_mappings = models.InstanceIdMapping.__table__ self.instance_id_mappings = models.InstanceIdMapping.__table__
@@ -8108,7 +8107,7 @@ class ArchiveTestCase(test.TestCase):
# Verify we have 0 in shadow # Verify we have 0 in shadow
self.assertEqual(len(rows), 0) self.assertEqual(len(rows), 0)
# Archive 2 rows # Archive 2 rows
db.archive_deleted_rows(self.context, max_rows=2) db.archive_deleted_rows(max_rows=2)
rows = self.conn.execute(qiim).fetchall() rows = self.conn.execute(qiim).fetchall()
# Verify we have 4 left in main # Verify we have 4 left in main
self.assertEqual(len(rows), 4) self.assertEqual(len(rows), 4)
@@ -8116,7 +8115,7 @@ class ArchiveTestCase(test.TestCase):
# Verify we have 2 in shadow # Verify we have 2 in shadow
self.assertEqual(len(rows), 2) self.assertEqual(len(rows), 2)
# Archive 2 more rows # Archive 2 more rows
db.archive_deleted_rows(self.context, max_rows=2) db.archive_deleted_rows(max_rows=2)
rows = self.conn.execute(qiim).fetchall() rows = self.conn.execute(qiim).fetchall()
# Verify we have 2 left in main # Verify we have 2 left in main
self.assertEqual(len(rows), 2) self.assertEqual(len(rows), 2)
@@ -8124,7 +8123,7 @@ class ArchiveTestCase(test.TestCase):
# Verify we have 4 in shadow # Verify we have 4 in shadow
self.assertEqual(len(rows), 4) self.assertEqual(len(rows), 4)
# Try to archive more, but there are no deleted rows left. # Try to archive more, but there are no deleted rows left.
db.archive_deleted_rows(self.context, max_rows=2) db.archive_deleted_rows(max_rows=2)
rows = self.conn.execute(qiim).fetchall() rows = self.conn.execute(qiim).fetchall()
# Verify we still have 2 left in main # Verify we still have 2 left in main
self.assertEqual(len(rows), 2) self.assertEqual(len(rows), 2)
@@ -8178,7 +8177,7 @@ class ArchiveTestCase(test.TestCase):
# Verify we have 0 in shadow # Verify we have 0 in shadow
self.assertEqual(len(rows), 0) self.assertEqual(len(rows), 0)
# Archive 2 rows # Archive 2 rows
db.archive_deleted_rows_for_table(self.context, tablename, max_rows=2) db.archive_deleted_rows_for_table(tablename, max_rows=2)
# Verify we have 4 left in main # Verify we have 4 left in main
rows = self.conn.execute(qmt).fetchall() rows = self.conn.execute(qmt).fetchall()
self.assertEqual(len(rows), 4) self.assertEqual(len(rows), 4)
@@ -8186,7 +8185,7 @@ class ArchiveTestCase(test.TestCase):
rows = self.conn.execute(qst).fetchall() rows = self.conn.execute(qst).fetchall()
self.assertEqual(len(rows), 2) self.assertEqual(len(rows), 2)
# Archive 2 more rows # Archive 2 more rows
db.archive_deleted_rows_for_table(self.context, tablename, max_rows=2) db.archive_deleted_rows_for_table(tablename, max_rows=2)
# Verify we have 2 left in main # Verify we have 2 left in main
rows = self.conn.execute(qmt).fetchall() rows = self.conn.execute(qmt).fetchall()
self.assertEqual(len(rows), 2) self.assertEqual(len(rows), 2)
@@ -8194,7 +8193,7 @@ class ArchiveTestCase(test.TestCase):
rows = self.conn.execute(qst).fetchall() rows = self.conn.execute(qst).fetchall()
self.assertEqual(len(rows), 4) self.assertEqual(len(rows), 4)
# Try to archive more, but there are no deleted rows left. # Try to archive more, but there are no deleted rows left.
db.archive_deleted_rows_for_table(self.context, tablename, max_rows=2) db.archive_deleted_rows_for_table(tablename, max_rows=2)
# Verify we still have 2 left in main # Verify we still have 2 left in main
rows = self.conn.execute(qmt).fetchall() rows = self.conn.execute(qmt).fetchall()
self.assertEqual(len(rows), 2) self.assertEqual(len(rows), 2)
@@ -8219,7 +8218,7 @@ class ArchiveTestCase(test.TestCase):
self.shadow_dns_domains.c.domain == uuidstr0) self.shadow_dns_domains.c.domain == uuidstr0)
rows = self.conn.execute(qsdd).fetchall() rows = self.conn.execute(qsdd).fetchall()
self.assertEqual(len(rows), 0) self.assertEqual(len(rows), 0)
db.archive_deleted_rows(self.context, max_rows=1) db.archive_deleted_rows(max_rows=1)
rows = self.conn.execute(qdd).fetchall() rows = self.conn.execute(qdd).fetchall()
self.assertEqual(len(rows), 0) self.assertEqual(len(rows), 0)
rows = self.conn.execute(qsdd).fetchall() rows = self.conn.execute(qsdd).fetchall()
@@ -8251,13 +8250,13 @@ class ArchiveTestCase(test.TestCase):
result = self.conn.execute(ins_stmt) result = self.conn.execute(ins_stmt)
result.inserted_primary_key[0] result.inserted_primary_key[0]
# The first try to archive console_pools should fail, due to FK. # The first try to archive console_pools should fail, due to FK.
num = db.archive_deleted_rows_for_table(self.context, "console_pools") num = db.archive_deleted_rows_for_table("console_pools")
self.assertEqual(num, 0) self.assertEqual(num, 0)
# Then archiving consoles should work. # Then archiving consoles should work.
num = db.archive_deleted_rows_for_table(self.context, "consoles") num = db.archive_deleted_rows_for_table("consoles")
self.assertEqual(num, 1) self.assertEqual(num, 1)
# Then archiving console_pools should work. # Then archiving console_pools should work.
num = db.archive_deleted_rows_for_table(self.context, "console_pools") num = db.archive_deleted_rows_for_table("console_pools")
self.assertEqual(num, 1) self.assertEqual(num, 1)
self._assert_shadow_tables_empty_except( self._assert_shadow_tables_empty_except(
'shadow_console_pools', 'shadow_console_pools',
@@ -8300,7 +8299,7 @@ class ArchiveTestCase(test.TestCase):
rows = self.conn.execute(qsi).fetchall() rows = self.conn.execute(qsi).fetchall()
self.assertEqual(len(rows), 0) self.assertEqual(len(rows), 0)
# Archive 7 rows, which should be 4 in one table and 3 in the other. # Archive 7 rows, which should be 4 in one table and 3 in the other.
db.archive_deleted_rows(self.context, max_rows=7) db.archive_deleted_rows(max_rows=7)
# Verify we have 5 left in the two main tables combined # Verify we have 5 left in the two main tables combined
iim_rows = self.conn.execute(qiim).fetchall() iim_rows = self.conn.execute(qiim).fetchall()
i_rows = self.conn.execute(qi).fetchall() i_rows = self.conn.execute(qi).fetchall()
@@ -8310,7 +8309,7 @@ class ArchiveTestCase(test.TestCase):
si_rows = self.conn.execute(qsi).fetchall() si_rows = self.conn.execute(qsi).fetchall()
self.assertEqual(len(siim_rows) + len(si_rows), 7) self.assertEqual(len(siim_rows) + len(si_rows), 7)
# Archive the remaining deleted rows. # Archive the remaining deleted rows.
db.archive_deleted_rows(self.context, max_rows=1) db.archive_deleted_rows(max_rows=1)
# Verify we have 4 total left in both main tables. # Verify we have 4 total left in both main tables.
iim_rows = self.conn.execute(qiim).fetchall() iim_rows = self.conn.execute(qiim).fetchall()
i_rows = self.conn.execute(qi).fetchall() i_rows = self.conn.execute(qi).fetchall()
@@ -8320,7 +8319,7 @@ class ArchiveTestCase(test.TestCase):
si_rows = self.conn.execute(qsi).fetchall() si_rows = self.conn.execute(qsi).fetchall()
self.assertEqual(len(siim_rows) + len(si_rows), 8) self.assertEqual(len(siim_rows) + len(si_rows), 8)
# Try to archive more, but there are no deleted rows left. # Try to archive more, but there are no deleted rows left.
db.archive_deleted_rows(self.context, max_rows=500) db.archive_deleted_rows(max_rows=500)
# Verify we have 4 total left in both main tables. # Verify we have 4 total left in both main tables.
iim_rows = self.conn.execute(qiim).fetchall() iim_rows = self.conn.execute(qiim).fetchall()
i_rows = self.conn.execute(qi).fetchall() i_rows = self.conn.execute(qi).fetchall()