Browse Source

Fix cleanup of expired load balancer entries

Fix a bad query filter, deleted load balancers have a DELETED
provisioning_status (instead of operating_status).

Add a functional test that checks that deleted and expired load
balancers are correctly selected by get_all_deleted_expiring function.

Fix a similar test for amphorae that was buggy and not enabled (because
of missing test_ prefix).

Change-Id: I0ce2eabfd4dd41210312ea3b7f6274c9a6d50e44
Story: 2006496
Task: 36458
changes/00/680400/2
Gregory Thiemonge 2 weeks ago
parent
commit
a4da3ef220

+ 1
- 1
octavia/db/repositories.py View File

@@ -196,7 +196,7 @@ class BaseRepository(object):
196 196
         if hasattr(self.model_class, 'status'):
197 197
             query = query.filter_by(status=consts.DELETED)
198 198
         else:
199
-            query = query.filter_by(operating_status=consts.DELETED)
199
+            query = query.filter_by(provisioning_status=consts.DELETED)
200 200
         # Do not load any relationship
201 201
         query = query.options(noload('*'))
202 202
         model_list = query.all()

+ 27
- 10
octavia/tests/functional/db/test_repositories.py View File

@@ -2661,13 +2661,17 @@ class HealthMonitorRepositoryTest(BaseRepositoryTest):
2661 2661
 
2662 2662
 class LoadBalancerRepositoryTest(BaseRepositoryTest):
2663 2663
 
2664
-    def create_loadbalancer(self, lb_id):
2665
-        lb = self.lb_repo.create(self.session, id=lb_id,
2666
-                                 project_id=self.FAKE_UUID_2, name="lb_name",
2667
-                                 description="lb_description",
2668
-                                 provisioning_status=constants.ACTIVE,
2669
-                                 operating_status=constants.ONLINE,
2670
-                                 enabled=True, tags=['test_tag'])
2664
+    def create_loadbalancer(self, lb_id, **overrides):
2665
+        settings = dict(
2666
+            id=lb_id,
2667
+            project_id=self.FAKE_UUID_2, name="lb_name",
2668
+            description="lb_description",
2669
+            provisioning_status=constants.ACTIVE,
2670
+            operating_status=constants.ONLINE,
2671
+            enabled=True, tags=['test_tag'],
2672
+        )
2673
+        settings.update(**overrides)
2674
+        lb = self.lb_repo.create(self.session, **settings)
2671 2675
         return lb
2672 2676
 
2673 2677
     def test_get(self):
@@ -2936,6 +2940,20 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
2936 2940
         lb = self.lb_repo.get(self.session, id=lb_id)
2937 2941
         self.assertEqual(constants.PENDING_UPDATE, lb.provisioning_status)
2938 2942
 
2943
+    def test_get_all_deleted_expiring_load_balancer(self):
2944
+        exp_age = datetime.timedelta(seconds=self.FAKE_EXP_AGE)
2945
+        updated_at = datetime.datetime.utcnow() - exp_age
2946
+        lb1 = self.create_loadbalancer(
2947
+            self.FAKE_UUID_1, updated_at=updated_at,
2948
+            provisioning_status=constants.DELETED)
2949
+        lb2 = self.create_loadbalancer(
2950
+            self.FAKE_UUID_2, provisioning_status=constants.DELETED)
2951
+
2952
+        expiring_ids = self.lb_repo.get_all_deleted_expiring(
2953
+            self.session, exp_age=exp_age)
2954
+        self.assertIn(lb1.id, expiring_ids)
2955
+        self.assertNotIn(lb2.id, expiring_ids)
2956
+
2939 2957
 
2940 2958
 class VipRepositoryTest(BaseRepositoryTest):
2941 2959
 
@@ -3175,7 +3193,7 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
3175 3193
         self.assertIsNotNone(lb)
3176 3194
         self.assertEqual(self.lb, lb)
3177 3195
 
3178
-    def get_all_deleted_expiring_amphora(self):
3196
+    def test_get_all_deleted_expiring_amphora(self):
3179 3197
         exp_age = datetime.timedelta(seconds=self.FAKE_EXP_AGE)
3180 3198
         updated_at = datetime.datetime.utcnow() - exp_age
3181 3199
         amphora1 = self.create_amphora(
@@ -3183,9 +3201,8 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
3183 3201
         amphora2 = self.create_amphora(
3184 3202
             self.FAKE_UUID_2, status=constants.DELETED)
3185 3203
 
3186
-        expiring_list = self.amphora_repo.get_all_deleted_expiring(
3204
+        expiring_ids = self.amphora_repo.get_all_deleted_expiring(
3187 3205
             self.session, exp_age=exp_age)
3188
-        expiring_ids = [amp.id for amp in expiring_list]
3189 3206
         self.assertIn(amphora1.id, expiring_ids)
3190 3207
         self.assertNotIn(amphora2.id, expiring_ids)
3191 3208
 

+ 5
- 0
releasenotes/notes/fix-loadbalancer-db-cleanup-61ee81a4fd597067.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+fixes:
3
+  - |
4
+    Fix an issue that prevented the cleanup of load balancer entries in the
5
+    database by the Octavia housekeeper service.

Loading…
Cancel
Save