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

snap, snap/pack: add pack validation for default-configure hook #13097

Conversation

ernestl
Copy link
Collaborator

@ernestl ernestl commented Aug 21, 2023

Additional to PR-12701, to address this comment.

As a temporary measure checkConfigureHooks was added which extends checkSnap that is called from doMountSnap

The requirement is to have a similar check in place in:

  • snap.Validate (with this in place, arguably the temporary measure can fall away)
  • snap pack loadAndValidate

This PR proposes to achieve this by:

  1. Export addImplicitHooksFromContainer and use in loadAndValidate to populate missing implicit hooks to enable validation.
  2. Extend snap.Validate hook validation to check for the invalid combination of default-configure without configure.

Further consideration:

  • Arguably we can remove the temporary measure, but the doMountSnap handler checkSnap uses snap.ReadInfoFromMountPoint which unlike its counterpart snap.ReadInfoFromSnapFile does not have a snap.Validation step included. This means without the temporary measure in place, we would loose the check at that stage.
  • It seems as if direct snap pack testing is limited to a fairly simple case:
    Propose to extend test to include repack of some of the most complicated snaps we have, including essential snaps.

@codecov-commenter
Copy link

codecov-commenter commented Aug 21, 2023

Codecov Report

Merging #13097 (f4f85e9) into master (d8942e6) will increase coverage by 0.00%.
Report is 2 commits behind head on master.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

@@           Coverage Diff           @@
##           master   #13097   +/-   ##
=======================================
  Coverage   78.80%   78.80%           
=======================================
  Files        1011     1011           
  Lines      125673   125691   +18     
=======================================
+ Hits        99032    99056   +24     
+ Misses      20433    20429    -4     
+ Partials     6208     6206    -2     
Flag Coverage Δ
unittests 78.80% <100.00%> (+<0.01%) ⬆️

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

Files Changed Coverage Δ
snap/pack/pack.go 80.15% <100.00%> (+8.97%) ⬆️
snap/validate.go 95.30% <100.00%> (+0.06%) ⬆️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ernestl ernestl force-pushed the SNAPDENG-8345_Default_Configure_Pack_Validation branch 2 times, most recently from e08eaea to f3de965 Compare August 22, 2023 10:05
@ernestl ernestl requested a review from pedronis August 22, 2023 10:37
@ernestl ernestl added the Squash-merge Please squash this PR when merging. label Aug 22, 2023
@ernestl ernestl requested a review from Meulengracht August 22, 2023 10:38
@ernestl ernestl marked this pull request as ready for review August 22, 2023 10:54
Copy link
Member

@Meulengracht Meulengracht left a comment

Choose a reason for hiding this comment

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

Thanks, I think this looks super nice :)

@pedronis
Copy link
Collaborator

@ernestl do you need to merge master to fix golangci-lint issues?

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

direction looks reasonable, some wonderings

@ernestl ernestl force-pushed the SNAPDENG-8345_Default_Configure_Pack_Validation branch from f3de965 to f4f85e9 Compare September 1, 2023 08:26
@ernestl
Copy link
Collaborator Author

ernestl commented Sep 1, 2023

@ernestl do you need to merge master to fix golangci-lint issues?

Yes this was required, I realise it was not ideal to rebase, my apologies.

@@ -117,15 +117,16 @@ func loadAndValidate(sourceDir string) (*snap.Info, error) {
if err != nil {
return nil, err
}
snap.AddImplicitHooksFromContainer(info, container)
Copy link
Collaborator Author

@ernestl ernestl Sep 1, 2023

Choose a reason for hiding this comment

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

I attempted approach to create /internal helpers and share code with ReadInfoFromSnapFile, but concluded it would not look/work nice. As far as I can see not possible without exporting new function, so exporting AddImplicitHooksFromContainer seems like an ok trade-off.

@ernestl ernestl changed the title snap, snap/pack: enhance snap pack validation to cover default-configure hook snap, snap/pack: add pack validation for default-configure hook Sep 4, 2023
@ernestl ernestl requested a review from Meulengracht September 4, 2023 09:51
@pedronis pedronis self-requested a review September 4, 2023 09:59
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

thanks

Copy link
Member

@Meulengracht Meulengracht left a comment

Choose a reason for hiding this comment

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

Thank you

@ernestl ernestl merged commit 0815f66 into canonical:master Sep 6, 2023
alexmurray pushed a commit to alexmurray/snapd that referenced this pull request Oct 17, 2023
…nical#13097)

* snap/pack: enhance snap pack to validate all container info

* snap: enhanced snap info validation to flag default-configure without configure hook

* snap: fixed implicit hook test

* snap, snap/pack: added unit tests

* snap/pack: add additional unit tests

* snap: revert back to not using ReadInfoFromSnapFile
fredldotme pushed a commit to fredldotme/snapd that referenced this pull request Jun 4, 2024
…nical#13097)

* snap/pack: enhance snap pack to validate all container info

* snap: enhanced snap info validation to flag default-configure without configure hook

* snap: fixed implicit hook test

* snap, snap/pack: added unit tests

* snap/pack: add additional unit tests

* snap: revert back to not using ReadInfoFromSnapFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Squash-merge Please squash this PR when merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants