81 Commits

Author SHA1 Message Date
Stephen Finucane
298c5107eb Bump to hacking 2.x
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>
2020-02-07 10:35:08 -08:00
Stephen Finucane
da7cd17a2b Drop use of six
We no longer need much of the functionality this was providing.

Change-Id: I0f625b714950a712249757906974715358f9e6c6
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2020-02-07 10:35:08 -08:00
Sean McGinnis
37473e3afa
Fix deprecation warnings
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>
2019-04-09 15:18:14 -05:00
Doug Wiegley
bc203115b1
Allow lists to be generated from any non-string iterable
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
2019-02-18 09:50:59 -07:00
Matt Riedemann
6d62263009 Add ListOfUUIDField
This adds a simple ListOfUUIDField which is copied from
kuryr-kubernetes and is also needed in nova.

Change-Id: Ife866af6e07c887774689fd98ac6fde6fa55d6de
2019-02-04 17:00:30 +00:00
Balazs Gibizer
ad962c05be Make the hash of a defaulted set field stable
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
2018-06-01 16:08:31 +02:00
Sean McGinnis
b719764ba8 Don't force unicode strings for UUID coercion
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
2018-04-11 21:05:58 +00:00
Seyeong Kim
b1d0b5d886 Fixing UUID coerce function for unicode non uuid form
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
2018-04-05 18:16:25 -07:00
Balazs Gibizer
0e3526710f Allow escalation of UUID validation warning to error
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
2018-02-02 12:21:52 +01:00
Sean McCully
934fb45a2d iso8601.is8601.Utc No Longer Exists
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
2017-08-29 19:29:20 -04:00
ChangBo Guo(gcb)
02531ea9e4 Update URLs in documents according to document migration
Change-Id: I4aba61ee6e6b27e9b1e49adcc3a55c857211ad1b
2017-07-13 10:00:49 +08:00
Akihiro Motoki
bdcce8b8ad rearrange existing documentation to fit the new standard layout
Minor formatting improvements found during the document check
are also done.

Change-Id: I55d582100c40961a5b0f5ec4b2ea9a55f2d8d8a1
2017-07-01 21:02:49 +09:00
Takashi NATSUME
f69bb43453 Fix string interpolation in ValueError
Fix string interpolation and misuse of
log marker function in ValueError.

Change-Id: Ief34fbf75a28c46b95c08a4d7ae2cb831607a05b
Closes-Bug: #1684771
2017-05-19 15:54:39 +09:00
Jenkins
bc6b75b30b Merge "Change Object schema type to be array instead of string." 2017-02-07 03:45:48 +00:00
Jenkins
e484ffbe1e Merge "fields: fix stringifying of objects when subclasses=True" 2017-02-07 03:45:43 +00:00
Julian Sy
526134585b Change Object schema type to be array instead of string.
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
2016-12-20 21:43:56 +00:00
gecong1973
49f5a9b00a Replace six.iteritems() with .items()
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
2016-12-12 13:30:37 +08:00
Jenkins
1d0de80f73 Merge "Fix get_schema() for Enum" 2016-12-05 13:24:28 +00:00
Jenkins
8799301ce8 Merge "Fix a typo" 2016-12-02 14:40:40 +00:00
gecong1973
ada694753f Fix a typo
TrivialFix

Change-Id: I9274d0b887ebbfed766d31b4fab51929be5715db
2016-11-28 17:20:18 +08:00
Daniel P. Berrange
2e0d4b0539 fields: fix stringifying of objects when subclasses=True
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
2016-11-02 14:16:26 +00:00
Julian Sy
16e520b6d6 Refactor get_schema for patterned FieldTypes
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
2016-10-31 15:19:40 +00:00
tengqm
4391f50709 Fix get_schema() for Enum
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
2016-10-20 04:23:51 -04:00
Julian Sy
5b44fafe6a JSON Schema get_schema implementation for last few fields
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
2016-09-26 19:23:07 +00:00
Javier Pena
45175c2d76 Add get_schema for IPV6Address FieldType class
https://review.openstack.org/343069 added a get_schema() method for
several classes, including IPV6Address. However, when merging,
IPV6Address didn't get it, but IPV4AndV6Address did (compare
https://review.openstack.org/#/c/343069/6/oslo_versionedobjects/fields.py
with
371cb27020).

Adding back the method to IPV6Address, so the gate jobs can pass.

Change-Id: Iea94adfb742b572d0f0a8d2885d9d3a7e0aa85c7
2016-08-24 10:29:31 +02:00
Jenkins
371cb27020 Merge "JSON schema get_schema implementation for more complex fields" 2016-08-23 17:32:59 +00:00
Julian Sy
86f4b03e25 JSON schema get_schema implementation for more complex fields
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
2016-08-10 21:39:34 +00:00
Octavian Ciuhandu
eb4d4a5b65 Adds new fields and field types
Adds IPV4AndV6Address, NonNegativeFloat, NonNegativeInteger field
types and their respective fields, which can be used later on in
different projects.

Change-Id: I58369998b7fab32c391813c06e9000867aa7887b
2016-08-06 22:28:05 +03:00
Jenkins
fb819b8b87 Merge "Improved error message for Object.coerce" 2016-07-05 19:45:51 +00:00
Julian Sy
e80ab966e0 JSON schema get_schema implementation for common fields
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
2016-06-30 21:37:35 +00:00
Julian Sy
92e7ac7108 JSON schema generation for versioned objects
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
2016-06-28 19:53:54 +00:00
John Perkins
238fd1954a Improved error message for Object.coerce
Include the full path to the module in the error message
for both the expected and actual object.

Change-Id: I2b5ff3afdbc622a66ba9f78cf8ed61d892694793
Closes-Bug: 1592625
2016-06-21 09:48:33 -06:00
Jenkins
cccbcf9fbd Merge "Add a pci address field" 2016-06-07 07:48:35 +00:00
Dan Smith
59ac1d009d Fix a typo in Enum error path
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
2016-04-25 08:36:33 -07:00
Dan Smith
f7e5f8e67a Fix issue with coercing valid_values to a tuple
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
2016-04-25 08:33:47 -07:00
Jenkins
60e1bdf588 Merge "Add BaseEnumField valid_values introspection" 2016-04-06 16:08:08 +00:00
Miguel Angel Ajo
0c7ec37d3a Add BaseEnumField valid_values introspection
The new class property allows introspection of the valid values,
used to ease testing by random field generation.

Change-Id: I749bc0acea4947450b4c02dca932a05a7a4ad534
2016-03-17 14:29:59 +00:00
Matt Riedemann
788e3d08f7 Use primitive type name in ValueError for Object field coerce failure
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
2016-03-08 14:48:21 -05:00
Graham Hayes
c459d5e9a9 Update formatting for example statemachine field
Change-Id: I6432a5b8b05e6b9fa57ac1af9a43d29f38b416d5
2016-03-03 12:38:11 +00:00
Moshe Levi
bb43887282 Add a pci address field
Change-Id: I4df82fcd9967eead4c80b4a0f32bf13d870cfcc4
2016-03-02 10:48:22 +02:00
Andrew Laski
15d96379aa Remove the executable bit from files
These files do not need to be executable so let's remove that
permission.

Change-Id: Id1e84e3c4f8e35e483c0eacc73c79b8dc3628c8b
2016-02-29 14:13:37 -05:00
Jenkins
83342c274f Merge "Fix messages in exceptions raised due to invalid state transitions" 2016-02-23 20:10:40 +00:00
Graham Hayes
c6adc63632 Deprecate current UUIDField behaviour
Change-Id: Ic7a62eec8f92de282fcf265d86f76d9c86dbc7fc
2016-02-04 08:15:08 -08:00
Dan Smith
b16584c6af Fix messages in exceptions raised due to invalid state transitions
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
2016-01-29 16:33:07 -08:00
Graham Hayes
18b5c6a66c Added a state machine field
This will allow objects to enforce the correct flow on
this field.

Change-Id: Id574c818f942fadffa3bf0b0a991fe13ea340bdb
2016-01-22 13:32:40 -08:00
Jenkins
686585fd64 Merge "Fix MACAddress coerce method to validate string first" 2016-01-07 16:56:45 +00:00
Moshe Levi
d1bcb9e329 Fix MACAddress coerce method to validate string first
This patch update the coerce method to verify
that value is a string before doing value.lower().

Change-Id: I6ee61c33e8fe2cc6f4a5384151bea6373c04397d
2016-01-04 00:23:46 +02:00
Chaozhe.Chen
56d225372d Remove meaningless default value in __get__()
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
2015-12-23 00:30:37 +08:00
ChangBo Guo(gcb)
b524bf5b71 Leverage dict comprehension in PEP-0274
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
2015-12-02 16:35:16 +08:00
Jenkins
cad06aa85f Merge "Add netaddr-related field types" 2015-11-21 02:17:26 +00:00