specinfra 2.88.0 → 2.88.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/specinfra/backend/lxd.rb +18 -44
- data/lib/specinfra/version.rb +1 -1
- data/spec/backend/lxd/build_command_spec.rb +113 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dff075bae4d6b20fa9332f60a6bd8e6da8d68dd7c6fb42e5d43d4a86f2d4b7d
|
4
|
+
data.tar.gz: 7703a50eddfa431bc02f8b84e10dbf88bd6065b5f50b4c7264114da23e9a1d6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfec33e4e99f8cd09444db43371ab805c50d588cd66787e3c37d8a2631d15141fd9fb91f9fde6b8a2a223374ab49d0bc4f3709b4d7a0f1059bd7005b134b1c63
|
7
|
+
data.tar.gz: 1a23d2c920e4b8fd5f05826c8a80b3bb1c3053025c1d3e4d8d81500ebb4bb360037e0819bd9c81e037d360533dc97bdd9c7ae1a52fac3f9d3c71bec3d8ad93fd
|
data/Rakefile
CHANGED
@@ -9,56 +9,30 @@ module Specinfra
|
|
9
9
|
module Backend
|
10
10
|
# LXD transport
|
11
11
|
class Lxd < Exec
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@remote_instance = [@remote, @instance].compact.join(':')
|
12
|
+
def build_command(cmd)
|
13
|
+
lxc_cmd = %W[lxc exec #{instance}]
|
14
|
+
lxc_cmd << '-t' if get_config(:interactive_shell)
|
15
|
+
lxc_cmd << '--'
|
16
|
+
(lxc_cmd << super(cmd)).join(' ')
|
19
17
|
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
run_pre_command(opts)
|
27
|
-
stdout, stderr, exit_status = with_env do
|
28
|
-
spawn_command(cmd)
|
29
|
-
end
|
30
|
-
|
31
|
-
if @example
|
32
|
-
@example.metadata[:command] = cmd
|
33
|
-
@example.metadata[:stdout] = stdout
|
34
|
-
end
|
35
|
-
|
36
|
-
CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => exit_status
|
37
|
-
end
|
38
|
-
|
39
|
-
def build_command(cmd)
|
40
|
-
cmd = super(cmd)
|
41
|
-
"lxc exec #{@remote_instance} -- #{cmd}"
|
42
|
-
end
|
43
|
-
|
44
|
-
def send_file(source, destination)
|
45
|
-
flags = %w[--create-dirs]
|
46
|
-
if File.directory?(source)
|
47
|
-
flags << '--recursive'
|
48
|
-
destination = Pathname.new(destination).dirname.to_s
|
49
|
-
end
|
50
|
-
cmd = %W[lxc file push #{source} #{@remote_instance}#{destination}] + flags
|
51
|
-
spawn_command(cmd.join(' '))
|
19
|
+
def send_file(source, destination)
|
20
|
+
flags = %w[--create-dirs]
|
21
|
+
if File.directory?(source)
|
22
|
+
flags << '--recursive'
|
23
|
+
destination = Pathname.new(destination).dirname.to_s
|
52
24
|
end
|
25
|
+
cmd = %W[lxc file push #{source} #{instance}#{destination}] + flags
|
26
|
+
spawn_command(cmd.join(' '))
|
27
|
+
end
|
53
28
|
|
54
|
-
|
29
|
+
private
|
55
30
|
|
56
|
-
|
57
|
-
|
31
|
+
def instance
|
32
|
+
raise 'Please specify lxd_instance' unless (instance = get_config(:lxd_instance))
|
33
|
+
raise 'Please specify lxd_remote' unless (remote = get_config(:lxd_remote))
|
58
34
|
|
59
|
-
|
60
|
-
spawn_command(cmd)
|
61
|
-
end
|
35
|
+
[remote, instance].compact.join(':')
|
62
36
|
end
|
63
37
|
end
|
64
38
|
end
|
data/lib/specinfra/version.rb
CHANGED
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Specinfra::Backend::Lxd do
|
6
|
+
let(:lxd_instance) { 'instance' }
|
7
|
+
let(:lxd_remote) { 'remote' }
|
8
|
+
let(:lxc_exec) { "lxc exec #{lxd_remote}:#{lxd_instance}" }
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
set :backend, :lxd
|
12
|
+
RSpec.configure do |c|
|
13
|
+
c.lxd_instance = lxd_instance
|
14
|
+
c.lxd_remote = lxd_remote
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
Specinfra::Backend::Lxd.clear
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#build_command' do
|
23
|
+
context 'without required lxd_instance set' do
|
24
|
+
let(:lxd_instance) { nil }
|
25
|
+
it {
|
26
|
+
expect { subject.build_command('true') }.to raise_error(RuntimeError, /lxd_instance/)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'without required lxd_remote set' do
|
31
|
+
let(:lxd_remote) { nil }
|
32
|
+
it {
|
33
|
+
expect { subject.build_command('true') }.to raise_error(RuntimeError, /lxd_remote/)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with simple command' do
|
38
|
+
it 'should escape spaces' do
|
39
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- /bin/sh -c test\\ -f\\ /etc/passwd"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with complex command' do
|
44
|
+
it 'should escape special chars' do
|
45
|
+
expect(subject.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)'))
|
46
|
+
.to eq "lxc exec #{lxd_remote}:#{lxd_instance} -- /bin/sh -c test\\ \\!\\ -f\\ /etc/selinux/config\\ \\|\\|\\ \\(getenforce\\ \\|\\ grep\\ -i\\ --\\ disabled\\ \\&\\&\\ grep\\ -i\\ --\\ \\^SELINUX\\=disabled\\$\\ /etc/selinux/config\\)"
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should escape quotes' do
|
50
|
+
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.7')
|
51
|
+
expect(subject.build_command(%Q(find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"))).to eq("#{lxc_exec} -- /bin/sh -c find\\ /etc/apt/\\ -name\\ \\*.list\\ \\|\\ xargs\\ grep\\ -o\\ -E\\ \\\"\\^deb\\ \\+\\[\\\\\\\"\\'\\]\\?http://ppa.launchpad.net/gluster/glusterfs-3.7\\\"")
|
52
|
+
else
|
53
|
+
# Since Ruby 2.7, `+` is not escaped.
|
54
|
+
expect(subject.build_command(%Q(find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"))).to eq("#{lxc_exec} -- /bin/sh -c find\\ /etc/apt/\\ -name\\ \\*.list\\ \\|\\ xargs\\ grep\\ -o\\ -E\\ \\\"\\^deb\\ +\\[\\\\\\\"\\'\\]\\?http://ppa.launchpad.net/gluster/glusterfs-3.7\\\"")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with custom shell' do
|
60
|
+
before { RSpec.configure { |c| c.shell = '/usr/local/bin/tcsh' } }
|
61
|
+
after { RSpec.configure { |c| c.shell = nil } }
|
62
|
+
|
63
|
+
it 'should use custom shell' do
|
64
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- /usr/local/bin/tcsh -c test\\ -f\\ /etc/passwd"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'with custom shell that needs escaping' do
|
69
|
+
before { RSpec.configure { |c| c.shell = '/usr/test & spec/bin/sh' } }
|
70
|
+
after { RSpec.configure { |c| c.shell = nil } }
|
71
|
+
|
72
|
+
it 'should use custom shell' do
|
73
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- /usr/test\\ \\&\\ spec/bin/sh -c test\\ -f\\ /etc/passwd"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'with an interactive shell' do
|
78
|
+
before { RSpec.configure { |c| c.interactive_shell = true } }
|
79
|
+
after { RSpec.configure { |c| c.interactive_shell = nil } }
|
80
|
+
|
81
|
+
it 'should emulate an interactive shell' do
|
82
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -t -- /bin/sh -i -c test\\ -f\\ /etc/passwd"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'with an login shell' do
|
87
|
+
before { RSpec.configure { |c| c.login_shell = true } }
|
88
|
+
after { RSpec.configure { |c| c.login_shell = nil } }
|
89
|
+
|
90
|
+
it 'should emulate an login shell' do
|
91
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- /bin/sh -l -c test\\ -f\\ /etc/passwd"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'with custom path' do
|
96
|
+
before { RSpec.configure { |c| c.path = '/opt/bin:/opt/foo/bin:$PATH' } }
|
97
|
+
after { RSpec.configure { |c| c.path = nil } }
|
98
|
+
|
99
|
+
it 'should use custom path' do
|
100
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- env PATH=\"/opt/bin:/opt/foo/bin:$PATH\" /bin/sh -c test\\ -f\\ /etc/passwd"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'with custom path that needs escaping' do
|
105
|
+
before { RSpec.configure { |c| c.path = '/opt/bin:/opt/test & spec/bin:$PATH' } }
|
106
|
+
after { RSpec.configure { |c| c.path = nil } }
|
107
|
+
|
108
|
+
it 'should use custom path' do
|
109
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- env PATH=\"/opt/bin:/opt/test & spec/bin:$PATH\" /bin/sh -c test\\ -f\\ /etc/passwd"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: specinfra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.88.
|
4
|
+
version: 2.88.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gosuke Miyashita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-scp
|
@@ -521,6 +521,7 @@ files:
|
|
521
521
|
- spec/backend/exec/env_spec.rb
|
522
522
|
- spec/backend/exec/read_noblock_spec.rb
|
523
523
|
- spec/backend/exec/stdxxx_handler_spec.rb
|
524
|
+
- spec/backend/lxd/build_command_spec.rb
|
524
525
|
- spec/backend/ssh/build_command_spec.rb
|
525
526
|
- spec/command/alpine/service_spec.rb
|
526
527
|
- spec/command/amazon/interface_spec.rb
|
@@ -670,6 +671,7 @@ test_files:
|
|
670
671
|
- spec/backend/exec/env_spec.rb
|
671
672
|
- spec/backend/exec/read_noblock_spec.rb
|
672
673
|
- spec/backend/exec/stdxxx_handler_spec.rb
|
674
|
+
- spec/backend/lxd/build_command_spec.rb
|
673
675
|
- spec/backend/ssh/build_command_spec.rb
|
674
676
|
- spec/command/alpine/service_spec.rb
|
675
677
|
- spec/command/amazon/interface_spec.rb
|