knife-server 0.3.3 → 1.0.0

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.
@@ -33,9 +33,51 @@ describe Chef::Knife::ServerBootstrapStandalone do
33
33
  @stderr = StringIO.new
34
34
  @knife.ui.stub!(:stderr).and_return(@stderr)
35
35
  @knife.config[:chef_node_name] = "yakky"
36
+ @knife.config[:ssh_user] = "root"
37
+ end
38
+
39
+ describe "distro selection" do
40
+
41
+ before do
42
+ @knife.config[:bootstrap_version] = "10"
43
+ @knife.stub(:determine_platform) { @knife.send(:distro_auto_map, "debian", "6") }
44
+ @knife.config[:platform] = "auto"
45
+ end
46
+
47
+ it "should auto-select from determine_platform by default" do
48
+ @knife.config.delete(:distro)
49
+ @knife.send(:bootstrap_distro).should eq("chef10/debian")
50
+ @knife.stub(:determine_platform) { "chef10/rhel" }
51
+ @knife.send(:bootstrap_distro).should eq("chef10/rhel")
52
+ end
53
+
54
+ it "should construct the distro path based on the chef server version and platform" do
55
+ @knife.send(:construct_distro, "rhel").should eq("chef10/rhel")
56
+ @knife.config[:bootstrap_version] = "11"
57
+ @knife.send(:construct_distro, "rhel").should eq("chef11/rhel")
58
+ end
59
+
60
+ it "should map the distro template based on a tuple of (platform, platform_version)" do
61
+ {
62
+ "el" => "rhel",
63
+ "redhat" => "rhel",
64
+ "debian" => "debian",
65
+ "ubuntu" => "debian",
66
+ "solaris2" => "solaris",
67
+ "solaris" => "solaris",
68
+ "sles" => "suse",
69
+ "suse" => "suse"
70
+ }.each do |key, value|
71
+ @knife.config[:bootstrap_version] = "10"
72
+ @knife.send(:distro_auto_map, key, 0).should eq("chef10/#{value}")
73
+ @knife.config[:bootstrap_version] = "11"
74
+ @knife.send(:distro_auto_map, key, 0).should eq("chef11/#{value}")
75
+ end
76
+ end
36
77
  end
37
78
 
38
79
  describe "#standalone_bootstrap" do
80
+
39
81
  before do
40
82
  @knife.config[:host] = "172.0.10.21"
41
83
  @knife.config[:chef_node_name] = "shave.yak"
@@ -95,17 +137,17 @@ describe Chef::Knife::ServerBootstrapStandalone do
95
137
  bootstrap.config[:distro].should eq("distro-praha")
96
138
  end
97
139
 
98
- it "configs the bootstrap's distro to chef-server-debian by default" do
140
+ it "configs the bootstrap's distro to chef11/omnibus by default" do
99
141
  @knife.config.delete(:distro)
100
142
 
101
- bootstrap.config[:distro].should eq("chef-server-debian")
143
+ bootstrap.config[:distro].should eq("chef11/omnibus")
102
144
  end
103
145
 
104
146
  it "configs the bootstrap's distro value driven off platform value" do
105
147
  @knife.config.delete(:distro)
106
148
  @knife.config[:platform] = "freebsd"
107
149
 
108
- bootstrap.config[:distro].should eq("chef-server-freebsd")
150
+ bootstrap.config[:distro].should eq("chef11/freebsd")
109
151
  end
110
152
 
111
153
  it "configs the bootstrap's ENV with the webui password" do
@@ -131,6 +173,15 @@ describe Chef::Knife::ServerBootstrapStandalone do
131
173
 
132
174
  bootstrap.config[:use_sudo].should_not be_true
133
175
  end
176
+
177
+ describe "#bootstrap_auto?" do
178
+ it "should always be true if it was set via --platform, even if the distro changes" do
179
+ @knife.config[:platform] = "auto"
180
+ bootstrap.config[:distro].should_not eq("auto")
181
+ @knife.send(:bootstrap_auto?).should be_true
182
+ end
183
+ end
184
+
134
185
  end
135
186
 
136
187
  describe "#run" do
@@ -194,9 +245,19 @@ describe Chef::Knife::ServerBootstrapStandalone do
194
245
  @knife.run
195
246
  end
196
247
 
197
- it "installs a new validation.pem key from the server" do
248
+ it "installs a new validation.pem key from the chef 10 server" do
249
+ @knife.config[:bootstrap_version] = "10"
250
+ @knife.config[:distro] = "yabba-debian"
251
+ Knife::Server::Credentials.should_receive(:new).
252
+ with(ssh, "/etc/chef/validation.pem", {})
253
+ credentials.should_receive(:install_validation_key)
254
+
255
+ @knife.run
256
+ end
257
+
258
+ it "installs a new validation.pem key from the omnibus server" do
198
259
  Knife::Server::Credentials.should_receive(:new).
199
- with(ssh, "/etc/chef/validation.pem")
260
+ with(ssh, "/etc/chef/validation.pem", {:omnibus => true})
200
261
  credentials.should_receive(:install_validation_key)
201
262
 
202
263
  @knife.run
@@ -30,16 +30,28 @@ describe Knife::Server::Credentials do
30
30
  Knife::Server::Credentials.new(ssh, validation_key_path)
31
31
  end
32
32
 
33
+ let(:omnibus_subject) do
34
+ Knife::Server::Credentials.new(ssh, validation_key_path, :omnibus => true)
35
+ end
36
+
33
37
  before do
34
38
  FileUtils.mkdir_p(File.dirname(validation_key_path))
35
39
  FileUtils.mkdir_p(File.dirname(client_key_path))
36
40
  File.new(validation_key_path, "wb") { |f| f.write("thekey") }
37
41
  File.new(client_key_path, "wb") { |f| f.write("clientkey") }
42
+
43
+ ENV['_SPEC_WEBUI_PASSWORD'] = ENV['WEBUI_PASSWORD']
44
+ end
45
+
46
+ after do
47
+ ENV['WEBUI_PASSWORD'] = ENV.delete('_SPEC_WEBUI_PASSWORD')
38
48
  end
39
49
 
40
50
  describe "#install_validation_key" do
41
51
  before do
42
52
  ssh.stub(:exec!).with("cat /etc/chef/validation.pem") { "newkey" }
53
+ ssh.stub(:exec!).
54
+ with("cat /etc/chef-server/chef-validator.pem") { "omnibuskey" }
43
55
  end
44
56
 
45
57
  it "creates a backup of the existing validation key file" do
@@ -63,6 +75,13 @@ describe Knife::Server::Credentials do
63
75
 
64
76
  key_str.should eq("newkey")
65
77
  end
78
+
79
+ it "copies the key back from the omnibus server into validation key file" do
80
+ omnibus_subject.install_validation_key("old")
81
+ key_str = File.open("/tmp/validation.pem", "rb") { |f| f.read }
82
+
83
+ key_str.should eq("omnibuskey")
84
+ end
66
85
  end
67
86
 
68
87
  describe "#create_root_client" do
@@ -74,6 +93,21 @@ describe Knife::Server::Credentials do
74
93
 
75
94
  subject.create_root_client
76
95
  end
96
+
97
+ it "creates an initial user on the omnibus server" do
98
+ ENV['WEBUI_PASSWORD'] = 'doowah'
99
+ ssh.should_receive(:exec!).with([
100
+ "echo 'doowah' |",
101
+ 'knife configure --initial --server-url http://127.0.0.1:8000',
102
+ '--user root --repository "" --admin-client-name chef-webui',
103
+ '--admin-client-key /etc/chef-server/chef-webui.pem',
104
+ '--validation-client-name chef-validator',
105
+ '--validation-key /etc/chef-server/chef-validator.pem',
106
+ '--defaults --yes'
107
+ ].join(" "))
108
+
109
+ omnibus_subject.create_root_client
110
+ end
77
111
  end
78
112
 
79
113
  describe "#install_client_key" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 1.0.0
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: 2012-12-24 00:00:00.000000000 Z
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -67,7 +67,7 @@ dependencies:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: 0.5.12
70
- type: :runtime
70
+ type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
@@ -139,7 +139,15 @@ files:
139
139
  - README.md
140
140
  - Rakefile
141
141
  - knife-server.gemspec
142
- - lib/chef/knife/bootstrap/chef-server-debian.erb
142
+ - lib/chef/knife/bootstrap/_common.sh
143
+ - lib/chef/knife/bootstrap/_omnibus.sh
144
+ - lib/chef/knife/bootstrap/_platform_and_version.sh
145
+ - lib/chef/knife/bootstrap/_set_hostname.sh
146
+ - lib/chef/knife/bootstrap/auto.sh
147
+ - lib/chef/knife/bootstrap/chef10/debian.erb
148
+ - lib/chef/knife/bootstrap/chef10/rhel.erb
149
+ - lib/chef/knife/bootstrap/chef11/omnibus.erb
150
+ - lib/chef/knife/bootstrap/chef11/rhel.erb
143
151
  - lib/chef/knife/server_backup.rb
144
152
  - lib/chef/knife/server_bootstrap_base.rb
145
153
  - lib/chef/knife/server_bootstrap_ec2.rb
@@ -171,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
179
  version: '0'
172
180
  segments:
173
181
  - 0
174
- hash: -302357605861096338
182
+ hash: 2065345583583086223
175
183
  required_rubygems_version: !ruby/object:Gem::Requirement
176
184
  none: false
177
185
  requirements:
@@ -180,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
188
  version: '0'
181
189
  segments:
182
190
  - 0
183
- hash: -302357605861096338
191
+ hash: 2065345583583086223
184
192
  requirements: []
185
193
  rubyforge_project:
186
194
  rubygems_version: 1.8.24