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

add feature for Host Power Policy Setting #17

Closed
wants to merge 10 commits into from

Conversation

rockaut
Copy link
Contributor

@rockaut rockaut commented Dec 17, 2018

Integrated new resource for VMHostPowerPolicy
Included Configuration file
Missing Unit tests because of issue #16

Signed-off-by: Markus Fischbacher fischbacher.markus@gmail.com

Integrated new resource for VMHostPowerPolicy
Included Configuration file
Missing Unit tests because of issue vmware#16

Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
Source/VMware.vSphereDSC/VMware.vSphereDSC.Helper.psm1 Outdated Show resolved Hide resolved
Source/VMware.vSphereDSC/VMware.vSphereDSC.psm1 Outdated Show resolved Hide resolved
Source/VMware.vSphereDSC/VMware.vSphereDSC.psm1 Outdated Show resolved Hide resolved
Source/VMware.vSphereDSC/VMware.vSphereDSC.psm1 Outdated Show resolved Hide resolved
Source/VMware.vSphereDSC/VMware.vSphereDSC.psm1 Outdated Show resolved Hide resolved
Source/VMware.vSphereDSC/VMware.vSphereDSC.psm1 Outdated Show resolved Hide resolved
Source/VMware.vSphereDSC/VMware.vSphereDSC.psm1 Outdated Show resolved Hide resolved
Source/VMware.vSphereDSC/VMware.vSphereDSC.psm1 Outdated Show resolved Hide resolved
Copy link
Contributor

@SimeonGerginov SimeonGerginov left a comment

Choose a reason for hiding this comment

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

You should fix the things I left in the other comments.

@vmwclabot
Copy link
Member

@rockaut, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

on @SimeonGerginov suggestions

Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
Will reimplement it with enum/strings later

Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
Cleaned some code too.

Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
@rockaut
Copy link
Contributor Author

rockaut commented Dec 20, 2018

May you check again please?
I changed most off your requests and also implemented the unit tests (hopefully to your satisfaction ;-)

Regarding the enum for the power policy - i will implement that later on.

Copy link
Contributor

@SimeonGerginov SimeonGerginov left a comment

Choose a reason for hiding this comment

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

Good job. I have one last request - if you can update your fork, because I have extracted the resources in separate files and added build script. So when you do that run the tests again, so we can be sure that everything is alright. After that I will merge it. Once again, good job !

@rockaut
Copy link
Contributor Author

rockaut commented Dec 20, 2018

For clarification... should we run the build script prior to commit?

@SimeonGerginov
Copy link
Contributor

Yes, for now run the build script prior to commit.

@rockaut
Copy link
Contributor Author

rockaut commented Jan 4, 2019

I checked out dev branch again and getting tons of unit test errors. I merged dev into my branch and cant get the unit tests for PowerSettings working again. The errors on my class resembles more or less the errors for the current classes.

Context Invoking with default resource properties
  [-] Should call the Connect-VIServer mock with the passed server and credentials once 372ms
    PSInvalidCastException: Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    PSInvalidCastException: Cannot create object of type "VMware.Vim.HostConfig". Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    RuntimeException: Cannot create object of type "VMware.Vim.HostConfig". Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    at ExecuteBlock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 1123
    at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 966
    at <ScriptBlock><Process>, <No file>: line 64
    at GetVMHost, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 122
    at Set, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 871
    at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\Tests\Unit\VMHostPowerPolicySettings.Unit.Tests.ps1: line 90
  [-] Should call Get-VMHost mock with the passed server and name once 49ms
    PSInvalidCastException: Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    PSInvalidCastException: Cannot create object of type "VMware.Vim.HostConfig". Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    RuntimeException: Cannot create object of type "VMware.Vim.HostConfig". Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    at ExecuteBlock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 1123
    at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 966
    at <ScriptBlock><Process>, <No file>: line 64
    at GetVMHost, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 122
    at Set, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 871
    at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\Tests\Unit\VMHostPowerPolicySettings.Unit.Tests.ps1: line 100
  [-] Should not call Set-HostPowerPolicy as power policy defaults to 2 55ms
    PSInvalidCastException: Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    PSInvalidCastException: Cannot create object of type "VMware.Vim.HostConfig". Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    RuntimeException: Cannot create object of type "VMware.Vim.HostConfig". Cannot convert the "VMware.Vim.PowerSystemInfo" value of type "VMware.Vim.PowerSystemInfo" to type "VMware.Vim.PowerSystemInfo".
    at ExecuteBlock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 1123
    at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 966
    at <ScriptBlock><Process>, <No file>: line 64
    at GetVMHost, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 122
    at Set, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 871
    at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\Tests\Unit\VMHostPowerPolicySettings.Unit.Tests.ps1: line 110

@rockaut
Copy link
Contributor Author

rockaut commented Jan 4, 2019

For example one of the errors for VMHostNtpSettings

    Describing VMHostNtpSettings\Get
      [-] Should call the Connect-VIServer mock with the passed server and credentials once 131ms
        InvalidOperationException: The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [NtpConfig <VMware.Vim.HostNtpConfig>]
        PSInvalidCastException: Cannot create object of type "VMware.Vim.HostDateTimeConfig". The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [N
tpConfig <VMware.Vim.HostNtpConfig>]
        RuntimeException: Cannot create object of type "VMware.Vim.HostDateTimeConfig". The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [NtpConf
ig <VMware.Vim.HostNtpConfig>]
        at ExecuteBlock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 1123
        at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 966
        at <ScriptBlock><Process>, <No file>: line 64
        at GetVMHost, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 122
        at Get, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 758
        at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\Tests\Unit\VMHostNtpSettings.Unit.Tests.ps1: line 921
      [-] Should call Get-VMHost mock with the passed server and name once 45ms
        InvalidOperationException: The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [NtpConfig <VMware.Vim.HostNtpConfig>]
        PSInvalidCastException: Cannot create object of type "VMware.Vim.HostDateTimeConfig". The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [N
tpConfig <VMware.Vim.HostNtpConfig>]
        RuntimeException: Cannot create object of type "VMware.Vim.HostDateTimeConfig". The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [NtpConf
ig <VMware.Vim.HostNtpConfig>]
        at ExecuteBlock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 1123
        at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 966
        at <ScriptBlock><Process>, <No file>: line 64
        at GetVMHost, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 122
        at Get, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 758
        at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\Tests\Unit\VMHostNtpSettings.Unit.Tests.ps1: line 931
      [-] Should match the properties retrieved from the server 48ms
        InvalidOperationException: The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [NtpConfig <VMware.Vim.HostNtpConfig>]
        PSInvalidCastException: Cannot create object of type "VMware.Vim.HostDateTimeConfig". The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [N
tpConfig <VMware.Vim.HostNtpConfig>]
        RuntimeException: Cannot create object of type "VMware.Vim.HostDateTimeConfig". The Id property was not found for the VMware.Vim.HostDateTimeConfig object. The available property is: [TimeZone <System.String>] , [NtpConf
ig <VMware.Vim.HostNtpConfig>]
        at ExecuteBlock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 1123
        at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Functions\Mock.ps1: line 966
        at <ScriptBlock><Process>, <No file>: line 64
        at GetVMHost, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 122
        at Get, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\VMware.vSphereDSC.psm1: line 758
        at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\Tests\Unit\VMHostNtpSettings.Unit.Tests.ps1: line 941

@vmwclabot
Copy link
Member

@rockaut, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link
Member

@rockaut, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link
Member

@rockaut, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link
Member

@rockaut, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link
Member

@rockaut, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
@SimeonGerginov
Copy link
Contributor

Are the Unit Tests still failing after the new commits ?

Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
Signed-off-by: Markus Fischbacher <fischbacher.markus@gmail.com>
@rockaut
Copy link
Contributor Author

rockaut commented Jan 7, 2019

@SimeonGerginov no, after merging with current dev now all green again.

Tests completed in 23.31s
Tests Passed: 163, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0

Code coverage report:
Covered 94,84 % of 543 analyzed Commands in 1 File.
Executing script C:\Program Files\WindowsPowerShell\Modules\VMware.vSphereDSC\Tests\Unit\VMHostPowerPolicySettings.Unit.Tests.ps1

  Describing VMHostPowerPolicySettings

    Describing VMHostPowerPolicySettings\Set

      Context Invoking with default resource properties
        [+] Should call the Connect-VIServer mock with the passed server and credentials once 381ms
        [+] Should call Get-VMHost mock with the passed server and name once 31ms
        [+] Should not call Set-HostPowerPolicy as power policy defaults to 2 35ms

      Context Invoking with same resource properties
        [+] Should call the Connect-VIServer mock with the passed server and credentials once 97ms
        [+] Should call Get-VMHost mock with the passed server and name once 29ms
        [+] Should not call Set-HostPowerPolicy as power policy is equal 27ms

      Context Invoking with changed resource properties
        [+] Should call the Connect-VIServer mock with the passed server and credentials once 164ms
        [+] Should call Get-VMHost mock with the passed server and name once 32ms
        [+] Should call Set-HostPowerPolicy as power policy is changed 44ms

    Describing VMHostPowerPolicySettings\Test

      Context Invoking with default resource properties
        [+] Should call the Connect-VIServer mock with the passed server and credentials once 150ms
        [+] Should call Get-VMHost mock with the passed server and name once 37ms
        [+] Should return $true as resource defaults to 2 24ms

      Context Invoking with updated resource properties
        [+] Should return $false as mock policy is changed to 1 105ms

      Context Invoking with updated resource but equal policy
        [+] Should return $true as mock policy is only changed to 2 78ms

    Describing VMHostPowerPolicySettings\Get

      Context Invoking with default resource properties
        [+] Should call the Connect-VIServer mock with the passed server and credentials once 144ms
        [+] Should call Get-VMHost mock with the passed server and name once 32ms
        [+] Should return the resource with the properties passed from the server 44ms

Copy link
Contributor

@SimeonGerginov SimeonGerginov left a comment

Choose a reason for hiding this comment

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

Good work ! There are little issues that needs to be fixed ! And after that you need to add Integration Tests and Resource documentation.

}

Configuration VMHostPowerPolicySettings_Config
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the Configuration and Node opening brackets on the same line for consistency with other configurations.

Host setting for power policy
#>
[DscProperty(Mandatory)]
[System.Int32] $PowerPolicy = 2
Copy link
Contributor

Choose a reason for hiding this comment

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

For simplicity set the type to be [int].

[System.Int32] $PowerPolicy = 2

[void] Set()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Move all opening brackets to the same line in the whole class.

$vmHost = $this.GetVMHost()

$vmHostCurrentPowerPolicy = $vmHost.ExtensionData.Config.PowerSystemInfo.CurrentPolicy
$shouldUpdateVMHostPowerPolicy = $this.ShouldUpdateVMHostPowerPolicy($vmHostCurrentPowerPolicy)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the call to the helper method here is redundant, because if we got here that means that the Test() method returned false so the PowerPolicy should be updated.

{
$this.ConnectVIServer()
$vmHost = $this.GetVMHost()
$vmHostPowerPolicy = $vmHost.ExtensionData.Config.PowerSystemInfo.CurrentPolicy
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to $vmHostCurrentPowerPolicy.

$this.ConnectVIServer()
$vmHost = $this.GetVMHost()

$result.Name = $this.Name
Copy link
Contributor

Choose a reason for hiding this comment

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

The Name should be retrieved from the server: $result.Name = $vmHost.Name.


Returns a boolean value indicating if the VMHost Power policy should be updated.
#>
[bool] ShouldUpdateVMHostPowerPolicy($vmHostCurrentPowerPolicy)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this method is redundant - you can just move the One line to the Test method.


public override int GetHashCode()
{
if( this.CurrentPolicy == null ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the bracket on a new line.

@@ -1,9 +1,9 @@
<#
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this file from the PR as Travis will take care of updating the content of it.

@@ -855,6 +855,66 @@ class VMHostNtpSettings : VMHostBaseDSC {
}
}

[DscResource()]
Copy link
Contributor

Choose a reason for hiding this comment

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

The same comment as for the psd1 file.

@SimeonGerginov SimeonGerginov added the enhancement New feature or request label Jan 7, 2019
@SimeonGerginov
Copy link
Contributor

@rockaut if you can update your pull request to merge into master instead of dev. (Or after you are ready create new PR).

@SimeonGerginov
Copy link
Contributor

SimeonGerginov commented Jan 11, 2019

@rockaut as we announced last week today we are deleting the dev branch. So when you are ready with the latest changes from the review, please create new Pull Request to the master branch.

To delete the dev branch we need to close all Pull Requests to it. Are you ok with closing this PR and creating new one to the master branch ?

@rockaut
Copy link
Contributor Author

rockaut commented Jan 11, 2019 via email

@SimeonGerginov
Copy link
Contributor

SimeonGerginov commented Jan 11, 2019

So @rockaut , can I close this one or will you close it?

@rockaut
Copy link
Contributor Author

rockaut commented Jan 11, 2019

will redo on master

@rockaut rockaut closed this Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants