Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Post plugins #15

Merged
merged 2 commits into from

1 participant

@tildedave
Owner

No description provided.

Dave King added some commits
Dave King Add support for 'post-plugins' argument.
* Executes plugins after bootstrapping
* Can be used to mark a node as ready to be in rotation (for example)
ff72200
Dave King Update docs for --post-plugins argument. 22149b2
@tildedave tildedave merged commit fb14c83 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 23, 2013
  1. Add support for 'post-plugins' argument.

    Dave King authored
    * Executes plugins after bootstrapping
    * Can be used to mark a node as ready to be in rotation (for example)
  2. Update docs for --post-plugins argument.

    Dave King authored
This page is out of date. Refresh to see the latest.
View
3  README.md
@@ -67,6 +67,7 @@ fix-rackspace create \
--private-key <private_key_file> \
--runlist "role[web],recipe[security-updates]" \
--plugins "save_network,save_cloud" \
+ --post-plugins "mark_node_as_ready" \
--hostname "test.example.com"
```
@@ -85,6 +86,8 @@ fix-rackspace create \
* `plugins`: Comma separated list of littlechef plugins. Plugins are executed after chef deploy but
before your recipe run. If your recipes depend on the `cloud` attribute being set, you can specify a custom
littlechef `save_cloud` plugin that uses ohai to save data to the node before your cookbooks are run.
+* `post-plugins`: Comma separated list of littlechef plugins. These plugins are executed after the initial
+ chef run. They can be used to mark that a node is ready to go into rotation (for example).
### Notes
View
5 littlechef_rackspace/commands.py
@@ -26,7 +26,7 @@ def __init__(self, rackspace_api, chef_deployer):
self.chef_deploy = chef_deployer
def execute(self, node_name, flavor, image, public_key_file, runlist=None, plugins=None,
- environment=None, hostname=None, **kwargs):
+ post_plugins=None, environment=None, hostname=None, **kwargs):
host = self.rackspace_api.create_node(node_name=node_name, flavor=flavor,
image=image, public_key_file=public_key_file,
progress=sys.stderr)
@@ -35,7 +35,8 @@ def execute(self, node_name, flavor, image, public_key_file, runlist=None, plugi
if hostname:
host.host_string = hostname
- self.chef_deploy.deploy(host=host, runlist=runlist, plugins=plugins)
+ self.chef_deploy.deploy(host=host, runlist=runlist, plugins=plugins,
+ post_plugins=post_plugins)
def validate_args(self, **kwargs):
required_args = ["node_name", "flavor", "image"]
View
9 littlechef_rackspace/deploy.py
@@ -9,9 +9,10 @@ class ChefDeployer(object):
def __init__(self, key_filename):
self.key_filename = key_filename
- def deploy(self, host, runlist=None, plugins=None):
+ def deploy(self, host, runlist=None, plugins=None, post_plugins=None):
runlist = runlist or []
plugins = plugins or []
+ post_plugins = post_plugins or []
self._setup_ssh_config(host)
self._deploy_chef(host)
@@ -21,6 +22,9 @@ def deploy(self, host, runlist=None, plugins=None):
self._bootstrap_node(host)
+ for plugin in post_plugins:
+ self._execute_plugin(host, plugin)
+
def _deploy_chef(self, host):
lc.env.user = "root"
lc.env.host = host.get_host_string()
@@ -43,6 +47,9 @@ def _save_node_data(self, host, runlist):
def _execute_plugin(self, host, plugin_name):
node = littlechef.lib.get_node(host.get_host_string())
plugin = littlechef.lib.import_plugin(plugin_name)
+ littlechef.lib.print_header("Executing plugin '{0}' on "
+ "{1}".format(plugin_name, lc.env.host_string))
+
plugin.execute(node)
def _setup_ssh_config(self, host):
View
8 littlechef_rackspace/runner.py
@@ -57,7 +57,10 @@ def print_help(self, file=None):
help="Hostname for newly created node (DNS will not be set up -- you must do this manually)",
default=None)
parser.add_option("-p", "--plugins", dest="plugins",
- help="Plugins to execute after chef bootstrapping. e.g, 'save_cloud,save_hosts'",
+ help="Plugins to execute after chef bootstrapping but before chef run e.g, 'save_cloud,save_hosts'",
+ default=None)
+parser.add_option("-P", "--post-plugins", dest="post-plugins",
+ help="Plugins to execute after chef run. e.g, 'mark_node_as_provisioned'",
default=None)
class Runner(object):
@@ -159,6 +162,9 @@ def main(self, cmd_args):
if args.get('plugins'):
args['plugins'] = args['plugins'].split(',')
+ if args.get('post-plugins'):
+ args['post_plugins'] = args['post-plugins'].split(',')
+
command.execute(**args)
class MissingRequiredArguments(Exception):
View
23 test/test_commands.py
@@ -33,7 +33,8 @@ def test_deploys_to_host_without_runlist(self):
self.command.execute(node_name="something", image="imageId",
flavor="fileId", public_key_file=StringIO("whatever"))
- self.deployer.deploy.assert_any_call(host=Host(), runlist=None, plugins=None)
+ self.deployer.deploy.assert_any_call(host=Host(), runlist=None, plugins=None,
+ post_plugins=None)
def test_deploys_to_host_with_hostname(self):
self.command.execute(node_name="something", image="imageId",
@@ -41,7 +42,8 @@ def test_deploys_to_host_with_hostname(self):
hostname="test.example.com")
self.deployer.deploy.assert_any_call(host=Host(host_string="test.example.com"),
- runlist=None, plugins=None)
+ runlist=None, plugins=None,
+ post_plugins=None)
def test_deploys_to_host_with_environment(self):
self.command.execute(node_name="something", image="imageId",
@@ -52,7 +54,8 @@ def test_deploys_to_host_with_environment(self):
expected_host.environment = 'staging'
self.deployer.deploy.assert_any_call(host=expected_host,
- runlist=None, plugins=None)
+ runlist=None, plugins=None,
+ post_plugins=None)
def test_deploys_to_host_with_runlist_and_plugins(self):
runlist = ["role[web]", "recipe[test]"]
@@ -63,7 +66,19 @@ def test_deploys_to_host_with_runlist_and_plugins(self):
runlist=runlist, plugins=plugins)
self.deployer.deploy.assert_any_call(host=Host(),
- runlist=runlist, plugins=plugins)
+ runlist=runlist, plugins=plugins,
+ post_plugins=None)
+
+ def test_deploys_to_host_with_post_plugins(self):
+ post_plugins = ['plugin1', 'plugin2', 'plugin3']
+
+ self.command.execute(node_name="something", image="imageId",
+ flavor="fileId", public_key_file=StringIO("whatever"),
+ post_plugins=post_plugins)
+
+ self.deployer.deploy.assert_any_call(host=Host(),
+ runlist=None, plugins=None,
+ post_plugins=post_plugins)
class RackspaceListImagesTest(unittest.TestCase):
View
23 test/test_deploy.py
@@ -157,7 +157,6 @@ def test_deploy_with_plugins_executes_plugins_on_node(self, littlechef, lc):
plugin = mock.Mock()
littlechef.lib.import_plugin.return_value = plugin
-
node_data = {'predefined': [ 'values' ]}
littlechef.lib.get_node.return_value = node_data
@@ -168,6 +167,17 @@ def test_deploy_with_plugins_executes_plugins_on_node(self, littlechef, lc):
@mock.patch('littlechef_rackspace.deploy.lc')
@mock.patch('littlechef_rackspace.deploy.littlechef')
+ def test_deploy_with_plugin_prints_header(self, littlechef, lc):
+ deployer = self._get_deployer(key_filename="~/.ssh/id_rsa")
+
+ deployer.deploy(self.host, plugins=['plugin1'])
+
+ littlechef.lib.print_header.assert_any_call(
+ "Executing plugin '{0}' on {1}".format('plugin1', self.host.get_host_string())
+ )
+
+ @mock.patch('littlechef_rackspace.deploy.lc')
+ @mock.patch('littlechef_rackspace.deploy.littlechef')
def test_deploy_with_multiple_plugins(self, littlechef, lc):
deployer = self._get_deployer(key_filename="~/.ssh/id_rsa")
@@ -175,4 +185,13 @@ def test_deploy_with_multiple_plugins(self, littlechef, lc):
littlechef.lib.import_plugin.assert_any_call('plugin1')
littlechef.lib.import_plugin.assert_any_call('plugin2')
- littlechef.lib.import_plugin.assert_any_call('plugin3')
+ littlechef.lib.import_plugin.assert_any_call('plugin3')
+
+ @mock.patch('littlechef_rackspace.deploy.lc')
+ @mock.patch('littlechef_rackspace.deploy.littlechef')
+ def test_deploy_with_post_plugins(self, littlechef, lc):
+ deployer = self._get_deployer(key_filename="~/.ssh/id_rsa")
+
+ deployer.deploy(self.host, post_plugins=['postplugin'])
+
+ littlechef.lib.import_plugin.assert_any_call('postplugin')
View
10 test/test_runner.py
@@ -137,3 +137,13 @@ def test_create_with_plugins_parses_plugins_into_array(self):
call_args = self.create_command.execute.call_args_list[0][1]
self.assertEquals(plugins.split(','), call_args["plugins"])
+
+ def test_create_with_postplugins_parses_postplugins_into_array(self):
+ with mock.patch.multiple("littlechef_rackspace.runner", RackspaceApi=self.api_class,
+ ChefDeployer=self.deploy_class, RackspaceCreate=self.create_class):
+ r = Runner(options={})
+ post_plugins = 'plugin1,plugin2,plugin3'
+ r.main(self.create_args + [ '--post-plugins', post_plugins ])
+
+ call_args = self.create_command.execute.call_args_list[0][1]
+ self.assertEquals(post_plugins.split(','), call_args["post_plugins"])
Something went wrong with that request. Please try again.