mirror of
https://github.com/PowerShell/PSDesiredStateConfiguration
synced 2026-06-21 13:45:25 +00:00
Fixed DependsOn and other OMI_BaseResource properties (#56)
This commit is contained in:
@@ -399,6 +399,13 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal.CrossPlatform
|
||||
}
|
||||
}
|
||||
|
||||
// as last resort - check if requested class is one of base classes
|
||||
moduleQualifiedResourceName = GetModuleQualifiedResourceName(s_defaultModuleInfoForResource.Item1, s_defaultModuleInfoForResource.Item2.ToString(), className, className);
|
||||
if (GuestConfigClassCache.TryGetValue(moduleQualifiedResourceName, out classCacheEntry))
|
||||
{
|
||||
return classCacheEntry.CimClassInstance;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1323,14 +1330,29 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal.CrossPlatform
|
||||
// MOF-based implementation of this used to generate MOF string representing classes/typeAst and pass it to MMI/MOF deserializer to get CimClass array
|
||||
// Here we are avoiding that roundtrip by constructing the resulting PSObjects directly
|
||||
var className = typeAst.Name;
|
||||
|
||||
var cimClassProperties = new List<PSObject>();
|
||||
string cimSuperClassName = null;
|
||||
if (typeAst.Attributes.Any(a => a.TypeName.GetReflectionAttributeType() == typeof(DscResourceAttribute)))
|
||||
{
|
||||
// In v2 code, PS classes with DscResourceAttribute were automtically inheriting (resource properties) from "OMI_BaseResource"
|
||||
cimSuperClassName = "OMI_BaseResource";
|
||||
|
||||
var moduleQualifiedResourceName = GetModuleQualifiedResourceName(s_defaultModuleInfoForResource.Item1, s_defaultModuleInfoForResource.Item2.ToString(), cimSuperClassName, cimSuperClassName);
|
||||
DscClassCacheEntry baseResource = null;
|
||||
if (ClassCache.TryGetValue(moduleQualifiedResourceName, out baseResource))
|
||||
{
|
||||
dynamic baseProperties = baseResource.CimClassInstance.Properties["ClassProperties"]?.Value;
|
||||
if (baseProperties != null)
|
||||
{
|
||||
foreach(PSObject prop in baseProperties)
|
||||
{
|
||||
cimClassProperties.Add(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cimClassProperties = ProcessMembers(embeddedInstanceTypes, typeAst, className);
|
||||
cimClassProperties.AddRange(ProcessMembers(embeddedInstanceTypes, typeAst, className));
|
||||
|
||||
Queue<object> bases = new Queue<object>();
|
||||
foreach (var b in typeAst.BaseTypes)
|
||||
|
||||
@@ -262,7 +262,7 @@ Describe "All types DSC resource tests" {
|
||||
|
||||
$resource = Get-DscResource | ? {$_.Name -eq "xTestClassResource"}
|
||||
$resource | Should -Not -BeNullOrEmpty
|
||||
$resource.Properties.Count | Should -Be 32
|
||||
$resource.Properties.Count | Should -Be 34
|
||||
|
||||
foreach($dscResourcePropertyInfo in $resource.Properties)
|
||||
{
|
||||
@@ -410,4 +410,33 @@ DSCAllTypesConfig -OutputPath TestDrive:\DSCAllTypesConfig
|
||||
"TestDrive:\DSCAllTypesConfig\localhost.mof" | Should -Exist
|
||||
Get-Content -Raw -Path "TestDrive:\DSCAllTypesConfig\localhost.mof" | Write-Verbose -Verbose
|
||||
}
|
||||
|
||||
It "Check multi-resource configuration compilation with dependencies" {
|
||||
|
||||
[Scriptblock]::Create(@"
|
||||
configuration MultiResourceConfig
|
||||
{
|
||||
Import-DscResource -ModuleName xTestClassResource
|
||||
ResourceForTests1 r1
|
||||
{
|
||||
Prop1 = 'Test'
|
||||
}
|
||||
ResourceForTests2 r2
|
||||
{
|
||||
Prop1 = 'Test'
|
||||
DependsOn = '[ResourceForTests1]r1'
|
||||
}
|
||||
ResourceForTests3 r3
|
||||
{
|
||||
Prop1 = 'Test'
|
||||
DependsOn = '[ResourceForTests1]r1','[ResourceForTests2]r2'
|
||||
}
|
||||
}
|
||||
|
||||
MultiResourceConfig -OutputPath TestDrive:\MultiResourceConfig
|
||||
"@) | Should -Not -Throw
|
||||
|
||||
"TestDrive:\MultiResourceConfig\localhost.mof" | Should -Exist
|
||||
Get-Content -Raw -Path "TestDrive:\MultiResourceConfig\localhost.mof" | Write-Verbose -Verbose
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -261,3 +261,65 @@ class xTestClassResource
|
||||
}
|
||||
}
|
||||
|
||||
[DscResource()]
|
||||
class ResourceForTests1
|
||||
{
|
||||
[DscProperty(Key)]
|
||||
[string] $Prop1
|
||||
|
||||
[void] Set()
|
||||
{
|
||||
}
|
||||
|
||||
[bool] Test()
|
||||
{
|
||||
return $true
|
||||
}
|
||||
|
||||
[ResourceForTests1] Get()
|
||||
{
|
||||
return $this
|
||||
}
|
||||
}
|
||||
|
||||
[DscResource()]
|
||||
class ResourceForTests2
|
||||
{
|
||||
[DscProperty(Key)]
|
||||
[string] $Prop1
|
||||
|
||||
[void] Set()
|
||||
{
|
||||
}
|
||||
|
||||
[bool] Test()
|
||||
{
|
||||
return $true
|
||||
}
|
||||
|
||||
[ResourceForTests2] Get()
|
||||
{
|
||||
return $this
|
||||
}
|
||||
}
|
||||
|
||||
[DscResource()]
|
||||
class ResourceForTests3
|
||||
{
|
||||
[DscProperty(Key)]
|
||||
[string] $Prop1
|
||||
|
||||
[void] Set()
|
||||
{
|
||||
}
|
||||
|
||||
[bool] Test()
|
||||
{
|
||||
return $true
|
||||
}
|
||||
|
||||
[ResourceForTests3] Get()
|
||||
{
|
||||
return $this
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user