Skip to content

Commit

Permalink
Add info to rejected jobs list in submission.json (new) (#1520)
Browse files Browse the repository at this point in the history
* Include more information for rejected jobs

The list of rejected jobs (jobs that have been de-selected prior to
running a test plan) is modified, so that instead of storing a list of
job ids, it stores a list of job representations (dictionaries holding
not only the job id but also additional info such as its plugin,
template_id, etc.)

* Add unit test for use_alternate_selection()

* Update submission schema

Add the new fields for the rejected-jobs section in the submission
schema.

In addition, `Plugin` can take 2 additional values, as explained in the
documentation[1], since there are attachment and resource jobs.

[1]:
https://canonical-checkbox.readthedocs-hosted.com/en/stable/reference/units/job.html
  • Loading branch information
pieqq authored Oct 10, 2024
1 parent d0fda12 commit dd75a99
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@
"rejected-jobs": [
{%- for job_id in state.metadata.rejected_jobs %}
{
"full_id": "{{ job_id }}"
"id": "{{ job_id|strip_ns }}",
"full_id": "{{ job_id }}",
"name": "{{ job_state_map[job_id].job.tr_summary() }}",
"plugin": "{{ job_state_map[job_id].job.plugin }}",
"certification_status": "{{ job_state_map[job_id].effective_certification_status }}",
"category": "{{ category_map[job_state_map[job_id].effective_category_id] }}",
"category_id": "{{ job_state_map[job_id].effective_category_id }}",
"template_id": {{ job_state_map[job_id].job.template_id | jsonify | safe }}
}{%- if not loop.last -%},{%- endif %}
{%- endfor %}
],
Expand Down
23 changes: 23 additions & 0 deletions checkbox-ng/plainbox/impl/session/test_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
UsageExpectation,
SessionMetaData,
)
from plainbox.impl.unit.job import JobDefinition
from plainbox.vendor import morris


Expand Down Expand Up @@ -276,3 +277,25 @@ def test_finish_bootstrap_match_no_match(
# called once to get all the jobs for the selected testplan
# and another time to prune it for match
self.assertEqual(select_units_mock.call_count, 1)

@mock.patch(
"plainbox.impl.session.assistant.UsageExpectation",
new=mock.MagicMock(),
)
def test_use_alternate_selection(self, mock_get_providers):
self_mock = mock.MagicMock()

job1_id = "com.canonical.certification::job_1"
job2_id = "com.canonical.certification::job_2"
job1 = JobDefinition({"id": job1_id})
job2 = JobDefinition({"id": job2_id})

self_mock.get_static_todo_list.return_value = [job1_id, job2_id]
self_mock._context.get_unit.side_effect = [job1, job2]
selection = [job1_id]

SessionAssistant.use_alternate_selection(self_mock, selection)
self.assertEqual(len(self_mock._metadata.rejected_jobs), 1)
self_mock._context.state.update_desired_job_list.assert_called_with(
[job1]
)
56 changes: 53 additions & 3 deletions submission-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@
},
"plugin": {
"$ref": "#/definitions/Plugin"
},
"template_id": {
"anyOf": [
{
"type": "null"
},
{
"type": "string"
}
],
"description": "If the job is instantiated from a template, this field points to its origin template."
}
},
"required": [
Expand All @@ -200,7 +211,9 @@
"io_log",
"name",
"outcome",
"status"
"status",
"plugin",
"template_id"
],
"title": "Result"
},
Expand Down Expand Up @@ -542,12 +555,47 @@
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
},
"full_id": {
"type": "string"
},
"name": {
"type": "string"
},
"plugin": {
"$ref": "#/definitions/Plugin"
},
"certification_status": {
"$ref": "#/definitions/CertificationStatus"
},
"category": {
"type": "string"
},
"category_id": {
"type": "string"
},
"template_id": {
"anyOf": [
{
"type": "null"
},
{
"type": "string"
}
],
"description": "If the job is instantiated from a template, this field points to its origin template."
}
},
"required": [
"full_id"
"id",
"full_id",
"name",
"category",
"category_id",
"plugin",
"template_id"
],
"title": "RejectedJob"
},
Expand Down Expand Up @@ -645,7 +693,9 @@
"shell",
"user-interact-verify",
"user-interact",
"manual"
"manual",
"attachment",
"resource"
],
"title": "Plugin"
},
Expand Down

0 comments on commit dd75a99

Please sign in to comment.