Esempio n. 1
0
 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))
Esempio n. 2
0
 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))
Esempio n. 3
0
 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))
Esempio n. 4
0
 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))
Esempio n. 5
0
 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))
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)
Esempio n. 8
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')
Esempio n. 9
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'])
     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)
Esempio n. 10
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')
Esempio n. 11
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)
Esempio n. 12
0
    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)
Esempio n. 13
0
    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)
Esempio n. 14
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)
Esempio n. 15
0
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)
Esempio n. 16
0
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)
Esempio n. 17
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"
     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)
Esempio n. 18
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)
Esempio n. 19
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"
     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)
Esempio n. 20
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)
Esempio n. 21
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)
Esempio n. 22
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)
Esempio n. 23
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)
Esempio n. 24
0
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))
Esempio n. 25
0
 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'])
Esempio n. 26
0
 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'])
Esempio n. 27
0
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))