Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Find nodes with recipe now looks in the expanded run_list

  • Loading branch information...
commit 772a6b00377ce341c321950085c3bcfa6dbf0b60 1 parent 7c2b8d2
@tobami authored
Showing with 20 additions and 13 deletions.
  1. +1 −1  littlechef/lib.py
  2. +1 −2  tests/roles/base.json
  3. +18 −10 tests/test_lib.py
View
2  littlechef/lib.py
@@ -89,7 +89,7 @@ def get_nodes_with_recipe(recipe_name, environment=None):
recipe_name = recipe_name.rstrip("*")
for n in get_nodes(environment):
recipes = get_recipes_in_node(n)
- for role in get_roles_in_node(n):
+ for role in get_roles_in_node(n, recursive=True):
recipes.extend(get_recipes_in_role(role))
if prefix_search:
if any(recipe.startswith(recipe_name) for recipe in recipes):
View
3  tests/roles/base.json
@@ -6,7 +6,6 @@
"description": "An example aplication role than needs the subversion recipe",
"chef_type": "role",
"run_list": [
- "recipe[subversion]",
- "recipe[vim]"
+ "recipe[subversion]"
]
}
View
28 tests/test_lib.py
@@ -151,7 +151,7 @@ def test_nodes_with_role_expanded(self):
self.assertTrue(nodes[0]['name'], 'nestedroles1')
def test_nodes_with_role_wildcard(self):
- """Should return nodes when wildcard is given and role is asigned"""
+ """Should return node when wildcard is given and role is asigned"""
nodes = list(lib.get_nodes_with_role('all_*'))
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0]['name'], 'testnode2')
@@ -166,7 +166,7 @@ def test_nodes_with_role_wildcard(self):
self.assertEqual(len(nodes), 0)
def test_nodes_with_role_in_env(self):
- """Should return all nodes with a given role and in the given env"""
+ """Should return node when role is asigned and environment matches"""
nodes = list(lib.get_nodes_with_role('all_you_can_eat', 'staging'))
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0]['name'], 'testnode2')
@@ -175,22 +175,30 @@ def test_nodes_with_role_in_env(self):
self.assertFalse(len(nodes))
def test_nodes_with_recipe(self):
- """Should return all nodes with a given recipe"""
- # All nodes have the subversion recipe in the expanded run_list
- nodes = list(lib.get_nodes_with_recipe('subversion'))
- self.assertEqual(len(nodes), 3)
- nodes = list(lib.get_nodes_with_recipe('sub*'))
- self.assertEqual(len(nodes), 3)
+ """Should return node when recipe is in the explicit run_list"""
nodes = list(lib.get_nodes_with_recipe('vim'))
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0]['name'], 'testnode3.mydomain.com')
+
+ def test_nodes_with_recipe_expanded(self):
+ """Should return node when recipe is in the expanded run_list"""
+ # 'subversion' is in the 'base' role
+ nodes = list(lib.get_nodes_with_recipe('subversion'))
+ self.assertEqual(len(nodes), 4)
+
# man recipe inside role "all_you_can_eat" and in testnode4
nodes = list(lib.get_nodes_with_recipe('man'))
self.assertEqual(len(nodes), 2)
self.assertEqual(nodes[0]['name'], 'testnode2')
+
+ def test_nodes_with_recipe_wildcard(self):
+ """Should return node when wildcard is given and role is asigned"""
+ nodes = list(lib.get_nodes_with_recipe('sub*'))
+ self.assertEqual(len(nodes), 4)
+
# Get node with at least one recipe
nodes = list(lib.get_nodes_with_recipe('*'))
- self.assertEqual(len(nodes), 4)
+ self.assertEqual(len(nodes), 5)
nodes = list(lib.get_nodes_with_role(''))
self.assertEqual(len(nodes), 0)
@@ -281,7 +289,7 @@ def test_build_node_data_bag(self):
data = json.loads(f.read())
self.assertTrue('id' in data and data['id'] == 'testnode2')
self.assertTrue('recipes' in data)
- self.assertEqual(data['recipes'], [u'subversion', u'man', u'vim'])
+ self.assertEqual(data['recipes'], [u'subversion', u'man'])
self.assertTrue('recipes' in data)
self.assertEqual(data['role'], [u'all_you_can_eat'])
self.assertEqual(data['roles'], [u'base', u'all_you_can_eat'])
Please sign in to comment.
Something went wrong with that request. Please try again.