knife_sous 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.gitignore +1 -0
  2. data/.ruby-version +1 -0
  3. data/Gemfile +9 -0
  4. data/Gemfile.lock +106 -0
  5. data/Guardfile +6 -0
  6. data/README.md +51 -0
  7. data/Rakefile +16 -0
  8. data/knife_sous.gemspec +28 -0
  9. data/lib/chef/knife/sous_bootstrap.rb +31 -0
  10. data/lib/chef/knife/sous_clean.rb +30 -0
  11. data/lib/chef/knife/sous_cook.rb +31 -0
  12. data/lib/chef/knife/sous_init.rb +39 -0
  13. data/lib/chef/knife/sous_list.rb +22 -0
  14. data/lib/chef/knife/sous_prepare.rb +31 -0
  15. data/lib/knife_sous/configure_command.rb +12 -0
  16. data/lib/knife_sous/dsl_definitions.rb +29 -0
  17. data/lib/knife_sous/dsl_wrapper.rb +8 -0
  18. data/lib/knife_sous/mixins/hash_mixins.rb +14 -0
  19. data/lib/knife_sous/namespace.rb +19 -0
  20. data/lib/knife_sous/namespace_presenter.rb +27 -0
  21. data/lib/knife_sous/node.rb +47 -0
  22. data/lib/knife_sous/node_command.rb +36 -0
  23. data/lib/knife_sous/node_presenter.rb +13 -0
  24. data/lib/knife_sous/processor_command.rb +52 -0
  25. data/lib/knife_sous.rb +3 -0
  26. data/lib/templates/nodes.example.rb +32 -0
  27. data/spec/lib/chef/knife/sous_bootstrap_spec.rb +42 -0
  28. data/spec/lib/chef/knife/sous_clean_spec.rb +41 -0
  29. data/spec/lib/chef/knife/sous_cook_spec.rb +52 -0
  30. data/spec/lib/chef/knife/sous_init_spec.rb +56 -0
  31. data/spec/lib/chef/knife/sous_list_spec.rb +33 -0
  32. data/spec/lib/chef/knife/sous_prepare_spec.rb +42 -0
  33. data/spec/lib/knife_sous/configure_command_spec.rb +27 -0
  34. data/spec/lib/knife_sous/dsl_definitions_spec.rb +52 -0
  35. data/spec/lib/knife_sous/dsl_wrapper_spec.rb +12 -0
  36. data/spec/lib/knife_sous/mixins/hash_mixins_spec.rb +23 -0
  37. data/spec/lib/knife_sous/namespace_presenter_spec.rb +57 -0
  38. data/spec/lib/knife_sous/namespace_spec.rb +59 -0
  39. data/spec/lib/knife_sous/node_presenter_spec.rb +18 -0
  40. data/spec/lib/knife_sous/node_spec.rb +63 -0
  41. data/spec/lib/knife_sous/processor_command_spec.rb +135 -0
  42. data/spec/spec_helper.rb +14 -0
  43. data/spec/support/fixtures/nodes.rb +20 -0
  44. data/spec/support/knife_command_helpers.rb +11 -0
  45. data/spec/support/shared_examples/collection.rb +24 -0
  46. data/spec/support/shared_examples/dsl_wrapper.rb +11 -0
  47. data/spec/support/shared_examples/node_command.rb +66 -0
  48. metadata +178 -0
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ class DummyCommand < Chef::Knife
4
+ include KnifeSous::ProcessorCommand
5
+ end
6
+
7
+ describe KnifeSous::ProcessorCommand do
8
+ include KnifeCommandHelpers
9
+
10
+ let(:processor) { command }
11
+
12
+ before do
13
+ processor.stub(:instance_eval)
14
+ File.stub(:read)
15
+ end
16
+
17
+ describe "options" do
18
+ it "should set the default node config path" do
19
+ processor.default_config[:node_manifest_file].should == "nodes/nodes.rb"
20
+ end
21
+
22
+ it "should replace node config path with option argument" do
23
+ cmd = command("--node-manifest-file=some/node/thing")
24
+ cmd.config[:node_manifest_file].should == "some/node/thing"
25
+ end
26
+ end
27
+
28
+ describe "#process_config" do
29
+ let(:namespace) { KnifeSous::Namespace.new('root') }
30
+
31
+ before do
32
+ KnifeSous::Namespace.stub(new: namespace )
33
+ namespace.stub(:instance_eval)
34
+ end
35
+
36
+ it "should validate the config" do
37
+ processor.should_receive(:validate_config!)
38
+ processor.process_config
39
+ end
40
+
41
+ it "should create and return root namespace and evaluate the config if file is valid" do
42
+ processor.stub(:validate_config!)
43
+ File.stub(read: 'config contents' )
44
+ processor.stub(manifest_file_path: 'some config path' )
45
+ namespace.should_receive(:instance_eval).with('config contents', 'some config path')
46
+
47
+ processor.process_config.should be_a KnifeSous::Namespace
48
+ end
49
+ end
50
+
51
+ describe "#validate_config" do
52
+ it "should print error and exit if file doesn't exist" do
53
+ File.stub(exists?: false)
54
+ processor.stub(manifest_file_path: 'some config path' )
55
+ processor.ui.should_receive(:fatal).with("Couldn't find some config path")
56
+ lambda { processor.validate_config! }.should raise_error SystemExit
57
+ end
58
+
59
+ it "should print error if file exists but isn't readable and return false" do
60
+ File.stub(exists?: true)
61
+ File.stub(readable?: false)
62
+ processor.stub(manifest_file_path: 'some config path' )
63
+ processor.ui.should_receive(:fatal).with("Can't read some config path")
64
+ lambda { processor.validate_config! }.should raise_error SystemExit
65
+ end
66
+
67
+ it "should return true if file exists and is readable" do
68
+ File.stub(exists?: true)
69
+ File.stub(readable?: true)
70
+ processor.validate_config!.should be_true
71
+ end
72
+ end
73
+
74
+ describe "#manfiest_file_patch" do
75
+ it "should return the full path to the config file" do
76
+ processor.manifest_file_path.should == File.expand_path(File.join(Dir.pwd, 'nodes', 'nodes.rb' ))
77
+ end
78
+ end
79
+
80
+ describe "#root_namespace" do
81
+ it "should process_config" do
82
+ processor.should_receive(:process_config)
83
+ processor.root_namespace
84
+ end
85
+ end
86
+
87
+ describe "#search" do
88
+ let(:root_namespace) { KnifeSous::Namespace.new("root_namespace") }
89
+ let(:nodeA) { KnifeSous::Node.new("nodeA") }
90
+
91
+ before do
92
+ processor.stub(root_namespace: root_namespace)
93
+ end
94
+
95
+ it "should return the target" do
96
+ root_namespace << nodeA
97
+ processor.search(%w[nodeA]).should == nodeA
98
+ end
99
+
100
+ it "should return a namespace if target" do
101
+ foo_space = KnifeSous::Namespace.new("foo")
102
+ bar_space = KnifeSous::Namespace.new("bar")
103
+ baz_space = KnifeSous::Namespace.new("baz")
104
+ root_namespace << foo_space
105
+ foo_space << bar_space
106
+ bar_space << baz_space
107
+ processor.search(%w[foo bar baz]).should == baz_space
108
+ end
109
+
110
+ context do
111
+ before do
112
+ other_namespace = KnifeSous::Namespace.new("other_namespace")
113
+ other_namespace << nodeA
114
+ root_namespace << other_namespace
115
+ end
116
+
117
+ it "shouldn't return nodes, unless fully qualified" do
118
+ processor.search(%w[nodeA other_namespace]).should == nil
119
+ end
120
+
121
+ it "shouldn't return nodes, unless fully qualified" do
122
+ processor.search(%w[nodeA]).should == nil
123
+ end
124
+
125
+ it "should require qualified namespaces" do
126
+ processor.search(%w[other_namespace nodeA]).should == nodeA
127
+ end
128
+ end
129
+ end
130
+
131
+ def command(*args)
132
+ knife_command(DummyCommand, *args)
133
+ end
134
+ end
135
+
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+
4
+ SPEC_ROOT = File.dirname(__FILE__)
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+ end
9
+
10
+ Dir[File.join(SPEC_ROOT, '/../lib/**/*.rb')].each{ |file| require file }
11
+
12
+ Dir[File.join(SPEC_ROOT, 'support', '*.rb')].each{ |file| require file }
13
+ Dir[File.join(SPEC_ROOT, 'support', 'shared_examples', '*.rb')].each{ |file| require file }
14
+
@@ -0,0 +1,20 @@
1
+ def default_options
2
+ {
3
+ node_config: "nodes/some_node.json",
4
+ ssh_port: 22,
5
+ identity_file: "path/to/identity/file"
6
+ }
7
+ end
8
+
9
+ namespace :production do |prod|
10
+ prod.node :node_awesome, default_options.merge!(hostname: '00.12.34.56')
11
+ prod.namespace :web do |web|
12
+ web.node :nodetastic,
13
+ hostname: "12.34.56.789",
14
+ ssh_port: 22,
15
+ identity_file: "path/to/identity"
16
+ end
17
+ end
18
+
19
+ node :vagrant, node_config: 'nodes/some_node.json', ssh_config: 'vagrant config'
20
+
@@ -0,0 +1,11 @@
1
+ module KnifeCommandHelpers
2
+ def knife_command(cmd_class, *args)
3
+ cmd_class.load_deps
4
+ command = cmd_class.new(args)
5
+ command.ui.stub(:msg)
6
+ command.ui.stub(:err)
7
+ command.stub(:show_usage)
8
+ command
9
+ end
10
+ end
11
+
@@ -0,0 +1,24 @@
1
+ shared_examples_for "a collection object" do
2
+ describe "<<" do
3
+ it "adds objects to the end of the collection" do
4
+ collection << 1 << 2
5
+ collection.to_a.should == [1,2]
6
+ end
7
+ end
8
+
9
+ describe "[]" do
10
+ it "gets the object in the collection by its index" do
11
+ collection << 'foo' << 'bar'
12
+ collection[0].should == 'foo'
13
+ collection[1].should == 'bar'
14
+ end
15
+ end
16
+
17
+ describe "first" do
18
+ it "gets the first object in the collection" do
19
+ collection << 'bar' << 'baz'
20
+ collection.first.should == 'bar'
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,11 @@
1
+ shared_examples_for "dsl wrapper" do
2
+ describe "#evaluate_block" do
3
+ it "should support passing itself in as the context" do
4
+ test_block = Proc.new { |i| i.foo 'bar'}
5
+ klass.stub(:foo)
6
+ klass.should_receive(:foo).with('bar')
7
+ klass.evaluate_block(&test_block)
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,66 @@
1
+ shared_examples_for "a node command" do
2
+ describe "#search_for_target" do
3
+ it "should search by the args" do
4
+ search_args = %w[search by these args]
5
+ node_command.name_args = search_args
6
+ node_command.stub(search: 'some search result')
7
+ node_command.should_receive(:search).with(search_args)
8
+ node_command.search_for_target.should == 'some search result'
9
+ end
10
+
11
+ it "should print error and exit if no results found" do
12
+ node_command.stub(search: nil)
13
+ node_command.ui.should_receive(:error).with("Can't find node. Run `knife sous list` to see nodes")
14
+ lambda { node_command.search_for_target }.should raise_error SystemExit
15
+ end
16
+ end
17
+
18
+ describe "#check_args" do
19
+ it "should print error, show usage and exit if no args are passed in" do
20
+ node_command.ui.should_receive(:fatal).with("You need to specificy a node or namespace")
21
+ node_command.should_receive(:show_usage)
22
+ lambda { node_command.check_args}.should raise_error SystemExit
23
+ end
24
+ end
25
+
26
+ describe "#run" do
27
+ before do
28
+ node_command.stub(:process_result)
29
+ node_command.stub(:check_args)
30
+ node_command.stub(:search_for_target)
31
+ end
32
+
33
+ it "should check that the args exist" do
34
+ node_command.should_receive(:check_args)
35
+ node_command.run
36
+ end
37
+
38
+ it "should search for the target" do
39
+ node_command.should_receive(:search_for_target)
40
+ node_command.run
41
+ end
42
+
43
+ it "should process result" do
44
+ node_command.stub(search_for_target: "search results")
45
+ node_command.should_receive(:process_result).with("search results")
46
+ node_command.run
47
+ end
48
+ end
49
+
50
+ describe "#process_result" do
51
+ it "should run solo_command Node" do
52
+ node = KnifeSous::Node.new('node')
53
+ node_command.should_receive(:solo_command).with(node)
54
+ node_command.process_result(node)
55
+ end
56
+
57
+ it "should run solo command on each child if result is a Namespace" do
58
+ namespace = KnifeSous::Namespace.new('namespace')
59
+ namespace << 'child1' << 'child2'
60
+ node_command.should_receive(:solo_command).with('child1')
61
+ node_command.should_receive(:solo_command).with('child2')
62
+ node_command.process_result(namespace)
63
+ end
64
+ end
65
+ end
66
+
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife_sous
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Shaun Dern
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ - !ruby/object:Gem::Dependency
63
+ name: knife-solo
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.2.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.2.0
78
+ description: Knife plugin for managing knife-solo nodes
79
+ email: shaun@substantail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - .gitignore
85
+ - .ruby-version
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - Guardfile
89
+ - README.md
90
+ - Rakefile
91
+ - knife_sous.gemspec
92
+ - lib/chef/knife/sous_bootstrap.rb
93
+ - lib/chef/knife/sous_clean.rb
94
+ - lib/chef/knife/sous_cook.rb
95
+ - lib/chef/knife/sous_init.rb
96
+ - lib/chef/knife/sous_list.rb
97
+ - lib/chef/knife/sous_prepare.rb
98
+ - lib/knife_sous.rb
99
+ - lib/knife_sous/configure_command.rb
100
+ - lib/knife_sous/dsl_definitions.rb
101
+ - lib/knife_sous/dsl_wrapper.rb
102
+ - lib/knife_sous/mixins/hash_mixins.rb
103
+ - lib/knife_sous/namespace.rb
104
+ - lib/knife_sous/namespace_presenter.rb
105
+ - lib/knife_sous/node.rb
106
+ - lib/knife_sous/node_command.rb
107
+ - lib/knife_sous/node_presenter.rb
108
+ - lib/knife_sous/processor_command.rb
109
+ - lib/templates/nodes.example.rb
110
+ - spec/lib/chef/knife/sous_bootstrap_spec.rb
111
+ - spec/lib/chef/knife/sous_clean_spec.rb
112
+ - spec/lib/chef/knife/sous_cook_spec.rb
113
+ - spec/lib/chef/knife/sous_init_spec.rb
114
+ - spec/lib/chef/knife/sous_list_spec.rb
115
+ - spec/lib/chef/knife/sous_prepare_spec.rb
116
+ - spec/lib/knife_sous/configure_command_spec.rb
117
+ - spec/lib/knife_sous/dsl_definitions_spec.rb
118
+ - spec/lib/knife_sous/dsl_wrapper_spec.rb
119
+ - spec/lib/knife_sous/mixins/hash_mixins_spec.rb
120
+ - spec/lib/knife_sous/namespace_presenter_spec.rb
121
+ - spec/lib/knife_sous/namespace_spec.rb
122
+ - spec/lib/knife_sous/node_presenter_spec.rb
123
+ - spec/lib/knife_sous/node_spec.rb
124
+ - spec/lib/knife_sous/processor_command_spec.rb
125
+ - spec/spec_helper.rb
126
+ - spec/support/fixtures/nodes.rb
127
+ - spec/support/knife_command_helpers.rb
128
+ - spec/support/shared_examples/collection.rb
129
+ - spec/support/shared_examples/dsl_wrapper.rb
130
+ - spec/support/shared_examples/node_command.rb
131
+ homepage: http://github.com/substantial/knife_sous
132
+ licenses:
133
+ - MIT
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project: knife_sous
152
+ rubygems_version: 1.8.24
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: A Chef Knife plugin which uses a DSL to configure and manage knife solo nodes.
156
+ Run knife solo commands on one or multiple nodes.
157
+ test_files:
158
+ - spec/lib/chef/knife/sous_bootstrap_spec.rb
159
+ - spec/lib/chef/knife/sous_clean_spec.rb
160
+ - spec/lib/chef/knife/sous_cook_spec.rb
161
+ - spec/lib/chef/knife/sous_init_spec.rb
162
+ - spec/lib/chef/knife/sous_list_spec.rb
163
+ - spec/lib/chef/knife/sous_prepare_spec.rb
164
+ - spec/lib/knife_sous/configure_command_spec.rb
165
+ - spec/lib/knife_sous/dsl_definitions_spec.rb
166
+ - spec/lib/knife_sous/dsl_wrapper_spec.rb
167
+ - spec/lib/knife_sous/mixins/hash_mixins_spec.rb
168
+ - spec/lib/knife_sous/namespace_presenter_spec.rb
169
+ - spec/lib/knife_sous/namespace_spec.rb
170
+ - spec/lib/knife_sous/node_presenter_spec.rb
171
+ - spec/lib/knife_sous/node_spec.rb
172
+ - spec/lib/knife_sous/processor_command_spec.rb
173
+ - spec/spec_helper.rb
174
+ - spec/support/fixtures/nodes.rb
175
+ - spec/support/knife_command_helpers.rb
176
+ - spec/support/shared_examples/collection.rb
177
+ - spec/support/shared_examples/dsl_wrapper.rb
178
+ - spec/support/shared_examples/node_command.rb