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

xVHD - Add support for setting disk type (Fixed, Dynamic, Differencing) #77

Merged
merged 10 commits into from
Jul 9, 2017
Merged

Conversation

johnf
Copy link
Contributor

@johnf johnf commented Jan 8, 2017

Add the ability to create Fixed disks

Fixes #72


This change is Reviewable

@msftclas
Copy link

msftclas commented Jan 8, 2017

Hi @johnf, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by Microsoft and real humans are currently evaluating your PR.

TTYL, MSBOT;

@PlagueHO
Copy link
Member

PlagueHO commented Jan 8, 2017

Hi @johnf - are you able to fix the problem in the MOF schema as reported by the AppVeyor tests failing?

@johnf johnf mentioned this pull request Jan 8, 2017
@johnf
Copy link
Contributor Author

johnf commented Jan 8, 2017

Fixed. Dumb typo

@PlagueHO
Copy link
Member

PlagueHO commented Jan 9, 2017

@johnf - awesome job! Thanks for addressing this.

Could you please add an entry to the #Unreleased section in the Readme.md listing the change?

Could you also add this to this parameter to the Examples/Sample_xVHD_DiffVHD.ps1 (and to the same place in the Examples section of the Readme.md).

It might be worth also creating an Examples/Sample_xVHD_FixedVHD.ps1 showing how the resource is used to create a fixed disk (and copy the example to the Readme.md)

Unfortunately this resource doesn't contain any unit tests for xVHD yet so we can't add tests for this change.

Thanks again for all your work on this! It is greatly appreciated.


Reviewed 3 of 3 files at r1.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 65 at r1 (raw file):

        # Type of Vhd to be created
        [ValidateSet("Dynamic","Fixed","Differencing")]
        [String]$Type = "Dynamic",

One thing that may be confusing here is that it would be possible for someone to specify a $Type of 'Dynamic' or 'Fixed' and also a $ParentPath set. This doesn't look like it would cause any problems, but it might imply to users that this was a possible combination of parameters (e.g. a Dynamic Differencing Disk- which isn't of course possible).

It might be worth adding a parameter validation check into the Set-* and Test-* that would throw an exception if an invalid combination of parameters was requested.


Comments from Reviewable

@kwirkykat kwirkykat added the waiting for author response The pull request is waiting for the author to respond to comments in the pull request. label Jan 20, 2017
@johnf
Copy link
Contributor Author

johnf commented Jun 12, 2017

I've updated my branch with your comments.

I added the new Example but in the README rather than add a whole new example I updated the first one to be Fixed.

@bgelens bgelens added needs review The pull request needs a code review. and removed waiting for author response The pull request is waiting for the author to respond to comments in the pull request. labels Jun 28, 2017
@bgelens
Copy link
Contributor

bgelens commented Jul 3, 2017

@johnf We have diverged a bit with the Readme since this PR was created. Examples are no longer part of it. Instead links are added to the example in the Examples folder. Probably a good idea to rebase and address the comments so we can take the PR.

Sorry to put you through this. Let me know if you are not comfortable with concepts as rebasing and such.


Reviewed 1 of 3 files at r1, 4 of 4 files at r2.
Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 64 at r2 (raw file):

        # Type of Vhd to be created
        [ValidateSet("Dynamic","Fixed","Differencing")]

Could you add [Parameter()] on top of the ValidateSet and Place $Type on a new line below [String]


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 83 at r2 (raw file):

    # Check the module combinations make sense
    if($ParentPath -and $Type -ne "Differencing")

You'll also need something like if ($null -eq $parentpath -and $Type -eq 'Differencing'){throw error}


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 151 at r2 (raw file):

                if($vhd.Type -ne $Type)
                {
                    Throw "This module can't convert disk types yet"

Are you planning to implement this, if not, please remove yet 😄


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 205 at r2 (raw file):

        # Type of Vhd to be created
        [ValidateSet("Dynamic","Fixed","Differencing")]

Same comments as with Set-TargetResource apply here


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 227 at r2 (raw file):

    # Check the module combinations make sense
    if($ParentPath -and $Type -ne "Differencing")

And here


Comments from Reviewable

@bgelens bgelens added waiting for author response The pull request is waiting for the author to respond to comments in the pull request. and removed needs review The pull request needs a code review. labels Jul 3, 2017
@bgelens bgelens changed the title Support setting disk type xVHD - Add support for setting disk type (Fixed, Dynamic, Differencing) Jul 3, 2017
@codecov-io
Copy link

codecov-io commented Jul 4, 2017

Codecov Report

Merging #77 into dev will increase coverage by 7%.
The diff coverage is 94%.

Impacted file tree graph

@@         Coverage Diff         @@
##            dev    #77   +/-   ##
===================================
+ Coverage    63%    71%   +7%     
===================================
  Files         9      9           
  Lines      1022   1032   +10     
  Branches     12     12           
===================================
+ Hits        651    733   +82     
+ Misses      359    287   -72     
  Partials     12     12

@johnf
Copy link
Contributor Author

johnf commented Jul 4, 2017

I've rebased

Copy link
Contributor

@bgelens bgelens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable didn't make any sense anymore so switched to GitHub review for now. Couple of points still. Would be greatly appreciated if you can address them.

@@ -75,6 +80,17 @@ function Set-TargetResource
Throw "Please ensure that Hyper-V role is installed with its PowerShell module"
}

# Check the module combinations make sense
if($ParentPath -and $Type -ne "Differencing")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a unit test for this resource. It doesn't have to cover the entire thing but at least validate these parameter conditions are working properly e.g. It 'Should throw when ParentPath defined and Type -ne Diff'

@@ -60,6 +60,11 @@ function Set-TargetResource
# Size of Vhd to be created
[Uint64]$MaximumSizeBytes,

# Type of Vhd to be created
[parameter()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:

[Parameter()]
[ValidateSet('Dynamic', 'Fixed', 'Differencing')]
[String]
$Type = 'Dynamic',


if($null -eq $ParentPath -and $Type -eq "Differencing")
{
Throw "Differencing requires a parent path"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And It 'Should throw when ParentPath is not defined and type is Differencing'

@@ -181,6 +207,11 @@ function Test-TargetResource
[ValidateSet("Vhd","Vhdx")]
[String]$Generation = "Vhd",

# Type of Vhd to be created
[parameter()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as with other comment

@@ -198,7 +229,18 @@ function Test-TargetResource
{
Throw "Either specify ParentPath or MaximumSizeBytes property."
}


# Check the module combinations make sense
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this comment or move it up (so the earlier validation is included under the comment as well) and change the wording so that it says something like, Validating Parameters

@johnf
Copy link
Contributor Author

johnf commented Jul 5, 2017

I written some tests which are close but aren't working quite right.
I'm not a powershell programmer and I don't have an environment at the moment where I can actually run the tests.
And the cycle of doing that via appveyor will take me hours :)

I've ticked allow edits from maintainers so you can commit to my branch if someone else can make them work

@bgelens
Copy link
Contributor

bgelens commented Jul 5, 2017

@johnf I've send in some commits to your repo to make some adjustments.
@PlagueHO could you review this PR (as I contributed the last commits, I would like some other eyes looking at the changes) The added unit tests are just an initial base set for parameter combination validation. Additional tests need to be added and I created an issue to increase code coverage already #119 )


Reviewed 2 of 3 files at r3, 2 of 2 files at r5.
Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


Comments from Reviewable

@bgelens bgelens added needs review The pull request needs a code review. and removed waiting for author response The pull request is waiting for the author to respond to comments in the pull request. labels Jul 5, 2017
… process. Fixed a bug when MaximumSizeBytes was not specified, resize was wrongly initialized.
@PlagueHO
Copy link
Member

PlagueHO commented Jul 7, 2017

Sorry about the minor nitpicks. Generally things look fine, but if you're going to do some rework on this module at some point then I've made some suggested changes. One other thing that you would want to address in any rework: Move strings to strings file.


Reviewed 1 of 4 files at r2, 2 of 2 files at r6.
Review status: all files reviewed at latest revision, 13 unresolved discussions.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 83 at r2 (raw file):

Previously, bgelens (Ben Gelens) wrote…

You'll also need something like if ($null -eq $parentpath -and $Type -eq 'Differencing'){throw error}

I'd generally recommend creating an Assert-ParametersValid function in a resource and using that to validate the parameter input - with throwing if they are invalid. But don't worry about doing that here. Just a suggestion for future.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 233 at r3 (raw file):

Previously, bgelens (Ben Gelens) wrote…

Could you remove this comment or move it up (so the earlier validation is included under the comment as well) and change the wording so that it says something like, Validating Parameters

See my earlier comments about parameter validation in Assert-ParametersValid - again not at all required here. Just if anyone is doing rework on this module that would be the recommended pattern.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 37 at r6 (raw file):

    if(!(Get-Module -ListAvailable -Name Hyper-V))
    {
        Throw 'Please ensure that Hyper-V role is installed with its PowerShell module'

Not required here (so please don't worry about fixing in this PR), but just a suggestion: convert to standard way of throwing custom errors. E.g. New-InvalidOperationException.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 137 at r6 (raw file):

    # If vhd should be absent, delete it
    if($Ensure -eq 'Absent')

Nitpick: Need space between if and ( - just use global search/replace to fix them all.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 197 at r6 (raw file):

        # Vhd file is not present
        catch

Hope I'm not being too much of a pain, but won't this catch any kind of error - not just missing VHD files?


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 212 at r6 (raw file):

                }
                $null = New-VHD @params
            }

Please add blank line after end of code blocks.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 282 at r6 (raw file):

    # Check if Hyper-V module is present for Hyper-V cmdlets
    if(!(Get-Module -ListAvailable -Name Hyper-V))

Not required, please don't worry about doing this now, just a suggestion for future: The recommended way of doing this is to move it to an Assert-HyperVRequired function.


Examples/Sample_xVHD_FixedVHD.ps1, line 5 at r6 (raw file):

    param
    (
        [string[]]$NodeName = 'localhost',

Please convert parameter block to be standard format. E.g.

[Parameter()]
[String[]]
$NodeName = 'localhost',

[Parameter(Mandatory = $true)]
[String]
$Name

Tests/Unit/MSFT_xVHD.tests.ps1, line 47 at r6 (raw file):

                    return $false
                }
                It 'Should throw when the module is missing' {

Add blank line here.


Tests/Unit/MSFT_xVHD.tests.ps1, line 126 at r6 (raw file):

                Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } -MockWith {
                    return $false
                }

Please add blank line here.


Tests/Unit/MSFT_xVHD.tests.ps1, line 162 at r6 (raw file):

                }

                #"Generation $Generation should match ParentPath extension $($ParentPath.Split('.')[-1])"

Space after #


Tests/Unit/MSFT_xVHD.tests.ps1, line 164 at r6 (raw file):

                #"Generation $Generation should match ParentPath extension $($ParentPath.Split('.')[-1])"
                Mock -CommandName Test-Path -MockWith { $true }
                It 'Should throw when file extension and generation have a mismatch' {

Please add blank line here.


Comments from Reviewable

@bgelens
Copy link
Contributor

bgelens commented Jul 8, 2017

No worries, keep up with the nitpicks!

I've made some changes per your findings. Please approve these if they are to your liking 😄

I'm not going to improve / enhance this resource further within the scope of this PR. The additions I made to it, felt needed to have this PR merged (most important: adding the test cases which resulted in some of the code being changed due to bug findings 😉 )
So further enhancements need to be addressed in a new PR. I've logged an issue #121 which should kick start the work on this.


Reviewed 2 of 2 files at r6.
Review status: 3 of 7 files reviewed at latest revision, 12 unresolved discussions.


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 137 at r6 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Nitpick: Need space between if and ( - just use global search/replace to fix them all.

Done


DSCResources/MSFT_xVHD/MSFT_xVHD.psm1, line 197 at r6 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Hope I'm not being too much of a pain, but won't this catch any kind of error - not just missing VHD files?

You are not, it is true and I was not happy with this myself. I already had made some changes to this PR original contributors code as this was actually the case with the type mismatch .
I'm not planning to reevaluate this resource in this PR but I've logged an issue #121


Examples/Sample_xVHD_FixedVHD.ps1, line 5 at r6 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Please convert parameter block to be standard format. E.g.

[Parameter()]
[String[]]
$NodeName = 'localhost',

[Parameter(Mandatory = $true)]
[String]
$Name

Done


Tests/Unit/MSFT_xVHD.tests.ps1, line 47 at r6 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Add blank line here.

Done


Tests/Unit/MSFT_xVHD.tests.ps1, line 126 at r6 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Please add blank line here.

Done


Tests/Unit/MSFT_xVHD.tests.ps1, line 162 at r6 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Space after #

Done


Tests/Unit/MSFT_xVHD.tests.ps1, line 164 at r6 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Please add blank line here.

Done


Comments from Reviewable

@PlagueHO
Copy link
Member

PlagueHO commented Jul 8, 2017

Thanks for all your work on getting this PR out 😁 Nearly there! You're doing great stuff.


Reviewed 1 of 4 files at r2, 4 of 4 files at r7.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


Examples/Sample_xVHD_DiffVHD.ps1, line 19 at r7 (raw file):

        [string]$Generation = "Vhd",

        [ValidateSet("Dynamic","Fixed","Differencing")]

This file looks like it still needs it's parameter style fixed.


Comments from Reviewable

@bgelens
Copy link
Contributor

bgelens commented Jul 8, 2017

OK please check again 😉


Reviewed 4 of 4 files at r7, 4 of 4 files at r8.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Examples/Sample_xVHD_DiffVHD.ps1, line 19 at r7 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

This file looks like it still needs it's parameter style fixed.

Done plus all other xVHD examples


Comments from Reviewable

@PlagueHO
Copy link
Member

PlagueHO commented Jul 8, 2017

Great job and done!

:lgtm_strong:


Reviewed 4 of 4 files at r8.
Review status: :shipit: all files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

@bgelens bgelens merged commit c044b73 into dsccommunity:dev Jul 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review The pull request needs a code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants