def test_nodes_with_role_in_env(self): """Should return all nodes with a given role and in the given env""" nodes = list(lib.get_nodes_with_role("all_you_can_eat", "staging")) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]["name"], "testnode2") # No nodes in production with this role nodes = list(lib.get_nodes_with_role("all_you_can_eat", "production")) self.assertFalse(len(nodes))
def test_nodes_with_role_in_env(self): """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') # No nodes in production with this role nodes = list(lib.get_nodes_with_role('all_you_can_eat', 'production')) self.assertFalse(len(nodes))
def test_nodes_with_role_in_env(self): """Should return all nodes with a given role and in the given env""" nodes = list(lib.get_nodes_with_role('all_you_can_eat', 'staging')) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]['name'], 'testnode2') # No nodes in production with this role nodes = list(lib.get_nodes_with_role('all_you_can_eat', 'production')) self.assertFalse(len(nodes))
def test_nodes_with_role_wildcard(self): """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') # Prefix with no wildcard nodes = list(lib.get_nodes_with_role('all_')) self.assertEqual(len(nodes), 0) # Nodes with at least one role nodes = list(lib.get_nodes_with_role('*')) self.assertEqual(len(nodes), 2) nodes = list(lib.get_nodes_with_role('')) self.assertEqual(len(nodes), 0)
def test_nodes_with_role_expanded(self): """Should return nodes when role is present in the expanded run_list""" # nested role 'base' nodes = list(lib.get_nodes_with_role('base')) self.assertEqual(len(nodes), 2) expected_nodes = ['nestedroles1', 'testnode2'] for node in nodes: self.assertTrue(node['name'] in expected_nodes) expected_nodes.remove(node['name']) # Find node regardless of recursion level of role sought for role in ['top_level_role', 'sub_role', 'sub_sub_role']: nodes = list(lib.get_nodes_with_role(role)) self.assertEqual(len(nodes), 1) self.assertTrue(nodes[0]['name'], 'nestedroles1')
def test_nodes_with_role(self): """Should return all nodes with a given role in their run_list""" nodes = list(lib.get_nodes_with_role('all_you_can_eat')) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]['name'], 'testnode2') self.assertTrue('role[all_you_can_eat]' in nodes[0]['run_list']) nodes = list(lib.get_nodes_with_role('all_*')) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]['name'], 'testnode2') nodes = list(lib.get_nodes_with_role('all_')) self.assertEquals(len(nodes), 0) nodes = list(lib.get_nodes_with_role('*')) self.assertEquals(len(nodes), 1) nodes = list(lib.get_nodes_with_role('')) self.assertEquals(len(nodes), 0)
def nodes_with_role(rolename): """Configures a list of nodes that have the given role in their run list""" nodes = [n['name'] for n in lib.get_nodes_with_role(rolename, env.chef_environment)] if not len(nodes): print("No nodes found with role '{0}'".format(rolename)) sys.exit(0) return node(*nodes)
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), 5) nodes = list(lib.get_nodes_with_role('')) self.assertEqual(len(nodes), 0)
def nodes_with_role(rolename): """Configures a list of nodes that have the given role in their run list""" nodes = [ n['name'] for n in lib.get_nodes_with_role(rolename, env.chef_environment) ] if not len(nodes): print("No nodes found with role '{0}'".format(rolename)) sys.exit(0) return node(*nodes)
def nodes_with_role(rolename): """Sets a list of nodes that contain the given role in their run list and calls node() """ nodes_in_env = [] nodes = lib.get_nodes_with_role(rolename) if env.chef_environment is None: # Pass all nodes nodes_in_env = [n["name"] for n in nodes] else: # Only nodes in environment nodes_in_env = [n["name"] for n in nodes if n.get("chef_environment") == env.chef_environment] if not len(nodes_in_env): print ("No nodes found with role '{0}'".format(rolename)) sys.exit(0) return node(*nodes_in_env)
def nodes_with_role(rolename): """Sets a list of nodes that have the given role in their run list and calls node() """ nodes_in_env = [] nodes = lib.get_nodes_with_role(rolename) if env.chef_environment is None: # Pass all nodes nodes_in_env = [n['name'] for n in nodes] else: # Only nodes in environment nodes_in_env = [n['name'] for n in nodes \ if n.get('chef_environment') == env.chef_environment] if not len(nodes_in_env): print("No nodes found with role '{0}'".format(rolename)) sys.exit(0) return node(*nodes_in_env)
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.assertEquals(len(nodes), 3) nodes = list(lib.get_nodes_with_recipe('sub*')) self.assertEquals(len(nodes), 3) nodes = list(lib.get_nodes_with_recipe('vim')) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]['name'], 'testnode3.mydomain.com') # man recipe inside role "all_you_can_eat" nodes = list(lib.get_nodes_with_recipe('man')) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]['name'], 'testnode2') # Get node with at least one recipe nodes = list(lib.get_nodes_with_recipe('*')) self.assertEquals(len(nodes), 3) nodes = list(lib.get_nodes_with_role('')) self.assertEquals(len(nodes), 0)
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.assertEquals(len(nodes), 3) nodes = list(lib.get_nodes_with_recipe("sub*")) self.assertEquals(len(nodes), 3) nodes = list(lib.get_nodes_with_recipe("vim")) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]["name"], "testnode3.mydomain.com") # man recipe inside role "all_you_can_eat" and in testnode4 nodes = list(lib.get_nodes_with_recipe("man")) self.assertEquals(len(nodes), 2) self.assertEquals(nodes[0]["name"], "testnode2") # Get node with at least one recipe nodes = list(lib.get_nodes_with_recipe("*")) self.assertEquals(len(nodes), 4) nodes = list(lib.get_nodes_with_role("")) self.assertEquals(len(nodes), 0)
def test_nodes_with_role(self): """Should return all nodes with a given role in their run_list""" nodes = list(lib.get_nodes_with_role('all_you_can_eat')) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]['name'], 'testnode2') self.assertTrue('role[all_you_can_eat]' in nodes[0]['run_list']) # nested role 'base' nodes = list(lib.get_nodes_with_role('base')) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]['name'], 'testnode2') # Wild card nodes = list(lib.get_nodes_with_role('all_*')) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]['name'], 'testnode2') # Prefix with no wildcard nodes = list(lib.get_nodes_with_role('all_')) self.assertEquals(len(nodes), 0) # Nodes with at least one role nodes = list(lib.get_nodes_with_role('*')) self.assertEquals(len(nodes), 1) nodes = list(lib.get_nodes_with_role('')) self.assertEquals(len(nodes), 0)
def test_nodes_with_role(self): """Should return all nodes with a given role in their run_list""" nodes = list(lib.get_nodes_with_role("all_you_can_eat")) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]["name"], "testnode2") self.assertTrue("role[all_you_can_eat]" in nodes[0]["run_list"]) # nested role 'base' nodes = list(lib.get_nodes_with_role("base")) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]["name"], "testnode2") # Wild card nodes = list(lib.get_nodes_with_role("all_*")) self.assertEquals(len(nodes), 1) self.assertEquals(nodes[0]["name"], "testnode2") # Prefix with no wildcard nodes = list(lib.get_nodes_with_role("all_")) self.assertEquals(len(nodes), 0) # Nodes with at least one role nodes = list(lib.get_nodes_with_role("*")) self.assertEquals(len(nodes), 1) nodes = list(lib.get_nodes_with_role("")) self.assertEquals(len(nodes), 0)
def list_nodes_with_role(role): """Show all nodes which have asigned a given role""" for node in lib.get_nodes_with_role(role): lib.print_node(node)
def list_nodes_with_role(role): """Show all nodes which have asigned a given role""" lib.print_nodes(lib.get_nodes_with_role(role, env.chef_environment))
def test_nodes_with_role(self): """Should return nodes when role is present in the explicit run_list""" nodes = list(lib.get_nodes_with_role('all_you_can_eat')) self.assertEqual(len(nodes), 1) self.assertEqual(nodes[0]['name'], 'testnode2') self.assertTrue('role[all_you_can_eat]' in nodes[0]['run_list'])