knife-server 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.cane +1 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +3 -0
  5. data/.travis.yml +12 -8
  6. data/CHANGELOG.md +32 -1
  7. data/Gemfile +9 -4
  8. data/Guardfile +28 -0
  9. data/README.md +28 -5
  10. data/Rakefile +31 -10
  11. data/knife-server.gemspec +18 -8
  12. data/lib/chef/knife/bootstrap/_omnibus.sh +63 -10
  13. data/lib/chef/knife/bootstrap/chef10/rhel.erb +2 -0
  14. data/lib/chef/knife/bootstrap/chef11/omnibus.erb +4 -1
  15. data/lib/chef/knife/bootstrap/chef11/rhel.erb +2 -0
  16. data/lib/chef/knife/server_backup.rb +24 -10
  17. data/lib/chef/knife/server_bootstrap_base.rb +68 -23
  18. data/lib/chef/knife/server_bootstrap_ec2.rb +33 -20
  19. data/lib/chef/knife/server_bootstrap_linode.rb +20 -13
  20. data/lib/chef/knife/server_bootstrap_openstack.rb +128 -0
  21. data/lib/chef/knife/server_bootstrap_standalone.rb +28 -16
  22. data/lib/chef/knife/server_restore.rb +23 -9
  23. data/lib/knife-server.rb +1 -0
  24. data/lib/knife/server/credentials.rb +78 -42
  25. data/lib/knife/server/ec2_security_group.rb +24 -21
  26. data/lib/knife/server/ssh.rb +54 -18
  27. data/lib/knife/server/version.rb +2 -1
  28. data/spec/chef/knife/server_backup_spec.rb +58 -44
  29. data/spec/chef/knife/server_bootstrap_ec2_spec.rb +108 -80
  30. data/spec/chef/knife/server_bootstrap_linode_spec.rb +93 -64
  31. data/spec/chef/knife/server_bootstrap_openstack_spec.rb +305 -0
  32. data/spec/chef/knife/server_bootstrap_standalone_spec.rb +113 -76
  33. data/spec/chef/knife/server_restore_spec.rb +38 -37
  34. data/spec/knife/server/credientials_spec.rb +248 -51
  35. data/spec/knife/server/ec2_security_group_spec.rb +76 -68
  36. data/spec/knife/server/ssh_spec.rb +138 -22
  37. metadata +107 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ac23ba3967334f48e3bad6406358d0653812228
4
- data.tar.gz: b1a1d3dd1f2616444e7a9fbe1bd3dde52a696091
3
+ metadata.gz: 27f50b0e90320e91ee8aa88d87c08dbf570f856e
4
+ data.tar.gz: deabf7cb66885f2566953221cfa843753e6b7aad
5
5
  SHA512:
6
- metadata.gz: 9a19382e580ef0d6336bb74f5bef965641785c6f81c327a84d459195e82a67783181805cb6d4e2f9dc34077b13eb2ce2e504d5718e35380a7173cd770a2b171a
7
- data.tar.gz: bb62f7d5d3c90f81e071aa975abfa9fc9be7625c6b9e1af375978a5cd689bc57e03400559a37e00785b074e35ea06c38f476e57e442679c3e8c11b3244e68a93
6
+ metadata.gz: ae51fa3de1500febc09772c79edc354db518afb0e42b5c649db0fc7e2e5e3c50517b48c7499c1f5677044c6580ba8319d694f9dfe9cd10a92ef029262efa3962
7
+ data.tar.gz: 21b67c8ca3a1e0ce7f54bd600d9a8c9999a711ccfa23c660515403434608efdf73b423b06acf717f0879c20a6987c16ede9da701bd3a5b376df126f50e183a82
data/.cane ADDED
@@ -0,0 +1 @@
1
+ --abc-exclude Knife::Server::SSH#exec_ssh
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ Style/FileName:
2
+ Exclude:
3
+ - lib/knife-server.rb
data/.travis.yml CHANGED
@@ -1,15 +1,19 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 1.9.2
6
- - ruby-head
4
+ - 2.1
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - ruby-head
7
8
 
8
9
  env:
9
- - "CHEF_VERSION=11.4.0"
10
- - "CHEF_VERSION=10.24.0"
11
- - "CHEF_VERSION=0.10.10"
10
+ - "CHEF_VERSION="
11
+ - "CHEF_VERSION='~> 11.14.2'"
12
+ - "CHEF_VERSION='~> 11.4.4'"
13
+ - "CHEF_VERSION='~> 10.26'"
14
+
15
+ bundler_args: --without guard
12
16
 
13
17
  matrix:
14
18
  allow_failures:
15
- - rvm: ruby-head
19
+ - rvm: ruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## 1.2.0 / 2014-09-13
2
+
3
+ ### Upstream changes
4
+
5
+ * Pull request [#48][], issue [#50][]: Fix issue affecting newer Knife/Chef versions dealing with nil default options. ([@dldinternet][], [@fnichol][])
6
+ * Patch specific versions of Chef to fix `knife configure` bug. ([@fnichol][])
7
+
8
+ ### New features
9
+
10
+ * Pull request [#51][]: Add OpenStack support to knife-server command. ([@johnbellone][])
11
+ * Re-use existing private user key for omnibus bootstraps. ([@fnichol][])
12
+ * Add support for downloading packages from a URL using the `--url` flag. ([@fnichol][])
13
+
14
+ ### Improvements
15
+
16
+ * Pull request [#43][]: Enable ssh on firewall. ([@taylor][])
17
+ * Add output when backing up and writing keys locally. ([@fnichol][])
18
+ * Issue [#28][]: Shunt stderr/ioctl warnings to a tmp log file for knife configure. ([@fnichol][])
19
+ * Issue [#9][], issue [#10][]: Validate that node_name & client_key are set when running plugins, giving the user a hint that their local knife.rb is not currently set up correctly. ([@fnichol][])
20
+ * Update download URL for Omnibus packages. ([@fnichol][])
21
+ * Update testing dependencies, upgrade to RSpec 3.x, freshen TravisCI build matrix, add style and complexity support. ([@fnichol][])
22
+
23
+
1
24
  ## 1.1.0 / 2013-07-26
2
25
 
3
26
  ### New features
@@ -161,18 +184,26 @@ The initial release.
161
184
  [#11]: https://github.com/fnichol/knife-server/issues/11
162
185
  [#13]: https://github.com/fnichol/knife-server/issues/13
163
186
  [#15]: https://github.com/fnichol/knife-server/issues/15
187
+ [#28]: https://github.com/fnichol/knife-server/issues/28
164
188
  [#29]: https://github.com/fnichol/knife-server/issues/29
165
189
  [#34]: https://github.com/fnichol/knife-server/issues/34
166
190
  [#35]: https://github.com/fnichol/knife-server/issues/35
167
191
  [#41]: https://github.com/fnichol/knife-server/issues/41
168
192
  [#42]: https://github.com/fnichol/knife-server/issues/42
193
+ [#43]: https://github.com/fnichol/knife-server/issues/43
194
+ [#48]: https://github.com/fnichol/knife-server/issues/48
195
+ [#50]: https://github.com/fnichol/knife-server/issues/50
196
+ [#51]: https://github.com/fnichol/knife-server/issues/51
169
197
  [@danryan]: https://github.com/danryan
198
+ [@dldinternet]: https://github.com/dldinternet
170
199
  [@erikh]: https://github.com/erikh
171
200
  [@fnichol]: https://github.com/fnichol
172
201
  [@iafonov]: https://github.com/iafonov
202
+ [@johnbellone]: https://github.com/johnbellone
173
203
  [@jssjr]: https://github.com/jssjr
174
204
  [@ranjib]: https://github.com/ranjib
175
205
  [@sawanoboly]: https://github.com/sawanoboly
176
206
  [@stormsilver]: https://github.com/stormsilver
207
+ [@taylor]: https://github.com/taylor
177
208
  [@wpeterson]: https://github.com/wpeterson
178
- [@xdissent]: https://github.com/xdissent
209
+ [@xdissent]: https://github.com/xdissent
data/Gemfile CHANGED
@@ -1,11 +1,16 @@
1
- source 'https://rubygems.org'
1
+ # -*- encoding: utf-8 -*-
2
+ source "https://rubygems.org"
2
3
 
3
4
  # Specify your gem's dependencies in knife-server.gemspec
4
5
  gemspec
5
6
 
6
- group :test do
7
- gem 'rake', '~> 0.9'
7
+ group :guard do
8
+ gem "guard-rspec"
9
+ gem "guard-rubocop"
10
+ gem "guard-cane"
11
+ end
8
12
 
13
+ group :test do
9
14
  # allow CI to override the version of Chef for matrix testing
10
- gem 'chef', (ENV['CHEF_VERSION'] || '>= 0.10.10')
15
+ gem "chef", (ENV["CHEF_VERSION"] || ">= 0.10.10")
11
16
  end
data/Guardfile ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ ignore %r{^\.gem/}
3
+
4
+ def rspec_opts
5
+ { :cmd => "bundle exec rspec" }
6
+ end
7
+
8
+ def rubocop_opts
9
+ { :all_on_start => false, :keep_failed => false, :cli => "-r finstyle -D" }
10
+ end
11
+
12
+ group :red_green_refactor, :halt_on_fail => true do
13
+ guard :rspec, rspec_opts do
14
+ watch(%r{^spec/(.*)_spec\.rb})
15
+ watch(%r{^lib/(.*)([^/]+)\.rb}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
16
+ watch(%r{^spec/spec_helper\.rb}) { "spec" }
17
+ end
18
+
19
+ guard :cane do
20
+ watch(%r{.*\.rb})
21
+ watch(".cane")
22
+ end
23
+
24
+ guard :rubocop, rubocop_opts do
25
+ watch(%r{.+\.rb$})
26
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
27
+ end
28
+ end
data/README.md CHANGED
@@ -20,7 +20,7 @@ $ knife server bootstrap ec2 \
20
20
  --aws-secret-access-key $AWS_SECRET_ACCESS_KEY \
21
21
  --region us-east-1 \
22
22
  --availability-zone us-east-1b \
23
- --image ami-de0d9eb7 \
23
+ --image ami-d017b2b8 \
24
24
  --ssh-user ubuntu \
25
25
  --flavor m1.small \
26
26
  --ssh-key id_rsa-aws \
@@ -46,7 +46,19 @@ knife server bootstrap linode \
46
46
  --linode-api-key $LINODE_API_KEY \
47
47
  --linode-datacenter 3 \
48
48
  --linode-flavor 1 \
49
- --linode-image 99 \
49
+ --linode-image 126 \
50
+ --ssh-password 'testing1234'
51
+ ```
52
+
53
+ To spin up your Chef Server on [OpenStack][openstack]:
54
+
55
+ ```bash
56
+ knife server bootstrap openstack \
57
+ --node-name openstack.example.com \
58
+ --openstack-node-name openstack \
59
+ --openstack-username $OS_USERNAME \
60
+ --openstack-password $OS_PASSWORD \
61
+ --openstack-auth-url $OS_AUTH_URL \
50
62
  --ssh-password 'testing1234'
51
63
  ```
52
64
 
@@ -159,12 +171,12 @@ that if you do not explicitly set `client_key` and `validation_key`, the
159
171
 
160
172
  For example, you could add lines similar to the following in your user's
161
173
  `~/.chef/knife.rb` or your project's `.chef/knife.rb` file (assuming you
162
- have a directory `"$HOME/.chef.d"` created with `mkdir -p $HOME/.chef.d`):
174
+ have a directory `"$HOME/.chef"` created with `mkdir -p $HOME/.chef`):
163
175
 
164
176
  ```ruby
165
177
  node_name "gramsay"
166
- client_key "#{ENV['HOME']}/.chef.d/gramsay.pem"
167
- validation_key "#{ENV['HOME']}/.chef.d/chef-validator.pem"
178
+ client_key "#{ENV['HOME']}/.chef/gramsay.pem"
179
+ validation_key "#{ENV['HOME']}/.chef/chef-validator.pem"
168
180
  ```
169
181
 
170
182
  Most options can be passed to the knife subcommands explicitly but this
@@ -403,6 +415,15 @@ to make future cloud adapter support easier to add.
403
415
  Provisions a Linode instance and sets up an Open Source Chef Server as
404
416
  described [above](#knife-server-bootstrap).
405
417
 
418
+ ### <a name="knife-server-bootstrap-openstack"></a> knife server bootstrap openstack
419
+
420
+ **Note:** You must install the [knife-openstack gem][knife-openstack] to use this
421
+ subcommand. This was done to keep the dependencies of this library lighter and
422
+ to make future cloud adapter support easier to add.
423
+
424
+ Provisions a Openstack instance and sets up an Open Source Chef Server as
425
+ described [above](#knife-server-bootstrap).
426
+
406
427
  #### Configuration
407
428
 
408
429
  This subcommand imports all relavent options from the knife-linode gem. For
@@ -622,5 +643,7 @@ Apache License, Version 2.0 (see [LICENSE][license])
622
643
  [install_chef]: http://www.opscode.com/chef/install/
623
644
  [knife-ec2]: https://github.com/opscode/knife-ec2
624
645
  [knife-linode]: https://github.com/opscode/knife-linode
646
+ [knife-openstack]: https://github.com/opscode/knife-openstack
625
647
  [stevendanna]: https://github.com/stevendanna
626
648
  [vagrant_site]: http://vagrantup.com/
649
+ [openstack]: http://openstack.org
data/Rakefile CHANGED
@@ -1,16 +1,37 @@
1
- #!/usr/bin/env rake
1
+ # -*- encoding: utf-8 -*-
2
+
2
3
  require "bundler/gem_tasks"
3
4
 
4
- begin
5
- require 'rspec/core/rake_task'
5
+ require "rspec/core/rake_task"
6
+ desc "Run all specs in spec directory"
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.pattern = "spec/**/*_spec.rb"
9
+ end
6
10
 
7
- task :default => :spec
11
+ desc "Run all test suites"
12
+ task :test => [:spec]
8
13
 
9
- desc "Run all specs in spec directory"
10
- RSpec::Core::RakeTask.new(:spec) do |t|
11
- t.pattern = 'spec/**/*_spec.rb'
12
- end
14
+ require "finstyle"
15
+ require "rubocop/rake_task"
16
+ RuboCop::RakeTask.new(:style) do |task|
17
+ task.options << "--display-cop-names"
18
+ end
13
19
 
14
- rescue LoadError
15
- STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n"
20
+ require "cane/rake_task"
21
+ desc "Run cane to check quality metrics"
22
+ Cane::RakeTask.new do |cane|
23
+ cane.canefile = "./.cane"
16
24
  end
25
+
26
+ desc "Display LOC stats"
27
+ task :stats do
28
+ puts "\n## Production Code Stats"
29
+ sh "countloc -r lib"
30
+ puts "\n## Test Code Stats"
31
+ sh "countloc -r spec"
32
+ end
33
+
34
+ desc "Run all quality tasks"
35
+ task :quality => [:cane, :style, :stats]
36
+
37
+ task :default => [:test, :quality]
data/knife-server.gemspec CHANGED
@@ -1,30 +1,40 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/knife/server/version', __FILE__)
2
+ require File.expand_path("../lib/knife/server/version", __FILE__)
3
+ require "English"
3
4
 
4
5
  Gem::Specification.new do |gem|
5
6
  gem.authors = ["Fletcher Nichol"]
6
7
  gem.email = ["fnichol@nichol.ca"]
7
- gem.summary = %q{Chef Knife plugin to bootstrap Chef Servers}
8
+ gem.summary = "Chef Knife plugin to bootstrap Chef Servers"
8
9
  gem.description = gem.summary
9
10
  gem.homepage = "http://fnichol.github.com/knife-server"
10
11
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
13
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
15
  gem.name = "knife-server"
15
16
  gem.require_paths = ["lib"]
16
17
  gem.version = Knife::Server::VERSION
17
18
 
18
- gem.required_ruby_version = ">= 1.9.2"
19
+ gem.required_ruby_version = ">= 1.9.3"
19
20
 
20
- gem.add_dependency "fog", "~> 1.3"
21
+ gem.add_dependency "fog"
21
22
  gem.add_dependency "net-ssh"
22
23
  gem.add_dependency "chef", ">= 0.10.10"
23
24
 
25
+ gem.add_development_dependency "rake"
24
26
  gem.add_development_dependency "knife-ec2", ">= 0.5.12"
25
27
  gem.add_development_dependency "knife-linode"
28
+ gem.add_development_dependency "knife-openstack"
26
29
 
27
- gem.add_development_dependency "rspec", "~> 2.13.0"
28
- gem.add_development_dependency "fakefs", "~> 0.4.0"
30
+ gem.add_development_dependency "rspec", "~> 3.0"
31
+ gem.add_development_dependency "fakefs", "~> 0.4"
29
32
  gem.add_development_dependency "timecop", "~> 0.3"
33
+ gem.add_development_dependency "countloc", "~> 0.4"
34
+
35
+ # style and complexity libraries are tightly version pinned as newer releases
36
+ # may introduce new and undesireable style choices which would be immediately
37
+ # enforced in CI
38
+ gem.add_development_dependency "finstyle", "1.2.0"
39
+ gem.add_development_dependency "cane", "2.6.2"
30
40
  end
@@ -5,12 +5,16 @@
5
5
  #
6
6
 
7
7
  package_url() {
8
- local base="http://www.opscode.com/chef/download-server"
9
- if [ -n "$version" ] ; then
10
- local v="&v=${version}"
11
- fi
8
+ if [ -n "$url" ] ; then
9
+ echo "$url"
10
+ else
11
+ local base="http://www.getchef.com/chef/download-server"
12
+ if [ -n "$version" ] ; then
13
+ local v="&v=${version}"
14
+ fi
12
15
 
13
- echo "${base}?p=${platform}&pv=${platform_version}&m=${machine}&prerelease=${prerelease}${v}"
16
+ echo "${base}?p=${platform}&pv=${platform_version}&m=${machine}&prerelease=${prerelease}${v}"
17
+ fi
14
18
  }
15
19
 
16
20
  # Set the filename for a deb, based on version and machine
@@ -36,6 +40,16 @@ failed_download() {
36
40
  exit 5
37
41
  }
38
42
 
43
+ is_server_installed() {
44
+ if [ -f "/opt/chef-server/bin/chef-server-ctl" ] ; then
45
+ return 0
46
+ elif [ -f "/opt/opscode/bin/chef-server-ctl" ] ; then
47
+ return 0
48
+ else
49
+ return 1
50
+ fi
51
+ }
52
+
39
53
  perform_download() {
40
54
  case "$1" in
41
55
  wget)
@@ -48,8 +62,8 @@ perform_download() {
48
62
  }
49
63
 
50
64
  download_package() {
51
- if [ -f "/opt/chef-server/bin/chef-server-ctl" ] ; then
52
- info "Chef Server detected in /opt/chef-server, skipping download"
65
+ if is_server_installed ; then
66
+ info "Chef Server detected, skipping download"
53
67
  return 0
54
68
  fi
55
69
 
@@ -72,8 +86,8 @@ download_package() {
72
86
  }
73
87
 
74
88
  install_package() {
75
- if [ -f "/opt/chef-server/bin/chef-server-ctl" ] ; then
76
- info "Chef Server detected in /opt/chef-server, skipping installation"
89
+ if is_server_installed ; then
90
+ info "Chef Server detected, skipping installation"
77
91
  return 0
78
92
  fi
79
93
 
@@ -90,6 +104,43 @@ install_package() {
90
104
  banner "Package installed"
91
105
  }
92
106
 
107
+ detect_info() {
108
+ if [ -f "/opt/chef-server/bin/chef-server-ctl" ] ; then
109
+ server_root="/opt/chef-server"
110
+ elif [ -f "/opt/opscode/bin/chef-server-ctl" ] ; then
111
+ server_root="/opt/opscode"
112
+ fi
113
+
114
+ info "Chef Server detected in $server_root"
115
+ }
116
+
117
+ patch_knife_code() {
118
+ local check="((Gem::Version.new(Chef::VERSION) <= Gem::Version.new(\"11.12.2\")) || (Gem::Version.new(Chef::VERSION) >= Gem::Version.new(\"11.6.0\"))) ? exit(0) : exit(1)"
119
+ local gems="$server_root/embedded/lib/ruby/gems/1.9.1/gems"
120
+ local patched="$gems/.patched"
121
+
122
+ if [ -f "$patched" ]; then
123
+ info "Patched knife configure detected, skipping"
124
+ elif echo "$script" | $server_root/embedded/bin/ruby -r chef/version; then
125
+ info "Patching knife configure bug (CHEF-5211)"
126
+ (cd $gems/chef-11.* && cat <<PATCH | tr "#" "\047" | patch -p1)
127
+ diff --git a/lib/chef/knife/configure.rb b/lib/chef/knife/configure.rb
128
+ index 6af3d4e..2c77bf1 100644
129
+ --- a/lib/chef/knife/configure.rb
130
+ +++ b/lib/chef/knife/configure.rb
131
+ @@ -153,6 +153,7 @@ EOH
132
+
133
+ def guess_servername
134
+ o = Ohai::System.new
135
+ + o.load_plugins
136
+ o.require_plugin #os#
137
+ o.require_plugin #hostname#
138
+ o[:fqdn] || #localhost#
139
+ PATCH
140
+ touch "$patched"
141
+ fi
142
+ }
143
+
93
144
  prepare_chef_server_rb() {
94
145
  local config_file="/etc/chef-server/chef-server.rb"
95
146
 
@@ -112,7 +163,7 @@ CHEF_SERVER
112
163
  symlink_binaries() {
113
164
  for bin in chef-client chef-solo chef-apply knife ohai ; do
114
165
  banner "Updating /usr/bin/$bin symlink"
115
- ln -snf /opt/chef-server/embedded/bin/$bin /usr/bin/$bin
166
+ ln -snf $server_root/embedded/bin/$bin /usr/bin/$bin
116
167
  done ; unset bin
117
168
  }
118
169
 
@@ -132,5 +183,7 @@ configure_firewall() {
132
183
  if [ -x "/usr/sbin/lokkit" ] ; then
133
184
  banner "Opening TCP port 443"
134
185
  /usr/sbin/lokkit -p 443:tcp
186
+ banner "Opening SSH port 22"
187
+ /usr/sbin/lokkit -p 22:tcp
135
188
  fi
136
189
  }