ci/lava: Fix lava-tags parsing
python-fire auto-converts `item1,item2` into a tuple, but if there is a dash `-` inside the argument, it treats it as a string. Let's validate the data, when it comes as a `str` or `tuple`. For more details, here are the tested scenarios: | --lava-tags= | Type | Value | |--------------|-------|---------------------| | None | bool | True | | '' | str | '' | | tag1 | str | "tag1" | | tag1, | tuple | ("tag1",) | | tag-1,tag-2 | str | 'tag-1,tag-2' | | tag1,tag2 | tuple | ("tag1", "tag2") | | ',' | str | ',' | | ',,' | str | ',,' | | 'tag1,,' | str | 'tag1,,' | See also: https://google.github.io/python-fire/guide/#argument-parsing Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31882>
This commit is contained in:

committed by
Marge Bot

parent
ce78dcb24e
commit
bc86b73bbe
@@ -407,7 +407,7 @@ class LAVAJobSubmitter(PathResolver):
|
||||
kernel_image_type: str = ""
|
||||
kernel_url_prefix: str = None
|
||||
kernel_external: str = None
|
||||
lava_tags: str = "" # Comma-separated LAVA tags for the job
|
||||
lava_tags: str | tuple[str, ...] = () # Comma-separated LAVA tags for the job
|
||||
mesa_job_name: str = "mesa_ci_job"
|
||||
pipeline_info: str = ""
|
||||
rootfs_url: str = None
|
||||
|
@@ -121,6 +121,22 @@ class LAVAJobDefinition:
|
||||
yaml.dump(self.generate_lava_yaml_payload(), job_stream)
|
||||
return job_stream.getvalue()
|
||||
|
||||
def consume_lava_tags_args(self, values: dict[str, Any]):
|
||||
# python-fire parses --lava-tags without arguments as True
|
||||
if isinstance(self.job_submitter.lava_tags, tuple):
|
||||
values["tags"] = self.job_submitter.lava_tags
|
||||
# python-fire parses "tag-1,tag2" as str and "tag1,tag2" as tuple
|
||||
# even if the -- --separator is something other than '-'
|
||||
elif isinstance(self.job_submitter.lava_tags, str):
|
||||
# Split string tags by comma, removing any trailing commas
|
||||
values["tags"] = self.job_submitter.lava_tags.rstrip(",").split(",")
|
||||
# Ensure tags are always a list of non-empty strings
|
||||
if "tags" in values:
|
||||
values["tags"] = [tag for tag in values["tags"] if tag]
|
||||
# Remove empty tags
|
||||
if "tags" in values and not values["tags"]:
|
||||
del values["tags"]
|
||||
|
||||
def generate_metadata(self) -> dict[str, Any]:
|
||||
# General metadata and permissions
|
||||
values = {
|
||||
@@ -150,8 +166,7 @@ class LAVAJobDefinition:
|
||||
},
|
||||
}
|
||||
|
||||
if self.job_submitter.lava_tags:
|
||||
values["tags"] = self.job_submitter.lava_tags.split(",")
|
||||
self.consume_lava_tags_args(values)
|
||||
|
||||
# QEMU lava jobs mandate proper arch value in the context
|
||||
if self.job_submitter.boot_method == "qemu-nfs":
|
||||
|
Reference in New Issue
Block a user