summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-11-07 09:28:15 +0000
committerGerrit Code Review <review@openstack.org>2018-11-07 09:28:15 +0000
commit1090c62f080c157c999aa9d201bc7e6fa88b5419 (patch)
tree6bd013d87671427170ca7fa029602a4a4c9894cb
parentd5c54eab68ee8c594518cbab20fac6e1c238af2f (diff)
parent860ec66aca308120dd999c6e067aef3d92602b90 (diff)
Merge "(fix) Support node filter by rack name"
-rw-r--r--python/drydock_provisioner/objects/__init__.py7
-rw-r--r--python/drydock_provisioner/orchestrator/orchestrator.py32
-rw-r--r--python/tests/unit/test_orch_node_filter.py75
-rw-r--r--python/tests/yaml_samples/deckhand_fullsite.yaml2
4 files changed, 94 insertions, 22 deletions
diff --git a/python/drydock_provisioner/objects/__init__.py b/python/drydock_provisioner/objects/__init__.py
index a38464d..0555e56 100644
--- a/python/drydock_provisioner/objects/__init__.py
+++ b/python/drydock_provisioner/objects/__init__.py
@@ -102,11 +102,12 @@ class Utils(object):
102 try: 102 try:
103 # Probably should handle non-string values 103 # Probably should handle non-string values
104 effective_list.extend( 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 effective_list.extend( 107 effective_list.extend(
108 filter(lambda x: ("!" + x) not in child_list, 108 [x for x in parent_list
109 filter(lambda x: x not in effective_list, parent_list))) 109 if ("!" + x) not in child_list
110 and x not in effective_list])
110 except TypeError: 111 except TypeError:
111 raise TypeError("Error iterating list argument") 112 raise TypeError("Error iterating list argument")
112 113
diff --git a/python/drydock_provisioner/orchestrator/orchestrator.py b/python/drydock_provisioner/orchestrator/orchestrator.py
index 85e1834..473d1b8 100644
--- a/python/drydock_provisioner/orchestrator/orchestrator.py
+++ b/python/drydock_provisioner/orchestrator/orchestrator.py
@@ -472,25 +472,25 @@ class Orchestrator(object):
472 472
473 target_nodes = dict() 473 target_nodes = dict()
474 474
475 if node_names and len(node_names) > 0: 475 if node_names:
476 self.logger.debug("Filtering nodes based on node names.") 476 self.logger.debug("Filtering nodes based on node names.")
477 target_nodes['node_names'] = [ 477 target_nodes['node_names'] = [
478 x for x in node_set if x.get_name() in node_names 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 self.logger.debug("Filtering nodes based on node tags.") 482 self.logger.debug("Filtering nodes based on node tags.")
483 target_nodes['node_tags'] = [ 483 target_nodes['node_tags'] = [
484 x for x in node_set for t in node_tags if x.has_tag(t) 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 self.logger.debug("Filtering nodes based on rack names.") 488 self.logger.debug("Filtering nodes based on rack names.")
489 target_nodes['rack_names'] = [ 489 target_nodes['rack_names'] = [
490 x for x in node_set if x.get_rack() in rack_names 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 self.logger.debug("Filtering nodes based on node labels.") 494 self.logger.debug("Filtering nodes based on node labels.")
495 target_nodes['node_labels'] = [] 495 target_nodes['node_labels'] = []
496 for k, v in node_labels.items(): 496 for k, v in node_labels.items():
@@ -499,7 +499,7 @@ class Orchestrator(object):
499 if getattr(x, 'owner_data', {}).get(k, None) == v 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 self.logger.info( 503 self.logger.info(
504 "Rack label filtering not yet implemented, returning all nodes." 504 "Rack label filtering not yet implemented, returning all nodes."
505 ) 505 )
@@ -531,21 +531,17 @@ class Orchestrator(object):
531 """ 531 """
532 if len(rest) > 1: 532 if len(rest) > 1:
533 result = self.list_intersection(rest[0], *rest[1:]) 533 result = self.list_intersection(rest[0], *rest[1:])
534 if a is None: 534 elif rest:
535 return result 535 result = rest[0]
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])))
547 else: 536 else:
537 result = None
538
539 if a is None:
540 return result
541 elif result is None:
548 return a 542 return a
543 else:
544 return list(set(a).intersection(set(result)))
549 545
550 def list_union(self, *lists): 546 def list_union(self, *lists):
551 """Return a unique-ified union of all the lists. 547 """Return a unique-ified union of all the lists.
diff --git a/python/tests/unit/test_orch_node_filter.py b/python/tests/unit/test_orch_node_filter.py
index 932c31d..7cc236a 100644
--- a/python/tests/unit/test_orch_node_filter.py
+++ b/python/tests/unit/test_orch_node_filter.py
@@ -54,7 +54,80 @@ class TestClass(object):
54 'filter_set': [ 54 'filter_set': [
55 { 55 {
56 'filter_type': 'intersection', 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 }
diff --git a/python/tests/yaml_samples/deckhand_fullsite.yaml b/python/tests/yaml_samples/deckhand_fullsite.yaml
index a8f6b06..5a74a3c 100644
--- a/python/tests/yaml_samples/deckhand_fullsite.yaml
+++ b/python/tests/yaml_samples/deckhand_fullsite.yaml
@@ -391,6 +391,8 @@ data:
391 address: 172.16.100.23 391 address: 172.16.100.23
392 metadata: 392 metadata:
393 rack: rack3 393 rack: rack3
394 owner_data:
395 foo: baz
394--- 396---
395schema: 'drydock/HardwareProfile/v1' 397schema: 'drydock/HardwareProfile/v1'
396metadata: 398metadata: