Merge "Use oslo.versionedobjects enums instead of status strings"
This commit is contained in:
commit
d163f5f6a0
@ -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 = [
|
||||
|
@ -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),
|
||||
|
@ -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()
|
||||
|
@ -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__)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
Normal file
45
magnum/tests/unit/objects/test_fields.py
Normal file
@ -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')
|
@ -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…
x
Reference in New Issue
Block a user