sous-chef 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sous-chef (0.0.6)
4
+ sous-chef (0.0.7)
5
5
  knife-solo (~> 0.1.0)
6
- rake (~> 10.0.3)
6
+ rake (~> 10.0.0)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
@@ -42,7 +42,7 @@ GEM
42
42
  chef (>= 0.10)
43
43
  highline
44
44
  thor (~> 0.15)
45
- mime-types (1.19)
45
+ mime-types (1.20.1)
46
46
  mixlib-authentication (1.3.0)
47
47
  mixlib-log
48
48
  mixlib-cli (1.3.0)
@@ -77,7 +77,7 @@ GEM
77
77
  diff-lcs (~> 1.1.3)
78
78
  rspec-mocks (2.12.1)
79
79
  systemu (2.5.2)
80
- thor (0.16.0)
80
+ thor (0.17.0)
81
81
  treetop (1.4.12)
82
82
  polyglot
83
83
  polyglot (>= 0.3.1)
@@ -89,6 +89,6 @@ PLATFORMS
89
89
 
90
90
  DEPENDENCIES
91
91
  bundler (~> 1.1)
92
- rake (~> 10.0.3)
92
+ rake (~> 10.0.0)
93
93
  rspec (~> 2.12.0)
94
94
  sous-chef!
data/README.md CHANGED
@@ -2,22 +2,31 @@
2
2
 
3
3
  Manage [knife-solo](http://matschaffer.github.com/knife-solo/) nodes.
4
4
 
5
- ## Install
5
+ ## Usage
6
+
7
+ Simply ensure the gem is installed using:
8
+
9
+ gem install sous-chef
10
+
11
+ Or add this to your Gemfile if you use bundler:
12
+
13
+ gem 'sous-chef'
6
14
 
7
- Add the following to your `Rakefile`:
15
+ And add the following to your `Rakefile`:
8
16
 
9
17
  ```ruby
10
18
  require 'sous-chef'
11
19
  ```
12
20
 
13
- You may run `rake sous_chef:init` to generate sample `nodes.yml` to
14
- `nodes/nodes.yml`
21
+ Run `rake sous_chef:init` to place a sample `nodes.yml` under `nodes/nodes.yml`
22
+
23
+ Run `rake -T` to display nodes and commands defined in `nodes/nodes.yml`
15
24
 
16
25
  ## Configure
17
26
 
18
- Create configuration in knife-solo nodes dir e.g. `nodes/nodes.yml`. Node
19
- configuration is used for sshconfig as well as nodename. You can namespace
20
- nodes however you want. Example `nodes.yml`:
27
+ Node configuration is done in `nodes/nodes.yml`. You can namespace your nodes
28
+ however you want. You can run multiple tasks in parallel using the `:all:`
29
+ namespace Example `nodes.yml`:
21
30
 
22
31
  ```yaml
23
32
  # Format:
@@ -62,10 +71,6 @@ vagrant:
62
71
  ForwardAgent: "yes"
63
72
  ```
64
73
 
65
- ## Usage
66
-
67
- `rake -T` for a full list of tasks provided:
68
-
69
74
  ## Contributing
70
75
 
71
76
  1. Fork it
@@ -1,10 +1,11 @@
1
1
  module SousChef::NodeHelpers
2
2
 
3
+ module_function
4
+
3
5
  def node?(settings)
4
6
  settings.is_a? SousChef::Node or settings.has_key?('node_config') or
5
7
  settings.has_key?('ssh_config')
6
8
  end
7
9
 
8
- module_function :node?
9
10
  end
10
11
 
@@ -0,0 +1,77 @@
1
+ require 'rake'
2
+
3
+ module SousChef::NodeTaskHelpers
4
+ include Rake::DSL
5
+
6
+ module_function
7
+
8
+ def build_node_task(node)
9
+ namespace node.name do
10
+ prepare_task(node)
11
+ cook_task(node)
12
+ bootstrap_task(node)
13
+ clean_task(node)
14
+ end
15
+ end
16
+
17
+ def clean_task(node)
18
+ desc "Run knife solo clean for #{node.name}"
19
+ task :clean do
20
+ run_knife 'clean', node
21
+ end
22
+ end
23
+
24
+ def cook_task(node)
25
+ desc "Run knife solo cook for #{node.name}"
26
+ task :cook do
27
+ run_knife 'cook', node
28
+ end
29
+ end
30
+
31
+ def bootstrap_task(node)
32
+ desc "Run knife solo bootstrap for #{node.name}"
33
+ task :bootstrap do
34
+ run_knife 'bootstrap', node
35
+ end
36
+ end
37
+
38
+ def prepare_task(node)
39
+ desc "Run knife solo prepare for #{node.name}"
40
+ task :prepare do
41
+ run_knife 'prepare', node
42
+ end
43
+ end
44
+
45
+ def batch_tasks(name, tasks)
46
+ task_names = tasks.map(&:name)
47
+
48
+ desc "Run knife solo prepare for all #{name} nodes"
49
+ multitask :prepare => filter_tasks(task_names, 'prepare')
50
+
51
+ desc "Run knife solo cook for all #{name} nodes"
52
+ multitask :cook => filter_tasks(task_names, 'cook')
53
+
54
+ desc "Run knife solo bootstrap for all #{name} nodes"
55
+ multitask :bootstrap => filter_tasks(task_names, 'bootstrap')
56
+
57
+ desc "Run knife solo clean for all #{name} nodes"
58
+ multitask :clean => filter_tasks(task_names, 'clean')
59
+ end
60
+
61
+ def filter_tasks(tasks_names, desired_task)
62
+ tasks_names.clone.keep_if { |task_name| task_name.include? desired_task }
63
+ end
64
+
65
+ def run(command)
66
+ puts "Running: #{command}"
67
+ system command
68
+ raise "Failure! #{$?}" if $? != 0
69
+ end
70
+
71
+ def run_knife(command, node)
72
+ options = "-F #{node.ssh_config_path} #{node.hostname}"
73
+ options = "#{options} -N #{node.name} #{node.config}" unless %w[clean].include? command
74
+ run "knife solo #{command} #{options}"
75
+ end
76
+ end
77
+
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  class SousChef::Collection
2
4
  extend Forwardable
3
5
 
@@ -1,5 +1,5 @@
1
1
  class SousChef::TaskBuilder
2
- include SousChef::NodeTasks
2
+ include SousChef::NodeTaskHelpers
3
3
  include SousChef::NodeHelpers
4
4
 
5
5
  def initialize(nodes)
@@ -8,6 +8,19 @@ class SousChef::TaskBuilder
8
8
 
9
9
  def build_tasks
10
10
  build_namespace(@nodes)
11
+ build_batch_tasks(@nodes)
12
+ end
13
+
14
+ def build_batch_tasks(collection)
15
+ collection.each do |name, collection|
16
+ next if node?(collection)
17
+ namespace name do |ns|
18
+ namespace :all do
19
+ batch_tasks(name, ns.tasks)
20
+ end
21
+ build_batch_tasks(collection)
22
+ end
23
+ end
11
24
  end
12
25
 
13
26
  def build_namespace(collection)
data/lib/sous-chef.rb CHANGED
@@ -3,6 +3,8 @@ module SousChef
3
3
  CONFIG_TEMPLATE = File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'nodes.example.yml'))
4
4
  CONFIG_FILE = File.join(Dir.pwd, "nodes", "nodes.yml")
5
5
 
6
+ module_function
7
+
6
8
  def config_file_location
7
9
  CONFIG_FILE
8
10
  end
@@ -20,12 +22,11 @@ module SousChef
20
22
  end
21
23
  end
22
24
 
23
- module_function :create_config, :config_file_location, :config_template_location
24
25
  end
25
26
 
26
27
  require 'helpers/node_helpers'
28
+ require 'helpers/node_task_helpers'
27
29
  require 'sous-chef/parser'
28
- require 'sous-chef/node_tasks'
29
30
  require 'sous-chef/node'
30
31
  require 'sous-chef/collection'
31
32
  require 'sous-chef/task_builder'
data/sous-chef.gemspec CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.email = "shaun@substantail.com"
7
7
 
8
8
  s.name = 'sous-chef'
9
- s.version = "0.0.6"
9
+ s.version = "0.0.7"
10
10
  s.description = %q{Manage knife-solo nodes}
11
- s.summary = %q{Manage knife-solo nodes by environment. Run knife solo
11
+ s.summary = %q{Rake tasks for managing knife-solo nodes by environment. Run knife solo
12
12
  commands on one or multiple nodes.}
13
13
  s.homepage = %q{http://github.com/substantial/sous-chef}
14
14
  s.license = "MIT"
@@ -20,11 +20,10 @@ commands on one or multiple nodes.}
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_runtime_dependency "rake", "~> 10.0.3"
23
+ s.add_runtime_dependency "rake", "~> 10.0.0"
24
24
  s.add_development_dependency "rspec", "~> 2.12.0"
25
- s.add_development_dependency "rake", "~> 10.0.3"
25
+ s.add_development_dependency "rake", "~> 10.0.0"
26
26
  s.add_development_dependency "bundler", "~> 1.1"
27
27
  s.add_dependency "knife-solo", "~> 0.1.0"
28
-
29
28
  end
30
29
 
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe SousChef::NodeTaskHelpers do
4
+ before do
5
+ SousChef::NodeTaskHelpers.stub(:run)
6
+ end
7
+
8
+ describe "#run_knife" do
9
+ let(:node) { double('node') }
10
+
11
+ before do
12
+ node.stub(name: 'foo')
13
+ node.stub(hostname: 'node_hostname')
14
+ node.stub(ssh_config_path: 'ssh_config_path')
15
+ node.stub(config: 'knife_solo_node_config')
16
+ end
17
+
18
+ it "should run knife solo command for given node" do
19
+ SousChef::NodeTaskHelpers.should_receive(:run).with("knife solo some_command -F ssh_config_path node_hostname -N foo knife_solo_node_config")
20
+ SousChef::NodeTaskHelpers.run_knife('some_command', node)
21
+ end
22
+
23
+ it "should not specify node config for #clean command" do
24
+ SousChef::NodeTaskHelpers.should_receive(:run).with("knife solo clean -F ssh_config_path node_hostname")
25
+ SousChef::NodeTaskHelpers.run_knife('clean', node)
26
+ end
27
+ end
28
+
29
+ describe "#filter_tasks" do
30
+ it "should filter for tasks that have the action" do
31
+ tasks = %w[foo:bar:action foo:bar:baz]
32
+ SousChef::NodeTaskHelpers.filter_tasks(tasks, 'action').should include "foo:bar:action"
33
+ end
34
+
35
+ it "shouldn't alter the input task list" do
36
+ tasks = %w[foo:bar:action foo:bar:baz]
37
+ tasks_clone = tasks.clone
38
+ SousChef::NodeTaskHelpers.filter_tasks(tasks, 'action').should include "foo:bar:action"
39
+ tasks.should == tasks_clone
40
+ end
41
+ end
42
+ end
43
+
@@ -1,5 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
+ def get_task(task_list, task_name)
4
+ task_list.select {|task| task.name == task_name}.first
5
+ end
6
+
3
7
  describe "sous_chef.rake" do
4
8
  before(:all) do
5
9
  @rake = Rake::Application.new
@@ -37,5 +41,21 @@ describe "generated node tasks" do
37
41
  it "should namespace nodes tasks" do
38
42
  rake_tasks.should include "production:web:OtherAwesome:bootstrap"
39
43
  end
44
+
45
+ it "should have #all task for namespaces" do
46
+ rake_tasks.should include "production:all:cook"
47
+ rake_tasks.should include "production:web:all:prepare"
48
+ end
49
+
50
+ describe "generated namespace#all tasks" do
51
+ let(:multitasks) { multitasks = @rake.tasks.keep_if{ |task| task.is_a? Rake::MultiTask } }
52
+
53
+ %w[prepare cook clean bootstrap].each do |command|
54
+ it "should include all node tasks for #{command}" do
55
+ production_prepare_multitask = get_task(multitasks, "production:web:all:#{command}")
56
+ production_prepare_multitask.prerequisites.should =~ ["production:web:OtherAwesome:#{command}"]
57
+ end
58
+ end
59
+ end
40
60
  end
41
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sous-chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 10.0.3
21
+ version: 10.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 10.0.3
29
+ version: 10.0.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 10.0.3
53
+ version: 10.0.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 10.0.3
61
+ version: 10.0.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: bundler
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -103,12 +103,12 @@ files:
103
103
  - README.md
104
104
  - Rakefile
105
105
  - lib/helpers/node_helpers.rb
106
+ - lib/helpers/node_task_helpers.rb
106
107
  - lib/sous-chef.rb
107
108
  - lib/sous-chef/collection.rb
108
109
  - lib/sous-chef/node.rb
109
110
  - lib/sous-chef/node_builder.rb
110
111
  - lib/sous-chef/node_manager.rb
111
- - lib/sous-chef/node_tasks.rb
112
112
  - lib/sous-chef/parser.rb
113
113
  - lib/sous-chef/task_builder.rb
114
114
  - lib/sous-chef/tasks.rb
@@ -117,11 +117,11 @@ files:
117
117
  - lib/templates/nodes.example.yml
118
118
  - sous-chef.gemspec
119
119
  - spec/helpers/node_helpers_spec.rb
120
+ - spec/helpers/node_task_helpers_spec.rb
120
121
  - spec/sous-chef/collection_spec.rb
121
122
  - spec/sous-chef/node_builder_spec.rb
122
123
  - spec/sous-chef/node_manager_spec.rb
123
124
  - spec/sous-chef/node_spec.rb
124
- - spec/sous-chef/node_tasks_spec.rb
125
125
  - spec/sous-chef/parser_spec.rb
126
126
  - spec/sous-chef/sous-chef_spec.rb
127
127
  - spec/sous-chef/task_builder_spec.rb
@@ -153,15 +153,15 @@ rubyforge_project: sous-chef
153
153
  rubygems_version: 1.8.24
154
154
  signing_key:
155
155
  specification_version: 3
156
- summary: Manage knife-solo nodes by environment. Run knife solo commands on one or
157
- multiple nodes.
156
+ summary: Rake tasks for managing knife-solo nodes by environment. Run knife solo commands
157
+ on one or multiple nodes.
158
158
  test_files:
159
159
  - spec/helpers/node_helpers_spec.rb
160
+ - spec/helpers/node_task_helpers_spec.rb
160
161
  - spec/sous-chef/collection_spec.rb
161
162
  - spec/sous-chef/node_builder_spec.rb
162
163
  - spec/sous-chef/node_manager_spec.rb
163
164
  - spec/sous-chef/node_spec.rb
164
- - spec/sous-chef/node_tasks_spec.rb
165
165
  - spec/sous-chef/parser_spec.rb
166
166
  - spec/sous-chef/sous-chef_spec.rb
167
167
  - spec/sous-chef/task_builder_spec.rb
@@ -1,47 +0,0 @@
1
- require 'rake'
2
-
3
- module SousChef::NodeTasks
4
- include Rake::DSL
5
-
6
- def build_node_task(node)
7
- namespace node.name do
8
- prepare_task(node)
9
- cook_task(node)
10
- bootstrap_task(node)
11
- end
12
- end
13
-
14
- def cook_task(node)
15
- desc "Run knife solo cook for #{node.name}"
16
- task :cook do
17
- run_knife 'cook', node
18
- end
19
- end
20
-
21
- def bootstrap_task(node)
22
- desc "Run knife solo bootstrap for #{node.name}"
23
- task :bootstrap do
24
- run_knife 'bootstrap', node
25
- end
26
- end
27
-
28
- def prepare_task(node)
29
- desc "Run knife solo prepare for #{node.name}"
30
- task :prepare do
31
- run_knife 'prepare', node
32
- end
33
- end
34
-
35
- def run(command)
36
- puts "Running: #{command}"
37
- system command
38
- raise "Failure! #{$?}" if $? != 0
39
- end
40
-
41
- def run_knife(command, node)
42
- run "knife solo #{command} -F #{node.ssh_config_path} #{node.hostname} -N #{node.name} #{node.config}"
43
- end
44
-
45
- module_function :build_node_task, :cook_task, :bootstrap_task, :prepare_task, :run, :run_knife
46
- end
47
-
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SousChef::NodeTasks do
4
- before do
5
- SousChef::NodeTasks.stub(:run)
6
- end
7
-
8
- describe "#run_knife" do
9
- it "should run knife solo command for given node" do
10
- node = double('node')
11
- node.stub(name: 'foo')
12
- node.stub(hostname: 'node_hostname')
13
- node.stub(ssh_config_path: 'ssh_config_path')
14
- node.stub(config: 'knife_solo_node_config')
15
- SousChef::NodeTasks.should_receive(:run).with("knife solo some_command -F ssh_config_path node_hostname -N foo knife_solo_node_config")
16
- SousChef::NodeTasks.run_knife('some_command', node)
17
- end
18
- end
19
- end
20
-