Skip to content

Commit

Permalink
Prevent recipe and role commands from aborting
Browse files Browse the repository at this point in the history
Changed internal nodename from 'littlechef/nodename' to just 'name'
Closes #39
  • Loading branch information
tobami committed Jun 8, 2011
1 parent 85842c1 commit f0ad57e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion littlechef/chef.py
Expand Up @@ -120,7 +120,7 @@ def _synchronize_node(cookbooks):
path = os.path.join(cookbook_path, cookbook)
if os.path.exists(path):
cookbooks_by_path[path] = cookbook
print "Uploading roles and cookbooks:"
print "Uploading roles, cookbooks and data bags:"
print " ({0})".format(", ".join(c for c in cookbooks))
to_upload = [p for p in cookbooks_by_path.keys()]
to_upload.append('roles')
Expand Down
9 changes: 4 additions & 5 deletions littlechef/lib.py
Expand Up @@ -33,17 +33,16 @@ def get_nodes():
and not f.startswith('.')]):
hostname = ".".join(filename.split('.')[:-1])#remove .json from name
node = get_node(hostname)
# Don't append "nodename" to the root namespace
# because it could colide with some cookbook's attribute
node['littlechef'] = {'nodename': hostname}
# Add node name so that we can tell to which node the data belongs to
node['name'] = hostname
nodes.append(node)
return nodes


def get_node(name):
node_path = os.path.join("nodes", name + ".json")
if not os.path.exists(node_path):
abort("No config file found for node '{0}'".format(name))
return {'run_list': []}
# Read node.json
with open(node_path, 'r') as f:
try:
Expand All @@ -57,7 +56,7 @@ def get_node(name):

def print_node(node, detailed=False):
"""Pretty prints the given node"""
nodename = node['littlechef']['nodename']
nodename = node['name']
print(colors.yellow("\n" + nodename))
# Roles
if detailed:
Expand Down
2 changes: 1 addition & 1 deletion littlechef/runner.py
Expand Up @@ -77,7 +77,7 @@ def node(host):
"""Select a node"""
if host == 'all':
for node in lib.get_nodes():
env.hosts.append(node['littlechef']['nodename'])
env.hosts.append(node['name'])
if not len(env.hosts):
abort('No nodes found')
else:
Expand Down
15 changes: 11 additions & 4 deletions littlechef/tests.py
Expand Up @@ -23,16 +23,23 @@ def tearDown(self):


class TestLib(BaseTest):
def test_get_node(self):
"""Should get data for a given node, empty when it doesn't exist"""
expected = {'run_list': []}
self.assertEquals(lib.get_node('Idon"texist'), expected)
expected = {'run_list': ['recipe[subversion]']}
self.assertEquals(lib.get_node('testnode'), expected)

def test_list_nodes(self):
expected = [
{'littlechef': {'nodename': 'testnode'},
'run_list': ['recipe[subversion]']}]
"""Should list all configured nodes"""
expected = [{'name': 'testnode', 'run_list': ['recipe[subversion]']}]
self.assertEquals(lib.get_nodes(), expected)

def test_list_recipes(self):
recipes = lib.get_recipes()
self.assertEquals(len(recipes), 3)
self.assertEquals(recipes[1]['description'], 'Subversion Client installs subversion and some extra svn libs')
self.assertEquals(recipes[1]['description'],
'Subversion Client installs subversion and some extra svn libs')
self.assertEquals(recipes[2]['name'], 'subversion::server')


Expand Down

0 comments on commit f0ad57e

Please sign in to comment.