Browse Source

Merge "(fix) Support node filter by rack name"

Zuul 5 months ago
parent
commit
1090c62f08

+ 4
- 3
python/drydock_provisioner/objects/__init__.py View File

@@ -102,11 +102,12 @@ class Utils(object):
102 102
         try:
103 103
             # Probably should handle non-string values
104 104
             effective_list.extend(
105
-                filter(lambda x: not x.startswith("!"), child_list))
105
+                [x for x in child_list if not x.startswith("!")])
106 106
 
107 107
             effective_list.extend(
108
-                filter(lambda x: ("!" + x) not in child_list,
109
-                       filter(lambda x: x not in effective_list, parent_list)))
108
+                [x for x in parent_list
109
+                 if ("!" + x) not in child_list
110
+                 and x not in effective_list])
110 111
         except TypeError:
111 112
             raise TypeError("Error iterating list argument")
112 113
 

+ 14
- 18
python/drydock_provisioner/orchestrator/orchestrator.py View File

@@ -472,25 +472,25 @@ class Orchestrator(object):
472 472
 
473 473
             target_nodes = dict()
474 474
 
475
-            if node_names and len(node_names) > 0:
475
+            if node_names:
476 476
                 self.logger.debug("Filtering nodes based on node names.")
477 477
                 target_nodes['node_names'] = [
478 478
                     x for x in node_set if x.get_name() in node_names
479 479
                 ]
480 480
 
481
-            if node_tags and len(node_tags) > 0:
481
+            if node_tags:
482 482
                 self.logger.debug("Filtering nodes based on node tags.")
483 483
                 target_nodes['node_tags'] = [
484 484
                     x for x in node_set for t in node_tags if x.has_tag(t)
485 485
                 ]
486 486
 
487
-            if rack_names and len(rack_names) > 0:
487
+            if rack_names:
488 488
                 self.logger.debug("Filtering nodes based on rack names.")
489 489
                 target_nodes['rack_names'] = [
490 490
                     x for x in node_set if x.get_rack() in rack_names
491 491
                 ]
492 492
 
493
-            if node_labels and len(node_labels) > 0:
493
+            if node_labels:
494 494
                 self.logger.debug("Filtering nodes based on node labels.")
495 495
                 target_nodes['node_labels'] = []
496 496
                 for k, v in node_labels.items():
@@ -499,7 +499,7 @@ class Orchestrator(object):
499 499
                         if getattr(x, 'owner_data', {}).get(k, None) == v
500 500
                     ])
501 501
 
502
-            if rack_labels and len(rack_labels) > 0:
502
+            if rack_labels:
503 503
                 self.logger.info(
504 504
                     "Rack label filtering not yet implemented, returning all nodes."
505 505
                 )
@@ -531,21 +531,17 @@ class Orchestrator(object):
531 531
         """
532 532
         if len(rest) > 1:
533 533
             result = self.list_intersection(rest[0], *rest[1:])
534
-            if a is None:
535
-                return result
536
-            elif result is None:
537
-                return a
538
-            else:
539
-                return list(set(a).intersection(set(result)))
540
-        elif len(rest) == 1:
541
-            if a is None and rest[0] is None:
542
-                return None
543
-            elif rest is None or rest[0]:
544
-                return a
545
-            else:
546
-                return list(set(a).intersection(set(rest[0])))
534
+        elif rest:
535
+            result = rest[0]
547 536
         else:
537
+            result = None
538
+
539
+        if a is None:
540
+            return result
541
+        elif result is None:
548 542
             return a
543
+        else:
544
+            return list(set(a).intersection(set(result)))
549 545
 
550 546
     def list_union(self, *lists):
551 547
         """Return a unique-ified union of all the lists.

+ 74
- 1
python/tests/unit/test_orch_node_filter.py View File

@@ -54,7 +54,80 @@ class TestClass(object):
54 54
             'filter_set': [
55 55
                 {
56 56
                     'filter_type': 'intersection',
57
-                    'node_names': 'compute01',
57
+                    'node_names': ['compute01'],
58
+                },
59
+            ],
60
+        }
61
+
62
+        node_list = deckhand_orchestrator.process_node_filter(nfs, design_data)
63
+
64
+        assert len(node_list) == 1
65
+
66
+    def test_node_filter_by_rackname(self, input_files, setup, deckhand_orchestrator,
67
+                                     deckhand_ingester):
68
+        input_file = input_files.join("deckhand_fullsite.yaml")
69
+
70
+        design_state = DrydockState()
71
+        design_ref = "file://%s" % str(input_file)
72
+
73
+        design_status, design_data = deckhand_ingester.ingest_data(
74
+            design_state=design_state, design_ref=design_ref)
75
+
76
+        nfs = {
77
+            'filter_set_type':
78
+            'intersection',
79
+            'filter_set': [
80
+                {
81
+                    'filter_type': 'intersection',
82
+                    'rack_names': ['rack2', 'rack3'],
83
+                },
84
+            ],
85
+        }
86
+
87
+        node_list = deckhand_orchestrator.process_node_filter(nfs, design_data)
88
+
89
+        assert len(node_list) == 2
90
+
91
+    def test_node_filter_by_nodetag(self, input_files, setup, deckhand_orchestrator,
92
+                                    deckhand_ingester):
93
+        input_file = input_files.join("deckhand_fullsite.yaml")
94
+
95
+        design_ref = "file://%s" % str(input_file)
96
+
97
+        design_status, design_data = deckhand_orchestrator.get_effective_site(design_ref)
98
+
99
+        nfs = {
100
+            'filter_set_type':
101
+            'intersection',
102
+            'filter_set': [
103
+                {
104
+                    'filter_type': 'intersection',
105
+                    'node_tags': ['test']
106
+                },
107
+            ],
108
+        }
109
+
110
+        node_list = deckhand_orchestrator.process_node_filter(nfs, design_data)
111
+
112
+        assert len(node_list) == 3
113
+
114
+    def test_node_filter_by_nodelabel(self, input_files, setup, deckhand_orchestrator,
115
+                                      deckhand_ingester):
116
+        input_file = input_files.join("deckhand_fullsite.yaml")
117
+
118
+        design_state = DrydockState()
119
+        design_ref = "file://%s" % str(input_file)
120
+
121
+        design_status, design_data = deckhand_ingester.ingest_data(
122
+            design_state=design_state, design_ref=design_ref)
123
+
124
+        nfs = {
125
+            'filter_set_type':
126
+            'intersection',
127
+            'filter_set': [
128
+                {
129
+                    'filter_type': 'intersection',
130
+                    'node_labels': {'foo': 'baz'},
58 131
                 },
59 132
             ],
60 133
         }

+ 2
- 0
python/tests/yaml_samples/deckhand_fullsite.yaml View File

@@ -391,6 +391,8 @@ data:
391 391
       address: 172.16.100.23
392 392
   metadata:
393 393
     rack: rack3
394
+    owner_data:
395
+      foo: baz
394 396
 ---
395 397
 schema: 'drydock/HardwareProfile/v1'
396 398
 metadata:

Loading…
Cancel
Save