72 Commits

Author SHA1 Message Date
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
Dan Smith
227a0bcee9 Add netaddr-related field types
This brings over the network-related fields from Nova.

Change-Id: I6db660bdda043477da4ee61947c9114696734c3d
2015-11-20 10:51:43 -08:00
Jay Pipes
24d330f53d Adds new MACAddressField
This patch adds another field type definition to o.vo for a MAC Address.

Change-Id: Iee44223e5eff5565cc5e02571e5a96bb29490925
Co-authored-by: Dan Berrange <berrange@redhat.com>
2015-11-17 18:15:20 -08:00
Matt Riedemann
bd977f400a Add SensitiveString field type
There are objects that define a String field to hold a serialized json
blob and that blob can have sensitive information in it (tokens,
passwords, etc). When the object is logged, repr will log that sensitive
information. This puts a burden on the code that's doing the logging to
remember to sanitize the object's string form before logging it.

It'd be simpler and cleaner to just have a field type that extends
String so it's the same in all respects except for when it's
stringified. So in SensitiveString's stringify method it just masks the
password on the field value before returning it.

And no SensitiveString does not play an acoustic guitar at your local
coffee shop, he's actually super tough and emotionally walled up, that's
why he doesn't like exposing too much information about himself in the
logs.

Closes-Bug: #1321785

Change-Id: I56466eb8b5d8000ef010f2015f453a9e74dc66b8
2015-10-09 09:05:33 -07:00
Sergey Vilgelm
815ccc483c Fix missing value types for log message
This patch add missing value types for some log message of exception.

Change-Id: I4eadc72c1da46e281fc9d22daf7de826d815f0d8
Closes-Bug: #1494574
2015-09-14 11:09:04 +03:00
Davanum Srinivas (dims)
19d21f65e2 Switch back to iso format on the wire
following change id replaced timeutils.isotime(dt) with dt.isoformat():
Ied2643d3d891600e0e5cd31c7ef1ff6107e3a777

However this change breaks existing contract between Nova components
on the wire, so we need to resurrect a bit of the older code.

Change-Id: I151e889258a33fe6ce961b514c3967f521a218cf
2015-08-18 12:38:51 +00:00
Balazs Gibizer
5f87da999d Switch from deprecated timeutils.isotime
oslo_utils.timeutils.isotime() is deprecated as of 1.6 so we need
to stop using it.

This patch replaces timeutils.isotime(dt) with dt.isoformat() as
the deprecation message suggests in oslo_utils.timeutils.
However this might be a backward incompatible change as
timeutils.isotime() produced '1955-11-05T18:00:00Z' format
but datetime.isoformat() produces '1955-11-05T18:00:00+00:00'
format.

Change-Id: Ied2643d3d891600e0e5cd31c7ef1ff6107e3a777
2015-08-10 09:23:08 +00:00
Jenkins
451ea897e1 Merge "Make direct call to object's obj_from_primitive" 2015-08-07 15:08:14 +00:00
Jenkins
e4fa9ec3e4 Merge "Support using the version manifest for obj_make_compatible()" 2015-08-05 22:30:52 +00:00
Thang Pham
3573e0391a Make direct call to object's obj_from_primitive
The following patch fixes field.Object's from_primitive()
to call a given object's obj_from_primitive() instead of
VersionedObject's obj_from_primitive().  By using the given
object instead of VersionedObject, the appropriate
OBJ_PROJECT_NAMESPACE is passed down to obj_from_primitive(),
and allows support for other projects namespaces.

Change-Id: I02e733f29ce2ee221270577f6dafdda706c74eb2
Closes-Bug: #1479041
Signed-off-by: Thang Pham <thang.g.pham@gmail.com>
2015-08-05 07:09:34 -07:00