mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-23 19:32:24 +03:00
Qemu VMs: only compute MD5 checksums for existing disks
This commit is contained in:
parent
5b00529666
commit
8b245c96f8
@ -1131,7 +1131,6 @@ class QemuVM(BaseNode):
|
|||||||
await cancellable_wait_run_in_executor(md5sum, self._hdb_disk_image, self.working_dir)
|
await cancellable_wait_run_in_executor(md5sum, self._hdb_disk_image, self.working_dir)
|
||||||
await cancellable_wait_run_in_executor(md5sum, self._hdc_disk_image, self.working_dir)
|
await cancellable_wait_run_in_executor(md5sum, self._hdc_disk_image, self.working_dir)
|
||||||
await cancellable_wait_run_in_executor(md5sum, self._hdd_disk_image, self.working_dir)
|
await cancellable_wait_run_in_executor(md5sum, self._hdd_disk_image, self.working_dir)
|
||||||
|
|
||||||
super().create()
|
super().create()
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
@ -2700,18 +2699,19 @@ class QemuVM(BaseNode):
|
|||||||
if not disk_image:
|
if not disk_image:
|
||||||
continue
|
continue
|
||||||
answer[f"hd{drive}_disk_image"] = self.manager.get_relative_image_path(disk_image, self.working_dir)
|
answer[f"hd{drive}_disk_image"] = self.manager.get_relative_image_path(disk_image, self.working_dir)
|
||||||
answer[f"hd{drive}_disk_image_md5sum"] = md5sum(disk_image, self.working_dir)
|
|
||||||
local_disk = os.path.join(self.working_dir, f"hd{drive}_disk.qcow2")
|
local_disk = os.path.join(self.working_dir, f"hd{drive}_disk.qcow2")
|
||||||
if os.path.exists(local_disk):
|
if os.path.exists(local_disk):
|
||||||
try:
|
try:
|
||||||
qcow2 = Qcow2(local_disk)
|
qcow2 = Qcow2(local_disk)
|
||||||
if qcow2.backing_file:
|
if qcow2.backing_file:
|
||||||
answer[f"hd{drive}_disk_image"] = os.path.basename(local_disk)
|
# update disk image path to the local disk image and add the backing file name in the answer
|
||||||
answer[f"hd{drive}_disk_image_md5sum"] = md5sum(local_disk, self.working_dir)
|
|
||||||
answer[f"hd{drive}_disk_image_backing_file"] = os.path.basename(qcow2.backing_file)
|
answer[f"hd{drive}_disk_image_backing_file"] = os.path.basename(qcow2.backing_file)
|
||||||
|
answer[f"hd{drive}_disk_image"] = os.path.basename(local_disk)
|
||||||
except (Qcow2Error, OSError) as e:
|
except (Qcow2Error, OSError) as e:
|
||||||
log.error(f"Could not read qcow2 disk image '{local_disk}': {e}")
|
log.error(f"Could not read qcow2 disk image '{local_disk}': {e}")
|
||||||
continue
|
continue
|
||||||
|
# only compute the md5sum if the disk exists to avoid computing one for a backing file
|
||||||
|
answer[f"hd{drive}_disk_image_md5sum"] = md5sum(local_disk, self.working_dir)
|
||||||
|
|
||||||
answer["cdrom_image"] = self.manager.get_relative_image_path(self._cdrom_image, self.working_dir)
|
answer["cdrom_image"] = self.manager.get_relative_image_path(self._cdrom_image, self.working_dir)
|
||||||
answer["cdrom_image_md5sum"] = md5sum(self._cdrom_image, self.working_dir)
|
answer["cdrom_image_md5sum"] = md5sum(self._cdrom_image, self.working_dir)
|
||||||
|
|||||||
@ -115,7 +115,7 @@ class Drawing:
|
|||||||
|
|
||||||
data = base64.decodebytes(data.split(",", 1)[1].encode())
|
data = base64.decodebytes(data.split(",", 1)[1].encode())
|
||||||
|
|
||||||
# We compute an hash of the image file to avoid duplication
|
# We compute a hash of the image file to avoid duplication
|
||||||
filename = hashlib.md5(data).hexdigest() + "." + extension
|
filename = hashlib.md5(data).hexdigest() + "." + extension
|
||||||
elem.set(href, filename)
|
elem.set(href, filename)
|
||||||
|
|
||||||
|
|||||||
@ -167,19 +167,19 @@ class QemuBase(BaseModel):
|
|||||||
aux: Optional[int] = Field(None, gt=0, le=65535, description="Auxiliary console TCP port")
|
aux: Optional[int] = Field(None, gt=0, le=65535, description="Auxiliary console TCP port")
|
||||||
aux_type: Optional[QemuConsoleType] = Field(None, description="Auxiliary console type")
|
aux_type: Optional[QemuConsoleType] = Field(None, description="Auxiliary console type")
|
||||||
hda_disk_image: Optional[str] = Field(None, description="QEMU hda disk image path")
|
hda_disk_image: Optional[str] = Field(None, description="QEMU hda disk image path")
|
||||||
hda_disk_image_backed: Optional[str] = Field(None, description="QEMU hda backed disk image path")
|
hda_disk_image_backing_file: Optional[str] = Field(None, description="QEMU hda backing file disk image path")
|
||||||
hda_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hda disk image checksum")
|
hda_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hda disk image checksum")
|
||||||
hda_disk_interface: Optional[QemuDiskInterfaceType] = Field(None, description="QEMU hda interface")
|
hda_disk_interface: Optional[QemuDiskInterfaceType] = Field(None, description="QEMU hda interface")
|
||||||
hdb_disk_image: Optional[str] = Field(None, description="QEMU hdb disk image path")
|
hdb_disk_image: Optional[str] = Field(None, description="QEMU hdb disk image path")
|
||||||
hdb_disk_image_backed: Optional[str] = Field(None, description="QEMU hdb backed disk image path")
|
hdb_disk_image_backing_file: Optional[str] = Field(None, description="QEMU hdb backing file disk image path")
|
||||||
hdb_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdb disk image checksum")
|
hdb_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdb disk image checksum")
|
||||||
hdb_disk_interface: Optional[QemuDiskInterfaceType] = Field(None, description="QEMU hdb interface")
|
hdb_disk_interface: Optional[QemuDiskInterfaceType] = Field(None, description="QEMU hdb interface")
|
||||||
hdc_disk_image: Optional[str] = Field(None, description="QEMU hdc disk image path")
|
hdc_disk_image: Optional[str] = Field(None, description="QEMU hdc disk image path")
|
||||||
hdc_disk_image_backed: Optional[str] = Field(None, description="QEMU hdc backed disk image path")
|
hdc_disk_image_backing_file: Optional[str] = Field(None, description="QEMU hdc backing file disk image path")
|
||||||
hdc_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdc disk image checksum")
|
hdc_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdc disk image checksum")
|
||||||
hdc_disk_interface: Optional[QemuDiskInterfaceType] = Field(None, description="QEMU hdc interface")
|
hdc_disk_interface: Optional[QemuDiskInterfaceType] = Field(None, description="QEMU hdc interface")
|
||||||
hdd_disk_image: Optional[str] = Field(None, description="QEMU hdd disk image path")
|
hdd_disk_image: Optional[str] = Field(None, description="QEMU hdd disk image path")
|
||||||
hdd_disk_image_backed: Optional[str] = Field(None, description="QEMU hdd backed disk image path")
|
hdd_disk_image_backing_file: Optional[str] = Field(None, description="QEMU hdd backing file disk image path")
|
||||||
hdd_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdd disk image checksum")
|
hdd_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdd disk image checksum")
|
||||||
hdd_disk_interface: Optional[QemuDiskInterfaceType] = Field(None, description="QEMU hdd interface")
|
hdd_disk_interface: Optional[QemuDiskInterfaceType] = Field(None, description="QEMU hdd interface")
|
||||||
cdrom_image: Optional[str] = Field(None, description="QEMU cdrom image path")
|
cdrom_image: Optional[str] = Field(None, description="QEMU cdrom image path")
|
||||||
|
|||||||
@ -259,14 +259,15 @@ def md5sum(path, working_dir=None, stopped_event=None, cache_to_md5file=True):
|
|||||||
else:
|
else:
|
||||||
md5sum_file = path + ".md5sum"
|
md5sum_file = path + ".md5sum"
|
||||||
|
|
||||||
try:
|
if os.path.exists(md5sum_file):
|
||||||
with open(md5sum_file) as f:
|
try:
|
||||||
md5 = f.read().strip()
|
with open(md5sum_file) as f:
|
||||||
if len(md5) == 32:
|
md5 = f.read().strip()
|
||||||
return md5
|
if len(md5) == 32:
|
||||||
# Unicode error is when user rename an image to .md5sum ....
|
return md5
|
||||||
except (OSError, UnicodeDecodeError):
|
# Unicode error is when user rename an image to .md5sum ....
|
||||||
pass
|
except (OSError, UnicodeDecodeError):
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
m = hashlib.md5()
|
m = hashlib.md5()
|
||||||
|
|||||||
@ -144,7 +144,6 @@ class TestQemuNodesRoutes:
|
|||||||
assert response.json()["project_id"] == compute_project.id
|
assert response.json()["project_id"] == compute_project.id
|
||||||
assert response.json()["ram"] == 1024
|
assert response.json()["ram"] == 1024
|
||||||
assert response.json()["hda_disk_image"] == "linux载.img"
|
assert response.json()["hda_disk_image"] == "linux载.img"
|
||||||
assert response.json()["hda_disk_image_md5sum"] == "fcea920f7412b5da7be0cf42b8c93759"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user