Skip to content

Commit 2e31f6a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Prevent archiving of pci_devices records because of 'instance_uuid'" into stable/victoria
2 parents cf1db74 + 09784db commit 2e31f6a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

nova/db/sqlalchemy/api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4225,7 +4225,11 @@ def _archive_deleted_rows_for_table(metadata, tablename, max_rows, before):
42254225
# NOTE(jake): instance_actions_events doesn't have a instance_uuid column
42264226
# but still needs to be archived as it is a FK constraint
42274227
if ((max_rows is None or rows_archived < max_rows) and
4228-
('instance_uuid' in columns or
4228+
# NOTE(melwitt): The pci_devices table uses the 'instance_uuid'
4229+
# column to track the allocated association of a PCI device and its
4230+
# records are not tied to the lifecycles of instance records.
4231+
(tablename != 'pci_devices' and
4232+
'instance_uuid' in columns or
42294233
tablename == 'instance_actions_events')):
42304234
instances = models.BASE.metadata.tables['instances']
42314235
limit = max_rows - rows_archived if max_rows is not None else None

nova/tests/functional/db/test_archive.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ def test_archive_deleted_rows_with_undeleted_residue(self):
114114
# Verify we have some system_metadata since we'll check that later.
115115
self.assertTrue(len(instance.system_metadata),
116116
'No system_metadata for instance: %s' % server_id)
117+
# Create a pci_devices record to simulate an instance that had a PCI
118+
# device allocated at the time it was deleted. There is a window of
119+
# time between deletion of the instance record and freeing of the PCI
120+
# device in nova-compute's _complete_deletion method during RT update.
121+
db.pci_device_update(admin_context, 1, 'fake-address',
122+
{'compute_node_id': 1,
123+
'address': 'fake-address',
124+
'vendor_id': 'fake',
125+
'product_id': 'fake',
126+
'dev_type': 'fake',
127+
'label': 'fake',
128+
'status': 'allocated',
129+
'instance_uuid': instance.uuid})
117130
# Now try and archive the soft deleted records.
118131
results, deleted_instance_uuids, archived = \
119132
db.archive_deleted_rows(max_rows=100)
@@ -128,6 +141,8 @@ def test_archive_deleted_rows_with_undeleted_residue(self):
128141
self.assertIn('instance_actions', results)
129142
self.assertIn('instance_actions_events', results)
130143
self.assertEqual(sum(results.values()), archived)
144+
# Verify that the pci_devices record has not been dropped
145+
self.assertNotIn('pci_devices', results)
131146

132147
def _get_table_counts(self):
133148
engine = sqlalchemy_api.get_engine()

0 commit comments

Comments
 (0)