Problem:
(Reported to Customer Support)
The Tidy resource throws an error: "Error: Could not back up files of type socket." when managing /tmp and it encounters a socket file. Tidy then fails to remove anything else after it errors. However, Tidy should not be backing up any files given the backup attribute.
That kind of defeats the purpose of using the Tidy resource, doesn't it? I understand about not being able to ensure special file existence (creation), but I would think special file absence should be easy. I was hoping Tidy would be the answer (it sure seems like it should) especially since I'm telling Puppet to not backup anything it's deleting.
Word.
Example:
Create a test file:
python -c "import socket as s; sock = s.socket(s.AF_UNIX); sock.bind('/tmp/testsocket')"
|
Create a test:
class test_tidy_tmp {
|
tidy {'/tmp':
|
age => '1w',
|
size => '1m',
|
backup => false,
|
}
|
}
|
|
node default {
|
include test_tidy_tmp
|
}
|
Execute the test:
[root@pe-201642-master ~]# puppet agent -t
|
Info: Using configured environment 'production'
|
Info: Retrieving pluginfacts
|
Info: Retrieving plugin
|
Info: Loading facts
|
Info: Caching catalog for pe-201642-master.puppetdebug.vlan
|
Notice: /Stage[main]/Test_tidy_tmp/Tidy[/tmp]: Tidying 1 file
|
Info: Applying configuration version '1480552981'
|
Error: Could not back up files of type socket
|
Error: /Stage[main]/Test_tidy_tmp/File[/tmp/testsocket]/ensure: change from socket to absent failed: Could not back up files of type socket
|
Notice: /Stage[main]/Test_tidy_tmp/Tidy[/tmp]: Dependency File[/tmp/testsocket] has failures: true
|
Warning: /Stage[main]/Test_tidy_tmp/Tidy[/tmp]: Skipping because of failed dependencies
|
Notice: Applied catalog in 9.99 seconds
|
Solutions:
Here are two solutions, either solves the problem, I propose implementing both.
Modify Tidy to ignore/skip files it cannot manage via File resources
tom:puppet tom.kishel$ diff /tmp/tidy.rb lib/puppet/type/tidy.rb
|
259,263c259
|
<
|
< # Exclude files that cannot be made into a file resource in mkfile.
|
< valid_file_resource_files = files.find_all { |f| ['directory', 'file', 'symlink'].include? File.ftype(f) }
|
<
|
< found_files = valid_file_resource_files.find_all { |path| tidy?(path) }.collect { |path| mkfile(path) }
|
---
|
> found_files = files.find_all { |path| tidy?(path) }.collect { |path| mkfile(path) }
|
Execute the solution test for Tidy:
[root@pe-201642-master ~]# puppet agent -t
|
Info: Using configured environment 'production'
|
Info: Retrieving pluginfacts
|
Info: Retrieving plugin
|
Info: Loading facts
|
Info: Caching catalog for pe-201642-master.puppetdebug.vlan
|
Notice: /Stage[main]/Test_tidy_tmp/Tidy[/tmp]: Tidying 0 files
|
Info: Applying configuration version '1480555895'
|
Notice: Applied catalog in 9.99 seconds
|
Result: Success
Modify File to allow ensure => absent for (fifo and) socket
tom:puppet tom.kishel$ diff /tmp/file.rb lib/puppet/type/file.rb
|
717c717
|
< # @raises [fail???] If the current file is one of %w{blockSpecial characterSpecial unknown} and can't be removed.
|
---
|
> # @raises [fail???] If the current file isn't one of %w{file link directory} and can't be removed.
|
737c737
|
< when "link", "file", "fifo", "socket"
|
---
|
> when "link", "file"
|
740,741c740
|
< # Potentially: "blockSpecial", "characterSpecial", "unknown"
|
< self.fail "Could not remove file of type #{current_type}"
|
---
|
> self.fail "Could not back up files of type #{current_type}"
|
938,945c937,939
|
< if type == "directory" and force?
|
< # (#18110) Directories cannot be removed without :force,
|
< # so it doesn't make sense to back them up unless using :force.
|
< true
|
< elsif type == "file" or type == "link"
|
< true
|
< else
|
< # Potentially: "blockSpecial", "characterSpecial", "fifo", "socket", "unknown"
|
---
|
> if type == "directory" and not force?
|
> # (#18110) Directories cannot be removed without :force, so it doesn't
|
> # make sense to back them up.
|
946a941,942
|
> else
|
> true
|
Create test files for File via Tidy:
mkfifo /tmo/testfifo
|
python -c "import socket as s; sock = s.socket(s.AF_UNIX); sock.bind('/tmp/testsocket')"
|
Execute the solution test for File via Tidy:
[root@pe-201642-master tmp]# puppet agent -t
|
Info: Using configured environment 'production'
|
Info: Retrieving pluginfacts
|
Info: Retrieving plugin
|
Info: Loading facts
|
Info: Caching catalog for pe-201642-master.puppetdebug.vlan
|
Notice: /Stage[main]/Tmp_tidy/Tidy[/tmp]: Tidying 2 files
|
Info: Applying configuration version '1480616019'
|
Notice: /Stage[main]/Tmp_tidy/File[/tmp/testfifo]/ensure: removed
|
Notice: /Stage[main]/Tmp_tidy/File[/tmp/testsocket]/ensure: removed
|
Notice: Applied catalog in 9.99 seconds
|
Result: Success
Create a test for just File:
node default {
|
file {'/tmp/testfifo':
|
ensure => absent,
|
backup => false,
|
}
|
|
file {'/tmp/testsocket':
|
ensure => absent,
|
backup => false,
|
}
|
}
|
Execute the solution test for just File:
[root@pe-201642-master ~]# puppet agent -t
|
Info: Using configured environment 'production'
|
Info: Retrieving pluginfacts
|
Info: Retrieving plugin
|
Info: Loading facts
|
Info: Caching catalog for pe-201642-master.puppetdebug.vlan
|
Info: Applying configuration version '1480555713'
|
Notice: /Stage[main]/Main/Node[default]/File[/tmp/testfifo]/ensure: removed
|
Notice: /Stage[main]/Main/Node[default]/File[/tmp/testsocket]/ensure: removed
|
Notice: Applied catalog in 9.99 seconds
|
Result: Success
|