Merge "Archive instance_actions and instance_actions_event"
This commit is contained in:
@@ -6470,6 +6470,35 @@ def _archive_deleted_rows_for_table(tablename, max_rows):
|
|||||||
# database's limit of maximum parameter in one SQL statement.
|
# database's limit of maximum parameter in one SQL statement.
|
||||||
deleted_column = table.c.deleted
|
deleted_column = table.c.deleted
|
||||||
columns = [c.name for c in table.c]
|
columns = [c.name for c in table.c]
|
||||||
|
|
||||||
|
# NOTE(clecomte): Tables instance_actions and instances_actions_events
|
||||||
|
# have to be manage differently so we soft-delete them here to let
|
||||||
|
# the archive work the same for all tables
|
||||||
|
if tablename == "instance_actions":
|
||||||
|
instances = models.BASE.metadata.tables["instances"]
|
||||||
|
deleted_instances = sql.select([instances.c.uuid]).\
|
||||||
|
where(instances.c.deleted != instances.c.deleted.default.arg)
|
||||||
|
update_statement = table.update().values(deleted=table.c.id).\
|
||||||
|
where(table.c.instance_uuid.in_(deleted_instances))
|
||||||
|
|
||||||
|
conn.execute(update_statement)
|
||||||
|
|
||||||
|
elif tablename == "instance_actions_events":
|
||||||
|
# NOTE(clecomte): we have to grab all the relation from
|
||||||
|
# instances because instance_actions_events rely on
|
||||||
|
# action_id and not uuid
|
||||||
|
instances = models.BASE.metadata.tables["instances"]
|
||||||
|
instance_actions = models.BASE.metadata.tables["instance_actions"]
|
||||||
|
deleted_instances = sql.select([instances.c.uuid]).\
|
||||||
|
where(instances.c.deleted != instances.c.deleted.default.arg)
|
||||||
|
deleted_actions = sql.select([instance_actions.c.id]).\
|
||||||
|
where(instance_actions.c.instance_uuid.in_(deleted_instances))
|
||||||
|
|
||||||
|
update_statement = table.update().values(deleted=table.c.id).\
|
||||||
|
where(table.c.action_id.in_(deleted_actions))
|
||||||
|
|
||||||
|
conn.execute(update_statement)
|
||||||
|
|
||||||
insert = shadow_table.insert(inline=True).\
|
insert = shadow_table.insert(inline=True).\
|
||||||
from_select(columns,
|
from_select(columns,
|
||||||
sql.select([table],
|
sql.select([table],
|
||||||
|
@@ -96,9 +96,9 @@ class TestDatabaseArchive(test_servers.ServersTestBase):
|
|||||||
self.assertIn('instance_system_metadata', results)
|
self.assertIn('instance_system_metadata', results)
|
||||||
self.assertEqual(len(instance.system_metadata),
|
self.assertEqual(len(instance.system_metadata),
|
||||||
results['instance_system_metadata'])
|
results['instance_system_metadata'])
|
||||||
# FIXME(mriedem): we fail to archive instances because of a fkey
|
# Verify that instances rows are dropped
|
||||||
# referential constraint error with instance_actions not being deleted
|
self.assertIn('instances', results)
|
||||||
self.assertNotIn('instances', results)
|
# Verify that instance_actions and actions_event are dropped
|
||||||
# FIXME(mriedem): instance_actions aren't soft deleted so they aren't
|
# by the archive
|
||||||
# archived, which we need to fix.
|
self.assertIn('instance_actions', results)
|
||||||
self.assertNotIn('instance_actions', results)
|
self.assertIn('instance_actions_events', results)
|
||||||
|
Reference in New Issue
Block a user