Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3784345
D1420.id3623.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D1420.id3623.diff
View Options
diff --git a/_modules/node.py b/_modules/node.py
--- a/_modules/node.py
+++ b/_modules/node.py
@@ -125,6 +125,9 @@
- keys are role to check the current node against
- values are list of items
+ If a key '*' is also present, it will be included
+ for every role.
+
Returns a list, extending all the filtered lists.
CLI Example:
@@ -136,7 +139,7 @@
filtered_list = []
for role, items in dictionary.items():
- if role in roles:
+ if role == '*' or role in roles:
filtered_list.extend(items)
return filtered_list
diff --git a/_tests/data/forests.yaml b/_tests/data/forests.yaml
--- a/_tests/data/forests.yaml
+++ b/_tests/data/forests.yaml
@@ -21,6 +21,14 @@
border:
- Onodlo
+items_by_role_with_star:
+ '*':
+ - Air
+ treecity:
+ - Caras Galadhon
+ border:
+ - Onodlo
+
shellgroups_ubiquity:
- ubiquity
diff --git a/_tests/modules/test_node.py b/_tests/modules/test_node.py
--- a/_tests/modules/test_node.py
+++ b/_tests/modules/test_node.py
@@ -52,3 +52,30 @@
]
self.assertEqual(['Caras Galadhon', 'Onodlo'],
sorted(node.filter_by_role('items_by_role')))
+
+ def test_filter_by_role_with_star(self):
+ node_key = self.grains['id']
+
+ self.assertEqual(['Air', 'Caras Galadhon'],
+ node.filter_by_role('items_by_role_with_star'))
+
+ self.assertEqual(['Air', 'Onodlo'],
+ node.filter_by_role(
+ 'items_by_role_with_star',
+ 'entwash'
+ ))
+
+ # No role
+ self.pillar['nodes'][node_key]['roles'] = []
+ self.assertEqual(['Air'],
+ node.filter_by_role('items_by_role_with_star'))
+
+ # More than one role
+ self.pillar['nodes'][node_key]['roles'] = [
+ 'border',
+ 'treecity'
+ ]
+ self.assertEqual(
+ ['Air', 'Caras Galadhon', 'Onodlo'],
+ sorted(node.filter_by_role('items_by_role_with_star'))
+ )
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 05:38 (21 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2265820
Default Alt Text
D1420.id3623.diff (2 KB)
Attached To
Mode
D1420: Allow a '*' key for node.filter_by_role
Attached
Detach File
Event Timeline
Log In to Comment