Skip to content

Commit 642caf0

Browse files
committed
Skip soft-deleted records in 330_enforce_mitaka_online_migrations
The 330_enforce_mitaka_online_migrations migration considers soft-deleted records as unmigrated (the blocker migration uses the select function from sqlalchemy), but the online migrations only migrate non-deleted records (the migrations use the model_query function which defaults to read_deleted='no'). So even after running all of the online migrations, operators can get stuck until they can hard delete any soft-deleted compute_nodes, aggregates, and pci_devices records they have. Conflicts: nova/tests/unit/db/test_sqlalchemy_migration.py NOTE(melwitt): The conflict is due to ocata unit tests that don't exist in newton. Closes-Bug: #1665719 Change-Id: I2285005098b7dab7753366f53667ff8d4532d668 (cherry picked from commit 6d64b72)
1 parent af44ff9 commit 642caf0

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

nova/db/sqlalchemy/migrate_repo/versions/330_enforce_mitaka_online_migrations.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
from sqlalchemy import MetaData, Table, func, select
13+
from sqlalchemy import MetaData, Table, and_, func, select
1414

1515
from nova import exception
1616
from nova.i18n import _
@@ -27,8 +27,9 @@ def upgrade(migrate_engine):
2727
aggregates = Table('aggregates', meta, autoload=True)
2828

2929
for table in (compute_nodes, aggregates):
30-
count = select([func.count()]).select_from(table).where(
31-
table.c.uuid == None).execute().scalar() # NOQA
30+
count = select([func.count()]).select_from(table).where(and_(
31+
table.c.deleted == 0,
32+
table.c.uuid == None)).execute().scalar() # NOQA
3233
if count > 0:
3334
msg = WARNING_MSG % {
3435
'count': count,
@@ -37,8 +38,9 @@ def upgrade(migrate_engine):
3738
raise exception.ValidationError(detail=msg)
3839

3940
pci_devices = Table('pci_devices', meta, autoload=True)
40-
count = select([func.count()]).select_from(pci_devices).where(
41-
pci_devices.c.parent_addr == None).execute().scalar() # NOQA
41+
count = select([func.count()]).select_from(pci_devices).where(and_(
42+
pci_devices.c.deleted == 0,
43+
pci_devices.c.parent_addr == None)).execute().scalar() # NOQA
4244
if count > 0:
4345
msg = WARNING_MSG % {
4446
'count': count,

nova/tests/unit/db/test_sqlalchemy_migration.py

+25
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,28 @@ def test_pci_device_not_migrated(self):
280280
'status': 'whatisthis?'})
281281
self.assertRaises(exception.ValidationError,
282282
self.migration.upgrade, self.engine)
283+
284+
def test_deleted_not_migrated(self):
285+
cn_values = dict(vcpus=1, memory_mb=512, local_gb=10,
286+
vcpus_used=0, memory_mb_used=256,
287+
local_gb_used=5, hypervisor_type='HyperDanVM',
288+
hypervisor_version='34', cpu_info='foo')
289+
cn = db_api.compute_node_create(self.context, cn_values)
290+
agg_values = dict(name='foo')
291+
agg = db_api.aggregate_create(self.context, agg_values)
292+
pd = db_api.pci_device_update(self.context, 1, 'foo:bar',
293+
{'parent_addr': None,
294+
'compute_node_id': 1,
295+
'address': 'foo:bar',
296+
'vendor_id': '123',
297+
'product_id': '456',
298+
'dev_type': 'foo',
299+
'label': 'foobar',
300+
'status': 'whatisthis?'})
301+
db_api.compute_node_delete(self.context, cn['id'])
302+
db_api.aggregate_delete(self.context, agg['id'])
303+
db_api.pci_device_destroy(self.context, pd['compute_node_id'],
304+
pd['address'])
305+
306+
# blocker should not block on soft-deleted records
307+
self.migration.upgrade(self.engine)

0 commit comments

Comments
 (0)