|
7 | 7 | allow(Facter::Util::FileHelper).to receive(:safe_read)
|
8 | 8 | .with('/proc/1/cgroup', nil)
|
9 | 9 | .and_return(cgroup_output)
|
10 |
| - allow(Facter::Util::FileHelper).to receive(:safe_read) |
11 |
| - .with('/proc/1/environ', nil) |
| 10 | + allow(Facter::Util::FileHelper).to receive(:safe_readlines) |
| 11 | + .with('/proc/1/environ', [], "\0", chomp: true) |
12 | 12 | .and_return(environ_output)
|
13 | 13 | end
|
14 | 14 |
|
|
18 | 18 |
|
19 | 19 | context 'when hypervisor is docker' do
|
20 | 20 | let(:cgroup_output) { load_fixture('docker_cgroup').read }
|
21 |
| - let(:environ_output) { 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' } |
| 21 | + let(:environ_output) { ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'] } |
22 | 22 | let(:result) { { docker: { 'id' => 'ee6e3c05422f1273c9b41a26f2b4ec64bdb4480d63a1ad9741e05cafc1651b90' } } }
|
23 | 23 |
|
24 | 24 | it 'return docker for vm' do
|
|
32 | 32 |
|
33 | 33 | context 'when hypervisor is nspawn' do
|
34 | 34 | let(:cgroup_output) { load_fixture('cgroup_file').read }
|
35 |
| - let(:environ_output) { 'PATH=/usr/local/sbin:/bincontainer=systemd-nspawnTERM=xterm-256color' } |
| 35 | + let(:environ_output) { ['PATH=/usr/local/sbin:/bin', 'container=systemd-nspawn', 'TERM=xterm-256color'] } |
36 | 36 | let(:result) { { systemd_nspawn: { 'id' => 'ee6e3c05422f1273c9b41a26f2b4ec64bdb4480d63a1ad9741e05cafc1651b90' } } }
|
37 | 37 |
|
38 | 38 | before do
|
|
52 | 52 |
|
53 | 53 | context 'when hypervisor is lxc and it is discovered by cgroup' do
|
54 | 54 | let(:cgroup_output) { load_fixture('lxc_cgroup').read }
|
55 |
| - let(:environ_output) { 'PATH=/usr/local/sbin:/sbin:/bin' } |
| 55 | + let(:environ_output) { ['PATH=/usr/local/sbin:/sbin:/bin'] } |
56 | 56 | let(:result) { { lxc: { 'name' => 'lxc_container' } } }
|
57 | 57 |
|
58 | 58 | it 'return lxc for vm' do
|
|
66 | 66 |
|
67 | 67 | context 'when hypervisor is lxc and it is discovered by environ' do
|
68 | 68 | let(:cgroup_output) { load_fixture('cgroup_file').read }
|
69 |
| - let(:environ_output) { 'container=lxcroot' } |
| 69 | + let(:environ_output) { ['container=lxcroot'] } |
70 | 70 | let(:result) { { lxc: {} } }
|
71 | 71 |
|
72 | 72 | it 'return lxc for vm' do
|
|
80 | 80 |
|
81 | 81 | context 'when hypervisor is neighter lxc nor docker' do
|
82 | 82 | let(:cgroup_output) { load_fixture('cgroup_file').read }
|
83 |
| - let(:environ_output) { 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin' } |
| 83 | + let(:environ_output) { ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin'] } |
84 | 84 | let(:result) { nil }
|
85 | 85 |
|
86 | 86 | it 'return lxc for vm' do
|
|
91 | 91 | expect(containers_resolver.resolve(:hypervisor)).to eq(result)
|
92 | 92 | end
|
93 | 93 | end
|
| 94 | + |
| 95 | + context 'when hypervisor is an unknown container runtime discovered by environ' do |
| 96 | + let(:cgroup_output) { load_fixture('cgroup_file').read } |
| 97 | + let(:environ_output) { ['container=UNKNOWN'] } |
| 98 | + let(:logger) { Facter::Log.class_variable_get(:@@logger) } |
| 99 | + |
| 100 | + it 'return container_other for vm' do |
| 101 | + expect(logger).to receive(:warn).with(/Container runtime, 'UNKNOWN', is unsupported, setting to, 'container_other'/) |
| 102 | + expect(containers_resolver.resolve(:vm)).to eq('container_other') |
| 103 | + end |
| 104 | + end |
94 | 105 | end
|
0 commit comments