From patchwork Thu Jul 22 10:14:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 113544 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6MAEHMJ001696 for ; Thu, 22 Jul 2010 10:14:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756127Ab0GVKOL (ORCPT ); Thu, 22 Jul 2010 06:14:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10481 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754944Ab0GVKOF (ORCPT ); Thu, 22 Jul 2010 06:14:05 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6MAE3Bp013505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 22 Jul 2010 06:14:03 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6MAE1Qg026003; Thu, 22 Jul 2010 06:14:02 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o6MADwpo009886; Thu, 22 Jul 2010 06:14:00 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH v2 2/5] [RFC] KVM test: DTM machine deletion tool for WHQL tests Date: Thu, 22 Jul 2010 13:14:16 +0300 Message-Id: <1279793659-22486-2-git-send-email-mgoldish@redhat.com> In-Reply-To: <1279793659-22486-1-git-send-email-mgoldish@redhat.com> References: <1279793659-22486-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 22 Jul 2010 10:14:18 +0000 (UTC) diff --git a/client/tests/kvm/deps/whql_delete_machine_15.cs b/client/tests/kvm/deps/whql_delete_machine_15.cs new file mode 100644 index 0000000..1d78a6d --- /dev/null +++ b/client/tests/kvm/deps/whql_delete_machine_15.cs @@ -0,0 +1,82 @@ +// DTM machine deletion tool +// Author: Michael Goldish +// Based on sample code by Microsoft. + +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using Microsoft.DistributedAutomation.DeviceSelection; +using Microsoft.DistributedAutomation.SqlDataStore; + +namespace automate0 +{ + class AutoJob + { + static int Main(string[] args) + { + if (args.Length != 2) + { + Console.WriteLine("Error: incorrect number of command line arguments"); + Console.WriteLine("Usage: {0} serverName clientName", + System.Environment.GetCommandLineArgs()[0]); + return 1; + } + string serverName = args[0]; + string clientName = args[1]; + + try + { + // Initialize DeviceScript and connect to data store + Console.WriteLine("Initializing DeviceScript object"); + DeviceScript script = new DeviceScript(); + Console.WriteLine("Connecting to data store"); + script.ConnectToNamedDataStore(serverName); + + // Find the client machine + IResourcePool rootPool = script.GetResourcePoolByName("$"); + Console.WriteLine("Looking for client machine '{0}'", clientName); + IResource machine = rootPool.GetResourceByName(clientName); + if (machine == null) + { + Console.WriteLine("Client machine not found"); + return 0; + } + Console.WriteLine("Client machine '{0}' found ({1}, {2})", + clientName, machine.OperatingSystem, machine.ProcessorArchitecture); + + // Change the client machine's status to 'unsafe' + Console.WriteLine("Changing the client machine's status to 'Unsafe'"); + try + { + machine.ChangeResourceStatus("Unsafe"); + } + catch (Exception e) + { + Console.WriteLine("Warning: " + e.Message); + } + while (machine.Status != "Unsafe") + { + try + { + machine = rootPool.GetResourceByName(clientName); + } + catch (Exception e) + { + Console.WriteLine("Warning: " + e.Message); + } + System.Threading.Thread.Sleep(1000); + } + + // Delete the client machine from datastore + Console.WriteLine("Deleting client machine from data store"); + script.DeleteResource(machine.Id); + return 0; + } + catch (Exception e) + { + Console.WriteLine("Error: " + e.Message); + return 1; + } + } + } +}