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

ActiveDirectoryDsc: Proof of Concept - Running local integration tests #592

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

johlju
Copy link
Member

@johlju johlju commented Apr 12, 2020

Pull Request (PR) description

The goal I had was to be able to run the integration tests on a VM in Hyper-V using Pester and get the Pester output in the console on the host. I had this laying around for a long time now, and spent the weekend converting it to handle the new pipeline which helped with a few steps, and then I wanted to finish this to a point where it is was working.
This is a PoC of that which now runs three of the integration tests in a Hyper-V VM. Comments appreciated! 😄

There are many manual steps to get to a point where we can run tests. I like to see if we can use any automation tool to help with this, all of this or parts of this. Tools like AutomatedLab, LabBuilder, Lability, or Test Kitchen might help.
The reason I focused on using Hyper-V is the seemless integration with PowerShell Direct.

I like to extend this PoC to all the integrations tests we have and also setting up child domain. I looking to have 4 nodes in the lab depending on the memory usage needed by the host.

README.md: https://github.com/dsccommunity/ActiveDirectoryDsc/blob/2d86b1767f3b8240744e9c73904e04be51a7a514/Tests/README.md

Todo:

  • Lower the memory for each VM but still being able to run the integration tests (currently 4GB per VM)
  • Fix the rest of the available integration tests so they run.
  • Setup 2 DC's in parent and 2 DC's in child (and potentially read-only DC's and different sites) - memory usage will limit us here.
  • Run integration tests using certificate

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (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 Community Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Community Testing Guidelines.
  • New/changed code adheres to DSC Community Style Guidelines.

This change is Reviewable

@johlju johlju added the discussion The issue is a discussion. label Apr 12, 2020
Copy link
Contributor

@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 14 files reviewed, 12 unresolved discussions (waiting on @johlju)


Tests/README.md, line 21 at r1 (raw file):

>**Note:** All these steps are expected to be run in the same elevated
>PowerShell prompt. It also expect that you have downloaded the appropriate

It also expects


Tests/README.md, line 27 at r1 (raw file):

<!-- markdownlint-disable MD031 - Fenced code blocks should be surrounded by blank lines -->
1. Create a Hyper-VM (Generation 2). In an elevated PowerShell prompt run
   this.

this:


Tests/README.md, line 68 at r1 (raw file):

   C:\Windows\System32\SysPrep\sysprep.exe /quiet /generalize /oobe /shutdown
  1. Create the folder where we store the exported image. This folder can

where we will store


Tests/README.md, line 135 at r1 (raw file):

   Get-VM -Name $vmNames | Start-VM -Verbose
  1. On each started VM finish the installation by configure the following

configuring


Tests/README.md, line 146 at r1 (raw file):

### Test prerequisites

The host for the virtual machines must have access to Internet. The

the Internet.


Tests/README.md, line 148 at r1 (raw file):

The host for the virtual machines must have access to Internet. The
below steps assumes the virtual machines that should run the integration
test are only connect to a private virtual switch and does not have access

only connected to a private virtual switch and do not have access


Tests/README.md, line 151 at r1 (raw file):

to the Internet.

The blow steps *must* be run in a elevated PowerShell console.

below steps


Tests/README.md, line 154 at r1 (raw file):

<!-- markdownlint-disable MD031 - Fenced code blocks should be surrounded by blank lines -->
1. Change to folder to root of your local working repository

Change directory to the root


Tests/README.md, line 297 at r1 (raw file):

several times. The integration tests that depend on an already existing
domain can be run several times without reverting to the checkpoint. The
resources that need a clean environment are the resources that configures

configure


Tests/README.md, line 300 at r1 (raw file):

the domain, e.g. `ADDomain` and `ADDomainController`.

1. Change to folder to root of your local working repository

Change directory to the root


Tests/TestHelpers/Prepare-DscLab-dc01.ps1, line 41 at r1 (raw file):

    }
}

Format to align hash table properties.


Tests/TestHelpers/Prepare-DscLab-dc02.ps1, line 41 at r1 (raw file):

    }
}

Format to align hash table properties

@X-Guardian
Copy link
Contributor

Hi @johlju, just a few grammar/typo fixes in reviewable.

Unfortunately, I don't have a Hyper-V host to test it with (my home lab is ESXi).

The way I have been running the integration tests is by git cloning the whole repo onto my test domain controller, then running build.ps1 build then invoke-pester on the relevant integration test. I see you are proposing to remove the code that runs Initialize-TestEnvironment from each integration test, what affect will that have on this process?

@johlju
Copy link
Member Author

johlju commented Apr 13, 2020

I see you are proposing to remove the code that runs Initialize-TestEnvironment from each integration test, what affect will that have on this process?

Yes it will, but maybe we shouldn't break your scenario 🤔 I will figure out a way so both ways works.

I tried to use the build process to initiate the tests but that is not 100% when the node reboots since the Initialize-TestEnvironment sets the machine PSModulePath and then Restore-TestEnvironment removes it at the end of the tests, meaning that after a reboot the configuration cannot be run automatically because the modules cannot be found. But for integration tests that will not reboot it works though. Maybe we can solve this by not running Restore-TestEnvironment if a resource requested a reboot? 🤔

try 
{
    # ...

    $DscConfigurationStatus = Get-DscConfigurationStatus
    if ($DscConfigurationStatus.RebootRequested)
    {
        return
    }

    # ...
}
finally
{
    if ($DscConfigurationStatus.RebootRequested)
    {
        Write-Warning 'A Reboot has been requested by the DSC. Please reboot then re-run the test'
    }
    else
    {
        Restore-TestEnvironment -TestEnvironment $script:testEnvironment
    }
}

@johlju johlju requested a review from X-Guardian April 13, 2020 11:40
Copy link
Member Author

@johlju johlju 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 14 files reviewed, 12 unresolved discussions (waiting on @X-Guardian)


Tests/README.md, line 21 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

It also expects

Done.


Tests/README.md, line 27 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

this:

Done.


Tests/README.md, line 68 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

where we will store

Done.


Tests/README.md, line 135 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

configuring

Done.


Tests/README.md, line 146 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

the Internet.

Done.


Tests/README.md, line 148 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

only connected to a private virtual switch and do not have access

Done.


Tests/README.md, line 151 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

below steps

Done.


Tests/README.md, line 154 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

Change directory to the root

Done.


Tests/README.md, line 297 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

configure

Done.


Tests/README.md, line 300 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

Change directory to the root

Done.


Tests/TestHelpers/Prepare-DscLab-dc01.ps1, line 41 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

Format to align hash table properties.

Done.


Tests/TestHelpers/Prepare-DscLab-dc02.ps1, line 41 at r1 (raw file):

Previously, X-Guardian (Simon Heather) wrote…

Format to align hash table properties

Done.

@johlju
Copy link
Member Author

johlju commented Apr 13, 2020

I added a section for VMware as you described it. I have VMware ESXi as well but it is not as easy as running remote scripts like Hyper-V is, but did see that PowerCLI has the Invoke-VMScript that could be used to not need to RDP into a VM I have to dig around this, but let's focus get one scenario working first. I figure most contributors have a Windows 10 with Hyper-V available, though they might not have memory needed to run VMs. :/ @X-Guardian are you running everything in a remote PowerShell Session (like Enter-PSSession) or do you RDP into the VM?

In this Hyper-V scenario I want to look into:

  • AutomatedLab that can help lower the steps need in the two first sections. After reading the blog article by @jpomfret it looks like there are just a few steps getting clean servers up; https://jesspomfret.com/automatedlab-sql-server/
  • Using the build pipeline as discussed above (it will help setting up certificate too).
  • (plus something else I forgot while writing this 😄)

@johlju johlju added the waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. label Apr 13, 2020
@X-Guardian
Copy link
Contributor

I RDP onto the VM, and it is a very manual process. Agreed you should initially focus on Hyper-V and getting to an automated process.

@johlju
Copy link
Member Author

johlju commented Apr 25, 2020

I will get back to this PR eventually. But need to give SqlServerDsc much needed love first.

@stale
Copy link

stale bot commented May 11, 2020

Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again.

@stale stale bot added the abandoned The pull request has been abandoned. label May 11, 2020
@johlju johlju changed the base branch from master to main January 5, 2021 16:30
@stale stale bot removed the abandoned The pull request has been abandoned. label Jan 5, 2021
@stale
Copy link

stale bot commented Jan 19, 2021

Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again.

@stale stale bot added the abandoned The pull request has been abandoned. label Jan 19, 2021
@stale stale bot removed the abandoned The pull request has been abandoned. label Apr 30, 2022
@johlju johlju removed the discussion The issue is a discussion. label May 1, 2022
@codecov
Copy link

codecov bot commented May 1, 2022

Codecov Report

Merging #592 (84c9de0) into main (b2838d9) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #592   +/-   ##
===================================
  Coverage    98%    98%           
===================================
  Files        25     25           
  Lines      3471   3471           
===================================
  Hits       3402   3402           
  Misses       69     69           

@stale
Copy link

stale bot commented Jun 12, 2022

Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again.

@stale stale bot added the abandoned The pull request has been abandoned. label Jun 12, 2022
@stale stale bot removed the abandoned The pull request has been abandoned. label Aug 14, 2022
@stale
Copy link

stale bot commented Sep 20, 2022

Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again.

@stale stale bot added the abandoned The pull request has been abandoned. label Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abandoned The pull request has been abandoned. 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.

Create Integration Tests for Resources
2 participants