Skip to content

Commit a13c03b

Browse files
committed
Catch process.CmdError instead of error.CmdError
Now we using process module from avocado to run commands and raise exceptiones, so adapt tp-libvirt cases to it. Signed-off-by: Yanbing Du <[email protected]>
1 parent 8d23e4d commit a13c03b

38 files changed

+194
-127
lines changed

libguestfs/tests/virt_sysprep.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import aexpect
55

66
from autotest.client.shared import error
7-
from autotest.client import utils
7+
8+
from avocado.utils import process
89

910
from virttest import libvirt_vm
1011
from virttest import virsh
@@ -80,7 +81,7 @@ def modify_source(vm_name, target, dst_image):
8081
virsh.attach_disk(vm_name, dst_image, target, extra=options,
8182
ignore_status=False)
8283
except (remote.LoginError, virt_vm.VMError,
83-
aexpect.ShellError, error.CmdError), detail:
84+
aexpect.ShellError, process.CmdError), detail:
8485
raise error.TestFail("Modify guest source failed: %s" % detail)
8586

8687
def modify_network(vm_name, first_nic):
@@ -141,7 +142,7 @@ def clean_clone_vm():
141142
virsh.undefine(vm_clone_name, ignore_status=False)
142143
if os.path.exists(clone_image):
143144
os.remove(clone_image)
144-
except error.CmdError, detail:
145+
except process.CmdError, detail:
145146
raise error.TestFail("Clean clone guest failed!:%s" % detail)
146147

147148
sysprep_type = params.get("sysprep_type", 'clone')
@@ -193,8 +194,8 @@ def clean_clone_vm():
193194
if sysprep_type == "resize":
194195
img_size = image_info_dict['vsize'] / 1024 / 1024 / 1024
195196
resize_image = "%s_resize.img" % clone_image
196-
utils.run("qemu-img create -f raw %s %dG" % (resize_image,
197-
(img_size + 1)))
197+
cmd = "qemu-img create -f raw %s %dG" % (resize_image, (img_size + 1))
198+
process.run(cmd, shell=True)
198199
lgf.virt_resize_cmd(clone_image, resize_image, timeout=600,
199200
debug=True)
200201
modify_source(vm_clone_name, target, resize_image)

libvirt/tests/src/libvirt_bench/libvirt_bench_usb_hotplug.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from autotest.client.shared import error
66

7+
from avocado.utils import process
8+
79
from virttest import data_dir
810
from virttest import virsh
911
from virttest import utils_test
@@ -91,28 +93,28 @@ def _is_stress_running():
9193

9294
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=options)
9395
if result.exit_status:
94-
raise error.CmdError(result.command, result)
96+
raise process.CmdError(result.command, result)
9597
if keyboard:
9698
attach_cmd = "device_add"
9799
attach_cmd += " usb-kdb,bus=usb1.0,id=kdb"
98100

99101
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=options)
100102
if result.exit_status:
101-
raise error.CmdError(result.command, result)
103+
raise process.CmdError(result.command, result)
102104
if mouse:
103105
attach_cmd = "device_add"
104106
attach_cmd += " usb-mouse,bus=usb1.0,id=mouse"
105107

106108
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=options)
107109
if result.exit_status:
108-
raise error.CmdError(result.command, result)
110+
raise process.CmdError(result.command, result)
109111
if tablet:
110112
attach_cmd = "device_add"
111113
attach_cmd += " usb-tablet,bus=usb1.0,id=tablet"
112114

113115
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=options)
114116
if result.exit_status:
115-
raise error.CmdError(result.command, result)
117+
raise process.CmdError(result.command, result)
116118
else:
117119
if disk:
118120
utils_test.libvirt.create_local_disk("file", path, size="1M")
@@ -128,7 +130,7 @@ def _is_stress_running():
128130

129131
result = virsh.attach_device(vm_name, disk_xml.xml)
130132
if result.exit_status:
131-
raise error.CmdError(result.command, result)
133+
raise process.CmdError(result.command, result)
132134
if mouse:
133135
mouse_xml = Input("mouse")
134136
mouse_xml.input_bus = "usb"
@@ -137,7 +139,7 @@ def _is_stress_running():
137139

138140
result = virsh.attach_device(vm_name, mouse_xml.xml)
139141
if result.exit_status:
140-
raise error.CmdError(result.command, result)
142+
raise process.CmdError(result.command, result)
141143
if tablet:
142144
tablet_xml = Input("tablet")
143145
tablet_xml.input_bus = "usb"
@@ -146,7 +148,7 @@ def _is_stress_running():
146148

147149
result = virsh.attach_device(vm_name, tablet_xml.xml)
148150
if result.exit_status:
149-
raise error.CmdError(result.command, result)
151+
raise process.CmdError(result.command, result)
150152
if keyboard:
151153
kbd_xml = Input("keyboard")
152154
kbd_xml.input_bus = "usb"
@@ -155,7 +157,7 @@ def _is_stress_running():
155157

156158
result = virsh.attach_device(vm_name, kbd_xml.xml)
157159
if result.exit_status:
158-
raise error.CmdError(result.command, result)
160+
raise process.CmdError(result.command, result)
159161

160162
if attach_type == "qemu_monitor":
161163
options = "--hmp"
@@ -165,46 +167,46 @@ def _is_stress_running():
165167

166168
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=options)
167169
if result.exit_status:
168-
raise error.CmdError(result.command, result)
170+
raise process.CmdError(result.command, result)
169171
if mouse:
170172
attach_cmd = "device_del"
171173
attach_cmd += (" mouse")
172174

173175
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=options)
174176
if result.exit_status:
175-
raise error.CmdError(result.command, result)
177+
raise process.CmdError(result.command, result)
176178
if keyboard:
177179
attach_cmd = "device_del"
178180
attach_cmd += (" keyboard")
179181

180182
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=options)
181183
if result.exit_status:
182-
raise error.CmdError(result.command, result)
184+
raise process.CmdError(result.command, result)
183185
if tablet:
184186
attach_cmd = "device_del"
185187
attach_cmd += (" tablet")
186188

187189
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=options)
188190
if result.exit_status:
189-
raise error.CmdError(result.command, result)
191+
raise process.CmdError(result.command, result)
190192
else:
191193
if disk:
192194
result = virsh.detach_device(vm_name, disk_xml.xml)
193195
if result.exit_status:
194-
raise error.CmdError(result.command, result)
196+
raise process.CmdError(result.command, result)
195197
if mouse:
196198
result = virsh.detach_device(vm_name, mouse_xml.xml)
197199
if result.exit_status:
198-
raise error.CmdError(result.command, result)
200+
raise process.CmdError(result.command, result)
199201
if keyboard:
200202
result = virsh.detach_device(vm_name, kbd_xml.xml)
201203
if result.exit_status:
202-
raise error.CmdError(result.command, result)
204+
raise process.CmdError(result.command, result)
203205
if tablet:
204206
result = virsh.detach_device(vm_name, tablet_xml.xml)
205207
if result.exit_status:
206-
raise error.CmdError(result.command, result)
207-
except error.CmdError, e:
208+
raise process.CmdError(result.command, result)
209+
except process.CmdError, e:
208210
if not status_error:
209211
raise error.TestFail("failed to attach device.\n"
210212
"Detail: %s." % result)

libvirt/tests/src/libvirt_scsi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from autotest.client.shared import error
99

10+
from avocado.utils import process
11+
1012
from virttest import virt_vm
1113
from virttest import qemu_storage
1214
from virttest import data_dir
@@ -77,7 +79,7 @@ def run(test, params, env):
7779
try:
7880
cdrom = CdromDisk(cdrom_path, data_dir.get_tmp_dir())
7981
cdrom.close()
80-
except error.CmdError, detail:
82+
except process.CmdError, detail:
8183
raise error.TestNAError("Failed to create cdrom disk: %s" % detail)
8284

8385
cdrom_disk = Disk(type_name="file")

libvirt/tests/src/libvirt_usb_hotplug_device.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from autotest.client.shared import error
88

9+
from avocado.utils import process
10+
911
from virttest import data_dir
1012
from virttest import virsh
1113
from virttest import utils_misc
@@ -91,7 +93,7 @@ def is_hotplug_ok():
9193

9294
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=opt)
9395
if result.exit_status or (result.stdout.find("OK") == -1):
94-
raise error.CmdError(result.command, result)
96+
raise process.CmdError(result.command, result)
9597

9698
attach_cmd = "device_add usb-storage,"
9799
attach_cmd += ("id=drive-usb-%s,bus=usb1.0,drive=drive-usb-%s" % (i, i))
@@ -101,7 +103,7 @@ def is_hotplug_ok():
101103

102104
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=opt)
103105
if result.exit_status:
104-
raise error.CmdError(result.command, result)
106+
raise process.CmdError(result.command, result)
105107
else:
106108
attributes = {'type_name': "usb", 'bus': "1", 'port': "0"}
107109
if usb_type == "storage":
@@ -124,7 +126,7 @@ def is_hotplug_ok():
124126

125127
result = virsh.attach_device(vm_name, dev_xml.xml)
126128
if result.exit_status:
127-
raise error.CmdError(result.command, result)
129+
raise process.CmdError(result.command, result)
128130

129131
if status_error and usb_type == "storage":
130132
if utils_misc.wait_for(is_hotplug_ok, timeout=30):
@@ -148,12 +150,12 @@ def is_hotplug_ok():
148150

149151
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=opt)
150152
if result.exit_status:
151-
raise error.CmdError(result.command, result)
153+
raise process.CmdError(result.command, result)
152154
else:
153155
result = virsh.detach_device(vm_name, dev_xml.xml)
154156
if result.exit_status:
155-
raise error.CmdError(result.command, result)
156-
except error.CmdError, e:
157+
raise process.CmdError(result.command, result)
158+
except process.CmdError, e:
157159
if not status_error:
158160
# live attach of device 'input' is not supported
159161
ret = result.stderr.find("Operation not supported")

libvirt/tests/src/macvtap.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from autotest.client.shared import error
66

7+
from avocado.utils import process
8+
79
from virttest import remote
810
from virttest import utils_net
911
from virttest import virsh
@@ -52,7 +54,7 @@ def run(test, params, env):
5254
origin_status = iface_cls.is_up()
5355
if not origin_status:
5456
iface_cls.up()
55-
except error.CmdError, detail:
57+
except process.CmdError, detail:
5658
raise error.TestNAError(str(detail))
5759
br_cls = utils_net.Bridge()
5860
if eth_card_no in br_cls.list_iface():
@@ -154,7 +156,7 @@ def private_test(session):
154156
% (vm1.name, vm2.name))
155157
try:
156158
iface_cls.down()
157-
except error.CmdError, detail:
159+
except process.CmdError, detail:
158160
raise error.TestNAError(str(detail))
159161
ping_s, _ = ping(vm2_ip, count=1, timeout=5, session=session)
160162
if not ping_s:
@@ -199,7 +201,7 @@ def bridge_test(session):
199201
% (vm1.name, vm2.name))
200202
try:
201203
iface_cls.down()
202-
except error.CmdError, detail:
204+
except process.CmdError, detail:
203205
raise error.TestNAError(str(detail))
204206
ping_s, _ = ping(remote_ip, count=1, timeout=5, session=session)
205207
if not ping_s:

libvirt/tests/src/multifunction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from autotest.client.shared import error
66

7+
from avocado.utils import process
8+
79
from virttest import libvirt_vm
810
from virttest import virsh
911
from virttest import data_dir
@@ -33,7 +35,7 @@ def cleanup_vm(vm_name=None, disk_removed=None):
3335
try:
3436
if vm_name is not None:
3537
virsh.undefine(vm_name)
36-
except error.CmdError:
38+
except process.CmdError:
3739
pass
3840
try:
3941
if disk_removed is not None:

libvirt/tests/src/numa/guest_numa.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import re
22
import logging
33

4-
from autotest.client.shared import utils
54
from autotest.client.shared import error
65

6+
from avocado.utils import process
7+
78
from virttest import virt_vm
89
from virttest import libvirt_xml
910
from virttest import utils_misc
@@ -359,6 +360,6 @@ def _update_qemu_conf():
359360
libvirtd.restart()
360361
for mt_path in mount_path:
361362
try:
362-
utils.system("umount %s" % mt_path)
363-
except error.CmdError:
363+
process.run("umount %s" % mt_path, shell=True)
364+
except process.CmdError:
364365
logging.warning("umount %s failed" % mt_path)

libvirt/tests/src/storage_discard.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import logging
77
import time
88

9-
from autotest.client import utils, lv_utils
9+
from autotest.client import lv_utils
1010
from autotest.client.shared import error
1111

12+
from avocado.utils import process
13+
1214
from virttest import virsh
1315
from virttest import data_dir
1416
from virttest import iscsi
@@ -35,7 +37,7 @@ def get_disk_capacity(disk_type, imagefile=None, lvname=None):
3537
while for block, it's volume space percentage in 'lvs'
3638
"""
3739
if disk_type == "file":
38-
result = utils.run("du -sm %s" % imagefile)
40+
result = process.run("du -sm %s" % imagefile, shell=True)
3941
return result.stdout.split()[0].strip()
4042
elif disk_type == "block":
4143
if lvname is None:
@@ -64,7 +66,7 @@ def create_iscsi_device(device_size="2G"):
6466
if iscsi_device == ():
6567
raise error.TestFail("No matched iscsi device.")
6668

67-
check_ret = utils.run("ls %s" % device_name)
69+
check_ret = process.run("ls %s" % device_name, shell=True)
6870
if check_ret.exit_status:
6971
raise error.TestFail("Can not find provided device:%s" % check_ret)
7072
return device_name
@@ -208,7 +210,7 @@ def do_fstrim(fstrim_type, vm, status_error=False):
208210
% vm.name)
209211
try:
210212
virsh.command(cmd, debug=True, ignore_status=False)
211-
except error.CmdError:
213+
except process.CmdError:
212214
raise error.TestFail("Execute qemu-agent-command failed.")
213215

214216

@@ -323,6 +325,7 @@ def run(test, params, env):
323325
lv_utils.vg_remove("vgthin")
324326
except error.TestError, detail:
325327
logging.debug(str(detail))
326-
utils.run("pvremove -f %s" % discard_device, ignore_status=True)
328+
process.run("pvremove -f %s" % discard_device, ignore_status=True,
329+
shell=True)
327330
if create_iscsi:
328331
utlv.setup_or_cleanup_iscsi(is_setup=False)

libvirt/tests/src/svirt/dac_nfs_disk.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import logging
44

55
from autotest.client.shared import error
6-
from autotest.client import utils
6+
7+
from avocado.utils import process
78

89
from virttest import qemu_storage
910
from virttest import data_dir
@@ -131,7 +132,8 @@ def run(test, params, env):
131132
export_options=export_options)
132133

133134
# set virt_use_nfs
134-
result = utils.run("setsebool virt_use_nfs %s" % virt_use_nfs)
135+
result = process.run("setsebool virt_use_nfs %s" % virt_use_nfs,
136+
shell=True)
135137
if result.exit_status:
136138
raise error.TestNAError("Failed to set virt_use_nfs value")
137139

@@ -213,7 +215,7 @@ def run(test, params, env):
213215
try:
214216
virsh.detach_disk(vm_name, target="vdf", extra="--persistent",
215217
debug=True)
216-
except error.CmdError:
218+
except process.CmdError:
217219
raise error.TestFail("Detach disk 'vdf' from VM %s failed."
218220
% vm.name)
219221
finally:

0 commit comments

Comments
 (0)