SQL Clone Test Environment

Recently we were testing some automation script to delete all clones for a specific image, but when we passed an incorrect image name, it started to delete all clones.  Not a good thing to happen in a production environment.  So, is it possible to install a new instance of the SQL Clone application in a test environment to perform these automation tests without purchasing another license?
Tagged:

Answers

  • Would it be possible to see your script?  I'm curious why it deleted all clones.
  • DavidWNAZDavidWNAZ Posts: 20 Bronze 1
    Sure!
    ________________________________________________________________________________
    Param($ImageName) 

    Connect-SqlClone -ServerUrl 'http://clone.server:14145'

    $image = Get-SqlCloneImage -Name $ImageName
     
    $clones = Get-SqlClone -Image $image
     
    $elapsed = [System.Diagnostics.Stopwatch]::StartNew()
     
    "Started at {0}, removing {1} clones for image ""{2}""" -f $(get-date) , $clones.Count , $image.Name
     
    $clones | foreach { # note - '{' needs to be on same line as 'foreach' !
        $_ | Remove-SqlClone | Wait-SqlCloneOperation
        "Removed clone ""{0}""" -f $_.Name ;
                        };
    "Total Elapsed Time: {0}" -f $($elapsed.Elapsed.ToString())

    _______________________________________________________________________________
  • Thanks!  Two ideas for you:

    1. If you pass in an invalid image name, an error is generated.  You can start the script with an $ErrorActionPreference = 'Stop', which will stop the script on the first error.
    2. Right now, Get-SqlCloneImage is generating an error and setting $image to $null.  If you pass in $null for the -Image parameter to Get-SqlCloneGet-SqlClone will return all of the clones, which is the behavior you're seeing.  You can do an if ($null -eq $image) { return } right after the call to Get-SqlCloneImage, which will also save you from grabbing all the clones.
  • DavidWNAZDavidWNAZ Posts: 20 Bronze 1
    Thanks for the input.  I'll include that once I get a test environment configured.  Still waiting for an answer on that.  I'm still relatively new to PS, so thanks for the tips!
Sign In or Register to comment.