Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Fix databag item update for recent versions of chef (>10) and add commis/wsgi.py #14

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ageron
Copy link

@ageron ageron commented Apr 18, 2013

Here's a fix for the databag item update bug discussed in Issue #13 (#13).

I also added wsgi.py... it can't hurt ! ;-)

ps: I pushed 2 untested and buggy commits before getting the thing to work in the 3rd commit. I know I could hack around the git history to remove these, but I don't have much time, so I hope you won't mind.

raise ChefAPIError(500, 'Name mismatch in data bag item')
item = self.get_item_or_404(bag_name, name)
update(item, data=request.raw_post_data)
update(item, data=json.dumps(data, indent=4))
Copy link
Owner

Choose a reason for hiding this comment

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

Why the indent? Might as well make it smaller in the DB :)

@ageron
Copy link
Author

ageron commented Apr 18, 2013

You're right, there's really no reason at all to have an indent here.

@ageron
Copy link
Author

ageron commented Apr 19, 2013

I added fixes for issues 15 & 16 regarding file upload.

@coderanger
Copy link
Owner

And yet you haven't fixed the indent so I can't merge it ;-)

@coderanger
Copy link
Owner

I'm also not sure your upload logic is correct. The point is that if the checksum already exists on the server it shouldn't be uploaded again, there should just be a new metadata entry in the cookbook version pointing at the same file data.

@ageron
Copy link
Author

ageron commented Apr 20, 2013

Hi,
I just removed the indent. :-)
I think my upload logic does what you're describing: first I try to find the CookbookFile for the given type and path (btw, wouldn't the path be sufficient?):
cookbook_file = cookbook.files.get(type=type, path=file_info["path"])
if it does not exist, then create it.
If the cookbook_file's content (aka SandboxFile) matches the requested checksum, then we're done. But if it does not (*), then we search for an already uploaded content matching the requested checksum. If it exists, then we point the cookbook_file to it. If it does not exists, we raise an Exception, so that the file will be uploaded.

Does this sound ok to you?

Cheers,
Aurélien

(*) This can happen if someone modifies a cookbook and forgets to change its version (or does not want to, for some reason) and then uploads the cookbook. Before my patch, I ended up with two cookbook_files for the same path (one for the old content, one for the new content).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants