Browse Source

Merge "Fix bug in recordset status"

changes/30/681130/1
Zuul 1 week ago
parent
commit
9fb598b7d1

+ 10
- 6
designate/objects/recordset.py View File

@@ -69,14 +69,18 @@ class RecordSet(base.DesignateObject, base.DictObjectMixin,
69 69
 
70 70
     @property
71 71
     def status(self):
72
-        # Return the worst status in order of ERROR, PENDING, ACTIVE
73
-        status = 'ACTIVE'
72
+        # Return the worst status in order of ERROR, PENDING, ACTIVE, DELETED.
73
+        status = None
74
+        statuses = {
75
+            'ERROR': 0,
76
+            'PENDING': 1,
77
+            'ACTIVE': 2,
78
+            'DELETED': 3,
79
+        }
74 80
         for record in self.records:
75
-            if (record.status == 'ERROR') or \
76
-                    (record.status == 'PENDING' and status != 'ERROR') or \
77
-                    (status != 'PENDING'):
81
+            if not status or statuses[record.status] < statuses[status]:
78 82
                 status = record.status
79
-        return status
83
+        return status or 'ACTIVE'
80 84
 
81 85
     fields = {
82 86
         'shard': fields.IntegerFields(nullable=True, minimum=0, maximum=4095),

+ 54
- 4
designate/tests/unit/objects/test_recordset.py View File

@@ -14,7 +14,6 @@
14 14
 # License for the specific language governing permissions and limitations
15 15
 # under the License.
16 16
 import itertools
17
-import unittest
18 17
 
19 18
 import mock
20 19
 import oslotest.base
@@ -111,16 +110,16 @@ class RecordSetTest(oslotest.base.BaseTestCase):
111 110
         )
112 111
         self.assertEqual('DELETE', record_set.action)
113 112
 
114
-    @unittest.expectedFailure  # bug
115 113
     def test_status_error(self):
116
-        statuses = ('ERROR', 'PENDING', 'ACTIVE')
117
-        for s1, s2, s3 in itertools.permutations(statuses):
114
+        statuses = ('ERROR', 'PENDING', 'ACTIVE', 'DELETED')
115
+        for s1, s2, s3, s4 in itertools.permutations(statuses):
118 116
             record_set = objects.RecordSet(
119 117
                 name='www.example.org.', type='A',
120 118
                 records=objects.RecordList(objects=[
121 119
                     objects.Record(data='192.0.2.1', status=s1),
122 120
                     objects.Record(data='192.0.2.2', status=s2),
123 121
                     objects.Record(data='192.0.2.3', status=s3),
122
+                    objects.Record(data='192.0.2.4', status=s4),
124 123
                 ])
125 124
             )
126 125
             self.assertEqual(record_set.status, 'ERROR')
@@ -163,6 +162,57 @@ class RecordSetTest(oslotest.base.BaseTestCase):
163 162
         )
164 163
         self.assertEqual('DELETED', record_set.status)
165 164
 
165
+    def test_status_many_expect_error(self):
166
+        rs = objects.RecordSet(
167
+            name='www.example.org.', type='A',
168
+            records=objects.RecordList(objects=[
169
+                objects.Record(data='192.0.2.2', status='ACTIVE'),
170
+                objects.Record(data='192.0.2.3', status='DELETED'),
171
+                objects.Record(data='192.0.2.4', status='DELETED'),
172
+                objects.Record(data='192.0.2.5', status='DELETED'),
173
+                objects.Record(data='192.0.2.6', status='ACTIVE'),
174
+                objects.Record(data='192.0.2.7', status='ACTIVE'),
175
+                objects.Record(data='192.0.2.8', status='ERROR'),
176
+                objects.Record(data='192.0.2.9', status='ACTIVE'),
177
+                objects.Record(data='192.0.2.10', status='ACTIVE'),
178
+            ])
179
+        )
180
+        self.assertEqual('ERROR', rs.status)
181
+
182
+    def test_status_many_expect_pending(self):
183
+        rs = objects.RecordSet(
184
+            name='www.example.org.', type='A',
185
+            records=objects.RecordList(objects=[
186
+                objects.Record(data='192.0.2.2', status='ACTIVE'),
187
+                objects.Record(data='192.0.2.3', status='DELETED'),
188
+                objects.Record(data='192.0.2.4', status='PENDING'),
189
+                objects.Record(data='192.0.2.5', status='DELETED'),
190
+                objects.Record(data='192.0.2.6', status='PENDING'),
191
+                objects.Record(data='192.0.2.7', status='ACTIVE'),
192
+                objects.Record(data='192.0.2.8', status='DELETED'),
193
+                objects.Record(data='192.0.2.9', status='PENDING'),
194
+                objects.Record(data='192.0.2.10', status='ACTIVE'),
195
+            ])
196
+        )
197
+        self.assertEqual('PENDING', rs.status)
198
+
199
+    def test_status_many_expect_active(self):
200
+        rs = objects.RecordSet(
201
+            name='www.example.org.', type='A',
202
+            records=objects.RecordList(objects=[
203
+                objects.Record(data='192.0.2.2', status='ACTIVE'),
204
+                objects.Record(data='192.0.2.3', status='DELETED'),
205
+                objects.Record(data='192.0.2.4', status='DELETED'),
206
+                objects.Record(data='192.0.2.5', status='DELETED'),
207
+                objects.Record(data='192.0.2.6', status='ACTIVE'),
208
+                objects.Record(data='192.0.2.7', status='ACTIVE'),
209
+                objects.Record(data='192.0.2.8', status='DELETED'),
210
+                objects.Record(data='192.0.2.9', status='ACTIVE'),
211
+                objects.Record(data='192.0.2.10', status='ACTIVE'),
212
+            ])
213
+        )
214
+        self.assertEqual('ACTIVE', rs.status)
215
+
166 216
     def test_validate(self):
167 217
         record_set = create_test_recordset()
168 218
         record_set.validate()

+ 13
- 0
releasenotes/notes/fix-recordset-status-204e2747ef47d5ad.yaml View File

@@ -0,0 +1,13 @@
1
+---
2
+fixes:
3
+  - |
4
+    Fixed a bug with the recordset status implementation to make it report
5
+    its status more accurately.
6
+
7
+    A recordset will now always report its highest priority state when it
8
+    contains multiple records. The order of priority is,
9
+    `ERROR`, `PENDING`, `ACTIVE` and `DELETED`.
10
+
11
+    See `bug 1842994`_ for more information.
12
+
13
+    .. _bug 1842994: https://bugs.launchpad.net/designate/+bug/1842994

Loading…
Cancel
Save