mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
parent
1885fe62a6
commit
042a69eecf
@ -62,7 +62,10 @@ class Qcow2:
|
|||||||
with open(self.path, 'rb') as f:
|
with open(self.path, 'rb') as f:
|
||||||
content = f.read(struct.calcsize(struct_format))
|
content = f.read(struct.calcsize(struct_format))
|
||||||
|
|
||||||
self.magic, self.version, self.backing_file_offset, self.backing_file_size = struct.unpack_from(struct_format, content)
|
try:
|
||||||
|
self.magic, self.version, self.backing_file_offset, self.backing_file_size = struct.unpack_from(struct_format, content)
|
||||||
|
except struct.error:
|
||||||
|
raise Qcow2Error("Invalid file header for {}".format(self.path))
|
||||||
|
|
||||||
if self.magic != 1363560955: # The first 4 bytes contain the characters 'Q', 'F', 'I' followed by 0xfb.
|
if self.magic != 1363560955: # The first 4 bytes contain the characters 'Q', 'F', 'I' followed by 0xfb.
|
||||||
raise Qcow2Error("Invalid magic for {}".format(self.path))
|
raise Qcow2Error("Invalid magic for {}".format(self.path))
|
||||||
|
@ -56,6 +56,12 @@ def test_invalid_file():
|
|||||||
Qcow2("tests/resources/nvram_iou")
|
Qcow2("tests/resources/nvram_iou")
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_empty_file(tmpdir):
|
||||||
|
open(str(tmpdir / 'a'), 'w+').close()
|
||||||
|
with pytest.raises(Qcow2Error):
|
||||||
|
Qcow2(str(tmpdir / 'a'))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(qemu_img() is None, reason="qemu-img is not available")
|
@pytest.mark.skipif(qemu_img() is None, reason="qemu-img is not available")
|
||||||
def test_rebase(tmpdir, loop):
|
def test_rebase(tmpdir, loop):
|
||||||
shutil.copy("tests/resources/empty8G.qcow2", str(tmpdir / "empty16G.qcow2"))
|
shutil.copy("tests/resources/empty8G.qcow2", str(tmpdir / "empty16G.qcow2"))
|
||||||
|
Loading…
Reference in New Issue
Block a user