Skip to content

tests: Use Factory.create_job over copy pasted duplicates

For some reason even though Factory.create_job exists to create jobs from the sample jobs definitions and device a lot of unit tests copy pasted the Job creation logic.

One way the duplicate Job parsers were used is modifying a single value in the job or device dictionaries and then testing how the Job parameters changed or which errors the job.validate() would raise. To support this functionality add a new arguments to the Factory.create_job: device_dict_preprocessor and job_dict_preprocessor. Those arguments take a function that will be called with the device and job dictionaries respectively. The function can modify them before parsing occurs.

Another change is to make the Factory.create_job reference the sample devices only by name instead of template file name. Before the filename would get the .jinja2 prefix stripped and then applied back for some reason. Referencing device by name is closer to how real system behaives where device templates are compiled on lava server which references the devices by their names.

Also make Job id have a random value over the static one. This requires certain tests to be modified to assert a dynamic value.

Other major changes:

test_basic.py

Make create_kvm_job be a wrapper around Factory.create_job.

test_interactive.py

Drop InteractiveFactory because it can be completely replaced with Factory class.

test_lavashell.py

Drop X86Factory because it can be completely replaced with Factory.

test_removable.py

Do a pipeline_refs comparison for juno-uboot-removable.yaml, mustang-secondary-media.yaml and uboot-ramdisk.yaml jobs.

Merge request reports