Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Improve speed of Test-IsNanoServer function #141

Closed
wants to merge 7 commits into from
Closed

Improve speed of Test-IsNanoServer function #141

wants to merge 7 commits into from

Conversation

X-Guardian
Copy link
Contributor

@X-Guardian X-Guardian commented Apr 18, 2019

Pull Request (PR) description

Currently, the Test-IsNanoServer function calls the Get-ComputerInfo cmdlet to check with the computer is running Nano server or not. Get-ComputerInfo can take 40+ seconds to run each time. This function is called for each user and group resource within a Dsc configuration and therefore can make the Dsc application very slow.

This PR replaces Get-ComputerInfo with checking the registry value at HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels\NanoServer, as documented here: https://msdn.microsoft.com/en-us/library/windows/desktop/hh846315(v=vs.85).aspx

This Pull Request (PR) fixes the following issues

None

Task list

  • Added an entry under the Unreleased section of the change log in the README.md.
    Entry should say what was changed, and how that affects users (if applicable).
  • Resource documentation added/updated in README.md.
  • Resource parameter descriptions added/updated in README.md, schema.mof
    and comment-based help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Resource Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Resource Testing Guidelines.
  • New/changed code adheres to DSC Resource Style Guidelines and Best Practices.

This change is Reviewable

Replace Get-ComputerInfo with Registry Value Test
@codecov-io
Copy link

codecov-io commented Apr 18, 2019

Codecov Report

Merging #141 into dev will decrease coverage by <1%.
The diff coverage is 71%.

Impacted file tree graph

@@         Coverage Diff         @@
##            dev   #141   +/-   ##
===================================
- Coverage    83%    83%   -1%     
===================================
  Files        19     19           
  Lines      2760   2760           
  Branches      4      4           
===================================
- Hits       2305   2303    -2     
- Misses      451    453    +2     
  Partials      4      4

@mhendric
Copy link
Contributor

Hey @X-Guardian , thanks for the contribution. I was looking through your build log, and it looks like you're failing in xMsiPackage. I've actually been troubleshooting the exact same issue over in xPSDesiredStateConfiguration. I have a fix almost ready to go and will try to submit it this week. I'll do the same in this repo.

The problem seems to occur on machines that default to using only SSL3 and TLS 1.0 for .NET, and the fix is to set SchUseStrongCrypto to true on the test machine, which allows TLS 1.1 and TLS 1.2 to be used.

https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls#schusestrongcrypto

Probable fix:

# Make TLS 1.2, TLS 1.1, and TLS 1.0 the default to prevent connection failures on machines
# where [Net.ServicePointManager]::SecurityProtocol is set to Ssl3, Tls
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord -ErrorAction Stop
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord -ErrorAction Stop

@mhendric
Copy link
Contributor

Opened #142 to track the issue above

Copy link
Contributor

@mhendric mhendric left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 4 unresolved discussions (waiting on @X-Guardian)


README.md, line 624 at r2 (raw file):

* Improved speed of Test-IsNanoServer function

This needs to be under the 'Unreleased' section, not underneath an existing version.


DscResources/CommonResourceHelper.psm1, line 11 at r2 (raw file):

Quoted 17 lines of code…
    $ServerLevelsRegKey = 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels'
    If (Test-Path $ServerLevelsRegKey)

    {
        $ServerLevels = Get-ItemProperty -Path $ServerLevelsRegKey
        If ($ServerLevels.NanoServer -eq 1)

        {
            $isNanoServer = $true
        }
        Else
        {
            $isNanoServer = $false
        }
    }
    Else {
        $isNanoServer = $false

Can you make the If and Else all lowercase, and also start local variables with a lowercase letter (serverLevelsRegKey , serverLevels)


DscResources/CommonResourceHelper.psm1, line 12 at r2 (raw file):

Test-Path $ServerLevelsRegKey)

Need a named -Path parameter here


Tests/Unit/CommonResourceHelper.Tests.ps1, line 41 at r2 (raw file):

                Mock -CommandName 'Get-ItemProperty' -MockWith { return $testComputerInfoServerNotNano }

Can you remove the whitespace on the end of this line?

Copy link
Contributor Author

@X-Guardian X-Guardian left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 4 unresolved discussions (waiting on @mhendric)


README.md, line 624 at r2 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
* Improved speed of Test-IsNanoServer function

This needs to be under the 'Unreleased' section, not underneath an existing version.

Done.


DscResources/CommonResourceHelper.psm1, line 11 at r2 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
    $ServerLevelsRegKey = 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels'
    If (Test-Path $ServerLevelsRegKey)

    {
        $ServerLevels = Get-ItemProperty -Path $ServerLevelsRegKey
        If ($ServerLevels.NanoServer -eq 1)

        {
            $isNanoServer = $true
        }
        Else
        {
            $isNanoServer = $false
        }
    }
    Else {
        $isNanoServer = $false

Can you make the If and Else all lowercase, and also start local variables with a lowercase letter (serverLevelsRegKey , serverLevels)

Done.


DscResources/CommonResourceHelper.psm1, line 12 at r2 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
Test-Path $ServerLevelsRegKey)

Need a named -Path parameter here

Done.


Tests/Unit/CommonResourceHelper.Tests.ps1, line 41 at r2 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
                Mock -CommandName 'Get-ItemProperty' -MockWith { return $testComputerInfoServerNotNano }

Can you remove the whitespace on the end of this line?

Done.

Copy link
Contributor

@mhendric mhendric left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mhendric)

@mhendric
Copy link
Contributor

Thanks for the updates @X-Guardian . This will need to be re-based, but I suggest waiting until #143 (pending review) is checked in.

@mhendric mhendric added the on hold The issue or pull request has been put on hold by a maintainer. label Apr 26, 2019
@mhendric
Copy link
Contributor

Hey @X-Guardian , #143 has now been checked in. Can you rebase and see if that resolves your issue?

@mhendric mhendric added waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. and removed on hold The issue or pull request has been put on hold by a maintainer. labels May 24, 2019
@X-Guardian
Copy link
Contributor Author

Hi @mhendric, my branch for this PR seems to have got lost. I've restored the branch on my forked Repo (https://github.com/X-Guardian/PSDscResources/tree/Test-IsNanoServer) but its now not linked to this PR. Anything you can do from your end, or shall I create a new PR?

@mhendric
Copy link
Contributor

Hi @X-Guardian . I've never tried this myself, but I think these instructions are pretty close to what you need to do. But these rely on creating a new PR as well. I'm not aware of any way to continue a PR when the original branch is lost (although I'm by no means a Git expert). Creating a new PR is probably the easiest way to get out of this.

https://github.com/PowerShell/DscResources/blob/master/GettingStartedWithGitHub.md#how-to-continue-working-on-a-pull-request-pr-when-an-author-contributor-is-unable-to-complete-it

@X-Guardian X-Guardian closed this May 24, 2019
@X-Guardian
Copy link
Contributor Author

Replaced by #154

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants