Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Disk Manager]: check image size in image_file_server_launcher.py #1962

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 59 additions & 18 deletions cloud/disk_manager/test/images/recipe/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@

def start(argv):
raw_image_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/raw.img")
raw_image_file_server = ImageFileServerLauncher(raw_image_file_path)
raw_image_file_size = 67108864
raw_image_file_server = ImageFileServerLauncher(raw_image_file_path, raw_image_file_size)
raw_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_RAW_IMAGE_FILE_SERVER_PORT", str(raw_image_file_server.port))
set_env("DISK_MANAGER_RECIPE_RAW_IMAGE_SIZE", "67108864")
set_env("DISK_MANAGER_RECIPE_RAW_IMAGE_CRC32", "3776401828")

qcow2_image_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/qcow2.img")
other_qcow2_image_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/qcow2_other.img")
qcow2_image_file_server = ImageFileServerLauncher(qcow2_image_file_path, other_qcow2_image_file_path)
qcow2_image_file_size = 16338944
other_qcow2_image_file_size = 33882112
qcow2_image_file_server = ImageFileServerLauncher(
qcow2_image_file_path,
qcow2_image_file_size,
other_qcow2_image_file_path,
other_qcow2_image_file_size,
)
qcow2_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_QCOW2_IMAGE_FILE_SERVER_PORT", str(qcow2_image_file_server.port))
# size and crc32 after converting to raw image
Expand All @@ -30,23 +38,34 @@ def start(argv):
set_env("DISK_MANAGER_RECIPE_OTHER_QCOW2_IMAGE_CRC32", "3837173913")

vmdk_image_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/vmdk.img")
vmdk_image_file_server = ImageFileServerLauncher(vmdk_image_file_path)
vmdk_image_file_size = 35782656
vmdk_image_file_server = ImageFileServerLauncher(vmdk_image_file_path, vmdk_image_file_size)
vmdk_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_VMDK_IMAGE_FILE_SERVER_PORT", str(vmdk_image_file_server.port))
# size and crc32 after converting to raw image
set_env("DISK_MANAGER_RECIPE_VMDK_IMAGE_SIZE", "67108864")
set_env("DISK_MANAGER_RECIPE_VMDK_IMAGE_CRC32", "1412309815")

vmdk_stream_optimized_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/vmdk_stream_optimized.img")
vmdk_stream_optimized_image_file_server = ImageFileServerLauncher(vmdk_stream_optimized_file_path)
vmdk_stream_optimized_file_path = yatest_common.source_path(
"cloud/disk_manager/test/images/recipe/data/vmdk_stream_optimized.img",
)
vmdk_stream_optimized_file_size = 34455040
vmdk_stream_optimized_image_file_server = ImageFileServerLauncher(
vmdk_stream_optimized_file_path,
vmdk_stream_optimized_file_size,
)
vmdk_stream_optimized_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_VMDK_STREAM_OPTIMIZED_IMAGE_FILE_SERVER_PORT", str(vmdk_stream_optimized_image_file_server.port))
# size and crc32 after converting to raw image
set_env("DISK_MANAGER_RECIPE_VMDK_STREAM_OPTIMIZED_IMAGE_SIZE", "67108864")
set_env("DISK_MANAGER_RECIPE_VMDK_STREAM_OPTIMIZED_IMAGE_CRC32", "1412309815")

vhd_raw_image_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/vhd_raw.img")
vhd_raw_image_file_server = ImageFileServerLauncher(vhd_raw_image_file_path)
vhd_raw_image_file_size = 67125760
vhd_raw_image_file_server = ImageFileServerLauncher(
vhd_raw_image_file_path,
vhd_raw_image_file_size,
)
vhd_raw_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_VHD_RAW_IMAGE_FILE_SERVER_PORT", str(vhd_raw_image_file_server.port))
# size and crc32 after converting to raw image
Expand All @@ -56,7 +75,8 @@ def start(argv):
set_env("DISK_MANAGER_RECIPE_VHD_RAW_IMAGE_MAP_FILE", image_map_file_path)

vhd_dynamic_image_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/vhd_dynamic.img")
vhd_dynamic_image_file_server = ImageFileServerLauncher(vhd_dynamic_image_file_path)
vhd_dynamic_image_file_size = 54541824
vhd_dynamic_image_file_server = ImageFileServerLauncher(vhd_dynamic_image_file_path, vhd_dynamic_image_file_size)
vhd_dynamic_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_VHD_DYNAMIC_IMAGE_FILE_SERVER_PORT", str(vhd_dynamic_image_file_server.port))
# size and crc32 after converting to raw image
Expand All @@ -67,7 +87,11 @@ def start(argv):

vhd_ubuntu1604_image_file_path = yatest_common.build_path("cloud/disk_manager/test/images/resources/vhd_images/ubuntu1604-ci-stable")
if os.path.exists(vhd_ubuntu1604_image_file_path):
vhd_ubuntu1604_image_file_server = ImageFileServerLauncher(vhd_ubuntu1604_image_file_path)
vhd_ubuntu1604_image_file_size = 4306535424
vhd_ubuntu1604_image_file_server = ImageFileServerLauncher(
vhd_ubuntu1604_image_file_path,
vhd_ubuntu1604_image_file_size,
)
vhd_ubuntu1604_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_VHD_UBUNTU1604_IMAGE_FILE_SERVER_PORT", str(vhd_ubuntu1604_image_file_server.port))
# size and crc32 after converting to raw image
Expand All @@ -76,13 +100,17 @@ def start(argv):
image_map_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/vhd_ubuntu1604_image_map.json")
set_env("DISK_MANAGER_RECIPE_VHD_UBUNTU1604_IMAGE_MAP_FILE", image_map_file_path)

nonexistent_image_file_server = ImageFileServerLauncher("nonexistent")
nonexistent_image_file_server = ImageFileServerLauncher("nonexistent", None)
nonexistent_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_NON_EXISTENT_IMAGE_FILE_SERVER_PORT", str(nonexistent_image_file_server.port))

ubuntu1804_image_file_path = yatest_common.build_path("cloud/disk_manager/test/images/resources/qcow2_images/ubuntu-18.04-minimal-cloudimg-amd64.img")
if os.path.exists(ubuntu1804_image_file_path):
ubuntu1804_image_file_server = ImageFileServerLauncher(ubuntu1804_image_file_path)
ubuntu1804_image_file_size = 332595200
ubuntu1804_image_file_server = ImageFileServerLauncher(
ubuntu1804_image_file_path,
ubuntu1804_image_file_size,
)
ubuntu1804_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_QCOW2_UBUNTU1804_IMAGE_FILE_SERVER_PORT", str(ubuntu1804_image_file_server.port))
set_env("DISK_MANAGER_RECIPE_QCOW2_UBUNTU1804_IMAGE_FILE_SIZE", "332595200")
jkuradobery marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -94,10 +122,14 @@ def start(argv):

ubuntu1604_image_file_path = yatest_common.build_path("cloud/disk_manager/test/images/resources/qcow2_images/ubuntu1604-ci-stable")
if os.path.exists(ubuntu1604_image_file_path):
ubuntu1604_image_file_server = ImageFileServerLauncher(ubuntu1604_image_file_path)
ubuntu1604_image_file_size = 1902575616
ubuntu1604_image_file_server = ImageFileServerLauncher(
ubuntu1604_image_file_path,
ubuntu1604_image_file_size,
)
ubuntu1604_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_QCOW2_UBUNTU1604_IMAGE_FILE_SERVER_PORT", str(ubuntu1604_image_file_server.port))
set_env("DISK_MANAGER_RECIPE_QCOW2_UBUNTU1604_IMAGE_FILE_SIZE", "332595200")
set_env("DISK_MANAGER_RECIPE_QCOW2_UBUNTU1604_IMAGE_FILE_SIZE", "1902575616")
# size and crc32 after converting to raw image
set_env("DISK_MANAGER_RECIPE_QCOW2_UBUNTU1604_IMAGE_SIZE", "15246295040")
set_env("DISK_MANAGER_RECIPE_QCOW2_UBUNTU1604_IMAGE_CRC32", "1189208160")
Expand All @@ -106,7 +138,11 @@ def start(argv):

ubuntu2204_vmdk_image_file_path = yatest_common.build_path("cloud/disk_manager/test/images/resources/vmdk_images/ubuntu-22.04-jammy-server-cloudimg-amd64.vmdk")
if os.path.exists(ubuntu2204_vmdk_image_file_path):
ubuntu2204_vmdk_image_file_server = ImageFileServerLauncher(ubuntu2204_vmdk_image_file_path)
ubuntu2204_vmdk_image_file_size = 667248128
ubuntu2204_vmdk_image_file_server = ImageFileServerLauncher(
ubuntu2204_vmdk_image_file_path,
ubuntu2204_vmdk_image_file_size,
)
ubuntu2204_vmdk_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_VMDK_UBUNTU2204_IMAGE_FILE_SERVER_PORT", str(ubuntu2204_vmdk_image_file_server.port))
set_env("DISK_MANAGER_RECIPE_VMDK_UBUNTU2204_IMAGE_FILE_SIZE", "667248128")
Expand All @@ -119,15 +155,20 @@ def start(argv):
windows_vmdk_image_file_path = yatest_common.build_path(
"cloud/disk_manager/test/images/resources/vmdk_images/windows-vmdk-stream-optimised-multiple-grains.vmdk")
if os.path.exists(windows_vmdk_image_file_path):
windows_vmdk_image_file_size = 1354152960
windows_vmdk_image_file_server = ImageFileServerLauncher(
windows_vmdk_image_file_path)
windows_vmdk_image_file_path,
windows_vmdk_image_file_size,
)
windows_vmdk_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_VMDK_WINDOWS_FILE_SERVER_PORT", str(windows_vmdk_image_file_server.port))
set_env("DISK_MANAGER_RECIPE_VMDK_WINDOWS_FILE_SIZE", "1354152960")
# size and crc32 after converting to raw image
set_env("DISK_MANAGER_RECIPE_VMDK_WINDOWS_IMAGE_SIZE", "8589934592")
set_env("DISK_MANAGER_RECIPE_VMDK_WINDOWS_IMAGE_CRC32", "2831814743")
image_map_file_path = yatest_common.source_path("cloud/disk_manager/test/images/recipe/data/windows_vmdk_stream_optimised_multiple_grains_image_map.json")
image_map_file_path = yatest_common.source_path(
"cloud/disk_manager/test/images/recipe/data/windows_vmdk_stream_optimised_multiple_grains_image_map.json",
)
set_env("DISK_MANAGER_RECIPE_VMDK_WINDOWS_IMAGE_MAP_FILE", image_map_file_path)

working_dir = get_unique_path_for_current_test(
Expand All @@ -149,7 +190,7 @@ def start(argv):
"--output-file-path",
invalid_qcow2_image_file_path,
])
invalid_qcow2_image_file_server = ImageFileServerLauncher(invalid_qcow2_image_file_path)
invalid_qcow2_image_file_server = ImageFileServerLauncher(invalid_qcow2_image_file_path, None)
invalid_qcow2_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_INVALID_QCOW2_IMAGE_FILE_SERVER_PORT", str(invalid_qcow2_image_file_server.port))

Expand All @@ -166,7 +207,7 @@ def start(argv):
"--output-file-path",
qcow2_fuzzing_image_file_path,
])
qcow2_fuzzing_image_file_server = ImageFileServerLauncher(qcow2_fuzzing_image_file_path)
qcow2_fuzzing_image_file_server = ImageFileServerLauncher(qcow2_fuzzing_image_file_path, None)
qcow2_fuzzing_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_QCOW2_FUZZING_IMAGE_FILE_SERVER_PORT", str(qcow2_fuzzing_image_file_server.port))

Expand All @@ -182,7 +223,7 @@ def start(argv):
vmdk_image_generator = VMDKImageGenerator(generated_raw_image_file_path, generated_vmdk_image_file_path)
vmdk_image_generator.generate()

generated_vmdk_image_file_server = ImageFileServerLauncher(generated_vmdk_image_file_path)
generated_vmdk_image_file_server = ImageFileServerLauncher(generated_vmdk_image_file_path, None)
generated_vmdk_image_file_server.start()
set_env("DISK_MANAGER_RECIPE_GENERATED_VMDK_IMAGE_FILE_SERVER_PORT", str(generated_vmdk_image_file_server.port))
# size and crc32 after converting to raw image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from cloud.storage.core.tools.common.python.daemon import Daemon
from contrib.ydb.tests.library.harness.kikimr_runner import get_unique_path_for_current_test, ensure_path_exists
import contrib.ydb.tests.library.common.yatest_common as yatest_common
Expand Down Expand Up @@ -25,11 +27,37 @@ def __init__(self, port, working_dir, image_file_path, other_image_file_path):
service_name=SERVICE_NAME)


def _check_file_is_valid(path: Path, expected_image_file_size: int):
jkuradobery marked this conversation as resolved.
Show resolved Hide resolved
if not path.is_file():
jkuradobery marked this conversation as resolved.
Show resolved Hide resolved
raise RuntimeError(f"Image file path {path} does not exist")
actual_image_file_size = path.stat().st_size
if actual_image_file_size != expected_image_file_size:
raise RuntimeError(
f"Image file size {actual_image_file_size} does not match expected"
jkuradobery marked this conversation as resolved.
Show resolved Hide resolved
)


class ImageFileServerLauncher:

def __init__(self, image_file_path, other_image_file_path=""):
self.__image_file_path = image_file_path
self.__other_image_file_path = other_image_file_path
def __init__(
self,
image_file_path: str,
expected_image_file_size: int | None,
other_image_file_path: str = "",
other_expected_image_file_size: int | None = None,
):

jkuradobery marked this conversation as resolved.
Show resolved Hide resolved
self.__image_file_path = Path(image_file_path)
if expected_image_file_size is not None:
_check_file_is_valid(Path(image_file_path), expected_image_file_size)
self.__other_image_file_path = ""
if other_image_file_path != "":
self.__other_image_file_path = Path(other_image_file_path)
if other_expected_image_file_size is None:
raise RuntimeError(
jkuradobery marked this conversation as resolved.
Show resolved Hide resolved
"other_expected_image_file_size can not be None if other_image_file_path is present"
)
_check_file_is_valid(self.__other_image_file_path, other_expected_image_file_size)

self.__port_manager = yatest_common.PortManager()
self.__port = self.__port_manager.get_port()
Expand All @@ -43,8 +71,8 @@ def __init__(self, image_file_path, other_image_file_path=""):
self.__daemon = ImageFileServer(
self.__port,
working_dir,
self.__image_file_path,
self.__other_image_file_path)
str(self.__image_file_path),
jkuradobery marked this conversation as resolved.
Show resolved Hide resolved
str(self.__other_image_file_path))

def start(self):
self.__daemon.start()
Expand Down
Loading