storeapi: support for pushing binary metadata #1774

Merged
merged 4 commits into from Dec 5, 2017

Conversation

3 participants
Contributor

matiasb commented Nov 29, 2017

Update push-metadata command to also push binary metadata (so far, icon only).

@sergiusens sergiusens added this to the 2.37 milestone Nov 29, 2017

This looks mostly good, though I have a question and it seems perhaps one test case isn't there. I need to give this a more thorough test tomorrow.

snapcraft/_store.py
+ ['unsquashfs', '-d',
+ os.path.join(temp_dir, 'squashfs-root'),
+ snap_path, '-e', 'meta/gui'])
+ logger.debug(output)
@kyrofa

kyrofa Nov 30, 2017

Member

I suspect this debug output will not be very useful on its own. Would it be worth adding some context to it?

@matiasb

matiasb Nov 30, 2017

Contributor

Yeah, makes sense, let me fix that.

@@ -404,6 +425,9 @@ def push_metadata(snap_filename, force):
with _requires_login():
store.push_precheck(snap_name)
store.push_metadata(snap_name, metadata, force)
+ with _get_icon_from_snap_file(snap_filename) as icon:
+ metadata = {'icon': icon}
+ store.push_binary_metadata(snap_name, metadata, force)
@kyrofa

kyrofa Nov 30, 2017

Member

It's possible for the icon to be None, here. I can't tell from the below: will that remove the icon from the store? That situation does not seem covered by tests.

@matiasb

matiasb Nov 30, 2017

Contributor

Yes, icon could be None, and that will remove the icon from the store.
I'll review tests and add it if missing. Thanks!

Member

kyrofa commented Dec 1, 2017

Thanks for the additional test, @matiasb. I've also tested this against the staging store with success. However, is there no way to selectively update metadata without updating it all in one go? What if I only wanted to update the icon, but not the other metadata?

Contributor

matiasb commented Dec 1, 2017

The implementation is the result of the discussion in https://forum.snapcraft.io/t/mechanisms-for-converging-store-and-snap-metadata/2200 (that summarizes the discussions during the rally too).
It would be simple to split text and binary metadata in different commands.
Note that, in any case, the metadata being pushed is extracted from a given revision, so not sure if you would want to push an icon from a revision and the description from another, for example (ie. you cannot push a specific value for a particular field, independent of a revision, as things were discussed at least -the store API would allow it, though-).

@sergiusens sergiusens changed the title from Push binary metadata to the Store to storeapi: support for pushing binary metadata Dec 1, 2017

manual-tests.md
+
+# Test push binary metadata with conflicts
+
+1. 'snapcraft build' a simple snap
@sergiusens

sergiusens Dec 1, 2017

Collaborator

this should be snapcraft snap, build is an intermediate command

@matiasb

matiasb Dec 4, 2017

Contributor

Right, fixing here and the previous one.

manual-tests.md
+2. Do a simple 'snapcraft push SNAP'
+3. Go to the Web and change snap's icon
+4. Change the snap's icon in the YAML file to something different than you put in the Web
+5. Try to update snap's metadata using `snapcraft push-metadata SNAP`
@sergiusens

sergiusens Dec 1, 2017

Collaborator

Does pushing the snap also raise the conflict?

@sergiusens

sergiusens Dec 1, 2017

Collaborator

Can we add a test for that?

@matiasb

matiasb Dec 4, 2017

Contributor

Push won't raise the conflict, and it won't update the metadata either. Metadata from a pushed revision will only be used if there are no previous changes made in the web UI.
Should we think about adding some warning/message while processing a push about conflicting metadata?

@sergiusens

sergiusens Dec 4, 2017

Collaborator

We shouldn't block on this for the PR, but an error code saying the metadata is not being updated due to divergences for which we can on the client instruct the user would be good. Being silent by default is fine.

snapcraft/_store.py
+ icon_file = open(icon_path, 'rb')
+ break
+ yield icon_file
+ if icon_file is not None:
@sergiusens

sergiusens Dec 1, 2017

Collaborator

should the yield above be wrapped in between a try and finally to always check and close the icon handle?

@matiasb

matiasb Dec 4, 2017

Contributor

Yes, updating.

snapcraft/storeapi/__init__.py
+
+ files = {}
+ # only icon support atm
+ icon = metadata.get('icon')
@sergiusens

sergiusens Dec 1, 2017

Collaborator

this is going to end up being a rather big function, how about a private module inside storeapi to handle this with some OO? Nothing complex

what do you think?

@matiasb

matiasb Dec 4, 2017

Contributor

Let me take a look, will try to refactor it.

Looks really good, just have comments/questions to throw back at you.

Collaborator

sergiusens commented Dec 5, 2017

works great
we do need to polish all that red in those errors.

@sergiusens sergiusens merged commit d549249 into snapcore:master Dec 5, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

gsilvapt added a commit to gsilvapt/snapcraft that referenced this pull request Dec 8, 2017

storeapi: support for pushing binary metadata (#1774)
Update the push-metadata command to also push binary metadata (so far, icon only).

daniellimws added a commit to daniellimws/snapcraft that referenced this pull request Dec 14, 2017

storeapi: support for pushing binary metadata (#1774)
Update the push-metadata command to also push binary metadata (so far, icon only).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment