diff --git a/nova/objects/fields.py b/nova/objects/fields.py index 08d9c5e4f24f..3c3cc64d87ad 100644 --- a/nova/objects/fields.py +++ b/nova/objects/fields.py @@ -943,6 +943,9 @@ class AddressBase(FieldType): else: raise ValueError(_('Value must match %s') % obj.PATTERN) + def get_schema(self): + return {'type': ['string'], 'pattern': self.PATTERN} + class PCIAddress(AddressBase): PATTERN = '[a-f0-9]{4}:[a-f0-9]{2}:[a-f0-9]{2}.[a-f0-9]' diff --git a/nova/tests/unit/objects/test_fields.py b/nova/tests/unit/objects/test_fields.py index 7b8e52900ae8..fc31102ef7ec 100644 --- a/nova/tests/unit/objects/test_fields.py +++ b/nova/tests/unit/objects/test_fields.py @@ -64,6 +64,14 @@ class FakeEnumAlt(fields.Enum): **kwargs) +class FakeAddress(fields.AddressBase): + PATTERN = '[a-z]+[0-9]+' + + +class FakeAddressField(fields.AutoTypedField): + AUTO_TYPE = FakeAddress() + + class FakeEnumField(fields.BaseEnumField): AUTO_TYPE = FakeEnum() @@ -735,3 +743,11 @@ class TestSecureBoot(TestField): def test_stringify_invalid(self): self.assertRaises(ValueError, self.field.stringify, 'enabled') + + +class TestSchemaGeneration(test.NoDBTestCase): + def test_address_base_get_schema(self): + field = FakeAddressField() + expected = {'type': ['string'], 'pattern': '[a-z]+[0-9]+', + 'readonly': False} + self.assertEqual(expected, field.get_schema())