-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
docker_spec.rb
771 lines (661 loc) · 33.1 KB
/
docker_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
# frozen_string_literal: true
require 'spec_helper'
require 'fakefs/spec_helpers'
module Beaker
platforms = [
'ubuntu-14.04-x86_64',
'fedora-22-x86_64',
'centos-7-x86_64',
'sles-12-x86_64',
'archlinux-2017.12.27-x86_64',
'amazon-2023-x86_64',
]
describe Docker do
require 'docker'
let(:hosts) do
the_hosts = make_hosts
the_hosts[2]['dockeropts'] = {
'Labels' => {
'one' => 3,
'two' => 4,
},
}
the_hosts
end
let(:logger) do
logger = instance_double(Logger)
allow(logger).to receive(:debug)
allow(logger).to receive(:info)
allow(logger).to receive(:warn)
allow(logger).to receive(:error)
allow(logger).to receive(:notify)
logger
end
let(:options) do
{
logger: logger,
forward_ssh_agent: true,
provision: true,
dockeropts: {
'Labels' => {
'one' => 1,
'two' => 2,
},
},
}
end
let(:image) do
image = instance_double(::Docker::Image)
allow(image).to receive(:id).and_return('zyxwvu')
allow(image).to receive(:tag)
image
end
let(:container_mode) do
'rootless'
end
let(:container_config) do
conf = {
'HostConfig' => {
'NetworkMode' => 'slirp4netns',
},
'NetworkSettings' => {
'IPAddress' => '192.0.2.1',
'Ports' => {
'22/tcp' => [
{
'HostIp' => '0.0.0.0',
'HostPort' => 8022,
},
],
},
'Gateway' => '192.0.2.254',
},
}
conf['HostConfig']['NetworkMode'] = 'bridge' unless container_mode == 'rootless'
conf
end
let(:container) do
container = instance_double(::Docker::Container)
allow(container).to receive(:id).and_return('abcdef')
allow(container).to receive(:start)
allow(container).to receive(:stats)
allow(container).to receive(:info).and_return(
*(0..2).map { |index| { 'Names' => ["/spec-container-#{index}"] } },
)
allow(container).to receive(:json).and_return(container_config)
allow(container).to receive(:kill)
allow(container).to receive(:delete)
allow(container).to receive(:exec)
container
end
let(:docker) { ::Beaker::Docker.new(hosts, options) }
let(:docker_options) { nil }
let(:version) { { 'ApiVersion' => '1.18', 'Arch' => 'amd64', 'GitCommit' => '4749651', 'GoVersion' => 'go1.4.2', 'KernelVersion' => '3.16.0-37-generic', 'Os' => 'linux', 'Version' => '1.6.0' } }
before do
allow(::Docker).to receive(:rootless?).and_return(true)
@docker_host = ENV.fetch('DOCKER_HOST', nil)
ENV.delete('DOCKER_HOST') if @docker_host
end
after do
ENV['DOCKER_HOST'] = @docker_host if @docker_host
end
context 'with connection failure' do
describe '#initialize' do
before do
require 'excon'
allow(::Docker).to receive(:version).and_raise(Excon::Errors::SocketError.new(StandardError.new('oops'))).exactly(4).times
end
it 'fails when docker not present' do
expect { docker }.to raise_error(RuntimeError, /Docker instance not connectable/)
expect { docker }.to raise_error(RuntimeError, /Check your DOCKER_HOST variable has been set/)
expect { docker }.to raise_error(RuntimeError, /If you are on OSX or Windows, you might not have Docker Machine setup correctly/)
expect { docker }.to raise_error(RuntimeError, /Error was: oops/)
end
end
end
context 'with a working connection' do
before do
# Stub out all of the docker-api gem. we should never really call it from these tests
allow(::Docker).to receive(:options).and_return(docker_options)
allow(::Docker).to receive(:podman?).and_return(false)
allow(::Docker).to receive(:version).and_return(version)
allow(::Docker::Image).to receive(:build).and_return(image)
allow(::Docker::Image).to receive(:create).and_return(image)
allow(::Docker::Container).to receive(:create).and_return(container)
end
describe '#initialize' do
it 'sets Docker options' do
expect(::Docker).to receive(:options=).with({ write_timeout: 300, read_timeout: 300 }).once
docker
end
context 'when Docker options are already set' do
let(:docker_options) { { write_timeout: 600, foo: :bar } }
it 'does not override Docker options' do
expect(::Docker).to receive(:options=).with({ write_timeout: 600, read_timeout: 300, foo: :bar }).once
docker
end
end
it 'checks the Docker gem can work with the api' do
expect { docker }.not_to raise_error
end
it 'hooks the Beaker logger into the Docker one' do
expect(::Docker).to receive(:logger=).with(logger)
docker
end
end
describe '#install_ssh_components' do
let(:test_container) { object_double(container) }
let(:host) { hosts[0] }
before do
allow(docker).to receive(:dockerfile_for)
end
platforms.each do |platform|
it 'calls exec at least twice' do
host['platform'] = platform
expect(test_container).to receive(:exec).at_least(:twice)
docker.install_ssh_components(test_container, host)
end
end
it 'accepts alpine as valid platform' do
host['platform'] = Beaker::Platform.new('alpine-3.8-x86_64')
expect(test_container).to receive(:exec).at_least(:twice)
docker.install_ssh_components(test_container, host)
end
it 'raises an error with an unsupported platform' do
host['platform'] = Beaker::Platform.new('windows-11-64')
expect { docker.install_ssh_components(test_container, host) }.to raise_error(RuntimeError, /windows/)
end
end
describe '#provision' do
before do
allow(docker).to receive(:dockerfile_for)
end
context 'when the host has "tag" defined' do
before do
hosts.each do |host|
host['tag'] = 'my_tag'
end
end
it 'tags the image with the value of the tag' do
expect(image).to receive(:tag).with({ repo: 'my_tag' }).exactly(3).times
docker.provision
end
end
context 'when the host has "use_image_entry_point" set to true on the host' do
before do
hosts.each do |host|
host['use_image_entry_point'] = true
end
end
it 'does not call #dockerfile_for but run methods necessary for ssh installation' do
expect(docker).not_to receive(:dockerfile_for)
expect(docker).to receive(:install_ssh_components).exactly(3).times # once per host
expect(docker).to receive(:fix_ssh).exactly(3).times # once per host
docker.provision
end
end
context 'when the host has a "dockerfile" for the host' do
before do
allow(docker).to receive(:buildargs_for).and_return('buildargs')
hosts.each do |host|
host['dockerfile'] = 'mydockerfile'
end
end
it 'does not call #dockerfile_for but run methods necessary for ssh installation' do
allow(File).to receive(:exist?).with('mydockerfile').and_return(true)
allow(::Docker::Image).to receive(:build_from_dir).with('/', hash_including(rm: true, buildargs: 'buildargs')).and_return(image)
expect(docker).not_to receive(:dockerfile_for)
expect(docker).to receive(:install_ssh_components).exactly(3).times # once per host
expect(docker).to receive(:fix_ssh).exactly(3).times # once per host
docker.provision
end
end
it 'calls image create for hosts when use_image_as_is is defined' do
hosts.each do |host|
host['use_image_as_is'] = true
expect(docker).not_to receive(:install_ssh_components)
expect(docker).not_to receive(:fix_ssh)
expect(::Docker::Image).to receive(:create).with('fromImage' => host['image']) # once per host
expect(::Docker::Image).not_to receive(:build)
expect(::Docker::Image).not_to receive(:build_from_dir)
end
docker.provision
end
it 'calls dockerfile_for with all the hosts' do
hosts.each do |host|
allow(docker).to receive(:dockerfile_for).with(host).and_return('')
expect(docker).not_to receive(:install_ssh_components)
expect(docker).not_to receive(:fix_ssh)
expect(docker).to receive(:dockerfile_for).with(host)
end
docker.provision
end
it 'passes the Dockerfile on to Docker::Image.create' do
allow(docker).to receive(:dockerfile_for).and_return('special testing value')
expect(::Docker::Image).to receive(:build).with('special testing value', { rm: true, buildargs: '{}' })
docker.provision
end
it 'passes the buildargs from ENV DOCKER_BUILDARGS on to Docker::Image.create' do
allow(docker).to receive(:dockerfile_for).and_return('special testing value')
ENV['DOCKER_BUILDARGS'] = 'HTTP_PROXY=http://1.1.1.1:3128'
expect(::Docker::Image).to receive(:build).with('special testing value', { rm: true, buildargs: '{"HTTP_PROXY":"http://1.1.1.1:3128"}' })
docker.provision
end
it 'passes the multiple buildargs from ENV DOCKER_BUILDARGS on to Docker::Image.create' do
allow(docker).to receive(:dockerfile_for).and_return('special testing value')
ENV['DOCKER_BUILDARGS'] = 'HTTP_PROXY=http://1.1.1.1:3128 HTTPS_PROXY=https://1.1.1.1:3129'
expect(::Docker::Image).to receive(:build).with('special testing value', { rm: true, buildargs: '{"HTTP_PROXY":"http://1.1.1.1:3128","HTTPS_PROXY":"https://1.1.1.1:3129"}' })
docker.provision
end
it 'creates a container based on the Image (identified by image.id)' do
hosts.each_with_index do |host, index|
expect(::Docker::Container).to receive(:create).with({
'Image' => image.id,
'Hostname' => host.name,
'HostConfig' => {
'PortBindings' => {
'22/tcp' => [{ 'HostPort' => /\b\d{4}\b/, 'HostIp' => '0.0.0.0' }],
},
'PublishAllPorts' => true,
'Privileged' => true,
'RestartPolicy' => {
'Name' => 'always',
},
},
'Labels' => {
'one' => ((index == 2) ? 3 : 1),
'two' => ((index == 2) ? 4 : 2),
},
'name' => /\Abeaker-/,
})
end
docker.provision
end
it 'creates a named container based on the Image (identified by image.id)' do
hosts.each_with_index do |host, index|
container_name = "spec-container-#{index}"
host['docker_container_name'] = container_name
allow(::Docker::Container).to receive(:all).and_return([])
expect(::Docker::Container).to receive(:create).with({
'Image' => image.id,
'Hostname' => host.name,
'name' => container_name,
'HostConfig' => {
'PortBindings' => {
'22/tcp' => [{ 'HostPort' => /\b\d{4}\b/, 'HostIp' => '0.0.0.0' }],
},
'PublishAllPorts' => true,
'Privileged' => true,
'RestartPolicy' => {
'Name' => 'always',
},
},
'Labels' => {
'one' => ((index == 2) ? 3 : 1),
'two' => ((index == 2) ? 4 : 2),
},
})
end
docker.provision
end
it 'creates a container with volumes bound' do
hosts.each_with_index do |host, index|
host['mount_folders'] = {
'mount1' => {
'host_path' => '/source_folder',
'container_path' => '/mount_point',
},
'mount2' => {
'host_path' => '/another_folder',
'container_path' => '/another_mount',
'opts' => 'ro',
},
'mount3' => {
'host_path' => '/different_folder',
'container_path' => '/different_mount',
'opts' => 'rw',
},
'mount4' => {
'host_path' => './',
'container_path' => '/relative_mount',
},
'mount5' => {
'host_path' => 'local_folder',
'container_path' => '/another_relative_mount',
},
}
expect(::Docker::Container).to receive(:create).with({
'Image' => image.id,
'Hostname' => host.name,
'HostConfig' => {
'Binds' => [
'/source_folder:/mount_point:z',
'/another_folder:/another_mount:ro',
'/different_folder:/different_mount:rw',
"#{File.expand_path('./')}:/relative_mount:z",
"#{File.expand_path('local_folder')}:/another_relative_mount:z",
],
'PortBindings' => {
'22/tcp' => [{ 'HostPort' => /\b\d{4}\b/, 'HostIp' => '0.0.0.0' }],
},
'PublishAllPorts' => true,
'Privileged' => true,
'RestartPolicy' => {
'Name' => 'always',
},
},
'Labels' => {
'one' => ((index == 2) ? 3 : 1),
'two' => ((index == 2) ? 4 : 2),
},
'name' => /\Abeaker-/,
})
end
docker.provision
end
it 'creates a container with capabilities added' do
hosts.each_with_index do |host, index|
host['docker_cap_add'] = %w[NET_ADMIN SYS_ADMIN]
expect(::Docker::Container).to receive(:create).with({
'Image' => image.id,
'Hostname' => host.name,
'HostConfig' => {
'PortBindings' => {
'22/tcp' => [{ 'HostPort' => /\b\d{4}\b/, 'HostIp' => '0.0.0.0' }],
},
'PublishAllPorts' => true,
'RestartPolicy' => {
'Name' => 'always',
},
'CapAdd' => %w[NET_ADMIN SYS_ADMIN],
},
'Labels' => {
'one' => ((index == 2) ? 3 : 1),
'two' => ((index == 2) ? 4 : 2),
},
'name' => /\Abeaker-/,
})
end
docker.provision
end
it 'creates a container with port bindings' do
hosts.each_with_index do |host, index|
host['docker_port_bindings'] = {
'8080/tcp' => [{ 'HostPort' => '8080', 'HostIp' => '0.0.0.0' }],
}
expect(::Docker::Container).to receive(:create).with({
'ExposedPorts' => {
'8080/tcp' => {},
},
'Image' => image.id,
'Hostname' => host.name,
'HostConfig' => {
'PortBindings' => {
'22/tcp' => [{ 'HostPort' => /\b\d{4}\b/, 'HostIp' => '0.0.0.0' }],
'8080/tcp' => [{ 'HostPort' => '8080', 'HostIp' => '0.0.0.0' }],
},
'PublishAllPorts' => true,
'Privileged' => true,
'RestartPolicy' => {
'Name' => 'always',
},
},
'Labels' => {
'one' => ((index == 2) ? 3 : 1),
'two' => ((index == 2) ? 4 : 2),
},
'name' => /\Abeaker-/,
})
end
docker.provision
end
it 'starts the container' do
expect(container).to receive(:start)
docker.provision
end
context 'when connecting to ssh' do
%w[rootless privileged].each do |mode|
context "when #{mode}" do
let(:container_mode) do
mode
end
it 'exposes port 22 to beaker' do
docker.provision
expect(hosts[0]['ip']).to eq '127.0.0.1'
expect(hosts[0]['port']).to eq 8022
end
it 'exposes port 22 to beaker when using DOCKER_HOST' do
ENV['DOCKER_HOST'] = 'tcp://192.0.2.2:2375'
docker.provision
expect(hosts[0]['ip']).to eq '192.0.2.2'
expect(hosts[0]['port']).to eq 8022
end
it 'has ssh agent forwarding enabled' do
docker.provision
expect(hosts[0]['ip']).to eq '127.0.0.1'
expect(hosts[0]['port']).to eq 8022
expect(hosts[0]['ssh'][:password]).to eq 'root'
expect(hosts[0]['ssh'][:port]).to eq 8022
expect(hosts[0]['ssh'][:forward_agent]).to be true
end
it 'connects to gateway ip' do
FakeFS do
FileUtils.touch('/.dockerenv')
docker.provision
expect(hosts[0]['ip']).to eq '192.0.2.254'
expect(hosts[0]['port']).to eq 8022
end
end
end
end
end
it 'generates a new /etc/hosts file referencing each host' do
ENV['DOCKER_HOST'] = nil
docker.provision
hosts.each do |host|
allow(docker).to receive(:get_domain_name).with(host).and_return('labs.lan')
etc_hosts = <<~HOSTS
127.0.0.1\tlocalhost localhost.localdomain
192.0.2.1\tvm1.labs.lan vm1
192.0.2.1\tvm2.labs.lan vm2
192.0.2.1\tvm3.labs.lan vm3
HOSTS
expect(docker).to receive(:set_etc_hosts).with(host, etc_hosts).once
end
docker.hack_etc_hosts(hosts, options)
end
it 'records the image and container for later' do
docker.provision
expect(hosts[0]['docker_image_id']).to eq image.id
expect(hosts[0]['docker_container_id']).to eq container.id
end
context 'when provision=false' do
let(:options) do
{
logger: logger,
forward_ssh_agent: true,
provision: false,
}
end
it 'fixes ssh' do
hosts.each_with_index do |host, index|
container_name = "spec-container-#{index}"
host['docker_container_name'] = container_name
allow(::Docker::Container).to receive(:all).and_return([container])
expect(docker).to receive(:fix_ssh).once
end
docker.provision
end
it 'does not create a container if a named one already exists' do
hosts.each_with_index do |host, index|
container_name = "spec-container-#{index}"
host['docker_container_name'] = container_name
allow(::Docker::Container).to receive(:all).and_return([container])
expect(::Docker::Container).not_to receive(:create)
end
docker.provision
end
end
end
describe '#cleanup' do
before do
# get into a state where there's something to clean
allow(::Docker::Container).to receive(:all).and_return([container])
allow(::Docker::Image).to receive(:remove).with(image.id)
allow(docker).to receive(:dockerfile_for)
docker.provision
end
it 'stops the containers' do
allow(docker).to receive(:sleep).and_return(true)
expect(container).to receive(:kill)
docker.cleanup
end
it 'deletes the containers' do
allow(docker).to receive(:sleep).and_return(true)
expect(container).to receive(:delete)
docker.cleanup
end
it 'deletes the images' do
allow(docker).to receive(:sleep).and_return(true)
expect(::Docker::Image).to receive(:remove).with(image.id)
docker.cleanup
end
it 'does not delete the image if docker_preserve_image is set to true' do
allow(docker).to receive(:sleep).and_return(true)
hosts.each do |host|
host['docker_preserve_image'] = true
end
expect(::Docker::Image).not_to receive(:remove)
docker.cleanup
end
it 'deletes the image if docker_preserve_image is set to false' do
allow(docker).to receive(:sleep).and_return(true)
hosts.each do |host|
host['docker_preserve_image'] = false
end
expect(::Docker::Image).to receive(:remove).with(image.id)
docker.cleanup
end
end
describe '#dockerfile_for' do
FakeFS.deactivate!
it 'raises on an unsupported platform' do
expect { docker.send(:dockerfile_for, make_host('none', { 'platform' => 'solaris-11-64', 'image' => 'foobar' })) }.to raise_error(/platform solaris-11-64 not yet supported/)
end
it 'sets "ENV container docker"' do
FakeFS.deactivate!
platforms.each do |platform|
dockerfile = docker.send(:dockerfile_for, make_host('none', {
'platform' => platform,
'image' => 'foobar',
}))
expect(dockerfile).to match(/ENV container docker/)
end
end
it 'adds docker_image_first_commands as RUN statements' do
FakeFS.deactivate!
platforms.each do |platform|
dockerfile = docker.send(:dockerfile_for, make_host('none', {
'platform' => platform,
'image' => 'foobar',
'docker_image_first_commands' => [
'special one',
'special two',
'special three',
],
}))
expect(dockerfile).to match(/RUN special one\nRUN special two\nRUN special three/)
end
end
it 'adds docker_image_commands as RUN statements' do
FakeFS.deactivate!
platforms.each do |platform|
dockerfile = docker.send(:dockerfile_for, make_host('none', {
'platform' => platform,
'image' => 'foobar',
'docker_image_commands' => [
'special one',
'special two',
'special three',
],
}))
expect(dockerfile).to match(/RUN special one\nRUN special two\nRUN special three/)
end
end
it 'adds docker_image_entrypoint' do
FakeFS.deactivate!
platforms.each do |platform|
dockerfile = docker.send(:dockerfile_for, make_host('none', {
'platform' => platform,
'image' => 'foobar',
'docker_image_entrypoint' => '/bin/bash',
}))
expect(dockerfile).to match(%r{ENTRYPOINT /bin/bash})
end
end
it 'uses zypper on sles' do
FakeFS.deactivate!
dockerfile = docker.send(:dockerfile_for, make_host('none', {
'platform' => Beaker::Platform.new('sles-12-x86_64'),
'image' => 'foobar',
}))
expect(dockerfile).to match(/zypper -n in openssh/)
end
(22..39).to_a.each do |fedora_release|
it "uses dnf on fedora #{fedora_release}" do
FakeFS.deactivate!
dockerfile = docker.send(:dockerfile_for, make_host('none', {
'platform' => Beaker::Platform.new("fedora-#{fedora_release}-x86_64"),
'image' => 'foobar',
}))
expect(dockerfile).to match(/dnf install -y sudo/)
end
end
it 'uses pacman on archlinux' do
FakeFS.deactivate!
dockerfile = docker.send(:dockerfile_for, make_host('none', {
'platform' => Beaker::Platform.new('archlinux-current-x86_64'),
'image' => 'foobar',
}))
expect(dockerfile).to match(/pacman --sync --refresh --noconfirm archlinux-keyring/)
expect(dockerfile).to match(/pacman --sync --refresh --noconfirm --sysupgrade/)
expect(dockerfile).to match(/pacman --sync --noconfirm curl net-tools openssh/)
end
end
describe '#fix_ssh' do
let(:test_container) { object_double(container) }
let(:host) { hosts[0] }
before do
allow(test_container).to receive(:id).and_return('abcdef')
end
it 'calls exec once when called without host' do
expect(test_container).to receive(:exec).once.with(
include(/PermitRootLogin/) &&
include(/PasswordAuthentication/) &&
include(/UseDNS/) &&
include(/MaxAuthTries/),
)
docker.send(:fix_ssh, test_container)
end
it 'execs sshd on alpine' do
host['platform'] = Beaker::Platform.new('alpine-3.8-x86_64')
expect(test_container).to receive(:exec).with(array_including('sed'))
expect(test_container).to receive(:exec).with(%w[/usr/sbin/sshd])
docker.send(:fix_ssh, test_container, host)
end
it 'restarts ssh service on ubuntu' do
host['platform'] = Beaker::Platform.new('ubuntu-20.04-x86_64')
expect(test_container).to receive(:exec).with(array_including('sed'))
expect(test_container).to receive(:exec).with(%w[service ssh restart])
docker.send(:fix_ssh, test_container, host)
end
it 'restarts sshd service otherwise' do
host['platform'] = Beaker::Platform.new('centos-6-x86_64')
expect(test_container).to receive(:exec).with(array_including('sed'))
expect(test_container).to receive(:exec).with(%w[service sshd restart])
docker.send(:fix_ssh, test_container, host)
end
end
end
end
end