Freigeben über


How to find whether lab environment is in healthy state or not?

MTM provides ability to see all the environments across your lab and one of the thing it shows is whether the environment is healthy or not. By healthy, I mean whether machines in the environment are ready to run tests or are ready to deploy an application or not. Yesterday one of our customer mentioned that she wants to find this out programmatically. So in this blog, I am sharing how to do that programmatically.

  • Login to a machine with tfs object model installed. (The tfs object model gets installed with VS, MTM, Tfs, test controller etc)
  • Open notepad, copy paste the following script and change the highlighted variables as per your setup/deployment.
  • Open a power-shell command prompt and run the modified power-shell script.
  • It should show whether your environment is healthy or not. 

Enjoy !!

(Update: 18/6/2014 Jason Van Eaton, an internal customer pointed out a bug in the post where he correctly mentioned that I am checking for NotReady state twice and am not checking for Offline state. Fixed it now.)

# Define parameters
$tfsCollectionUrl = New-Object System.URI("
https://myserver/tfs/defaultcollection");
$projectName = "myProject";
$environmentName = "myEnvironment";

# Load Client Assembly
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Lab.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Lab.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
  

# Connect to tfs
$tfsCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl);
$labService = $tfsCollection.GetService([Microsoft.TeamFoundation.Lab.Client.LabService]);

# Query for environments
$labEnvironmentQuerySpec = New-Object Microsoft.TeamFoundation.Lab.Client.LabEnvironmentQuerySpec;
$labEnvironmentQuerySpec.Project = $projectName;
$labEnvironmentQuerySpec.Disposition = [Microsoft.TeamFoundation.Lab.Client.LabEnvironmentDisposition]::Active;

$labEnvironments = $labService.QueryLabEnvironments($labEnvironmentQuerySpec);
foreach ($environment in $labEnvironments)
{
$envName = $environment.Name;
if ($envName -eq $environmentName)
{
foreach ($labSystem in $environment.LabSystems)
{
if ($labSystem.State -eq [Microsoft.TeamFoundation.Lab.Client.TestMachineState]::NotReady -Or $labSystem.State -eq [Microsoft.TeamFoundation.Lab.Client.TestMachineState]::Offline)
{
Write-Host $envName -> $labSystem.DisplayName -> $labSystem.State -> UnHealthy;
}
else
{
Write-Host $envName -> $labSystem.DisplayName -> $labSystem.State -> Healthy;
}

      }
}
}

Comments

  • Anonymous
    June 05, 2014
    Thanks so much Aseem for taking out time and helping. You were really quick. Would have taken long for me as I am new with MTM.Could you please point to me articles where I can start reading on MTM and get good hands on.?
  • Anonymous
    June 05, 2014
    Does this work for you Geetika?blogs.msdn.com/.../want-to-know-more-about-mtm.aspxRegardsAseem Bansal
  • Anonymous
    June 05, 2014
    You might also want to go through this link for understanding Lab Management flows in MTM.msdn.microsoft.com/.../dd997438(v=vs.110).aspxRegardsAseem Bansal
  • Anonymous
    June 06, 2014
    Thanks Aseem, Yes, the code you provided worked for me.I was writing a powershell script to use tcm.exe to run tests on multiple suites, configuration and multiple locales. I was trying to find a way to check on env issue and your script helped.I will go through the links you have suggested. Thanks again.I am not able to rate this article. Would like to give 5 star. Do I need to be member to rate this?
  • Anonymous
    June 06, 2014
    Good to know this that it helped, Geetika. To rate it, yes you should login.RegardsAseem Bansal
  • Anonymous
    June 09, 2014
    Hi Aseem,I have a different question. I am running around 4000 test cases at same time.Although an env has more than 1 test agents(2 or 3), I see that tests are running sequentially.Under controller in MTM, for every agent, I see Load distribution as 100. Does that mean only if tests queued more than 100, it will be taken by next agent?I am trying to look for way that the tests are run in parallel and not taking 10 hours :(Thanks for helping,Geetika
  • Anonymous
    August 20, 2014
    The comment has been removed