Collect test resources and write to file
What does this MR do and why?
Describe in detail what your merge request does and why.
QA team task https://gitlab.com/gitlab-org/quality/team-tasks/-/issues/1033
In this MR we are trying to call QA::Tools::TestResourceDataProcessor.collector(args, args)
every time do_fabricate!
is called (when a resource is created). This will keeps collecting any and all resources created during 1 single suite run and save into a hash of resources collection. At the end of the suite run QA::Tools::TestResourceDataProcessor.write_to_file
is called. Here, a couple different scenarios can happen:
- If there isn't any target json file then the file is created and the collection is written to the file.
- If the file is created locally, it has a simple name
test-resources.json
and lives underqa/tmp/
. - If the file is created in CI, the file name should have a random string attached to it as an artifact for a job from a later stage to use.
- If the file is created locally, it has a simple name
- In case the file was already there and there are existing content in the file (happens when run tests locally). The new data is merged with the old data without overriding anything then override the file content with the new collection.
- The JSON should look like this (same format either locally or in CI):
{
"QA::Resource::Group": [
{
"info": "with full_path 'gitlab-qa-sandbox-group/qa-test-2022-01-05-20-27-51-6b9ed0dd5a06714d'",
"api_path": "/groups/5"
}
],
"QA::Resource::Project": [
{
"info": "with full_path 'gitlab-qa-sandbox-group/qa-test-2022-01-05-20-27-51-6b9ed0dd5a06714d/project-to-test-assignees-07ec00a08add5662'",
"api_path": "/projects/2"
}
],
"QA::Resource::Issue": [
{
"info": "with id '1'",
"api_path": "/projects/2/issues/1"
}
]
}
The deletion doesn't happen until QA::Tools::DeleteTestResources.new(args).run
is called either via rake task locally or in a CI job.
- If called locally, read and parse the file, go through each type of resource, check for what doesn't return 404 get request GET then DELETE. For now, what failed to be deleted would only be printed out in the result.
- If called in CI, the logic is the same but every test job would have 1
test-resources-<randomstring>.json
file so we would gather this collection of file, go through each and callQA::Tools::DeleteTestResources.new(args).run
individually.
Relates to:
-
gitlab-qa!826 (closed) - Add
delete-test-resources
job and stagecleanup
. -
gitlab-org/quality/pipeline-common!119 (merged) - Add
.delete-test-resources-base
.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.