Skip to content

Commit d17f879

Browse files
(MODULES-6144) Add limits to iis_site type and provider
Prior to this commit there was no way to set the limits configurations for an IIS site using this module. All sites would instead inherit the default settings for connection timeout, max bandwidth, and maximum number of connections. This commit adds site limits to the iis_site type and provider. It also updates unit and acceptance tests for the new capability.
1 parent e152840 commit d17f879

7 files changed

Lines changed: 75 additions & 0 deletions

File tree

lib/puppet/provider/iis_site/webadministration.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def update
4545

4646
cmd << self.class.ps_script_content('logproperties', @resource)
4747

48+
cmd << self.class.ps_script_content('limitsproperty', @resource)
49+
4850
cmd << self.class.ps_script_content('serviceautostartprovider', @resource)
4951

5052

@@ -139,6 +141,7 @@ def self.instances
139141
binding.delete('certificatehash') unless binding['protocol'] == 'https'
140142
binding.delete('certificatestorename') unless binding['protocol'] == 'https'
141143
end
144+
site['limits'] = {} if site['limits'].nil?
142145

143146
site_hash[:ensure] = site['state'].downcase
144147
site_hash[:name] = site['name']
@@ -147,6 +150,7 @@ def self.instances
147150
site_hash[:serverautostart] = to_bool(site['serverautostart'])
148151
site_hash[:enabledprotocols] = site['enabledprotocols']
149152
site_hash[:bindings] = site['bindings']
153+
site_hash[:limits] = site['limits']
150154
site_hash[:logpath] = site['logpath']
151155
site_hash[:logperiod] = site['logperiod']
152156
site_hash[:logtruncatesize] = site['logtruncatesize']

lib/puppet/provider/templates/iisadministration/_getwebsites.ps1.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Get-IISSite | %{
1616
certificatestorename = [string]$_.certificateStoreName
1717
}
1818
})
19+
limits = New-Object -TypeName PSObject -Property @{
20+
maxbandwidth = [int64]$_.limits.maxbandwidth
21+
maxconnections = [int64]$_.limits.maxconnections
22+
connectiontimeout = [int]$_.limits.connectiontimeout.totalseconds
23+
}
1924
logformat = [string]$_.LogFile.logFormat
2025
logpath = [string]$_.LogFile.directory
2126
logperiod = [string]$_.LogFile.period

lib/puppet/provider/templates/webadministration/_getwebsites.ps1.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ Get-WebSite | % {
2424
certificatestorename = [string]$_.certificateStoreName
2525
}
2626
})
27+
limits = New-Object -TypeName PSObject -Property @{
28+
maxbandwidth = [int64]$_.limits.maxbandwidth
29+
maxconnections = [int64]$_.limits.maxconnections
30+
connectiontimeout = [int]$_.limits.connectiontimeout.totalseconds
31+
}
2732
logformat = [string]$_.LogFile.logFormat
2833
logpath = [string]$_.LogFile.directory
2934
logperiod = [string]$_.LogFile.period
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%- if resource[:limits] -%>
2+
$website = Get-WebConfiguration -Filter '/system.applicationHost/sites/site' | Where-Object -FilterScript {$_.Name -eq '<%= resource[:name] %>' }
3+
<%- resource[:limits].each do |limit_name,limit_setting| -%>
4+
<%- if limit_name == 'connectiontimeout' -%>
5+
Set-WebConfiguration -Filter "$($website.ItemXPath)/limits/@<%= limit_name %>" -Value (New-Timespan -Seconds <%= limit_setting %>)
6+
<%- else -%>
7+
Set-WebConfiguration -Filter "$($website.ItemXPath)/limits/@<%= limit_name %>" -Value <%= limit_setting %>
8+
<%- end -%>
9+
<%- end -%>
10+
<%- end -%>

lib/puppet/type/iis_site.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,26 @@ def insync?(is)
294294
end
295295
end
296296

297+
newproperty(:limits) do
298+
desc 'Configure limits for an IIS Site'
299+
valid_limits = ['connectiontimeout', 'maxbandwidth', 'maxconnections']
300+
validate do |value|
301+
fail "#{self.name.to_s} should be a Hash" unless value.is_a? ::Hash
302+
value.each do |key, limit|
303+
fail("Invalid iis site limit key '#{key}'. Should be one of: #{valid_limits}") unless valid_limits.include? key
304+
fail("Invalid value '#{limit}' for #{key}. Must be an integer") unless limit.is_a? Integer
305+
if key != 'connectiontimeout' and (limit < 1 or limit > 4294967295)
306+
fail("Invalid value '#{limit} for #{key}'. Cannot be less than 1 or greater than 4294967295")
307+
end
308+
end
309+
end
310+
def insync?(is)
311+
should.select do |k,v|
312+
is[k] != v
313+
end.empty?
314+
end
315+
end
316+
297317
autorequire(:iis_application_pool) { self[:applicationpool] }
298318

299319
validate do

spec/acceptance/iis_site_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
# 'sslflags' => 1,
6666
# },
6767
],
68+
limits => {
69+
connectiontimeout => 120,
70+
maxbandwidth => 4294967200,
71+
maxconnections => 4294967200,
72+
},
6873
logflags => ['ClientIP', 'Date', 'Time', 'UserName'],
6974
logformat => 'W3C',
7075
loglocaltimerollover => false,

spec/unit/puppet/type/iis_site_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,32 @@
104104
}
105105
end
106106
end
107+
context "property :limits" do
108+
it "requires a hash" do
109+
expect {
110+
resource[:limits] = "hi"
111+
}.to raise_error(Puppet::Error, /Hash/)
112+
expect {
113+
resource[:limits] = ["hi"]
114+
}.to raise_error(Puppet::Error, /Hash/)
115+
end
116+
it "accepts only valid limits as keys" do
117+
expect {
118+
resource[:limits] = {'invalid' => 'setting'}
119+
}.to raise_error(Puppet::Error, /Invalid iis site limit key/)
120+
end
121+
it "rejects invalid limits values" do
122+
expect {
123+
resource[:limits] = { 'maxconnections' => "string"}
124+
}.to raise_error(Puppet::Error, /integer/)
125+
expect {
126+
resource[:limits] = { 'maxbandwidth' => 0 }
127+
}.to raise_error(Puppet::Error, /Cannot be less than 1 or greater than 4294967295/)
128+
expect {
129+
resource[:limits] = { 'maxbandwidth' => 4294967296 }
130+
}.to raise_error(Puppet::Error, /Cannot be less than 1 or greater than 4294967295/)
131+
end
132+
end
107133
context "parameter :applicationpool" do
108134
it "should not allow nil" do
109135
expect {

0 commit comments

Comments
 (0)