kitchen-rackspace 0.21.2 → 0.22.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.
@@ -1,664 +0,0 @@
1
- require_relative "../../spec_helper"
2
-
3
- describe Kitchen::Driver::Rackspace do
4
- let(:logged_output) { StringIO.new }
5
- let(:logger) { Logger.new(logged_output) }
6
- let(:config) { {} }
7
- let(:state) { {} }
8
- let(:platform_name) { "ubuntu" }
9
- let(:default_networks) { nil }
10
- let(:instance_name) { "potatoes" }
11
-
12
- let(:instance) do
13
- double(
14
- name: instance_name,
15
- logger:,
16
- to_str: "instance",
17
- platform: double(name: platform_name)
18
- )
19
- end
20
-
21
- let(:driver) { described_class.new(config) }
22
-
23
- before(:each) do
24
- allow_any_instance_of(described_class).to receive(:instance)
25
- .and_return(instance)
26
- ENV["RACKSPACE_USERNAME"] = "user"
27
- ENV["RACKSPACE_API_KEY"] = "key"
28
- end
29
-
30
- describe "#initialize" do
31
- before(:each) do
32
- allow(Fog).to receive(:timeout=)
33
- end
34
-
35
- context "default options" do
36
- it "defaults to v2 cloud" do
37
- expect(driver[:version]).to eq("v2")
38
- end
39
-
40
- it "defaults to the smallest flavor size" do
41
- expect(driver[:flavor_id]).to eq("performance1-1")
42
- end
43
-
44
- it "defaults to local user's SSH public key" do
45
- path = File.expand_path("~/.ssh/id_rsa.pub")
46
- expect(File).to receive(:exist?).with(path).and_return(true)
47
- expect(driver[:public_key_path]).to eq(path)
48
- end
49
-
50
- it "defaults to SSH with root user on port 22" do
51
- expect(driver[:username]).to eq("root")
52
- expect(driver[:port]).to eq("22")
53
- end
54
-
55
- it "defaults to a random server name" do
56
- expect(driver[:server_name]).to be_a(String)
57
- end
58
-
59
- it "defaults to the DFW region" do
60
- expect(driver[:rackspace_region]).to eq("dfw")
61
- end
62
-
63
- it "defaults to username from $RACKSPACE_USERNAME" do
64
- expect(driver[:rackspace_username]).to eq("user")
65
- end
66
-
67
- it "defaults to API key from $RACKSPACE_API_KEY" do
68
- expect(driver[:rackspace_api_key]).to eq("key")
69
- end
70
-
71
- it "defaults to wait_for timeout of 600 seconds" do
72
- expect(driver[:wait_for]).to eq(600)
73
- expect(Fog).to have_received(:timeout=).with(600)
74
- end
75
-
76
- it "defaults the SSH TCP bypassing to false" do
77
- expect(driver[:no_ssh_tcp_check]).to eq(false)
78
- end
79
-
80
- it "defaults the TCP bypass sleep time to 120 seconds" do
81
- expect(driver[:no_ssh_tcp_check_sleep]).to eq(120)
82
- end
83
-
84
- it "defaults to the standard Rackspace networks" do
85
- expect(driver[:networks]).to eq(default_networks)
86
- end
87
-
88
- it "defaults to not waiting for rackconnect" do
89
- expect(driver[:rackconnect_wait]).to eq(false)
90
- end
91
-
92
- it "defaults to not waiting for managed service level" do
93
- expect(driver[:servicelevel_wait]).to eq(false)
94
- end
95
-
96
- it "defaults to the public ip address" do
97
- expect(driver[:servicenet]).to eq(false)
98
- end
99
-
100
- it "defaults to no_passwd_lock as false" do
101
- expect(driver[:no_passwd_lock]).to eq(false)
102
- end
103
- end
104
-
105
- platforms = {
106
- "ubuntu-12.04" => "f2d30a56-bc2b-4906-8027-92f8a45bbb10",
107
- "ubuntu-12" => "f2d30a56-bc2b-4906-8027-92f8a45bbb10",
108
- "ubuntu-14.04" => "e6baca58-c5f4-48d3-901a-abdeb0cfe907",
109
- "ubuntu-14" => "e6baca58-c5f4-48d3-901a-abdeb0cfe907",
110
- "ubuntu" => "9b3ae961-0ba0-4d5a-973f-2e79043f0ddd",
111
- "centos-6" => "7d791876-4c8f-44a2-8d4b-e84bfb0b1c8c",
112
- "centos" => "1a79f262-33d2-428c-924b-9852a6c15ea8",
113
- }
114
- platforms.each do |platform, id|
115
- context "name is #{platform}" do
116
- let(:platform_name) { platform }
117
-
118
- it "defaults to the correct image ID" do
119
- expect(driver[:image_id]).to eq(id)
120
- end
121
- end
122
- end
123
-
124
- context "overridden options" do
125
- config = {
126
- image_id: "22",
127
- flavor_id: "33",
128
- public_key_path: "/tmp",
129
- username: "admin",
130
- port: "2222",
131
- server_name: "puppy",
132
- rackspace_region: "ord",
133
- wait_for: 1200,
134
- rackconnect_wait: true,
135
- servicelevel_wait: true,
136
- use_private_ip_address: true,
137
- }
138
-
139
- let(:config) { config }
140
-
141
- config.each do |key, value|
142
- it "it uses the overridden #{key} option" do
143
- expect(driver[key]).to eq(value)
144
- end
145
- end
146
-
147
- it "sets the new wait_for variable" do
148
- expect(driver[:wait_for]).to eq(1200)
149
- expect(Fog).to have_received(:timeout=).with(1200)
150
- end
151
- end
152
-
153
- context "OpenStack environment variables" do
154
- before(:each) do
155
- ENV.delete("RACKSPACE_USERNAME")
156
- ENV.delete("RACKSPACE_API_KEY")
157
- ENV.delete("RACKSPACE_REGION")
158
- ENV["OS_USERNAME"] = "os_user"
159
- ENV["OS_PASSWORD"] = "os_pass"
160
- ENV["OS_REGION_NAME"] = "os_region"
161
- end
162
-
163
- it "gets to username from $OS_USERNAME" do
164
- expect(driver[:rackspace_username]).to eq("os_user")
165
- end
166
-
167
- it "gets to API key from $OS_PASSWORD" do
168
- expect(driver[:rackspace_api_key]).to eq("os_pass")
169
- end
170
-
171
- it "gets to region from $OS_REGION_NAME" do
172
- expect(driver[:rackspace_region]).to eq("os_region")
173
- end
174
- end
175
- end
176
-
177
- describe "#create" do
178
- let(:config) { super().merge(wait_for: "1200") }
179
- let(:server) do
180
- double(id: "test123",
181
- wait_for: true,
182
- public_ip_address: "1.2.3.4")
183
- end
184
-
185
- before(:each) do
186
- {
187
- default_name: "a_monkey!",
188
- create_server: server,
189
- tcp_check: true,
190
- }.each do |k, v|
191
- allow_any_instance_of(described_class).to receive(k).and_return(v)
192
- end
193
- end
194
-
195
- context "username and API key only provided" do
196
- let(:config) do
197
- {
198
- rackspace_username: "hello",
199
- rackspace_api_key: "world",
200
- wait_for: 1200,
201
- }
202
- end
203
-
204
- it "generates a server name in the absence of one" do
205
- driver.create(state)
206
- expect(driver[:server_name]).to eq("a_monkey!")
207
- end
208
-
209
- it "gets a proper server ID" do
210
- driver.create(state)
211
- expect(state[:server_id]).to eq("test123")
212
- end
213
-
214
- it "gets a proper hostname (IP)" do
215
- driver.create(state)
216
- expect(state[:hostname]).to eq("1.2.3.4")
217
- end
218
-
219
- it "calls tcp_check" do
220
- expect(driver).to receive(:tcp_check)
221
- driver.create(state)
222
- end
223
- end
224
-
225
- context "a Fog error" do
226
- before(:each) do
227
- allow_any_instance_of(described_class).to receive(:create_server)
228
- .and_raise(Fog::Errors::Error, "Uhoh")
229
- end
230
-
231
- it "re-raises the error" do
232
- expect { driver.create(state) }.to raise_error(Kitchen::ActionFailed,
233
- "Uhoh")
234
- end
235
- end
236
- end
237
-
238
- describe "#create and rackconnect_wait" do
239
- let(:server) do
240
- double(id: "test123",
241
- wait_for: true,
242
- public_ip_address: "1.2.3.4",
243
- private_ip_address: "10.9.8.7",
244
- update: nil)
245
- end
246
-
247
- before(:each) do
248
- {
249
- default_name: "a_monkey!",
250
- create_server: server,
251
- tcp_check: true,
252
- }.each do |k, v|
253
- allow_any_instance_of(described_class).to receive(k).and_return(v)
254
- end
255
- end
256
-
257
- context "username and API key only provided" do
258
- let(:config) do
259
- {
260
- rackspace_username: "hello",
261
- rackspace_api_key: "world",
262
- wait_for: 1200,
263
- rackconnect_wait: true,
264
- }
265
- end
266
-
267
- it "generates a server name in the absence of one" do
268
- driver.create(state)
269
- expect(driver[:server_name]).to eq("a_monkey!")
270
- end
271
-
272
- it "gets a proper server ID" do
273
- driver.create(state)
274
- expect(state[:server_id]).to eq("test123")
275
- end
276
-
277
- it "gets a proper hostname (IP)" do
278
- driver.create(state)
279
- expect(state[:hostname]).to eq("1.2.3.4")
280
- end
281
-
282
- it "calls tcp_check" do
283
- expect(driver).to receive(:tcp_check)
284
- driver.create(state)
285
- end
286
-
287
- it "calls rackconnect_check " do
288
- expect(driver).to receive(:rackconnect_check)
289
- driver.create(state)
290
- end
291
-
292
- it "rackconnect_check waits for rackconnect_automation" do
293
- expect(server).to receive(:wait_for)
294
- driver.send(:rackconnect_check, server)
295
- end
296
- end
297
- end
298
-
299
- describe "#create and servicelevel_wait" do
300
- let(:server) do
301
- double(id: "test123",
302
- wait_for: true,
303
- public_ip_address: "1.2.3.4",
304
- private_ip_address: "10.9.8.7",
305
- update: nil)
306
- end
307
-
308
- before(:each) do
309
- {
310
- default_name: "a_monkey!",
311
- create_server: server,
312
- tcp_check: true,
313
- }.each do |k, v|
314
- allow_any_instance_of(described_class).to receive(k).and_return(v)
315
- end
316
- end
317
-
318
- context "username and API key only provided" do
319
- let(:config) do
320
- {
321
- rackspace_username: "hello",
322
- rackspace_api_key: "world",
323
- wait_for: 1200,
324
- servicelevel_wait: true,
325
- }
326
- end
327
-
328
- it "generates a server name in the absence of one" do
329
- driver.create(state)
330
- expect(driver[:server_name]).to eq("a_monkey!")
331
- end
332
-
333
- it "gets a proper server ID" do
334
- driver.create(state)
335
- expect(state[:server_id]).to eq("test123")
336
- end
337
-
338
- it "gets a proper hostname (IP)" do
339
- driver.create(state)
340
- expect(state[:hostname]).to eq("1.2.3.4")
341
- end
342
-
343
- it "calls tcp_check" do
344
- expect(driver).to receive(:tcp_check)
345
- driver.create(state)
346
- end
347
-
348
- it "calls servicelevel_check " do
349
- expect(driver).to receive(:servicelevel_check)
350
- driver.create(state)
351
- end
352
-
353
- it "servicelevel_check waits for managed service level automation" do
354
- expect(server).to receive(:wait_for)
355
- driver.send(:servicelevel_check, server)
356
- end
357
- end
358
- end
359
-
360
- describe "#create and use_private_ip_address" do
361
- let(:server) do
362
- double(id: "test123",
363
- wait_for: true,
364
- public_ip_address: "1.2.3.4",
365
- private_ip_address: "10.9.8.7")
366
- end
367
-
368
- before(:each) do
369
- {
370
- default_name: "a_monkey!",
371
- create_server: server,
372
- tcp_check: true,
373
- }.each do |k, v|
374
- allow_any_instance_of(described_class).to receive(k).and_return(v)
375
- end
376
- end
377
-
378
- context "username and API key only provided" do
379
- let(:config) do
380
- {
381
- rackspace_username: "hello",
382
- rackspace_api_key: "world",
383
- wait_for: 1200,
384
- servicenet: true,
385
- }
386
- end
387
-
388
- it "generates a server name in the absence of one" do
389
- driver.create(state)
390
- expect(driver[:server_name]).to eq("a_monkey!")
391
- end
392
-
393
- it "gets a proper server ID" do
394
- driver.create(state)
395
- expect(state[:server_id]).to eq("test123")
396
- end
397
-
398
- it "gets a private ip as the hostname" do
399
- driver.create(state)
400
- expect(state[:hostname]).to eq("10.9.8.7")
401
- end
402
- end
403
- end
404
-
405
- describe "#destroy" do
406
- let(:server_id) { "12345" }
407
- let(:hostname) { "example.com" }
408
- let(:state) { { server_id:, hostname: } }
409
- let(:server) { double(nil?: false, destroy: true) }
410
- let(:servers) { double(get: server) }
411
- let(:compute) { double(servers:) }
412
-
413
- before(:each) do
414
- allow_any_instance_of(described_class).to receive(:compute)
415
- .and_return(compute)
416
- end
417
-
418
- context "a live server that needs to be destroyed" do
419
- it "destroys the server" do
420
- expect(state).to receive(:delete).with(:server_id)
421
- expect(state).to receive(:delete).with(:hostname)
422
- driver.destroy(state)
423
- end
424
- end
425
-
426
- context "no server ID present" do
427
- let(:state) { {} }
428
-
429
- it "does nothing" do
430
- allow(driver).to receive(:compute)
431
- expect(driver).to_not receive(:compute)
432
- expect(state).to_not receive(:delete)
433
- driver.destroy(state)
434
- end
435
- end
436
-
437
- context "a server that was already destroyed" do
438
- let(:servers) do
439
- s = double("servers")
440
- allow(s).to receive(:get).with("12345").and_return(nil)
441
- s
442
- end
443
- let(:compute) { double(servers:) }
444
-
445
- before(:each) do
446
- allow_any_instance_of(described_class).to receive(:compute)
447
- .and_return(compute)
448
- end
449
-
450
- it "does not try to destroy the server again" do
451
- allow_message_expectations_on_nil
452
- driver.destroy(state)
453
- end
454
- end
455
- end
456
-
457
- describe "#compute" do
458
- let(:config) do
459
- {
460
- rackspace_username: "monkey",
461
- rackspace_api_key: "potato",
462
- rackspace_region: "ord",
463
- }
464
- end
465
-
466
- context "all requirements provided" do
467
- it "creates a new compute connection" do
468
- allow(Fog::Compute).to receive(:new) { |arg| arg }
469
- res = config.merge(provider: "Rackspace", version: "v2")
470
- expect(driver.send(:compute)).to eq(res)
471
- end
472
- end
473
-
474
- context "no username provided" do
475
- let(:config) do
476
- { rackspace_username: nil, rackspace_api_key: "1234" }
477
- end
478
-
479
- it "raises an error" do
480
- expect { driver.send(:compute) }.to raise_error(ArgumentError)
481
- end
482
- end
483
-
484
- context "no API key provided" do
485
- let(:config) do
486
- { rackspace_username: "monkey", rackspace_api_key: nil }
487
- end
488
-
489
- it "raises an error" do
490
- expect { driver.send(:compute) }.to raise_error(ArgumentError)
491
- end
492
- end
493
- end
494
-
495
- describe "#create_server" do
496
- let(:config) do
497
- {
498
- server_name: "hello",
499
- image_id: "there",
500
- flavor_id: "captain",
501
- public_key_path: "tarpals",
502
- no_passwd_lock: false,
503
- networks: default_networks,
504
- user_data: nil,
505
- config_drive: false,
506
- }
507
- end
508
- before(:each) do
509
- @expected = config.merge(name: config[:server_name])
510
- @expected.delete_if do |k, _|
511
- k == :server_name
512
- end
513
- end
514
- let(:servers) do
515
- s = double("servers")
516
- allow(s).to receive(:bootstrap) { |arg| arg }
517
- s
518
- end
519
- let(:compute) { double(servers:) }
520
-
521
- before(:each) do
522
- allow_any_instance_of(described_class).to receive(:compute)
523
- .and_return(compute)
524
- end
525
-
526
- it "creates the server using a compute connection" do
527
- expect(driver.send(:create_server)).to eq(@expected)
528
- end
529
-
530
- context "additional networks specified" do
531
- let(:server_id) { "12345" }
532
- let(:server) do
533
- double(id: "test123", wait_for: true,
534
- public_ip_address: "1.2.3.4")
535
- end
536
- let(:hostname) { "example.com" }
537
- let(:servers) { double("servers", bootstrap: server) }
538
- let(:compute) { double(Fog::Compute, servers:) }
539
- let(:state) { { server_id:, hostname: } }
540
- let(:user_specified_network) { "bob_dole" }
541
- let(:config) do
542
- {
543
- rackspace_username: "monkey",
544
- rackspace_api_key: "potato",
545
- rackspace_region: "ord",
546
- networks: [user_specified_network],
547
- }
548
- end
549
-
550
- before(:each) do
551
- { wait_for_sshd: true, compute: }.each do |k, v|
552
- allow_any_instance_of(described_class).to receive(k).and_return(v)
553
- end
554
- end
555
-
556
- it "has the user specified network, plus default Rackspace networks" do
557
- driver.send(:create_server)
558
- expect(servers).to have_received(:bootstrap) do |arg|
559
- expect(arg[:networks][2]).to eq user_specified_network
560
- end
561
- end
562
- end
563
- end
564
-
565
- describe "#default_name" do
566
- let(:login) { "user" }
567
- let(:hostname) { "host" }
568
-
569
- before(:each) do
570
- allow(Etc).to receive(:getlogin).and_return(login)
571
- allow(Socket).to receive(:gethostname).and_return(hostname)
572
- end
573
-
574
- it "generates a name" do
575
- expect(driver.send(:default_name)).to match(/^potatoes-user-host-(\S*)/)
576
- end
577
-
578
- context "local node with a long hostname" do
579
- let(:hostname) { "ab.c" * 20 }
580
-
581
- it "limits the generated name to 63 characters" do
582
- expect(driver.send(:default_name).length).to be <= 63
583
- end
584
- end
585
-
586
- context "node with a long hostname, username, and base name" do
587
- let(:login) { "abcd" * 20 }
588
- let(:hostname) { "efgh" * 20 }
589
- let(:instance_name) { "ijkl" * 20 }
590
-
591
- it "limits the generated name to 63 characters" do
592
- expect(driver.send(:default_name).length).to eq(63)
593
- end
594
- end
595
-
596
- context "a login and hostname with punctuation in them" do
597
- let(:login) { "some.u-se-r" }
598
- let(:hostname) { "a.host-name" }
599
- let(:instance_name) { "a.instance-name" }
600
-
601
- it "strips out the dots to prevent bad server names" do
602
- expect(driver.send(:default_name)).to_not include(".")
603
- end
604
-
605
- it "strips out all but the three hyphen separators" do
606
- expect(driver.send(:default_name).count("-")).to eq(3)
607
- end
608
- end
609
-
610
- context "a non-login shell" do
611
- let(:login) { nil }
612
-
613
- it "subs in a placeholder login string" do
614
- expect(driver.send(:default_name)).to match(/^potatoes-nologin-/)
615
- end
616
- end
617
- end
618
-
619
- describe "#tcp_check" do
620
- before(:each) do
621
- allow_any_instance_of(described_class).to receive(:wait_for_sshd)
622
- allow_any_instance_of(described_class).to receive(:sleep)
623
- end
624
-
625
- context "the default non-skipping behavior" do
626
- it "uses Kitchen's own SSH check" do
627
- expect(driver).to receive(:wait_for_sshd)
628
- expect(driver).to_not receive(:sleep)
629
- driver.send(:tcp_check, state)
630
- end
631
- end
632
-
633
- context "a config set to wait instead of TCP check" do
634
- let(:config) { { no_ssh_tcp_check: true } }
635
-
636
- it "uses a sleep instead of a port check" do
637
- expect(driver).to_not receive(:wait_for_sshd)
638
- expect(driver).to receive(:sleep)
639
- driver.send(:tcp_check, state)
640
- end
641
- end
642
- end
643
-
644
- describe "#networks" do
645
- context "the default Rackspace networks" do
646
- it "returns nil so Fog will use the defaults" do
647
- expect(driver.send(:networks)).to eq(nil)
648
- end
649
- end
650
-
651
- context "a custom Rackspace network" do
652
- let(:config) { { networks: %w{abcdefg} } }
653
-
654
- it "returns the base networks plus the custom one" do
655
- expected = %w{
656
- 00000000-0000-0000-0000-000000000000
657
- 11111111-1111-1111-1111-111111111111
658
- abcdefg
659
- }
660
- expect(driver.send(:networks)).to eq(expected)
661
- end
662
- end
663
- end
664
- end