This allows us to use a new version of flake8 that supports Python
3-only syntax. Existing issues are resolved.
Change-Id: I5de7e5cde6a5260f4e7e57586952256b59d3756d
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
We no longer need much of the functionality this was providing.
Change-Id: I0f625b714950a712249757906974715358f9e6c6
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This addresses a couple sources of deprecation warnings in the code.
The collections package has moved abstract base classes from
collections.* to collections.abc.*. Use of the old path causes
DeprecationWarning messages now, but will eventually be removed. Six
does not support this yet, so for now just try the newer preferred path
and fall back to the old path if the import fails.
This also addresses unit test deprecation methods with self.skip()
changing to self.skipTest().
Change-Id: I0463ab2109adeee6468261f9e96225766a55998e
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
The type check on the list field requires a list, though many
objects can be trivially iterated as lists, like sqlalchemy
lazy query objects. Relax the check slightly to fit a broader
range of "lists".
Change-Id: I514a0e6d445e9a14e3c0279b4e9bebfa0940337d
This adds a simple ListOfUUIDField which is copied from
kuryr-kubernetes and is also needed in nova.
Change-Id: Ife866af6e07c887774689fd98ac6fde6fa55d6de
The string representation of an empty set is different between py27 and
py35. The ObjectVersionChecker uses the string represenation of the
default value of the fields as input for the hash of the object. This
makes hash of an object with a set field defaulted to an empty set
unstable.
This patch enhances the repr generation of the Field object to avoid the
unstable hash situation.
Change-Id: Ie9519c1893175614d60af97b635e6ff57f2b0d7d
Closes-Bug: #1771804
Change Ic6b6308fb1960ec40407e6efde30137b64543e72 attempts to
fix difference between Python 2 and Python 3 values by switching
from using str() to formatting into a unicode string (u"%s").
This is equivalent to changing str() to unicode(), but that is
not correct for expected default string types for Python 2.
This requires either using six.text_type(), or just formatting
into a string, without forcing unicode ("%s"), to be correct on
either runtime.
Change-Id: I178f14cdc670d7a696778891e587ef75de208fc2
Closes-bug: #1763179
If we use non uuid unicode user id in py27 env,
unicode error pop up when function is called.
Closes-bug: #1760918
Change-Id: Ic6b6308fb1960ec40407e6efde30137b64543e72
Today UUIDField emits a warning if the provided value is not a valid
UUID. However this warning cannot be escalated to an exception through
the standard warnings module because the validation code also adds a
warning filter to the warning filter list that overrides the existing
filters.
This patch ensures that the 'once' warning filter only added to the
end of the filter list. This way if the client has already specified
another filter for this warning (e.g. and error filter) then that
filter will not be overriden.
Change-Id: I17cb96d16fcd91195478b738fbdda01b47cfd69d
Closes-Bug: #1746966
iso8601.UTC is correct datetime UTC field object.
iso8601.UTC is correct datetime UTC field object.
iso8601 >= 0.1.12 includes only iso8601.UTC for python3
while both UTC and Utc() for python2. Less then 0.1.12
included both UTC and Utc() for both python2/3.
Change-Id: Ie7957959e836d2f78409d4197c6a2d7ad9e8457b
Closes-Bug: #1713354
This is done so that nullable Object field's schema can be given the null or
object type property.
implements bp json-schema-for-versioned-object
Change-Id: I43b04a76cccc9d4f893162535050fed6940bee6c
1.As mentioned in [1], we should avoid using
six.iteritems to achieve iterators. We can use
dict.items instead, as it will return iterators
in PY3 as well. And dict.items/keys will more readable.
2.In py2, the performance about list should be negligible,
see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html
Change-Id: I6bf760e6f3db50696dc87230c444f9ed493615f0
When the 'Object' field stringifys a value, it is
currently hardcoded to report the object name that
the field was initialized with. This used to be
sufficient, until the 'subclasses' parameter was
added. When subclasses=True, the value may be any
arbitrary subclass, so we should be reporting the
actual object name associated with the value.
Closes-Bug: #1638577
Change-Id: I0bb4ade30a60554710a12f0f058945ef43826eff
Created a base class StringPattern that implements similar JSON schema for
patterned field types - UUID, PCI, MAC, IP Address
implements bp json-schema-for-versioned-object
Change-Id: Ie44ad83ce0cb41bec538adcd336dacdcafebd3ea
The Enum field is a subclass of String. However, when dumping schema, it
was not dumping its data type so the schema dumped was useless. This
patch fixes the issue.
Change-Id: I373f13412003a68fa0207ba44658b96ed7dc46a0
This implements the get_schema() method of the following FieldType:
Object, IPV6Address, NonNegativeInteger, NonNegativeFloat,
IPV4AndV6Address, Dict(fixed from last patch)
implements bp json-schema-for-versioned-object
Change-Id: I6bce3ba7bb32ed2dd8ed6e7f313411bbfef5eff0
This implements the get_schema() method of the following FieldType
classes:
UUID, MACAddress, PCIAddress, DateTime, IPV4Address, IPV6Address,
IPV4Network, IPV6Network, Dict
Implements blueprint json-schema-for-versioned-object
Change-Id: Ie139f01e0bf04c8e4ebdef00a72b30d04a73a6a4
Adds IPV4AndV6Address, NonNegativeFloat, NonNegativeInteger field
types and their respective fields, which can be used later on in
different projects.
Change-Id: I58369998b7fab32c391813c06e9000867aa7887b
This implements the get_schema method of common Field and FieldType classes.
This method will be used by the to_json_schema method in Versioned objects
to partially generate the schema of the object's fields.
Fields implemented in this patch: string, enum, integer, float, boolean, list
This also fixes check for default value for Field.
Implements blueprint json-schema-for-versioned-object
Change-Id: Ibd84cb4e33c375044611c6ffa137ee67d21a93e5
This adds a method that generates a versioned object's fields
in json schema. In addition, each field would also generate
its respective json schema property.
Implements blueprint json-schema-for-versioned-object
Change-Id: I5914606e4db79a15b573cfc4a6b9b8807199e402
Include the full path to the module in the error message
for both the expected and actual object.
Change-Id: I2b5ff3afdbc622a66ba9f78cf8ed61d892694793
Closes-Bug: 1592625
This fixes a bug that I found while making another change, along with
a test that exercises the code that pokes it.
Change-Id: Ibb1ca5e171c6329a46a5d853a3ab8613f58d067f
A recent patch exposed valid_values via property, and cocerced the
result to a tuple to convey the immutable nature of them. This was
a good thought, but unfortunately breaks __repr__ stability, which
we use in the fixture to calculate the object hashes.
We could make the __repr__ dig into the raw types on the field
instead of using the property, but this is probably not the best and
smallest change at this point. If we can get everyone to start using
tuples for their value_values list, then we could land a change to
coerce and enforce that. Right now, we just need to fix the
unexpected regression.
Change-Id: I09b78e7f816fc26c69a3e9435c9d92d5acb5821b
The new class property allows introspection of the valid values,
used to ease testing by random field generation.
Change-Id: I749bc0acea4947450b4c02dca932a05a7a4ad534
When the Object field coerce method doesn't get an object, the
type put into the ValueError message is the empty string, which is
not useful.
This change uses the type name from the value so the error has
useful details.
Change-Id: I45386cfda17243a82864780da1701d3b35432ae0
Closes-Bug: #1552480
The recently-added FakeStateMachineField raises exceptions with strings
that have improper grammar, such as:
FooObject's are not allowed transition out of ERROR state to ACTIVE ...
In addition to the grammar issue, the field's name in the object is not
provided which may make it very difficult to debug.
Finally, the tests for this field did not actually validate the string
of the exception.
This patch corrects the strings, includes the field name, and makes the
test actually validate that the output looks like we expect.
Change-Id: I7bee955fba15b9570416518b16ac64181bf7e320
In function object.__get__(self, instance, owner), owner is always
the owner class, while instance is the instance that the attribute
was accessed through, or None when the attribute is accessed through
the owner. Setting owner default value makes no sense.
refer to:
http://python-reference.readthedocs.org/en/latest/docs/dunderdsc/get.html#get
Change-Id: I74c2105f3100711b62171db65bc0656393adf2b8
PEP-0274 introduced dict comprehensions to replace dict constructor
with a sqeuence of key-pairs[1], these are benefits:
First, it makes the code look neater.
Second, it gains a micro-optimization.
We dropped python 2.6 support, we can leverage this now.
Note: This commit doesn't handle dict constructor with kwargs.
[1]http://legacy.python.org/dev/peps/pep-0274/
Change-Id: Ifca656d516809a6a52cf15bac3f6361e8d83aa58