Add previous_status to SupportStatus

Add previous_status parameter to SupportStatus for
better understanding of objects life cycles.

bp deprecating-improvements

Change-Id: I447d001ada9b0a0297de79704d91e263934a185f
changes/39/186339/6
Peter Razumovsky 7 years ago
parent 25cff7933d
commit 5684f47af0
  1. 27
      heat/engine/support.py
  2. 2
      heat/tests/test_engine_service.py
  3. 50
      heat/tests/test_support.py

@ -20,7 +20,8 @@ SUPPORT_STATUSES = (UNKNOWN, SUPPORTED, PROTOTYPE, DEPRECATED,
class SupportStatus(object):
def __init__(self, status=SUPPORTED, message=None, version=None):
def __init__(self, status=SUPPORTED, message=None, version=None,
previous_status=None):
"""Use SupportStatus for current status of object.
:param status: current status of object.
@ -29,18 +30,30 @@ class SupportStatus(object):
doc generating.
:param message: specific status message for object.
"""
if status in SUPPORT_STATUSES:
self.status = status
self.message = message
self.version = version
else:
self.status = status
self.message = message
self.version = version
self.previous_status = previous_status
self.validate()
def validate(self):
if (self.previous_status is not None and
not isinstance(self.previous_status, SupportStatus)):
raise ValueError(_('previous_status must be SupportStatus '
'instead of %s') % type(self.previous_status))
if self.status not in SUPPORT_STATUSES:
self.status = UNKNOWN
self.message = _("Specified status is invalid, defaulting to"
" %s") % UNKNOWN
self.version = None
self.previous_status = None
def to_dict(self):
return {'status': self.status,
'message': self.message,
'version': self.version}
'version': self.version,
'previous_status': self.previous_status.to_dict()
if self.previous_status is not None else None}

@ -2110,6 +2110,7 @@ class StackServiceTest(common.HeatTestCase):
'status': 'SUPPORTED',
'version': None,
'message': None,
'previous_status': None
},
}
@ -2132,6 +2133,7 @@ class StackServiceTest(common.HeatTestCase):
'status': 'SUPPORTED',
'version': None,
'message': None,
'previous_status': None
},
}
schema = self.eng.resource_schema(self.ctx, type_name=type_name)

@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.engine import support
from heat.tests import common
@ -18,32 +20,72 @@ from heat.tests import common
class SupportStatusTest(common.HeatTestCase):
def test_valid_status(self):
for sstatus in support.SUPPORT_STATUSES:
previous = support.SupportStatus(version='test_version')
status = support.SupportStatus(
status=sstatus,
message='test_message',
version='test_version'
version='test_version',
previous_status=previous,
)
self.assertEqual(sstatus, status.status)
self.assertEqual('test_message', status.message)
self.assertEqual('test_version', status.version)
self.assertEqual(previous, status.previous_status)
self.assertEqual({
'status': sstatus,
'message': 'test_message',
'version': 'test_version'
'version': 'test_version',
'previous_status': {'status': 'SUPPORTED',
'message': None,
'version': 'test_version',
'previous_status': None},
}, status.to_dict())
def test_invalid_status(self):
status = support.SupportStatus(
status='RANDOM',
message='test_message',
version='test_version'
version='test_version',
previous_status=support.SupportStatus()
)
self.assertEqual(support.UNKNOWN, status.status)
self.assertEqual('Specified status is invalid, defaulting to UNKNOWN',
status.message)
self.assertIsNone(status.version)
self.assertIsNone(status.previous_status)
self.assertEqual({
'status': 'UNKNOWN',
'message': 'Specified status is invalid, defaulting to UNKNOWN',
'version': None
'version': None,
'previous_status': None,
}, status.to_dict())
def test_previous_status(self):
sstatus = support.SupportStatus(
status=support.DEPRECATED,
version='2015.2',
previous_status=support.SupportStatus(
status=support.SUPPORTED,
version='2015.1'
)
)
self.assertEqual(support.DEPRECATED, sstatus.status)
self.assertEqual('2015.2', sstatus.version)
self.assertEqual(support.SUPPORTED, sstatus.previous_status.status)
self.assertEqual('2015.1', sstatus.previous_status.version)
self.assertEqual({'status': 'DEPRECATED',
'version': '2015.2',
'message': None,
'previous_status': {'status': 'SUPPORTED',
'version': '2015.1',
'message': None,
'previous_status': None}},
sstatus.to_dict())
def test_invalid_previous_status(self):
ex = self.assertRaises(ValueError,
support.SupportStatus, previous_status='YARRR')
self.assertEqual('previous_status must be SupportStatus '
'instead of %s' % str, six.text_type(ex))

Loading…
Cancel
Save