• 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    fastboot_deploy_nfs = {
22        "timeout": {"minutes": 10},
23        "to": "nfs",
24        "nfsrootfs": nfsrootfs,
25    }
26
27    fastboot_deploy_prepare = {
28        "timeout": {"minutes": 5},
29        "to": "downloads",
30        "os": "oe",
31        "images": {
32            "kernel": {
33                "url": f"{args.kernel_url_prefix}/{args.kernel_image_name}",
34            },
35        },
36        "postprocess": {
37            "docker": {
38                "image": DOCKER_IMAGE,
39                "steps": [
40                    f"cat Image.gz {args.dtb_filename}.dtb > Image.gz+dtb",
41                    "mkbootimg --kernel Image.gz+dtb"
42                    + ' --cmdline "root=/dev/nfs rw nfsroot=$NFS_SERVER_IP:$NFS_ROOTFS,tcp,hard rootwait ip=dhcp init=/init"'
43                    + " --pagesize 4096 --base 0x80000000 -o boot.img",
44                ],
45            }
46        },
47    }
48
49    fastboot_deploy = {
50        "timeout": {"minutes": 2},
51        "to": "fastboot",
52        "docker": {
53            "image": DOCKER_IMAGE,
54        },
55        "images": {
56            "boot": {"url": "downloads://boot.img"},
57        },
58    }
59
60    # URLs to our kernel rootfs to boot from, both generated by the base
61    # container build
62    job_definition.attach_kernel_and_dtb(fastboot_deploy_prepare["images"])
63    job_definition.attach_external_modules(fastboot_deploy_nfs)
64
65    return (fastboot_deploy_nfs, fastboot_deploy_prepare, fastboot_deploy)
66
67
68def tftp_deploy_actions(job_definition: "LAVAJobDefinition", nfsrootfs) -> tuple[dict[str, Any]]:
69    args = job_definition.job_submitter
70    tftp_deploy = {
71        "timeout": {"minutes": 5},
72        "to": "tftp",
73        "os": "oe",
74        "kernel": {
75            "url": f"{args.kernel_url_prefix}/{args.kernel_image_name}",
76        },
77        "nfsrootfs": nfsrootfs,
78    }
79    job_definition.attach_kernel_and_dtb(tftp_deploy)
80    job_definition.attach_external_modules(tftp_deploy)
81
82    return (tftp_deploy,)
83
84
85def uart_test_actions(
86    args: "LAVAJobSubmitter", init_stage1_steps: list[str], artifact_download_steps: list[str]
87) -> tuple[dict[str, Any]]:
88    # skeleton test definition: only declaring each job as a single 'test'
89    # since LAVA's test parsing is not useful to us
90    run_steps = []
91    test = {
92        "timeout": {"minutes": args.job_timeout_min},
93        "failure_retry": 1,
94        "definitions": [
95            {
96                "name": "mesa",
97                "from": "inline",
98                "lava-signal": "kmsg",
99                "path": "inline/mesa.yaml",
100                "repository": {
101                    "metadata": {
102                        "name": "mesa",
103                        "description": "Mesa test plan",
104                        "os": ["oe"],
105                        "scope": ["functional"],
106                        "format": "Lava-Test Test Definition 1.0",
107                    },
108                    "run": {"steps": run_steps},
109                },
110            }
111        ],
112    }
113
114    run_steps += init_stage1_steps
115    run_steps += artifact_download_steps
116
117    run_steps += [
118        f"mkdir -p {args.ci_project_dir}",
119        f"curl {args.build_url} | tar --zstd -x -C {args.ci_project_dir}",
120        # Sleep a bit to give time for bash to dump shell xtrace messages into
121        # console which may cause interleaving with LAVA_SIGNAL_STARTTC in some
122        # devices like a618.
123        "sleep 1",
124        # Putting CI_JOB name as the testcase name, it may help LAVA farm
125        # maintainers with monitoring
126        f"lava-test-case '{args.project_name}_{args.mesa_job_name}' --shell /init-stage2.sh",
127    ]
128
129    return (test,)
130
131
132def tftp_boot_action(args: "LAVAJobSubmitter") -> dict[str, Any]:
133    tftp_boot = {
134        "failure_retry": NUMBER_OF_ATTEMPTS_LAVA_BOOT,
135        "method": args.boot_method,
136        "prompts": ["lava-shell:"],
137        "commands": "nfs",
138    }
139
140    return tftp_boot
141
142
143def fastboot_boot_action(args: "LAVAJobSubmitter") -> dict[str, Any]:
144    fastboot_boot = {
145        "timeout": {"minutes": 2},
146        "docker": {"image": DOCKER_IMAGE},
147        "failure_retry": NUMBER_OF_ATTEMPTS_LAVA_BOOT,
148        "method": args.boot_method,
149        "prompts": ["lava-shell:"],
150        "commands": ["set_active a"],
151    }
152
153    return fastboot_boot
154