From fdd4d1c7cd8910f0fe540cdc11d8aad19bc93742 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Tue, 22 Nov 2016 15:47:53 -0500 Subject: [PATCH] Remove redundant VersionedObject Fields This removes the NonNegativeInteger NonNegativeFloat and IPV4AndV6Address Fields, since they already are defined in ovo. implements bp json-schema-for-versioned-object Depends-On: I083c854d0e1d18806169a1454e8127eda9e8ffb8 Change-Id: I61b7b6fa53013aff200e55b7031d5ba23669e1f4 --- nova/objects/fields.py | 44 ++------------------------ nova/tests/unit/objects/test_fields.py | 4 +-- requirements.txt | 2 +- 3 files changed, 6 insertions(+), 44 deletions(-) diff --git a/nova/objects/fields.py b/nova/objects/fields.py index f9f99f70896f..fa0c612c5f09 100644 --- a/nova/objects/fields.py +++ b/nova/objects/fields.py @@ -39,8 +39,10 @@ ElementTypeError = fields.ElementTypeError BooleanField = fields.BooleanField UnspecifiedDefault = fields.UnspecifiedDefault IntegerField = fields.IntegerField +NonNegativeIntegerField = fields.NonNegativeIntegerField UUIDField = fields.UUIDField FloatField = fields.FloatField +NonNegativeFloatField = fields.NonNegativeFloatField StringField = fields.StringField SensitiveStringField = fields.SensitiveStringField EnumField = fields.EnumField @@ -61,6 +63,7 @@ DictOfListOfStringsField = fields.DictOfListOfStringsField IPAddressField = fields.IPAddressField IPV4AddressField = fields.IPV4AddressField IPV6AddressField = fields.IPV6AddressField +IPV4AndV6AddressField = fields.IPV4AndV6AddressField IPNetworkField = fields.IPNetworkField IPV4NetworkField = fields.IPV4NetworkField IPV6NetworkField = fields.IPV6NetworkField @@ -673,17 +676,6 @@ class InstancePowerState(Enum): return cls.ALL[index] -class IPV4AndV6Address(IPAddress): - @staticmethod - def coerce(obj, attr, value): - result = IPAddress.coerce(obj, attr, value) - if result.version != 4 and result.version != 6: - raise ValueError(_('Network "%(val)s" is not valid ' - 'in field %(attr)s') % - {'val': value, 'attr': attr}) - return result - - class NetworkModel(FieldType): @staticmethod def coerce(obj, attr, value): @@ -709,24 +701,6 @@ class NetworkModel(FieldType): ','.join([str(vif['id']) for vif in value])) -class NonNegativeFloat(FieldType): - @staticmethod - def coerce(obj, attr, value): - v = float(value) - if v < 0: - raise ValueError(_('Value must be >= 0 for field %s') % attr) - return v - - -class NonNegativeInteger(FieldType): - @staticmethod - def coerce(obj, attr, value): - v = int(value) - if v < 0: - raise ValueError(_('Value must be >= 0 for field %s') % attr) - return v - - class AddressBase(FieldType): @staticmethod def coerce(obj, attr, value): @@ -924,17 +898,5 @@ class InstancePowerStateField(BaseEnumField): AUTO_TYPE = InstancePowerState() -class IPV4AndV6AddressField(AutoTypedField): - AUTO_TYPE = IPV4AndV6Address() - - class ListOfIntegersField(AutoTypedField): AUTO_TYPE = List(fields.Integer()) - - -class NonNegativeFloatField(AutoTypedField): - AUTO_TYPE = NonNegativeFloat() - - -class NonNegativeIntegerField(AutoTypedField): - AUTO_TYPE = NonNegativeInteger() diff --git a/nova/tests/unit/objects/test_fields.py b/nova/tests/unit/objects/test_fields.py index a67b71bd9bf9..48fb0222ed5b 100644 --- a/nova/tests/unit/objects/test_fields.py +++ b/nova/tests/unit/objects/test_fields.py @@ -230,7 +230,7 @@ class TestInteger(TestField): class TestNonNegativeInteger(TestInteger): def setUp(self): super(TestNonNegativeInteger, self).setUp() - self.field = fields.Field(fields.NonNegativeInteger()) + self.field = fields.NonNegativeIntegerField() self.coerce_bad_values.extend(['-2', '4.2']) @@ -247,7 +247,7 @@ class TestFloat(TestField): class TestNonNegativeFloat(TestFloat): def setUp(self): super(TestNonNegativeFloat, self).setUp() - self.field = fields.Field(fields.NonNegativeFloat()) + self.field = fields.NonNegativeFloatField() self.coerce_bad_values.extend(['-4.2']) diff --git a/requirements.txt b/requirements.txt index 87c228ae8183..1c1ace1180c6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -51,7 +51,7 @@ oslo.service>=1.10.0 # Apache-2.0 rfc3986>=0.2.2 # Apache-2.0 oslo.middleware>=3.0.0 # Apache-2.0 psutil<2.0.0,>=1.1.1 # BSD -oslo.versionedobjects>=1.13.0 # Apache-2.0 +oslo.versionedobjects>=1.17.0 # Apache-2.0 os-brick>=1.8.0 # Apache-2.0 os-vif>=1.3.0 # Apache-2.0 os-win>=1.1.0 # Apache-2.0