-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FACT-3202) Add is_virtual and virtual support for crio
Prior to this change facter returned: $ facter is_virtual false $ facter virtual physical After this change facter returns: $ facter is_virtual true $ facter virtual crio This change separates out reading pid 1's environment from proc and reading the cgroup information. It also adds a container_other type when the container runtime is not explicitly supported.
- Loading branch information
1 parent
d04a42d
commit 21afec5
Showing
9 changed files
with
109 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Util | ||
module Linux | ||
class Proc | ||
class << self | ||
def getenv_for_pid(pid, field) | ||
path = "/proc/#{pid}/environ" | ||
lines = Facter::Util::FileHelper.safe_readlines(path, [], "\0", chomp: false) | ||
lines.each do |line| | ||
if line.slice(0, field.length) == field && line.slice(field.length) == '=' | ||
return line.slice(field.length + 1, line.length - (field.length + 1)) | ||
end | ||
end | ||
nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facter::Util::Linux::Proc do | ||
describe '#getenv_for_pid' do | ||
before do | ||
allow(Facter::Util::FileHelper).to receive(:safe_readlines) | ||
.with('/proc/1/environ', nil, "\0", { chomp: true }) | ||
.and_return(proc_environ.readlines("\0", chomp: true)) | ||
end | ||
|
||
context 'when field exists' do | ||
let(:proc_environ) { load_fixture('proc_environ_podman') } | ||
|
||
it 'returns the field' do | ||
result = Facter::Util::Linux::Proc.getenv_for_pid(1, 'container') | ||
expect(result).to eq('podman') | ||
end | ||
end | ||
|
||
context 'when field does not exist' do | ||
let(:proc_environ) { load_fixture('proc_environ_podman') } | ||
|
||
it 'returns nil' do | ||
result = Facter::Util::Linux::Proc.getenv_for_pid(1, 'butter') | ||
expect(result).to eq(nil) | ||
end | ||
end | ||
|
||
context 'when field is empty' do | ||
let(:proc_environ) { load_fixture('proc_environ_no_value') } | ||
|
||
it 'returns an empty string' do | ||
result = Facter::Util::Linux::Proc.getenv_for_pid(1, 'bubbles') | ||
expect(result).to eq('') | ||
end | ||
end | ||
end | ||
end |
Binary file not shown.
Binary file not shown.