Refactor SupportStatus into its own module

This will allow a properties to also use SupportStatus

Change-Id: I66783eaefcb7c773120c0f1e5cb7eeacbd483cf7
This commit is contained in:
Steve Baker 2014-02-20 09:54:28 +13:00
parent 3f7ba12266
commit 7c6bf662c6
5 changed files with 93 additions and 50 deletions

View File

@ -25,6 +25,7 @@ from heat.common import identifier
from heat.common import short_id
from heat.engine import scheduler
from heat.engine import resources
from heat.engine import support
from heat.engine import timestamp
# import class to avoid name collisions and ugly aliasing
from heat.engine.attributes import Attributes
@ -91,29 +92,6 @@ class Metadata(object):
rs.update_and_save({'rsrc_metadata': metadata})
class SupportStatus(object):
SUPPORT_STATUSES = (UNKNOWN, SUPPORTED, PROTOTYPE, DEPRECATED,
UNSUPPORTED) = ('UNKNOWN', 'SUPPORTED', 'PROTOTYPE',
'DEPRECATED', 'UNSUPPORTED')
def __init__(self, status=SUPPORTED, message=None, version=None):
if status in self.SUPPORT_STATUSES:
self.status = status
self.message = message
self.version = version
else:
self.status = self.UNKNOWN
self.message = _("Specified status is invalid, defaulting to"
" %s") % self.UNKNOWN
self.version = None
def to_dict(self):
return {'status': self.status,
'message': self.message,
'version': self.version}
class Resource(object):
ACTIONS = (INIT, CREATE, DELETE, UPDATE, ROLLBACK, SUSPEND, RESUME, ADOPT
) = ('INIT', 'CREATE', 'DELETE', 'UPDATE', 'ROLLBACK',
@ -150,7 +128,7 @@ class Resource(object):
# If set to None no limit will be applied.
physical_resource_name_limit = 255
support_status = SupportStatus()
support_status = support.SupportStatus()
def __new__(cls, name, json, stack):
'''Create a new Resource of the appropriate class for its type.'''

View File

@ -15,7 +15,7 @@
from heat.common import exception
from heat.engine import clients
from heat.engine.resource import SupportStatus
from heat.engine import support
from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import subnet
from heat.engine import properties
@ -208,8 +208,8 @@ class RouterInterface(neutron.NeutronResource):
class RouterGateway(neutron.NeutronResource):
support_status = SupportStatus(
SupportStatus.DEPRECATED,
support_status = support.SupportStatus(
support.DEPRECATED,
_('RouterGateway resource is deprecated and should not be used. '
'Instead use the `external_gateway_info` property in the router '
'resource to set up the gateway.')

38
heat/engine/support.py Normal file
View File

@ -0,0 +1,38 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# 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.
SUPPORT_STATUSES = (UNKNOWN, SUPPORTED, PROTOTYPE, DEPRECATED,
UNSUPPORTED) = ('UNKNOWN', 'SUPPORTED', 'PROTOTYPE',
'DEPRECATED', 'UNSUPPORTED')
class SupportStatus(object):
def __init__(self, status=SUPPORTED, message=None, version=None):
if status in SUPPORT_STATUSES:
self.status = status
self.message = message
self.version = version
else:
self.status = UNKNOWN
self.message = _("Specified status is invalid, defaulting to"
" %s") % UNKNOWN
self.version = None
def to_dict(self):
return {'status': self.status,
'message': self.message,
'version': self.version}

View File

@ -1298,26 +1298,3 @@ class ReducePhysicalResourceNameTest(HeatTestCase):
else:
# check that nothing has changed
self.assertEqual(self.original, reduced)
class SupportStatusTest(HeatTestCase):
def test_valid_status(self):
status = resource.SupportStatus(
status='DEPRECATED',
message='test_message',
version='test_version'
)
self.assertEqual('DEPRECATED', status.status)
self.assertEqual('test_message', status.message)
self.assertEqual('test_version', status.version)
def test_invalid_status(self):
status = resource.SupportStatus(
status='RANDOM',
message='test_message',
version='test_version'
)
self.assertEqual('UNKNOWN', status.status)
self.assertEqual('Specified status is invalid, defaulting to UNKNOWN',
status.message)
self.assertIsNone(status.version)

View File

@ -0,0 +1,50 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# 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 heat.engine import support
from heat.tests.common import HeatTestCase
class SupportStatusTest(HeatTestCase):
def test_valid_status(self):
status = support.SupportStatus(
status=support.DEPRECATED,
message='test_message',
version='test_version'
)
self.assertEqual('DEPRECATED', status.status)
self.assertEqual('test_message', status.message)
self.assertEqual('test_version', status.version)
self.assertEqual({
'status': 'DEPRECATED',
'message': 'test_message',
'version': 'test_version'
}, status.to_dict())
def test_invalid_status(self):
status = support.SupportStatus(
status='RANDOM',
message='test_message',
version='test_version'
)
self.assertEqual(support.UNKNOWN, status.status)
self.assertEqual('Specified status is invalid, defaulting to UNKNOWN',
status.message)
self.assertIsNone(status.version)
self.assertEqual({
'status': 'UNKNOWN',
'message': 'Specified status is invalid, defaulting to UNKNOWN',
'version': None
}, status.to_dict())