• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from typing import TYPE_CHECKING, Any
2
3if TYPE_CHECKING:
4    from ..lava_job_submitter import LAVAJobSubmitter
5    from .lava_job_definition import LAVAJobDefinition
6
7from .constants import NUMBER_OF_ATTEMPTS_LAVA_BOOT
8
9# Use the same image that is being used for the hardware enablement and health-checks.
10# They are pretty small (<100MB) and have all the tools we need to run LAVA, so it is a safe choice.
11# You can find the Dockerfile here:
12# https://gitlab.collabora.com/lava/health-check-docker/-/blob/main/Dockerfile
13# And the registry here: https://gitlab.collabora.com/lava/health-check-docker/container_registry/
14DOCKER_IMAGE = "registry.gitlab.collabora.com/lava/health-check-docker"
15
16
17def fastboot_deploy_actions(
18    job_definition: "LAVAJobDefinition", nfsrootfs
19) -> tuple[dict[str, Any], ...]:
20    args = job_definition.job_submitter
21    cmdline = f"{job_definition.lava_nfs_args}{job_definition.extra_nfsroot_args}"
22    fastboot_deploy_nfs = {
23        "timeout": {"minutes": 10},
24        "to": "nfs",
25        "nfsrootfs": nfsrootfs,
26    }
27
28    fastboot_deploy_prepare = {
29        "timeout": {"minutes": 5},
30        "to": "downloads",
31        "os": "oe",
32        "images": {
33            "kernel": {
34                "url": f"{args.kernel_url_prefix}/{args.kernel_image_name}",
35            },
36        },
37        "postprocess": {
38            "docker": {
39                "image": DOCKER_IMAGE,
40                "steps": [
41                    f"cat Image.gz {args.dtb_filename}.dtb > Image.gz+dtb",
42                    "mkbootimg --kernel Image.gz+dtb"
43                    + f' --cmdline "{cmdline}"'
44                    + " --pagesize 4096 --base 0x80000000 -o boot.img",
45                ],
46            }
47        },
48    }
49
50    fastboot_deploy = {
51        "timeout": {"minutes": 2},
52        "to": "fastboot",
53        "docker": {
54            "image": DOCKER_IMAGE,
55        },
56        "images": {
57            "boot": {"url": "downloads://boot.img"},
58        },
59    }
60
61    # URLs to our kernel rootfs to boot from, both generated by the base
62    # container build
63    job_definition.attach_kernel_and_dtb(fastboot_deploy_prepare["images"])
64    job_definition.attach_external_modules(fastboot_deploy_nfs)
65
66    return (fastboot_deploy_nfs, fastboot_deploy_prepare, fastboot_deploy)
67
68
69def tftp_deploy_actions(job_definition: "LAVAJobDefinition", nfsrootfs) -> tuple[dict[str, Any]]:
70    args = job_definition.job_submitter
71    tftp_deploy = {
72        "timeout": {"minutes": 5},
73        "to": "tftp",
74        "os": "oe",
75        "kernel": {
76            "url": f"{args.kernel_url_prefix}/{args.kernel_image_name}",
77        },
78        "nfsrootfs": nfsrootfs,
79    }
80    job_definition.attach_kernel_and_dtb(tftp_deploy)
81    job_definition.attach_external_modules(tftp_deploy)
82
83    return (tftp_deploy,)
84
85
86def qemu_deploy_actions(job_definition: "LAVAJobDefinition", nfsrootfs) -> tuple[dict[str, Any]]:
87    args = job_definition.job_submitter
88    qemu_deploy = {
89        "timeout": {"minutes": 5},
90        "to": "nfs",
91        "images": {
92            "kernel": {
93                "image_arg": "-kernel {kernel}",
94                "url": f"{args.kernel_url_prefix}/{args.kernel_image_name}",
95            },
96            "nfsrootfs": nfsrootfs,
97        },
98    }
99    job_definition.attach_external_modules(qemu_deploy)
100
101    return (qemu_deploy,)
102
103
104def uart_test_actions(
105    args: "LAVAJobSubmitter", init_stage1_steps: list[str], jwt_steps: list[str]
106) -> tuple[dict[str, Any]]:
107    # skeleton test definition: only declaring each job as a single 'test'
108    # since LAVA's test parsing is not useful to us
109    run_steps = []
110    test = {
111        "timeout": {"minutes": args.job_timeout_min},
112        "failure_retry": 1,
113        "definitions": [
114            {
115                "name": "mesa",
116                "from": "inline",
117                "lava-signal": "kmsg",
118                "path": "inline/mesa.yaml",
119                "repository": {
120                    "metadata": {
121                        "name": "mesa",
122                        "description": "Mesa test plan",
123                        "os": ["oe"],
124                        "scope": ["functional"],
125                        "format": "Lava-Test Test Definition 1.0",
126                    },
127                    "run": {"steps": run_steps},
128                },
129            }
130        ],
131    }
132
133    run_steps += init_stage1_steps
134    run_steps += jwt_steps
135
136    run_steps += [
137        # Sleep a bit to give time for bash to dump shell xtrace messages into
138        # console which may cause interleaving with LAVA_SIGNAL_STARTTC in some
139        # devices like a618.
140        "sleep 1",
141        # Putting CI_JOB name as the testcase name, it may help LAVA farm
142        # maintainers with monitoring
143        f"lava-test-case '{args.project_name}_{args.mesa_job_name}' --shell /init-stage2.sh",
144    ]
145
146    return (test,)
147
148
149def tftp_boot_action(args: "LAVAJobSubmitter") -> dict[str, Any]:
150    tftp_boot = {
151        "failure_retry": NUMBER_OF_ATTEMPTS_LAVA_BOOT,
152        "method": args.boot_method,
153        "prompts": ["lava-shell:"],
154        "commands": "nfs",
155    }
156
157    return tftp_boot
158
159
160def qemu_boot_action(args: "LAVAJobSubmitter") -> dict[str, Any]:
161    qemu_boot = {
162        "failure_retry": NUMBER_OF_ATTEMPTS_LAVA_BOOT,
163        "method": args.boot_method,
164        "prompts": ["lava-shell:"],
165    }
166
167    return qemu_boot
168
169
170def fastboot_boot_action(args: "LAVAJobSubmitter") -> dict[str, Any]:
171    fastboot_boot = {
172        "timeout": {"minutes": 2},
173        "docker": {"image": DOCKER_IMAGE},
174        "failure_retry": NUMBER_OF_ATTEMPTS_LAVA_BOOT,
175        "method": args.boot_method,
176        "prompts": ["lava-shell:"],
177        "commands": ["set_active a"],
178    }
179
180    return fastboot_boot
181