-
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.
Merge pull request #2574 from lollipopman/crio-container-support
(FACT-3202) Add is_virtual and virtual support for crio
- Loading branch information
Showing
9 changed files
with
125 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,21 @@ | ||
# 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: true) | ||
lines.each do |line| | ||
key, value = line.split('=', 2) | ||
return value if key == field | ||
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', [], "\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.