This topic contains 1 reply, has 2 voices, and was last updated by
May 3, 2019 at 4:02 am #154866ParticipantTopics: 1Replies: 0Points: 34Rank: Member
I've been working with DSC for about 2 years now and am surprised by how little I have found on this topic. I come from an application development background so I have high expectations of my local development process. Specifically:
- Easily list dependencies in 1 place. Use that list for both local development and in production deployments.
- Rapid iterations of change code => build code => test change => repeat. Rapid meaning 1 – 10 seconds.
My current process does not meet my expectations. I'm hoping others are willing to share their setup so I can spot ways to improve. Here is how I do it:
- Azure Automation pull server
- Local Windows 10 dev machine
- Target DSC node – an Azure VM. OS varies but is usually Windows Server 2012 R2
This is how I used to do it:
- Deploy the VM. Do not register it to Azure Automation.
- Log into the VM.
- Install git, VS Code, clone repo.
- Source code has all PowerShell modules in it. This means 3rd party OS (gross, I know) and custom modules we wrote.
- Source code has DSC configs.
- Custom build script copies all modules to a directory in the PSModulesPath.
- Custom build script complies the config (dot sourced).
- Custom build script applies the config to localhost with Start-DscConfiguration.
- Rapidly repeat steps 6 – 8 to work through any compilation or runtime errors.
- When task is complete, check in changes to modules & config.
- Delete the VM.
- Push modules to Azure Automation. All modules needed are in the project so we know we are deploying the same versions we just tested.
- Push configs to Azure Automation. Compile them.
- Deploy the VM to Azure. This time, let it register to Azure Automation.
- Very rapid feedback when developing both configs and custom modules.
- Setting up a dev machine on the target DSC node is cumbersome. Imagine if the DSC failed on step 13. I now have to set the whole thing up again to troubleshoot.
- Obvious problem – 3rd party modules are included in the project. This is fixed in the next process described below.
This is the direction I'm heading for an improved process:
- Deploy a VM to Azure. Let it register with Azure Automation pull server. (Assume a minimal or empty DSC config exists just to let the initial registration succeed).
- On my local workstation, Install-Module all modules my config depends on.
- Compile the config (dot source). Iterate to work through compilation errors.
- Upload the mof(s) to Azure Automation.
- Remote into the Azure VM and trigger an on-demand pull with Update-DscConfiguration.
- Review errors in Event logs.
- Repeat from 2 – 6 until task is complete.
- Deploy all 3rd party and custom modules to Azure Automation using an ARM template or similar.
- Let Azure Automation comple the DSC.
- Verify the config was applied successfully.
- Check in changes.
The one variation of this is if I need to author a custom DSC module. In this case, I'd also add a symlink in step 2.
- No need to setup dev tools on the target DSC node. Can just use my local workstation.
- Removed source controlled 3rd party modules from my project. I can now just install the package and version I want, when I want it.
- There is no single manifest for modules. Notice step 2 uses Install-Module and step 8 uses something else. We must roll our own manifest to prevent simple mistakes.
- Feedback loop is slower. The time it takes to see the results of a change in this process is significantly slower than what was used in process A.
How do you do it?
May 3, 2019 at 6:23 am #154935ParticipantTopics: 1Replies: 44Points: 140Rank: Participant
That's a great question, and I'm also surprised by how few people ask that question...
the TL,DR is... Test-Kitchen...
Now in a bit more details, although I feel I already talked about it a lot (maybe not enough):
There are different elements you want to test: Custom DSC Resource, Composite, Configuration and types of tests such as Unit, Integration and "Operation Validation" tests, where appropriate...
From your description you seem to be focused on testing your configuration, or maybe also a bit of Custom DSC Resources, so I'll quickly cover those only.
Test-Kitchen is a testing harness enabling Test-Driven Infrastructure development that handles and abstracts the repetitive tasks of create/test/destroy Nodes & configurations. It's, at core, a single node testing tool (you can't test multi-nodes inter-dependency out of the box).
Stuart Preston (From Chef) and I, have talked about it during last PS Conf EU, watch the video for an introduction.
I've also wrote about the benefit and workflow for DSC in details in a blog post, a while ago.
So the workflow is roughly:
- you dev your module/config
kitchen createto create the VM
kitchen convergeto apply the config
kitchen verifyto run the tests
kitchen destroyto remove the VM
- All those can be abstracted behind a simple
- Test-Kitchen (and the libs) allows you to pull required modules from a gallery
- You can use a driver for Azure, or Hyper-V, Vagrant, AWS and other...
The downside when using a cloud provider is the Added Delay. Local virtualisation usually can run a (relatively simple) end to end test in about 5min (from creating the VM to Destroy). Some configs can be faster (Diff disks, Linked Clone, better HW...).
There's much more to it (i.e. test matrix with multiple suites on multiple platforms...), but feel free to look at the links and ask further question.
Side note, that does not remove the need for further integration testing in Azure (if that's your prod environment), such as making sure the Group of nodes work together...
You must be logged in to reply to this topic.