KVM test: kvm_vm.py: make -drive index optional for both images and cdrom ISOs
PATCH 1/9 KVM test: kvm_vm.py: make -drive index optional for both images and cdrom ISOs
--- client/tests/kvm/kvm_vm.py | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
client/tests/kvm/kvm_vm.py +9 -6
@@ -214,16 +214,18 @@ class VM: def add_smp(help, smp): return " -smp %s" % smp - def add_cdrom(help, filename, index=2): + def add_cdrom(help, filename, index=None): if has_option(help, "drive"): - return " -drive file='%s',index=%d,media=cdrom" % (filename, - index) + cmd = " -drive file='%s',media=cdrom" % filename + if index is not None: cmd += ",index=%s" % index + return cmd else: return " -cdrom '%s'" % filename - def add_drive(help, filename, format=None, cache=None, werror=None, - serial=None, snapshot=False, boot=False): + def add_drive(help, filename, index=None, format=None, cache=None, + werror=None, serial=None, snapshot=False, boot=False): cmd = " -drive file='%s'" % filename + if index is not None: cmd += ",index=%s" % index if format: cmd += ",if=%s" % format if cache: cmd += ",cache=%s" % cache if werror: cmd += ",werror=%s" % werror
@@ -362,6 +364,7 @@ class VM: continue qemu_cmd += add_drive(help, get_image_filename(image_params, root_dir), + image_params.get("drive_index"), image_params.get("drive_format"), image_params.get("drive_cache"), image_params.get("drive_werror"),
@@ -414,7 +417,7 @@ class VM: iso = params.get("cdrom") if iso: iso = kvm_utils.get_path(root_dir, iso) - qemu_cmd += add_cdrom(help, iso) + qemu_cmd += add_cdrom(help, iso, 2) # Even though this is not a really scalable approach, # it doesn't seem like we are going to need more than
Signature · 1 line
1.5.4.1
PATCH 2/9 KVM test: allow definition of multiple cdroms
Instead of using 'cdrom_extra', define 'cdroms' similarly to 'images'. Also set -drive indices for cd1 and image1.
Also fix regular expression in tests.cfg.sample, so it doesn't match 'cdroms' when it shouldn't.
Note: if you use your own tests.cfg, you should change the line
cdrom.* ?<= ...
to
cdrom(_.*)? ?<= ...
It won't hurt to do the same for image_name.
--- client/tests/kvm/kvm_vm.py | 19 +++++++------------ client/tests/kvm/tests.cfg.sample | 4 ++-- client/tests/kvm/tests_base.cfg.sample | 10 ++++++++-- 3 files changed, 17 insertions(+), 16 deletions(-)
client/tests/kvm/kvm_vm.py +7 -12
@@ -414,18 +414,13 @@ class VM: if smp: qemu_cmd += add_smp(help, smp) - iso = params.get("cdrom") - if iso: - iso = kvm_utils.get_path(root_dir, iso) - qemu_cmd += add_cdrom(help, iso, 2) - - # Even though this is not a really scalable approach, - # it doesn't seem like we are going to need more than - # 2 CDs active on the same VM. - iso_extra = params.get("cdrom_extra") - if iso_extra: - iso_extra = kvm_utils.get_path(root_dir, iso_extra) - qemu_cmd += add_cdrom(help, iso_extra, 3) + cdroms = kvm_utils.get_sub_dict_names(params, "cdroms") + for cdrom in cdroms: + cdrom_params = kvm_utils.get_sub_dict(params, cdrom) + iso = cdrom_params.get("cdrom") + if iso: + qemu_cmd += add_cdrom(help, kvm_utils.get_path(root_dir, iso), + cdrom_params.get("drive_index")) # We may want to add {floppy_otps} parameter for -fda # {fat:floppy:}/path/. However vvfat is not usually recommended.
client/tests/kvm/tests.cfg.sample +2 -2
@@ -13,8 +13,8 @@ include cdkeys.cfg # * All image files are expected under /tmp/kvm_autotest_root/images/ # * All iso files are expected under /tmp/kvm_autotest_root/isos/ qemu_img_binary = /usr/bin/qemu-img -image_name.* ?<= /tmp/kvm_autotest_root/images/ -cdrom.* ?<= /tmp/kvm_autotest_root/isos/ +image_name(_.*)? ?<= /tmp/kvm_autotest_root/images/ +cdrom(_.*)? ?<= /tmp/kvm_autotest_root/isos/ # Here are the test sets variants. The variant 'qemu_kvm_windows_quick' is # fully commented, the following ones have comments only on noteworthy points
client/tests/kvm/tests_base.cfg.sample +8 -2
@@ -3,9 +3,10 @@ # Define the objects we'll be using vms = vm1 images = image1 +cdroms = cd1 nics = nic1 monitors = humanmonitor1 -login_timeout = 360 + # Choose the main VM and monitor main_vm = vm1 main_monitor = humanmonitor1
@@ -33,8 +34,10 @@ qemu_img_binary = qemu-img smp = 1 mem = 512 image_size = 10G +drive_index_image1 = 0 shell_port = 22 display = vnc +drive_index_cd1 = 2 # Monitor params monitor_type = human
@@ -56,6 +59,7 @@ run_tcpdump = yes # Misc profilers = kvm_stat +login_timeout = 360 # Tests
@@ -1044,7 +1048,9 @@ variants: unattended_install.cdrom: timeout = 7200 finish_program = deps/finish.exe - cdrom_extra = windows/winutils.iso + cdroms += " extracd" + cdrom_extracd = windows/winutils.iso + drive_index_extracd = 3 migrate: migration_test_command = ver && vol migration_bg_command = start ping -t localhost
Signature · 1 line
1.5.4.1
PATCH 3/9 KVM test: rss_file_transfer.py: add convenience functions upload() and download()
--- client/tests/kvm/rss_file_transfer.py | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-)
client/tests/kvm/rss_file_transfer.py +26 -6
@@ -395,6 +395,30 @@ class FileDownloadClient(FileTransferClient): raise +def upload(address, port, src_pattern, dst_path, timeout=60, + connect_timeout=10): + """ + Connect to server and upload files. + + @see: FileUploadClient + """ + client = FileUploadClient(address, port, connect_timeout) + client.upload(src_pattern, dst_path, timeout) + client.close() + + +def download(address, port, src_pattern, dst_path, timeout=60, + connect_timeout=10): + """ + Connect to server and upload files. + + @see: FileDownloadClient + """ + client = FileDownloadClient(address, port, connect_timeout) + client.download(src_pattern, dst_path, timeout) + client.close() + + def main(): import optparse
@@ -418,13 +442,9 @@ def main(): port = int(port) if options.download: - client = FileDownloadClient(address, port) - client.download(src_pattern, dst_path, timeout=options.timeout) - client.close() + download(address, port, src_pattern, dst_path, options.timeout) elif options.upload: - client = FileUploadClient(address, port) - client.upload(src_pattern, dst_path, timeout=options.timeout) - client.close() + upload(address, port, src_pattern, dst_path, options.timeout) if __name__ == "__main__":
Signature · 1 line
1.5.4.1
RFC PATCH 4/9 KVM test: DTM automation program for WHQL tests
This C# program should run on a DTM/WHQL server. It's used by the whql_submission test to schedule and monitor device submission jobs.
Note: the binary is copied to the server at run time, so it doesn't need to be packaged in winutils.iso.
--- client/tests/kvm/deps/whql_submission_15.cs | 254 ++++++++++++++++++++++++++ client/tests/kvm/deps/whql_submission_15.exe | Bin 0 -> 10240 bytes 2 files changed, 254 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/deps/whql_submission_15.cs create mode 100644 client/tests/kvm/deps/whql_submission_15.exe
client/tests/kvm/deps/whql_submission_15.cs new file +254 -0
@@ -0,0 +1,254 @@ +// DTM submission automation program +// Author: Michael Goldish <[email protected]> +// Based on sample code by Microsoft. + +// Note: this program has only been tested with DTM version 1.5. +// It might fail to work with other versions, specifically because it uses +// a few undocumented methods/attributes. + +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 != 5) + { + Console.WriteLine("Error: incorrect number of command line arguments"); + Console.WriteLine("Usage: {0} serverName clientName machinePoolName submissionName timeout", + System.Environment.GetCommandLineArgs()[0]); + return 1; + } + string serverName = args[0]; + string clientName = args[1]; + string machinePoolName = args[2]; + string submissionName = args[3]; + double timeout = Convert.ToDouble(args[4]); + + 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 client machine + IResourcePool rootPool = script.GetResourcePoolByName("$"); + Console.WriteLine("Looking for client machine '{0}'", clientName); + IResource machine = null; + while (true) + { + try + { + machine = rootPool.GetResourceByName(clientName); + } + catch (Exception e) + { + Console.WriteLine("Warning: " + e.Message); + } + // Make sure the machine is valid + if (machine != null && + machine.OperatingSystem != null && + machine.OperatingSystem.Length > 0 && + machine.ProcessorArchitecture != null && + machine.ProcessorArchitecture.Length > 0 && + machine.GetDevices().Length > 0) + break; + System.Threading.Thread.Sleep(1000); + } + Console.WriteLine("Client machine '{0}' found ({1}, {2})", + clientName, machine.OperatingSystem, machine.ProcessorArchitecture); + + // Create machine pool and add client machine to it + // (this must be done because jobs cannot be scheduled for machines in the + // default pool) + try + { + script.CreateResourcePool(machinePoolName, rootPool.ResourcePoolId); + } + catch (Exception e) + { + Console.WriteLine("Warning: " + e.Message); + } + IResourcePool newPool = script.GetResourcePoolByName(machinePoolName); + Console.WriteLine("Moving the client machine to pool '{0}'", machinePoolName); + machine.ChangeResourcePool(newPool); + + // Reset client machine + if (machine.Status != "Ready") + { + Console.WriteLine("Changing the client machine's status to 'Reset'"); + while (true) + { + try + { + machine.ChangeResourceStatus("Reset"); + break; + } + catch (Exception e) + { + Console.WriteLine("Warning: " + e.Message); + } + System.Threading.Thread.Sleep(5000); + } + Console.WriteLine("Waiting for client machine to be ready"); + while (machine.Status != "Ready") + { + try + { + machine = rootPool.GetResourceByName(clientName); + } + catch (Exception e) + { + Console.WriteLine("Warning: " + e.Message); + } + System.Threading.Thread.Sleep(1000); + } + } + Console.WriteLine("Client machine is ready"); + + // Get requested device regex and look for a matching device + Console.WriteLine("Device to test: "); + Regex deviceRegex = new Regex(Console.ReadLine(), RegexOptions.IgnoreCase); + Console.WriteLine("Looking for device '{0}'", deviceRegex); + IDevice device = null; + foreach (IDevice d in machine.GetDevices()) + { + if (deviceRegex.IsMatch(d.FriendlyName)) + { + device = d; + Console.WriteLine("Found device '{0}'", d.FriendlyName); + break; + } + } + if (device == null) + { + Console.WriteLine("Error: device '{0}' not found", deviceRegex); + return 1; + } + + // Create submission + Object[] existingSubmissions = script.GetSubmissionByName(submissionName); + if (existingSubmissions.Length > 0) + { + Console.WriteLine("Submission '{0}' already exists -- removing it", + submissionName); + script.DeleteSubmission(((ISubmission)existingSubmissions[0]).Id); + } + Console.WriteLine("Creating submission '{0}'", submissionName); + ISubmission submission = script.CreateHardwareSubmission(submissionName, + newPool.ResourcePoolId, device.InstanceId); + + // Get DeviceData objects from the user + List<Object> deviceDataList = new List<Object>(); + while (true) + { + ISubmissionDeviceData dd = script.CreateNewSubmissionDeviceData(); + Console.WriteLine("DeviceData name: "); + dd.Name = Console.ReadLine(); + if (dd.Name.Length == 0) + break; + Console.WriteLine("DeviceData data: "); + dd.Data = Console.ReadLine(); + deviceDataList.Add(dd); + } + + // Set the submission's DeviceData + submission.SetDeviceData(deviceDataList.ToArray()); + + // Get descriptors from the user + List<Object> descriptorList = new List<Object>(); + while (true) + { + Console.WriteLine("Descriptor path: "); + string descriptorPath = Console.ReadLine(); + if (descriptorPath.Length == 0) + break; + descriptorList.Add(script.GetDescriptorByPath(descriptorPath)); + } + + // Set the submission's descriptors + submission.SetLogoDescriptors(descriptorList.ToArray()); + + // Create a schedule + ISchedule schedule = script.CreateNewSchedule(); + Console.WriteLine("Scheduling jobs:"); + foreach (IJob j in submission.GetJobs()) + { + Console.WriteLine(" " + j.Name); + schedule.AddDeviceJob(device, j); + } + schedule.AddSubmission(submission); + schedule.SetResourcePool(newPool); + script.RunSchedule(schedule); + + // Wait for jobs to complete + Console.WriteLine("Waiting for all jobs to complete (timeout={0})", timeout); + DateTime endTime = DateTime.Now.AddSeconds(timeout); + int numCompleted = 0, numFailed = 0; + while (numCompleted < submission.GetResults().Length && DateTime.Now < endTime) + { + // Sleep for 30 seconds + System.Threading.Thread.Sleep(30000); + // Count completed submission jobs + numCompleted = 0; + foreach (IResult r in submission.GetResults()) + if (r.ResultStatus != "InProgress") + numCompleted++; + // Report results in a Python readable format and count failed schedule jobs + // (submission jobs are a subset of schedule jobs) + Console.WriteLine(); + Console.WriteLine("---- ["); + numFailed = 0; + foreach (IResult r in schedule.GetResults()) + { + Console.WriteLine(" {"); + Console.WriteLine(" 'job': r'''{0}''',", r.Job.Name); + Console.WriteLine(" 'logs': r'''{0}''',", r.LogLocation); + if (r.ResultStatus != "InProgress") + Console.WriteLine(" 'report': r'''{0}''',", + submission.GetSubmissionResultReport(r)); + Console.WriteLine(" 'status': '{0}',", r.ResultStatus); + Console.WriteLine(" 'pass': {0}, 'fail': {1}, 'notrun': {2}, 'notapplicable': {3}", + r.Pass, r.Fail, r.NotRun, r.NotApplicable); + Console.WriteLine(" },"); + numFailed += r.Fail; + } + Console.WriteLine("] ----"); + } + Console.WriteLine(); + + // Cancel incomplete jobs + foreach (IResult r in schedule.GetResults()) + if (r.ResultStatus == "InProgress") + r.Cancel(); + + // Report failures + if (numCompleted < submission.GetResults().Length) + Console.WriteLine("Some jobs did not complete on time."); + if (numFailed > 0) + Console.WriteLine("Some jobs failed."); + + if (numFailed > 0 || numCompleted < submission.GetResults().Length) + return 1; + + Console.WriteLine("All jobs completed."); + + return 0; + } + catch (Exception e) + { + Console.WriteLine("Error: " + e.Message); + return 1; + } + } + } +}
client/tests/kvm/deps/whql_submission_15.exe new file binary +0 -0
Signature · 1 line
1.5.4.1
RFC PATCH 5/9 KVM test: DTM machine deletion tool for WHQL tests
This C# program should run on a DTM server. It's used by the whql_client_install test to delete the client machine from the server's data store (if listed there) prior to client installation. This seems to be necessary to prevent trouble during testing (like failure to contact the client machine).
Note: the binary is copied to the server at run time, so it doesn't need to be packaged in winutils.iso.
--- client/tests/kvm/deps/whql_delete_machine_15.cs | 82 ++++++++++++++++++++++ client/tests/kvm/deps/whql_delete_machine_15.exe | Bin 0 -> 10240 bytes 2 files changed, 82 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/deps/whql_delete_machine_15.cs create mode 100644 client/tests/kvm/deps/whql_delete_machine_15.exe
client/tests/kvm/deps/whql_delete_machine_15.cs new file +82 -0
@@ -0,0 +1,82 @@ +// DTM machine deletion tool +// Author: Michael Goldish <[email protected]> +// 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; + } + } + } +}
client/tests/kvm/deps/whql_delete_machine_15.exe new file binary +0 -0
Signature · 1 line
1.5.4.1
RFC PATCH 6/9 KVM test: add utility functions start_windows_service() and stop_windows_service()
These utilities use sc to stop and start windows services. They're used by whql_submission and whql_client_install to stop or restart wttsvc on the client machine.
--- client/tests/kvm/kvm_test_utils.py | 46 ++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_test_utils.py +46 -0
@@ -242,6 +242,52 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp", raise +def stop_windows_service(session, service, timeout=120): + """ + Stop a Windows service using sc. + If the service is already stopped or is not installed, do nothing. + + @param service: The name of the service + @param timeout: Time duration to wait for service to stop + @raise: error.TestError is raised if the service can't be stopped + """ + end_time = time.time() + timeout + while time.time() < end_time: + o = session.get_command_output("sc stop %s" % service, timeout=60) + # FAILED 1060 means the service isn't installed. + # FAILED 1062 means the service hasn't been started. + if re.search(r"\bFAILED (1060|1062)\b", o, re.I): + break + time.sleep(1) + else: + raise error.TestError("Could not stop service '%s'" % service) + + +def start_windows_service(session, service, timeout=120): + """ + Start a Windows service using sc. + If the service is already running, do nothing. + If the service isn't installed, fail. + + @param service: The name of the service + @param timeout: Time duration to wait for service to start + @raise: error.TestError is raised if the service can't be started + """ + end_time = time.time() + timeout + while time.time() < end_time: + o = session.get_command_output("sc start %s" % service, timeout=60) + # FAILED 1060 means the service isn't installed. + if re.search(r"\bFAILED 1060\b", o, re.I): + raise error.TestError("Could not start service '%s' " + "(service not installed)" % service) + # FAILED 1056 means the service is already running. + if re.search(r"\bFAILED 1056\b", o, re.I): + break + time.sleep(1) + else: + raise error.TestError("Could not start service '%s'" % service) + + def get_time(session, time_command, time_filter_re, time_format): """ Return the host time and guest time. If the guest time cannot be fetched
Signature · 1 line
1.5.4.1
RFC PATCH 7/9 KVM test: add whql_submission test
whql_submission runs a submission on a given device. It requires a functioning external DTM server which runs rss.exe like regular Windows VMs, preferably with administrator permissions.
The submission is defined by descriptors and device_data objects, which are specified in the config file(s). All jobs of the submission are executed. When all jobs complete, or when the timeout expires, HTML reports are generated and copied to test.debugdir (client/results/default/kvm...whql_submission/debug) and the raw test logs (wtl or xml files) are copied to test.debugdir as well.
--- client/tests/kvm/tests/whql_submission.py | 176 +++++++++++++++++++++++++++++ 1 files changed, 176 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/whql_submission.py
client/tests/kvm/tests/whql_submission.py new file +176 -0
@@ -0,0 +1,176 @@ +import logging, time, os, re +from autotest_lib.client.common_lib import error +import kvm_subprocess, kvm_test_utils, kvm_utils, rss_file_transfer + + +def run_whql_submission(test, params, env): + """ + WHQL submission test: + 1) Log into the guest (the client machine) and into a DTM server machine + 2) Copy the automation program binary (dsso_test_binary) to the server machine + 3) Run the automation program + 4) Pass the program all relevant parameters (e.g. device_data) + 5) Wait for the program to terminate + 6) Parse and report job results + (logs and HTML reports are placed in test.bindir) + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm, 0, 240) + + # Collect parameters + server_address = params.get("server_address") + server_shell_port = int(params.get("server_shell_port")) + server_file_transfer_port = int(params.get("server_file_transfer_port")) + server_studio_path = params.get("server_studio_path", "%programfiles%\\ " + "Microsoft Driver Test Manager\\Studio") + dsso_test_binary = params.get("dsso_test_binary", + "deps/whql_submission_15.exe") + dsso_test_binary = kvm_utils.get_path(test.bindir, dsso_test_binary) + test_device = params.get("test_device") + test_timeout = float(params.get("test_timeout", 600)) + wtt_services = params.get("wtt_services") + + # Restart WTT service(s) on the client + logging.info("Restarting WTT services on client") + for svc in wtt_services.split(): + kvm_test_utils.stop_windows_service(session, svc) + for svc in wtt_services.split(): + kvm_test_utils.start_windows_service(session, svc) + + # Copy dsso_test_binary to the server + rss_file_transfer.upload(server_address, server_file_transfer_port, + dsso_test_binary, server_studio_path, timeout=60) + + # Open a shell session with the server + server_session = kvm_utils.remote_login("nc", server_address, + server_shell_port, "", "", + session.prompt, session.linesep) + + # Get the computer names of the server and client + cmd = "echo %computername%" + server_name = server_session.get_command_output(cmd).strip() + client_name = session.get_command_output(cmd).strip() + session.close() + + # Run the automation program on the server + server_session.get_command_output("cd %s" % server_studio_path) + cmd = "%s %s %s %s %s %s" % (os.path.basename(dsso_test_binary), + server_name, + client_name, + "%s_pool" % client_name, + "%s_submission" % client_name, + test_timeout) + server_session.sendline(cmd) + + # Helper function: wait for a given prompt and raise an exception if an + # error occurs + def find_prompt(prompt): + m, o = server_session.read_until_last_line_matches( + [prompt, server_session.prompt], print_func=logging.info, + timeout=600) + if m != 0: + errors = re.findall("^Error:.*$", o, re.I | re.M) + if errors: + raise error.TestError(errors[0]) + else: + raise error.TestError("Error running automation program: could " + "not find '%s' prompt" % prompt) + + # Tell the automation program which device to test + find_prompt("Device to test:") + server_session.sendline(test_device) + + # Give the automation program all the device data supplied by the user + find_prompt("DeviceData name:") + for dd in kvm_utils.get_sub_dict_names(params, "device_data"): + dd_params = kvm_utils.get_sub_dict(params, dd) + if dd_params.get("dd_name") and dd_params.get("dd_data"): + server_session.sendline(dd_params.get("dd_name")) + server_session.sendline(dd_params.get("dd_data")) + server_session.sendline() + + # Give the automation program all the descriptor information supplied by + # the user + find_prompt("Descriptor path:") + for desc in kvm_utils.get_sub_dict_names(params, "descriptors"): + desc_params = kvm_utils.get_sub_dict(params, desc) + if desc_params.get("desc_path"): + server_session.sendline(desc_params.get("desc_path")) + server_session.sendline() + + # Wait for the automation program to terminate + m, o = server_session.read_up_to_prompt(print_func=logging.info, + timeout=test_timeout + 120) + # (test_timeout + 120 is used here because the automation program is + # supposed to terminate cleanly on its own when test_timeout expires) + server_session.close() + + # Look for test results in the automation program's output + result_summaries = re.findall(r"---- \[.*?\] ----", o, re.DOTALL) + if not result_summaries: + raise error.TestError("The automation program did not return any " + "results") + results = result_summaries[-1].strip("-") + results = eval("".join(results.splitlines())) + + # Download logs and HTML reports from the server + for i, r in enumerate(results): + if "report" in r: + try: + rss_file_transfer.download(server_address, + server_file_transfer_port, + r["report"], test.debugdir) + except rss_file_transfer.FileTransferNotFoundError: + pass + if "logs" in r: + try: + rss_file_transfer.download(server_address, + server_file_transfer_port, + r["logs"], test.debugdir) + except rss_file_transfer.FileTransferNotFoundError: + pass + else: + try: + # Create symlinks to test log dirs to make it easier + # to access them (their original names are not human + # readable) + link_name = "logs_%s" % r["report"].split("\\")[-1] + link_name = link_name.replace(" ", "_") + link_name = link_name.replace("/", "_") + os.symlink(r["logs"].split("\\")[-1], + os.path.join(test.debugdir, link_name)) + except (KeyError, OSError): + pass + + # Print result summary + logging.info("") + logging.info("Result summary:") + name_length = max(len(r.get("job", "")) for r in results) + fmt = "%%-%ds %%-15s %%-8s %%-8s %%-8s %%-15s" % name_length + logging.info(fmt % ("Job", "Status", "Pass", "Fail", "NotRun", "NotApplicable")) + logging.info(fmt % ("---", "------", "----", "----", "------", "-------------")) + for r in results: + logging.info(fmt % (r.get("job"), r.get("status"), + r.get("pass"), r.get("fail"), r.get("notrun"), + r.get("notapplicable"))) + logging.info("(see logs and HTML reports in %s)" % test.debugdir) + + # Fail if the automation program did not terminate on time + if not m: + raise error.TestFail("The automation program did not terminate " + "on time") + + # Fail if there are failed or incomplete jobs + failed_jobs = [r.get("job") for r in results if r.get("fail", 0) > 0] + running_jobs = [r.get("job") for r in results if r.get("notrun", 0) > 0] + errors = [] + if failed_jobs: + errors += ["Jobs failed: %s." % failed_jobs] + if running_jobs: + errors += ["Jobs did not complete on time: %s." % running_jobs] + if errors: + raise error.TestFail(" ".join(errors))
Signature · 1 line
1.5.4.1
RFC PATCH 8/9 KVM test: add whql_client_install test
whql_client_install installs the DTM client on a guest. It requires a functioning external DTM server which runs rss.exe like regular Windows VMs.
--- client/tests/kvm/tests/whql_client_install.py | 110 +++++++++++++++++++++++++ 1 files changed, 110 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/whql_client_install.py
client/tests/kvm/tests/whql_client_install.py new file +110 -0
@@ -0,0 +1,110 @@ +import logging, time, os, re +from autotest_lib.client.common_lib import error +import kvm_subprocess, kvm_test_utils, kvm_utils, rss_file_transfer + + +def run_whql_client_install(test, params, env): + """ + WHQL DTM client installation: + 1) Log into the guest (the client machine) and into a DTM server machine + 2) Stop the DTM client service (wttsvc) on the client machine + 3) Delete the client machine from the server's data store + 4) Rename the client machine (give it a randomly generated name) + 5) Move the client machine into the server's workgroup + 6) Reboot the client machine + 7) Install the DTM client software + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm, 0, 240) + + # Collect test params + server_address = params.get("server_address") + server_shell_port = int(params.get("server_shell_port")) + server_file_transfer_port = int(params.get("server_file_transfer_port")) + server_studio_path = params.get("server_studio_path", "%programfiles%\\ " + "Microsoft Driver Test Manager\\Studio") + server_username = params.get("server_username") + server_password = params.get("server_password") + dsso_delete_machine_binary = params.get("dsso_delete_machine_binary", + "deps/whql_delete_machine_15.exe") + dsso_delete_machine_binary = kvm_utils.get_path(test.bindir, + dsso_delete_machine_binary) + install_timeout = float(params.get("install_timeout", 600)) + install_cmd = params.get("install_cmd") + wtt_services = params.get("wtt_services") + + # Stop WTT service(s) on client + for svc in wtt_services.split(): + kvm_test_utils.stop_windows_service(session, svc) + + # Copy dsso_delete_machine_binary to server + rss_file_transfer.upload(server_address, server_file_transfer_port, + dsso_delete_machine_binary, server_studio_path, + timeout=60) + + # Open a shell session with server + server_session = kvm_utils.remote_login("nc", server_address, + server_shell_port, "", "", + session.prompt, session.linesep) + + # Get server and client information + cmd = "echo %computername%" + server_name = server_session.get_command_output(cmd).strip() + client_name = session.get_command_output(cmd).strip() + cmd = "wmic computersystem get workgroup" + server_workgroup = server_session.get_command_output(cmd).strip() + + # Delete the client machine from the server's data store (if it's there) + server_session.get_command_output("cd %s" % server_studio_path) + cmd = "%s %s %s" % (os.path.basename(dsso_delete_machine_binary), + server_name, client_name) + server_session.get_command_output(cmd, print_func=logging.info) + server_session.close() + + # Rename the client machine + client_name = "autotest_%s" % kvm_utils.generate_random_string(4) + logging.info("Renaming client machine to '%s'" % client_name) + cmd = ('wmic computersystem where name="%%computername%%" rename name="%s"' + % client_name) + s = session.get_command_status(cmd, timeout=600) + if s != 0: + raise error.TestError("Could not rename the client machine") + + # Join the server's workgroup + logging.info("Joining workgroup '%s'" % server_workgroup) + cmd = ('wmic computersystem where name="%%computername%%" call ' + 'joindomainorworkgroup name="%s"' % server_workgroup) + s = session.get_command_status(cmd, timeout=600) + if s != 0: + raise error.TestError("Could not change the client's workgroup") + + # Reboot + session = kvm_test_utils.reboot(vm, session) + + # Access shared resources on the server machine + logging.info("Attempting to access remote share on server") + cmd = r"net use \\%s /user:%s %s" % (server_name, server_username, + server_password) + end_time = time.time() + 120 + while time.time() < end_time: + s = session.get_command_status(cmd) + if s == 0: + break + time.sleep(5) + else: + raise error.TestError("Could not access server share from client " + "machine") + + # Install + logging.info("Installing DTM client (timeout=%ds)", install_timeout) + install_cmd = r"cmd /c \\%s\%s" % (server_name, install_cmd.lstrip("\\")) + s, o = session.get_command_status_output(install_cmd, + timeout=install_timeout) + if s != 0: + raise error.TestError("Client installation failed") + + session.close()
Signature · 1 line
1.5.4.1
RFC PATCH 9/9 KVM test: add WHQL test definitions to tests_base.cfg.sample
The parameters that define submissions (dd_name_*, dd_data_*, desc_path_*) were collected from manually created submissions.
I haven't yet collected the parameters for Windows 2003 and 2008, so for now WHQL tests are disabled for these versions.
This patch also adds a comment in tests.cfg.sample, encouraging the user to specify the DTM server's address and ports there.
Note that this patch renames WinVista.32sp1 to WinVista.32.sp1,
WinVista.32sp2 to WinVista.32.sp2,
WinVista.64sp1 to WinVista.64.sp1 and
WinVista.64sp2 to WinVista.64.sp2.--- client/tests/kvm/tests.cfg.sample | 8 + client/tests/kvm/tests_base.cfg.sample | 230 ++++++++++++++++++++++++-------- 2 files changed, 184 insertions(+), 54 deletions(-)
client/tests/kvm/tests.cfg.sample +8 -0
@@ -73,6 +73,14 @@ variants: only Fedora.13.64 only unattended_install.cdrom boot shutdown +# You may provide information about the DTM server for WHQL tests here: +#whql: +# server_address = 10.20.30.40 +# server_shell_port = 10022 +# server_file_transfer_port = 10023 +# Note that the DTM server must run rss.exe (available under deps/), +# preferably with administrator privileges. + # Uncomment the following lines to enable abort-on-error mode: #abort_on_error = yes #kill_vm.* ?= no
client/tests/kvm/tests_base.cfg.sample +176 -54
291 lines not on this page · raw message
Signature · 1 line
1.5.4.1
Re: [KVM-AUTOTEST PATCH 6/9] [RFC] KVM test: add utility functions start_windows_service() and stop_windows_service()
In reply to Michael GoldishQuoted 25 lines · Michael Goldish
These utilities use sc to stop and start windows services. They're used by
whql_submissionandwhql_client_installto stop or restart wttsvc on the client machine.Signed-off-by Michael Goldish <[email protected]>--- client/tests/kvm/kvm_test_utils.py | 46 ++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-)client/tests/kvm/kvm_test_utils.py +9
-0@@ -242,6 +242,52 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp", raise +def stop_windows_service(session, service, timeout=120): + """ + Stop a Windows service using sc. + If the service is already stopped or is not installed, do nothing. + + @param service: The name of the service + @param timeout: Time duration to wait for service to stop + @raise: error.TestError is raised if the service can't be stopped + """
client/tests/kvm/kvm_test_utils.py def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp", · line 263
Quoted 10 lines
client/tests/kvm/kvm_test_utils.py +10
-0+ end_time = time.time() + timeout + while time.time() < end_time: + o = session.get_command_output("sc stop %s" % service, timeout=60) + # FAILED 1060 means the service isn't installed. + # FAILED 1062 means the service hasn't been started. + if re.search(r"\bFAILED (1060|1062)\b", o, re.I): + break + time.sleep(1) + else: + raise error.TestError("Could not stop service '%s'" % service)
Hi Michael,
How about combine those two function together ? we can also use it do other setup.
def setup_windows_service(session, service, action, timeout=120):
...
# FAILED 1060 means the service isn't installed.
# FAILED 1062 means the service hasn't been started.
# FAILED 1056 means the service is already running.
dict = {
#"$action" : ["$fail_str", "$break_str"]
"stop": ["", "(1060|1062)"],
"start": ["1060", "1056"],
...
...
} end_time = time.time() + timeout
while time.time() < end_time:
o = session.get_command_output("sc %s %s" % service, action, timeout=60)
if re.search(r"\bFAILED %s\b" % dict[action][0], o, re.I):
raise error.TestError("..... %s, %s" % (action, dict[action][0]))
if re.search(r"\bFAILED %s\b" % dict[action][1], o, re.I):
break
...
...
time.sleep(1)
else:
raise error.TestError("Could not %s service '%s'" % (action, service))Quoted 35 lines
client/tests/kvm/kvm_test_utils.py +25
-0+def start_windows_service(session, service, timeout=120): + """ + Start a Windows service using sc. + If the service is already running, do nothing. + If the service isn't installed, fail. + + @param service: The name of the service + @param timeout: Time duration to wait for service to start + @raise: error.TestError is raised if the service can't be started + """ + end_time = time.time() + timeout + while time.time() < end_time: + o = session.get_command_output("sc start %s" % service, timeout=60) + # FAILED 1060 means the service isn't installed. + if re.search(r"\bFAILED 1060\b", o, re.I): + raise error.TestError("Could not start service '%s' " + "(service not installed)" % service) + # FAILED 1056 means the service is already running. + if re.search(r"\bFAILED 1056\b", o, re.I): + break + time.sleep(1) + else: + raise error.TestError("Could not start service '%s'" % service) + + def get_time(session, time_command, time_filter_re, time_format): """ Return the host time and guest time. If the guest time cannot be fetchedSignature · 6 lines
1.5.4.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [KVM-AUTOTEST PATCH 6/9] [RFC] KVM test: add utility functions start_windows_service() and stop_windows_service()
Quoted 54 lines · Amos Kong
Quoted 25 lines · Michael Goldish
These utilities use sc to stop and start windows services. They're used by
whql_submissionandwhql_client_installto stop or restart wttsvc on the client machine.Signed-off-by Michael Goldish <[email protected]>--- client/tests/kvm/kvm_test_utils.py | 46 ++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-)client/tests/kvm/kvm_test_utils.py +9
-0@@ -242,6 +242,52 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp", raise +def stop_windows_service(session, service, timeout=120): + """ + Stop a Windows service using sc. + If the service is already stopped or is not installed, do nothing. + + @param service: The name of the service + @param timeout: Time duration to wait for service to stop + @raise: error.TestError is raised if the service can't be stopped + """client/tests/kvm/kvm_test_utils.py def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp", · line 263
Quoted 10 lines
client/tests/kvm/kvm_test_utils.py +10
-0+ end_time = time.time() + timeout + while time.time() < end_time: + o = session.get_command_output("sc stop %s" % service, timeout=60) + # FAILED 1060 means the service isn't installed. + # FAILED 1062 means the service hasn't been started. + if re.search(r"\bFAILED (1060|1062)\b", o, re.I): + break + time.sleep(1) + else: + raise error.TestError("Could not stop service '%s'" % service)Hi Michael,
How about combine those two function together ? we can also use it do other setup.
def setup_windows_service(session, service, action, timeout=120): ... # FAILED 1060 means the service isn't installed. # FAILED 1062 means the service hasn't been started. # FAILED 1056 means the service is already running. dict = { #"$action" : ["$fail_str", "$break_str"] "stop": ["", "(1060|1062)"], "start": ["1060", "1056"], ... ... }
Quoted 12 lines
end_time = time.time() + timeout
while time.time() < end_time:
o = session.get_command_output("sc %s %s" % service, action, timeout=60)
if re.search(r"\bFAILED %s\b" % dict[action][0], o, re.I):
raise error.TestError("..... %s, %s" % (action, dict[action][0]))
if re.search(r"\bFAILED %s\b" % dict[action][1], o, re.I):
break
...
...
time.sleep(1)
else:
raise error.TestError("Could not %s service '%s'" % (action, service))Personally I think this looks more complicated than having two separate functions.
As for using the function to do other things, what other things did you have in mind? This function runs 'sc start' or 'sc stop' repeatedly with no parameters until an error message is printed. I don't know of any other 'sc' operation that can work this way. ('sc pause' and 'sc continue' won't display error messages when the service is already paused/resumed. 'sc config' and 'sc control' require additional parameters.)
Quoted 39 lines
Quoted 35 lines
client/tests/kvm/kvm_test_utils.py +25
-0+def start_windows_service(session, service, timeout=120): + """ + Start a Windows service using sc. + If the service is already running, do nothing. + If the service isn't installed, fail. + + @param service: The name of the service + @param timeout: Time duration to wait for service to start + @raise: error.TestError is raised if the service can't be started + """ + end_time = time.time() + timeout + while time.time() < end_time: + o = session.get_command_output("sc start %s" % service, timeout=60) + # FAILED 1060 means the service isn't installed. + if re.search(r"\bFAILED 1060\b", o, re.I): + raise error.TestError("Could not start service '%s' " + "(service not installed)" % service) + # FAILED 1056 means the service is already running. + if re.search(r"\bFAILED 1056\b", o, re.I): + break + time.sleep(1) + else: + raise error.TestError("Could not start service '%s'" % service) + + def get_time(session, time_command, time_filter_re, time_format): """ Return the host time and guest time. If the guest time cannot be fetchedSignature · 6 lines
1.5.4.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html