Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that jobs that have an after suspend counterpart are run before suspend (New) #1037

Merged
merged 10 commits into from
Mar 7, 2024

Conversation

pieqq
Copy link
Collaborator

@pieqq pieqq commented Mar 5, 2024

Description

Some jobs should be run before and after suspend. To take this into
account, the siblings field was developed, along with the
also-after-suspend and also-after-suspend-manual flags.

These would let Checkbox spawn a similar job with an added dependency on
the suspend job (either the manual or the automated version of it).

The problem is that the original job did not have any dependency to
force it to be run before the suspend job.

This was not an issue for test plans organized manually, using regular
expressions, because you could have an include section that looks like:

storage_.*
com.canonical.certification::suspend/suspend_advanced_auto
after-suspend-storage.*

However, now that template ids can be added in test plans, this is a
problem.

This patch will make sure the jobs that need to run before suspend are
added as dependencies of their related suspend job, so that regardless
of the order in the test plan, they will be run in the proper order.

Resolved issues

https://warthogs.atlassian.net/browse/CHECKBOX-1265

Documentation

The Job Unit reference page has been updated to explain what happens when the also-after-suspend flag is used, or when a sibling is defined that depends on a suspend job.

Tests

Given the following units:

id: demoresource
plugin: resource
command:
    echo 'name: sda'
    echo 'path: /dev/sda'
    echo
    echo 'name: sdb'
    echo 'path: /dev/sdb'

unit: template
template-resource: demoresource
template-id: demo-template
id: demo-test-storage-{name}
plugin: shell
command: echo "This is the path: {path}"
flags: also-after-suspend

unit: test plan
id: demo-test-plan
bootstrap_include:
  demoresource
include:
  demo-template     # template id generated from job id

Before applying the patch:

$ checkbox-cli list-bootstrapped com.canonical.certification::demo-test-plan

com.canonical.certification::demo-test-storage-sda
com.canonical.certification::sleep
com.canonical.certification::rtc
com.canonical.certification::suspend/suspend_advanced_auto
com.canonical.certification::after-suspend-demo-test-storage-sda
com.canonical.certification::demo-test-storage-sdb
com.canonical.certification::after-suspend-demo-test-storage-sdb

The demo-test-storage-sdb job should be run before suspend/suspend_advanced_auto, but is run after.

After applying the patch:

$ checkbox-cli list-bootstrapped com.canonical.certification::demo-test-plan

com.canonical.certification::demo-test-storage-sda
com.canonical.certification::rtc
com.canonical.certification::sleep
com.canonical.certification::demo-test-storage-sdb
com.canonical.certification::suspend/suspend_advanced_auto
com.canonical.certification::after-suspend-demo-test-storage-sda
com.canonical.certification::after-suspend-demo-test-storage-sdb

I also ran the test plan to make sure it executed properly and in the right order.

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 98.14815% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 40.76%. Comparing base (4c07bd0) to head (f33a07b).

Files Patch % Lines
checkbox-ng/plainbox/impl/ctrl.py 97.14% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1037      +/-   ##
==========================================
+ Coverage   40.67%   40.76%   +0.08%     
==========================================
  Files         335      336       +1     
  Lines       37423    37460      +37     
  Branches     6359     6370      +11     
==========================================
+ Hits        15222    15269      +47     
+ Misses      21560    21550      -10     
  Partials      641      641              
Flag Coverage Δ
checkbox-ng 66.89% <98.14%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@kissiel kissiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff; landable as is.
Some tips below, tho - it can be made less complicated (especially tests, which have to cover a lot of branching). If you think it's a lot of work, ping me, but I'm kindly asking for a few tweaks.

checkbox-ng/plainbox/configuration.py Outdated Show resolved Hide resolved
checkbox-ng/plainbox/configuration.py Outdated Show resolved Hide resolved
checkbox-ng/plainbox/impl/ctrl.py Outdated Show resolved Hide resolved
checkbox-ng/plainbox/impl/ctrl.py Outdated Show resolved Hide resolved
checkbox-ng/plainbox/impl/ctrl.py Outdated Show resolved Hide resolved
checkbox-ng/plainbox/impl/ctrl.py Show resolved Hide resolved
pieqq added 10 commits March 6, 2024 17:45
…e suspend

Some jobs should be run before *and* after suspend. To take this into
account, the `siblings` field was developed, along with the
`also-after-suspend` and `also-after-suspend-manual` flags[2].

These would let Checkbox spawn a similar job with an added dependency on
the suspend job (either the manual or the automated version of it).

The problem is that the original job did not have any dependency to
force it to be run *before* the suspend job.

This was not an issue for test plans organized manually, using regular
expressions, because you could have an include section that looks like:

    storage_.*
    com.canonical.certification::suspend/suspend_advanced_auto
    after-suspend-storage.*

However, now that template ids can be added in test plans[3], this is a
problem.

This patch will make sure the jobs that need to run before suspend are
added as dependencies of their related suspend job, so that regardless
of the order in the test plan, they will be run in the proper order.

Fix: #1010

[1]
https://checkbox.readthedocs.io/en/stable/reference/units/job.html#job-siblings-field
[2]
https://checkbox.readthedocs.io/en/stable/reference/units/job.html#also-after-suspend-flag
[3]
https://checkbox.readthedocs.io/en/latest/reference/units/test-plan.html
_get_suspend_inhibitor_list() and _get_before_suspend_dependency_set()
work very similarly.

This patch introduces a new helper function,
_is_job_impacting_suspend(), which helps identifying jobs that should
run before the manual and automated suspend jobs.

Both _get_suspend_inhibitor_list() and
_get_before_suspend_dependency_set() make use of it to prevent code
duplication.
With the new helper function, less tests are required.
If the filtering is done on the whole job_list, the suspend job will
depend on jobs that are not required (undesired) for the current session
run.

As a result, the suspend job is skipped with reasons like:

    required dependency 'com.canonical.certification::audio/
    playback_auto' did not run yet

and all of the after-suspend jobs are skipped!

the job_list therefore needs to be narrowed down to remove the
"undesired" jobs and only keep the ones that are actually going to run.
Copy link
Contributor

@kissiel kissiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff, +1

@pieqq pieqq merged commit 990f6ff into main Mar 7, 2024
32 checks passed
@pieqq pieqq deleted the 1010-suspend-job-update branch March 7, 2024 01:01
LiaoU3 pushed a commit to LiaoU3/checkbox that referenced this pull request Mar 20, 2024
…ore suspend (New) (canonical#1037)

Some jobs should be run before *and* after suspend. To take this into
account, the `siblings` field was developed[1], along with the
`also-after-suspend` and `also-after-suspend-manual` flags[2].

These would let Checkbox spawn a similar job with an added dependency on
the suspend job (either the manual or the automated version of it).

The problem is that the original job did not have any dependency to
force it to be run *before* the suspend job.

This was not an issue for test plans organized manually, using regular
expressions, because you could have an include section that looks like:

    storage_.*
    com.canonical.certification::suspend/suspend_advanced_auto
    after-suspend-storage.*

However, now that template ids can be added in test plans[3], this is a
problem.

This patch will make sure the jobs that need to run before suspend are
added as dependencies of their related suspend job, so that regardless
of the order in the test plan, they will be run in the proper order.

Documentation is updated to mention guarantee of job running before
suspend in Job Unit reference page.

Fix: canonical#1010

[1]
https://checkbox.readthedocs.io/en/stable/reference/units/job.html#job-siblings-field
[2]
https://checkbox.readthedocs.io/en/stable/reference/units/job.html#also-after-suspend-flag
[3]
https://checkbox.readthedocs.io/en/latest/reference/units/test-plan.html
binli pushed a commit to binli/checkbox that referenced this pull request Mar 22, 2024
…ore suspend (New) (canonical#1037)

Some jobs should be run before *and* after suspend. To take this into
account, the `siblings` field was developed[1], along with the
`also-after-suspend` and `also-after-suspend-manual` flags[2].

These would let Checkbox spawn a similar job with an added dependency on
the suspend job (either the manual or the automated version of it).

The problem is that the original job did not have any dependency to
force it to be run *before* the suspend job.

This was not an issue for test plans organized manually, using regular
expressions, because you could have an include section that looks like:

    storage_.*
    com.canonical.certification::suspend/suspend_advanced_auto
    after-suspend-storage.*

However, now that template ids can be added in test plans[3], this is a
problem.

This patch will make sure the jobs that need to run before suspend are
added as dependencies of their related suspend job, so that regardless
of the order in the test plan, they will be run in the proper order.

Documentation is updated to mention guarantee of job running before
suspend in Job Unit reference page.

Fix: canonical#1010

[1]
https://checkbox.readthedocs.io/en/stable/reference/units/job.html#job-siblings-field
[2]
https://checkbox.readthedocs.io/en/stable/reference/units/job.html#also-after-suspend-flag
[3]
https://checkbox.readthedocs.io/en/latest/reference/units/test-plan.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants