Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VhdFile: Test-TargetResource is always $false for directories #176

Open
DmitryMashkov-DM opened this issue Dec 9, 2019 · 2 comments
Open
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.

Comments

@DmitryMashkov-DM
Copy link

Details of the scenario you tried and the problem that is occurring

Try to include a 'Directory' resource like
MSFT_xFileDirectory {
SourcePath = 'C:\Program Files\WindowsPowerShell\Modules\xActiveDirectory'
DestinationPath = "\Program Files\WindowsPowerShell\Modules"
type = 'Directory'
Recurse = $True
Ensure='Present'
}
The subtree copies correctly.
Then run the Test-DscConfiguration or wait for the Monitor action on complete. There's a false result.
The root cause is that LastWriteTime for the directory is the time of last file operation within the directory, meaning it will never match the timestamp of original directory. SHA-* algorithm also not applicable.

Verbose logs showing the problem

VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] SourcePath => C:\Program
Files\WindowsPowerShell\Modules\xActiveDirectory
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] Type => Directory
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] Ensure => True
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] Content =>
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] DestinationPath => \Program
Files\WindowsPowerShell\Modules
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] Force => False
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] Attributes =>
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] Recurse => True
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] Testing the file with relative VHD
destination \Program Files\WindowsPowerShell\Modules
VERBOSE: [DESKTOP-1NHIAMI]: [[xVhdFile]Inject DC1] Test returned False
VERBOSE: [DESKTOP-1NHIAMI]: LCM: [ End Test ] [[xVhdFile]Inject DC1] False in 1.2560 seconds.

Suggested solution to the issue

Rewrite ItemHasChanged to separately process directories and files.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Configuration LabDCs
{
    Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -module xHyper-V
    Import-DscResource -ModuleName 'xPSDesiredStateConfiguration'
xVhdFile "Inject"
{
    VhdPath =  "C:\temp\OSDisk.vhdx"
    FileDirectory =  @(

        # xActiveDirectory
        MSFT_xFileDirectory {
            SourcePath = 'C:\Program Files\WindowsPowerShell\Modules\xActiveDirectory\'
            DestinationPath = "\Program Files\WindowsPowerShell\Modules\" 
            type    = 'Directory'
            Recurse = $True
	    Ensure='Present'
        }
    )
    DependsOn = "[xVhd]$($DCName[0])"
}
    }
}

The operating system the target node is running

OsName : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture : 64-bit
WindowsVersion : 2004
WindowsBuildLabEx : 19037.1.amd64fre.vb_release.191202-1231
OsLanguage : en-US
OsMuiLanguages : {en-US, ru-RU}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.19037.1
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19037.1
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

3.17.0.0

@aromano2 aromano2 added the needs investigation The issue needs to be investigated by the maintainers or/and the community. label Jan 30, 2020
@aromano2
Copy link

aromano2 commented Jan 30, 2020

@DmitryMashkov-DM thanks for opening this issue. I have confirmed the issue really stems from using Copy-Item since it doesn't copy the metadata associated for the item. The way I'd like to proceed is replace the use of Copy-Item with robocopy.

@johlju I see that SqlServerDsc already has a helper function that implements robocopy: https://github.com/dsccommunity/SqlServerDsc/blob/master/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1. Would we be able to put this helper function in a more central location so that any DSC module could benefit from its use? Maybe here https://github.com/dsccommunity/DscResource.Common/tree/master/source/Public?

@aromano2 aromano2 added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. and removed needs investigation The issue needs to be investigated by the maintainers or/and the community. labels Jan 30, 2020
@johlju
Copy link
Member

johlju commented Jan 30, 2020

Absolutely! That would be great to have it there. Then we can reuse it in SqlServerDsc from there.

@johlju johlju changed the title xVHDFile: Test-TargetResource is always $false for directories VhdFile: Test-TargetResource is always $false for directories Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

3 participants