From 5f93b3474c922b508488f09d505e9575706d382a Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Wed, 9 Aug 2017 21:49:02 +0100 Subject: [PATCH 01/17] Added Additional Example utilizing the LanguagePack and Language Resources together --- Examples/Sample_CombinedResourceUse.ps1 | 32 +++++++++++++++++++++++++ Examples/Sample_ConfigureLanguage.ps1 | 3 ++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 Examples/Sample_CombinedResourceUse.ps1 diff --git a/Examples/Sample_CombinedResourceUse.ps1 b/Examples/Sample_CombinedResourceUse.ps1 new file mode 100644 index 0000000..7ffbc26 --- /dev/null +++ b/Examples/Sample_CombinedResourceUse.ps1 @@ -0,0 +1,32 @@ +Configuration Example +{ + + Import-DscResource -Module LanguageDsc + + LanguagePack InstallLanguagePack + { + LanguagePackName = "en-GB" + LanguagePackLocation = "\\fileserver1\LanguagePacks\" + } + + Language ConfigureLanguage { + IsSingleInstance = "Yes" + LocationID = 242 + MUILanguage = "en-GB" + MUIFallbackLanguage = "en-US" + SystemLocale = "en-GB" + AddInputLanguages = @("0809:00000809") + RemoveInputLanguages = @("0409:00000409") + UserLocale = "en-GB" + CopySystem = $true + CopyNewUser = $true + Dependson = "[LanguagePack]InstallLanguagePack" + } + + LocalConfigurationManager + { + RebootNodeIfNeeded = $true + ActionAfterReboot = 'ContinueConfiguration' + ConfigurationMode = 'ApplyAndAutoCorrect' + } +} \ No newline at end of file diff --git a/Examples/Sample_ConfigureLanguage.ps1 b/Examples/Sample_ConfigureLanguage.ps1 index 637cd1a..d932292 100644 --- a/Examples/Sample_ConfigureLanguage.ps1 +++ b/Examples/Sample_ConfigureLanguage.ps1 @@ -5,7 +5,8 @@ Configuration Example Import-DscResource -Module LanguageDsc - Language ConfigureLanguage { + Language ConfigureLanguage + { IsSingleInstance = "Yes" LocationID = 242 MUILanguage = "en-GB" From 88d911dcfad2057e4f0714287ca9d0d00c050239 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Wed, 9 Aug 2017 22:18:22 +0100 Subject: [PATCH 02/17] Added wait for language pack installation to resource. This massively increases runtime for the resource but stops failures. --- DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 index 9c7e026..eddab85 100644 --- a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 +++ b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 @@ -89,6 +89,14 @@ Function Set-TargetResource if (Test-Path -Path $LanguagePackLocation) { lpksetup.exe /i $LanguagePackName /p $LanguagePackLocation /r /a /s + $startTime = Get-Date + do + { + $Process = Get-Process -Name "lpksetup" -ErrorAction SilentlyContinue + $currentTime = (Get-Date) - $startTime + Write-Verbose "Waiting for Process to finish. Time Taken: $($currentTime)" + Start-Sleep -Seconds 10 + } while ($null -ne $Process) } else { From b6d9e7c9d676cd891a509224d8af6b6c519c4f83 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Wed, 9 Aug 2017 22:35:39 +0100 Subject: [PATCH 03/17] Removing DSCResource.Tests submodule stub --- DSCResource.Tests | 1 - 1 file changed, 1 deletion(-) delete mode 160000 DSCResource.Tests diff --git a/DSCResource.Tests b/DSCResource.Tests deleted file mode 160000 index 104da5c..0000000 --- a/DSCResource.Tests +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 104da5c476906230ccdfbd2375ac01151211efdf From 13c071edefaa4d483ef68424ed8391d4464c4a5b Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Wed, 9 Aug 2017 22:59:33 +0100 Subject: [PATCH 04/17] Added newline to avoid CI error --- Examples/Sample_CombinedResourceUse.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Sample_CombinedResourceUse.ps1 b/Examples/Sample_CombinedResourceUse.ps1 index 7ffbc26..a00bec0 100644 --- a/Examples/Sample_CombinedResourceUse.ps1 +++ b/Examples/Sample_CombinedResourceUse.ps1 @@ -29,4 +29,4 @@ Configuration Example ActionAfterReboot = 'ContinueConfiguration' ConfigurationMode = 'ApplyAndAutoCorrect' } -} \ No newline at end of file +} From 2c555b32ac0ee58974dcdf6c2e50dbf016c4467a Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sat, 12 Aug 2017 17:11:41 +0100 Subject: [PATCH 05/17] Added Optin for additional tests --- .MetaTestOptIn.json | 6 ++++-- .gitignore | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index 053c1a2..3074e38 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -1,4 +1,6 @@ [ - "Common Tests - Validate Markdown Files", - "Common Tests - Validate Example Files" + "Common Tests - Validate Markdown Files", + "Common Tests - Validate Example Files", + "Common Tests - Validate Module Files", + "Common Tests - Validate Script Files" ] diff --git a/.gitignore b/.gitignore index f9f0b1b..4262dae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ DSCResource.Tests +DSCResource.Tests/* .vs +/DSCResource.Tests +/DSCResource.Tests From 09df30ef8bd91fbd491db9aa3a34a9321eb51130 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sat, 9 Sep 2017 19:00:41 +0100 Subject: [PATCH 06/17] Updated Integration Tests --- .../MSFT_LanguagePack/MSFT_LanguagePack.psm1 | 47 ++++---- Examples/Sample_ConfigureLanguage.ps1 | 15 ++- README.md | 10 ++ .../MSFT_Language.Integration.Tests.ps1 | 71 +++++++++++- Tests/Integration/MSFT_Language.config.ps1 | 39 +++++-- .../MSFT_LanguagePack.Integration.Tests.ps1 | 109 ++++++++++++++++-- .../Integration/MSFT_LanguagePack.config.ps1 | 19 ++- 7 files changed, 253 insertions(+), 57 deletions(-) diff --git a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 index eddab85..eac11f7 100644 --- a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 +++ b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 @@ -83,36 +83,39 @@ Function Set-TargetResource switch ($Ensure) { 'Present' { - if ($PSBoundParameters.ContainsKey('LanguagePackLocation')) + if ($PSBoundParameters.ContainsKey('LanguagePackLocation')) + { + Write-Verbose "Installing Language Pack" + if (Test-Path -Path $LanguagePackLocation) { - Write-Verbose "Installing Language Pack" - if (Test-Path -Path $LanguagePackLocation) - { - lpksetup.exe /i $LanguagePackName /p $LanguagePackLocation /r /a /s - $startTime = Get-Date - do - { - $Process = Get-Process -Name "lpksetup" -ErrorAction SilentlyContinue - $currentTime = (Get-Date) - $startTime - Write-Verbose "Waiting for Process to finish. Time Taken: $($currentTime)" - Start-Sleep -Seconds 10 - } while ($null -ne $Process) - } - else - { - Throw "Invalid source Location" - } + lpksetup.exe /i $LanguagePackName /p $LanguagePackLocation /r /a /s + $startTime = Get-Date } else { - Throw "Language Pack location must be specified when adding a new Language Pack" + Throw "Invalid source Location" } } - 'Absent' { - Write-Verbose "Removing Language Pack" - lpksetup.exe /u $LanguagePackName /r /a /s + else + { + Throw "Language Pack location must be specified when adding a new Language Pack" } + } + 'Absent' { + Write-Verbose "Removing Language Pack" + lpksetup.exe /u $LanguagePackName /r /a /s + } + default { + Throw "invalid operation" + } } + do + { + $Process = Get-Process -Name "lpksetup" -ErrorAction SilentlyContinue + $currentTime = (Get-Date) - $startTime + Write-Verbose "Waiting for Process to finish. Time Taken: $($currentTime)" + Start-Sleep -Seconds 10 + } while ($null -ne $Process) #Force a reboot after installing or removing a language pack $global:DSCMachineStatus = 1 } diff --git a/Examples/Sample_ConfigureLanguage.ps1 b/Examples/Sample_ConfigureLanguage.ps1 index d932292..f0df42f 100644 --- a/Examples/Sample_ConfigureLanguage.ps1 +++ b/Examples/Sample_ConfigureLanguage.ps1 @@ -2,20 +2,19 @@ Configuration Example { - Import-DscResource -Module LanguageDsc - Language ConfigureLanguage + Language ConfigureLanguage { - IsSingleInstance = "Yes" - LocationID = 242 - MUILanguage = "en-GB" + IsSingleInstance = "Yes" + LocationID = 242 + MUILanguage = "en-GB" MUIFallbackLanguage = "en-US" - SystemLocale = "en-GB" - AddInputLanguages = @("0809:00000809") + SystemLocale = "en-GB" + AddInputLanguages = @("0809:00000809") RemoveInputLanguages = @("0409:00000409") UserLocale = "en-GB" - CopySystem = $true + CopySystem = $true CopyNewUser = $true } } diff --git a/README.md b/README.md index 151669b..0b4fcbe 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,13 @@ This resource will install or remove a single language pack from the target syst * Initial release with the following resources: * Language * LanguagePack + +## How to Test +This resource is configured to exclude integration tests from its automated testing utilizing appveyor. This is due to the external dependencies required for the langagePack Resource. To configure a valid testing environment the following prerequisites are required: +* Windows Server Operating System with en-US language installed +* Git for Windows +* C:\LanguagePacks must exist +* en-GB (English-UK) Language Pack must be in C:\LanguagePacks +* de-DE (German) Language Pack must be in C:\LanguagePacks + +These specifics can be controlled by modifying the MSFT_LanguagePack.Integration.Tests.ps1 file diff --git a/Tests/Integration/MSFT_Language.Integration.Tests.ps1 b/Tests/Integration/MSFT_Language.Integration.Tests.ps1 index a4a5c95..e4c4445 100644 --- a/Tests/Integration/MSFT_Language.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Language.Integration.Tests.ps1 @@ -18,11 +18,58 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion -# TODO: Other Init Code Goes Here... +Import-Module "$script:moduleRoot\DSCResources\$script:DSCResourceName\$script:DSCResourceName.psm1" # Using try/finally to always cleanup. try { + $LocationID = 242 + $MUILanguage = "en-GB" + $MUIFallbackLanguage = 'en-US' + $SystemLocale = 'en-GB' + $AddInputLanguages = "0809:00000809" + $RemoveInputLanguages = "0409:00000409" + $UserLocale = "en-GB" + + Describe "Pre-flight Checks" { + Context "Ensure System requires modification" { + $CurrentState = Get-TargetResource -IsSingleInstance "Yes" + It "LocationID requires modification" { + $CurrentState.LocationID | Should Not Be $LocationID + } + + It "MUILanguage requires modification" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.MUILanguage | Should Not Be $MUILanguage + } + + It "MUI Fallback Language requires modification" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.MUIFallbackLanguage | Should Not Be $MUIFallbackLanguage + } + + It "System Locale requires modification" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.SystemLocale | Should Not Be $SystemLocale + } + + It "$AddInputLanguages keyboard is not already installed" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.CurrentInstalledLanguages.Values | Should Not Match $AddInputLanguages + } + + It "$RemoveInputLanguages keyboard should be installed" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.CurrentInstalledLanguages.Values | Should Match $RemoveInputLanguages + } + + It "User Locale requires modification" { + #$CurrentState = Get-TargetResource -IsSingleInstance "Yes" + $CurrentState.UserLocale | Should Not Be $UserLocale + } + } + } + #region Integration Tests $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" . $configFile @@ -31,7 +78,14 @@ try #region DEFAULT TESTS It 'Should compile and apply the MOF without throwing' { { - & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive + & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive ` + -LocationID $LocationID ` + -MUILanguage $MUILanguage ` + -MUIFallbackLanguage $MUIFallbackLanguage ` + -SystemLocale $SystemLocale ` + -AddInputLanguages $AddInputLanguages ` + -RemoveInputLanguages $RemoveInputLanguages ` + -UserLocale $UserLocale Start-DscConfiguration -Path $TestDrive ` -ComputerName localhost -Wait -Verbose -Force } | Should not throw @@ -42,8 +96,17 @@ try } #endregion - It 'Should have set the resource and all the parameters should match' { - # TODO: Validate the Config was Set Correctly Here... + It 'Resource Test should return true' { + Test-TargetResource -IsSingleInstance "Yes" ` + -LocationID $LocationID ` + -MUILanguage $MUILanguage ` + -MUIFallbackLanguage $MUIFallbackLanguage ` + -SystemLocale $SystemLocale ` + -AddInputLanguages $AddInputLanguages ` + -RemoveInputLanguages $RemoveInputLanguages ` + -UserLocale $UserLocale ` + -CopySystem $true ` + -CopyNewUser $true | Should Be $true } } #endregion diff --git a/Tests/Integration/MSFT_Language.config.ps1 b/Tests/Integration/MSFT_Language.config.ps1 index 35001e0..96d65bc 100644 --- a/Tests/Integration/MSFT_Language.config.ps1 +++ b/Tests/Integration/MSFT_Language.config.ps1 @@ -1,19 +1,42 @@ # Integration Test Config Template Version: 1.0.0 configuration MSFT_Language_Config { - + Param + ( + [Parameter(Mandatory=$true)] + [Int] + $LocationID, + [Parameter(Mandatory=$true)] + [String] + $MUILanguage, + [Parameter(Mandatory=$true)] + [String] + $MUIFallbackLanguage, + [Parameter(Mandatory=$true)] + [String] + $SystemLocale, + [Parameter(Mandatory=$true)] + [String] + $AddInputLanguages, + [Parameter(Mandatory=$true)] + [String] + $RemoveInputLanguages, + [Parameter(Mandatory=$true)] + [String] + $UserLocale + ) Import-DscResource -ModuleName LanguageDsc node localhost { Language Integration_Test { IsSingleInstance = "Yes" - LocationID = 242 - MUILanguage = "en-GB" - MUIFallbackLanguage = "en-US" - SystemLocale = "en-GB" - AddInputLanguages = @("0809:00000809") - RemoveInputLanguages = @("0409:00000409") - UserLocale = "en-GB" + LocationID = $LocationID + MUILanguage = $MUILanguage + MUIFallbackLanguage = $MUIFallbackLanguage + SystemLocale = $SystemLocale + AddInputLanguages = $AddInputLanguages + RemoveInputLanguages = $RemoveInputLanguages + UserLocale = $UserLocale CopySystem = $true CopyNewUser = $true } diff --git a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 index a6b308c..c8bca67 100644 --- a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 @@ -17,21 +17,87 @@ $TestEnvironment = Initialize-TestEnvironment ` -TestType Integration #endregion - -# TODO: Other Init Code Goes Here... +Import-Module "$script:moduleRoot\DSCResources\$script:DSCResourceName\$script:DSCResourceName.psm1" # Using try/finally to always cleanup. try { - #region Integration Tests + $LanguagePackFolderLocation = "c:\LanguagePacks\" + $LanguagePackFileLocation = "c:\LanguagePacks\x64fre_Server_de-de_lp.cab" + $NewLanguagePackFromFolder = 'en-GB' + $NewLanguagePackFromFile = 'de-DE' + $RemoveLanguagePack = 'en-GB' + + Describe "Pre-flight Checks" { + + Context "Ensure Language Binaries are available" { + It "Language Pack Folder $LanguagePackFolderLocation Exists" { + Test-Path -Path $LanguagePackFolderLocation -PathType Container | Should Be $true + } + + It "Language Pack Folder must include at least 1 cab file" { + (Get-ChildItem -Path $LanguagePackFolderLocation -Filter "*.cab").count | Should BeGreaterThan 0 + } + + It "Language Pack File Location must be a cab file" { + $LanguagePackFileLocation.EndsWith(".cab") | Should Be $true + } + + It "Language Pack File Location must exist" { + Test-Path -Path $LanguagePackFileLocation -PathType Leaf | Should Be $true + } + } + + + Context "Ensure System requires modification" { + It "New Language Pack $NewLanguagePackFromFolder mustn't be installed" { + $CurrentState = Get-TargetResource -LanguagePackName $NewLanguagePackFromFolder + $CurrentState.ensure | Should Be "Absent" + } + + It "New Language Pack $NewLanguagePackFromFile mustn't be installed" { + $CurrentState = Get-TargetResource -LanguagePackName $NewLanguagePackFromFile + $CurrentState.ensure | Should Be "Absent" + } + + It "Language Pack to be removed $RemoveLanguagePack must be installed" { + $CurrentState = Get-TargetResource -LanguagePackName $RemoveLanguagePack + $CurrentState.ensure | Should Be "Present" + } + } + } + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" - . $configFile + . $configFile + + #region Integration Tests + Describe "$($script:DSCResourceName) Folder Install Integration" -Tag "Integration" { + #region DEFAULT TESTS + It "Should compile and apply the MOF without throwing" { + { + Write-Verbose "Run Config" -Verbose:$true + & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive -LangaugePackName $NewLanguagePackFromFolder -LangaugePackLocation $LanguagePackFolderLocation -Ensure "Present" + Start-DscConfiguration -Path $TestDrive ` + -ComputerName localhost -Wait -Verbose -Force + } | Should not throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw + } + #endregion + + It 'Should have installed the language Pack' { + $currentConfig = Get-TargetResource -LanguagePackName $NewLanguagePackFromFolder -Verbose + $currentConfig.Ensure | Should Be $true + } + } - Describe "$($script:DSCResourceName)_Integration" -Tag "Integration" { + Describe "$($script:DSCResourceName) File Install Integration" -Tag "Integration" { #region DEFAULT TESTS It 'Should compile and apply the MOF without throwing' { { - & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive + & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive -LangaugePackName $NewLanguagePackFromFile -LangaugePackLocation $LanguagePackFileLocation -Ensure "Present" Start-DscConfiguration -Path $TestDrive ` -ComputerName localhost -Wait -Verbose -Force } | Should not throw @@ -41,15 +107,34 @@ try { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw } #endregion - InModuleScope 'MSFT_Language' { - It 'Should have set the resource and all the parameters should match' { - $currentConfig = Get-TargetResource -LanguagePackName "en-GB" -Verbose - $currentConfig.Ensure | Should Be $true - } + + It 'Should have installed the language Pack' { + $currentConfig = Get-TargetResource -LanguagePackName $NewLanguagePackFromFile -Verbose + $currentConfig.Ensure | Should Be $true } } - #endregion + Describe "$($script:DSCResourceName) Language Pack Uninstall Integration" -Tag "Integration" { + #region DEFAULT TESTS + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:DSCResourceName)_Config" -OutputPath $TestDrive -LangaugePackName $RemoveLanguagePack -Ensure "Absent" + Start-DscConfiguration -Path $TestDrive ` + -ComputerName localhost -Wait -Verbose -Force + } | Should not throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw + } + #endregion + + It 'Should have removed the language Pack' { + $currentConfig = Get-TargetResource -LanguagePackName $RemoveLanguagePack -Verbose + $currentConfig.Ensure | Should Be $false + } + } + #endregion } finally { diff --git a/Tests/Integration/MSFT_LanguagePack.config.ps1 b/Tests/Integration/MSFT_LanguagePack.config.ps1 index 2829291..047e133 100644 --- a/Tests/Integration/MSFT_LanguagePack.config.ps1 +++ b/Tests/Integration/MSFT_LanguagePack.config.ps1 @@ -1,14 +1,27 @@ # Integration Test Config Template Version: 1.0.0 configuration MSFT_LanguagePack_Config { + Param + ( + [Parameter(Mandatory=$true)] + [String] + $LangaugePackName, + [Parameter(Mandatory=$false)] + [String] + $LangaugePackLocation, + [Parameter(Mandatory=$true)] + [ValidateSet("Present","Absent")] + [String] + $Ensure + ) Import-DscResource -ModuleName LanguageDsc node localhost { LanguagePack Integration_Test { - LanguagePackName = "De-DE" - LanguagePackLocation = "C:\Temp\x64fre_Server_de-de_lp.cab" - Ensure = "Present" + LanguagePackName = $LangaugePackName + LanguagePackLocation = $LangaugePackLocation + Ensure = $Ensure } } } From a83512645252f665ad919561b701fb8e536a9848 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 09:38:22 +0000 Subject: [PATCH 07/17] Updated to fix PAAS guideline errors --- .../MSFT_LanguagePack/MSFT_LanguagePack.psm1 | 14 ++++++++------ README.md | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 index eac11f7..5c2e2d6 100644 --- a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 +++ b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 @@ -71,17 +71,18 @@ Function Set-TargetResource [System.String] $LanguagePackName, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $LanguagePackLocation, - [Parameter(Mandatory = $false)] + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure="Present" ) - switch ($Ensure) { + switch ($Ensure) + { 'Present' { if ($PSBoundParameters.ContainsKey('LanguagePackLocation')) { @@ -145,11 +146,11 @@ Function Test-TargetResource [System.String] $LanguagePackName, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $LanguagePackLocation, - [Parameter(Mandatory = $false)] + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure="Present" @@ -163,7 +164,8 @@ Function Test-TargetResource Write-Verbose "Language Pack Found: $Found" - switch ($Ensure) { + switch ($Ensure) + { 'Present' { $result = $Found } diff --git a/README.md b/README.md index 0b4fcbe..7b09839 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ This resource will install or remove a single language pack from the target syst * LanguagePack ## How to Test + This resource is configured to exclude integration tests from its automated testing utilizing appveyor. This is due to the external dependencies required for the langagePack Resource. To configure a valid testing environment the following prerequisites are required: + * Windows Server Operating System with en-US language installed * Git for Windows * C:\LanguagePacks must exist From aee149943a95e90634dddb10e31ca717157ecacc Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 10:12:25 +0000 Subject: [PATCH 08/17] Updated Language.psm1 to follow PSSA guidelines and updated build script to download required binaries for integration testing --- DSCResources/MSFT_Language/MSFT_Language.psm1 | 36 +++++++++---------- appveyor.yml | 33 +++++++++++++++++ 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/DSCResources/MSFT_Language/MSFT_Language.psm1 b/DSCResources/MSFT_Language/MSFT_Language.psm1 index 09bfe54..8ee9f7e 100644 --- a/DSCResources/MSFT_Language/MSFT_Language.psm1 +++ b/DSCResources/MSFT_Language/MSFT_Language.psm1 @@ -133,39 +133,39 @@ Function Set-TargetResource [System.String] $IsSingleInstance, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Int32] $LocationID, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $MUILanguage, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $MUIFallbackLanguage, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $SystemLocale, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String[]] $AddInputLanguages, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String[]] $RemoveInputLanguages, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $UserLocale, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Boolean] $CopySystem =$true, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Boolean] $CopyNewUser=$true ) @@ -345,41 +345,41 @@ Function Test-TargetResource [System.String] $IsSingleInstance, - [Parameter(Mandatory = $false)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.Int32] $LocationID, - [Parameter(Mandatory = $false)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] $MUILanguage, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $MUIFallbackLanguage, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $SystemLocale, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String[]] $AddInputLanguages, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String[]] $RemoveInputLanguages, - [Parameter(Mandatory = $false)] + [Parameter()] [System.String] $UserLocale, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Boolean] $CopySystem, - [Parameter(Mandatory = $false)] + [Parameter()] [System.Boolean] $CopyNewUser ) diff --git a/appveyor.yml b/appveyor.yml index 2f488bf..4143cfe 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,6 +7,39 @@ # environment configuration # #---------------------------------# version: 1.0.{build}.0 # TODO Modify version + +image: Visual Studio 2017 +init: +#init script to download binaries required for integration testing +- ps: >- + $LanguagePackFolderLocation = "c:\LanguagePacks\" + + $LanguagePackFileLocation = "c:\LanguagePacks\x64fre_Server_de-de_lp.cab" + + $StorageAccountName = "languageddsctesting" + + $ContainerName = "intergrationtesting" + + + New-Item -Path $LanguagePackFolderLocation -ItemType Directory + + $RESTResult = Invoke-RestMethod "https://$StorageAccountName.blob.core.windows.net/$($ContainerName)?restype=container&comp=list" -Method Get + + [XML]$RESTResult = $RESTResult.Substring(3) #trim random chars off front + + [XML]$XMLResult = $RESTResult + + $reader=(New-Object System.Xml.XmlNodeReader $RESTResult) + + + foreach ($Blob in $XMLResult.EnumerationResults.Blobs.GetEnumerator()) + + { + $OutputFile = Join-Path -Path $LanguagePackFolderLocation -ChildPath $Blob.Name + (New-Object System.Net.WebClient).DownloadFile($Blob.Url, $OutputFile) + } + + install: - git clone https://github.com/PowerShell/DscResource.Tests - ps: Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" From 528d807443bace142a65919ff3894f3126821a1c Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 10:18:17 +0000 Subject: [PATCH 09/17] Updated integration preflight checks with the integration tag for exclusion, removed exclusion from appveyor build --- Tests/Integration/MSFT_Language.Integration.Tests.ps1 | 2 +- Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 | 2 +- appveyor.yml | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/Integration/MSFT_Language.Integration.Tests.ps1 b/Tests/Integration/MSFT_Language.Integration.Tests.ps1 index e4c4445..5b6ccdd 100644 --- a/Tests/Integration/MSFT_Language.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Language.Integration.Tests.ps1 @@ -31,7 +31,7 @@ try $RemoveInputLanguages = "0409:00000409" $UserLocale = "en-GB" - Describe "Pre-flight Checks" { + Describe "Pre-flight Checks" -Tag "Integration" { Context "Ensure System requires modification" { $CurrentState = Get-TargetResource -IsSingleInstance "Yes" It "LocationID requires modification" { diff --git a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 index c8bca67..a9a299b 100644 --- a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 @@ -28,7 +28,7 @@ try $NewLanguagePackFromFile = 'de-DE' $RemoveLanguagePack = 'en-GB' - Describe "Pre-flight Checks" { + Describe "Pre-flight Checks" -Tag "Integration" { Context "Ensure Language Binaries are available" { It "Language Pack Folder $LanguagePackFolderLocation Exists" { diff --git a/appveyor.yml b/appveyor.yml index 4143cfe..626f732 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -57,7 +57,8 @@ build: false test_script: - ps: | - Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "Integration" -Verbose + Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -Verbose + #Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "Integration" -Verbose #---------------------------------# # deployment configuration # From 6c871fac06a7ca155c3dd040e70346a1e5d908e3 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 10:43:05 +0000 Subject: [PATCH 10/17] Added Artifact for PowerShell Gallery Module deployment, fixed LangaugePack removal time bug, fixed languagePack tests failing as result should be "Absent / Present" not $true / $false --- .../MSFT_LanguagePack/MSFT_LanguagePack.psm1 | 6 ++++++ .../MSFT_LanguagePack.Integration.Tests.ps1 | 8 ++++---- appveyor.yml | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 index 5c2e2d6..9258a0e 100644 --- a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 +++ b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 @@ -80,6 +80,7 @@ Function Set-TargetResource [System.String] $Ensure="Present" ) + $timeout = 7200 switch ($Ensure) { @@ -105,6 +106,7 @@ Function Set-TargetResource 'Absent' { Write-Verbose "Removing Language Pack" lpksetup.exe /u $LanguagePackName /r /a /s + $startTime = Get-Date } default { Throw "invalid operation" @@ -114,6 +116,10 @@ Function Set-TargetResource { $Process = Get-Process -Name "lpksetup" -ErrorAction SilentlyContinue $currentTime = (Get-Date) - $startTime + if ($currentTime.TotalSeconds -gt $timeout) + { + throw "Process did not complete in under $timeout seconds" + } Write-Verbose "Waiting for Process to finish. Time Taken: $($currentTime)" Start-Sleep -Seconds 10 } while ($null -ne $Process) diff --git a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 index a9a299b..5ef0c38 100644 --- a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 @@ -26,7 +26,7 @@ try $LanguagePackFileLocation = "c:\LanguagePacks\x64fre_Server_de-de_lp.cab" $NewLanguagePackFromFolder = 'en-GB' $NewLanguagePackFromFile = 'de-DE' - $RemoveLanguagePack = 'en-GB' + $RemoveLanguagePack = 'en-US' Describe "Pre-flight Checks" -Tag "Integration" { @@ -89,7 +89,7 @@ try It 'Should have installed the language Pack' { $currentConfig = Get-TargetResource -LanguagePackName $NewLanguagePackFromFolder -Verbose - $currentConfig.Ensure | Should Be $true + $currentConfig.Ensure | Should Be "Present" } } @@ -110,7 +110,7 @@ try It 'Should have installed the language Pack' { $currentConfig = Get-TargetResource -LanguagePackName $NewLanguagePackFromFile -Verbose - $currentConfig.Ensure | Should Be $true + $currentConfig.Ensure | Should Be "Present" } } @@ -131,7 +131,7 @@ try It 'Should have removed the language Pack' { $currentConfig = Get-TargetResource -LanguagePackName $RemoveLanguagePack -Verbose - $currentConfig.Ensure | Should Be $false + $currentConfig.Ensure | Should Be "Absent" } } #endregion diff --git a/appveyor.yml b/appveyor.yml index 626f732..ea98935 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -68,3 +68,20 @@ test_script: deploy_script: - ps: | Invoke-AppveyorAfterTestTask + + +#---------------------------------# +# artifact configuration # +#---------------------------------# + +after_build: +- cmd: >- + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\DSCResources\* + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\Examples\* + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LanguageDsc.psd1 + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LICENSE + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\README.md + +artifacts: +- path: LanguageDsc.zip + name: LanguageDsc.zip \ No newline at end of file From 5fafdd7e10241d15ce66c530cbc09e16b65d86f9 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 11:11:23 +0000 Subject: [PATCH 11/17] Excluded integration tests which require a reboot to test positive --- Tests/Integration/MSFT_Language.Integration.Tests.ps1 | 2 +- Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 | 2 +- appveyor.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Integration/MSFT_Language.Integration.Tests.ps1 b/Tests/Integration/MSFT_Language.Integration.Tests.ps1 index 5b6ccdd..de2d74e 100644 --- a/Tests/Integration/MSFT_Language.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Language.Integration.Tests.ps1 @@ -74,7 +74,7 @@ try $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" . $configFile - Describe "$($script:DSCResourceName)_Integration" -Tag "Integration" { + Describe "$($script:DSCResourceName)_Integration" -Tag "Integration","RebootRequired" { #region DEFAULT TESTS It 'Should compile and apply the MOF without throwing' { { diff --git a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 index 5ef0c38..0471507 100644 --- a/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_LanguagePack.Integration.Tests.ps1 @@ -114,7 +114,7 @@ try } } - Describe "$($script:DSCResourceName) Language Pack Uninstall Integration" -Tag "Integration" { + Describe "$($script:DSCResourceName) Language Pack Uninstall Integration" -Tag "Integration","RebootRequired" { #region DEFAULT TESTS It 'Should compile and apply the MOF without throwing' { { diff --git a/appveyor.yml b/appveyor.yml index ea98935..8b4c43c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -57,7 +57,7 @@ build: false test_script: - ps: | - Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -Verbose + Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "RebootRequired" -Verbose #Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "Integration" -Verbose #---------------------------------# @@ -84,4 +84,4 @@ after_build: artifacts: - path: LanguageDsc.zip - name: LanguageDsc.zip \ No newline at end of file + name: LanguageDsc.zip From 52f04cc75932f5b5403ac1586245e6f9fd94dd3a Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 11:36:34 +0000 Subject: [PATCH 12/17] Moved post testing artifact creation to deployment configuration --- appveyor.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 8b4c43c..90c06e7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -66,6 +66,12 @@ test_script: # scripts to run before deployment deploy_script: + - cmd: >- + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\DSCResources\* + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\Examples\* + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LanguageDsc.psd1 + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LICENSE + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\README.md - ps: | Invoke-AppveyorAfterTestTask @@ -74,14 +80,6 @@ deploy_script: # artifact configuration # #---------------------------------# -after_build: -- cmd: >- - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\DSCResources\* - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\Examples\* - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LanguageDsc.psd1 - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LICENSE - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\README.md - artifacts: - path: LanguageDsc.zip - name: LanguageDsc.zip + name: LanguageDsc From 8fe198e13b18ee02a5a4b0802bb3d1a8ebc59d8e Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 12:58:46 +0000 Subject: [PATCH 13/17] Moved Module zip creation into testing section to ensure it runs before artifact upload --- appveyor.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 90c06e7..e4219d7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -59,6 +59,12 @@ test_script: - ps: | Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "RebootRequired" -Verbose #Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "Integration" -Verbose + - cmd: >- + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\DSCResources\* -r + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\Examples\* -r + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LanguageDsc.psd1 + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LICENSE + 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\README.md #---------------------------------# # deployment configuration # @@ -66,12 +72,6 @@ test_script: # scripts to run before deployment deploy_script: - - cmd: >- - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\DSCResources\* - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\Examples\* - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LanguageDsc.psd1 - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LICENSE - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\README.md - ps: | Invoke-AppveyorAfterTestTask From 4096485ab4d913a796e7fc77f881f4beaa833933 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 13:12:38 +0000 Subject: [PATCH 14/17] Made Module creation into multiple commands to avoid errors relating to multiple recursive folders --- appveyor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index e4219d7..5534794 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -61,9 +61,13 @@ test_script: #Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "Integration" -Verbose - cmd: >- 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\DSCResources\* -r + - cmd: >- 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\Examples\* -r + - cmd: >- 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LanguageDsc.psd1 + - cmd: >- 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LICENSE + - cmd: >- 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\README.md #---------------------------------# From 7f9e0191e868e5e608ecf4e908a7fa42c6111116 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 15:11:09 +0000 Subject: [PATCH 15/17] Changed module package source to relative pathing to preserve folder structure in zip file --- appveyor.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5534794..bc38f09 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -60,15 +60,15 @@ test_script: Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "RebootRequired" -Verbose #Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag "Integration" -Verbose - cmd: >- - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\DSCResources\* -r + 7z a LanguageDsc.zip DSCResources\* -r - cmd: >- - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\Examples\* -r + 7z a LanguageDsc.zip Examples\* -r - cmd: >- - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LanguageDsc.psd1 + 7z a LanguageDsc.zip LanguageDsc.psd1 - cmd: >- - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\LICENSE + 7z a LanguageDsc.zip LICENSE - cmd: >- - 7z a LanguageDsc.zip %APPVEYOR_BUILD_FOLDER%\README.md + 7z a LanguageDsc.zip README.md #---------------------------------# # deployment configuration # From 1f33aa7bce5f7fab215297c21584d4ef788f22ab Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 29 Oct 2017 15:45:16 +0000 Subject: [PATCH 16/17] Updated Module Metadata --- LanguageDsc.psd1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/LanguageDsc.psd1 b/LanguageDsc.psd1 index 0e675ab..cdfed82 100644 --- a/LanguageDsc.psd1 +++ b/LanguageDsc.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '1.0' +ModuleVersion = '1.0.0.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -30,7 +30,7 @@ CompanyName = "Leo D'Arcy" Copyright = "(c) 2017 Leo D'Arcy. All rights reserved." # Description of the functionality provided by this module -# Description = '' + Description = 'DSC Module for managing the installation and removal of language packs and setting language settings on Windows operating systems' # Minimum version of the Windows PowerShell engine required by this module PowerShellVersion = '4.0' @@ -75,7 +75,7 @@ FunctionsToExport = @() CmdletsToExport = @() # Variables to export from this module -VariablesToExport = '*' +VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. AliasesToExport = @() @@ -95,19 +95,19 @@ PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() + Tags = @("Language", "LanguageDSC", "LanguagePack", "DSC", "DesiredStateConfiguration", "DSCResource") # A URL to the license for this module. - # LicenseUri = '' + LicenseUri = 'https://github.com/ld0614/LanguageDsc/blob/master/LICENSE' # A URL to the main website for this project. - # ProjectUri = '' + ProjectUri = 'https://github.com/ld0614/LanguageDsc' # A URL to an icon representing this module. # IconUri = '' # ReleaseNotes of this module - # ReleaseNotes = '' + ReleaseNotes = 'Initial Release of LanguageDSC Module containing Language and LanguagePack resources' } # End of PSData hashtable From df4ded7f99fe25404e0d541c17329743aebde2e7 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Sun, 17 Dec 2017 11:50:26 +0000 Subject: [PATCH 17/17] Added SuppressReboot parameter to LanguagePack resource. --- .../MSFT_LanguagePack/MSFT_LanguagePack.psm1 | 29 +++++++++++++++++-- .../MSFT_LanguagePack.schema.mof | 1 + LanguageDsc.psd1 | 2 +- ModuleCreation.ps1 | 3 +- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 index 9258a0e..6f8dfe5 100644 --- a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 +++ b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.psm1 @@ -9,6 +9,9 @@ .PARAMETER LanguagePackLocation Not used in Get-TargetResource. + .PARAMETER SuppressReboot + Not used in Get-TargetResource. + .PARAMETER Ensure Not used in Get-TargetResource. #> @@ -39,6 +42,7 @@ Function Get-TargetResource $returnValue = @{ LanguagePackName = [System.String]$LanguagePackName + SuppressReboot = [Boolean]$false Ensure = [System.String]$ensure } @@ -56,6 +60,10 @@ Function Get-TargetResource Either Local or Remote path to the language pack cab file. This is only used when installing a language pack + .PARAMETER SuppressReboot + If set to true the reboot required flag isn't set after successful installation of a + language pack, this can be useful to save time when installing multiple language packs. + .PARAMETER Ensure Indicates whether the given language pack should be installed or uninstalled. Set this property to Present to install the Language Pack, and Absent to uninstall @@ -75,6 +83,10 @@ Function Set-TargetResource [System.String] $LanguagePackLocation, + [Parameter()] + [Boolean] + $SuppressReboot=$false, + [Parameter()] [ValidateSet("Present","Absent")] [System.String] @@ -123,8 +135,13 @@ Function Set-TargetResource Write-Verbose "Waiting for Process to finish. Time Taken: $($currentTime)" Start-Sleep -Seconds 10 } while ($null -ne $Process) - #Force a reboot after installing or removing a language pack - $global:DSCMachineStatus = 1 + + #allow for suppression to install multiple language packs at the same time to save time + if ($SuppressReboot -ne $true) + { + #Force a reboot after installing or removing a language pack + $global:DSCMachineStatus = 1 + } } <# @@ -137,6 +154,10 @@ Function Set-TargetResource .PARAMETER LanguagePackLocation Not used in Test-TargetResource. + .PARAMETER SuppressReboot + If set to true the reboot required flag isn't set after successful installation of a + language pack, this can be useful to save time when installing multiple language packs. + .PARAMETER Ensure Indicates whether the given language pack should be present or absent. Set this property to Present to install the Language Pack, and Absent to uninstall @@ -155,6 +176,10 @@ Function Test-TargetResource [Parameter()] [System.String] $LanguagePackLocation, + + [Parameter()] + [Boolean] + $SuppressReboot=$false, [Parameter()] [ValidateSet("Present","Absent")] diff --git a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.schema.mof b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.schema.mof index 748bf85..17ad9da 100644 --- a/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.schema.mof +++ b/DSCResources/MSFT_LanguagePack/MSFT_LanguagePack.schema.mof @@ -4,6 +4,7 @@ class MSFT_LanguagePack : OMI_BaseResource { [Key] String LanguagePackName; [Write] String LanguagePackLocation; + [Write] Boolean SuppressReboot; [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; }; diff --git a/LanguageDsc.psd1 b/LanguageDsc.psd1 index cdfed82..76da642 100644 --- a/LanguageDsc.psd1 +++ b/LanguageDsc.psd1 @@ -81,7 +81,7 @@ VariablesToExport = @() AliasesToExport = @() # DSC resources to export from this module -# DscResourcesToExport = @() +DscResourcesToExport = @('Language', 'LanguagePack') # List of all modules packaged with this module # ModuleList = @() diff --git a/ModuleCreation.ps1 b/ModuleCreation.ps1 index 36cb202..f5a99bd 100644 --- a/ModuleCreation.ps1 +++ b/ModuleCreation.ps1 @@ -1,5 +1,6 @@ $LanguagePackName = New-xDscResourceProperty -Name "LanguagePackName" -Type String -Attribute Key $LanguagePackLocation = New-xDscResourceProperty -Name "LanguagePackLocation" -Type String -Attribute Write +$SuppressReboot = New-xDscResourceProperty -Name "SuppressReboot" -Type Boolean -Attribute Write $Ensure = New-xDscResourceProperty –Name Ensure -Type String -Attribute Write –ValidateSet “Present”, “Absent” $IsSingleInstance = New-xDscResourceProperty -Name "IsSingleInstance" -Type String -Attribute Key -ValidateSet “Yes” @@ -14,6 +15,6 @@ $CopySystem = New-xDscResourceProperty -Name "CopySystem" -Type Boolean -Attribu $CopyNewUser = New-xDscResourceProperty -Name "CopyNewUser" -Type Boolean -Attribute Write $CurrentInstalledLanguages = New-xDscResourceProperty -Name CurrentInstalledLanguages -Type Hashtable -Attribute Read -New-xDscResource -Name "MSFT_LanguagePack" -FriendlyName "LanguagePack" -Property $LanguagePackName, $LanguagePackLocation, $Ensure -Path "C:\Temp\DSCResources" -ModuleName "LanguageDsc" +New-xDscResource -Name "MSFT_LanguagePack" -FriendlyName "LanguagePack" -Property $LanguagePackName, $LanguagePackLocation, $SuppressReboot, $Ensure -Path "C:\Temp\DSCResources" -ModuleName "LanguageDsc" New-xDscResource -Name "MSFT_Language" -FriendlyName "Language" -Property $IsSingleInstance, $LocationID, $MUILanguage, $MUIFallbackLanguage, $SystemLocale, $AddInputLanguages, $RemoveInputLanguages, $UserLocale, $CopySystem, $CopyNewUser, $CurrentInstalledLanguages -Path "C:\Temp\DSCResources" -ModuleName "LanguageDsc"