Skip to content

Commit ca6b3bc

Browse files
authored
Merge pull request #55 from tvpartytonight/PA-5966
Stop using legacy facts
2 parents b0b24da + 139ee61 commit ca6b3bc

File tree

7 files changed

+42
-46
lines changed

7 files changed

+42
-46
lines changed

lib/puppet/provider/mount.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def mount
2626
def remount
2727
# TRANSLATORS refers to remounting a file system
2828
info _('Remounting')
29-
os = Facter.value(:operatingsystem)
29+
os = Facter.value('os.name')
3030
supports_remounts = (resource[:remounts] == :true)
3131
if supports_remounts && os == 'AIX'
3232
remount_with_option('remount')

lib/puppet/provider/mount/parsed.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'puppet/provider/parsedfile'
22
require_relative '../mount'
33

4-
fstab = case Facter.value(:osfamily)
4+
fstab = case Facter.value('os.family')
55
when 'Solaris' then '/etc/vfstab'
66
when 'AIX' then '/etc/filesystems'
77
else
@@ -20,14 +20,14 @@
2020

2121
commands mountcmd: 'mount', umount: 'umount'
2222

23-
@fields = case Facter.value(:osfamily)
23+
@fields = case Facter.value('os.family')
2424
when 'Solaris'
2525
[:device, :blockdevice, :name, :fstype, :pass, :atboot, :options]
2626
else
2727
[:device, :name, :fstype, :options, :dump, :pass]
2828
end
2929

30-
if Facter.value(:osfamily) == 'AIX'
30+
if Facter.value('os.family') == 'AIX'
3131
# * is the comment character on AIX /etc/filesystems
3232
text_line :comment, match: %r{^\s*\*}
3333
else
@@ -43,7 +43,7 @@
4343
field_pattern = '(\s*(?>\S+))'
4444
text_line :incomplete, match: %r{^(?!#{field_pattern}{#{mandatory_fields.length}})}
4545

46-
case Facter.value(:osfamily)
46+
case Facter.value('os.family')
4747
when 'AIX'
4848
# The only field that is actually ordered is :name. See `man filesystems` on AIX
4949
@fields = [:name, :account, :boot, :check, :dev, :free, :mount, :nodename,
@@ -272,7 +272,7 @@ def self.prefetch(resources = nil)
272272
end
273273

274274
def self.mountinstances
275-
regex = case Facter.value(:osfamily)
275+
regex = case Facter.value('os.family')
276276
when 'Darwin'
277277
%r{ on (?:/private/var/automount)?(\S*)}
278278
when 'Solaris', 'HP-UX'

lib/puppet/type/mount.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def syncothers
145145

146146
# Default to the device but with "dsk" replaced with "rdsk".
147147
defaultto do
148-
if Facter.value(:osfamily) == 'Solaris'
148+
if Facter.value('os.family') == 'Solaris'
149149
if (device = resource[:device]) && device.include?('/dsk/')
150150
device.sub(%r{/dsk/}, '/rdsk/')
151151
elsif (fstype = resource[:fstype]) && fstype == 'nfs'
@@ -193,7 +193,7 @@ def syncothers
193193

194194
defaultto do
195195
if @resource.managed?
196-
if Facter.value(:osfamily) == 'Solaris'
196+
if Facter.value('os.family') == 'Solaris'
197197
'-'
198198
else
199199
0
@@ -220,7 +220,7 @@ def munge(value)
220220
desc "Whether to dump the mount. Not all platform support this.
221221
Valid values are `1` or `0` (or `2` on FreeBSD). Default is `0`."
222222

223-
if Facter.value(:operatingsystem) == 'FreeBSD'
223+
if Facter.value('os.name') == 'FreeBSD'
224224
newvalue(%r{(0|1|2)})
225225
else
226226
newvalue(%r{(0|1)})
@@ -267,7 +267,7 @@ def munge(value)
267267

268268
newvalues(:true, :false)
269269
defaultto do
270-
case Facter.value(:operatingsystem)
270+
case Facter.value('os.name')
271271
when 'FreeBSD', 'Darwin', 'DragonFly', 'OpenBSD'
272272
false
273273
when 'AIX'

spec/integration/provider/mount_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
describe 'mount provider (integration)', unless: Puppet.features.microsoft_windows? do
66
include PuppetSpec::Files
77

8-
family = Facter.value(:osfamily)
9-
108
def create_fake_fstab(initially_contains_entry)
119
File.open(@fake_fstab, 'w') do |f|
1210
if initially_contains_entry
@@ -24,8 +22,8 @@ def create_fake_fstab(initially_contains_entry)
2422
allow(Facter).to receive(:value).with(:hostname).and_return('some_host')
2523
allow(Facter).to receive(:value).with(:domain).and_return('some_domain')
2624
allow(Facter).to receive(:value).with(:kernel).and_return('Linux')
27-
allow(Facter).to receive(:value).with(:operatingsystem).and_return('RedHat')
28-
allow(Facter).to receive(:value).with(:osfamily).and_return('RedHat')
25+
allow(Facter).to receive(:value).with('os.name').and_return('RedHat')
26+
allow(Facter).to receive(:value).with('os.family').and_return('RedHat')
2927
allow(Facter).to receive(:value).with(:fips_enabled).and_return(false)
3028
Puppet::Util::ExecutionStub.set do |command, _options|
3129
case command[0]
@@ -111,9 +109,7 @@ def run_in_catalog(settings)
111109
['local', 'journaled', '', nil].each do |options_setting|
112110
describe "When setting options => '#{options_setting}'" do
113111
it "leaves the system in the #{expected_final_state ? 'mounted' : 'unmounted'} state, #{expected_fstab_data ? 'with' : 'without'} data in /etc/fstab" do
114-
if family == 'Solaris'
115-
skip('Solaris: The double :operatingsystem value does not get changed in lib/puppet/provider/mount/parsed.rb')
116-
elsif options_setting && options_setting.empty?
112+
if options_setting && options_setting.empty?
117113
expect { run_in_catalog(ensure: ensure_setting, options: options_setting) }.to raise_error Puppet::ResourceError
118114
else
119115
if options_setting

spec/unit/provider/mount/parsed_spec.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121

2222
# LAK:FIXME I can't double Facter because this test happens at parse-time.
2323
it 'defaults to /etc/vfstab on Solaris' do
24-
if Facter.value(:osfamily) != 'Solaris'
24+
if Facter.value('os.family') != 'Solaris'
2525
skip('This test only works on Solaris')
2626
else
2727
expect(described_class.default_target).to eq('/etc/vfstab')
2828
end
2929
end
3030

3131
it 'defaults to /etc/filesystems on AIX' do
32-
pending 'This test only works on AIX' unless Facter.value(:osfamily) == 'AIX'
32+
pending 'This test only works on AIX' unless Facter.value('os.family') == 'AIX'
3333
expect(described_class.default_target).to eq('/etc/filesystems')
3434
end
3535

3636
it 'defaults to /etc/fstab on anything else' do
37-
if Facter.value(:osfamily) == 'Solaris'
37+
if Facter.value('os.family') == 'Solaris'
3838
skip('This test only does not work on Solaris')
3939
else
4040
expect(described_class.default_target).to eq('/etc/fstab')
@@ -53,7 +53,7 @@
5353
# it_should_behave_like "all parsedfile providers",
5454
# provider_class, my_fixtures('*.fstab')
5555

56-
describe 'on Solaris', if: Facter.value(:osfamily) == 'Solaris' do
56+
describe 'on Solaris', if: Facter.value('os.family') == 'Solaris' do
5757
it 'extracts device from the first field' do
5858
expect(described_class.parse_line(vfstab_sample)[:device]).to eq('/dev/dsk/c0d0s0')
5959
end
@@ -83,7 +83,7 @@
8383
end
8484
end
8585

86-
describe 'on other platforms than Solaris', if: Facter.value(:osfamily) != 'Solaris' do
86+
describe 'on other platforms than Solaris', if: Facter.value('os.family') != 'Solaris' do
8787
it 'extracts device from the first field' do
8888
expect(described_class.parse_line(fstab_sample)[:device]).to eq('/dev/vg00/lv01')
8989
end
@@ -112,7 +112,7 @@
112112

113113
describe 'mountinstances' do
114114
it 'gets name from mountoutput found on Solaris' do
115-
allow(Facter).to receive(:value).with(:osfamily).and_return 'Solaris'
115+
allow(Facter).to receive(:value).with('os.family').and_return 'Solaris'
116116
allow(described_class).to receive(:mountcmd).and_return(File.read(my_fixture('solaris.mount')))
117117
mounts = described_class.mountinstances
118118
expect(mounts.size).to eq(6)
@@ -125,7 +125,7 @@
125125
end
126126

127127
it 'gets name from mountoutput found on HP-UX' do
128-
allow(Facter).to receive(:value).with(:osfamily).and_return 'HP-UX'
128+
allow(Facter).to receive(:value).with('os.family').and_return 'HP-UX'
129129
allow(described_class).to receive(:mountcmd).and_return(File.read(my_fixture('hpux.mount')))
130130
mounts = described_class.mountinstances
131131
expect(mounts.size).to eq(17)
@@ -149,7 +149,7 @@
149149
end
150150

151151
it 'gets name from mountoutput found on Darwin' do
152-
allow(Facter).to receive(:value).with(:osfamily).and_return 'Darwin'
152+
allow(Facter).to receive(:value).with('os.family').and_return 'Darwin'
153153
allow(described_class).to receive(:mountcmd).and_return(File.read(my_fixture('darwin.mount')))
154154
mounts = described_class.mountinstances
155155
expect(mounts.size).to eq(6)
@@ -162,7 +162,7 @@
162162
end
163163

164164
it 'gets name from mountoutput found on Linux' do
165-
allow(Facter).to receive(:value).with(:osfamily).and_return 'Gentoo'
165+
allow(Facter).to receive(:value).with('os.family').and_return 'Gentoo'
166166
allow(described_class).to receive(:mountcmd).and_return(File.read(my_fixture('linux.mount')))
167167
mounts = described_class.mountinstances
168168
expect(mounts[0]).to eq(name: '/', mounted: :yes)
@@ -175,7 +175,7 @@
175175
end
176176

177177
it 'gets name from mountoutput found on AIX' do
178-
allow(Facter).to receive(:value).with(:osfamily).and_return 'AIX'
178+
allow(Facter).to receive(:value).with('os.family').and_return 'AIX'
179179
allow(described_class).to receive(:mountcmd).and_return(File.read(my_fixture('aix.mount')))
180180
mounts = described_class.mountinstances
181181
expect(mounts[0]).to eq(name: '/', mounted: :yes)
@@ -196,8 +196,8 @@
196196
end
197197

198198
it "supports AIX's paragraph based /etc/filesystems" do
199-
pending 'This test only works on AIX' unless Facter.value(:osfamily) == 'AIX'
200-
allow(Facter).to receive(:value).with(:osfamily).and_return 'AIX'
199+
pending 'This test only works on AIX' unless Facter.value('os.family') == 'AIX'
200+
allow(Facter).to receive(:value).with('os.family').and_return 'AIX'
201201
allow(described_class).to receive(:default_target).and_return my_fixture('aix.filesystems')
202202
allow(described_class).to receive(:mountcmd).and_return File.read(my_fixture('aix.mount'))
203203
instances = described_class.instances
@@ -220,8 +220,8 @@
220220
end
221221

222222
before :each do
223-
allow(Facter).to receive(:value).with(:osfamily).and_return platform
224-
if Facter[:osfamily] == 'Solaris'
223+
allow(Facter).to receive(:value).with('os.family').and_return platform
224+
if Facter.value('os.family') == 'Solaris'
225225
platform == 'solaris' ||
226226
skip("We need to double the operatingsystem fact at load time, but can't")
227227
else
@@ -244,7 +244,7 @@
244244
end
245245

246246
# Following mountpoint are present in all fstabs/mountoutputs
247-
describe 'on other platforms than Solaris', if: Facter.value(:osfamily) != 'Solaris' do
247+
describe 'on other platforms than Solaris', if: Facter.value('os.family') != 'Solaris' do
248248
it 'includes unmounted resources' do
249249
expect(instances).to include(name: '/', ensure: :mounted)
250250
end
@@ -275,8 +275,8 @@
275275

276276
before :each do
277277
allow(Facter).to receive(:value).with(:kernel).and_return 'Linux'
278-
allow(Facter).to receive(:value).with(:operatingsystem).and_return 'RedHat'
279-
allow(Facter).to receive(:value).with(:osfamily).and_return 'RedHat'
278+
allow(Facter).to receive(:value).with('os.name').and_return 'RedHat'
279+
allow(Facter).to receive(:value).with('os.family').and_return 'RedHat'
280280
begin
281281
mount = my_fixture('linux.mount')
282282
allow(described_class).to receive(:mountcmd).and_return File.read(mount)
@@ -331,11 +331,11 @@
331331
end
332332

333333
before :each do
334-
[:osfamily, :operatingsystem, :kernel].each do |fact|
334+
['os.family', 'os.name', :kernel].each do |fact|
335335
allow(Facter).to receive(:value).with(fact).and_return platform
336336
end
337337

338-
if Facter[:osfamily] == 'Solaris'
338+
if Facter.value('os.family') == 'Solaris'
339339
platform == 'solaris' ||
340340
skip("We need to double the operatingsystem fact at load time, but can't")
341341
else
@@ -357,7 +357,7 @@
357357
allow(described_class).to receive(:default_target).and_return fstab
358358
end
359359

360-
describe 'on other platforms than Solaris', if: Facter.value(:osfamily) != 'Solaris' do
360+
describe 'on other platforms than Solaris', if: Facter.value('os.family') != 'Solaris' do
361361
it 'sets :ensure to :unmounted if found in fstab but not mounted' do
362362
described_class.prefetch(resource_hash)
363363
expect(res_unmounted.provider.get(:ensure)).to eq(:unmounted)

spec/unit/provider/mount_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
allow(mounter).to receive(:info)
7676
allow(mounter).to receive(:options).and_return('ro')
7777
allow(resource).to receive(:[]).with(:remounts).and_return(:true)
78-
expect(Facter).to receive(:value).with(:operatingsystem).and_return 'AIX'
78+
expect(Facter).to receive(:value).with('os.name').and_return 'AIX'
7979
expect(mounter).to receive(:mountcmd).with('-o', 'ro,remount', name)
8080
mounter.remount
8181
end
@@ -93,7 +93,7 @@
9393
allow(mounter).to receive(:info)
9494
allow(mounter).to receive(:options)
9595
allow(resource).to receive(:[]).with(:remounts).and_return(false)
96-
expect(Facter).to receive(:value).with(:operatingsystem).and_return 'OpenBSD'
96+
expect(Facter).to receive(:value).with('os.name').and_return 'OpenBSD'
9797
expect(mounter).to receive(:mountcmd).with('-o', 'update', name)
9898
mounter.remount
9999
end
@@ -102,7 +102,7 @@
102102
allow(mounter).to receive(:info)
103103
allow(mounter).to receive(:options)
104104
allow(resource).to receive(:[]).with(:remounts).and_return(false)
105-
expect(Facter).to receive(:value).with(:operatingsystem).and_return 'AIX'
105+
expect(Facter).to receive(:value).with('os.name').and_return 'AIX'
106106
expect(mounter).to receive(:mount)
107107
expect(mounter).to receive(:unmount)
108108
mounter.remount

spec/unit/type/mount_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def mounted?
167167
describe 'for blockdevice' do
168168
before :each do
169169
# blockdevice is only used on Solaris
170-
[:osfamily, :operatingsystem, :kernel].each do |fact|
170+
['os.family', 'os.name', :kernel].each do |fact|
171171
allow(Facter).to receive(:value).with(fact).and_return 'Solaris'
172172
end
173173
end
@@ -252,21 +252,21 @@ def mounted?
252252
end
253253

254254
it 'supports - on Solaris' do
255-
[:osfamily, :operatingsystem, :kernel].each do |fact|
255+
['os.family', 'os.name', :kernel].each do |fact|
256256
allow(Facter).to receive(:value).with(fact).and_return 'Solaris'
257257
end
258258
expect { described_class.new(name: '/foo', ensure: :present, pass: '-') }.not_to raise_error
259259
end
260260

261261
it 'defaults to 0 on non Solaris' do
262-
[:osfamily, :operatingsystem, :kernel].each do |fact|
262+
['os.family', 'os.name', :kernel].each do |fact|
263263
allow(Facter).to receive(:value).with(fact).and_return 'HP-UX'
264264
end
265265
expect(described_class.new(name: '/foo', ensure: :present)[:pass]).to eq(0)
266266
end
267267

268268
it 'defaults to - on Solaris' do
269-
[:osfamily, :operatingsystem, :kernel].each do |fact|
269+
['os.family', 'os.name', :kernel].each do |fact|
270270
allow(Facter).to receive(:value).with(fact).and_return 'Solaris'
271271
end
272272
expect(described_class.new(name: '/foo', ensure: :present)[:pass]).to eq('-')
@@ -283,11 +283,11 @@ def mounted?
283283
end
284284

285285
# Unfortunately the operatingsystem is evaluatet at load time so I am unable to double operatingsystem
286-
it 'supports 2 as a value for dump on FreeBSD', if: Facter.value(:operatingsystem) == 'FreeBSD' do
286+
it 'supports 2 as a value for dump on FreeBSD', if: Facter.value('os.name') == 'FreeBSD' do
287287
expect { described_class.new(name: '/foo', ensure: :present, dump: '2') }.not_to raise_error
288288
end
289289

290-
it 'does not support 2 as a value for dump when not on FreeBSD', if: Facter.value(:operatingsystem) != 'FreeBSD' do
290+
it 'does not support 2 as a value for dump when not on FreeBSD', if: Facter.value('os.name') != 'FreeBSD' do
291291
expect { described_class.new(name: '/foo', ensure: :present, dump: '2') }.to raise_error Puppet::Error, %r{Invalid value}
292292
end
293293

0 commit comments

Comments
 (0)