Browse Source

Merge "DB Migration: fix downgrade in 579c267fbb" into stable/queens

Zuul 9 months ago
parent
commit
57d981b12a

+ 4
- 2
manila/db/migrations/alembic/versions/579c267fbb4d_add_share_instances_access_map.py View File

@@ -89,10 +89,12 @@ def downgrade():
89 89
     instance_access_table = utils.load_table('share_instance_access_map',
90 90
                                              connection)
91 91
 
92
-    for access_rule in connection.execute(access_table.select()):
92
+    share_access_rules = connection.execute(
93
+        access_table.select().where(access_table.c.deleted == "False"))
94
+
95
+    for access_rule in share_access_rules:
93 96
         access_mapping = connection.execute(
94 97
             instance_access_table.select().where(
95
-                instance_access_table.c.deleted == "False").where(
96 98
                 instance_access_table.c.access_id == access_rule['id'])
97 99
         ).first()
98 100
 

+ 105
- 1
manila/tests/db/migrations/alembic/migrations_data_checks.py View File

@@ -586,6 +586,9 @@ class AccessRulesStatusMigrationChecks(BaseMigrationChecks):
586 586
     def check_downgrade(self, engine):
587 587
         share_instances_rules_table = utils.load_table(
588 588
             'share_instance_access_map', engine)
589
+        share_instance_rules_to_check = engine.execute(
590
+            share_instances_rules_table.select().where(
591
+                share_instances_rules_table.c.id.in_(('1', '2', '3', '4'))))
589 592
 
590 593
         valid_statuses = {
591 594
             '1': 'active',
@@ -594,7 +597,7 @@ class AccessRulesStatusMigrationChecks(BaseMigrationChecks):
594 597
             '4': None,
595 598
         }
596 599
 
597
-        for rule in engine.execute(share_instances_rules_table.select()):
600
+        for rule in share_instance_rules_to_check:
598 601
             valid_state = valid_statuses[rule['share_instance_id']]
599 602
             self.test_case.assertEqual(valid_state, rule['state'])
600 603
 
@@ -2562,3 +2565,104 @@ class BackenInfoTableChecks(BaseMigrationChecks):
2562 2565
     def check_downgrade(self, engine):
2563 2566
         self.test_case.assertRaises(sa_exc.NoSuchTableError, utils.load_table,
2564 2567
                                     self.new_table_name, engine)
2568
+
2569
+
2570
+@map_to_migration('579c267fbb4d')
2571
+class ShareInstanceAccessMapTableChecks(BaseMigrationChecks):
2572
+    share_access_table = 'share_access_map'
2573
+    share_instance_access_table = 'share_instance_access_map'
2574
+
2575
+    @staticmethod
2576
+    def generate_share_instance(share_id, **kwargs):
2577
+        share_instance_data = {
2578
+            'id': uuidutils.generate_uuid(),
2579
+            'deleted': 'False',
2580
+            'host': 'fake',
2581
+            'share_id': share_id,
2582
+            'status': constants.STATUS_AVAILABLE,
2583
+        }
2584
+        share_instance_data.update(**kwargs)
2585
+        return share_instance_data
2586
+
2587
+    @staticmethod
2588
+    def generate_share_access_map(share_id, **kwargs):
2589
+        share_access_data = {
2590
+            'id': uuidutils.generate_uuid(),
2591
+            'share_id': share_id,
2592
+            'deleted': 'False',
2593
+            'access_type': 'ip',
2594
+            'access_to': '192.0.2.10',
2595
+        }
2596
+        share_access_data.update(**kwargs)
2597
+        return share_access_data
2598
+
2599
+    def setup_upgrade_data(self, engine):
2600
+        share = {
2601
+            'id': uuidutils.generate_uuid(),
2602
+            'share_proto': 'fake',
2603
+            'size': 1,
2604
+            'snapshot_id': None,
2605
+            'user_id': 'fake',
2606
+            'project_id': 'fake'
2607
+        }
2608
+        share_table = utils.load_table('shares', engine)
2609
+        engine.execute(share_table.insert(share))
2610
+
2611
+        share_instances = [
2612
+            self.generate_share_instance(share['id']),
2613
+            self.generate_share_instance(share['id']),
2614
+        ]
2615
+
2616
+        share_instance_table = utils.load_table('share_instances', engine)
2617
+        for share_instance in share_instances:
2618
+            engine.execute(share_instance_table.insert(share_instance))
2619
+
2620
+        share_accesses = [
2621
+            self.generate_share_access_map(
2622
+                share['id'], state=constants.ACCESS_STATE_ACTIVE),
2623
+            self.generate_share_access_map(
2624
+                share['id'], state=constants.ACCESS_STATE_ERROR),
2625
+        ]
2626
+        self.active_share_access = share_accesses[0]
2627
+        self.error_share_access = share_accesses[1]
2628
+        share_access_table = utils.load_table('share_access_map', engine)
2629
+        engine.execute(share_access_table.insert(share_accesses))
2630
+
2631
+    def check_upgrade(self, engine, data):
2632
+        share_access_table = utils.load_table(
2633
+            self.share_access_table, engine)
2634
+        share_instance_access_table = utils.load_table(
2635
+            self.share_instance_access_table, engine)
2636
+        share_accesses = engine.execute(share_access_table.select())
2637
+        share_instance_accesses = engine.execute(
2638
+            share_instance_access_table.select())
2639
+
2640
+        for share_access in share_accesses:
2641
+            self.test_case.assertFalse(hasattr(share_access, 'state'))
2642
+
2643
+        for si_access in share_instance_accesses:
2644
+            if si_access['access_id'] in (self.active_share_access['id'],
2645
+                                          self.error_share_access['id']):
2646
+                self.test_case.assertIn(si_access['state'],
2647
+                                        (self.active_share_access['state'],
2648
+                                         self.error_share_access['state']))
2649
+
2650
+    def check_downgrade(self, engine):
2651
+        self.test_case.assertRaises(
2652
+            sa_exc.NoSuchTableError, utils.load_table,
2653
+            self.share_instance_access_table, engine)
2654
+
2655
+        share_access_table = utils.load_table(
2656
+            self.share_access_table, engine)
2657
+        share_accesses = engine.execute(share_access_table.select().where(
2658
+            share_access_table.c.id.in_((self.active_share_access['id'],
2659
+                                         self.error_share_access['id']))))
2660
+
2661
+        for share_access in share_accesses:
2662
+            self.test_case.assertTrue(hasattr(share_access, 'state'))
2663
+            if share_access['id'] == self.active_share_access['id']:
2664
+                self.test_case.assertEqual(
2665
+                    constants.ACCESS_STATE_ACTIVE, share_access['state'])
2666
+            elif share_access['id'] == self.error_share_access['id']:
2667
+                self.test_case.assertEqual(
2668
+                    constants.ACCESS_STATE_ERROR, share_access['state'])

+ 7
- 0
releasenotes/notes/bug-1717392-fix-downgrade-share-access-map-bbd5fe9cc7002f2d.yaml View File

@@ -0,0 +1,7 @@
1
+---
2
+fixes:
3
+  - The `Launchpad bug 1717392
4
+    <https://bugs.launchpad.net/manila/+bug/1717392>`_
5
+    has been fixed and database downgrades do not fail if the database
6
+    contains deleted access rules. Database downgrades are not recommended
7
+    in production environments.

Loading…
Cancel
Save