Skip to content

(CONT-173) - Updating deprecated facter instances #1277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/facter/root_home.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Facter::Util::RootHome
class << self
# determines the root home directory
def returnt_root_home
root_ent = Facter::Util::Resolution.exec('getent passwd root')
root_ent = Facter::Core::Execution.execute('getent passwd root')
# The home directory is the sixth element in the passwd entry
# If the platform doesn't have getent, root_ent will be nil and we should
# return it straight away.
Expand All @@ -25,7 +25,7 @@ def returnt_root_home
Facter.add(:root_home) do
confine kernel: :darwin
setcode do
str = Facter::Util::Resolution.exec('dscacheutil -q user -a name root')
str = Facter::Core::Execution.execute('dscacheutil -q user -a name root')
hash = {}
str.split("\n").each do |pair|
key, value = pair.split(%r{:})
Expand All @@ -39,7 +39,7 @@ def returnt_root_home
confine kernel: :aix
root_home = nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is weird and should really be inside setcode.

setcode do
str = Facter::Util::Resolution.exec('lsuser -c -a home root')
str = Facter::Core::Execution.execute('lsuser -c -a home root')
str&.split("\n")&.each do |line|
next if %r{^#}.match?(line)
root_home = line.split(%r{:})[1]
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/facter/root_home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:expected_root_home) { '/' }

it 'returns /' do
expect(Facter::Util::Resolution).to receive(:exec).with('getent passwd root').and_return(root_ent)
expect(Facter::Core::Execution).to receive(:execute).with('getent passwd root').and_return(root_ent)
expect(described_class.returnt_root_home).to eq(expected_root_home)
end
end
Expand All @@ -18,13 +18,13 @@
let(:expected_root_home) { '/root' }

it 'returns /root' do
expect(Facter::Util::Resolution).to receive(:exec).with('getent passwd root').and_return(root_ent)
expect(Facter::Core::Execution).to receive(:execute).with('getent passwd root').and_return(root_ent)
expect(described_class.returnt_root_home).to eq(expected_root_home)
end
end
context 'when windows' do
it 'is nil on windows' do
expect(Facter::Util::Resolution).to receive(:exec).with('getent passwd root').and_return(nil)
expect(Facter::Core::Execution).to receive(:execute).with('getent passwd root').and_return(nil)
expect(described_class.returnt_root_home).to be_nil
end
end
Expand All @@ -44,7 +44,7 @@
sample_dscacheutil = File.read(fixtures('dscacheutil', 'root'))

it 'returns /var/root' do
allow(Facter::Util::Resolution).to receive(:exec).with('dscacheutil -q user -a name root').and_return(sample_dscacheutil)
allow(Facter::Core::Execution).to receive(:execute).with('dscacheutil -q user -a name root').and_return(sample_dscacheutil)
expect(Facter.fact(:root_home).value).to eq(expected_root_home)
end
end
Expand All @@ -59,7 +59,7 @@
sample_lsuser = File.read(fixtures('lsuser', 'root'))

it 'returns /root' do
allow(Facter::Util::Resolution).to receive(:exec).with('lsuser -c -a home root').and_return(sample_lsuser)
allow(Facter::Core::Execution).to receive(:execute).with('lsuser -c -a home root').and_return(sample_lsuser)
expect(Facter.fact(:root_home).value).to eq(expected_root_home)
end
end
Expand Down