Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move exec method to utils.py, and catch unexpected exception.

  • Loading branch information...
commit b465a8904790defb061916bd163e20fbe0f7917a 1 parent 97270e2
@yudoufu yudoufu authored
View
6 koan/qcreate.py
@@ -24,12 +24,8 @@
"""
import virtinstall
-import utils
def start_install(*args, **kwargs):
- image_commands = virtinstall.create_image_file(*args, **kwargs)
- for command in image_commands:
- utils.subprocess_call(command)
-
+ virtinstall.create_image_file(*args, **kwargs)
cmd = virtinstall.build_commandline("qemu:///system", *args, **kwargs)
utils.subprocess_call(cmd)
View
9 koan/utils.py
@@ -550,6 +550,11 @@ def __try_connect(url):
traceback.print_exc()
return None
-
-
+def create_qemu_image_file(path, size, driver_type):
+ cmd = ["qemu-img", "create", "-f", driver_type, path, "%sG" % size]
+ try:
+ subprocess_call(cmd)
+ except:
+ traceback.print_exc()
+ raise InfoException, "Image file create failed: %s" % string.join(cmd, " ")
View
5 koan/virtinstall.py
@@ -104,7 +104,6 @@ def _sanitize_nics(nics, bridge, profile_bridge, network_count):
def create_image_file(disks=None, **kwargs):
disks = _sanitize_disks(disks)
- commands = []
for path, size, driver_type in disks:
if driver_type is None:
continue
@@ -112,9 +111,7 @@ def create_image_file(disks=None, **kwargs):
continue
if str(size) == "0":
continue
- cmd = 'qemu-img create -f %s %s %sG'% (driver_type, path, size)
- commands.append(shlex.split(cmd.strip()))
- return commands
+ utils.create_qemu_image_file(path, size, driver_type)
def build_commandline(uri,
name=None,
View
24 tests/koan/virtinstall.py
@@ -199,29 +199,31 @@ def testImage(self):
"--network bridge=br2 --wait 0 --noautoconsole")
)
- @patch('koan.virtinstall.os.path', new_callable=OsPathMock)
- def test_create_qcow_file(self, mock):
+ @patch('koan.virtinstall.utils.subprocess_call')
+ @patch('koan.virtinstall.utils.os.path', new_callable=OsPathMock)
+ def test_create_qcow_file(self, mock_path, mock_subprocess):
disks = [
( '/path/to/imagedir/new_qcow_file', '30', 'qcow' ),
( '/path/to/imagedir/new_qcow2_file', '30', 'qcow2' ),
( '/path/to/imagedir/new_raw_file', '30', 'raw' ),
( '/path/to/imagedir/new_vmdk_file', '30', 'vmdk' ),
+ ( '/path/to/imagedir/new_qcow_file', '30'),
( '/path/to/imagedir/new_qcow2_file', '0', 'qcow2' ),
( '/path/to/imagedir/existfile', '30', 'qcow2' ),
( '/path/to/imagedir', '30', 'qcow2' ),
]
- commands = create_image_file(disks)
+ create_image_file(disks)
res = []
- for cmd in commands:
- res.append(" ".join(cmd))
+ for args, kargs in mock_subprocess.call_args_list:
+ res.append(" ".join(args[0]))
self.assertEquals(res,
- [
- 'qemu-img create -f qcow /path/to/imagedir/new_qcow_file 30G',
- 'qemu-img create -f qcow2 /path/to/imagedir/new_qcow2_file 30G',
- 'qemu-img create -f raw /path/to/imagedir/new_raw_file 30G',
- 'qemu-img create -f vmdk /path/to/imagedir/new_vmdk_file 30G',
- ]
+ [
+ 'qemu-img create -f qcow /path/to/imagedir/new_qcow_file 30G',
+ 'qemu-img create -f qcow2 /path/to/imagedir/new_qcow2_file 30G',
+ 'qemu-img create -f raw /path/to/imagedir/new_raw_file 30G',
+ 'qemu-img create -f vmdk /path/to/imagedir/new_vmdk_file 30G',
+ ]
)
Please sign in to comment.
Something went wrong with that request. Please try again.