Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/puppet/parser/functions/parse_auto_update_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ module Puppet::Parser::Functions
autoupdate_hash = { 'notifyonly' => 2,
'autonotify' => 3,
'scheduled' => 4,
'autoinstall' => 5 }
'autoinstall' => 5,
'notifyrestart' => 7 }

option = args[0]
error_msg = "Valid options for auto_update_option are NotifyOnly|AutoNotify|Scheduled|AutoInstall|2|3|4|5, provided '#{option}'"
error_msg = "Valid options for auto_update_option are NotifyOnly|AutoNotify|Scheduled|AutoInstall|NotifyRestart|2|3|4|5|7, provided '#{option}'"
if option.is_a?(Numeric) || option =~ %r{^\d$}
option = Integer(option) if option.is_a?(String)
raise Puppet::ParseError, error_msg if option < 2 || option > 5
raise Puppet::ParseError, error_msg if option < 2 || option > 7

return option
end
Expand Down
13 changes: 12 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
Optional[Variant[Stdlib::HTTPUrl,Boolean]] $server_url = undef,
Optional[Boolean] $enable_status_server = undef,
Optional[Boolean] $accept_trusted_publisher_certs = undef,
Optional[Variant[Enum['NotifyOnly', 'AutoNotify', 'Scheduled', 'AutoInstall'],Integer[2,5]]] $auto_update_option = undef,
Optional[Variant[Enum['NotifyOnly', 'AutoNotify', 'Scheduled', 'AutoInstall', 'NotifyRestart'],Integer[2,5],Integer[7,7]]]
$auto_update_option = undef,
Optional[Boolean] $auto_install_minor_updates = undef,
Optional[Variant[Integer[1,22],Boolean]] $detection_frequency_hours = undef,
Optional[Boolean] $disable_windows_update_access = undef,
Expand Down Expand Up @@ -212,6 +213,16 @@

if $auto_update_option {
$_parsed_auto_update_option = parse_auto_update_option($auto_update_option)

# Option 7 is only supported on Windows Server 2016 and later.
if $_parsed_auto_update_option == 7 {
# Windows 2012's major version in facter is "2012 R2" which cannot be converted to integer directly.
# So, extract the leading digits from the major release string.
$_windows_version = regsubst($facts['os']['release']['major'], '^(\d+).*$', '\1')
if (Integer($_windows_version) < 2016) {
fail('auto_update_option value 7 is only supported on Windows Server 2016 and later.')
}
}
if $_parsed_auto_update_option == 4 and !($scheduled_install_day and $scheduled_install_hour) {
fail("scheduled_install_day and scheduled_install_hour required when specifying auto_update_option => '${auto_update_option}'")
}
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
auto_update_option: au_opt
}
end
let(:error_message) { %r{expects a value of type Undef, Enum\['AutoInstall', 'AutoNotify', 'NotifyOnly', 'Scheduled'\], or Integer\[2, 5\]} }
let(:error_message) { %r{expects a value of type Undef, Enum\['AutoInstall', 'AutoNotify', 'NotifyOnly', 'NotifyRestart', 'Scheduled'\], Integer\[2, 5\], or Integer\[7, 7\]} }

it_behaves_like 'fail validation'
end
Expand Down
5 changes: 3 additions & 2 deletions spec/functions/parse_auto_update_option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
expected_hash = { 'NotifyOnly' => 2,
'AutoNotify' => 3,
'Scheduled' => 4,
'AutoInstall' => 5 }
'AutoInstall' => 5,
'NotifyRestart' => 7 }

expected_hash.each_key do |auto_update_option|
describe "when parsing #{auto_update_option}" do
Expand Down Expand Up @@ -41,7 +42,7 @@
expect {
scope.function_parse_auto_update_option(['Whatthe'])
}.to raise_error(Puppet::Error,
"Valid options for auto_update_option are #{expected_hash.keys.join('|')}|2|3|4|5, provided 'Whatthe'")
"Valid options for auto_update_option are #{expected_hash.keys.join('|')}|2|3|4|5|7, provided 'Whatthe'")
end
end
end