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

fix: match python version in agent test workflow to version on agent #258

Merged
merged 32 commits into from
Apr 24, 2024

Conversation

boukeas
Copy link
Contributor

@boukeas boukeas commented Apr 19, 2024

Description and resolved issues

Merging #250 and deploying to staging uncovered certain issues.

  • Unpacking attachments fails on the agent used for testing because unpacking uses the filter argument of tarfile.extractall which is not supported in the Python version installed on the agent, i.e. 3.8.10.
  • This issue would normally have surfaced in the agent testing workflow, prior to deployment. It did not because that workflow does not specify a Python patch version (only 3.8), resulting in the latest patch version being installed, i.e. 3.8.18). The filter argument was added in version 3.8.17, so it is supported in the environment used for testing in the workflow but not in the actual agent.
  • Testing on staging revealed that the provisioning and firmware update stages were triggered when attachments were provided under the provision_data and firmware_update_data fields. The code assumes that any data under these fields suggests that the corresponding stages should be triggered.

Changes

  • A fully qualified Python version (3.8.12) is specified in the agent testing workflow. It does not match the Python version installed on the agent because that version is not available on our self-hosted runners, but it is sufficient for testing because the filtering feature was introduced in 3.8.17.
  • The filter functionality provides an important safety feature. Instead of re-implementing what would necessarily be a subset of that functionality, I decided to use a minimal subset of the implementation provided in the main branch of the Python standard library. A check in the imports section decides whether or not to use the tarfile that comes with the current Python installation (if it supports filter) or the alternative one otherwise. The major advantages to this solution is that (a) the actual unpacking code remains unchanged and uses the filter functionality and (b) this is not a version-sensitive solution, i.e. whenever it can be guaranteed that the agents will run a Python version supporting filter, the unpacking code will remain the same and only the conditional import will be removed.
  • After attachments are unpacked, attachment data is stripped from the job data dict, restoring it to a state that is identical to how it would be if attachments had not been included (i.e. like the good old days). This respects any assumptions that Testflinger makes about the contents of the job data dict and removes any possible interference with other stages. Note that attachment data doesn't even need to be included in the job data dict in the first place (it's all in the gzipped-tar archive) and it may be removed anyway in a later version. The reasons it has been kept are that (a) it is useful to display the attachments under the Provision Data and Firmware update data sections of the Job page on Testflinger and (b) it is yet unclear how that attachment data might be used by a device connector later down the line.

boukeas added 26 commits April 19, 2024 10:44
The Python version currently installed on (some of) the agents is 3.8.10.
The agents test workflow installs 3.8 -> 3.8.18, which will lead to
version-sensitive code passing when it shouldn't.
The provisioning and firmware update phases will be triggered when
`provision_data` or `firmware_update` data are not empty, which is the
case when attachments are provided for these phases.

In order to minimise changes to the agent code and keep its logic
exactly the same as before (for now), attachment data is *stripped*
from the job data dict as soon as the attachments are unpacked. This
eliminates any interference that the presence of attachments may have
to the execution of each phase.
Copy link
Collaborator

@plars plars left a comment

Choose a reason for hiding this comment

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

patching things up like this is certainly not my favorite thing to do, but I'm ok with it as a temporary measure if we don't have a better approach. I was really hoping we could use the get_members workaround that I suggested before, but you're right that there's a lot going on in the existing data_filter and get_filtered_attrs that we would miss if we just did that.

Copy link
Contributor

@thp-canonical thp-canonical left a comment

Choose a reason for hiding this comment

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

Some ideas.

agent/tox.ini Outdated Show resolved Hide resolved
agent/testflinger_agent/tarfile_patch.py Outdated Show resolved Hide resolved
@boukeas boukeas marked this pull request as ready for review April 23, 2024 15:27
@boukeas boukeas requested a review from plars April 23, 2024 15:27
Copy link
Contributor

@nadzyah nadzyah left a comment

Choose a reason for hiding this comment

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

The changes look good in general, I'd just like to suggest the simplification of some parts of the code

agent/testflinger_agent/agent.py Outdated Show resolved Hide resolved
agent/testflinger_agent/tarfile_patch.py Show resolved Hide resolved
agent/testflinger_agent/tarfile_patch.py Show resolved Hide resolved
Copy link
Contributor

@thp-canonical thp-canonical left a comment

Choose a reason for hiding this comment

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

I didn't check whether agent/testflinger_agent/tarfile_patch.py is a proper subset of Python 3.8's tarfile.py, but trust that somebody else will verify that :)

Added one more comment about simplifying the nested try..except..else blocks, but other than that, I think this is fine. It might also make sense to add some comment along the lines of "if you read this comment and the minimum supported Python version is >= X.Y.Z, the tarfile_patch.py file can be removed and the import changed back to tarfile".

@boukeas boukeas requested a review from nadzyah April 23, 2024 16:15
Copy link
Collaborator

@plars plars left a comment

Choose a reason for hiding this comment

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

one very small thing, otherwise looks fine to me.

.github/workflows/agent-tox.yml Show resolved Hide resolved
@boukeas boukeas merged commit 3b5616d into main Apr 24, 2024
2 checks passed
@boukeas boukeas deleted the CERTTF-303-attachments-tarfile branch April 24, 2024 11:08
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.

4 participants