mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-23 17:34:21 +03:00
virtconv: Drop all the chdir hackery
This was just lazy stuff to avoid having to assumble abspaths. Plus it confuses cprofile
This commit is contained in:
parent
6cad350649
commit
472a52b170
@ -58,7 +58,6 @@ class TestVirtConv(unittest.TestCase):
|
||||
utils.test_create(conn, out_xml)
|
||||
|
||||
def _compare(self, in_path, disk_format=None):
|
||||
cwd = os.getcwd()
|
||||
in_type = "ovf"
|
||||
if "vmx" in in_path:
|
||||
in_type = "vmx"
|
||||
@ -70,11 +69,7 @@ class TestVirtConv(unittest.TestCase):
|
||||
if disk_format:
|
||||
out_path += ".disk_%s" % disk_format
|
||||
|
||||
try:
|
||||
os.chdir(os.path.dirname(in_path))
|
||||
self._convert_helper(in_path, out_path, in_type, disk_format)
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
self._convert_helper(in_path, out_path, in_type, disk_format)
|
||||
|
||||
|
||||
def testOVF2Libvirt(self):
|
||||
|
@ -223,14 +223,9 @@ class VirtConverter(object):
|
||||
logging.debug("converter not input_file=%s parser=%s",
|
||||
self._input_file, self.parser)
|
||||
|
||||
cwd = os.getcwd()
|
||||
try:
|
||||
os.chdir(self._top_dir)
|
||||
self._guest = self.parser.export_libvirt(self.conn,
|
||||
self._input_file)
|
||||
self._guest.add_default_devices()
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
self._guest = self.parser.export_libvirt(self.conn,
|
||||
self._input_file)
|
||||
self._guest.add_default_devices()
|
||||
|
||||
def __del__(self):
|
||||
for f in self._force_clean:
|
||||
|
@ -166,10 +166,9 @@ def parse_netdev_entry(conn, ifaces, fullkey, value):
|
||||
return net, inst
|
||||
|
||||
|
||||
def parse_disk_entry(conn, disks, fullkey, value):
|
||||
def parse_disk_entry(conn, disks, fullkey, value, topdir):
|
||||
"""
|
||||
Parse a particular key/value for a disk. FIXME: this should be a
|
||||
lot smarter.
|
||||
Parse a particular key/value for a disk.
|
||||
"""
|
||||
# skip bus values, e.g. 'scsi0.present = "TRUE"'
|
||||
if re.match(r"^(scsi|ide)[0-9]+[^:]", fullkey):
|
||||
@ -213,7 +212,7 @@ def parse_disk_entry(conn, disks, fullkey, value):
|
||||
if lvalue.endswith(".vmdk"):
|
||||
fmt = "vmdk"
|
||||
# See if the filename is actually a VMDK descriptor file
|
||||
newpath = parse_vmdk(disk.path)
|
||||
newpath = parse_vmdk(os.path.join(topdir, disk.path))
|
||||
if newpath:
|
||||
logging.debug("VMDK file parsed path %s->%s",
|
||||
disk.path, newpath)
|
||||
@ -252,6 +251,7 @@ class vmx_parser(parser_class):
|
||||
|
||||
@staticmethod
|
||||
def export_libvirt(conn, input_file):
|
||||
topdir = os.path.dirname(os.path.abspath(input_file))
|
||||
infile = open(input_file, "r")
|
||||
contents = infile.readlines()
|
||||
infile.close()
|
||||
@ -280,7 +280,7 @@ class vmx_parser(parser_class):
|
||||
|
||||
disks = []
|
||||
for key, value in _find_keys(["scsi", "ide"]):
|
||||
parse_disk_entry(conn, disks, key, value)
|
||||
parse_disk_entry(conn, disks, key, value, topdir)
|
||||
|
||||
ifaces = []
|
||||
for key, value in _find_keys("ethernet"):
|
||||
|
Loading…
Reference in New Issue
Block a user