def test_attribute_merge_cookbook_default(self): """Should have the value found in recipe/attributes/default.rb""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode2.json') with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('subversion' in data) self.assertTrue(data['subversion']['repo_name'] == 'repo')
def test_attribute_merge_role_override(self): """Should have the value found in the roles override attributes""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode2.json') with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('subversion' in data) self.assertEquals(data['subversion']['password'], 'role_override_pass')
def test_attribute_merge_cookbook_boolean(self): """Should have real boolean values for default cookbook attributes""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode3_mydomain_com.json') with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('vim' in data) self.assertTrue(data['vim']['sucks'] is True)
def test_attribute_merge_node_normal(self): """Should have the value found in the node attributes""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode2.json') with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('subversion' in data) self.assertTrue(data['subversion']['user'] == 'node_user')
def test_attribute_merge_role_override(self): """Should have the value found in the roles override attributes""" chef._build_node_data_bag() item_path = os.path.join("data_bags", "node", "testnode2.json") with open(item_path, "r") as f: data = json.loads(f.read()) self.assertTrue("subversion" in data) self.assertEquals(data["subversion"]["password"], "role_override_pass")
def test_attribute_merge_cookbook_boolean(self): """Should have real boolean values for default cookbook attributes""" chef._build_node_data_bag() item_path = os.path.join("data_bags", "node", "testnode3_mydomain_com.json") with open(item_path, "r") as f: data = json.loads(f.read()) self.assertTrue("vim" in data) self.assertTrue(data["vim"]["sucks"] is True)
def test_attribute_merge_cookbook_default(self): """Should have the value found in recipe/attributes/default.rb""" chef._build_node_data_bag() item_path = os.path.join("data_bags", "node", "testnode2.json") with open(item_path, "r") as f: data = json.loads(f.read()) self.assertTrue("subversion" in data) self.assertTrue(data["subversion"]["repo_name"] == "repo")
def test_attribute_merge_role_default(self): """Should have the value found in the roles default attributes""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode2.json') with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('subversion' in data) self.assertEquals(data['subversion']['repo_server'], 'role_default_repo_server') self.assertTrue('other_attr' in data) self.assertEquals(data['other_attr']['other_key'], 'nada')
def test_attribute_merge_deep_dict(self): """Should deep-merge a dict when it is defined in two different places """ chef._build_node_data_bag() item_path = os.path.join("data_bags", "node", "testnode2.json") with open(item_path, "r") as f: data = json.loads(f.read()) self.assertTrue("other_attr" in data) expected = {"deep_dict": {"deep_key1": "node_value1", "deep_key2": "role_value2"}} self.assertTrue(data["other_attr"]["deep_dict"], expected)
def test_attribute_merge_role_default(self): """Should have the value found in the roles default attributes""" chef._build_node_data_bag() item_path = os.path.join("data_bags", "node", "testnode2.json") with open(item_path, "r") as f: data = json.loads(f.read()) self.assertTrue("subversion" in data) self.assertEquals(data["subversion"]["repo_server"], "role_default_repo_server") self.assertTrue("other_attr" in data) self.assertEquals(data["other_attr"]["other_key"], "nada")
def test_build_node_data_bag_nonalphanumeric(self): """Should create a node data bag when node name contains non-alphanumerical characters""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode3.json') self.assertTrue(os.path.exists(item_path)) with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('id' in data and data['id'] == 'testnode3') self.assertTrue('name' in data and data['name'] == 'testnode3.mydomain.com')
def build_node_data_bag(): """Tells LittleChef to build the node data bag""" current_dir = os.getcwd() os.chdir(KITCHEN_DIR) try: lib.get_recipes() # This builds metadata.json for all recipes chef._build_node_data_bag() except SystemExit as e: log.error(e) finally: os.chdir(current_dir) return True
def test_attribute_merge_deep_dict(self): """Should deep-merge a dict when it is defined in two different places""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode2.json') with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('other_attr' in data) expected = { "deep_dict": { "deep_key1": "node_value1", "deep_key2": "role_value2" } } self.assertTrue(data['other_attr']['deep_dict'], expected)
def test_build_node_data_bag_nonalphanumeric(self): """Should create a node data bag when node name contains invalid chars """ chef._build_node_data_bag() # A node called testnode3.mydomain.com will have the data bag id # 'testnode3', because dots are not allowed. filename = 'testnode3_mydomain_com' nodename = filename.replace("_", ".") item_path = os.path.join('data_bags', 'node', filename + '.json') self.assertTrue(os.path.exists(item_path), "node file does not exist") with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('id' in data and data['id'] == filename) self.assertTrue('name' in data and data['name'] == nodename)
def test_build_node_data_bag_nonalphanumeric(self): """Should create a node data bag when node name contains non-alphanumerical characters""" chef._build_node_data_bag() # A node called testnode3.mydomain.com will have the data bag id # 'testnode3', because dots are not allowed. item_path = os.path.join('data_bags', 'node', 'testnode3_mydomain_com.json') self.assertTrue(os.path.exists(item_path)) with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('id' in data and data['id'] == 'testnode3_mydomain_com') self.assertTrue('name' in data and data['name'] == 'testnode3.mydomain.com')
def test_automatic_attributes(self): """Should add Chef's automatic attributes""" chef._build_node_data_bag() # Check node with single word fqdn testnode1_path = os.path.join('data_bags', 'node', 'testnode1.json') with open(testnode1_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('fqdn' in data and data['fqdn'] == 'testnode1') self.assertTrue('hostname' in data and data['hostname'] == 'testnode1') self.assertTrue('domain' in data and data['domain'] == '') # Check node with complex fqdn testnode3_path = os.path.join('data_bags', 'node', 'testnode3.json') with open(testnode3_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('fqdn' in data and data['fqdn'] == 'testnode3.mydomain.com') self.assertTrue('hostname' in data and data['hostname'] == 'testnode3') self.assertTrue('domain' in data and data['domain'] == 'mydomain.com')
def test_automatic_attributes(self): """Should add Chef's automatic attributes""" chef._build_node_data_bag() # Check node with single word fqdn testnode1_path = os.path.join("data_bags", "node", "testnode1.json") with open(testnode1_path, "r") as f: data = json.loads(f.read()) self.assertTrue("fqdn" in data and data["fqdn"] == "testnode1") self.assertTrue("hostname" in data and data["hostname"] == "testnode1") self.assertTrue("domain" in data and data["domain"] == "") # Check node with complex fqdn testnode3_path = os.path.join("data_bags", "node", "testnode3_mydomain_com.json") with open(testnode3_path, "r") as f: print testnode3_path data = json.loads(f.read()) self.assertTrue("fqdn" in data and data["fqdn"] == "testnode3.mydomain.com") self.assertTrue("hostname" in data and data["hostname"] == "testnode3") self.assertTrue("domain" in data and data["domain"] == "mydomain.com")
def test_build_node_data_bag(self): """Should create a node data bag with one item per node""" chef._build_node_data_bag() item_path = os.path.join("data_bags", "node", "testnode1.json") self.assertTrue(os.path.exists(item_path)) with open(item_path, "r") as f: data = json.loads(f.read()) self.assertTrue("id" in data and data["id"] == "testnode1") self.assertTrue("name" in data and data["name"] == "testnode1") self.assertTrue("recipes" in data and data["recipes"] == ["subversion"]) self.assertTrue("recipes" in data and data["role"] == []) item_path = os.path.join("data_bags", "node", "testnode2.json") self.assertTrue(os.path.exists(item_path)) with open(item_path, "r") as f: data = json.loads(f.read()) self.assertTrue("id" in data and data["id"] == "testnode2") self.assertTrue("recipes" in data) self.assertEquals(data["recipes"], [u"subversion", u"man", u"vim"]) self.assertTrue("recipes" in data) self.assertEquals(data["role"], [u"all_you_can_eat"]) self.assertEquals(data["roles"], [u"base", u"all_you_can_eat"])
def test_automatic_attributes(self): """Should add Chef's automatic attributes""" chef._build_node_data_bag() # Check node with single word fqdn testnode1_path = os.path.join('data_bags', 'node', 'testnode1.json') with open(testnode1_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('fqdn' in data and data['fqdn'] == 'testnode1') self.assertTrue('hostname' in data and data['hostname'] == 'testnode1') self.assertTrue('domain' in data and data['domain'] == '') # Check node with complex fqdn testnode3_path = os.path.join('data_bags', 'node', 'testnode3_mydomain_com.json') with open(testnode3_path, 'r') as f: print testnode3_path data = json.loads(f.read()) self.assertTrue('fqdn' in data and data['fqdn'] == 'testnode3.mydomain.com') self.assertTrue('hostname' in data and data['hostname'] == 'testnode3') self.assertTrue('domain' in data and data['domain'] == 'mydomain.com')
def test_build_node_data_bag(self): """Should create a node data bag with one item per node""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode1.json') self.assertTrue(os.path.exists(item_path)) with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('id' in data and data['id'] == 'testnode1') self.assertTrue('name' in data and data['name'] == 'testnode1') self.assertTrue('recipes' in data and data['recipes'] == ['subversion']) self.assertTrue('recipes' in data and data['role'] == []) item_path = os.path.join('data_bags', 'node', 'testnode2.json') self.assertTrue(os.path.exists(item_path)) with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('id' in data and data['id'] == 'testnode2') self.assertTrue('recipes' in data) self.assertEquals(data['recipes'], [u'subversion', u'man', u'vim']) self.assertTrue('recipes' in data) self.assertEquals(data['role'], [u'all_you_can_eat']) self.assertEquals(data['roles'], [u'base', u'all_you_can_eat'])
def test_build_node_data_bag(self): """Should create a node data bag with one item per node""" chef._build_node_data_bag() item_path = os.path.join('data_bags', 'node', 'testnode1.json') self.assertTrue(os.path.exists(item_path)) with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('id' in data and data['id'] == 'testnode1') self.assertTrue('name' in data and data['name'] == 'testnode1') self.assertTrue( 'recipes' in data and data['recipes'] == ['subversion']) self.assertTrue( 'recipes' in data and data['role'] == []) item_path = os.path.join('data_bags', 'node', 'testnode2.json') self.assertTrue(os.path.exists(item_path)) with open(item_path, 'r') as f: data = json.loads(f.read()) self.assertTrue('id' in data and data['id'] == 'testnode2') self.assertTrue('recipes' in data) self.assertEquals(data['recipes'], [u'subversion', u'man', u'vim']) self.assertTrue('recipes' in data) self.assertEquals(data['role'], [u'all_you_can_eat']) self.assertEquals(data['roles'], [u'base', u'all_you_can_eat'])