From f7c25df2fe6183ae849b9a52d26502a6f608abbb Mon Sep 17 00:00:00 2001 From: Drew Wilson Date: Tue, 12 Aug 2014 15:59:13 +0100 Subject: [PATCH] Fixes for issues #31 & #32. Site names containing spaces were rendered incorrectly in the powersell commands. Updated manage_virtual_application to use powershell provider --- manifests/manage_virtual_application.pp | 12 +++--- .../manage_virtual_application_spec.rb | 39 ++++++++++++------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/manifests/manage_virtual_application.pp b/manifests/manage_virtual_application.pp index da7e50e..dc7462e 100644 --- a/manifests/manage_virtual_application.pp +++ b/manifests/manage_virtual_application.pp @@ -10,17 +10,17 @@ } exec { "CreateVirtualApplication-${site_name}-${virtual_application_name}" : - command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-WebApplication -Name ${virtual_application_name} -Site ${site_name} -PhysicalPath ${site_path} -ApplicationPool ${app_pool}\"", - path => "${iis::param::powershell::path};${::path}", - onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\${site_name}\\${virtual_application_name}\\\")) { exit 1 } else { exit 0 }\"", + command => "Import-Module WebAdministration; New-WebApplication -Name ${virtual_application_name} -Site \"${site_name}\" -PhysicalPath \"${site_path}\" -ApplicationPool \"${app_pool}\"", + onlyif => "Import-Module WebAdministration; if((Test-Path \"IIS:\\Sites\\${site_name}\") -and (Get-ChildItem \"IIS:\\Sites\\${site_name}\" | where {\$_.Schema.Name -eq 'Application' -and \$_.Name -eq '${virtual_application_name}'})) { exit 1 } else { exit 0 }", require => [ Iis::Createpath["${site_name}-${virtual_application_name}-${site_path}"], Iis::Manage_site[$site_name] ], + provider => powershell, logoutput => true, } } else { exec { "DeleteVirtualApplication-${site_name}-${virtual_application_name}" : - command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; Remove-WebApplication -Name ${virtual_application_name} -Site ${site_name}\"", - path => "${iis::param::powershell::path};${::path}", - onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if(!(Test-Path \\\"IIS:\\Sites\\${site_name}\\${virtual_application_name}\\\")) { exit 1 } else { exit 0 }\"", + command => "Import-Module WebAdministration; Remove-WebApplication -Name ${virtual_application_name} -Site \"${site_name}\"", + onlyif => "Import-Module WebAdministration; if((Test-Path \"IIS:\\Sites\\${site_name}\") -and (Get-ChildItem \"IIS:\\Sites\\${site_name}\" | where {\$_.Schema.Name -eq 'Application' -and \$_.Name -eq '${virtual_application_name}'})) { exit 0 } else { exit 1 }", + provider => powershell, logoutput => true, } } diff --git a/spec/defines/manage_virtual_application_spec.rb b/spec/defines/manage_virtual_application_spec.rb index 6fd3508..5c02c77 100644 --- a/spec/defines/manage_virtual_application_spec.rb +++ b/spec/defines/manage_virtual_application_spec.rb @@ -11,11 +11,9 @@ :app_pool => 'myAppPool.example.com', }} - it { should contain_class('iis::param::powershell') } - it { should contain_exec('CreateVirtualApplication-myWebSite-mySite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebApplication -Name mySite -Site myWebSite -PhysicalPath C:\\inetpub\\wwwroot\\myHost -ApplicationPool myAppPool.example.com\"", - 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\mySite\\\")) { exit 1 } else { exit 0 }\"", + 'command' => "Import-Module WebAdministration; New-WebApplication -Name mySite -Site \"myWebSite\" -PhysicalPath \"C:\\inetpub\\wwwroot\\myHost\" -ApplicationPool \"myAppPool.example.com\"", + 'onlyif' => "Import-Module WebAdministration; if((Test-Path \"IIS:\\Sites\\myWebSite\") -and (Get-ChildItem \"IIS:\\Sites\\myWebSite\" | where {\$_.Schema.Name -eq 'Application' -and \$_.Name -eq 'mySite'})) { exit 1 } else { exit 0 }", })} end @@ -29,11 +27,26 @@ }} it { should contain_exec('CreateVirtualApplication-myWebSite-mySite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebApplication -Name mySite -Site myWebSite -PhysicalPath C:\\inetpub\\wwwroot\\myHost -ApplicationPool myAppPool.example.com\"", - 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\mySite\\\")) { exit 1 } else { exit 0 }\"", + 'command' => "Import-Module WebAdministration; New-WebApplication -Name mySite -Site \"myWebSite\" -PhysicalPath \"C:\\inetpub\\wwwroot\\myHost\" -ApplicationPool \"myAppPool.example.com\"", + 'onlyif' => "Import-Module WebAdministration; if((Test-Path \"IIS:\\Sites\\myWebSite\") -and (Get-ChildItem \"IIS:\\Sites\\myWebSite\" | where {\$_.Schema.Name -eq 'Application' -and \$_.Name -eq 'mySite'})) { exit 1 } else { exit 0 }", })} end +describe 'when I create a virtual application in IIS on a site with spaces in the name' do + let(:title) { 'myVirtualApp' } + let(:params) {{ + :site_name => 'My Web Site', + :site_path => 'C:\inetpub\wwwroot\myHost', + :app_pool => 'myAppPool.example.com', + :ensure => 'present', + }} + + it { should contain_exec('CreateVirtualApplication-My Web Site-myVirtualApp').with({ + 'command' => "Import-Module WebAdministration; New-WebApplication -Name myVirtualApp -Site \"My Web Site\" -PhysicalPath \"C:\\inetpub\\wwwroot\\myHost\" -ApplicationPool \"myAppPool.example.com\"", + 'onlyif' => "Import-Module WebAdministration; if((Test-Path \"IIS:\\Sites\\My Web Site\") -and (Get-ChildItem \"IIS:\\Sites\\My Web Site\" | where {\$_.Schema.Name -eq 'Application' -and \$_.Name -eq 'myVirtualApp'})) { exit 1 } else { exit 0 }", + })} +end + describe 'when I create a virtual application in IIS and set ensure to installed' do let(:title) { 'mySite' } let(:params) {{ @@ -44,8 +57,8 @@ }} it { should contain_exec('CreateVirtualApplication-myWebSite-mySite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebApplication -Name mySite -Site myWebSite -PhysicalPath C:\\inetpub\\wwwroot\\myHost -ApplicationPool myAppPool.example.com\"", - 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\mySite\\\")) { exit 1 } else { exit 0 }\"", + 'command' => "Import-Module WebAdministration; New-WebApplication -Name mySite -Site \"myWebSite\" -PhysicalPath \"C:\\inetpub\\wwwroot\\myHost\" -ApplicationPool \"myAppPool.example.com\"", + 'onlyif' => "Import-Module WebAdministration; if((Test-Path \"IIS:\\Sites\\myWebSite\") -and (Get-ChildItem \"IIS:\\Sites\\myWebSite\" | where {\$_.Schema.Name -eq 'Application' -and \$_.Name -eq 'mySite'})) { exit 1 } else { exit 0 }", })} end @@ -59,8 +72,8 @@ }} it { should contain_exec('DeleteVirtualApplication-myWebSite-mySite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Remove-WebApplication -Name mySite -Site myWebSite\"", - 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if(!(Test-Path \\\"IIS:\\Sites\\myWebSite\\mySite\\\")) { exit 1 } else { exit 0 }\"", + 'command' => "Import-Module WebAdministration; Remove-WebApplication -Name mySite -Site \"myWebSite\"", + 'onlyif' => "Import-Module WebAdministration; if((Test-Path \"IIS:\\Sites\\myWebSite\") -and (Get-ChildItem \"IIS:\\Sites\\myWebSite\" | where {\$_.Schema.Name -eq 'Application' -and \$_.Name -eq 'mySite'})) { exit 0 } else { exit 1 }", })} end @@ -74,8 +87,8 @@ }} it { should contain_exec('DeleteVirtualApplication-myWebSite-mySite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Remove-WebApplication -Name mySite -Site myWebSite\"", - 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if(!(Test-Path \\\"IIS:\\Sites\\myWebSite\\mySite\\\")) { exit 1 } else { exit 0 }\"", + 'command' => "Import-Module WebAdministration; Remove-WebApplication -Name mySite -Site \"myWebSite\"", + 'onlyif' => "Import-Module WebAdministration; if((Test-Path \"IIS:\\Sites\\myWebSite\") -and (Get-ChildItem \"IIS:\\Sites\\myWebSite\" | where {\$_.Schema.Name -eq 'Application' -and \$_.Name -eq 'mySite'})) { exit 0 } else { exit 1 }", })} end -end \ No newline at end of file +end