-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(MODULES-8554) Add error repoting for background upgrades
This commit adds a new type/provider to check for an error log from a previous installation and fail if the error log exists. This will allow upgrades to leave behind error logs on failure to indicate the next puppet run should not perform the upgrade since the previous one failed. The provider will delete the existing error log before failing so that after the failed puppet run the user can attempt the upgrade again. This should provide error reporting for upgrades that require background processes (i.e. windows upgrades) by failing the next puppet run after the upgrade failure.
- Loading branch information
Sean P. McDonald
committed
Mar 11, 2019
1 parent
60fee39
commit 1c97903
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
lib/puppet/provider/puppet_agent_upgrade_error/puppet_agent_upgrade_error.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Puppet::Type.type(:puppet_agent_upgrade_error).provide :puppet_agent_upgrade_error do | ||
def ensure_notexist | ||
logfile = File.join(Puppet["statedir"].to_s, @resource[:name]) | ||
Puppet.debug "Checking for Error logfile #{logfile}" | ||
not File.exists?(logfile) | ||
end | ||
|
||
def delete_file_and_read_content(filename) | ||
logfile = File.join(Puppet["statedir"].to_s, filename) | ||
Puppet.debug "Reading Error Log #{logfile}" | ||
if Puppet.features.microsoft_windows? | ||
# The file laid down by the installation script on windows will be UTF-16LE. | ||
# In this scenario we need to open the file in binmode and read each line | ||
# individually, then encode the result back to UTF-8 so we can sub out both | ||
# the UTF-16 header \uFEFF and the \r\n line carriages. | ||
content = File.open(logfile,"rb:UTF-16LE"){ |file| file.readlines }[0].encode!('UTF-8').gsub("\uFEFF",'').gsub("\r",'') | ||
else | ||
content = File.read(logfile) | ||
end | ||
Puppet.debug "Deleting Error Log" | ||
File.delete(logfile) | ||
return content | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Puppet::Type.newtype(:puppet_agent_upgrade_error) do | ||
@doc = <<-DOC | ||
Fails when a previous background installation failed. The type | ||
will check for the existance of an installation failure log | ||
and raise an error with the contents of the log if it exists | ||
DOC | ||
|
||
newproperty(:ensure_notexist) do | ||
desc "whether or not the error log exists" | ||
def insync?(not_exist) | ||
if not_exist | ||
true | ||
else | ||
raise Puppet::Error.new("Failed previous installation with: #{provider.delete_file_and_read_content(@resource[:name])}") | ||
end | ||
end | ||
|
||
defaultto { true } | ||
end | ||
|
||
newparam(:name) do | ||
desc "The name of the failure log to check for in puppet's $statedir. If this log exists the resource will fail." | ||
isnamevar | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters