Added a special datastructures (CoercedList, CoercedDict and CoercedSet)
which are able to coerce their values to appropriate element type.
The instances of these structures are returned when the values of
appropriate compound fields initially coerced. As a result, all
subsequent calls which are going to add new elements to the fields'
colelctions will be processed by the overridden methods of new
datastructures, thus the new elements will be coerced and the exceptions
risen if the coercing is not possible.
This also fixes a bug in TestObjMakeList which was specifying incorrect
obj_name for the elements in 'objects' collection of MyList test class.
It was not leading to failures as the items of this collection were not
being coerced prior to this patch.
Change-Id: I004646ce643e7e51305cfb1cd4eb5e8647a83513
Closes-Bug: #1466057
The coerce method impls all raise an exception when the
python type provided for a field does not match what was
required. Sometimes it is pretty hard to figure out what
the wrong type was, so report this along with the desired
type
This changes the exception message from something like
"A datetime.datetime is required in field start"
to
"A datetime.datetime is required in field start, not a str"
which can help debugging.
Change-Id: I53535e7af2165285ef1804f03f0beebe8fc42a59
ObjectVersionChecker just needs a list of classes, we don't need
to check the base.VersionedObjectRegistry everytime, so just
initialize the list of classes in the constructor and default
it to the base.VersionedObjectRegistry to get the current
behavior. Will make it easy to run ObjectVersionChecker against
custom registries.
Change-Id: I700daa278473dff5285e0b21afffc03671e390f9
Currently, objects will directly instantiate the EnumField
class, passing in the list of valid enum values. This is
sub-optimal as the same enum type may be needed in several
objects, and we want to ensure we're always using the same
list of valid values.
To address this, introduce a BaseEnumField class that provides
the custom __repr__() impl based on the enum values. Make the
existing EnumField subclass this, to allow for continued use
of anonymous enum fields, but discourage its use in favour of
creating named enum fields by directly subclassing BaseEnumField
Change-Id: I83199b0f791d3ac5591c7dfc1d14f4fa706d0a64
The current Boolean field type has a strict interpretation of
truth values which matches the python language interpretation.
For data that comes from the end user though, it is more useful
to have a flexible interpretation, that accepts commonly used
strings like 'yes', 'no', 'on', 'off', etc as handled by the
oslo_utils bool_from_string() method
Since the Boolean field is part of the ABI/API, we cannot
change its semantics, so this introduces new FlexibleBoolean
and FlexibleBooleanField classes
Change-Id: Id785cdd99eca5ac469db9d7b4759957461873cee
Rewrite README.rst and copy it to doc/source/index.rst to add a little
bit more content.
Generate documentation for APIs. fixture, safe_utils and test submodules
are not documented.
Fix indentation in obj_reset_changes() docstring.
Fix formatting of obj_make_list() docstring.
Co-Authored-By: Dan Smith <dansmith@redhat.com>
Change-Id: I8110919de072c5a5139e3797f256925c92656117
Add more dictionary methods to VersionedObjectDictCompat:
* __iter__()
* keys(), iterkeys()
* values(), itervalues()
Thanks to new methods, dict constructor now accepts
VersionedObjectDictCompat: it's possible to write directly dict(obj)
instead of having to write dict(obj.iteritems()).
On Python 3, items() now returns an iterator instead of a list, to
respect Python 3 dictionary API, as the new keys() and values() methods.
Keep iterkeys(), itervalues() and iteritems() on Python 3, even if
Python 3 dictionaries don't have these methods, just to ease the
transition from Python 2 to Python 3 in Nova.
Change-Id: I4c52d44c7ba49f98b1bbd123209fce7b70ade98d
VersionedObjectDictCompat code come from Nova. While Nova may drop the
dictionary compatibility, dropping a class in a library requires a
deprecation process, so notes are not really usefull.
Remove also useless docstrings: in oslo_versionedobjects, there is no
really "backward compatibility" issue since it's a new library. Again,
docstrings came from Nova, but I consider them useless in this library.
Replace also "compat" with "compatibility" in VersionedObjectDictCompat
docstring.
Change-Id: Ie42e9ef68f3acd657521454ff3cb5fbdc42ad416
The coerce() methods in object fields generate ValueError
exceptions if an incorrect type is used. Most of the messages
do not indicate which field was involved although that information
is available in the coerce() methods. This change adds the
field name to the error messages.
Ported from:
Ic94d52f6019c5a5a291675e321f96f5c65beaf10
Co-Authored-By: Paul Murray <pmurray@hp.com>
Closes-Bug: #1430681
Change-Id: I4a359ea1478481e81f66c9c20e0bcac79ccd6a3a
Unit tests are failing without it, and the file
oslo_versionedobjects/exception.py has:
import webob.exc
So it's looking like webob is missing from requirements.txt.
This patch fixes that. Note that this should be fixed in
the kilo branch later on.
Change-Id: Ib0ac48aeea4f8413740af89340e3b094312fa6b4
In some case, one field should be limited to some value, like the
cpu architect field.
Make sure that when the value limitation is changed,
the fingerprint will be changed, so that a version bump should happen.
Ported (but changed for consistency) from:
I7848f8b934c169a76b1cfd875f7905273f9f914b
Co-Authored-By: yunhong jiang <yunhong.jiang@intel.com>
Co-Authored-By: Dan Smith <dansmith@redhat.com>
Change-Id: Iac498869d10d2238b3ddf704640cd152cb794099
To avoid having to monkey-patch the VersionedObject class from the oslo
library, get the indirection_api from the current self or cls variables
(the class or instance inheriting from the VersionedObject class) in
remotable decorators.
Change-Id: I8fed628e3d82539e477b8b72532858095a9b8ef4
Update the version of hacking to the one released for kilo, and fix
issues with code formatting that cause the new hacking checks to fail.
Change-Id: I4c9906df3e71f33b5a13e1f68584d445d79daceb
Port If8e73b92e798cc16cac4952974f5e6210c1bc5e1 from Nova
Currently the default value will be used for all instances of the nova
objects. We should return only a copy.
Co-Authored-By: yunhong jiang <yunhong.jiang@intel.com>
Change-Id: I64c0bee754706ed1ed1e6329217cc30d145d11b9
Lot of projects use fatal_exception_format_errors, we
need to separate out ours in its own group.
Closes-Bug: #1433647
Change-Id: I7a53ed2c5b2387214c4edba7295cb800e12f47a9
Pulling in changes to remove oslo namespace in _i18n module
and the list_opts for better configuration support with
oslo-config-generator in versionutils module
(Tip of oslo-incubator is change id - Id69701978d7a1701885bf17507a1f369e1035747)
Change-Id: Ibc793966fb442a870785186257ab44f1afc3e0b1
The fixture was just serializing and deserializing method arguments
with JSON, but this is not indicative of what actually happens in
a real project (like nova) where arguments can be objects.
Change-Id: I299983a2e345a2b8075038553c6a4dd77d3fd5e8
This makes it easier to ensure that you're using the same indirection
or serialization routines in tests as you are in production.
Change-Id: I4530ba5781ad81ad4a6b4af466af348551c3c3e4
This was found when converting nova to use o.vo. If we provide our own
base class (for namespacing reasons) we need the serializer to use it
(as intended) to find the indirection_api.
Change-Id: I480427fe97476e4e20fef453be6bb6ed28ae51ac
This was another pretty Nova-specific helper function that embedded
serialization of certain data types in method arguments.
Change-Id: I44a9188c3578d10b5647d077f912b765a5696acf
This allows the serialization and project namespaces to be overridden in
subclasses of VersionedObject. The project one should be set on each
using implementation, but the base serialization one is just there for
projects that already use this code and need it to be equal to what they
currently use.
Change-Id: Iecec043adc31441cc8865fa5e54d9a0ee4a5989a