Skip to content

new: allow providing the image over attachment for IoT#1026

Draft
p-gentili wants to merge 3 commits intomainfrom
iot-provisioning-artifact
Draft

new: allow providing the image over attachment for IoT#1026
p-gentili wants to merge 3 commits intomainfrom
iot-provisioning-artifact

Conversation

@p-gentili
Copy link
Copy Markdown
Contributor

Description

The server side now allows the user to provide the boot image as at attachment, useful when there's no accessible URL hosting the artifact.

Resolved issues

Part of https://warthogs.atlassian.net/browse/ZAP-1436

Documentation

On server side

Web service API changes

N/A

Tests

Updated.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 95.77465% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.33%. Comparing base (ebf71bd) to head (0438f5e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1026      +/-   ##
==========================================
+ Coverage   77.21%   77.33%   +0.12%     
==========================================
  Files         116      116              
  Lines       12065    12122      +57     
  Branches      996      998       +2     
==========================================
+ Hits         9316     9375      +59     
+ Misses       2520     2519       -1     
+ Partials      229      228       -1     
Flag Coverage Δ *Carryforward flag
agent 75.78% <ø> (ø)
cli 91.80% <ø> (ø) Carriedforward from 151e6e5
device 63.76% <100.00%> (+0.41%) ⬆️
server 87.01% <70.00%> (+0.08%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
Agent 75.78% <ø> (ø)
CLI 91.80% <ø> (ø)
Common ∅ <ø> (∅)
Device Connectors 63.76% <100.00%> (+0.41%) ⬆️
Server 87.01% <70.00%> (+0.08%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

@ajzobro ajzobro left a comment

Choose a reason for hiding this comment

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

I know it's in draft, but it caught my eye :-)

if not attachments_dir.is_dir():
return None
files = sorted(p for p in attachments_dir.iterdir() if p.is_file())
return files[0] if files else None
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think that taking the first file alphabetically is a very robust solution. If we intend to keep it this way, can you include commentary as to why this choice was made?

has_url = "url" in data
has_urls = "urls" in data
if has_url and has_urls:
def validate_image_source(self, data, **_):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if this is a "boot" image, could we consider adding the classifier onto the variable name so as not to confuse it with other "image" contexts.

has_urls = "urls" in data
if has_url and has_urls:
def validate_image_source(self, data, **_):
"""Validate that at most one URL source is provided.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Validate that at most one URL source is provided.
"""Validate that at most one boot image source is provided.

if (
"url" not in data
and "urls" not in data
and not data.get("attachments")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we seem to be missing an error message in the case where url(s) and an attachment have been provided. It seems reasonable (based on the comments above) that if the attachment will be used to the exclusion of the urls that if both a boot image provisioning attachment and a url/urls are provided that we should respond with an appropriate error rather than silently discard or otherwise not use the url/urls value(s).

)


class ZapperIoTCustomProvisionData(BaseZapperProvisionData):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since both of these leverage the Base -- is it really the base that should be getting these new rules? Or should we have a ZapperIoT*ProvisionData class?

class ZapperIoTCustomProvisionData(BaseZapperProvisionData):
class ZapperIoTPresetProvisionData(BaseZapperProvisionData):

I have the same comments for both classes.

Comment thread server/tests/test_v1.py
def test_add_job_zapper_iot_custom_provision_data_attachment(mongo_app):
"""Test that a job with zapper_iot_custom using an attachment works."""
provision_data = {
"attachments": [{"agent": "provision/image.img"}],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

see comments above about picking the first file alphabetically -- can we at least only look at *.img files if that's the standard?

Comment thread server/tests/test_v1.py
output = app.post("/v1/job", json=job_data)
assert HTTPStatus.OK == output.status_code


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add more tests or combinations of mutually exclusive things (url/urls/attachments)

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