Browse Source

Use oslo.versionedobjects enums instead of status strings

Statuses are currently defined as a StringField when they should
be defined as an Enum object.  This fix changes these objects from
using StringField by extending the Enum object in
oslo.versionedobjects

Change-Id: I12760e1d72f4af9931ee97bbad298f92f785118f
Partial-Bug: #1489136
changes/99/217399/3
Cale Rath 7 years ago
parent
commit
e4add16a69
  1. 2
      magnum/conductor/handlers/bay_conductor.py
  2. 18
      magnum/objects/bay.py
  3. 23
      magnum/objects/fields.py
  4. 2
      magnum/service/periodic.py
  5. 2
      magnum/tests/unit/conductor/handlers/test_bay_conductor.py
  6. 2
      magnum/tests/unit/db/test_bay.py
  7. 45
      magnum/tests/unit/objects/test_fields.py
  8. 2
      magnum/tests/unit/service/test_periodic.py

2
magnum/conductor/handlers/bay_conductor.py

@ -28,7 +28,7 @@ from magnum.i18n import _
from magnum.i18n import _LE
from magnum.i18n import _LI
from magnum import objects
from magnum.objects.bay import Status as bay_status
from magnum.objects.fields import BayStatus as bay_status
bay_heat_opts = [

18
magnum/objects/bay.py

@ -19,18 +19,7 @@ from magnum.common import exception
from magnum.common import utils
from magnum.db import api as dbapi
from magnum.objects import base
class Status(object):
CREATE_IN_PROGRESS = 'CREATE_IN_PROGRESS'
CREATE_FAILED = 'CREATE_FAILED'
CREATE_COMPLETE = 'CREATE_COMPLETE'
UPDATE_IN_PROGRESS = 'UPDATE_IN_PROGRESS'
UPDATE_FAILED = 'UPDATE_FAILED'
UPDATE_COMPLETE = 'UPDATE_COMPLETE'
DELETE_IN_PROGRESS = 'DELETE_IN_PROGRESS'
DELETE_FAILED = 'DELETE_FAILED'
DELETE_COMPLETE = 'DELETE_COMPLETE'
from magnum.objects import fields as m_fields
@base.MagnumObjectRegistry.register
@ -49,10 +38,7 @@ class Bay(base.MagnumPersistentObject, base.MagnumObject,
'user_id': fields.StringField(nullable=True),
'baymodel_id': fields.StringField(nullable=True),
'stack_id': fields.StringField(nullable=True),
# One of CREATE_IN_PROGRESS|CREATE_FAILED|CREATED
# UPDATE_IN_PROGRESS|UPDATE_FAILED|UPDATED
# DELETE_IN_PROGRESS|DELETE_FAILED|DELETED
'status': fields.StringField(nullable=True),
'status': m_fields.BayStatusField(nullable=True),
'status_reason': fields.StringField(nullable=True),
'api_address': fields.StringField(nullable=True),
'node_addresses': fields.ListOfStringsField(nullable=True),

23
magnum/objects/fields.py

@ -15,5 +15,28 @@
from oslo_versionedobjects import fields
class BayStatus(fields.Enum):
CREATE_IN_PROGRESS = 'CREATE_IN_PROGRESS'
CREATE_FAILED = 'CREATE_FAILED'
CREATE_COMPLETE = 'CREATE_COMPLETE'
UPDATE_IN_PROGRESS = 'UPDATE_IN_PROGRESS'
UPDATE_FAILED = 'UPDATE_FAILED'
UPDATE_COMPLETE = 'UPDATE_COMPLETE'
DELETE_IN_PROGRESS = 'DELETE_IN_PROGRESS'
DELETE_FAILED = 'DELETE_FAILED'
DELETE_COMPLETE = 'DELETE_COMPLETE'
ALL = (CREATE_IN_PROGRESS, CREATE_FAILED, CREATE_COMPLETE,
UPDATE_IN_PROGRESS, UPDATE_FAILED, UPDATE_COMPLETE,
DELETE_IN_PROGRESS, DELETE_FAILED, DELETE_COMPLETE)
def __init__(self):
super(BayStatus, self).__init__(valid_values=BayStatus.ALL)
class ListOfDictsField(fields.AutoTypedField):
AUTO_TYPE = fields.List(fields.Dict(fields.FieldType()))
class BayStatusField(fields.BaseEnumField):
AUTO_TYPE = BayStatus()

2
magnum/service/periodic.py

@ -26,7 +26,7 @@ from magnum.common import exception
from magnum.i18n import _LI
from magnum.i18n import _LW
from magnum import objects
from magnum.objects.bay import Status as bay_status
from magnum.objects.fields import BayStatus as bay_status
LOG = log.getLogger(__name__)

2
magnum/tests/unit/conductor/handlers/test_bay_conductor.py

@ -18,7 +18,7 @@ from oslo_service import loopingcall
from magnum.common import exception
from magnum.conductor.handlers import bay_conductor
from magnum import objects
from magnum.objects.bay import Status as bay_status
from magnum.objects.fields import BayStatus as bay_status
from magnum.tests import base
from magnum.tests.unit.db import base as db_base
from magnum.tests.unit.db import utils

2
magnum/tests/unit/db/test_bay.py

@ -20,7 +20,7 @@ import six
from magnum.common import context
from magnum.common import exception
from magnum.common import utils as magnum_utils
from magnum.objects.bay import Status as bay_status
from magnum.objects.fields import BayStatus as bay_status
from magnum.tests.unit.db import base
from magnum.tests.unit.db import utils

45
magnum/tests/unit/objects/test_fields.py

@ -0,0 +1,45 @@
# Copyright 2015 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_versionedobjects.tests import test_fields
from magnum.objects import fields
class TestBayStatus(test_fields.TestField):
def setUp(self):
super(TestBayStatus, self).setUp()
self.field = fields.BayStatusField()
self.coerce_good_values = [('CREATE_IN_PROGRESS',
'CREATE_IN_PROGRESS'),
('CREATE_FAILED', 'CREATE_FAILED'),
('CREATE_COMPLETE', 'CREATE_COMPLETE'),
('UPDATE_IN_PROGRESS',
'UPDATE_IN_PROGRESS'),
('UPDATE_FAILED', 'UPDATE_FAILED'),
('UPDATE_COMPLETE', 'UPDATE_COMPLETE'),
('DELETE_IN_PROGRESS',
'DELETE_IN_PROGRESS'),
('DELETE_FAILED', 'DELETE_FAILED'),
('DELETE_COMPLETE', 'DELETE_COMPLETE'), ]
self.coerce_bad_values = ['DELETE_STOPPED']
self.to_primitive_values = self.coerce_good_values[0:1]
self.from_primitive_values = self.coerce_good_values[0:1]
def test_stringify(self):
self.assertEqual("'UPDATE_FAILED'",
self.field.stringify('UPDATE_FAILED'))
def test_stringify_invalid(self):
self.assertRaises(ValueError, self.field.stringify, 'DELETE_STOPPED')

2
magnum/tests/unit/service/test_periodic.py

@ -20,7 +20,7 @@ from magnum.common import context
from magnum.common.rpc_service import CONF
from magnum.db.sqlalchemy import api as dbapi
from magnum import objects
from magnum.objects.bay import Status as bay_status
from magnum.objects.fields import BayStatus as bay_status
from magnum.service import periodic
from magnum.tests import base
from magnum.tests.unit.db import utils

Loading…
Cancel
Save