specinfra 2.87.2 → 2.88.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcc0b3de91a94ee5078f10a370ba357129cb84a51cc8f74f15c47b4578c0a52c
4
- data.tar.gz: 3244b71ca2590ec756ff09408a9bc02a4acf67d82370389259b2a4ed8f9f816f
3
+ metadata.gz: 2dff075bae4d6b20fa9332f60a6bd8e6da8d68dd7c6fb42e5d43d4a86f2d4b7d
4
+ data.tar.gz: 7703a50eddfa431bc02f8b84e10dbf88bd6065b5f50b4c7264114da23e9a1d6f
5
5
  SHA512:
6
- metadata.gz: 76cca256c92c5ddf1a82d8745de7e53cd932430a2eb996c4ca0ced1fe926a4063b7348fcd4e61c3b5db3dc0634f54033f782ae89a7bc7aaf189e09594357a711
7
- data.tar.gz: 23ccd50fe257b9a1464c2bc34b74f540998c044079c3e2328667a14957ab85eec671526e57e035a2b3e2b0ef35ff9880b090477a2bdca7387f7e6cbc07a69a20
6
+ metadata.gz: dfec33e4e99f8cd09444db43371ab805c50d588cd66787e3c37d8a2631d15141fd9fb91f9fde6b8a2a223374ab49d0bc4f3709b4d7a0f1059bd7005b134b1c63
7
+ data.tar.gz: 1a23d2c920e4b8fd5f05826c8a80b3bb1c3053025c1d3e4d8d81500ebb4bb360037e0819bd9c81e037d360533dc97bdd9c7ae1a52fac3f9d3c71bec3d8ad93fd
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ if defined?(RSpec)
18
18
 
19
19
  task :backend => 'backend:all'
20
20
  namespace :backend do
21
- backends = %w[exec ssh]
21
+ backends = Dir.glob("spec/backend/*").map { |path| File.basename(path) }
22
22
 
23
23
  task :all => backends
24
24
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+ require 'fileutils'
5
+ require 'shellwords'
6
+ require 'sfl' if Specinfra.ruby_is_older_than?(1, 9, 0)
7
+
8
+ module Specinfra
9
+ module Backend
10
+ # LXD transport
11
+ class Lxd < Exec
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(' ')
17
+ end
18
+
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
24
+ end
25
+ cmd = %W[lxc file push #{source} #{instance}#{destination}] + flags
26
+ spawn_command(cmd.join(' '))
27
+ end
28
+
29
+ private
30
+
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))
34
+
35
+ [remote, instance].compact.join(':')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -6,6 +6,7 @@ require 'specinfra/backend/powershell/command'
6
6
  require 'specinfra/backend/cmd'
7
7
  require 'specinfra/backend/docker'
8
8
  require 'specinfra/backend/lxc'
9
+ require 'specinfra/backend/lxd'
9
10
  require 'specinfra/backend/winrm'
10
11
  require 'specinfra/backend/shell_script'
11
12
  require 'specinfra/backend/dockerfile'
@@ -20,6 +20,8 @@ module Specinfra
20
20
  :docker_image,
21
21
  :docker_url,
22
22
  :lxc,
23
+ :lxd_remote,
24
+ :lxd_instance,
23
25
  :request_pty,
24
26
  :ssh_options,
25
27
  :ssh_without_env,
@@ -1,5 +1,5 @@
1
1
  module Specinfra
2
- VERSION = "2.87.2"
2
+ VERSION = "2.88.1"
3
3
 
4
4
  def self.ruby_is_older_than?(*version)
5
5
  (RUBY_VERSION.split('.').map(&:to_i) <=> version) < 0
@@ -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.87.2
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: 2023-12-25 00:00:00.000000000 Z
11
+ date: 2024-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-scp
@@ -128,6 +128,7 @@ files:
128
128
  - lib/specinfra/backend/exec.rb
129
129
  - lib/specinfra/backend/jexec.rb
130
130
  - lib/specinfra/backend/lxc.rb
131
+ - lib/specinfra/backend/lxd.rb
131
132
  - lib/specinfra/backend/powershell/command.rb
132
133
  - lib/specinfra/backend/powershell/script_helper.rb
133
134
  - lib/specinfra/backend/powershell/support/check_file_access_rules.ps1
@@ -520,6 +521,7 @@ files:
520
521
  - spec/backend/exec/env_spec.rb
521
522
  - spec/backend/exec/read_noblock_spec.rb
522
523
  - spec/backend/exec/stdxxx_handler_spec.rb
524
+ - spec/backend/lxd/build_command_spec.rb
523
525
  - spec/backend/ssh/build_command_spec.rb
524
526
  - spec/command/alpine/service_spec.rb
525
527
  - spec/command/amazon/interface_spec.rb
@@ -669,6 +671,7 @@ test_files:
669
671
  - spec/backend/exec/env_spec.rb
670
672
  - spec/backend/exec/read_noblock_spec.rb
671
673
  - spec/backend/exec/stdxxx_handler_spec.rb
674
+ - spec/backend/lxd/build_command_spec.rb
672
675
  - spec/backend/ssh/build_command_spec.rb
673
676
  - spec/command/alpine/service_spec.rb
674
677
  - spec/command/amazon/interface_spec.rb