summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/incidental_win_dsc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:03:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:03:01 +0000
commita453ac31f3428614cceb99027f8efbdb9258a40b (patch)
treef61f87408f32a8511cbd91799f9cececb53e0374 /test/integration/targets/incidental_win_dsc
parentInitial commit. (diff)
downloadansible-upstream.tar.xz
ansible-upstream.zip
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/incidental_win_dsc')
-rw-r--r--test/integration/targets/incidental_win_dsc/aliases6
-rw-r--r--test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xSetReboot/ANSIBLE_xSetReboot.psm141
-rw-r--r--test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xSetReboot/ANSIBLE_xSetReboot.schema.mof7
-rw-r--r--test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1214
-rw-r--r--test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.schema.mof60
-rw-r--r--test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/xTestDsc.psd113
-rw-r--r--test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1214
-rw-r--r--test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.schema.mof63
-rw-r--r--test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/xTestDsc.psd113
-rw-r--r--test/integration/targets/incidental_win_dsc/meta/main.yml2
-rw-r--r--test/integration/targets/incidental_win_dsc/tasks/main.yml39
-rw-r--r--test/integration/targets/incidental_win_dsc/tasks/tests.yml544
12 files changed, 1216 insertions, 0 deletions
diff --git a/test/integration/targets/incidental_win_dsc/aliases b/test/integration/targets/incidental_win_dsc/aliases
new file mode 100644
index 00000000..9114c742
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/aliases
@@ -0,0 +1,6 @@
+shippable/windows/incidental
+windows
+skip/windows/2008
+skip/windows/2008-R2
+skip/windows/2012
+skip/windows/2012-R2
diff --git a/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xSetReboot/ANSIBLE_xSetReboot.psm1 b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xSetReboot/ANSIBLE_xSetReboot.psm1
new file mode 100644
index 00000000..dbf1ecf3
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xSetReboot/ANSIBLE_xSetReboot.psm1
@@ -0,0 +1,41 @@
+#Requires -Version 5.0 -Modules CimCmdlets
+
+Function Get-TargetResource
+{
+ [CmdletBinding()]
+ [OutputType([Hashtable])]
+ param(
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [String]$KeyParam
+ )
+ return @{Value = [bool]$global:DSCMachineStatus}
+}
+
+Function Set-TargetResource
+{
+ [CmdletBinding()]
+ param (
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [String]$KeyParam,
+ [Bool]$Value = $true
+ )
+ $global:DSCMachineStatus = [int]$Value
+}
+
+Function Test-TargetResource
+{
+ [CmdletBinding()]
+ [OutputType([Boolean])]
+ param (
+ [Parameter(Mandatory=$true)]
+ [ValidateNotNullOrEmpty()]
+ [String]$KeyParam,
+ [Bool]$Value = $true
+ )
+ $false
+}
+
+Export-ModuleMember -Function *-TargetResource
+
diff --git a/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xSetReboot/ANSIBLE_xSetReboot.schema.mof b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xSetReboot/ANSIBLE_xSetReboot.schema.mof
new file mode 100644
index 00000000..288b8877
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xSetReboot/ANSIBLE_xSetReboot.schema.mof
@@ -0,0 +1,7 @@
+[ClassVersion("1.0.0"), FriendlyName("xSetReboot")]
+class ANSIBLE_xSetReboot : OMI_BaseResource
+{
+ [Key] String KeyParam;
+ [Write] Boolean Value;
+};
+
diff --git a/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1 b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1
new file mode 100644
index 00000000..79f64969
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1
@@ -0,0 +1,214 @@
+#Requires -Version 5.0 -Modules CimCmdlets
+
+Function ConvertFrom-CimInstance {
+ param(
+ [Parameter(Mandatory=$true)][CimInstance]$Instance
+ )
+ $hashtable = @{
+ _cim_instance = $Instance.CimSystemProperties.ClassName
+ }
+ foreach ($prop in $Instance.CimInstanceProperties) {
+ $hashtable."$($prop.Name)" = ConvertTo-OutputValue -Value $prop.Value
+ }
+ return $hashtable
+}
+
+Function ConvertTo-OutputValue {
+ param($Value)
+
+ if ($Value -is [DateTime[]]) {
+ $Value = $Value | ForEach-Object { $_.ToString("o") }
+ } elseif ($Value -is [DateTime]) {
+ $Value = $Value.ToString("o")
+ } elseif ($Value -is [Double]) {
+ $Value = $Value.ToString() # To avoid Python 2 double parsing issues on test validation
+ } elseif ($Value -is [Double[]]) {
+ $Value = $Value | ForEach-Object { $_.ToString() }
+ } elseif ($Value -is [PSCredential]) {
+ $password = $null
+ $password_ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode($Value.Password)
+ try {
+ $password = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($password_ptr)
+ } finally {
+ [System.Runtime.InteropServices.Marshal]::ZeroFreeGlobalAllocUnicode($password_ptr)
+ }
+ $Value = @{
+ username = $Value.Username
+ password = $password
+ }
+ } elseif ($Value -is [CimInstance[]]) {
+ $value_list = [System.Collections.Generic.List`1[Hashtable]]@()
+ foreach ($cim_instance in $Value) {
+ $value_list.Add((ConvertFrom-CimInstance -Instance $cim_instance))
+ }
+ $Value = $value_list.ToArray()
+ } elseif ($Value -is [CimInstance]) {
+ $Value = ConvertFrom-CimInstance -Instance $Value
+ }
+
+ return ,$Value
+}
+
+Function Get-TargetResource
+{
+ [CmdletBinding()]
+ [OutputType([Hashtable])]
+ param(
+ [Parameter(Mandatory = $true)]
+ [ValidateSet("Present", "Absent")]
+ [String] $Ensure = "Present",
+
+ [Parameter(Mandatory = $true)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Path
+ )
+ return @{
+ Ensure = $Ensure
+ Path = $Path
+ }
+}
+
+Function Set-TargetResource
+{
+ [CmdletBinding()]
+ param
+ (
+ [Parameter(Mandatory = $true)]
+ [ValidateSet("Present", "Absent")]
+ [String] $Ensure = "Present",
+
+ [Parameter(Mandatory = $true)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Path,
+
+ [String] $DefaultParam = "Default",
+ [String] $StringParam,
+ [String[]] $StringArrayParam,
+ [SByte] $Int8Param,
+ [SByte[]] $Int8ArrayParam,
+ [Byte] $UInt8Param,
+ [Byte[]] $UInt8ArrayParam,
+ [Int16] $Int16Param,
+ [Int16[]] $Int16ArrayParam,
+ [UInt16] $UInt16Param,
+ [UInt16[]] $UInt16ArrayParam,
+ [Int32] $Int32Param,
+ [Int32[]] $Int32ArrayParam,
+ [UInt32] $UInt32Param,
+ [UInt32[]] $UInt32ArrayParam,
+ [Int64] $Int64Param,
+ [Int64[]] $Int64ArrayParam,
+ [UInt64] $UInt64Param,
+ [UInt64[]] $UInt64ArrayParam,
+ [Bool] $BooleanParam,
+ [Bool[]] $BooleanArrayParam,
+ [Char] $CharParam,
+ [Char[]] $CharArrayParam,
+ [Single] $SingleParam,
+ [Single[]] $SingleArrayParam,
+ [Double] $DoubleParam,
+ [Double[]] $DoubleArrayParam,
+ [DateTime] $DateTimeParam,
+ [DateTime[]] $DateTimeArrayParam,
+ [PSCredential] $PSCredentialParam,
+ [CimInstance[]] $HashtableParam,
+ [CimInstance] $CimInstanceParam,
+ [CimInstance[]] $CimInstanceArrayParam,
+ [CimInstance] $NestedCimInstanceParam,
+ [CimInstance[]] $NestedCimInstanceArrayParam
+ )
+
+ $info = @{
+ Version = "1.0.0"
+ Ensure = @{
+ Type = $Ensure.GetType().FullName
+ Value = $Ensure
+ }
+ Path = @{
+ Type = $Path.GetType().FullName
+ Value = $Path
+ }
+ DefaultParam = @{
+ Type = $DefaultParam.GetType().FullName
+ Value = $DefaultParam
+ }
+ }
+
+ foreach ($kvp in $PSCmdlet.MyInvocation.BoundParameters.GetEnumerator()) {
+ $info."$($kvp.Key)" = @{
+ Type = $kvp.Value.GetType().FullName
+ Value = (ConvertTo-OutputValue -Value $kvp.Value)
+ }
+ }
+
+ if (Test-Path -Path $Path) {
+ Remove-Item -Path $Path -Force > $null
+ }
+ New-Item -Path $Path -ItemType File > $null
+ Set-Content -Path $Path -Value (ConvertTo-Json -InputObject $info -Depth 10) > $null
+ Write-Verbose -Message "set verbose"
+ Write-Warning -Message "set warning"
+}
+
+Function Test-TargetResource
+{
+ [CmdletBinding()]
+ [OutputType([Boolean])]
+ param
+ (
+ [Parameter(Mandatory = $true)]
+ [ValidateSet("Present", "Absent")]
+ [String] $Ensure = "Present",
+
+ [Parameter(Mandatory = $true)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Path,
+
+ [String] $DefaultParam = "Default",
+ [String] $StringParam,
+ [String[]] $StringArrayParam,
+ [SByte] $Int8Param,
+ [SByte[]] $Int8ArrayParam,
+ [Byte] $UInt8Param,
+ [Byte[]] $UInt8ArrayParam,
+ [Int16] $Int16Param,
+ [Int16[]] $Int16ArrayParam,
+ [UInt16] $UInt16Param,
+ [UInt16[]] $UInt16ArrayParam,
+ [Int32] $Int32Param,
+ [Int32[]] $Int32ArrayParam,
+ [UInt32] $UInt32Param,
+ [UInt32[]] $UInt32ArrayParam,
+ [Int64] $Int64Param,
+ [Int64[]] $Int64ArrayParam,
+ [UInt64] $UInt64Param,
+ [UInt64[]] $UInt64ArrayParam,
+ [Bool] $BooleanParam,
+ [Bool[]] $BooleanArrayParam,
+ [Char] $CharParam,
+ [Char[]] $CharArrayParam,
+ [Single] $SingleParam,
+ [Single[]] $SingleArrayParam,
+ [Double] $DoubleParam,
+ [Double[]] $DoubleArrayParam,
+ [DateTime] $DateTimeParam,
+ [DateTime[]] $DateTimeArrayParam,
+ [PSCredential] $PSCredentialParam,
+ [CimInstance[]] $HashtableParam,
+ [CimInstance] $CimInstanceParam,
+ [CimInstance[]] $CimInstanceArrayParam,
+ [CimInstance] $NestedCimInstanceParam,
+ [CimInstance[]] $NestedCimInstanceArrayParam
+ )
+ Write-Verbose -Message "test verbose"
+ Write-Warning -Message "test warning"
+ $exists = Test-Path -LiteralPath $Path -PathType Leaf
+ if ($Ensure -eq "Present") {
+ $exists
+ } else {
+ -not $exists
+ }
+}
+
+Export-ModuleMember -Function *-TargetResource
+
diff --git a/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.schema.mof b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.schema.mof
new file mode 100644
index 00000000..c61b2b1e
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.schema.mof
@@ -0,0 +1,60 @@
+[ClassVersion("1.0.0")]
+class ANSIBLE_xTestClass
+{
+ [Key] String Key;
+ [Write] String StringValue;
+ [Write] SInt32 IntValue;
+ [Write] String StringArrayValue[];
+};
+
+[ClassVersion("1.0.0")]
+class ANSIBLE_xNestedClass
+{
+ [Key] String KeyValue;
+ [Write, EmbeddedInstance("ANSIBLE_xTestClass")] String CimValue;
+ [Write, EmbeddedInstance("MSFT_KeyValuePair")] String HashValue[];
+ [Write] SInt16 IntValue;
+};
+
+[ClassVersion("1.0.0"), FriendlyName("xTestResource")]
+class ANSIBLE_xTestResource : OMI_BaseResource
+{
+ [Key] String Path;
+ [Required, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure;
+ [Read] String ReadParam;
+ [Write] String DefaultParam;
+ [Write] String StringParam;
+ [Write] String StringArrayParam[];
+ [Write] SInt8 Int8Param;
+ [Write] SInt8 Int8ArrayParam[];
+ [Write] UInt8 UInt8Param;
+ [Write] UInt8 UInt8ArrayParam[];
+ [Write] SInt16 Int16Param;
+ [Write] SInt16 Int16ArrayParam[];
+ [Write] UInt16 UInt16Param;
+ [Write] UInt16 UInt16ArrayParam[];
+ [Write] SInt32 Int32Param;
+ [Write] SInt32 Int32ArrayParam[];
+ [Write] UInt32 UInt32Param;
+ [Write] UInt32 UInt32ArrayParam[];
+ [Write] SInt64 Int64Param;
+ [Write] SInt64 Int64ArrayParam[];
+ [Write] UInt64 UInt64Param;
+ [Write] UInt64 UInt64ArrayParam[];
+ [Write] Boolean BooleanParam;
+ [Write] Boolean BooleanArrayParam[];
+ [Write] Char16 CharParam;
+ [Write] Char16 CharArrayParam[];
+ [Write] Real32 SingleParam;
+ [Write] Real32 SingleArrayParam[];
+ [Write] Real64 DoubleParam;
+ [Write] Real64 DoubleArrayParam[];
+ [Write] DateTime DateTimeParam;
+ [Write] DateTime DateTimeArrayParam[];
+ [Write, EmbeddedInstance("MSFT_Credential")] String PSCredentialParam;
+ [Write, EmbeddedInstance("MSFT_KeyValuePair")] String HashtableParam[];
+ [Write, EmbeddedInstance("ANSIBLE_xTestClass")] String CimInstanceArrayParam[];
+ [Write, EmbeddedInstance("ANSIBLE_xNestedClass")] String NestedCimInstanceParam;
+ [Write, EmbeddedInstance("ANSIBLE_xNestedClass")] String NestedCimInstanceArrayParam[];
+};
+
diff --git a/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/xTestDsc.psd1 b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/xTestDsc.psd1
new file mode 100644
index 00000000..3d61611d
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.0/xTestDsc.psd1
@@ -0,0 +1,13 @@
+@{
+ ModuleVersion = '1.0.0'
+ GUID = '80c895c4-de3f-4d6d-8fa4-c504c96b6f22'
+ Author = 'Ansible'
+ CompanyName = 'Ansible'
+ Copyright = '(c) 2019'
+ Description = 'Test DSC Resource for Ansible integration tests'
+ PowerShellVersion = '5.0'
+ CLRVersion = '4.0'
+ FunctionsToExport = '*'
+ CmdletsToExport = '*'
+}
+
diff --git a/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1 b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1
new file mode 100644
index 00000000..d75256e1
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1
@@ -0,0 +1,214 @@
+#Requires -Version 5.0 -Modules CimCmdlets
+
+Function ConvertFrom-CimInstance {
+ param(
+ [Parameter(Mandatory=$true)][CimInstance]$Instance
+ )
+ $hashtable = @{
+ _cim_instance = $Instance.CimSystemProperties.ClassName
+ }
+ foreach ($prop in $Instance.CimInstanceProperties) {
+ $hashtable."$($prop.Name)" = ConvertTo-OutputValue -Value $prop.Value
+ }
+ return $hashtable
+}
+
+Function ConvertTo-OutputValue {
+ param($Value)
+
+ if ($Value -is [DateTime[]]) {
+ $Value = $Value | ForEach-Object { $_.ToString("o") }
+ } elseif ($Value -is [DateTime]) {
+ $Value = $Value.ToString("o")
+ } elseif ($Value -is [Double]) {
+ $Value = $Value.ToString() # To avoid Python 2 double parsing issues on test validation
+ } elseif ($Value -is [Double[]]) {
+ $Value = $Value | ForEach-Object { $_.ToString() }
+ } elseif ($Value -is [PSCredential]) {
+ $password = $null
+ $password_ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode($Value.Password)
+ try {
+ $password = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($password_ptr)
+ } finally {
+ [System.Runtime.InteropServices.Marshal]::ZeroFreeGlobalAllocUnicode($password_ptr)
+ }
+ $Value = @{
+ username = $Value.Username
+ password = $password
+ }
+ } elseif ($Value -is [CimInstance[]]) {
+ $value_list = [System.Collections.Generic.List`1[Hashtable]]@()
+ foreach ($cim_instance in $Value) {
+ $value_list.Add((ConvertFrom-CimInstance -Instance $cim_instance))
+ }
+ $Value = $value_list.ToArray()
+ } elseif ($Value -is [CimInstance]) {
+ $Value = ConvertFrom-CimInstance -Instance $Value
+ }
+
+ return ,$Value
+}
+
+Function Get-TargetResource
+{
+ [CmdletBinding()]
+ [OutputType([Hashtable])]
+ param(
+ [Parameter(Mandatory = $true)]
+ [ValidateSet("Present", "Absent")]
+ [String] $Ensure = "Present",
+
+ [Parameter(Mandatory = $true)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Path
+ )
+ return @{
+ Ensure = $Ensure
+ Path = $Path
+ }
+}
+
+Function Set-TargetResource
+{
+ [CmdletBinding()]
+ param
+ (
+ [Parameter(Mandatory = $true)]
+ [ValidateSet("Present", "Absent")]
+ [String] $Ensure = "Present",
+
+ [Parameter(Mandatory = $true)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Path,
+
+ [String] $DefaultParam = "Default",
+ [String] $StringParam,
+ [String[]] $StringArrayParam,
+ [SByte] $Int8Param,
+ [SByte[]] $Int8ArrayParam,
+ [Byte] $UInt8Param,
+ [Byte[]] $UInt8ArrayParam,
+ [Int16] $Int16Param,
+ [Int16[]] $Int16ArrayParam,
+ [UInt16] $UInt16Param,
+ [UInt16[]] $UInt16ArrayParam,
+ [Int32] $Int32Param,
+ [Int32[]] $Int32ArrayParam,
+ [UInt32] $UInt32Param,
+ [UInt32[]] $UInt32ArrayParam,
+ [Int64] $Int64Param,
+ [Int64[]] $Int64ArrayParam,
+ [UInt64] $UInt64Param,
+ [UInt64[]] $UInt64ArrayParam,
+ [Bool] $BooleanParam,
+ [Bool[]] $BooleanArrayParam,
+ [Char] $CharParam,
+ [Char[]] $CharArrayParam,
+ [Single] $SingleParam,
+ [Single[]] $SingleArrayParam,
+ [Double] $DoubleParam,
+ [Double[]] $DoubleArrayParam,
+ [DateTime] $DateTimeParam,
+ [DateTime[]] $DateTimeArrayParam,
+ [PSCredential] $PSCredentialParam,
+ [CimInstance[]] $HashtableParam,
+ [CimInstance] $CimInstanceParam,
+ [CimInstance[]] $CimInstanceArrayParam,
+ [CimInstance] $NestedCimInstanceParam,
+ [CimInstance[]] $NestedCimInstanceArrayParam
+ )
+
+ $info = @{
+ Version = "1.0.1"
+ Ensure = @{
+ Type = $Ensure.GetType().FullName
+ Value = $Ensure
+ }
+ Path = @{
+ Type = $Path.GetType().FullName
+ Value = $Path
+ }
+ DefaultParam = @{
+ Type = $DefaultParam.GetType().FullName
+ Value = $DefaultParam
+ }
+ }
+
+ foreach ($kvp in $PSCmdlet.MyInvocation.BoundParameters.GetEnumerator()) {
+ $info."$($kvp.Key)" = @{
+ Type = $kvp.Value.GetType().FullName
+ Value = (ConvertTo-OutputValue -Value $kvp.Value)
+ }
+ }
+
+ if (Test-Path -Path $Path) {
+ Remove-Item -Path $Path -Force > $null
+ }
+ New-Item -Path $Path -ItemType File > $null
+ Set-Content -Path $Path -Value (ConvertTo-Json -InputObject $info -Depth 10) > $null
+ Write-Verbose -Message "set verbose"
+ Write-Warning -Message "set warning"
+}
+
+Function Test-TargetResource
+{
+ [CmdletBinding()]
+ [OutputType([Boolean])]
+ param
+ (
+ [Parameter(Mandatory = $true)]
+ [ValidateSet("Present", "Absent")]
+ [String] $Ensure = "Present",
+
+ [Parameter(Mandatory = $true)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Path,
+
+ [String] $DefaultParam = "Default",
+ [String] $StringParam,
+ [String[]] $StringArrayParam,
+ [SByte] $Int8Param,
+ [SByte[]] $Int8ArrayParam,
+ [Byte] $UInt8Param,
+ [Byte[]] $UInt8ArrayParam,
+ [Int16] $Int16Param,
+ [Int16[]] $Int16ArrayParam,
+ [UInt16] $UInt16Param,
+ [UInt16[]] $UInt16ArrayParam,
+ [Int32] $Int32Param,
+ [Int32[]] $Int32ArrayParam,
+ [UInt32] $UInt32Param,
+ [UInt32[]] $UInt32ArrayParam,
+ [Int64] $Int64Param,
+ [Int64[]] $Int64ArrayParam,
+ [UInt64] $UInt64Param,
+ [UInt64[]] $UInt64ArrayParam,
+ [Bool] $BooleanParam,
+ [Bool[]] $BooleanArrayParam,
+ [Char] $CharParam,
+ [Char[]] $CharArrayParam,
+ [Single] $SingleParam,
+ [Single[]] $SingleArrayParam,
+ [Double] $DoubleParam,
+ [Double[]] $DoubleArrayParam,
+ [DateTime] $DateTimeParam,
+ [DateTime[]] $DateTimeArrayParam,
+ [PSCredential] $PSCredentialParam,
+ [CimInstance[]] $HashtableParam,
+ [CimInstance] $CimInstanceParam,
+ [CimInstance[]] $CimInstanceArrayParam,
+ [CimInstance] $NestedCimInstanceParam,
+ [CimInstance[]] $NestedCimInstanceArrayParam
+ )
+ Write-Verbose -Message "test verbose"
+ Write-Warning -Message "test warning"
+ $exists = Test-Path -LiteralPath $Path -PathType Leaf
+ if ($Ensure -eq "Present") {
+ $exists
+ } else {
+ -not $exists
+ }
+}
+
+Export-ModuleMember -Function *-TargetResource
+
diff --git a/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.schema.mof b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.schema.mof
new file mode 100644
index 00000000..9301664b
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.schema.mof
@@ -0,0 +1,63 @@
+[ClassVersion("1.0.1")]
+class ANSIBLE_xTestClass
+{
+ [Key] String KeyValue;
+ [Write, ValueMap{"Choice1", "Choice2"}, Values{"Choice1", "Choice2"}] String Choice;
+ [Write] String StringValue;
+ [Write] SInt32 IntValue;
+ [Write] String StringArrayValue[];
+};
+
+[ClassVersion("1.0.1")]
+class ANSIBLE_xNestedClass
+{
+ [Key] String KeyValue;
+ [Write, EmbeddedInstance("ANSIBLE_xTestClass")] String CimValue;
+ [Write, EmbeddedInstance("ANSIBLE_xTestClass")] String CimArrayValue[];
+ [Write, EmbeddedInstance("MSFT_KeyValuePair")] String HashValue[];
+ [Write] SInt16 IntValue;
+};
+
+[ClassVersion("1.0.1"), FriendlyName("xTestResource")]
+class ANSIBLE_xTestResource : OMI_BaseResource
+{
+ [Key] String Path;
+ [Required, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure;
+ [Read] String ReadParam;
+ [Write] String DefaultParam;
+ [Write] String StringParam;
+ [Write] String StringArrayParam[];
+ [Write] SInt8 Int8Param;
+ [Write] SInt8 Int8ArrayParam[];
+ [Write] UInt8 UInt8Param;
+ [Write] UInt8 UInt8ArrayParam[];
+ [Write] SInt16 Int16Param;
+ [Write] SInt16 Int16ArrayParam[];
+ [Write] UInt16 UInt16Param;
+ [Write] UInt16 UInt16ArrayParam[];
+ [Write] SInt32 Int32Param;
+ [Write] SInt32 Int32ArrayParam[];
+ [Write] UInt32 UInt32Param;
+ [Write] UInt32 UInt32ArrayParam[];
+ [Write] SInt64 Int64Param;
+ [Write] SInt64 Int64ArrayParam[];
+ [Write] UInt64 UInt64Param;
+ [Write] UInt64 UInt64ArrayParam[];
+ [Write] Boolean BooleanParam;
+ [Write] Boolean BooleanArrayParam[];
+ [Write] Char16 CharParam;
+ [Write] Char16 CharArrayParam[];
+ [Write] Real32 SingleParam;
+ [Write] Real32 SingleArrayParam[];
+ [Write] Real64 DoubleParam;
+ [Write] Real64 DoubleArrayParam[];
+ [Write] DateTime DateTimeParam;
+ [Write] DateTime DateTimeArrayParam[];
+ [Write, EmbeddedInstance("MSFT_Credential")] String PSCredentialParam;
+ [Write, EmbeddedInstance("MSFT_KeyValuePair")] String HashtableParam[];
+ [Write, EmbeddedInstance("ANSIBLE_xTestClass")] String CimInstanceParam;
+ [Write, EmbeddedInstance("ANSIBLE_xTestClass")] String CimInstanceArrayParam[];
+ [Write, EmbeddedInstance("ANSIBLE_xNestedClass")] String NestedCimInstanceParam;
+ [Write, EmbeddedInstance("ANSIBLE_xNestedClass")] String NestedCimInstanceArrayParam[];
+};
+
diff --git a/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/xTestDsc.psd1 b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/xTestDsc.psd1
new file mode 100644
index 00000000..0c43b852
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/files/xTestDsc/1.0.1/xTestDsc.psd1
@@ -0,0 +1,13 @@
+@{
+ ModuleVersion = '1.0.1'
+ GUID = '80c895c4-de3f-4d6d-8fa4-c504c96b6f22'
+ Author = 'Ansible'
+ CompanyName = 'Ansible'
+ Copyright = '(c) 2019'
+ Description = 'Test DSC Resource for Ansible integration tests'
+ PowerShellVersion = '5.0'
+ CLRVersion = '4.0'
+ FunctionsToExport = '*'
+ CmdletsToExport = '*'
+}
+
diff --git a/test/integration/targets/incidental_win_dsc/meta/main.yml b/test/integration/targets/incidental_win_dsc/meta/main.yml
new file mode 100644
index 00000000..9f37e96c
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/meta/main.yml
@@ -0,0 +1,2 @@
+dependencies:
+- setup_remote_tmp_dir
diff --git a/test/integration/targets/incidental_win_dsc/tasks/main.yml b/test/integration/targets/incidental_win_dsc/tasks/main.yml
new file mode 100644
index 00000000..f37295ab
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/tasks/main.yml
@@ -0,0 +1,39 @@
+---
+- name: get powershell version
+ win_shell: $PSVersionTable.PSVersion.Major
+ register: powershell_version
+
+- name: expect failure when running on old PS hosts
+ win_dsc:
+ resource_name: File
+ register: fail_dsc_old
+ failed_when: '"This module cannot run as it requires a minimum PowerShell version of 5.0" not in fail_dsc_old.msg'
+ when: powershell_version.stdout_lines[0]|int < 5
+
+- name: run tests when PSv5+
+ when: powershell_version.stdout_lines[0]|int >= 5
+ block:
+ - name: add remote temp dir to PSModulePath
+ win_path:
+ name: PSModulePath
+ state: present
+ scope: machine
+ elements:
+ - '{{ remote_tmp_dir }}'
+
+ - name: copy custom DSC resources to remote temp dir
+ win_copy:
+ src: xTestDsc
+ dest: '{{ remote_tmp_dir }}'
+
+ - name: run tests
+ include_tasks: tests.yml
+
+ always:
+ - name: remove remote tmp dir from PSModulePath
+ win_path:
+ name: PSModulePath
+ state: absent
+ scope: machine
+ elements:
+ - '{{ remote_tmp_dir }}'
diff --git a/test/integration/targets/incidental_win_dsc/tasks/tests.yml b/test/integration/targets/incidental_win_dsc/tasks/tests.yml
new file mode 100644
index 00000000..d2a6802f
--- /dev/null
+++ b/test/integration/targets/incidental_win_dsc/tasks/tests.yml
@@ -0,0 +1,544 @@
+---
+- name: fail with incorrect DSC resource name
+ win_dsc:
+ resource_name: FakeResource
+ register: fail_invalid_resource
+ failed_when: fail_invalid_resource.msg != "Resource 'FakeResource' not found."
+
+- name: fail with invalid DSC version
+ win_dsc:
+ resource_name: xTestResource
+ module_version: 0.0.1
+ register: fail_invalid_version
+ failed_when: 'fail_invalid_version.msg != "Resource ''xTestResource'' with version ''0.0.1'' not found. Versions installed: ''1.0.0'', ''1.0.1''."'
+
+- name: fail with mandatory option not set
+ win_dsc:
+ resource_name: xSetReboot
+ Value: yes
+ register: fail_man_key
+ failed_when: 'fail_man_key.msg != "missing required arguments: KeyParam"'
+
+- name: fail with mandatory option not set in sub dict
+ win_dsc:
+ resource_name: xTestResource
+ Path: C:\path
+ Ensure: Present
+ CimInstanceParam: # Missing KeyValue in dict
+ Choice: Choice1
+ register: fail_man_key_sub_dict
+ failed_when: 'fail_man_key_sub_dict.msg != "missing required arguments: KeyValue found in CimInstanceParam"'
+
+- name: fail invalid option
+ win_dsc:
+ resource_name: xSetReboot
+ KeyParam: key
+ OtherParam: invalid
+ register: fail_invalid_option
+ failed_when: 'fail_invalid_option.msg != "Unsupported parameters for (win_dsc) module: OtherParam. Supported parameters include: KeyParam, PsDscRunAsCredential_username, module_version, Value, PsDscRunAsCredential_password, resource_name, DependsOn"'
+
+- name: fail invalid option in sub dict
+ win_dsc:
+ resource_name: xTestResource
+ Path: C:\path
+ Ensure: Present
+ NestedCimInstanceParam:
+ KeyValue: key
+ CimValue:
+ KeyValue: other key
+ InvalidKey: invalid
+ register: fail_invalid_option_sub_dict
+ failed_when: 'fail_invalid_option_sub_dict.msg != "Unsupported parameters for (win_dsc) module: InvalidKey found in NestedCimInstanceParam -> CimValue. Supported parameters include: IntValue, KeyValue, StringArrayValue, Choice, StringValue"'
+
+- name: fail invalid read only option
+ win_dsc:
+ resource_name: xTestResource
+ Path: C:\path
+ Ensure: Present
+ ReadParam: abc
+ register: fail_invalid_option_read_only
+ failed_when: '"Unsupported parameters for (win_dsc) module: ReadParam" not in fail_invalid_option_read_only.msg'
+
+- name: fail invalid choice
+ win_dsc:
+ resource_name: xTestResource
+ Path: C:\path
+ Ensure: invalid
+ register: fail_invalid_choice
+ failed_when: 'fail_invalid_choice.msg != "value of Ensure must be one of: Present, Absent. Got no match for: invalid"'
+
+- name: fail invalid choice in sub dict
+ win_dsc:
+ resource_name: xTestResource
+ Path: C:\path
+ Ensure: Present
+ CimInstanceArrayParam:
+ - KeyValue: key
+ - KeyValue: key2
+ Choice: Choice3
+ register: fail_invalid_choice_sub_dict
+ failed_when: 'fail_invalid_choice_sub_dict.msg != "value of Choice must be one of: Choice1, Choice2. Got no match for: Choice3 found in CimInstanceArrayParam"'
+
+- name: fail old version missing new option
+ win_dsc:
+ resource_name: xTestResource
+ module_version: 1.0.0
+ Path: C:\path
+ Ensure: Present
+ CimInstanceParam: # CimInstanceParam does not exist in the 1.0.0 version
+ Key: key
+ register: fail_invalid_option_old
+ failed_when: '"Unsupported parameters for (win_dsc) module: CimInstanceParam" not in fail_invalid_option_old.msg'
+
+- name: fail old version missing new option sub dict
+ win_dsc:
+ resource_name: xTestResource
+ module_version: 1.0.0
+ Path: C:\path
+ Ensure: Present
+ CimInstanceArrayParam:
+ - Key: key
+ Choice: Choice1
+ register: fail_invalid_option_old_sub_dict
+ failed_when: 'fail_invalid_option_old_sub_dict.msg != "Unsupported parameters for (win_dsc) module: Choice found in CimInstanceArrayParam. Supported parameters include: Key, IntValue, StringArrayValue, StringValue"'
+
+- name: create test file (check mode)
+ win_dsc:
+ resource_name: File
+ DestinationPath: '{{ remote_tmp_dir }}\dsc-file'
+ Contents: file contents
+ Attributes:
+ - Hidden
+ - ReadOnly
+ Ensure: Present
+ Type: File
+ register: create_file_check
+ check_mode: yes
+
+- name: get result of create test file (check mode)
+ win_stat:
+ path: '{{ remote_tmp_dir }}\dsc-file'
+ register: create_file_actual_check
+
+- name: assert create test file (check mode)
+ assert:
+ that:
+ - create_file_check is changed
+ - create_file_check.module_version == None # Some built in modules don't have a version set
+ - not create_file_check.reboot_required
+ - not create_file_actual_check.stat.exists
+
+- name: assert create test file verbosity (check mode)
+ assert:
+ that:
+ - create_file_check.verbose_test is defined
+ - not create_file_check.verbose_set is defined
+ when: ansible_verbosity >= 3
+
+- name: create test file
+ win_dsc:
+ resource_name: File
+ DestinationPath: '{{ remote_tmp_dir }}\dsc-file'
+ Contents: file contents
+ Attributes:
+ - Hidden
+ - ReadOnly
+ Ensure: Present
+ Type: File
+ register: create_file
+
+- name: get result of create test file
+ win_stat:
+ path: '{{ remote_tmp_dir }}\dsc-file'
+ register: create_file_actual
+
+- name: assert create test file verbosity
+ assert:
+ that:
+ - create_file.verbose_test is defined
+ - create_file.verbose_set is defined
+ when: ansible_verbosity >= 3
+
+- name: assert create test file
+ assert:
+ that:
+ - create_file is changed
+ - create_file.module_version == None
+ - not create_file.reboot_required
+ - create_file_actual.stat.exists
+ - create_file_actual.stat.attributes == "ReadOnly, Hidden, Archive"
+ - create_file_actual.stat.checksum == 'd48daab51112b49ecabd917adc345b8ba257055e'
+
+- name: create test file (idempotent)
+ win_dsc:
+ resource_name: File
+ DestinationPath: '{{ remote_tmp_dir }}\dsc-file'
+ Contents: file contents
+ Attributes:
+ - Hidden
+ - ReadOnly
+ Ensure: Present
+ Type: File
+ register: create_file_again
+
+- name: assert create test file (idempotent)
+ assert:
+ that:
+ - not create_file_again is changed
+ - create_file.module_version == None
+ - not create_file.reboot_required
+
+- name: get SID of the current Ansible user
+ win_shell: |
+ Add-Type -AssemblyName System.DirectoryServices.AccountManagement
+ [System.DirectoryServices.AccountManagement.UserPrincipal]::Current.Sid.Value
+ register: actual_sid
+
+- name: run DSC process as another user
+ win_dsc:
+ resource_name: Script
+ GetScript: '@{ Result= "" }'
+ SetScript: |
+ Add-Type -AssemblyName System.DirectoryServices.AccountManagement
+ $sid = [System.DirectoryServices.AccountManagement.UserPrincipal]::Current.Sid.Value
+ Set-Content -Path "{{ remote_tmp_dir }}\runas.txt" -Value $sid
+ TestScript: $false
+ PsDscRunAsCredential_username: '{{ ansible_user }}'
+ PsDscRunAsCredential_password: '{{ ansible_password }}'
+ register: runas_user
+
+- name: get result of run DSC process as another user
+ slurp:
+ path: '{{ remote_tmp_dir }}\runas.txt'
+ register: runas_user_result
+
+- name: assert run DSC process as another user
+ assert:
+ that:
+ - runas_user is changed
+ - runas_user.module_version != None # Can't reliably set the version but we can test it is set
+ - not runas_user.reboot_required
+ - runas_user_result.content|b64decode == actual_sid.stdout
+
+- name: run DSC that sets reboot_required with defaults
+ win_dsc:
+ resource_name: xSetReboot
+ KeyParam: value # Just to satisfy the Resource with key validation
+ register: set_reboot_defaults
+
+- name: assert run DSC that sets reboot_required with defaults
+ assert:
+ that:
+ - set_reboot_defaults.reboot_required
+
+- name: run DSC that sets reboot_required with False
+ win_dsc:
+ resource_name: xSetReboot
+ KeyParam: value
+ Value: no
+ register: set_reboot_false
+
+- name: assert run DSC that sets reboot_required with False
+ assert:
+ that:
+ - not set_reboot_false.reboot_required
+
+- name: run DSC that sets reboot_required with True
+ win_dsc:
+ resource_name: xSetReboot
+ KeyParam: value
+ Value: yes
+ register: set_reboot_true
+
+- name: assert run DSC that sets reboot_required with True
+ assert:
+ that:
+ - set_reboot_true.reboot_required
+
+- name: test DSC with all types
+ win_dsc:
+ resource_name: xTestResource
+ Path: '{{ remote_tmp_dir }}\test-types.json'
+ Ensure: Present
+ StringParam: string param
+ StringArrayParam:
+ - string 1
+ - string 2
+ Int8Param: 127 # [SByte]::MaxValue
+ Int8ArrayParam:
+ - 127
+ - '127'
+ UInt8Param: 255 # [Byte]::MaxValue
+ UInt8ArrayParam:
+ - 255
+ - '255'
+ Int16Param: 32767 # [Int16]::MaxValue
+ Int16ArrayParam: 32767, 32767
+ UInt16Param: '65535' # [UInt16]::MaxValue
+ UInt16ArrayParam: 65535
+ Int32Param: 2147483647 # [Int32]::MaxValue
+ Int32ArrayParam: '2147483647'
+ UInt32Param: '4294967295' # [UInt32]::MaxValue
+ UInt32ArrayParam:
+ - '4294967295'
+ - 4294967295
+ Int64Param: 9223372036854775807 # [Int64]::MaxValue
+ Int64ArrayParam:
+ - -9223372036854775808 # [Int64]::MinValue
+ - 9223372036854775807
+ UInt64Param: 18446744073709551615 # [UInt64]::MaxValue
+ UInt64ArrayParam:
+ - 0 # [UInt64]::MinValue
+ - 18446744073709551615
+ BooleanParam: True
+ BooleanArrayParam:
+ - True
+ - 'True'
+ - 'true'
+ - 'y'
+ - 'yes'
+ - 1
+ - False
+ - 'False'
+ - 'false'
+ - 'n'
+ - 'no'
+ - 0
+ CharParam: c
+ CharArrayParam:
+ - c
+ - h
+ - a
+ - r
+ SingleParam: 3.402823E+38
+ SingleArrayParam:
+ - '3.402823E+38'
+ - 1.2393494
+ DoubleParam: 1.79769313486232E+300
+ DoubleArrayParam:
+ - '1.79769313486232E+300'
+ - 3.56821831681516
+ DateTimeParam: '2019-02-22T13:57:31.2311892-04:00'
+ DateTimeArrayParam:
+ - '2019-02-22T13:57:31.2311892+00:00'
+ - '2019-02-22T13:57:31.2311892+04:00'
+ PSCredentialParam_username: username1
+ PSCredentialParam_password: password1
+ HashtableParam:
+ key1: string 1
+ key2: ''
+ key3: 1
+ CimInstanceParam:
+ KeyValue: a
+ CimInstanceArrayParam:
+ - KeyValue: b
+ Choice: Choice1
+ StringValue: string 1
+ IntValue: 1
+ StringArrayValue:
+ - abc
+ - def
+ - KeyValue: c
+ Choice: Choice2
+ StringValue: string 2
+ IntValue: '2'
+ StringArrayValue:
+ - ghi
+ - jkl
+ NestedCimInstanceParam:
+ KeyValue: key value
+ CimValue:
+ KeyValue: d
+ CimArrayValue:
+ - KeyValue: e
+ Choice: Choice2
+ HashValue:
+ a: a
+ IntValue: '300'
+ register: dsc_types
+
+- name: get result of test DSC with all types
+ slurp:
+ path: '{{ remote_tmp_dir }}\test-types.json'
+ register: dsc_types_raw
+
+- name: convert result of test DSC with all types to dict
+ set_fact:
+ dsc_types_actual: '{{ dsc_types_raw.content | b64decode | from_json }}'
+
+- name: assert test DSC with all types
+ assert:
+ that:
+ - dsc_types is changed
+ - dsc_types.module_version == '1.0.1'
+ - not dsc_types.reboot_required
+ - dsc_types_actual.Version == '1.0.1'
+ - dsc_types_actual.Verbose.Value.IsPresent
+ - dsc_types_actual.DefaultParam.Value == 'Default' # ensures that the default is set in the engine if we don't set it outselves
+ - dsc_types_actual.Ensure.Value == 'Present'
+ - dsc_types_actual.Path.Value == remote_tmp_dir + "\\test-types.json"
+ - dsc_types_actual.StringParam.Type == 'System.String'
+ - dsc_types_actual.StringParam.Value == 'string param'
+ - dsc_types_actual.StringArrayParam.Type == 'System.String[]'
+ - dsc_types_actual.StringArrayParam.Value == ['string 1', 'string 2']
+ - dsc_types_actual.Int8Param.Type == 'System.SByte'
+ - dsc_types_actual.Int8Param.Value == 127
+ - dsc_types_actual.Int8ArrayParam.Type == 'System.SByte[]'
+ - dsc_types_actual.Int8ArrayParam.Value == [127, 127]
+ - dsc_types_actual.UInt8Param.Type == 'System.Byte'
+ - dsc_types_actual.UInt8Param.Value == 255
+ - dsc_types_actual.UInt8ArrayParam.Type == 'System.Byte[]'
+ - dsc_types_actual.UInt8ArrayParam.Value == [255, 255]
+ - dsc_types_actual.Int16Param.Type == 'System.Int16'
+ - dsc_types_actual.Int16Param.Value == 32767
+ - dsc_types_actual.Int16ArrayParam.Type == 'System.Int16[]'
+ - dsc_types_actual.Int16ArrayParam.Value == [32767, 32767]
+ - dsc_types_actual.UInt16Param.Type == 'System.UInt16'
+ - dsc_types_actual.UInt16Param.Value == 65535
+ - dsc_types_actual.UInt16ArrayParam.Type == 'System.UInt16[]'
+ - dsc_types_actual.UInt16ArrayParam.Value == [65535]
+ - dsc_types_actual.Int32Param.Type == 'System.Int32'
+ - dsc_types_actual.Int32Param.Value == 2147483647
+ - dsc_types_actual.Int32ArrayParam.Type == 'System.Int32[]'
+ - dsc_types_actual.Int32ArrayParam.Value == [2147483647]
+ - dsc_types_actual.UInt32Param.Type == 'System.UInt32'
+ - dsc_types_actual.UInt32Param.Value == 4294967295
+ - dsc_types_actual.UInt32ArrayParam.Type == 'System.UInt32[]'
+ - dsc_types_actual.UInt32ArrayParam.Value == [4294967295, 4294967295]
+ - dsc_types_actual.Int64Param.Type == 'System.Int64'
+ - dsc_types_actual.Int64Param.Value == 9223372036854775807
+ - dsc_types_actual.Int64ArrayParam.Type == 'System.Int64[]'
+ - dsc_types_actual.Int64ArrayParam.Value == [-9223372036854775808, 9223372036854775807]
+ - dsc_types_actual.UInt64Param.Type == 'System.UInt64'
+ - dsc_types_actual.UInt64Param.Value == 18446744073709551615
+ - dsc_types_actual.UInt64ArrayParam.Type == 'System.UInt64[]'
+ - dsc_types_actual.UInt64ArrayParam.Value == [0, 18446744073709551615]
+ - dsc_types_actual.BooleanParam.Type == 'System.Boolean'
+ - dsc_types_actual.BooleanParam.Value == True
+ - dsc_types_actual.BooleanArrayParam.Type == 'System.Boolean[]'
+ - dsc_types_actual.BooleanArrayParam.Value == [True, True, True, True, True, True, False, False, False, False, False, False]
+ - dsc_types_actual.CharParam.Type == 'System.Char'
+ - dsc_types_actual.CharParam.Value == 'c'
+ - dsc_types_actual.CharArrayParam.Type == 'System.Char[]'
+ - dsc_types_actual.CharArrayParam.Value == ['c', 'h', 'a', 'r']
+ - dsc_types_actual.SingleParam.Type == 'System.Single'
+ - dsc_types_actual.SingleParam.Value|string == '3.402823e+38'
+ - dsc_types_actual.SingleArrayParam.Type == 'System.Single[]'
+ - dsc_types_actual.SingleArrayParam.Value|length == 2
+ - dsc_types_actual.SingleArrayParam.Value[0]|string == '3.402823e+38'
+ - dsc_types_actual.SingleArrayParam.Value[1]|string == '1.23934937'
+ - dsc_types_actual.DoubleParam.Type == 'System.Double'
+ - dsc_types_actual.DoubleParam.Value == '1.79769313486232E+300'
+ - dsc_types_actual.DoubleArrayParam.Type == 'System.Double[]'
+ - dsc_types_actual.DoubleArrayParam.Value|length == 2
+ - dsc_types_actual.DoubleArrayParam.Value[0] == '1.79769313486232E+300'
+ - dsc_types_actual.DoubleArrayParam.Value[1] == '3.56821831681516'
+ - dsc_types_actual.DateTimeParam.Type == 'System.DateTime'
+ - dsc_types_actual.DateTimeParam.Value == '2019-02-22T17:57:31.2311890+00:00'
+ - dsc_types_actual.DateTimeArrayParam.Type == 'System.DateTime[]'
+ - dsc_types_actual.DateTimeArrayParam.Value == ['2019-02-22T13:57:31.2311890+00:00', '2019-02-22T09:57:31.2311890+00:00']
+ - dsc_types_actual.PSCredentialParam.Type == 'System.Management.Automation.PSCredential'
+ - dsc_types_actual.PSCredentialParam.Value.username == 'username1'
+ - dsc_types_actual.PSCredentialParam.Value.password == 'password1'
+ # Hashtable is actually a CimInstance[] of MSFT_KeyValuePairs
+ - dsc_types_actual.HashtableParam.Type == 'Microsoft.Management.Infrastructure.CimInstance[]'
+ - dsc_types_actual.HashtableParam.Value|length == 3
+ # Can't guarantee the order of the keys so just check they are the values they could be
+ - dsc_types_actual.HashtableParam.Value[0].Key in ["key1", "key2", "key3"]
+ - dsc_types_actual.HashtableParam.Value[0].Value in ["string 1", "1", ""]
+ - dsc_types_actual.HashtableParam.Value[0]._cim_instance == 'MSFT_KeyValuePair'
+ - dsc_types_actual.HashtableParam.Value[1].Key in ["key1", "key2", "key3"]
+ - dsc_types_actual.HashtableParam.Value[1].Value in ["string 1", "1", ""]
+ - dsc_types_actual.HashtableParam.Value[1]._cim_instance == 'MSFT_KeyValuePair'
+ - dsc_types_actual.HashtableParam.Value[2].Key in ["key1", "key2", "key3"]
+ - dsc_types_actual.HashtableParam.Value[2].Value in ["string 1", "1", ""]
+ - dsc_types_actual.HashtableParam.Value[2]._cim_instance == 'MSFT_KeyValuePair'
+ - dsc_types_actual.CimInstanceParam.Type == 'Microsoft.Management.Infrastructure.CimInstance'
+ - dsc_types_actual.CimInstanceParam.Value.Choice == None
+ - dsc_types_actual.CimInstanceParam.Value.IntValue == None
+ - dsc_types_actual.CimInstanceParam.Value.KeyValue == 'a'
+ - dsc_types_actual.CimInstanceParam.Value.StringArrayValue == None
+ - dsc_types_actual.CimInstanceParam.Value.StringValue == None
+ - dsc_types_actual.CimInstanceParam.Value._cim_instance == "ANSIBLE_xTestClass"
+ - dsc_types_actual.CimInstanceArrayParam.Type == 'Microsoft.Management.Infrastructure.CimInstance[]'
+ - dsc_types_actual.CimInstanceArrayParam.Value|length == 2
+ - dsc_types_actual.CimInstanceArrayParam.Value[0].Choice == 'Choice1'
+ - dsc_types_actual.CimInstanceArrayParam.Value[0].IntValue == 1
+ - dsc_types_actual.CimInstanceArrayParam.Value[0].KeyValue == 'b'
+ - dsc_types_actual.CimInstanceArrayParam.Value[0].StringArrayValue == ['abc', 'def']
+ - dsc_types_actual.CimInstanceArrayParam.Value[0].StringValue == 'string 1'
+ - dsc_types_actual.CimInstanceArrayParam.Value[0]._cim_instance == 'ANSIBLE_xTestClass'
+ - dsc_types_actual.CimInstanceArrayParam.Value[1].Choice == 'Choice2'
+ - dsc_types_actual.CimInstanceArrayParam.Value[1].IntValue == 2
+ - dsc_types_actual.CimInstanceArrayParam.Value[1].KeyValue == 'c'
+ - dsc_types_actual.CimInstanceArrayParam.Value[1].StringArrayValue == ['ghi', 'jkl']
+ - dsc_types_actual.CimInstanceArrayParam.Value[1].StringValue == 'string 2'
+ - dsc_types_actual.CimInstanceArrayParam.Value[1]._cim_instance == 'ANSIBLE_xTestClass'
+ - dsc_types_actual.NestedCimInstanceParam.Type == 'Microsoft.Management.Infrastructure.CimInstance'
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimArrayValue|length == 1
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimArrayValue[0].Choice == 'Choice2'
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimArrayValue[0].IntValue == None
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimArrayValue[0].KeyValue == 'e'
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimArrayValue[0].StringArrayValue == None
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimArrayValue[0].StringValue == None
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimArrayValue[0]._cim_instance == 'ANSIBLE_xTestClass'
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimValue.Choice == None
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimValue.IntValue == None
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimValue.KeyValue == 'd'
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimValue.StringArrayValue == None
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimValue.StringValue == None
+ - dsc_types_actual.NestedCimInstanceParam.Value.CimValue._cim_instance == 'ANSIBLE_xTestClass'
+ - dsc_types_actual.NestedCimInstanceParam.Value.HashValue|length == 1
+ - dsc_types_actual.NestedCimInstanceParam.Value.HashValue[0].Key == 'a'
+ - dsc_types_actual.NestedCimInstanceParam.Value.HashValue[0].Value == 'a'
+ - dsc_types_actual.NestedCimInstanceParam.Value.HashValue[0]._cim_instance == 'MSFT_KeyValuePair'
+ - dsc_types_actual.NestedCimInstanceParam.Value.IntValue == 300
+ - dsc_types_actual.NestedCimInstanceParam.Value.KeyValue == 'key value'
+ - dsc_types_actual.NestedCimInstanceParam.Value._cim_instance == 'ANSIBLE_xNestedClass'
+
+- name: test DSC with all types older version
+ win_dsc:
+ resource_name: xTestResource
+ module_version: 1.0.0
+ Path: '{{ remote_tmp_dir }}\test-types.json'
+ Ensure: Absent
+ StringParam: string param old
+ CimInstanceArrayParam:
+ - Key: old key
+ StringValue: string old 1
+ IntValue: 0
+ StringArrayValue:
+ - zyx
+ - wvu
+ register: dsc_types_old
+
+- name: get result of test DSC with all types older version
+ slurp:
+ path: '{{ remote_tmp_dir }}\test-types.json'
+ register: dsc_types_old_raw
+
+- name: convert result of test DSC with all types to dict
+ set_fact:
+ dsc_types_old_actual: '{{ dsc_types_old_raw.content | b64decode | from_json }}'
+
+- name: assert test DSC with all types older version
+ assert:
+ that:
+ - dsc_types_old is changed
+ - dsc_types_old.module_version == '1.0.0'
+ - not dsc_types_old.reboot_required
+ - dsc_types_old_actual.Version == '1.0.0'
+ - dsc_types_old_actual.Verbose.Value.IsPresent
+ - dsc_types_old_actual.DefaultParam.Value == 'Default'
+ - dsc_types_old_actual.Ensure.Value == 'Absent'
+ - dsc_types_old_actual.Path.Value == remote_tmp_dir + "\\test-types.json"
+ - dsc_types_old_actual.StringParam.Type == 'System.String'
+ - dsc_types_old_actual.StringParam.Value == 'string param old'
+ - dsc_types_old_actual.CimInstanceArrayParam.Type == 'Microsoft.Management.Infrastructure.CimInstance[]'
+ - dsc_types_old_actual.CimInstanceArrayParam.Value|length == 1
+ - not dsc_types_old_actual.CimInstanceArrayParam.Value[0].Choice is defined # 1.0.0 does not have a Choice option
+ - dsc_types_old_actual.CimInstanceArrayParam.Value[0].IntValue == 0
+ - dsc_types_old_actual.CimInstanceArrayParam.Value[0].Key == 'old key'
+ - dsc_types_old_actual.CimInstanceArrayParam.Value[0].StringArrayValue == ['zyx', 'wvu']
+ - dsc_types_old_actual.CimInstanceArrayParam.Value[0].StringValue == 'string old 1'
+ - dsc_types_old_actual.CimInstanceArrayParam.Value[0]._cim_instance == 'ANSIBLE_xTestClass'