Skip to content
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

(FACT-2785) partitions.<partition_name>.mount has wrong value on sles15-64 #2077

Merged
merged 1 commit into from
Sep 9, 2020
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
2 changes: 1 addition & 1 deletion lib/facter/facts/linux/partitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def partitions
mountpoints = Facter::Resolvers::Mountpoints.resolve(:mountpoints)
return parts unless mountpoints

mountpoints.each do |mnt|
mountpoints.reverse_each do |mnt|
next unless parts[mnt[:device]]

parts[mnt[:device]].merge!(mount: mnt[:path])
Expand Down
77 changes: 77 additions & 0 deletions spec/facter/facts/linux/partitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,82 @@
have_attributes(name: 'partitions', value: nil)
end
end

context 'when the same device is mounted in multiple places' do
let(:mountpoints_resolver_output) do
[{
device: '/dev/sda2',
filesystem: 'btrfs',
path: '/',
options: ['rw', 'relatime', 'space_cache', 'subvolid=267', 'subvol=/@/.snapshots/1/snapshot'],
available: '10.74 GiB',
available_bytes: 11_534_614_528,
size: '13.09 GiB',
size_bytes: 14_050_918_400,
used: '1.96 GiB',
used_bytes: 2_101_231_616,
capacity: '15.41%'
}, {
device: '/dev/sda2',
filesystem: 'btrfs',
path: '/boot/grub2/x86_64-efi',
options: ['rw', 'relatime', 'space_cache', 'subvolid=264', 'subvol=/@/boot/grub2/x86_64-efi'],
available: '10.74 GiB',
available_bytes: 11_534_614_528,
size: '13.09 GiB',
size_bytes: 14_050_918_400,
used: '1.96 GiB',
used_bytes: 2_101_231_616,
capacity: '15.41%'
}]
end

let(:partitions_resolver_output) do
{
'/dev/sda2' => {
size_bytes: 14_050_918_400,
size: '13.09 GiB',
filesystem: 'btrfs',
uuid: 'bbc18fba-8191-48c8-b8bd-30373654bb3e',
partuuid: 'c96cd2ea-1046-461c-b0fe-1e5aa19aba61'
}
}
end

let(:final_result) do
{
'/dev/sda2' => {
'size_bytes' => 14_050_918_400,
'size' => '13.09 GiB',
'filesystem' => 'btrfs',
'uuid' => 'bbc18fba-8191-48c8-b8bd-30373654bb3e',
'partuuid' => 'c96cd2ea-1046-461c-b0fe-1e5aa19aba61',
'mount' => '/'
}
}
end

before do
allow(Facter::Resolvers::Mountpoints).to receive(:resolve).with(:mountpoints)
.and_return(mountpoints_resolver_output)
allow(Facter::Resolvers::Partitions).to receive(:resolve).with(:partitions)
.and_return(partitions_resolver_output)
end

it 'calls Facter::Resolvers::Mountpoints' do
fact.call_the_resolver
expect(Facter::Resolvers::Mountpoints).to have_received(:resolve).with(:mountpoints)
end

it 'calls Facter::Resolvers::Partitions' do
fact.call_the_resolver
expect(Facter::Resolvers::Partitions).to have_received(:resolve).with(:partitions)
end

it 'returns partitions information from the first mountpoint' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'partitions', value: final_result)
end
end
end
end