|
42 | 42 | allow(Facter::Core::Execution).to receive(:which)
|
43 | 43 | .with('lsblk').and_return('/usr/bin/lsblk')
|
44 | 44 | allow(Facter::Core::Execution).to receive(:execute)
|
45 |
| - .with('lsblk -fp', logger: an_instance_of(Facter::Log)).and_return(load_fixture('lsblk_output').read) |
| 45 | + .with('lsblk --version 2>&1', logger: an_instance_of(Facter::Log)).and_return('lsblk from util-linux 2.24') |
| 46 | + allow(Facter::Core::Execution).to receive(:execute) |
| 47 | + .with('lsblk -p -P -o NAME,FSTYPE,LABEL,UUID,PARTUUID,PARTLABEL', logger: an_instance_of(Facter::Log)).and_return(load_fixture('lsblk_output_old').read) |
46 | 48 | end
|
47 | 49 |
|
48 | 50 | context 'when block has a device subdir' do
|
|
68 | 70 | context 'when there is more than one partition' do
|
69 | 71 | it 'checks for blkid only once' do
|
70 | 72 | resolver.resolve(:partitions)
|
71 |
| - expect(Facter::Core::Execution).to have_received(:which).with('blkid').once |
| 73 | + expect(Facter::Core::Execution).to have_received(:which).with('blkid').at_most(:once) |
72 | 74 | end
|
73 | 75 |
|
74 | 76 | it 'checks for lsblk only once' do
|
75 | 77 | resolver.resolve(:partitions)
|
76 |
| - expect(Facter::Core::Execution).to have_received(:which).with('lsblk').once |
| 78 | + expect(Facter::Core::Execution).to have_received(:which).with('lsblk').at_most(:once) |
77 | 79 | end
|
78 | 80 | end
|
79 | 81 |
|
|
189 | 191 | end
|
190 | 192 | end
|
191 | 193 | end
|
| 194 | + |
| 195 | + context 'when lsblk can read partition types' do |
| 196 | + let(:sda_subdirs) do |
| 197 | + ['/sys/block/sda/queue', |
| 198 | + '/sys/block/sda/sda2', |
| 199 | + '/sys/block/sda/sda2/stat', |
| 200 | + '/sys/block/sda/sda2/dev', |
| 201 | + '/sys/block/sda/sda2/uevent', |
| 202 | + '/sys/block/sda/sda1'] |
| 203 | + end |
| 204 | + |
| 205 | + before do |
| 206 | + allow(File).to receive(:directory?).with("#{sys_block_path}/sda/device").and_return(true) |
| 207 | + allow(Dir).to receive(:[]).with("#{sys_block_path}/sda/**/*").and_return(sda_subdirs) |
| 208 | + sda_subdirs.each { |subdir| allow(File).to receive(:directory?).with(subdir).and_return(true) } |
| 209 | + allow(Facter::Util::FileHelper).to receive(:safe_read) |
| 210 | + .with("#{sys_block_path}/sda/sda2/size", '0').and_return('201213') |
| 211 | + allow(Facter::Util::FileHelper).to receive(:safe_read) |
| 212 | + .with("#{sys_block_path}/sda/sda1/size", '0').and_return('234') |
| 213 | + end |
| 214 | + |
| 215 | + let(:partitions) do |
| 216 | + { '/dev/sda1' => { filesystem: 'ext3', label: '/boot', parttype: '21686148-6449-6E6F-744E-656564454649', size: '117.00 KiB', |
| 217 | + size_bytes: 119_808, uuid: '88077904-4fd4-476f-9af2-0f7a806ca25e', |
| 218 | + partuuid: '00061fe0-01' }, |
| 219 | + '/dev/sda2' => { filesystem: 'LVM2_member', parttype: '0fc63daf-8483-4772-8e79-3d69d8477de4', size: '98.25 MiB', |
| 220 | + size_bytes: 103_021_056, uuid: 'edi7s0-2WVa-ZBan' } } |
| 221 | + end |
| 222 | + |
| 223 | + it 'return partitions fact with part_type' do |
| 224 | + allow(Facter::Core::Execution).to receive(:execute) |
| 225 | + .with('lsblk --version 2>&1', logger: an_instance_of(Facter::Log)).and_return('lsblk from util-linux 2.25') |
| 226 | + allow(Facter::Core::Execution).to receive(:execute) |
| 227 | + .with('lsblk -p -P -o NAME,FSTYPE,UUID,LABEL,PARTUUID,PARTLABEL,PARTTYPE', logger: an_instance_of(Facter::Log)).and_return(load_fixture('lsblk_output_new').read) |
| 228 | + |
| 229 | + expect(resolver.resolve(:partitions)).to eq(partitions) |
| 230 | + end |
| 231 | + end |
192 | 232 | end
|
193 | 233 | end
|
0 commit comments