locked
Automated Stop and Start of a test environment in MTM 2010 Lab Center RRS feed

  • Question

  • Hello,

    I have a task to "Shut down" and "Start" an entire test environment (not single virtual machine) in Microsoft Test Manager (MTM) 2010 Lab Center on a daily basis. This task will be scheduled outside working hours and must be automated. I have spent quite a while trying to figure out the best way of achieving this but all my effort has so far failed to yield any results.

    The ideal scenario would be to have a script or program set up as a Windows Scheduled Task on our Hyper-V Host which then runs at say midnight each day to stop and then start the test environment.

    Can I stress that I have no interest in a solution that requires any manual input, as this has got to be fully automated. If anyone has set up something similar they can share or suggest a successfully tested solution, I'd be most grateful. I have attached a screenshot of my test labs as they appear in MTM 2010, just to shed some further light on what I'm talking about, with the manual "Shut down" and "Start" buttons displayed just above the list of test environments. 

     

    Wednesday, July 3, 2013 2:28 PM

Answers

  • From looking at the snapshot, it looks like your environments are 100% Virtual and managed by SCVMM. Is this correct? The reason I ask is that Physical Environments must be dealt with differently. So assuming SCVMM...

    ...I wrote a series of posts a few years ago about how to Start, Stop, Deploy, Delete and Clone environments using the VS2010 Lab Center API's. The final part of the series is here:

    http://www.havecomputerwillcode.com/blog/?p=372

    You will have to write a small application to do this - but I think the sample app in Part 3 should get you nearly all the way there.

    Grey Ham


    Blog: http://www.havecomputerwillcode.com/blog

    Thursday, July 4, 2013 8:28 AM
  • Hi,

    Glad the app could help. It definitely has no instructions :-)

    Unfortunately, to solve your problem, you will need to write a small app and you will need C# knowledge to do it (and to use the TFS SDK's). 

    With regards your other questions:

    To programmatically connect to Team Foundation Server without using a dialog (ie: from the command line), see this post:

    http://geekswithblogs.net/TarunArora/archive/2011/06/18/tfs-2010-sdk-connecting-to-tfs-2010-programmaticallyndashpart-1.aspx

    To start an individual environment, you just need to call the .Start() method on the LabEnvironment object (there is a panel at the bottom of the application in Part 3 - Source Code - that lets you start/stop environments).

    Unfortunately, I don't have a Lab Center 2010 around anymore (the 2012 API's are different) so I can't easily modify my app for your needs or I would. If you can find a seasoned C# developer, it shouldn't take much work for them to convert my sample and Tarun's connection code into a command line utility though.

    Grey Ham


    Blog: http://www.havecomputerwillcode.com/blog

    Thursday, July 4, 2013 10:25 AM

All replies

  • Not sure about Lab VMs but I was using PSEXEC with power shell script to restart my remote machines and other stuff such as build MSI installation remotely.

    I would suggest you to give it a try.

    Thanks,


    Vivek MCP,MCTS

    Wednesday, July 3, 2013 7:16 PM
  • From looking at the snapshot, it looks like your environments are 100% Virtual and managed by SCVMM. Is this correct? The reason I ask is that Physical Environments must be dealt with differently. So assuming SCVMM...

    ...I wrote a series of posts a few years ago about how to Start, Stop, Deploy, Delete and Clone environments using the VS2010 Lab Center API's. The final part of the series is here:

    http://www.havecomputerwillcode.com/blog/?p=372

    You will have to write a small application to do this - but I think the sample app in Part 3 should get you nearly all the way there.

    Grey Ham


    Blog: http://www.havecomputerwillcode.com/blog

    Thursday, July 4, 2013 8:28 AM
  • Thanks Vivek. I will certainly look into that.
    Thursday, July 4, 2013 8:54 AM
  • You're correct on that, i.e. the environments are 100% virtual and are all managed by SCVMM 2008 R2.

    I have also had a chance to try out your Deploy Environments application and I think it's an absolutely brilliant tool. Do you have any user instructions that go with it by any chance? Fortunately for me, I managed to quickly fix the one error that it threw on Line 77 of the DeployToForm.cs file and that then got it to build successfully and generate the EnumerateEnvironments executable.

    Scheduling a Windows Task to run the executable itself is straightforward, but the challenge now is to be able to enable the tool to automatically:

    1) Connect to the required Team Project Collection

    2) Stop and Start a specific Lab environment.

    Any ideas? 

    Thursday, July 4, 2013 9:37 AM
  • Hi,

    Glad the app could help. It definitely has no instructions :-)

    Unfortunately, to solve your problem, you will need to write a small app and you will need C# knowledge to do it (and to use the TFS SDK's). 

    With regards your other questions:

    To programmatically connect to Team Foundation Server without using a dialog (ie: from the command line), see this post:

    http://geekswithblogs.net/TarunArora/archive/2011/06/18/tfs-2010-sdk-connecting-to-tfs-2010-programmaticallyndashpart-1.aspx

    To start an individual environment, you just need to call the .Start() method on the LabEnvironment object (there is a panel at the bottom of the application in Part 3 - Source Code - that lets you start/stop environments).

    Unfortunately, I don't have a Lab Center 2010 around anymore (the 2012 API's are different) so I can't easily modify my app for your needs or I would. If you can find a seasoned C# developer, it shouldn't take much work for them to convert my sample and Tarun's connection code into a command line utility though.

    Grey Ham


    Blog: http://www.havecomputerwillcode.com/blog

    Thursday, July 4, 2013 10:25 AM
  • Greg,

    Thanks ever so much for your sterling effort on this. It's very much appreciated and I honestly can't thank you enough. I will give it a go and hopefully should crack it.

    Reg.

    Friday, July 5, 2013 4:23 PM