Merge "Prevent archiving of pci_devices records because of 'instance_uuid'" into stable/train
This commit is contained in:
commit
bf5f69697e
|
@ -5593,7 +5593,11 @@ def _archive_deleted_rows_for_table(metadata, tablename, max_rows, before):
|
||||||
# NOTE(jake): instance_actions_events doesn't have a instance_uuid column
|
# NOTE(jake): instance_actions_events doesn't have a instance_uuid column
|
||||||
# but still needs to be archived as it is a FK constraint
|
# but still needs to be archived as it is a FK constraint
|
||||||
if ((max_rows is None or rows_archived < max_rows) and
|
if ((max_rows is None or rows_archived < max_rows) and
|
||||||
('instance_uuid' in columns or
|
# NOTE(melwitt): The pci_devices table uses the 'instance_uuid'
|
||||||
|
# column to track the allocated association of a PCI device and its
|
||||||
|
# records are not tied to the lifecycles of instance records.
|
||||||
|
(tablename != 'pci_devices' and
|
||||||
|
'instance_uuid' in columns or
|
||||||
tablename == 'instance_actions_events')):
|
tablename == 'instance_actions_events')):
|
||||||
instances = models.BASE.metadata.tables['instances']
|
instances = models.BASE.metadata.tables['instances']
|
||||||
limit = max_rows - rows_archived if max_rows is not None else None
|
limit = max_rows - rows_archived if max_rows is not None else None
|
||||||
|
|
|
@ -137,6 +137,19 @@ class TestDatabaseArchive(test_servers.ServersTestBase):
|
||||||
# Verify we have some system_metadata since we'll check that later.
|
# Verify we have some system_metadata since we'll check that later.
|
||||||
self.assertTrue(len(instance.system_metadata),
|
self.assertTrue(len(instance.system_metadata),
|
||||||
'No system_metadata for instance: %s' % server_id)
|
'No system_metadata for instance: %s' % server_id)
|
||||||
|
# Create a pci_devices record to simulate an instance that had a PCI
|
||||||
|
# device allocated at the time it was deleted. There is a window of
|
||||||
|
# time between deletion of the instance record and freeing of the PCI
|
||||||
|
# device in nova-compute's _complete_deletion method during RT update.
|
||||||
|
db.pci_device_update(admin_context, 1, 'fake-address',
|
||||||
|
{'compute_node_id': 1,
|
||||||
|
'address': 'fake-address',
|
||||||
|
'vendor_id': 'fake',
|
||||||
|
'product_id': 'fake',
|
||||||
|
'dev_type': 'fake',
|
||||||
|
'label': 'fake',
|
||||||
|
'status': 'allocated',
|
||||||
|
'instance_uuid': instance.uuid})
|
||||||
# Now try and archive the soft deleted records.
|
# Now try and archive the soft deleted records.
|
||||||
results, deleted_instance_uuids, archived = \
|
results, deleted_instance_uuids, archived = \
|
||||||
db.archive_deleted_rows(max_rows=100)
|
db.archive_deleted_rows(max_rows=100)
|
||||||
|
@ -151,6 +164,8 @@ class TestDatabaseArchive(test_servers.ServersTestBase):
|
||||||
self.assertIn('instance_actions', results)
|
self.assertIn('instance_actions', results)
|
||||||
self.assertIn('instance_actions_events', results)
|
self.assertIn('instance_actions_events', results)
|
||||||
self.assertEqual(sum(results.values()), archived)
|
self.assertEqual(sum(results.values()), archived)
|
||||||
|
# Verify that the pci_devices record has not been dropped
|
||||||
|
self.assertNotIn('pci_devices', results)
|
||||||
|
|
||||||
def _get_table_counts(self):
|
def _get_table_counts(self):
|
||||||
engine = sqlalchemy_api.get_engine()
|
engine = sqlalchemy_api.get_engine()
|
||||||
|
|
Loading…
Reference in New Issue