From 06ca693df4418bd15d40f75f3d197fbfbee24bc8 Mon Sep 17 00:00:00 2001 From: calebfornari Date: Tue, 31 Dec 2013 17:40:15 -0500 Subject: [PATCH 1/2] Handle cases where IIS has zero existing sites. --- manifests/manage_site.pp | 2 +- spec/defines/manage_site_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/manifests/manage_site.pp b/manifests/manage_site.pp index 0e436e7..c54d1ec 100644 --- a/manifests/manage_site.pp +++ b/manifests/manage_site.pp @@ -17,7 +17,7 @@ $switches = join($createSwitches,' ') exec { "CreateSite-${site_name}" : - command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-WebSite ${switches} \"", + command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; \$id = (Get-WebSite | foreach {\$_.id} | sort -Descending | select -first 1) + 1; New-WebSite ${switches} -ID \$id \"", path => "${iis::param::powershell::path};${::path}", onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\${site_name}\\\")) { exit 1 } else { exit 0 }\"", logoutput => true, diff --git a/spec/defines/manage_site_spec.rb b/spec/defines/manage_site_spec.rb index 2e876e6..cec64ba 100644 --- a/spec/defines/manage_site_spec.rb +++ b/spec/defines/manage_site_spec.rb @@ -14,7 +14,7 @@ it { should include_class('iis::param::powershell') } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end @@ -33,7 +33,7 @@ it { should include_class('iis::param::powershell') } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end @@ -48,7 +48,7 @@ } } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end @@ -63,7 +63,7 @@ } } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end From 771b8ca761a8c3d413b51576e46935867777d1d3 Mon Sep 17 00:00:00 2001 From: Caleb Fornari Date: Tue, 31 Dec 2013 18:31:23 -0500 Subject: [PATCH 2/2] Removing extra space as it's breaking the tests. --- spec/defines/manage_site_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/defines/manage_site_spec.rb b/spec/defines/manage_site_spec.rb index cec64ba..6730595 100644 --- a/spec/defines/manage_site_spec.rb +++ b/spec/defines/manage_site_spec.rb @@ -33,7 +33,7 @@ it { should include_class('iis::param::powershell') } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end @@ -97,4 +97,4 @@ 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if(!(Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end -end \ No newline at end of file +end