forked from Mirror/pmbootstrap
core: chroot: Deduplicate supported arch list (MR 2476)
self.arch is a property and calls Arch.from_str, which errors upon encountering an unknown architecture. Therefore, the error message is changed and needs to be adjusted in the tests. Since Arch.supported is a set, error messages were not deterministic before, so we need to sort the list of architectures now. Signed-off-by: Jens Reidel <adrian@travitia.xyz>
This commit is contained in:
parent
6d72043ac2
commit
9ca0ada582
3 changed files with 6 additions and 12 deletions
|
@ -45,7 +45,7 @@ class Arch(enum.Enum):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid architecture: '{arch}',"
|
f"Invalid architecture: '{arch}',"
|
||||||
" expected something like:"
|
" expected something like:"
|
||||||
f" {', '.join([str(a) for a in Arch.supported()])}"
|
f" {', '.join(sorted(str(a) for a in Arch.supported()))}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -41,21 +41,12 @@ class Chroot:
|
||||||
"""
|
"""
|
||||||
Ensures that this suffix follows the correct format.
|
Ensures that this suffix follows the correct format.
|
||||||
"""
|
"""
|
||||||
valid_arches = [
|
|
||||||
"x86",
|
|
||||||
"x86_64",
|
|
||||||
"aarch64",
|
|
||||||
"armhf", # XXX: remove this?
|
|
||||||
"armv7",
|
|
||||||
"riscv64",
|
|
||||||
]
|
|
||||||
|
|
||||||
if self.__type not in ChrootType._member_map_.values():
|
if self.__type not in ChrootType._member_map_.values():
|
||||||
raise ValueError(f"Invalid chroot type: '{self.__type}'")
|
raise ValueError(f"Invalid chroot type: '{self.__type}'")
|
||||||
|
|
||||||
# A buildroot suffix must have a name matching one of alpines
|
# A buildroot suffix must have a name matching one of alpines
|
||||||
# architectures.
|
# architectures.
|
||||||
if self.__type == ChrootType.BUILDROOT and self.__name not in valid_arches:
|
if self.__type == ChrootType.BUILDROOT and self.arch not in Arch.supported():
|
||||||
raise ValueError(f"Invalid buildroot suffix: '{self.__name}'")
|
raise ValueError(f"Invalid buildroot suffix: '{self.__name}'")
|
||||||
|
|
||||||
# A rootfs or installer suffix must have a name matching a device.
|
# A rootfs or installer suffix must have a name matching a device.
|
||||||
|
|
|
@ -42,7 +42,10 @@ def test_invalid_chroots(pmb_args):
|
||||||
|
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
Chroot(ChrootType.BUILDROOT, "BAD_ARCH")
|
Chroot(ChrootType.BUILDROOT, "BAD_ARCH")
|
||||||
assert str(excinfo.value) == "Invalid buildroot suffix: 'BAD_ARCH'"
|
assert (
|
||||||
|
str(excinfo.value)
|
||||||
|
== "Invalid architecture: 'BAD_ARCH', expected something like: aarch64, armhf, armv7, riscv64, x86, x86_64"
|
||||||
|
)
|
||||||
|
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
Chroot(ChrootType.NATIVE, "aarch64")
|
Chroot(ChrootType.NATIVE, "aarch64")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue