Page MenuHomeDevCentral

D1420.id3622.diff
No OneTemporary

D1420.id3622.diff

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

Mime Type
text/plain
Expires
Wed, Nov 27, 05:29 (21 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2265820
Default Alt Text
D1420.id3622.diff (2 KB)

Event Timeline