Browse Source

Fix misuse of nova.objects.base.obj_equal_prims

The nova.objects.base.obj_equal_prims returns True or False.
It does not assert anything.
So the return value should be asserted in tests.

Add assertTrue where the nova.objects.base.obj_equal_prims is called.

Change-Id: I49460ec3b572ee14b32229e771a5499ff91e8722
Closes-Bug: #1839853
(cherry picked from commit 5c1d9dcbb2)
(cherry picked from commit a8e19afb3d)
changes/90/676290/1
Takashi NATSUME 1 month ago
parent
commit
a17bb97b2e

+ 50
- 39
nova/tests/functional/db/test_build_request.py View File

@@ -62,13 +62,15 @@ class BuildRequestTestCase(test.NoDBTestCase):
62 62
             expected = getattr(expected_req, key)
63 63
             db_value = getattr(req_obj, key)
64 64
             if key == 'instance':
65
-                objects.base.obj_equal_prims(expected, db_value)
65
+                self.assertTrue(objects.base.obj_equal_prims(expected,
66
+                                                             db_value))
66 67
                 continue
67 68
             elif key in ('block_device_mappings', 'tags'):
68 69
                 self.assertEqual(1, len(db_value))
69 70
                 # Can't compare list objects directly, just compare the single
70 71
                 # item they contain.
71
-                objects.base.obj_equal_prims(expected[0], db_value[0])
72
+                self.assertTrue(objects.base.obj_equal_prims(expected[0],
73
+                                                             db_value[0]))
72 74
                 continue
73 75
             self.assertEqual(expected, db_value)
74 76
 
@@ -221,8 +223,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
221 223
         self.assertEqual(2, len(req_list))
222 224
         for i in range(len(req_list)):
223 225
             self.assertEqual(reqs[i].instance_uuid, req_list[i].instance_uuid)
224
-            objects.base.obj_equal_prims(reqs[i].instance,
225
-                                         req_list[i].instance)
226
+            self.assertTrue(objects.base.obj_equal_prims(reqs[i].instance,
227
+                                                         req_list[i].instance))
226 228
 
227 229
     def test_get_all_filter_by_project_id(self):
228 230
         reqs = [self._create_req(), self._create_req(project_id='filter')]
@@ -232,8 +234,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
232 234
         self.assertEqual(1, len(req_list))
233 235
         self.assertEqual(reqs[0].project_id, req_list[0].project_id)
234 236
         self.assertEqual(reqs[0].instance_uuid, req_list[0].instance_uuid)
235
-        objects.base.obj_equal_prims(reqs[0].instance,
236
-                                     req_list[0].instance)
237
+        self.assertTrue(objects.base.obj_equal_prims(reqs[0].instance,
238
+                                                     req_list[0].instance))
237 239
 
238 240
     def test_get_all_bypass_project_id_filter_as_admin(self):
239 241
         reqs = [self._create_req(), self._create_req(project_id='filter')]
@@ -245,8 +247,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
245 247
         for i in range(len(req_list)):
246 248
             self.assertEqual(reqs[i].project_id, req_list[i].project_id)
247 249
             self.assertEqual(reqs[i].instance_uuid, req_list[i].instance_uuid)
248
-            objects.base.obj_equal_prims(reqs[i].instance,
249
-                                         req_list[i].instance)
250
+            self.assertTrue(objects.base.obj_equal_prims(reqs[i].instance,
251
+                                                         req_list[i].instance))
250 252
 
251 253
     def test_get_by_filters(self):
252 254
         reqs = [self._create_req(), self._create_req()]
@@ -258,8 +260,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
258 260
         self.assertEqual(2, len(req_list))
259 261
         for i in range(len(req_list)):
260 262
             self.assertEqual(reqs[i].instance_uuid, req_list[i].instance_uuid)
261
-            objects.base.obj_equal_prims(reqs[i].instance,
262
-                                         req_list[i].instance)
263
+            self.assertTrue(objects.base.obj_equal_prims(reqs[i].instance,
264
+                                                         req_list[i].instance))
263 265
 
264 266
     def test_get_by_filters_limit_0(self):
265 267
         self._create_req()
@@ -302,8 +304,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
302 304
         self.assertIsInstance(req_list, objects.BuildRequestList)
303 305
         self.assertEqual(1, len(req_list))
304 306
         self.assertEqual(reqs[1].instance_uuid, req_list[0].instance_uuid)
305
-        objects.base.obj_equal_prims(reqs[1].instance,
306
-                                     req_list[0].instance)
307
+        self.assertTrue(objects.base.obj_equal_prims(reqs[1].instance,
308
+                                                     req_list[0].instance))
307 309
 
308 310
     def test_get_by_filters_exact_match_list(self):
309 311
         instance_find = fake_instance.fake_instance_obj(
@@ -322,8 +324,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
322 324
         self.assertIsInstance(req_list, objects.BuildRequestList)
323 325
         self.assertEqual(1, len(req_list))
324 326
         self.assertEqual(reqs[1].instance_uuid, req_list[0].instance_uuid)
325
-        objects.base.obj_equal_prims(reqs[1].instance,
326
-                                     req_list[0].instance)
327
+        self.assertTrue(objects.base.obj_equal_prims(reqs[1].instance,
328
+                                                     req_list[0].instance))
327 329
 
328 330
     def test_get_by_filters_exact_match_metadata(self):
329 331
         instance_find = fake_instance.fake_instance_obj(
@@ -342,8 +344,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
342 344
         self.assertIsInstance(req_list, objects.BuildRequestList)
343 345
         self.assertEqual(1, len(req_list))
344 346
         self.assertEqual(reqs[1].instance_uuid, req_list[0].instance_uuid)
345
-        objects.base.obj_equal_prims(reqs[1].instance,
346
-                                     req_list[0].instance)
347
+        self.assertTrue(objects.base.obj_equal_prims(reqs[1].instance,
348
+                                                     req_list[0].instance))
347 349
 
348 350
     def test_get_by_filters_exact_match_metadata_list(self):
349 351
         instance_find = fake_instance.fake_instance_obj(
@@ -364,8 +366,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
364 366
         self.assertIsInstance(req_list, objects.BuildRequestList)
365 367
         self.assertEqual(1, len(req_list))
366 368
         self.assertEqual(reqs[1].instance_uuid, req_list[0].instance_uuid)
367
-        objects.base.obj_equal_prims(reqs[1].instance,
368
-                                     req_list[0].instance)
369
+        self.assertTrue(objects.base.obj_equal_prims(reqs[1].instance,
370
+                                                     req_list[0].instance))
369 371
 
370 372
     def test_get_by_filters_regex_match_one(self):
371 373
         instance_find = fake_instance.fake_instance_obj(
@@ -384,8 +386,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
384 386
         self.assertIsInstance(req_list, objects.BuildRequestList)
385 387
         self.assertEqual(1, len(req_list))
386 388
         self.assertEqual(reqs[1].instance_uuid, req_list[0].instance_uuid)
387
-        objects.base.obj_equal_prims(reqs[1].instance,
388
-                                     req_list[0].instance)
389
+        self.assertTrue(objects.base.obj_equal_prims(reqs[1].instance,
390
+                                                     req_list[0].instance))
389 391
 
390 392
     def test_get_by_filters_regex_match_both(self):
391 393
         instance_find = fake_instance.fake_instance_obj(
@@ -406,8 +408,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
406 408
         self.assertEqual(2, len(req_list))
407 409
         for i in range(len(req_list)):
408 410
             self.assertEqual(reqs[i].instance_uuid, req_list[i].instance_uuid)
409
-            objects.base.obj_equal_prims(reqs[i].instance,
410
-                                         req_list[i].instance)
411
+            self.assertTrue(objects.base.obj_equal_prims(reqs[i].instance,
412
+                                                         req_list[i].instance))
411 413
 
412 414
     def test_get_by_filters_sort_asc(self):
413 415
         instance_1024 = fake_instance.fake_instance_obj(
@@ -426,10 +428,12 @@ class BuildRequestListTestCase(test.NoDBTestCase):
426 428
         self.assertIsInstance(req_list, objects.BuildRequestList)
427 429
         self.assertEqual(2, len(req_list))
428 430
         self.assertEqual(req_first.instance_uuid, req_list[0].instance_uuid)
429
-        objects.base.obj_equal_prims(req_first.instance, req_list[0].instance)
431
+        self.assertTrue(objects.base.obj_equal_prims(req_first.instance,
432
+                                                     req_list[0].instance))
430 433
 
431 434
         self.assertEqual(req_second.instance_uuid, req_list[1].instance_uuid)
432
-        objects.base.obj_equal_prims(req_second.instance, req_list[1].instance)
435
+        self.assertTrue(objects.base.obj_equal_prims(req_second.instance,
436
+                                                     req_list[1].instance))
433 437
 
434 438
     def test_get_by_filters_sort_desc(self):
435 439
         instance_1024 = fake_instance.fake_instance_obj(
@@ -448,10 +452,12 @@ class BuildRequestListTestCase(test.NoDBTestCase):
448 452
         self.assertIsInstance(req_list, objects.BuildRequestList)
449 453
         self.assertEqual(2, len(req_list))
450 454
         self.assertEqual(req_first.instance_uuid, req_list[0].instance_uuid)
451
-        objects.base.obj_equal_prims(req_first.instance, req_list[0].instance)
455
+        self.assertTrue(objects.base.obj_equal_prims(req_first.instance,
456
+                                                     req_list[0].instance))
452 457
 
453 458
         self.assertEqual(req_second.instance_uuid, req_list[1].instance_uuid)
454
-        objects.base.obj_equal_prims(req_second.instance, req_list[1].instance)
459
+        self.assertTrue(objects.base.obj_equal_prims(req_second.instance,
460
+                                                     req_list[1].instance))
455 461
 
456 462
     def test_get_by_filters_sort_build_req_id(self):
457 463
         # Create instance objects this way so that there is no 'id' set.
@@ -471,10 +477,12 @@ class BuildRequestListTestCase(test.NoDBTestCase):
471 477
         self.assertIsInstance(req_list, objects.BuildRequestList)
472 478
         self.assertEqual(2, len(req_list))
473 479
         self.assertEqual(req_first.instance_uuid, req_list[0].instance_uuid)
474
-        objects.base.obj_equal_prims(req_first.instance, req_list[0].instance)
480
+        self.assertTrue(objects.base.obj_equal_prims(req_first.instance,
481
+                                                     req_list[0].instance))
475 482
 
476 483
         self.assertEqual(req_second.instance_uuid, req_list[1].instance_uuid)
477
-        objects.base.obj_equal_prims(req_second.instance, req_list[1].instance)
484
+        self.assertTrue(objects.base.obj_equal_prims(req_second.instance,
485
+                                                     req_list[1].instance))
478 486
 
479 487
     def test_get_by_filters_multiple_sort_keys(self):
480 488
         instance_first = fake_instance.fake_instance_obj(
@@ -498,13 +506,16 @@ class BuildRequestListTestCase(test.NoDBTestCase):
498 506
         self.assertIsInstance(req_list, objects.BuildRequestList)
499 507
         self.assertEqual(3, len(req_list))
500 508
         self.assertEqual(req_first.instance_uuid, req_list[0].instance_uuid)
501
-        objects.base.obj_equal_prims(req_first.instance, req_list[0].instance)
509
+        self.assertTrue(objects.base.obj_equal_prims(req_first.instance,
510
+                                                     req_list[0].instance))
502 511
 
503 512
         self.assertEqual(req_second.instance_uuid, req_list[1].instance_uuid)
504
-        objects.base.obj_equal_prims(req_second.instance, req_list[1].instance)
513
+        self.assertTrue(objects.base.obj_equal_prims(req_second.instance,
514
+                                                     req_list[1].instance))
505 515
 
506 516
         self.assertEqual(req_third.instance_uuid, req_list[2].instance_uuid)
507
-        objects.base.obj_equal_prims(req_third.instance, req_list[2].instance)
517
+        self.assertTrue(objects.base.obj_equal_prims(req_third.instance,
518
+                                                     req_list[2].instance))
508 519
 
509 520
     def test_get_by_filters_marker(self):
510 521
         instance = fake_instance.fake_instance_obj(
@@ -526,8 +537,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
526 537
         # The returned build request should be the last one in the reqs list
527 538
         # since the marker is the 2nd item in the list (of 3).
528 539
         self.assertEqual(expected_req.instance_uuid, req.instance_uuid)
529
-        objects.base.obj_equal_prims(expected_req.instance,
530
-                                     req.instance)
540
+        self.assertTrue(objects.base.obj_equal_prims(expected_req.instance,
541
+                                                     req.instance))
531 542
 
532 543
     def test_get_by_filters_marker_not_found(self):
533 544
         self._create_req()
@@ -549,8 +560,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
549 560
         self.assertEqual(2, len(req_list))
550 561
         for i, req in enumerate(reqs[:2]):
551 562
             self.assertEqual(req.instance_uuid, req_list[i].instance_uuid)
552
-            objects.base.obj_equal_prims(req.instance,
553
-                                         req_list[i].instance)
563
+            self.assertTrue(objects.base.obj_equal_prims(req.instance,
564
+                                                         req_list[i].instance))
554 565
 
555 566
     def test_get_by_filters_marker_limit(self):
556 567
         instance = fake_instance.fake_instance_obj(
@@ -570,8 +581,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
570 581
         self.assertEqual(2, len(req_list))
571 582
         for i, req in enumerate(reqs[2:]):
572 583
             self.assertEqual(req.instance_uuid, req_list[i].instance_uuid)
573
-            objects.base.obj_equal_prims(req.instance,
574
-                                         req_list[i].instance)
584
+            self.assertTrue(objects.base.obj_equal_prims(req.instance,
585
+                                                         req_list[i].instance))
575 586
 
576 587
     def test_get_by_filters_marker_overlimit(self):
577 588
         instance = fake_instance.fake_instance_obj(
@@ -591,8 +602,8 @@ class BuildRequestListTestCase(test.NoDBTestCase):
591 602
         self.assertEqual(2, len(req_list))
592 603
         for i, req in enumerate(reqs[2:]):
593 604
             self.assertEqual(req.instance_uuid, req_list[i].instance_uuid)
594
-            objects.base.obj_equal_prims(req.instance,
595
-                                         req_list[i].instance)
605
+            self.assertTrue(objects.base.obj_equal_prims(req.instance,
606
+                                                         req_list[i].instance))
596 607
 
597 608
     def test_get_by_filters_bails_on_empty_list_check(self):
598 609
         instance1 = fake_instance.fake_instance_obj(

+ 3
- 2
nova/tests/unit/objects/test_build_request.py View File

@@ -185,8 +185,9 @@ class _TestBuildRequestObject(object):
185 185
                          len(build_request_obj.instance.tags))
186 186
         # Can't compare list objects directly, just compare the single
187 187
         # item they contain.
188
-        base.obj_equal_prims(build_request_obj.tags[0],
189
-                             build_request_obj.instance.tags[0])
188
+        self.assertTrue(base.obj_equal_prims(
189
+                            build_request_obj.tags[0],
190
+                            build_request_obj.instance.tags[0]))
190 191
 
191 192
 
192 193
 class TestBuildRequestObject(test_objects._LocalTest,

Loading…
Cancel
Save