Permalink
Browse files

New flag for strategy, wired in.

  • Loading branch information...
1 parent f2fdbcc commit 4ab61adeb1cb6ac7e27ece2cbc7d04111998b1ae @neo-technology-release-persona neo-technology-release-persona committed Jun 6, 2012
View
@@ -30,6 +30,10 @@ flag [:hk,:hook]
desc 'Cucumber features directory to invoke, after the Puppet run success'
flag [:features]
+desc 'Strategy for deploying Puppet'
+default_value :bundler
+flag [:strategy]
+
desc 'do a dry run first'
default_value false
arg_name 'noop'
@@ -1,4 +1,5 @@
require 'skewer/config'
+require 'skewer/strategy/bundler'
require 'skewer'
module Skewer
@@ -8,11 +9,11 @@ class Bootstrapper
MAX_CACHE = 3600
attr_writer :mock
- def initialize(node,options)
+ def initialize(node,installer,options)
@node = node
@options = options
@mock = false
- @install_strategy = Skewer::Strategy::Bundler.new(@node)
+ @installer = installer
end
def host_key_exists(host)
@@ -94,9 +95,9 @@ def prepare_node
def go
i_should_run = should_i_run?
- @install_strategy.install if i_should_run
+ @installer.install if i_should_run
sync_source
- @install_strategy.preflight if i_should_run
+ @installer.preflight if i_should_run
end
end
end
View
@@ -16,6 +16,19 @@ def initialize(options)
config.slurp_options(options)
end
+ def select_strategy(option)
+ require 'skewer/strategy/bundler'
+ require 'skewer/strategy/debian_package'
+ if option == :bundler
+ Skewer::Strategy::Bundler.new(@node)
+ elsif option == :debian
+ Skewer::Strategy::DebianPackage.new(@node)
+ else
+ raise "I don't know about that strategy - sorry"
+ end
+ end
+
+
def select_node(cloud)
logger.debug "Evaluating cloud #{cloud}"
image = @options[:image]
@@ -62,7 +75,8 @@ def destroy
def bootstrap
node = select_node(@options[:cloud])
@node = node
- @bootstrapper = Bootstrapper.new(node, @options)
+ @installer = select_strategy(config.get(:strategy))
+ @bootstrapper = Bootstrapper.new(node, @installer, @options)
end
def go
@@ -72,7 +86,7 @@ def go
node = @node
node.wait_for { ready? }
@bootstrapper.go
- Puppet.run(node, @options)
+ Puppet.run(node, @installer, @options)
location = get_location(node)
Hooks.new(location).run
View
@@ -5,25 +5,25 @@ module Skewer
# responsible for executing puppet
class Puppet
include Skewer
+
+ def initialize(installer)
+ @installer = installer
+ end
def arguments
[
"--modulepath modules",
"--vardir /var/lib/puppet"
].join(' ')
end
- def bundle
- Skewer::Strategy::Bundler.new(nil).executable()
- end
-
def command_string(username, options)
@command_line = "cd infrastructure"
if username == 'root'
@command_line << " &&"
else
@command_line << " && sudo"
end
- @command_line << " #{self.bundle} exec"
+ @command_line << " #{@installer.executable}"
@command_line << " puppet apply"
@command_line << " manifests/site.pp"
@command_line << " --color false"
@@ -46,8 +46,8 @@ def run(node, options)
result
end
- def self.run(node, options)
- this = self.new
+ def self.run(node, installer, options)
+ this = self.new(installer)
this.run(node, options)
end
end
View
@@ -2,10 +2,12 @@ module Skewer
require 'logger'
require 'skewer/config'
+
def logger
@log ||= Logger.new(STDOUT)
end
+
# Get the location (dns name, or IP) for a given Fog server. Cloud
# provider agnostic.
def get_location(server = nil)
View
@@ -15,7 +15,7 @@
node.should_receive(:ssh).at_least(1).times
ConfHelper.new.conf.set(:puppet_repo, 'target')
lambda {
- Skewer::Bootstrapper.new(node, {:role => 'foo'}).sync_source
+ Skewer::Bootstrapper.new(node, nil,{:role => 'foo'}).sync_source
}.should raise_exception RuntimeError
ConfHelper.new.conf.set(:puppet_repo, '../infrastructure')
File.exist?('target/manifests/nodes.pp').should == true
@@ -34,7 +34,7 @@
FileUtils.mkdir_p(faux_homedir)
FileUtils.touch("#{faux_homedir}/my_great_test_key.pem")
- bootstrapper = Skewer::Bootstrapper.new(node, {})
+ bootstrapper = Skewer::Bootstrapper.new(node,nil, {})
bootstrapper.add_key_to_agent(kernel, 'tmp/foo')
ConfHelper.new.conf.set(:key_name, nil)
@@ -45,7 +45,7 @@
node = stub('node')
node.should_receive(:dns_name).at_least(1).times.and_return('foo.bar.com')
- bootstrapper = Skewer::Bootstrapper.new(node, {:role => 'foo'})
+ bootstrapper = Skewer::Bootstrapper.new(node,nil, {:role => 'foo'})
bootstrapper.destroy_lock_file
bootstrapper.should_i_run?.should == true
@@ -58,7 +58,7 @@
node = stub('node')
node.should_receive(:dns_name).at_least(1).times.and_return('foo.bar.com')
- bootstrapper = Skewer::Bootstrapper.new(node, {:role => 'foo'})
+ bootstrapper = Skewer::Bootstrapper.new(node, nil,{:role => 'foo'})
bootstrapper.destroy_lock_file
bootstrapper.should_i_run?.should == true
@@ -71,7 +71,7 @@
node.should_receive(:scp).at_least(1).times
node.should_receive(:ssh).at_least(1).times
node.should_receive(:dns_name).at_least(1).times.and_return('foo.bar.com')
- bootstrapper = Skewer::Bootstrapper.new(node, {:role => 'foo'})
+ bootstrapper = Skewer::Bootstrapper.new(node, Skewer::Strategy::Bundler.new(node), {:role => 'foo'})
bootstrapper.destroy_lock_file
bootstrapper.mock = true
bootstrapper.go
@@ -82,7 +82,7 @@
it "should allow mocking out of the source step" do
node = stub('node')
node.should_not_receive(:username)
- bootstrapper = Skewer::Bootstrapper.new(node, {:role => 'foo'})
+ bootstrapper = Skewer::Bootstrapper.new(node,nil, {:role => 'foo'})
bootstrapper.mock = true
bootstrapper.sync_source
end
@@ -91,7 +91,7 @@
node = stub('node')
node.should_receive(:username).at_least(2).times
node.should_receive(:ssh)
- bootstrapper = Skewer::Bootstrapper.new(node, {:role => 'foo'})
+ bootstrapper = Skewer::Bootstrapper.new(node, nil, {:role => 'foo'})
lambda {
bootstrapper.sync_source
}.should raise_exception RuntimeError
View
@@ -66,4 +66,20 @@
Skewer::Dispatcher.new({:cloud => :nil, :cuke_dir => 'spec'})
@config.get(:cuke_dir).should == 'spec'
end
+
+ it "should give a debian strategy if we ask for debian in the config" do
+ Skewer::Dispatcher.new({}).select_strategy(:debian).should be_a Skewer::Strategy::DebianPackage
+ end
+
+ it "should give a bundler strategy if we ask for bundler in the config" do
+ Skewer::Dispatcher.new({}).select_strategy(:bundler).should be_a Skewer::Strategy::Bundler
+ end
+
+ it "should barf if we ask for something unsupported" do
+ begin
+ Skewer::Dispatcher.new({}).select_strategy(:ebuild)
+ rescue Exception => e
+ e.message.should == "I don't know about that strategy - sorry"
+ end
+ end
end
View
@@ -3,7 +3,9 @@
describe Skewer::Puppet do
before(:each) do
- @puppet = Skewer::Puppet.new
+ installer = stub('installer')
+ installer.should_receive(:executable).and_return('/usr/local/bin/bundle exec')
+ @puppet = Skewer::Puppet.new(installer)
@root = File.expand_path File.join(File.dirname(__FILE__), "..")
@prefix = "cd infrastructure && /usr/local/bin/bundle exec puppet apply manifests/site.pp --color false"
@sudo_prefix = "cd infrastructure && sudo /usr/local/bin/bundle exec puppet apply manifests/site.pp --color false"
@@ -25,14 +27,6 @@
@puppet.command_string('root', {:noop => true}).should == "#{@prefix} --modulepath modules --vardir /var/lib/puppet --noop"
end
- it "should have args for our custom modulepath" do
- @puppet.arguments.should match(/modulepath/)
- end
-
- it "should not have args for external node configuration" do
- @puppet.arguments.should_not match(/external_nodes/)
- end
-
it "should blow up if something fails" do
node = mock('node')
result = stub('result')

0 comments on commit 4ab61ad

Please sign in to comment.