Permalink
Browse files

Merge branch 'master' of github.com:tobami/littlechef

Conflicts:
	fix
  • Loading branch information...
2 parents fe23f25 + 01b8e4d commit f60afdbe896e96b6d08f02f0bb14f23163828235 @tobami committed Nov 11, 2011
Showing with 77 additions and 25 deletions.
  1. +2 −1 CHANGELOG
  2. +3 −0 NOTICE
  3. +2 −2 README.md
  4. +55 −15 fix
  5. +1 −2 littlechef/__init__.py
  6. +14 −5 tests/test_command.py
View
@@ -2,12 +2,13 @@
LittleChef Changelog
====================
-Version 1.0.3 November , 2011
+Version 1.0.3 November 11, 2011
----------------------------------------
* NEW #15 (partly): Automatic metadata.json regeneration from metadata.rb
* NEW #63: cleonte contributed deploy_chef support for CentOS/RHEL v6
* NEW #70: Markus added Chef Solo logs (found on /var/log/chef/solo.log)
+* NEW: Made debug and env proper command line options instead of fake fabric tasks
* FIX #67: Andrew fixed `get_ips` for OSX by adding a regex to parse IPs
* FIX #66: Remove sensible data from a node after a configuration run
View
3 NOTICE
@@ -15,3 +15,6 @@ Contributors and Copyright holders:
* Peter Harkins
* Van Lindberg
* Markus Korn <thekorn@gmx.de>
+ * Andrew Brookins <a@andrewbrookins.com>
+ * Mike Heffner <Mike Heffner>
+ * Eivind Uggedal
View
@@ -168,10 +168,10 @@ Note: Don't cook outside of a kitchen!
* `fix node:MYNODE role:MYROLE`: The same as above but role-based
* `fix node:MYNODE1,MYNODE2`: Configures several pre-configured nodes, in order
* `fix node:all`: It will apply all roles, recipes and attributes defined for each and every node in `nodes/`
-* `fix node:all env:MYENV`: Configures all nodes which have the attribute `chef_environment` set to `MYENV`
+* `fix --env MYENV node:all`: Configures all nodes which have the attribute `chef_environment` set to `MYENV`
* `fix nodes_with_role:ROLE1`: Configures all nodes which have a certain role in their run_list.
* `fix nodes_with_role:ROL*`: Configures all nodes which have at least one role which starts with 'ROL' in their run_list.
-* `fix nodes_with_role:ROLE1 env:MYENV`: Configures all nodes in the environment MYENV which have a certain role in their run_list.
+* `fix --env MYENV nodes_with_role:ROLE1`: Configures all nodes in the environment MYENV which have a certain role in their run_list.
* `fix --debug node:MYNODE`: You can start all your commands with `fix --debug` to see
all Chef Solo debugging information. Also, the node file and node databag wont't be
deleted from the node.
View
70 fix
@@ -1,5 +1,7 @@
#!/usr/bin/env python
from __future__ import print_function
+from optparse import OptionParser
+
import sys
import os
@@ -22,6 +24,42 @@ except ImportError:
print(INSTALL_ERROR)
sys.exit(1)
+
+class LittlechefOptionParser(OptionParser):
+
+ def print_help(self, file=None):
+ from fabric.main import list_commands, state, load_fabfile
+ OptionParser.print_help(self, file)
+ docstring, callables, default = load_fabfile(fabfile)
+ state.commands.update(callables)
+ for c in list_commands("\n", "normal"):
+ print(c)
+ sys.exit(0)
+
+# commandline options
+parser = LittlechefOptionParser()
+parser.add_option(
+ "-v", "--version", dest="version", action="store_true", default=False,
+ help="Print littlechef version"
+)
+parser.add_option(
+ "-l", dest="list_commands", action="store_true", default=False,
+ help="List all available orders"
+)
+parser.add_option(
+ "--no-report", dest="no_report", action="store_true", default=False,
+ help="Don't save the chef-solo output as a report on the node"
+)
+parser.add_option(
+ "--debug", dest="debug", action="store_true", default=False,
+ help="Ask chef-solo for verbose debugging output"
+)
+parser.add_option(
+ "--env", dest="environment", default=None,
+ help="Using a certain chef environment"
+)
+(options, args) = parser.parse_args()
+
## Process args list and call fabric's main() ##
if not sys.argv:
print(NO_ORDER)
@@ -36,25 +74,27 @@ else:
print(NO_ORDER)
else:
# Check for version, that overrides everything else.
- for arg in '-v', '-V', '--version':
- if arg in sys.argv:
- print(VERSION.format(littlechef.__version__))
- sys.exit(0)
- if '--no-report' in sys.argv:
+ if options.version:
+ print(VERSION.format(littlechef.__version__))
+ sys.exit(0)
+ if options.no_report:
littlechef.enable_logs = False
sys.argv.remove('--no-report')
- if '--debug' in sys.argv:
+ if options.debug:
littlechef.loglevel = 'debug'
sys.argv.remove('--debug')
- for arg in sys.argv:
- if "--env=" in arg:
- chef_environment = arg.split("=")[1]
- if chef_environment == '':
- print("Error: No environment was given", file=sys.stderr)
- sys.exit(1)
- else:
- littlechef.chef_environment = chef_environment
- sys.argv.remove(arg)
+ if options.environment is not None:
+ # Check for mistakes:
+ # * fix --env list_nodes
+ # * fix --env nodes_with_role:bla role:authorization
+ if len(args) == 0 or ":" in options.environment:
+ print("Error: no value given for --env", file=sys.stderr)
+ sys.exit(1)
+ littlechef.chef_environment = options.environment
+ idx = sys.argv.index("--env")
+ sys.argv.remove("--env")
+ sys.argv.pop(idx)
+
# Otherwise, insert our fabfile at the correct place
if fix_cmd:
sys.argv[1:1] = ['-f', fabfile]
View
@@ -14,13 +14,12 @@
.. _Chef: http://wiki.opscode.com/display/chef/Home
"""
-__version__ = "1.0.3b"
+__version__ = "1.0.3"
__author__ = "Miquel Torres <tobami@gmail.com>"
__cooking__ = False
chef_environment = None
loglevel = "info"
-
LOGFILE = '/var/log/chef/solo.log'
enable_logs = True
View
@@ -85,15 +85,24 @@ def test_list_commands(self):
class TestEnvironment(BaseTest):
- def test_no_value(self):
- """Should error out when the env value is empty"""
- resp, error = self.execute([fix, 'list_nodes', '--env='])
+ def test_no_valid_value(self):
+ """Should error out when the env value is empty or is a fabric task"""
+ resp, error = self.execute([fix, 'list_nodes', '--env'])
self.assertEquals(resp, "")
- self.assertTrue("Error: No environment was given" in error, error)
+ self.assertTrue("error: --env option requires an argument" in error, error)
+
+ resp, error = self.execute([fix, '--env', 'list_nodes'])
+ self.assertEquals(resp, "")
+ self.assertTrue("Error: no value given for --env" in error, error)
+
+ cmd = [fix, '--env', 'nodes_with_role:base', 'role:base']
+ resp, error = self.execute(cmd)
+ self.assertEquals(resp, "")
+ self.assertTrue("Error: no value given for --env" in error, error)
def test_valid_environment(self):
"""Should set the chef_environment value when one is given"""
- resp, error = self.execute([fix, 'list_nodes', '--env=staging'])
+ resp, error = self.execute([fix, 'list_nodes', '--env', 'staging'])
self.assertEquals(error, "", error)
self.assertTrue("Environment: staging" in resp, resp)

0 comments on commit f60afdb

Please sign in to comment.