[openstack-dev] [all][dev][python] constructing a deterministic representation of a python data structure

Davanum Srinivas davanum at gmail.com
Thu Nov 3 19:02:48 UTC 2016


Does oslo.versionedobjects solve some of your needs?

http://www.slideshare.net/davanum/ovo-deep-dive
https://gorka.eguileor.com/learning-something-new-about-oslo-versioned-objects/
http://www.danplanet.com/blog/2015/10/06/upgrades-in-nova-objects/

-- Dims

On Thu, Nov 3, 2016 at 2:24 PM, Amrith Kumar <amrith at tesora.com> wrote:
> TL;DR
>
>
>
> I want to take a python data structure (see later for details) and represent
> it in a format that will be stable across python versions, and platforms so
> that I can construct a stable hash. I’m looking for pointers to some best
> practices on how to do this.
>
>
>
> The longer version
>
>
>
> Assume that there’s some function in python that is:
>
>
>
> def fn(*args, **kwargs):
>
>>
>
>
> I’d like to take (args, kwargs) and construct a hash of some representation
> that is deterministic. Specifically, assume that fn() is a method in the API
> (oslo.messaging transport …). I’d like to construct the hash on the sender
> side and on the RPC server side and make sure that the parameters are the
> same.
>
>
>
> So, just before calling call() or cast(), I could compute the hash and stuff
> it into the dictionary that is being sent over, and I can do the same on the
> receiving side. But since I cannot guarantee that the representation on the
> receiving side is necessarily identical to the representation on the sending
> side, I have issues computing the hash.
>
>
>
> In IRC, jroll suggested json; can one safely assume that json.dumps() is a
> deterministic representation?
>
>
>
> Thanks for any pointers and suggestions.
>
>
>
> -amrith
>
>
> __________________________________________________________________________
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>



-- 
Davanum Srinivas :: https://twitter.com/dims



More information about the OpenStack-dev mailing list