furnish-knife-server 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjhkZGNhNTNmNTMxOWYwOWZjM2YwYWY5N2U3OTU4M2Y3ZDdmM2VjNQ==
5
+ data.tar.gz: !binary |-
6
+ ZmNiOGUyZGQyOGFmZjY5MmVkOTM1NGViYmFkM2E4ZWQ1OTQzNWZkOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MzJjZGU2NzFjMTM4Yjk4MDNmN2Y3NTkwZDE0NWRmM2JhYjM0ZDlhYzU5Y2Vl
10
+ MDU0ZDEyMzVmYjlkZGMzMTA4NTE1NmJkMGQ3MTc4MjRiZTdmMWM0NTM5YjVk
11
+ MWNjOGUyOGUzZWRkMjYyMWYyOTVjOTA0ZDY0Mjg2NjY3NGU0MjU=
12
+ data.tar.gz: !binary |-
13
+ MzM5MzEyOGUzZTkzNTMxNTExNWU3MDM2YWExMmJkZjY4YTA0ODAzZDVkNTNh
14
+ ODk0M2E3ZTg0MDMyMGFmNjk5NmIwYjAwYzQwOTZiMTBiY2NkYjRlMGJkZTE1
15
+ ZjRhNjMwNTZhOTRhNTZhNWY2OWJkZTIzMTlmM2UzZTQzNTgxNTY=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ html
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in furnish-knife-server.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ # vim: ft=ruby
2
+ guard 'minitest' do
3
+ # with Minitest::Unit
4
+ watch(%r!^test/(.*)\/?test_(.*)\.rb!)
5
+ watch(%r!^test/helper\.rb!) { "test" }
6
+ end
7
+
8
+ guard 'rake', :run_on_all => false, :task => 'rdoc_cov' do
9
+ watch(%r!^lib/(.*)([^/]+)\.rb!)
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Erik Hollensbe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Furnish Knife Server Integration - Build Chef 10 and 11 Servers as a Provisioner.
2
+
3
+ This provides two provisioners which leverage the near-saintly
4
+ [knife-server](https://github.com/fnichol/knife-server) orchestration to build
5
+ chef servers for Chef 10 and 11.
6
+
7
+ The rather unsurprising provisioner names:
8
+
9
+ * Furnish::Provisioner::Chef10Server
10
+ * Furnish::Provisioner::Chef11Server
11
+
12
+ Build Chef 10 and Chef 11 servers respectively. Since most of the functionality
13
+ is common, they both inherit from:
14
+
15
+ * Furnish::Provisioner::KnifeServer
16
+
17
+ Which implements the knife-server integration.
18
+
19
+ If you're new to [furnish](https://github.com/chef-workflow/furnish), you
20
+ should probably read up on that first.
21
+
22
+ ## Achtung!
23
+
24
+ Just like `knife-server`, after the chef server is built, your `client_key` and
25
+ `validation_key` are moved out of the way, and the new ones created with `knife
26
+ configure -i` are placed in their steads.
27
+
28
+ What this *means* is that you have not set the `config_file` attribute in the
29
+ provisioners to something that is non-standard, very likely `~/.chef/knife.rb`,
30
+ wherever that is on whatever system you use this on, will contain the names of
31
+ the files to throw these credentials into. It is a very good idea to **template
32
+ or generate knife.rb** in a way that allows you careful control of how these
33
+ files get generated. The provisioners do not do you any extra favors other than
34
+ that.
35
+
36
+ ## Testing
37
+
38
+ There is a full test suite that uses our
39
+ [furnish-vagrant](https://github.com/chef-workflow/furnish-vagrant) and
40
+ [furnish-ip](https://github.com/chef-workflow/furnish-ip) provisioners to
41
+ orchestrate locally. As of this writing one machine is created for Chef 10, and
42
+ another for Chef 11. They both use the "precise64" [vagrant box](http://vagrantbox.es),
43
+ and it will be downloaded on your first test run if you do not have it.
44
+
45
+ The tests are not fast and communicate very little by default. Output goes
46
+ through furnish's logging system which is directed to a file by default. If you
47
+ wish to change this, set `FURNISH_DEBUG` in your environment, and information
48
+ about the run will be output to the TTY.
49
+
50
+ ## Installation
51
+
52
+ Add this line to your application's Gemfile:
53
+
54
+ gem 'furnish-knife-server'
55
+
56
+ And then execute:
57
+
58
+ $ bundle
59
+
60
+ Or install it yourself as:
61
+
62
+ $ gem install furnish-knife-server
63
+
64
+ ## Huge Thanks
65
+
66
+ Fletcher Nichol did most of the work in knife-server itself, this is just the
67
+ glue. He's also been really keen on accepting both bug fixes and patches --
68
+ making it an easy decision to lean on his software to solve this problem.
69
+
70
+ So, thanks!
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
77
+ 4. Push to the branch (`git push origin my-new-feature`)
78
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList["test/test_*.rb"]
8
+ t.verbose = true
9
+ end
10
+
11
+ RDoc::Task.new do |rdoc|
12
+ rdoc.title = "Furnish provisioner for knife-server -- automate a build of a chef server"
13
+ rdoc.main = "README.md"
14
+ rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
15
+ rdoc.rdoc_files -= ["lib/furnish/knife-server/version.rb"]
16
+ if ENV["RDOC_COVER"]
17
+ rdoc.options << "-C"
18
+ end
19
+ end
20
+
21
+ desc "run tests with coverage report"
22
+ task "test:coverage" do
23
+ ENV["COVERAGE"] = "1"
24
+ Rake::Task["test"].invoke
25
+ end
26
+
27
+ desc "run rdoc with coverage report"
28
+ task :rdoc_cov do
29
+ # ugh
30
+ ENV["RDOC_COVER"] = "1"
31
+ ruby "-S rake rerdoc"
32
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'furnish/knife-server/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "furnish-knife-server"
8
+ gem.version = Furnish::KnifeServer::VERSION
9
+ gem.authors = ["Erik Hollensbe"]
10
+ gem.email = ["erik+github@hollensbe.org"]
11
+ gem.description = %q{Furnish provisioner for knife-server -- automate a build of a chef-server}
12
+ gem.summary = %q{Furnish provisioner for knife-server -- automate a build of a chef-server}
13
+ gem.homepage = "https://github.com/chef-workflow/furnish-knife-server"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'knife-server', '~> 1.0.1'
21
+ gem.add_dependency 'furnish', '~> 0.1.0'
22
+
23
+ gem.add_development_dependency 'furnish-vagrant', '~> 0.1.0'
24
+ gem.add_development_dependency 'furnish-ip', '~> 0.1.0'
25
+ gem.add_development_dependency 'rake'
26
+ gem.add_development_dependency 'minitest', '~> 4.5.0'
27
+ gem.add_development_dependency 'guard-minitest'
28
+ gem.add_development_dependency 'guard-rake', '~> 0.0.8'
29
+ gem.add_development_dependency 'rdoc', '~> 4'
30
+ gem.add_development_dependency 'rb-fsevent'
31
+ gem.add_development_dependency 'simplecov'
32
+ end
@@ -0,0 +1,6 @@
1
+ module Furnish # :nodoc:
2
+ module KnifeServer # :nodoc:
3
+ # The version of furnish-knife-server.
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
@@ -0,0 +1,53 @@
1
+ require 'furnish/provisioners/knife_server'
2
+
3
+ module Furnish # :nodoc:
4
+ module Provisioner # :nodoc:
5
+ #
6
+ # Builds a Chef 10 Server as a part of a Furnish::ProvisionerGroup.
7
+ #
8
+ # Please see Furnish::Provisioner::Chef10Server#new and
9
+ # Furnish::Provisioner::KnifeServer for information on how to create
10
+ # this provisioner.
11
+ #
12
+ class Chef10Server < KnifeServer
13
+ ##
14
+ # :attr: platform
15
+ #
16
+ # Actually just Furnish::Provisioner::KnifeServer#platform with a default
17
+ # of "auto".
18
+
19
+ ##
20
+ # :attr: bootstrap_version
21
+ #
22
+ # Actually just Furnish::Provisioner::KnifeServer#bootstrap_version with
23
+ # a default of "10.24.0".
24
+
25
+ ##
26
+ # Construct a provisioner.
27
+ #
28
+ # There are a large number of arguments covered in
29
+ # Furnish::Provisioner::KnifeServer that apply to all provisioners
30
+ # that inherit from it, so you should read that too.
31
+ #
32
+ # The defaults here are:
33
+ # * #platform: "auto" -- this is knife-server speak for "figure it out"
34
+ # * #bootstrap_version: "10.24.0"
35
+ #
36
+ # Note that bootstrap versions that do not start with "10" or "0.10" will
37
+ # raise during provisioner construction.
38
+ #
39
+ # It takes a hash of arguments, which maps to the attributes described in
40
+ # this class and KnifeServer.
41
+ def initialize(args)
42
+ super
43
+
44
+ @platform ||= "auto"
45
+ @bootstrap_version ||= "10.24.0"
46
+
47
+ unless @bootstrap_version =~ /^10\./ or @bootstrap_version =~ /^0\.10/
48
+ raise ArgumentError, "#{self.class} provisioner requires a bootstrap version in the 10.x series"
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ require 'furnish/provisioners/knife_server'
2
+
3
+ module Furnish # :nodoc:
4
+ module Provisioner # :nodoc:
5
+ #
6
+ # Builds a Chef 11 Server as a part of a Furnish::ProvisionerGroup.
7
+ #
8
+ # Please see Furnish::Provisioner::Chef11Server#new and
9
+ # Furnish::Provisioner::KnifeServer for information on how to create
10
+ # this provisioner.
11
+ #
12
+ class Chef11Server < KnifeServer
13
+ ##
14
+ # :attr: platform
15
+ #
16
+ # Actually just Furnish::Provisioner::KnifeServer#platform with a default
17
+ # of "omnibus".
18
+
19
+ ##
20
+ # :attr: bootstrap_version
21
+ #
22
+ # Actually just Furnish::Provisioner::KnifeServer#bootstrap_version with
23
+ # a default of "11.0.6".
24
+
25
+ ##
26
+ # Construct a provisioner.
27
+ #
28
+ # There are a large number of arguments covered in
29
+ # Furnish::Provisioner::KnifeServer that apply to all provisioners
30
+ # that inherit from it, so you should read that too.
31
+ #
32
+ # The defaults here are:
33
+ # * #platform: "omnibus" -- this is knife-server speak for "use erchef omnibus", and should be portable.
34
+ # * #bootstrap_version: "11.0.6"
35
+ #
36
+ # Note that bootstrap versions that do not start with "11" will raise
37
+ # during provisioner construction.
38
+ #
39
+ # It takes a hash of arguments, which maps to the attributes described in
40
+ # this class and KnifeServer.
41
+ def initialize(args)
42
+ super
43
+
44
+ @platform = "omnibus"
45
+ @bootstrap_version ||= "11.0.6"
46
+
47
+ unless @bootstrap_version =~ /^11\./
48
+ raise ArgumentError, "#{self.class} provisioner requires a bootstrap version in the 11.x series"
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,201 @@
1
+ require 'furnish/provisioners/api'
2
+ require 'chef/knife/ssh' # required for chef 10.12
3
+ require 'chef/knife/server_bootstrap_standalone'
4
+
5
+ module Furnish # :nodoc:
6
+ module Provisioner # :nodoc:
7
+ #
8
+ # Base class for Chef10Server and Chef11Server provisioners. The
9
+ # constructor and attributes in here are very important to know to use the
10
+ # other provisioners effectively.
11
+ #
12
+ class KnifeServer < API
13
+ ##
14
+ # :attr: ssh_user
15
+ #
16
+ # The user to connect as. Required.
17
+ #
18
+ furnish_property :ssh_user,
19
+ "The user to connect as.",
20
+ String
21
+
22
+ ##
23
+ # :attr: ssh_password
24
+ #
25
+ # The ssh password. This or #ssh_identity_file must be set.
26
+ #
27
+ furnish_property :ssh_password,
28
+ "The ssh password. This or :ssh_identity_file must be set.",
29
+ String
30
+
31
+ ##
32
+ # :attr: ssh_identity_file
33
+ #
34
+ # Path to a SSH private key. This or #ssh_password must be set.
35
+ #
36
+ furnish_property :ssh_identity_file,
37
+ "Path to a SSH private key. This or :ssh_password must be set.",
38
+ String
39
+
40
+ ##
41
+ # :attr: node_name
42
+ #
43
+ # The node name of the chef server. default is "test-chef-server".
44
+ #
45
+ furnish_property :node_name,
46
+ "The node name for the chef server. default: test-chef-server",
47
+ String
48
+
49
+ ##
50
+ # :attr: platform
51
+ #
52
+ # Platform as supplied to knife-server. Defaults are present in subclasses.
53
+ #
54
+ furnish_property :platform,
55
+ "Platform as supplied to knife-server. Defaults are present in subclasses.",
56
+ String
57
+
58
+ ##
59
+ # :attr: bootstrap_version
60
+ #
61
+ # Version of chef to bootstrap. Defaults are present in subclasses.
62
+ #
63
+ furnish_property :bootstrap_version,
64
+ "Version of chef to bootstrap. Defaults are present in subclasses.",
65
+ String
66
+
67
+ ##
68
+ # :attr: install_test
69
+ #
70
+ # Run opscode pedant after installation to test the chef server. Only
71
+ # works on Chef 11. Default is false.
72
+ #
73
+ furnish_property :install_test,
74
+ "Use opscode pedant to test the chef server after provision? Default false."
75
+
76
+ ##
77
+ # :attr: config_file
78
+ #
79
+ # Path to knife.rb configuration. Yielded to following provisioners after
80
+ # startup succeeds.
81
+ #
82
+ furnish_property :config_file,
83
+ "Path to knife.rb configuration.",
84
+ String
85
+
86
+ configure_startup do
87
+ requires :ips, "Set of IPs. Will use first one.", Set
88
+ yields :config_file, "Path to knife.rb used to bootstrap server", Set
89
+ yields :chef_server_ip, "IP address of bootstrapped chef server", Set
90
+ end
91
+
92
+ configure_shutdown { accepts_from_any true }
93
+
94
+ ##
95
+ # This is the base class constructor for Chef10Server and Chef11Server
96
+ # provisioners.
97
+ #
98
+ # It takes a hash of arguments, which maps to the attributes described in
99
+ # this class, so go read those. If a hash is not supplied, this will
100
+ # raise an ArgumentError.
101
+ #
102
+ # The minimum you will need for either provisioner is `ssh_user` and
103
+ # `ssh_password` or `ssh_identity_file`. Other defaults are provided
104
+ # based on the class used.
105
+ #
106
+ def initialize(args)
107
+ super
108
+
109
+ @node_name ||= "test-chef-server"
110
+
111
+ check_ssh_args
112
+ end
113
+
114
+ ##
115
+ #
116
+ # Helper to ensure that ssh arguments are passed properly.
117
+ #
118
+ def check_ssh_args
119
+ unless ssh_user
120
+ raise ArgumentError, "ssh_user must be supplied!"
121
+ end
122
+
123
+ unless ssh_password or ssh_identity_file
124
+ raise ArgumentError, "ssh_password or ssh_identity_file must be provided"
125
+ end
126
+ end
127
+
128
+ #--
129
+ # FIXME
130
+ #
131
+ # copied from chef-workflow/support/knife-plugin -- move to furnish-chef
132
+ # once finished
133
+ #
134
+ # also a copy in test suite and provisioner for knife-server
135
+ #++
136
+
137
+ #
138
+ # shim to make knife plugins as code -- will be disappearing soon.
139
+ #
140
+ def init_knife_plugin(klass, args)
141
+ require 'stringio'
142
+
143
+ require 'chef/application/knife'
144
+ require 'chef/knife'
145
+ require 'chef/config'
146
+
147
+ Chef::Config.from_file(config_file) if config_file
148
+
149
+ klass.options = Chef::Application::Knife.options.merge(klass.options)
150
+ klass.load_deps
151
+ cli = klass.new(args)
152
+ cli.ui = Chef::Knife::UI.new(
153
+ Furnish.logger,
154
+ Furnish.logger,
155
+ StringIO.new('', 'r'),
156
+ cli.config
157
+ )
158
+
159
+ return cli
160
+ end
161
+
162
+ #
163
+ # Provision a Chef Server with knife-server. Takes the first IP address
164
+ # from a set of IP addresses called :ips as its incoming argument.
165
+ #
166
+ # Yields the ip of the chef server as :chef_server_ip, and the config
167
+ # file used to bootstrap it as :config_file (see #config_file)
168
+ #
169
+ def startup(args={})
170
+ ip = args[:ips].first
171
+
172
+ raise "No IP to use for the chef server" unless ip
173
+
174
+ args = %W[--node-name #{node_name} --host #{ip} --platform #{platform} --bootstrap-version #{bootstrap_version} --ssh-user #{ssh_user}]
175
+
176
+ args += %W[--no-test] unless install_test
177
+ args += %W[--ssh-password #{ssh_password}] if ssh_password
178
+ args += %W[--identity-file #{ssh_identity_file}] if ssh_identity_file
179
+
180
+ init_knife_plugin(Chef::Knife::ServerBootstrapStandalone, args).run
181
+ return({ :config_file => config_file, :chef_server_ip => ip })
182
+ end
183
+
184
+ #
185
+ # Teardown a Chef Server -- current does nothing, as the machine is
186
+ # expected to be torn down instead.
187
+ #
188
+ def shutdown(args={ })
189
+ { }
190
+ end
191
+
192
+ #
193
+ # Reporting facility produces the name of the group, the name of the node
194
+ # the chef server owns, and the platform used to build it.
195
+ #
196
+ def report
197
+ [furnish_group_name, "node name: #{node_name}", "platform: #{platform}"]
198
+ end
199
+ end
200
+ end
201
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'bundler/setup'
2
+
3
+ if ENV["COVERAGE"]
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter '/test/'
7
+ end
8
+ end
9
+
10
+ unless ENV["FURNISH_DEBUG"]
11
+ $stderr.puts <<-EOF
12
+
13
+ These tests are *SLOW* and take some time to run with very little feedback.
14
+ If you want output of what is going on in the test suite, set FURNISH_DEBUG
15
+ in your environment.
16
+
17
+ EOF
18
+ end
19
+
20
+ require 'furnish/test'
21
+ require 'furnish/provisioners/auto_ip'
22
+ require 'furnish/provisioners/vagrant'
23
+ require 'tc' # test/tc.rb
24
+ require 'minitest/autorun'
data/test/tc.rb ADDED
@@ -0,0 +1,110 @@
1
+ #
2
+ # This is a specialized test case for orchestrating against the knife-server
3
+ # bits with a vagrant box.
4
+ #
5
+ class Furnish::KnifeServerTestCase < Furnish::SchedulerTestCase
6
+ BOX_URL = "http://files.vagrantup.com/precise64.box"
7
+
8
+ def setup
9
+ super
10
+ sched.serial = true
11
+ end
12
+
13
+ def teardown
14
+ sched.teardown
15
+ super
16
+ end
17
+
18
+ def ip
19
+ @ip = Furnish::IP.new("10.10.10.0/24")
20
+ @ip.allocate("10.10.10.0")
21
+ @ip.allocate("10.10.10.1")
22
+ @ip
23
+ end
24
+
25
+ def machine_provisioner
26
+ [
27
+ Furnish::Provisioner::AutoIP.new(:ip => ip),
28
+ Furnish::Provisioner::Vagrant.new(:box_url => BOX_URL)
29
+ ]
30
+ end
31
+
32
+ def build_knife_config(chef_dir=nil, ip=nil)
33
+ require 'tempfile'
34
+
35
+ chef_dir ||= Dir.mktmpdir
36
+
37
+ content = <<-EOF
38
+ log_level :info
39
+ log_location STDOUT
40
+ node_name 'test-user'
41
+ client_key File.join('#{chef_dir}', 'admin.pem')
42
+ validation_client_name 'chef-validator'
43
+ validation_key File.join('#{chef_dir}', 'validation.pem')
44
+ cache_type 'BasicFile'
45
+ ssl_verify_mode :verify_none
46
+ cache_options( :path => File.join('#{chef_dir}', 'checksums' ))
47
+ class Net::HTTP
48
+ unless @knife_patched
49
+ alias original_initialize initialize
50
+
51
+ def initialize(*args)
52
+ original_initialize(*args)
53
+ self.ssl_version = :TLSv1
54
+ end
55
+ @knife_patched = true
56
+ end
57
+ end
58
+ EOF
59
+
60
+ if ip
61
+ content += <<-EOF
62
+ chef_server_url 'https://#{ip}'
63
+ EOF
64
+ end
65
+
66
+ File.binwrite(File.join(chef_dir, 'knife.rb'), content)
67
+
68
+ return chef_dir
69
+ end
70
+
71
+ #--
72
+ # FIXME
73
+ #
74
+ # copied from chef-workflow/support/knife-plugin -- move to furnish-chef
75
+ # once finished
76
+ #
77
+ # also a copy in test suite and provisioner for knife-server
78
+ #++
79
+
80
+ def init_knife_plugin(klass, args, config_file=nil)
81
+ require 'stringio'
82
+
83
+ require 'chef/application/knife'
84
+ require 'chef/knife'
85
+ require 'chef/config'
86
+
87
+ Chef::Config.from_file(config_file) if config_file
88
+
89
+ klass.options = Chef::Application::Knife.options.merge(klass.options)
90
+ klass.load_deps
91
+ cli = klass.new(args)
92
+ cli.ui = Chef::Knife::UI.new(
93
+ Furnish.logger,
94
+ Furnish.logger,
95
+ StringIO.new('', 'r'),
96
+ cli.config
97
+ )
98
+
99
+ return cli
100
+ end
101
+
102
+ def assert_chef_server_works(config_dir)
103
+ require 'chef/knife/node_list'
104
+ init_knife_plugin(Chef::Knife::NodeList, [], File.join(config_dir, 'knife.rb')).run
105
+ assert(true, "chef server for #{config_dir} is alive")
106
+ rescue Exception => e
107
+ Furnish.logger.puts e.inspect
108
+ assert(false, "chef server for #{config_dir} is alive")
109
+ end
110
+ end
@@ -0,0 +1,60 @@
1
+ require 'helper'
2
+ require 'furnish/provisioners/chef10_server'
3
+ require 'fileutils'
4
+
5
+ class TestChef10Server < Furnish::KnifeServerTestCase
6
+ def test_constructor
7
+ # XXX see test_knife_server for other validations to this constructor.
8
+
9
+ assert_raises(
10
+ ArgumentError,
11
+ "Furnish::Provisioner::Chef10Server provisioner requires a bootstrap version in the 10.x series"
12
+ ) do
13
+ Furnish::Provisioner::Chef10Server.new(
14
+ :ssh_user => "foo",
15
+ :ssh_password => "bar",
16
+ :bootstrap_version => "11.4.0"
17
+ )
18
+ end
19
+
20
+ obj = Furnish::Provisioner::Chef10Server.new(
21
+ :ssh_user => "foo",
22
+ :ssh_password => "bar"
23
+ )
24
+
25
+ assert_kind_of(Furnish::Provisioner::KnifeServer, obj)
26
+ assert_equal("auto", obj.platform, "platform defaults to auto")
27
+ assert_equal("10.24.0", obj.bootstrap_version, "bootstrap_version defaults to 10.24.0")
28
+ end
29
+
30
+ def test_basic_provision
31
+ config_dir = build_knife_config
32
+ assert(config_dir, "build knife configuration directory")
33
+
34
+ this_prov = Furnish::Provisioner::Chef10Server.new(
35
+ :ssh_user => "vagrant",
36
+ :ssh_password => "vagrant",
37
+ :config_file => File.join(config_dir, "knife.rb")
38
+ )
39
+
40
+ sched.schedule_provision("test1", machine_provisioner + [this_prov], [])
41
+ sched.run
42
+
43
+ assert_solved("test1")
44
+
45
+ build_knife_config(config_dir, ip.group_ips("test1").first)
46
+
47
+ assert_chef_server_works(config_dir)
48
+ assert_equal(
49
+ [
50
+ "test1",
51
+ "node name: test-chef-server",
52
+ "platform: auto"
53
+ ],
54
+ this_prov.report,
55
+ "report yields data about the chef server"
56
+ )
57
+ ensure
58
+ FileUtils.rm_rf(config_dir) if config_dir
59
+ end
60
+ end
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+ require 'furnish/provisioners/chef11_server'
3
+ require 'fileutils'
4
+
5
+ class TestChef11Server < Furnish::KnifeServerTestCase
6
+ def test_constructor
7
+ # XXX see test_knife_server for other validations to this constructor.
8
+
9
+ assert_raises(
10
+ ArgumentError,
11
+ "Furnish::Provisioner::Chef11Server provisioner requires a bootstrap version in the 11.x series"
12
+ ) do
13
+ Furnish::Provisioner::Chef11Server.new(
14
+ :ssh_user => "foo",
15
+ :ssh_password => "bar",
16
+ :bootstrap_version => "10.24.0"
17
+ )
18
+ end
19
+
20
+ obj = Furnish::Provisioner::Chef11Server.new(
21
+ :ssh_user => "foo",
22
+ :ssh_password => "bar"
23
+ )
24
+
25
+ assert_kind_of(Furnish::Provisioner::KnifeServer, obj)
26
+ assert_equal("omnibus", obj.platform, "platform defaults to omnibus")
27
+ assert_equal("11.0.6", obj.bootstrap_version, "bootstrap_version defaults to 11.4.0")
28
+
29
+ obj = Furnish::Provisioner::Chef11Server.new(
30
+ :ssh_user => "foo",
31
+ :ssh_password => "bar",
32
+ :platform => "auto"
33
+ )
34
+
35
+ assert_equal("omnibus", obj.platform, "platform cannot be changed from 'omnibus'")
36
+ end
37
+
38
+ def test_basic_provision
39
+ config_dir = build_knife_config
40
+ assert(config_dir, "build knife configuration directory")
41
+
42
+ this_prov = Furnish::Provisioner::Chef11Server.new(
43
+ :ssh_user => "vagrant",
44
+ :ssh_password => "vagrant",
45
+ :config_file => File.join(config_dir, "knife.rb")
46
+ )
47
+
48
+ sched.schedule_provision("test1", machine_provisioner + [this_prov], [])
49
+ sched.run
50
+
51
+ assert_solved("test1")
52
+
53
+ build_knife_config(config_dir, ip.group_ips("test1").first)
54
+ assert_chef_server_works(config_dir)
55
+
56
+ assert_equal(
57
+ [
58
+ "test1",
59
+ "node name: test-chef-server",
60
+ "platform: omnibus"
61
+ ],
62
+ this_prov.report,
63
+ "report yields data about the chef server"
64
+ )
65
+ ensure
66
+ FileUtils.rm_rf(config_dir) if config_dir
67
+ end
68
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+ require 'furnish/provisioners/knife_server'
3
+
4
+ class TestKnifeServer < Furnish::KnifeServerTestCase
5
+ def test_constructor
6
+ assert_raises(ArgumentError, "arguments must be a kind of hash!") { Furnish::Provisioner::KnifeServer.new(nil) }
7
+ assert_raises(ArgumentError, "ssh_user must be supplied!") { Furnish::Provisioner::KnifeServer.new({}) }
8
+ assert_raises(ArgumentError, "ssh_password or ssh_identity_file must be provided") { Furnish::Provisioner::KnifeServer.new(:ssh_user => "foo") }
9
+
10
+ obj = Furnish::Provisioner::KnifeServer.new(
11
+ :ssh_user => "foo",
12
+ :ssh_password => "bar"
13
+ )
14
+
15
+ assert_equal("test-chef-server", obj.node_name, "node_name defaults to test-chef-server")
16
+ assert_nil(obj.ssh_identity_file, "ssh_identity_file is nil")
17
+ assert_nil(obj.config_file, "config_file defaults to nil")
18
+ assert_nil(obj.install_test, "install_test defaults to nil")
19
+
20
+ args = {
21
+ :ssh_user => "foo",
22
+ :ssh_identity_file => "id_rsa",
23
+ :platform => "poo",
24
+ :node_name => "blah",
25
+ :bootstrap_version => "10.10.0",
26
+ :config_file => "knife.rb",
27
+ :install_test => true
28
+ }
29
+
30
+ obj = Furnish::Provisioner::KnifeServer.new(args)
31
+
32
+ args.each do |key, value|
33
+ assert_equal(value, obj.send(key), "attrs are being set from constructor hash")
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: furnish-knife-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Erik Hollensbe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: knife-server
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: furnish
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: furnish-vagrant
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: furnish-ip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 4.5.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 4.5.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.8
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 0.0.8
125
+ - !ruby/object:Gem::Dependency
126
+ name: rdoc
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '4'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rb-fsevent
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Furnish provisioner for knife-server -- automate a build of a chef-server
168
+ email:
169
+ - erik+github@hollensbe.org
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - .gitignore
175
+ - Gemfile
176
+ - Guardfile
177
+ - LICENSE.txt
178
+ - README.md
179
+ - Rakefile
180
+ - furnish-knife-server.gemspec
181
+ - lib/furnish/knife-server/version.rb
182
+ - lib/furnish/provisioners/chef10_server.rb
183
+ - lib/furnish/provisioners/chef11_server.rb
184
+ - lib/furnish/provisioners/knife_server.rb
185
+ - test/helper.rb
186
+ - test/tc.rb
187
+ - test/test_chef10_server.rb
188
+ - test/test_chef11_server.rb
189
+ - test/test_knife_server.rb
190
+ homepage: https://github.com/chef-workflow/furnish-knife-server
191
+ licenses: []
192
+ metadata: {}
193
+ post_install_message:
194
+ rdoc_options: []
195
+ require_paths:
196
+ - lib
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ! '>='
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ requirements: []
208
+ rubyforge_project:
209
+ rubygems_version: 2.0.3
210
+ signing_key:
211
+ specification_version: 4
212
+ summary: Furnish provisioner for knife-server -- automate a build of a chef-server
213
+ test_files:
214
+ - test/helper.rb
215
+ - test/tc.rb
216
+ - test/test_chef10_server.rb
217
+ - test/test_chef11_server.rb
218
+ - test/test_knife_server.rb