diff mbox

[2/5] Fixing exception raising to be compliant with the autotest coding standard.

Message ID 1243019807-21078-2-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues May 22, 2009, 7:16 p.m. UTC
On kvm autotest, we are raising exceptions like:

raise error.TestError, "Error message"

When the preferred form is:

raise error.TestError("Error message")

This change converts all occurrences of exception raising to the preferred form.
---
 client/tests/kvm_runtest_2/kvm_guest_wizard.py  |    8 +-
 client/tests/kvm_runtest_2/kvm_install.py       |   18 +++---
 client/tests/kvm_runtest_2/kvm_preprocessing.py |    4 +-
 client/tests/kvm_runtest_2/kvm_runtest_2.py     |    2 +-
 client/tests/kvm_runtest_2/kvm_tests.py         |   70 +++++++++++-----------
 client/tests/kvm_runtest_2/stepmaker.py         |    8 +-
 6 files changed, 55 insertions(+), 55 deletions(-)
diff mbox

Patch

diff --git a/client/tests/kvm_runtest_2/kvm_guest_wizard.py b/client/tests/kvm_runtest_2/kvm_guest_wizard.py
index 46de723..d24537f 100644
--- a/client/tests/kvm_runtest_2/kvm_guest_wizard.py
+++ b/client/tests/kvm_runtest_2/kvm_guest_wizard.py
@@ -133,16 +133,16 @@  def barrier_2(vm, words, fail_if_stuck_for, stuck_detection_history, output_dir,
 def run_steps(test, params, env):
     vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
     if not vm:
-        raise error.TestError, "VM object not found in environment"
+        raise error.TestError("VM object not found in environment")
     if not vm.is_alive():
-        raise error.TestError, "VM seems to be dead; Guestwizard requires a living VM"
+        raise error.TestError("VM seems to be dead; Guestwizard requires a living VM")
 
     steps_filename = params.get("steps")
     if not steps_filename:
-        raise error.TestError, "Steps filename not specified"
+        raise error.TestError("Steps filename not specified")
     steps_filename = os.path.join(test.bindir, "steps", steps_filename)
     if not os.path.exists(steps_filename):
-        raise error.TestError, "Steps file not found: %s" % steps_filename
+        raise error.TestError("Steps file not found: %s" % steps_filename)
 
     fail_if_stuck_for = params.get("fail_if_stuck_for")
     if fail_if_stuck_for:
diff --git a/client/tests/kvm_runtest_2/kvm_install.py b/client/tests/kvm_runtest_2/kvm_install.py
index 1b3bb47..7cde643 100755
--- a/client/tests/kvm_runtest_2/kvm_install.py
+++ b/client/tests/kvm_runtest_2/kvm_install.py
@@ -36,11 +36,11 @@  def run_kvm_install(test, params, env):
         if not repo:
             message = "KVM git repository path not specified"
             logging.error(message)
-            raise error.TestError, message
+            raise error.TestError(message)
         if not user_repo:
             message = "KVM user git repository path not specified"
             logging.error(message)
-            raise error.TestError, message
+            raise error.TestError(message)
         __install_kvm_from_git(test, srcdir, repo, user_repo, branch, tag,
                                user_tag, lbranch)
 
@@ -51,7 +51,7 @@  def run_kvm_install(test, params, env):
         if not release_dir:
             message = "Release dir not specified"
             logging.error(message)
-            raise error.TestError, message
+            raise error.TestError(message)
         __install_kvm_release(test, srcdir, release_dir, release_tag)
 
     # install from snapshot
@@ -61,7 +61,7 @@  def run_kvm_install(test, params, env):
         if not snapshot_dir:
             message = "Snapshot dir not specified"
             logging.error(message)
-            raise error.TestError, message
+            raise error.TestError(message)
         __install_kvm_from_snapshot(test, srcdir, snapshot_dir, snapshot_date)
 
     # install from tarball
@@ -70,7 +70,7 @@  def run_kvm_install(test, params, env):
         if not tarball:
             message = "Local tarball filename not specified"
             logging.error(message)
-            raise error.TestError, message
+            raise error.TestError(message)
         __install_kvm_from_local_tarball(test, srcdir, tarball)
 
     # install from local sources
@@ -81,7 +81,7 @@  def run_kvm_install(test, params, env):
     else:
         message = "Invalid installation mode: '%s'" % install_mode
         logging.error(message)
-        raise error.TestError, message
+        raise error.TestError(message)
 
     # load kvm modules (unless requested not to)
     if params.get('load_modules', "yes") == "yes":
@@ -95,7 +95,7 @@  def __cleanup_dir(dir):
         if dirs or files:
             message = "Directory \'%s\' is not empty" % dir
             logging.error(message)
-            raise error.TestError, message
+            raise error.TestError(message)
 
 def __install_kvm_release(test, srcdir, release_dir, release_tag):
     if not release_tag:
@@ -208,7 +208,7 @@  def __load_kvm_modules():
     if utils.system("grep kvm /proc/modules 1>/dev/null", ignore_status=True) == 0:
         message = "Failed to remove old KVM modules"
         logging.error(message)
-        raise error.TestError, message
+        raise error.TestError(message)
 
     logging.info("Loading new KVM modules...")
     os.chdir("kernel")
@@ -224,7 +224,7 @@  def __load_kvm_modules():
     if utils.system("grep kvm_%s /proc/modules 1>/dev/null" %(vendor), ignore_status=True) != 0:
         message = "Failed to load KVM modules"
         logging.error(message)
-        raise error.TestError, message
+        raise error.TestError(message)
 
 def __install_kvm(test, srcdir):
     # create destination dir
diff --git a/client/tests/kvm_runtest_2/kvm_preprocessing.py b/client/tests/kvm_runtest_2/kvm_preprocessing.py
index a233f7c..a3ffa72 100644
--- a/client/tests/kvm_runtest_2/kvm_preprocessing.py
+++ b/client/tests/kvm_runtest_2/kvm_preprocessing.py
@@ -35,7 +35,7 @@  def preprocess_image(test, params):
         if not kvm_vm.create_image(params, qemu_img_path, image_dir):
             message = "Could not create image"
             logging.error(message)
-            raise error.TestError, message
+            raise error.TestError(message)
 
 
 def preprocess_vm(test, params, env, name):
@@ -84,7 +84,7 @@  def preprocess_vm(test, params, env, name):
         if not vm.create(name, params, qemu_path, image_dir, iso_dir, for_migration):
             message = "Could not start VM"
             logging.error(message)
-            raise error.TestError, message
+            raise error.TestError(message)
 
     scrdump_filename = os.path.join(test.debugdir, "pre_%s.ppm" % name)
     vm.send_monitor_cmd("screendump %s" % scrdump_filename)
diff --git a/client/tests/kvm_runtest_2/kvm_runtest_2.py b/client/tests/kvm_runtest_2/kvm_runtest_2.py
index 5371d4b..5a1f0fc 100644
--- a/client/tests/kvm_runtest_2/kvm_runtest_2.py
+++ b/client/tests/kvm_runtest_2/kvm_runtest_2.py
@@ -77,7 +77,7 @@  class kvm_runtest_2(test.test):
                 if not routine_obj:
                     message = "Unsupported test type: %s" % type
                     logging.error(message)
-                    raise error.TestError, message
+                    raise error.TestError(message)
                 # If we don't have the test routine yet...
                 if not routine_obj.routine:
                     # Dynamically import the module
diff --git a/client/tests/kvm_runtest_2/kvm_tests.py b/client/tests/kvm_runtest_2/kvm_tests.py
index 90a87db..efd8b6f 100644
--- a/client/tests/kvm_runtest_2/kvm_tests.py
+++ b/client/tests/kvm_runtest_2/kvm_tests.py
@@ -12,15 +12,15 @@  import scan_results
 def run_boot(test, params, env):
     vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
     if not vm:
-        raise error.TestError, "VM object not found in environment"
+        raise error.TestError("VM object not found in environment")
     if not vm.is_alive():
-        raise error.TestError, "VM seems to be dead; Test requires a living VM"
+        raise error.TestError("VM seems to be dead; Test requires a living VM")
 
     logging.info("Waiting for guest to be up...")
 
     session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
     if not session:
-        raise error.TestFail, "Could not log into guest"
+        raise error.TestFail("Could not log into guest")
 
     logging.info("Logged in")
 
@@ -30,7 +30,7 @@  def run_boot(test, params, env):
         logging.info("Reboot command sent; waiting for guest to go down...")
 
         if not kvm_utils.wait_for(lambda: not session.is_responsive(), 120, 0, 1):
-            raise error.TestFail, "Guest refuses to go down"
+            raise error.TestFail("Guest refuses to go down")
 
         session.close()
 
@@ -38,7 +38,7 @@  def run_boot(test, params, env):
 
         session = kvm_utils.wait_for(vm.ssh_login, 120, 0, 2)
         if not session:
-            raise error.TestFail, "Could not log into guest after reboot"
+            raise error.TestFail("Could not log into guest after reboot")
 
         logging.info("Guest is up again")
 
@@ -49,16 +49,16 @@  def run_migration(test, params, env):
     src_vm_name = params.get("migration_src")
     vm = kvm_utils.env_get_vm(env, src_vm_name)
     if not vm:
-        raise error.TestError, "VM '%s' not found in environment" % src_vm_name
+        raise error.TestError("VM '%s' not found in environment" % src_vm_name)
     if not vm.is_alive():
-        raise error.TestError, "VM '%s' seems to be dead; Test requires a living VM" % src_vm_name
+        raise error.TestError("VM '%s' seems to be dead; Test requires a living VM" % src_vm_name)
 
     dest_vm_name = params.get("migration_dst")
     dest_vm = kvm_utils.env_get_vm(env, dest_vm_name)
     if not dest_vm:
-        raise error.TestError, "VM '%s' not found in environment" % dest_vm_name
+        raise error.TestError("VM '%s' not found in environment" % dest_vm_name)
     if not dest_vm.is_alive():
-        raise error.TestError, "VM '%s' seems to be dead; Test requires a living VM" % dest_vm_name
+        raise error.TestError("VM '%s' seems to be dead; Test requires a living VM" % dest_vm_name)
 
     pre_scrdump_filename = os.path.join(test.debugdir, "migration_pre.ppm")
     post_scrdump_filename = os.path.join(test.debugdir, "migration_post.ppm")
@@ -66,14 +66,14 @@  def run_migration(test, params, env):
     # See if migration is supported
     s, o = vm.send_monitor_cmd("help info")
     if not "info migrate" in o:
-        raise error.TestError, "Migration is not supported"
+        raise error.TestError("Migration is not supported")
 
     # Log into guest and get the output of migration_test_command
     logging.info("Waiting for guest to be up...")
 
     session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
     if not session:
-        raise error.TestFail, "Could not log into guest"
+        raise error.TestFail("Could not log into guest")
 
     logging.info("Logged in")
 
@@ -88,7 +88,7 @@  def run_migration(test, params, env):
     s, o = vm.send_monitor_cmd(cmd)
     if s:
         logging.error("Migration command failed (command: %r, output: %r)" % (cmd, o))
-        raise error.TestFail, "Migration command failed"
+        raise error.TestFail("Migration command failed")
 
     # Define some helper functions
     def mig_finished():
@@ -113,7 +113,7 @@  def run_migration(test, params, env):
 
     # Wait for migration to finish
     if not kvm_utils.wait_for(mig_finished, 90, 2, 2, "Waiting for migration to finish..."):
-        raise error.TestFail, "Timeout elapsed while waiting for migration to finish"
+        raise error.TestFail("Timeout elapsed while waiting for migration to finish")
 
     # Report migration status
     if mig_succeeded():
@@ -123,7 +123,7 @@  def run_migration(test, params, env):
             message = "Migration failed"
         else:
             message = "Migration ended with unknown status"
-        raise error.TestFail, message
+        raise error.TestFail(message)
 
     # Get 'post' screendump
     dest_vm.send_monitor_cmd("screendump %s" % post_scrdump_filename)
@@ -153,7 +153,7 @@  def run_migration(test, params, env):
 
     session = dest_vm.ssh_login()
     if not session:
-        raise error.TestFail, "Could not log into guest after migration"
+        raise error.TestFail("Could not log into guest after migration")
 
     logging.info("Logged in after migration")
 
@@ -166,21 +166,21 @@  def run_migration(test, params, env):
         logging.info("Command: %s" % params.get("migration_test_command"))
         logging.info("Output before:" + kvm_utils.format_str_for_message(reference_output))
         logging.info("Output after:" + kvm_utils.format_str_for_message(output))
-        raise error.TestFail, "Command produced different output before and after migration"
+        raise error.TestFail("Command produced different output before and after migration")
 
 
 def run_autotest(test, params, env):
     vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
     if not vm:
-        raise error.TestError, "VM object not found in environment"
+        raise error.TestError("VM object not found in environment")
     if not vm.is_alive():
-        raise error.TestError, "VM seems to be dead; Test requires a living VM"
+        raise error.TestError("VM seems to be dead; Test requires a living VM")
 
     logging.info("Logging into guest...")
 
     session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
     if not session:
-        raise error.TestFail, "Could not log into guest"
+        raise error.TestFail("Could not log into guest")
 
     logging.info("Logged in")
 
@@ -222,7 +222,7 @@  def run_autotest(test, params, env):
     if copy:
         logging.info("Copying autotest.tar.bz2 to guest (file is missing or has a different size)...")
         if not vm.scp_to_remote(tarred_autotest_path, ""):
-            raise error.TestFail, "Could not copy autotest.tar.bz2 to guest"
+            raise error.TestFail("Could not copy autotest.tar.bz2 to guest")
 
     # Check if we need to copy <test_name>.tar.bz2
     copy = False
@@ -237,13 +237,13 @@  def run_autotest(test, params, env):
     if copy:
         logging.info("Copying %s.tar.bz2 to guest (file is missing or has a different size)..." % test_name)
         if not vm.scp_to_remote(tarred_test_path, ""):
-            raise error.TestFail, "Could not copy %s.tar.bz2 to guest" % test_name
+            raise error.TestFail("Could not copy %s.tar.bz2 to guest" % test_name)
 
     # Extract autotest.tar.bz2
     logging.info("Extracting autotest.tar.bz2...")
     status = session.get_command_status("tar xvfj autotest.tar.bz2")
     if status != 0:
-        raise error.TestFail, "Could not extract autotest.tar.bz2"
+        raise error.TestFail("Could not extract autotest.tar.bz2")
 
     # mkdir autotest/tests
     session.sendline("mkdir autotest/tests")
@@ -252,7 +252,7 @@  def run_autotest(test, params, env):
     logging.info("Extracting %s.tar.bz2..." % test_name)
     status = session.get_command_status("tar xvfj %s.tar.bz2 -C autotest/tests" % test_name)
     if status != 0:
-        raise error.TestFail, "Could not extract %s.tar.bz2" % test_name
+        raise error.TestFail("Could not extract %s.tar.bz2" % test_name)
 
     # Run the test
     logging.info("Running test '%s'..." % test_name)
@@ -264,7 +264,7 @@  def run_autotest(test, params, env):
     match, output = session.read_up_to_prompt(timeout=test_timeout, print_func=logging.info)
     logging.info("---------------- End of test output ----------------")
     if not match:
-        raise error.TestFail, "Timeout elapsed while waiting for test to complete"
+        raise error.TestFail("Timeout elapsed while waiting for test to complete")
 
     session.close()
 
@@ -300,9 +300,9 @@  def run_autotest(test, params, env):
 
     # Fail the test if necessary
     if status_fail:
-        raise error.TestFail, message_fail
+        raise error.TestFail(message_fail)
     elif status_error:
-        raise error.TestError, message_error
+        raise error.TestError(message_error)
 
 
 
@@ -329,11 +329,11 @@  def run_yum_update(test, params, env):
     if not vm:
         message = "VM object not found in environment"
         logging.error(message)
-        raise error.TestError, message
+        raise error.TestError(message)
     if not vm.is_alive():
         message = "VM seems to be dead; Test requires a living VM"
         logging.error(message)
-        raise error.TestError, message
+        raise error.TestError(message)
 
     logging.info("Logging into guest...")
 
@@ -341,7 +341,7 @@  def run_yum_update(test, params, env):
     if not session:
         message = "Could not log into guest"
         logging.error(message)
-        raise error.TestFail, message
+        raise error.TestFail(message)
 
     logging.info("Logged in")
 
@@ -354,15 +354,15 @@  def run_yum_update(test, params, env):
 def run_linux_s3(test, params, env):
     vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
     if not vm:
-        raise error.TestError, "VM object not found in environment"
+        raise error.TestError("VM object not found in environment")
     if not vm.is_alive():
-        raise error.TestError, "VM seems to be dead; Test requires a living VM"
+        raise error.TestError("VM seems to be dead; Test requires a living VM")
 
     logging.info("Waiting for guest to be up...")
 
     session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
     if not session:
-        raise error.TestFail, "Could not log into guest"
+        raise error.TestFail("Could not log into guest")
 
     logging.info("Logged in")
     logging.info("Checking that VM supports S3")
@@ -371,7 +371,7 @@  def run_linux_s3(test, params, env):
     if status == None:
         logging.error("Failed to check if S3 exists")
     elif status != 0:
-        raise error.TestFail, "Guest does not support S3"
+        raise error.TestFail("Guest does not support S3")
 
     logging.info("Waiting for a while for X to start")
     time.sleep(10)
@@ -379,7 +379,7 @@  def run_linux_s3(test, params, env):
     src_tty = session.get_command_output("fgconsole").strip()
     logging.info("Current virtual terminal is %s" % src_tty)
     if src_tty not in map(str, range(1,10)):
-	raise error.TestFail, "Got a strange current vt (%s)" % src_tty
+	raise error.TestFail("Got a strange current vt (%s)" % src_tty)
 
     dst_tty = "1"
     if src_tty == "1":
@@ -389,7 +389,7 @@  def run_linux_s3(test, params, env):
     command = "chvt %s && echo mem > /sys/power/state && chvt %s" % (dst_tty, src_tty)
     status = session.get_command_status(command, timeout=120)
     if status != 0:
-        raise error.TestFail, "Suspend to mem failed"
+        raise error.TestFail("Suspend to mem failed")
 
     logging.info("VM resumed after S3")
 
diff --git a/client/tests/kvm_runtest_2/stepmaker.py b/client/tests/kvm_runtest_2/stepmaker.py
index c07c125..8881ced 100644
--- a/client/tests/kvm_runtest_2/stepmaker.py
+++ b/client/tests/kvm_runtest_2/stepmaker.py
@@ -323,16 +323,16 @@  class StepMaker(stepeditor.StepMakerWindow):
 def run_stepmaker(test, params, env):
     vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
     if not vm:
-        raise error.TestError, "VM object not found in environment"
+        raise error.TestError("VM object not found in environment")
     if not vm.is_alive():
-        raise error.TestError, "VM seems to be dead; Step Maker requires a living VM"
+        raise error.TestError("VM seems to be dead; Step Maker requires a living VM")
 
     steps_filename = params.get("steps")
     if not steps_filename:
-        raise error.TestError, "Steps filename not specified"
+        raise error.TestError("Steps filename not specified")
     steps_filename = os.path.join(test.bindir, "steps", steps_filename)
     if os.path.exists(steps_filename):
-        raise error.TestError, "Steps file %s already exists" % steps_filename
+        raise error.TestError("Steps file %s already exists" % steps_filename)
 
     StepMaker(vm, steps_filename, test.debugdir, params)
     gtk.main()