diff --git a/imagecraft/image_definition.py b/imagecraft/image_definition.py index c9516997..328c405d 100644 --- a/imagecraft/image_definition.py +++ b/imagecraft/image_definition.py @@ -121,7 +121,7 @@ class ImageDefinition(BaseModel): name: str display_name: str - revision: str + revision: int class_: str = Field(alias="class") architecture: str series: str @@ -141,7 +141,7 @@ class Config: def __init__( # noqa: PLR0913 self, series: str, - revision: str, + revision: int, architecture: str, pocket: str, kernel: str | None, diff --git a/imagecraft/models/project.py b/imagecraft/models/project.py index a5730389..fc81da7a 100644 --- a/imagecraft/models/project.py +++ b/imagecraft/models/project.py @@ -153,6 +153,17 @@ def _validate_package_repositories( validate_package_repositories(repositories) return repositories + @validator("version") # pyright: ignore[reportUntypedFunctionDecorator] + @classmethod + def _validate_version(cls, version: str) -> str: + try: + int(version) + except ValueError as e: + raise CraftValidationError( + "Invalid version", + details="value is not an integer.", + ) from e + return version @validator("platforms", pre=True) # pyright: ignore[reportUntypedFunctionDecorator] @classmethod diff --git a/imagecraft/plugins/ubuntu_seed.py b/imagecraft/plugins/ubuntu_seed.py index 49e46c71..b39a5ac3 100644 --- a/imagecraft/plugins/ubuntu_seed.py +++ b/imagecraft/plugins/ubuntu_seed.py @@ -103,7 +103,7 @@ def get_build_commands(self) -> list[str]: if branch: source_branch = branch - version = self._part_info.project_info.get_project_var("version", raw_read=True) + version = int(self._part_info.project_info.get_project_var("version", raw_read=True)) main_repo = get_main_package_repository(self._part_info.project_info.package_repositories) diff --git a/imagecraft/ubuntu_image.py b/imagecraft/ubuntu_image.py index b2b0de01..de3fd84a 100644 --- a/imagecraft/ubuntu_image.py +++ b/imagecraft/ubuntu_image.py @@ -26,7 +26,7 @@ def ubuntu_image_cmds_build_rootfs( # noqa: PLR0913 series: str, - version: str, + version: int, arch: str, pocket: str, sources: list[str], diff --git a/tests/conftest.py b/tests/conftest.py index aab9116e..209a5c04 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -66,7 +66,7 @@ def default_project(extra_project_params): return Project( name=ProjectName("default"), - version=VersionStr("1.0"), + version=VersionStr("1"), summary=SummaryStr("default project"), description="default project", base="ubuntu@22.04", diff --git a/tests/unit/models/test_project.py b/tests/unit/models/test_project.py index 915aa9eb..0af7c6be 100644 --- a/tests/unit/models/test_project.py +++ b/tests/unit/models/test_project.py @@ -25,7 +25,7 @@ IMAGECRAFT_YAML_GENERIC = """ name: ubuntu-server-amd64 -version: "22.04" +version: 1 series: jammy platforms: amd64: @@ -79,7 +79,7 @@ IMAGECRAFT_YAML_SIMPLE_PLATFORM = """ name: ubuntu-server-amd64 -version: "22.04" +version: 1 series: jammy platforms: amd64: @@ -94,7 +94,7 @@ IMAGECRAFT_YAML_MINIMAL_PLATFORM = """ name: ubuntu-server-amd64 -version: "22.04" +version: 1 series: jammy platforms: amd64: @@ -107,7 +107,7 @@ IMAGECRAFT_YAML_NO_BUILD_FOR_PLATFORM = """ name: ubuntu-server-amd64 -version: "22.04" +version: 1 series: jammy platforms: amd64: @@ -121,7 +121,7 @@ IMAGECRAFT_YAML_SIMPLE_PACKAGE_REPO = """ name: ubuntu-server-amd64 -version: "22.04" +version: 1 series: jammy platforms: amd64: @@ -288,3 +288,17 @@ def reload_project_package_repositories(mock_package_repositories, raises): mock_package_repositories, ProjectValidationError, ) + + +def test_project_version_invalid(yaml_loaded_data): + def reload_project_version(mock_version): + yaml_loaded_data["version"] = mock_version + with pytest.raises(CraftValidationError) as err: + Project.unmarshal(yaml_loaded_data) + + return str(err.value) + + mock_version = ["24.04"] + assert "value is not an integer" in reload_project_version( + mock_version, + ) diff --git a/tests/unit/plugins/test_ubuntu_seed.py b/tests/unit/plugins/test_ubuntu_seed.py index be19a0ef..9f994940 100644 --- a/tests/unit/plugins/test_ubuntu_seed.py +++ b/tests/unit/plugins/test_ubuntu_seed.py @@ -74,7 +74,7 @@ def _ubuntu_seed_plugin(spec, tmp_path): plugin_properties=plugin_properties, ) project_vars = { - "version": "22.04", + "version": "1", } package_repositories = [ PackageRepositoryApt.unmarshal( diff --git a/tests/unit/services/test_lifecycle.py b/tests/unit/services/test_lifecycle.py index 997464c1..8798b4f2 100644 --- a/tests/unit/services/test_lifecycle.py +++ b/tests/unit/services/test_lifecycle.py @@ -45,7 +45,7 @@ def test_lifecycle_args( platform="amd64", base="ubuntu@22.04", project_name="default", - project_vars={"version": "1.0"}, + project_vars={"version": "1"}, package_repositories=None, ) @@ -73,7 +73,7 @@ def test_lifecycle_args_no_platform( platform=None, base="ubuntu@22.04", project_name="default", - project_vars={"version": "1.0"}, + project_vars={"version": "1"}, package_repositories=None, ) diff --git a/tests/unit/test_application.py b/tests/unit/test_application.py index 47818d29..f3e4e78e 100644 --- a/tests/unit/test_application.py +++ b/tests/unit/test_application.py @@ -16,7 +16,7 @@ IMAGECRAFT_YAML = """ name: ubuntu-server-amd64 -version: "22.04" +version: 1 series: jammy platforms: amd64: @@ -59,7 +59,7 @@ IMAGECRAFT_YAML_NO_GADGET = """ name: ubuntu-server-amd64 -version: "22.04" +version: 1 series: jammy platforms: amd64: diff --git a/tests/unit/test_ubuntu_image.py b/tests/unit/test_ubuntu_image.py index 0f72dc9d..8de50c9c 100644 --- a/tests/unit/test_ubuntu_image.py +++ b/tests/unit/test_ubuntu_image.py @@ -32,7 +32,7 @@ ( ImageDefinition( series="mantic", - revision="22.04", + revision=1, architecture="amd64", pocket="release", kernel="linux-image-generic", @@ -69,7 +69,7 @@ ), """name: craft-driver display-name: Craft Driver -revision: '22.04' +revision: 1 class: preinstalled architecture: amd64 series: mantic @@ -114,7 +114,7 @@ ( ImageDefinition( series="mantic", - revision="22.04", + revision=2, architecture="amd64", pocket="proposed", kernel="linux-image-generic", @@ -129,7 +129,7 @@ ), """name: craft-driver display-name: Craft Driver -revision: '22.04' +revision: 2 class: preinstalled architecture: amd64 series: mantic @@ -158,7 +158,7 @@ ( ImageDefinition( series="mantic", - revision="22.04", + revision=1, architecture="amd64", pocket="proposed", kernel=None, @@ -173,7 +173,7 @@ ), """name: craft-driver display-name: Craft Driver -revision: '22.04' +revision: 1 class: preinstalled architecture: amd64 series: mantic @@ -200,7 +200,7 @@ def test_ubuntu_image_cmds_build_rootfs(mocker): assert ubuntu_image_cmds_build_rootfs( series="mantic", - version="22.04", + version=1, arch="amd64", pocket="proposed", sources=["source1", "source2"],