dsccommunity / HyperVDsc

This module contains DSC resources for deployment and configuration of Microsoft Hyper-V.
MIT License
114 stars 65 forks source link

Fix issue when VHD file mounted #209

Open nyanhp opened 1 year ago

nyanhp commented 1 year ago

Pull Request (PR) description

This PR fixes an issue with Get/Test and the resource VHDFile. If the VHD that files are copied to/from is attached to a running machine, the resource fails and the system is not in the desired state.

This PR skips mounting the VHD if the machine is running. Documentation has been updated to include that change.

This Pull Request (PR) fixes the following issues

Task list


This change is Reviewable

nyanhp commented 1 year ago

Build fails due to https://github.com/dsccommunity/DscResource.DocGenerator/issues/131

nyanhp commented 1 year ago

To whoever owns this module, the build will not work on an Ubuntu worker due to this line: https://github.com/dsccommunity/HyperVDsc/blob/6c0e58362fe9a670d010c2bbeb1983486867e4ec/tests/Unit/Stubs/Hyper-V.stubs.psm1#L4

The error that occurs with every test is similar to this one:

Executing script /home/jhp/HyperVDsc/tests/Unit/HyperVDsc.Common.Tests.ps1
  [-] Error occurred in test script '/home/jhp/HyperVDsc/tests/Unit/HyperVDsc.Common.Tests.ps1' 0ms
    DriveNotFoundException: Cannot find drive. A drive with the name 'C' does not exist.
    at <ScriptBlock>, /home/jhp/HyperVDsc/tests/Unit/Stubs/Hyper-V.stubs.psm1: line 4
    at <ScriptBlock>, /home/jhp/HyperVDsc/tests/Unit/HyperVDsc.Common.Tests.ps1: line 27
    at <ScriptBlock>, /home/jhp/HyperVDsc/output/RequiredModules/Pester/4.10.1/Pester.psm1: line 1111
    at Invoke-Pester<End>, /home/jhp/HyperVDsc/output/RequiredModules/Pester/4.10.1/Pester.psm1: line 1137
    at <ScriptBlock>, /home/jhp/HyperVDsc/output/RequiredModules/Sampler/0.116.1/tasks/Invoke-Pester.pester.build.ps1: line 351
    at *Task, /home/jhp/HyperVDsc/output/RequiredModules/InvokeBuild/5.10.1/Invoke-Build.ps1: line 590
    at *Task, /home/jhp/HyperVDsc/output/RequiredModules/InvokeBuild/5.10.1/Invoke-Build.ps1: line 562
    at *Task, /home/jhp/HyperVDsc/output/RequiredModules/InvokeBuild/5.10.1/Invoke-Build.ps1: line 562
    at *Task, /home/jhp/HyperVDsc/output/RequiredModules/InvokeBuild/5.10.1/Invoke-Build.ps1: line 562
    at <ScriptBlock><End>, /home/jhp/HyperVDsc/output/RequiredModules/InvokeBuild/5.10.1/Invoke-Build.ps1: line 748
    at <ScriptBlock><Begin>, /home/jhp/HyperVDsc/build.ps1: line 506

Can we use a Windows build worker for this repository?

nyanhp commented 1 year ago

@johlju do you know who maintains this module? I am not able to get the build to work. It fails while publishing the test results to codecov.io

johlju commented 1 year ago

Unfortunatly I don't think there is any active maintainer on this module any longer.

johlju commented 1 year ago

I have a look see if I can se anything.

johlju commented 1 year ago

/azp run

azure-pipelines[bot] commented 1 year ago
Azure Pipelines successfully started running 1 pipeline(s).
johlju commented 1 year ago

Please revert that change above and it should work. If not then we have to look for an issue somewhere else, because that is how all pipelines looks.

johlju commented 1 year ago

@nyanhp it seems you renamed the folder DSC_VHD to DSC_Vhd but the rename is not part of the change. Becuase of that this PR suggest to add new files instead of changing the existing resource.

nyanhp commented 1 year ago

@johlju I've reverted the change to the build worker image and the VHD casing. But even with the correct casing, the original issue remains:

Exception: Failed to import classes from file
/home/vsts/work/1/s/source/DSCResources/DSC_VHD/DSC_VHD.schema.mof. Error
Exception calling "ImportClasses" with "3" argument(s): "Unable to load shared
library 'libmi' or one of its dependencies. In order to help diagnose loading
problems, consider setting the LD_DEBUG environment variable: liblibmi: cannot
open shared object file: No such file or directory"
johlju commented 1 year ago

Charge the build stage and test stages (unit and integration if it exist) to use windows-latest as the VM image instead of Ubuntu.

johlju commented 1 year ago

In azure-pipelines.yml

johlju commented 1 year ago

Not sure why the build fails now, something is off with the pipeline files. I don't recognize the error. Have no time to find the cause. Ping me in a week or so and I can help dig.

nyanhp commented 1 year ago

Thanks for your effort @johlju , I assume the renaming VHD to Vhd was the issue. I can see that all tests were passed, only the code coverage could not be reported.

codecov[bot] commented 1 year ago

Codecov Report

Merging #209 (968fd4b) into main (6c0e583) will increase coverage by 0%. The diff coverage is 92%.

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #209   +/-   ##
===================================
  Coverage    83%    83%           
===================================
  Files        11     11           
  Lines      1441   1497   +56     
===================================
+ Hits       1203   1257   +54     
- Misses      238    240    +2     
Impacted Files Coverage Δ
...ces/DSC_VhdFileDirectory/DSC_VhdFileDirectory.psm1 90% <92%> (+1%) :arrow_up: