81 Commits

Author SHA1 Message Date
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
Jenkins
63ff83fb7b Merge "Add a new VersionPredicate type of field" 2015-08-04 03:56:06 +00:00
Dan Smith
b38c8ddb85 Support using the version manifest for obj_make_compatible()
This adds a new method called obj_make_compatible_from_manifest() to
the base object. This is to be used by the newer backport method (which
receives a version manifest from the client) in order to perform a more
prescriptive run of obj_make_compatible(). Since the latter is part of our
public library API, this does a slightly hacky think of stashing the
manifest so that it is visible to lower layers. We cache other such data
on the object like this in other places, so there is precedent for this.
However, it would be good to see if we can clean this up via refactoring
the internals in a way that won't break people (and/or just make a change
in a major version bump later). For now, I think this is the least likely-
to-break-people change we can make.

Change-Id: I0c33a34a3cb454d6d35e2092d72ebd41d4c12729
2015-07-28 12:05:57 -07:00
Sylvain Bauza
1032134b58 Add a new DictOfListOfStrings type of field
In order to coerce correctly some fields that are primarly dictionaries having
either strings or list of strings as values, we need to provide a new field type
which would accept only list of strings as values for dicts so anyone who would
want to use that type would just have to make sure to hydrate all the items by
putting them into a single list.

Change-Id: I708860357e17bcc70733187c3289dd859b09c60b
2015-07-23 17:18:01 +02:00
Sylvain Bauza
2e083bce6e Add a new VersionPredicate type of field
Providing a version string for a field means sometimes that we want to verify
that the string is correct for a versionpredicate.

By adding a new type of field coercing using VersionPredicate, we can make sure
that the field is correct.

Change-Id: I53213e8bfa1928936c0f6904e23dfa886233528b
2015-07-21 16:41:53 +02:00
Alexander Tivelkov
e14209d1af Compound fields now coerce their elements' values
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'
collections 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.

This patch restores the functionality of patch
2da963c3b313e14c4e60301e87f9c9260d7166cb which was reverted due
to found bug. This one fixes this bug by removing custom initializers for
coerced collections.

Change-Id: I9dc8fc408cefea921e4e27c0e75f98291674f867
Partial-Bug: #1469865
2015-07-13 19:07:21 +03:00
Jenkins
505716e895 Merge "Revert "Compound fields now coerce their elements' values"" 2015-06-30 04:32:03 +00:00
Davanum Srinivas (dims)
b71b24e320 Revert "Compound fields now coerce their elements' values"
This reverts commit 2da963c3b313e14c4e60301e87f9c9260d7166cb.

Partial-Bug: #1469865
Change-Id: I8a52e6ccaf5cc1a7d006396806ee092a3e7e11d2
2015-06-30 02:28:59 +00:00
Jenkins
20e5ca83dc Merge "fields: allow subclasses in ObjectField/ListOfObjectsField" 2015-06-24 21:11:16 +00:00
Daniel P. Berrange
28e2b4f004 fields: allow subclasses in ObjectField/ListOfObjectsField
The Object class currently does a direct comparison of the
'obj_name()' value of the thing being coerced, against the
internal _obj_name field it was initialized with.

This does not allow for creation of object fields which
allow arbitrary subclasses - only the base class passes
the check.

Introduce a new 'subclasses' parameter, defaulting to
False, which traverses the python class hierarchy,
checking the obj_name() value on all parent classes
of the value being coerced.

Change-Id: Ie56b94e57a6e18292c10c926836592938540e515
2015-06-23 14:58:29 +01:00
Alexander Tivelkov
2da963c3b3 Compound fields now coerce their elements' values
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
2015-06-21 13:31:27 +03:00
Daniel P. Berrange
4f22c09499 fields: report what the wrong type was when coerce fails
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
2015-06-18 17:01:34 +01:00
Daniel P. Berrange
ab13d2f6ea fields: introduce BaseEnumField to allow subclassing
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
2015-05-19 14:55:32 +01:00
Daniel P. Berrange
df0cfdca52 fields: add a FlexibleBoolean field type
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
2015-05-18 17:32:00 +01:00
Davanum Srinivas
224654429e Add field name to error messages in object type checking
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
2015-05-12 12:00:42 +00:00
Davanum Srinivas
143c11d5a0 Add enum fieldtype field
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
2015-05-08 19:14:17 +00:00
Davanum Srinivas
ae5558fbe7 Copy the default value for field
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
2015-03-28 11:16:59 -04:00
Michal Jastrzebski (inc0)
4f4b7d3112 Fixes for heat implementation
Methods to enable heat tests pass.
Mixin for comparable objects and tzinfo-naive datetime.

Change-Id: Ib60df38259922e6bf51dbfcc275267f6850d3820
2015-02-18 16:26:49 +01:00
Grzegorz Grasza
1b8336fbe8 Compatibility with Python 3
Make the tests run under Python 3.4.
Tests now work with random hash seed.

Change-Id: I5f9f57e0bef2c015ab2ff4b5732ccdade5d3bfbe
Closes-Bug: 1417279
Closes-Bug: 1417285
2015-02-12 09:46:28 -08:00
Grzegorz Grasza
c330f938c8 Remove references to Nova
Remove remaining references to "Nova" where possible, code cleanup.
Also removed IP fields

Co-Authored-By: Michal Jastrzebski (inc0) <michal.jastrzebski@intel.com>
Change-Id: Ibad8f9fc6453321055029ad69b0374261509b9d5
Closes-Bug: 1417287
2015-02-12 08:30:06 -08:00
Grzegorz Grasza
f739f2bdaf Fix initial test failures
Fix py26 compatibility by removing dict comprehension
Remove history.rst from docs generation since it causes an error

Change-Id: Iedc6e6caa6fe2650c83683347c5d9ddcb4d105e8
Closes-Bug: 1420302
Closes-Bug: #1420372
Co-Authored-By: Dan Smith <dansmith@redhat.com>
2015-02-10 12:32:13 -08:00
Doug Hellmann
1e146a916e clean up and get most test running
Remove extraneous utility code and tests.

Skip tests related to remote object verification until we can rewrite
them (see the adopt-oslo-versionedobjects spec for details).

Fix pep8 errors.

Update requirements.

Set python's hash seed in tox.ini for tests that compare things that
might come out in a different order.
2015-02-02 16:24:14 -05:00
Doug Hellmann
591c480caf rename files 2015-02-02 15:07:55 -05:00