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.
- checksums.yaml +4 -4
- data/.cane +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +12 -8
- data/CHANGELOG.md +32 -1
- data/Gemfile +9 -4
- data/Guardfile +28 -0
- data/README.md +28 -5
- data/Rakefile +31 -10
- data/knife-server.gemspec +18 -8
- data/lib/chef/knife/bootstrap/_omnibus.sh +63 -10
- data/lib/chef/knife/bootstrap/chef10/rhel.erb +2 -0
- data/lib/chef/knife/bootstrap/chef11/omnibus.erb +4 -1
- data/lib/chef/knife/bootstrap/chef11/rhel.erb +2 -0
- data/lib/chef/knife/server_backup.rb +24 -10
- data/lib/chef/knife/server_bootstrap_base.rb +68 -23
- data/lib/chef/knife/server_bootstrap_ec2.rb +33 -20
- data/lib/chef/knife/server_bootstrap_linode.rb +20 -13
- data/lib/chef/knife/server_bootstrap_openstack.rb +128 -0
- data/lib/chef/knife/server_bootstrap_standalone.rb +28 -16
- data/lib/chef/knife/server_restore.rb +23 -9
- data/lib/knife-server.rb +1 -0
- data/lib/knife/server/credentials.rb +78 -42
- data/lib/knife/server/ec2_security_group.rb +24 -21
- data/lib/knife/server/ssh.rb +54 -18
- data/lib/knife/server/version.rb +2 -1
- data/spec/chef/knife/server_backup_spec.rb +58 -44
- data/spec/chef/knife/server_bootstrap_ec2_spec.rb +108 -80
- data/spec/chef/knife/server_bootstrap_linode_spec.rb +93 -64
- data/spec/chef/knife/server_bootstrap_openstack_spec.rb +305 -0
- data/spec/chef/knife/server_bootstrap_standalone_spec.rb +113 -76
- data/spec/chef/knife/server_restore_spec.rb +38 -37
- data/spec/knife/server/credientials_spec.rb +248 -51
- data/spec/knife/server/ec2_security_group_spec.rb +76 -68
- data/spec/knife/server/ssh_spec.rb +138 -22
- metadata +107 -31
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
#
|
2
3
|
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
3
4
|
# Copyright:: Copyright (c) 2012 Fletcher Nichol
|
@@ -16,10 +17,10 @@
|
|
16
17
|
# limitations under the License.
|
17
18
|
#
|
18
19
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
20
|
+
require "chef/knife/server_bootstrap_ec2"
|
21
|
+
require "chef/knife/ssh"
|
22
|
+
require "fakefs/spec_helpers"
|
23
|
+
require "net/ssh"
|
23
24
|
Chef::Knife::ServerBootstrapEc2.load_deps
|
24
25
|
|
25
26
|
describe Chef::Knife::ServerBootstrapEc2 do
|
@@ -29,15 +30,15 @@ describe Chef::Knife::ServerBootstrapEc2 do
|
|
29
30
|
Chef::Log.logger = Logger.new(StringIO.new)
|
30
31
|
@knife = Chef::Knife::ServerBootstrapEc2.new
|
31
32
|
@stdout = StringIO.new
|
32
|
-
@knife.ui.
|
33
|
+
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
|
33
34
|
@stderr = StringIO.new
|
34
|
-
@knife.ui.
|
35
|
+
allow(@knife.ui).to receive(:stderr).and_return(@stderr)
|
35
36
|
@knife.config[:chef_node_name] = "yakky"
|
36
37
|
@knife.config[:platform] = "omnibus"
|
37
38
|
@knife.config[:ssh_user] = "root"
|
38
39
|
end
|
39
40
|
|
40
|
-
let(:connection) {
|
41
|
+
let(:connection) { double(Fog::Compute::AWS) }
|
41
42
|
|
42
43
|
describe "#ec2_bootstrap" do
|
43
44
|
before do
|
@@ -45,94 +46,100 @@ describe Chef::Knife::ServerBootstrapEc2 do
|
|
45
46
|
@knife.config[:ssh_user] = "jdoe"
|
46
47
|
@knife.config[:ssh_port] = "2222"
|
47
48
|
@knife.config[:identity_file] = "~/.ssh/mykey_dsa"
|
48
|
-
@knife.config[:security_groups] = %w
|
49
|
-
@knife.config[:tags] = %w
|
49
|
+
@knife.config[:security_groups] = %w[x y z]
|
50
|
+
@knife.config[:tags] = %w[tag1=val1 tag2=val2]
|
50
51
|
@knife.config[:distro] = "distro-praha"
|
51
52
|
@knife.config[:ebs_size] = "42"
|
52
53
|
@knife.config[:webui_password] = "daweb"
|
53
54
|
@knife.config[:amqp_password] = "queueitup"
|
54
55
|
|
55
|
-
ENV[
|
56
|
-
ENV[
|
56
|
+
ENV["_SPEC_WEBUI_PASSWORD"] = ENV["WEBUI_PASSWORD"]
|
57
|
+
ENV["_SPEC_AMQP_PASSWORD"] = ENV["AMQP_PASSWORD"]
|
57
58
|
end
|
58
59
|
|
59
60
|
after do
|
60
|
-
ENV[
|
61
|
-
ENV[
|
61
|
+
ENV["WEBUI_PASSWORD"] = ENV.delete("_SPEC_WEBUI_PASSWORD")
|
62
|
+
ENV["AMQP_PASSWORD"] = ENV.delete("_SPEC_AMQP_PASSWORD")
|
62
63
|
end
|
63
64
|
|
64
65
|
let(:bootstrap) { @knife.ec2_bootstrap }
|
65
66
|
|
66
67
|
it "returns an Ec2ServerCreate instance" do
|
67
|
-
bootstrap.
|
68
|
+
expect(bootstrap).to be_a(Chef::Knife::Ec2ServerCreate)
|
68
69
|
end
|
69
70
|
|
70
71
|
it "configs the bootstrap's chef_node_name" do
|
71
|
-
bootstrap.config[:chef_node_name].
|
72
|
+
expect(bootstrap.config[:chef_node_name]).to eq("shave.yak")
|
72
73
|
end
|
73
74
|
|
74
75
|
it "configs the bootstrap's ssh_user" do
|
75
|
-
bootstrap.config[:ssh_user].
|
76
|
+
expect(bootstrap.config[:ssh_user]).to eq("jdoe")
|
76
77
|
end
|
77
78
|
|
78
79
|
it "configs the bootstrap's ssh_port" do
|
79
|
-
bootstrap.config[:ssh_port].
|
80
|
+
expect(bootstrap.config[:ssh_port]).to eq("2222")
|
80
81
|
end
|
81
82
|
|
82
83
|
it "configs the bootstrap's identity_file" do
|
83
|
-
bootstrap.config[:identity_file].
|
84
|
+
expect(bootstrap.config[:identity_file]).to eq("~/.ssh/mykey_dsa")
|
84
85
|
end
|
85
86
|
|
86
87
|
it "configs the bootstrap's security_groups" do
|
87
|
-
bootstrap.config[:security_groups].
|
88
|
+
expect(bootstrap.config[:security_groups]).to eq(%w[x y z])
|
88
89
|
end
|
89
90
|
|
90
91
|
it "configs the bootstrap's ebs_size" do
|
91
|
-
bootstrap.config[:ebs_size].
|
92
|
+
expect(bootstrap.config[:ebs_size]).to eq("42")
|
92
93
|
end
|
93
94
|
|
94
95
|
it "configs the bootstrap's tags" do
|
95
|
-
bootstrap.config[:tags].
|
96
|
-
bootstrap.config[:tags].
|
96
|
+
expect(bootstrap.config[:tags]).to include("tag1=val1")
|
97
|
+
expect(bootstrap.config[:tags]).to include("tag2=val2")
|
97
98
|
end
|
98
99
|
|
99
100
|
it "adds Role=chef_server to the bootstrap's tags" do
|
100
|
-
bootstrap.config[:tags].
|
101
|
+
expect(bootstrap.config[:tags]).to include("Role=chef_server")
|
101
102
|
end
|
102
103
|
|
103
104
|
it "configs the bootstrap's distro" do
|
104
|
-
bootstrap.config[:distro].
|
105
|
+
expect(bootstrap.config[:distro]).to eq("distro-praha")
|
105
106
|
end
|
106
107
|
|
107
108
|
it "configs the bootstrap's distro to chef11/omnibus by default" do
|
108
109
|
@knife.config.delete(:distro)
|
109
110
|
|
110
|
-
bootstrap.config[:distro].
|
111
|
+
expect(bootstrap.config[:distro]).to eq("chef11/omnibus")
|
111
112
|
end
|
112
113
|
|
113
114
|
it "configs the bootstrap's distro value driven off platform value" do
|
114
115
|
@knife.config.delete(:distro)
|
115
116
|
@knife.config[:platform] = "freebsd"
|
116
117
|
|
117
|
-
bootstrap.config[:distro].
|
118
|
+
expect(bootstrap.config[:distro]).to eq("chef11/freebsd")
|
118
119
|
end
|
119
120
|
|
120
|
-
it "configs the
|
121
|
+
it "configs the distro based on bootstrap_version and platform" do
|
121
122
|
@knife.config.delete(:distro)
|
122
123
|
@knife.config[:platform] = "freebsd"
|
123
124
|
@knife.config[:bootstrap_version] = "10"
|
124
125
|
|
125
|
-
bootstrap.config[:distro].
|
126
|
+
expect(bootstrap.config[:distro]).to eq("chef10/freebsd")
|
126
127
|
end
|
127
128
|
|
128
129
|
it "configs the bootstrap's ENV with the webui password" do
|
129
130
|
bootstrap
|
130
|
-
|
131
|
+
|
132
|
+
expect(ENV["WEBUI_PASSWORD"]).to eq("daweb")
|
131
133
|
end
|
132
134
|
|
133
135
|
it "configs the bootstrap's ENV with the amqp password" do
|
134
136
|
bootstrap
|
135
|
-
|
137
|
+
|
138
|
+
expect(ENV["AMQP_PASSWORD"]).to eq("queueitup")
|
139
|
+
end
|
140
|
+
|
141
|
+
it "skips config values with nil defaults" do
|
142
|
+
expect(bootstrap.config[:bootstrap_version]).to be_nil
|
136
143
|
end
|
137
144
|
end
|
138
145
|
|
@@ -156,12 +163,12 @@ describe Chef::Knife::ServerBootstrapEc2 do
|
|
156
163
|
end
|
157
164
|
|
158
165
|
it "constructs a connection" do
|
159
|
-
Fog::Compute.
|
160
|
-
:provider =>
|
161
|
-
:aws_access_key_id =>
|
162
|
-
:aws_secret_access_key =>
|
163
|
-
:region =>
|
164
|
-
|
166
|
+
expect(Fog::Compute).to receive(:new).with(
|
167
|
+
:provider => "AWS",
|
168
|
+
:aws_access_key_id => "key",
|
169
|
+
:aws_secret_access_key => "secret",
|
170
|
+
:region => "hell-south-666"
|
171
|
+
)
|
165
172
|
|
166
173
|
@knife.ec2_connection
|
167
174
|
end
|
@@ -169,37 +176,41 @@ describe Chef::Knife::ServerBootstrapEc2 do
|
|
169
176
|
|
170
177
|
describe "#server_dns_name" do
|
171
178
|
before do
|
172
|
-
@knife.config[:chef_node_name] =
|
173
|
-
@knife.
|
179
|
+
@knife.config[:chef_node_name] = "shavemy.yak"
|
180
|
+
allow(@knife).to receive(:ec2_connection) { connection }
|
174
181
|
end
|
175
182
|
|
176
183
|
context "when server is found" do
|
177
184
|
before do
|
178
|
-
connection.
|
185
|
+
expect(connection).to receive(:servers) { [server] }
|
179
186
|
end
|
180
187
|
|
181
188
|
let(:server) do
|
182
|
-
|
183
|
-
:
|
189
|
+
double(
|
190
|
+
:dns_name => "blahblah.aws.compute.com",
|
191
|
+
:state => "running",
|
192
|
+
:tags => { "Name" => "shavemy.yak", "Role" => "chef_server" }
|
193
|
+
)
|
184
194
|
end
|
185
195
|
|
186
196
|
it "returns the provisioned dns name" do
|
187
|
-
@knife.server_dns_name.
|
197
|
+
expect(@knife.server_dns_name).to eq("blahblah.aws.compute.com")
|
188
198
|
end
|
189
199
|
|
190
200
|
it "ignores terminated instances" do
|
191
|
-
server.
|
192
|
-
|
201
|
+
allow(server).to receive(:state) { "terminated" }
|
202
|
+
|
203
|
+
expect(@knife.server_dns_name).to be_nil
|
193
204
|
end
|
194
205
|
end
|
195
206
|
|
196
207
|
context "when server is not found" do
|
197
208
|
before do
|
198
|
-
connection.
|
209
|
+
allow(connection).to receive(:servers) { [] }
|
199
210
|
end
|
200
211
|
|
201
212
|
it "returns nil" do
|
202
|
-
@knife.server_dns_name.
|
213
|
+
expect(@knife.server_dns_name).to be_nil
|
203
214
|
end
|
204
215
|
end
|
205
216
|
end
|
@@ -217,15 +228,15 @@ describe Chef::Knife::ServerBootstrapEc2 do
|
|
217
228
|
@knife.config[:validation_key] = "/var/tmp/validation.pem"
|
218
229
|
@knife.config[:ssh_port] = "2345"
|
219
230
|
@knife.config[:identity_file] = "~/.ssh/mykey_dsa"
|
220
|
-
@knife.
|
221
|
-
@knife.
|
222
|
-
Chef::Knife::Ec2ServerCreate.
|
223
|
-
Knife::Server::Ec2SecurityGroup.
|
224
|
-
Knife::Server::SSH.
|
225
|
-
Knife::Server::Credentials.
|
226
|
-
security_group.
|
227
|
-
credentials.
|
228
|
-
credentials.
|
231
|
+
allow(@knife).to receive(:ec2_connection) { connection }
|
232
|
+
allow(@knife).to receive(:server_dns_name) { "grapes.wrath" }
|
233
|
+
allow(Chef::Knife::Ec2ServerCreate).to receive(:new) { bootstrap }
|
234
|
+
allow(Knife::Server::Ec2SecurityGroup).to receive(:new) { security_group }
|
235
|
+
allow(Knife::Server::SSH).to receive(:new) { ssh }
|
236
|
+
allow(Knife::Server::Credentials).to receive(:new) { credentials }
|
237
|
+
allow(security_group).to receive(:configure_chef_server_group)
|
238
|
+
allow(credentials).to receive(:install_validation_key)
|
239
|
+
allow(credentials).to receive(:create_root_client)
|
229
240
|
end
|
230
241
|
|
231
242
|
after do
|
@@ -234,66 +245,83 @@ describe Chef::Knife::ServerBootstrapEc2 do
|
|
234
245
|
end
|
235
246
|
end
|
236
247
|
|
237
|
-
let(:bootstrap) {
|
238
|
-
let(:security_group) {
|
239
|
-
let(:ssh) {
|
240
|
-
let(:credentials) {
|
248
|
+
let(:bootstrap) { double(:run => true, :config => Hash.new) }
|
249
|
+
let(:security_group) { double }
|
250
|
+
let(:ssh) { double }
|
251
|
+
let(:credentials) { double.as_null_object }
|
252
|
+
|
253
|
+
it "exits if Chef::Config[:node_name] is missing" do
|
254
|
+
Chef::Config[:node_name] = nil
|
255
|
+
|
256
|
+
expect { @knife.run }.to raise_error SystemExit
|
257
|
+
end
|
258
|
+
|
259
|
+
it "exits if Chef::Config[:client_key] is missing" do
|
260
|
+
Chef::Config[:client_key] = nil
|
261
|
+
|
262
|
+
expect { @knife.run }.to raise_error SystemExit
|
263
|
+
end
|
241
264
|
|
242
265
|
it "exits if node_name option is missing" do
|
243
|
-
def @knife.exit(
|
266
|
+
def @knife.exit(_); end
|
244
267
|
@knife.config.delete(:chef_node_name)
|
245
268
|
|
246
|
-
@knife.
|
269
|
+
expect(@knife).to receive(:exit)
|
247
270
|
@knife.run
|
248
271
|
end
|
249
272
|
|
250
273
|
it "configures the ec2 security group" do
|
251
|
-
Knife::Server::Ec2SecurityGroup.
|
274
|
+
expect(Knife::Server::Ec2SecurityGroup).to receive(:new).
|
252
275
|
with(connection, @knife.ui)
|
253
|
-
security_group.
|
254
|
-
with(
|
276
|
+
expect(security_group).to receive(:configure_chef_server_group).
|
277
|
+
with("mygroup", :description => "mygroup group")
|
255
278
|
|
256
279
|
@knife.run
|
257
280
|
end
|
258
281
|
|
259
282
|
it "bootstraps an ec2 server" do
|
260
|
-
bootstrap.
|
283
|
+
expect(bootstrap).to receive(:run)
|
284
|
+
|
261
285
|
@knife.run
|
262
286
|
end
|
263
287
|
|
264
288
|
it "installs a new validation.pem key from the chef 10 server" do
|
265
289
|
@knife.config[:bootstrap_version] = "10"
|
266
|
-
Knife::Server::SSH.
|
267
|
-
:host => "grapes.wrath",
|
268
|
-
:
|
269
|
-
|
270
|
-
|
290
|
+
expect(Knife::Server::SSH).to receive(:new).with(
|
291
|
+
:host => "grapes.wrath",
|
292
|
+
:user => "root",
|
293
|
+
:port => "2345",
|
294
|
+
:keys => ["~/.ssh/mykey_dsa"]
|
295
|
+
)
|
296
|
+
expect(Knife::Server::Credentials).to receive(:new).
|
271
297
|
with(ssh, "/etc/chef/validation.pem", {})
|
272
|
-
credentials.
|
298
|
+
expect(credentials).to receive(:install_validation_key)
|
273
299
|
|
274
300
|
@knife.run
|
275
301
|
end
|
276
302
|
|
277
303
|
it "installs a new validation.pem key from the omnibus server" do
|
278
|
-
Knife::Server::SSH.
|
279
|
-
:host => "grapes.wrath",
|
280
|
-
:
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
304
|
+
expect(Knife::Server::SSH).to receive(:new).with(
|
305
|
+
:host => "grapes.wrath",
|
306
|
+
:user => "root",
|
307
|
+
:port => "2345",
|
308
|
+
:keys => ["~/.ssh/mykey_dsa"]
|
309
|
+
)
|
310
|
+
expect(Knife::Server::Credentials).to receive(:new).
|
311
|
+
with(ssh, "/etc/chef/validation.pem", :omnibus => true)
|
312
|
+
expect(credentials).to receive(:install_validation_key)
|
285
313
|
|
286
314
|
@knife.run
|
287
315
|
end
|
288
316
|
|
289
317
|
it "create a root client key" do
|
290
|
-
credentials.
|
318
|
+
expect(credentials).to receive(:create_root_client)
|
291
319
|
|
292
320
|
@knife.run
|
293
321
|
end
|
294
322
|
|
295
323
|
it "installs a client key" do
|
296
|
-
credentials.
|
324
|
+
expect(credentials).to receive(:install_client_key).
|
297
325
|
with("smithers", "/var/tmp/myclientkey.pem")
|
298
326
|
|
299
327
|
@knife.run
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
#
|
2
3
|
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
3
4
|
# Copyright:: Copyright (c) 2013 Fletcher Nichol
|
@@ -16,10 +17,10 @@
|
|
16
17
|
# limitations under the License.
|
17
18
|
#
|
18
19
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
20
|
+
require "chef/knife/server_bootstrap_linode"
|
21
|
+
require "chef/knife/ssh"
|
22
|
+
require "fakefs/spec_helpers"
|
23
|
+
require "net/ssh"
|
23
24
|
Chef::Knife::ServerBootstrapLinode.load_deps
|
24
25
|
|
25
26
|
describe Chef::Knife::ServerBootstrapLinode do
|
@@ -29,15 +30,15 @@ describe Chef::Knife::ServerBootstrapLinode do
|
|
29
30
|
Chef::Log.logger = Logger.new(StringIO.new)
|
30
31
|
@knife = Chef::Knife::ServerBootstrapLinode.new
|
31
32
|
@stdout = StringIO.new
|
32
|
-
@knife.ui.
|
33
|
+
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
|
33
34
|
@stderr = StringIO.new
|
34
|
-
@knife.ui.
|
35
|
+
allow(@knife.ui).to receive(:stderr).and_return(@stderr)
|
35
36
|
@knife.config[:chef_node_name] = "yakky"
|
36
37
|
@knife.config[:platform] = "omnibus"
|
37
38
|
@knife.config[:ssh_user] = "root"
|
38
39
|
end
|
39
40
|
|
40
|
-
let(:connection) {
|
41
|
+
let(:connection) { double(Fog::Compute::AWS) }
|
41
42
|
|
42
43
|
describe "#linode_bootstrap" do
|
43
44
|
|
@@ -50,70 +51,76 @@ describe Chef::Knife::ServerBootstrapLinode do
|
|
50
51
|
@knife.config[:webui_password] = "daweb"
|
51
52
|
@knife.config[:amqp_password] = "queueitup"
|
52
53
|
|
53
|
-
ENV[
|
54
|
-
ENV[
|
54
|
+
ENV["_SPEC_WEBUI_PASSWORD"] = ENV["WEBUI_PASSWORD"]
|
55
|
+
ENV["_SPEC_AMQP_PASSWORD"] = ENV["AMQP_PASSWORD"]
|
55
56
|
end
|
56
57
|
|
57
58
|
after do
|
58
|
-
ENV[
|
59
|
-
ENV[
|
59
|
+
ENV["WEBUI_PASSWORD"] = ENV.delete("_SPEC_WEBUI_PASSWORD")
|
60
|
+
ENV["AMQP_PASSWORD"] = ENV.delete("_SPEC_AMQP_PASSWORD")
|
60
61
|
end
|
61
62
|
|
62
63
|
let(:bootstrap) { @knife.linode_bootstrap }
|
63
64
|
|
64
65
|
it "returns a LinodeServerCreate instance" do
|
65
|
-
bootstrap.
|
66
|
+
expect(bootstrap).to be_a(Chef::Knife::LinodeServerCreate)
|
66
67
|
end
|
67
68
|
|
68
69
|
it "configs the bootstrap's chef_node_name" do
|
69
|
-
bootstrap.config[:chef_node_name].
|
70
|
+
expect(bootstrap.config[:chef_node_name]).to eq("shave.yak")
|
70
71
|
end
|
71
72
|
|
72
73
|
it "configs the bootstrap's ssh_user" do
|
73
|
-
bootstrap.config[:ssh_user].
|
74
|
+
expect(bootstrap.config[:ssh_user]).to eq("jdoe")
|
74
75
|
end
|
75
76
|
|
76
77
|
it "configs the bootstrap's identity_file" do
|
77
|
-
bootstrap.config[:identity_file].
|
78
|
+
expect(bootstrap.config[:identity_file]).to eq("~/.ssh/mykey_dsa")
|
78
79
|
end
|
79
80
|
|
80
81
|
it "configs the bootstrap's linode_api_key" do
|
81
|
-
bootstrap.config[:linode_api_key].
|
82
|
+
expect(bootstrap.config[:linode_api_key]).to eq("linode123")
|
82
83
|
end
|
83
84
|
|
84
85
|
it "configs the bootstrap's distro" do
|
85
|
-
bootstrap.config[:distro].
|
86
|
+
expect(bootstrap.config[:distro]).to eq("distro-praha")
|
86
87
|
end
|
87
88
|
|
88
89
|
it "configs the bootstrap's distro to chef11/omnibus by default" do
|
89
90
|
@knife.config.delete(:distro)
|
90
91
|
|
91
|
-
bootstrap.config[:distro].
|
92
|
+
expect(bootstrap.config[:distro]).to eq("chef11/omnibus")
|
92
93
|
end
|
93
94
|
|
94
95
|
it "configs the bootstrap's distro value driven off platform value" do
|
95
96
|
@knife.config.delete(:distro)
|
96
97
|
@knife.config[:platform] = "freebsd"
|
97
98
|
|
98
|
-
bootstrap.config[:distro].
|
99
|
+
expect(bootstrap.config[:distro]).to eq("chef11/freebsd")
|
99
100
|
end
|
100
101
|
|
101
|
-
it "configs the
|
102
|
+
it "configs the distro based on bootstrap_version and platform" do
|
102
103
|
@knife.config.delete(:distro)
|
103
104
|
@knife.config[:platform] = "freebsd"
|
104
105
|
@knife.config[:bootstrap_version] = "10"
|
105
106
|
|
106
|
-
bootstrap.config[:distro].
|
107
|
+
expect(bootstrap.config[:distro]).to eq("chef10/freebsd")
|
107
108
|
end
|
108
109
|
|
109
110
|
it "configs the bootstrap's ENV with the webui password" do
|
110
111
|
bootstrap
|
111
|
-
|
112
|
+
|
113
|
+
expect(ENV["WEBUI_PASSWORD"]).to eq("daweb")
|
112
114
|
end
|
113
115
|
|
114
116
|
it "configs the bootstrap's ENV with the amqp password" do
|
115
117
|
bootstrap
|
116
|
-
|
118
|
+
|
119
|
+
expect(ENV["AMQP_PASSWORD"]).to eq("queueitup")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "skips config values with nil defaults" do
|
123
|
+
expect(bootstrap.config[:bootstrap_version]).to be_nil
|
117
124
|
end
|
118
125
|
end
|
119
126
|
|
@@ -134,10 +141,10 @@ describe Chef::Knife::ServerBootstrapLinode do
|
|
134
141
|
end
|
135
142
|
|
136
143
|
it "constructs a connection" do
|
137
|
-
Fog::Compute.
|
138
|
-
:provider =>
|
139
|
-
:linode_api_key =>
|
140
|
-
|
144
|
+
expect(Fog::Compute).to receive(:new).with(
|
145
|
+
:provider => "Linode",
|
146
|
+
:linode_api_key => "key"
|
147
|
+
)
|
141
148
|
|
142
149
|
@knife.linode_connection
|
143
150
|
end
|
@@ -146,38 +153,42 @@ describe Chef::Knife::ServerBootstrapLinode do
|
|
146
153
|
describe "#server_ip_address" do
|
147
154
|
|
148
155
|
before do
|
149
|
-
@knife.config[:linode_node_name] =
|
150
|
-
@knife.
|
156
|
+
@knife.config[:linode_node_name] = "yak"
|
157
|
+
allow(@knife).to receive(:linode_connection) { connection }
|
151
158
|
end
|
152
159
|
|
153
160
|
context "when server is found" do
|
154
161
|
|
155
162
|
before do
|
156
|
-
connection.
|
163
|
+
allow(connection).to receive(:servers) { [server] }
|
157
164
|
end
|
158
165
|
|
159
166
|
let(:server) do
|
160
|
-
|
167
|
+
double(
|
168
|
+
:name => "yak",
|
169
|
+
:status => 1,
|
170
|
+
:public_ip_address => "10.11.12.13"
|
171
|
+
)
|
161
172
|
end
|
162
173
|
|
163
174
|
it "returns the provisioned ip address" do
|
164
|
-
@knife.server_ip_address.
|
175
|
+
expect(@knife.server_ip_address).to eq("10.11.12.13")
|
165
176
|
end
|
166
177
|
|
167
178
|
it "ignores terminated instances" do
|
168
|
-
server.
|
179
|
+
allow(server).to receive(:status) { 0 }
|
169
180
|
|
170
|
-
@knife.server_ip_address.
|
181
|
+
expect(@knife.server_ip_address).to be_nil
|
171
182
|
end
|
172
183
|
end
|
173
184
|
|
174
185
|
context "when server is not found" do
|
175
186
|
before do
|
176
|
-
connection.
|
187
|
+
allow(connection).to receive(:servers) { [] }
|
177
188
|
end
|
178
189
|
|
179
190
|
it "returns nil" do
|
180
|
-
@knife.server_ip_address.
|
191
|
+
expect(@knife.server_ip_address).to be_nil
|
181
192
|
end
|
182
193
|
end
|
183
194
|
end
|
@@ -195,13 +206,13 @@ describe Chef::Knife::ServerBootstrapLinode do
|
|
195
206
|
@knife.config[:validation_key] = "/var/tmp/validation.pem"
|
196
207
|
@knife.config[:identity_file] = "~/.ssh/mykey_dsa"
|
197
208
|
@knife.config[:ssh_password] = "booboo"
|
198
|
-
@knife.
|
199
|
-
@knife.
|
200
|
-
Chef::Knife::LinodeServerCreate.
|
201
|
-
Knife::Server::SSH.
|
202
|
-
Knife::Server::Credentials.
|
203
|
-
credentials.
|
204
|
-
credentials.
|
209
|
+
allow(@knife).to receive(:linode_connection) { connection }
|
210
|
+
allow(@knife).to receive(:server_ip_address) { "11.11.11.13" }
|
211
|
+
allow(Chef::Knife::LinodeServerCreate).to receive(:new) { bootstrap }
|
212
|
+
allow(Knife::Server::SSH).to receive(:new) { ssh }
|
213
|
+
allow(Knife::Server::Credentials).to receive(:new) { credentials }
|
214
|
+
allow(credentials).to receive(:install_validation_key)
|
215
|
+
allow(credentials).to receive(:create_root_client)
|
205
216
|
end
|
206
217
|
|
207
218
|
after do
|
@@ -210,61 +221,79 @@ describe Chef::Knife::ServerBootstrapLinode do
|
|
210
221
|
end
|
211
222
|
end
|
212
223
|
|
213
|
-
let(:bootstrap) {
|
214
|
-
let(:ssh) {
|
215
|
-
let(:credentials) {
|
224
|
+
let(:bootstrap) { double(:run => true, :config => Hash.new) }
|
225
|
+
let(:ssh) { double }
|
226
|
+
let(:credentials) { double.as_null_object }
|
227
|
+
|
228
|
+
it "exits if Chef::Config[:node_name] is missing" do
|
229
|
+
Chef::Config[:node_name] = nil
|
230
|
+
|
231
|
+
expect { @knife.run }.to raise_error SystemExit
|
232
|
+
end
|
233
|
+
|
234
|
+
it "exits if Chef::Config[:client_key] is missing" do
|
235
|
+
Chef::Config[:client_key] = nil
|
236
|
+
|
237
|
+
expect { @knife.run }.to raise_error SystemExit
|
238
|
+
end
|
216
239
|
|
217
240
|
it "exits if node_name option is missing" do
|
218
241
|
@knife.config.delete(:chef_node_name)
|
219
242
|
|
220
|
-
|
243
|
+
expect { @knife.run }.to raise_error(SystemExit)
|
221
244
|
end
|
222
245
|
|
223
246
|
it "exits if platform is set to auto" do
|
224
247
|
@knife.config[:platform] = "auto"
|
225
248
|
|
226
|
-
|
249
|
+
expect { @knife.run }.to raise_error(SystemExit)
|
227
250
|
end
|
228
251
|
|
229
252
|
it "bootstraps a linode server" do
|
230
|
-
bootstrap.
|
253
|
+
expect(bootstrap).to receive(:run)
|
231
254
|
|
232
255
|
@knife.run
|
233
256
|
end
|
234
257
|
|
235
258
|
it "installs a new validation.pem key from the chef 10 server" do
|
236
259
|
@knife.config[:bootstrap_version] = "10"
|
237
|
-
Knife::Server::SSH.
|
238
|
-
:host => "11.11.11.13",
|
239
|
-
:
|
240
|
-
|
241
|
-
|
260
|
+
expect(Knife::Server::SSH).to receive(:new).with(
|
261
|
+
:host => "11.11.11.13",
|
262
|
+
:user => "root",
|
263
|
+
:port => "22",
|
264
|
+
:keys => ["~/.ssh/mykey_dsa"],
|
265
|
+
:password => "booboo"
|
266
|
+
)
|
267
|
+
expect(Knife::Server::Credentials).to receive(:new).
|
242
268
|
with(ssh, "/etc/chef/validation.pem", {})
|
243
|
-
credentials.
|
269
|
+
expect(credentials).to receive(:install_validation_key)
|
244
270
|
|
245
271
|
@knife.run
|
246
272
|
end
|
247
273
|
|
248
274
|
it "installs a new validation.pem key from the omnibus server" do
|
249
|
-
Knife::Server::SSH.
|
250
|
-
:host => "11.11.11.13",
|
251
|
-
:
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
275
|
+
expect(Knife::Server::SSH).to receive(:new).with(
|
276
|
+
:host => "11.11.11.13",
|
277
|
+
:user => "root",
|
278
|
+
:port => "22",
|
279
|
+
:keys => ["~/.ssh/mykey_dsa"],
|
280
|
+
:password => "booboo"
|
281
|
+
)
|
282
|
+
expect(Knife::Server::Credentials).to receive(:new).
|
283
|
+
with(ssh, "/etc/chef/validation.pem", :omnibus => true)
|
284
|
+
expect(credentials).to receive(:install_validation_key)
|
256
285
|
|
257
286
|
@knife.run
|
258
287
|
end
|
259
288
|
|
260
289
|
it "create a root client key" do
|
261
|
-
credentials.
|
290
|
+
expect(credentials).to receive(:create_root_client)
|
262
291
|
|
263
292
|
@knife.run
|
264
293
|
end
|
265
294
|
|
266
295
|
it "installs a client key" do
|
267
|
-
credentials.
|
296
|
+
expect(credentials).to receive(:install_client_key).
|
268
297
|
with("smithers", "/var/tmp/myclientkey.pem")
|
269
298
|
|
270
299
|
@knife.run
|