From: Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: nic_hotplug: Use -f on mv commands Date: Tue, 1 Nov 2011 01:23:42 -0200 Message-ID: <1320117822-12486-1-git-send-email-lmr@redhat.com> Cc: kvm@vger.kernel.org, crosa@redhat.com, Lucas Meneghel Rodrigues To: autotest@test.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:19394 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753289Ab1KADXx (ORCPT ); Mon, 31 Oct 2011 23:23:53 -0400 Sender: kvm-owner@vger.kernel.org List-ID: A given sequence of nic_hotplug iterations might leave the system in a state that mv might overwrite a file. If the -f flag is not passed to the mv command, the system will go to interactive mode, which is clearly not desirable. So, introduce a mimic of the os.path.exists() API to verify the presence of the udev rules backup file and -f to avoid the command going into interactive mode. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/tests/nic_hotplug.py | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-) diff --git a/client/tests/kvm/tests/nic_hotplug.py b/client/tests/kvm/tests/nic_hotplug.py index e1f4973..7a35a51 100644 --- a/client/tests/kvm/tests/nic_hotplug.py +++ b/client/tests/kvm/tests/nic_hotplug.py @@ -1,6 +1,6 @@ -import logging +import logging, os from autotest_lib.client.common_lib import error -from autotest_lib.client.virt import virt_test_utils, virt_utils +from autotest_lib.client.virt import virt_test_utils, virt_utils, aexpect def run_nic_hotplug(test, params, env): @@ -29,19 +29,25 @@ def run_nic_hotplug(test, params, env): vm = virt_test_utils.get_living_vm(env, params.get("main_vm")) login_timeout = int(params.get("login_timeout", 360)) guest_delay = int(params.get("guest_delay", 20)) - romfile = params.get("romfile", "") pci_model = params.get("pci_model", "rtl8139") run_dhclient = params.get("run_dhclient", "no") guest_is_not_windows = "Win" not in params.get("guest_name", "") session = virt_test_utils.wait_for_login(vm, timeout=login_timeout) + udev_rules_path = "/etc/udev/rules.d/70-persistent-net.rules" + udev_rules_bkp_path = "/tmp/70-persistent-net.rules" + + def guest_path_isfile(path): + try: + session.cmd("test -f %s" % path) + except aexpect.ShellError: + return False + return True + if guest_is_not_windows: - # Disable udev rules that usually mess up with device naming - mv_stat, o = session.cmd_status_output("mv /etc/udev/rules.d/" - "70-persistent-net.rules /tmp") - logging.debug("command to disable udev rules returned status: %s" % - mv_stat) + if guest_path_isfile(udev_rules_path): + session.cmd("mv -f %s %s" % (udev_rules_path, udev_rules_bkp_path)) # Modprobe the module if specified in config file module = params.get("modprobe_module") @@ -94,7 +100,5 @@ def run_nic_hotplug(test, params, env): # disable the rules failed. We may be undoing what was done in a previous # (failed) test that never reached this point. if guest_is_not_windows: - mv_stat, o = session.cmd_status_output("mv /tmp/70-persistent-net" - ".rules /etc/udev/rules.d/") - logging.debug("command to revert udev rules returned status: %s" % - mv_stat) + if guest_path_isfile(udev_rules_bkp_path): + session.cmd("mv -f %s %s" % (udev_rules_bkp_path, udev_rules_path)) -- 1.7.7