From 7f734b5b006f747e7c9b23806e3cc860eb288384 Mon Sep 17 00:00:00 2001 From: John Bollinger Date: Thu, 29 Mar 2018 10:57:03 -0500 Subject: [PATCH 1/2] Made the Autofs::Mapentry type more permissive The Autofs::Mapentry type rejected some map designations that Autofs itself permits. The type is updated to accept all valid designations that aren't plain absolute paths. Inasmuch as the accepted designations vary with the specified map type, and this data type (still) does not make distinctions based on map type, it now accepts some map designations that Autofs will reject. Specifically, for 'file', 'directory', and 'program' map types, Autofs expects the map name to be an absolute path, and the Autofs::Mapentry data type no longer enforces this. --- spec/defines/mount_spec.rb | 49 ++++++++++++++++++++++++++++++++++++++ types/mapentry.pp | 9 ++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/spec/defines/mount_spec.rb b/spec/defines/mount_spec.rb index 3ac1f81..e462321 100644 --- a/spec/defines/mount_spec.rb +++ b/spec/defines/mount_spec.rb @@ -274,6 +274,55 @@ end end + context 'with map format option' do + let(:title) { '/data' } + let(:params) do + { + mapfile: 'file,sun:/etc/auto.data', + mapfile_manage: false, + } + end + + it do + is_expected.to compile + is_expected.to contain_concat(master_map_file) + is_expected.to contain_concat__fragment('autofs::fragment preamble /data file,sun:/etc/auto.data') + .with_target(master_map_file) + .with_content(%r{\A\s*/data\s+file,sun:/etc/auto.data\s*$}) + end + end + + context 'with map type and no leading slash' do + # this example is drawn directly from the Linux auto.master(5) manual page + let(:title) { '/mnt' } + let(:params) do + { + mapfile: 'yp:mnt.map', + mapfile_manage: false, + } + end + + it do + is_expected.to compile + is_expected.to contain_concat(master_map_file) + is_expected.to contain_concat__fragment('autofs::fragment preamble /mnt yp:mnt.map') + .with_target(master_map_file) + .with_content(%r{\A\s*/mnt\s+yp:mnt.map\s*$}) + end + end + + context 'with relative map file' do + # This one expects compilation to fail + let(:title) { '/data' } + let(:params) do + { + mapfile: 'etc/auto.data', + } + end + + it { is_expected.to compile.and_raise_error(/.*/) } + end + context 'with ensure set to absent' do let(:title) { '/data' } let(:params) do diff --git a/types/mapentry.pp b/types/mapentry.pp index f0655f4..de3fe5c 100644 --- a/types/mapentry.pp +++ b/types/mapentry.pp @@ -1,6 +1,9 @@ -# This type matches a map type and path. +# This type matches a map specfication with map type and optional format, +# or the built-in -hosts map. # @example program:/etc/auto.smb # @example file:/etc/auto.file -# @example hosts:-hosts +# @example file,sun:/etc/auto.file +# @example yp:mnt.map +# @example -hosts -type Autofs::Mapentry = Pattern[/^[a-z]+:\/([^\/\0]+(\/)?)+$|^-hosts$/] +type Autofs::Mapentry = Pattern[/\A([a-z]+(,[a-z]+)?:\S+|-hosts)\z/] From 9aa15f4909d82efb995ea098d6b85236be672e02 Mon Sep 17 00:00:00 2001 From: John Bollinger Date: Thu, 29 Mar 2018 12:31:50 -0500 Subject: [PATCH 2/2] Code style adjustments to please RuboCop Applied some code-style adjustments to satisfy the RuboCop-enforced style rules for the project. --- spec/defines/mount_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/defines/mount_spec.rb b/spec/defines/mount_spec.rb index e462321..27473f1 100644 --- a/spec/defines/mount_spec.rb +++ b/spec/defines/mount_spec.rb @@ -279,16 +279,16 @@ let(:params) do { mapfile: 'file,sun:/etc/auto.data', - mapfile_manage: false, + mapfile_manage: false } end it do is_expected.to compile is_expected.to contain_concat(master_map_file) - is_expected.to contain_concat__fragment('autofs::fragment preamble /data file,sun:/etc/auto.data') - .with_target(master_map_file) - .with_content(%r{\A\s*/data\s+file,sun:/etc/auto.data\s*$}) + is_expected.to contain_concat__fragment('autofs::fragment preamble /data file,sun:/etc/auto.data'). + with_target(master_map_file). + with_content(%r{\A\s*/data\s+file,sun:/etc/auto.data\s*$}) end end @@ -298,16 +298,16 @@ let(:params) do { mapfile: 'yp:mnt.map', - mapfile_manage: false, + mapfile_manage: false } end it do is_expected.to compile is_expected.to contain_concat(master_map_file) - is_expected.to contain_concat__fragment('autofs::fragment preamble /mnt yp:mnt.map') - .with_target(master_map_file) - .with_content(%r{\A\s*/mnt\s+yp:mnt.map\s*$}) + is_expected.to contain_concat__fragment('autofs::fragment preamble /mnt yp:mnt.map'). + with_target(master_map_file). + with_content(%r{\A\s*/mnt\s+yp:mnt.map\s*$}) end end @@ -316,11 +316,11 @@ let(:title) { '/data' } let(:params) do { - mapfile: 'etc/auto.data', + mapfile: 'etc/auto.data' } end - it { is_expected.to compile.and_raise_error(/.*/) } + it { is_expected.to compile.and_raise_error(%r{.*}) } end context 'with ensure set to absent' do