Add downgrade case to pending release checking
We have to make possible to downgrade openstack release from later version to earlier version. Implements blueprint openstack-patching-nailgun-part Change-Id: I473887ae49f9fa85e2cafcc53cb23cc230e321cc
This commit is contained in:
parent
5f2944a8d5
commit
99d901c06a
@ -21,6 +21,22 @@ from nailgun.objects import Release
|
||||
|
||||
|
||||
class ClusterValidator(BasicValidator):
|
||||
|
||||
@classmethod
|
||||
def _can_update_release(cls, curr_release, pend_release):
|
||||
return any([
|
||||
# redeploy
|
||||
curr_release.id == pend_release.id,
|
||||
|
||||
# update to upper release
|
||||
curr_release.operating_system == pend_release.operating_system
|
||||
and curr_release.version in pend_release.can_update_from_versions,
|
||||
|
||||
# update to lower release
|
||||
curr_release.operating_system == pend_release.operating_system
|
||||
and pend_release.version in curr_release.can_update_from_versions,
|
||||
])
|
||||
|
||||
@classmethod
|
||||
def _validate_common(cls, data, instance=None):
|
||||
d = cls.validate_json(data)
|
||||
@ -44,14 +60,7 @@ class ClusterValidator(BasicValidator):
|
||||
release_id = instance.release_id
|
||||
curr_release = Release.get_by_uid(release_id)
|
||||
|
||||
def curr_release_can_be_updated_with_pend_release():
|
||||
return release_id == pend_release_id or (
|
||||
curr_release.operating_system ==
|
||||
pend_release.operating_system
|
||||
and curr_release.version in
|
||||
pend_release.can_update_from_versions)
|
||||
|
||||
if not curr_release_can_be_updated_with_pend_release():
|
||||
if not cls._can_update_release(curr_release, pend_release):
|
||||
raise errors.InvalidData(
|
||||
"Cannot set pending release as "
|
||||
"it cannot update current release",
|
||||
|
@ -71,3 +71,84 @@ class TestClusterValidator(BaseTestCase):
|
||||
ClusterValidator.validate(self.cluster_data)
|
||||
except errors.InvalidData as e:
|
||||
self.fail('Release exists validation failed: {0}'.format(e))
|
||||
|
||||
def test_pending_release_validation_success(self):
|
||||
curr_release = Mock(
|
||||
id=1,
|
||||
operating_system='Ubuntu',
|
||||
version='2014.1',
|
||||
can_update_from_versions=[],
|
||||
)
|
||||
pend_release = Mock(
|
||||
id=2,
|
||||
operating_system='Ubuntu',
|
||||
version='2014.2',
|
||||
can_update_from_versions=['2014.1'],
|
||||
)
|
||||
|
||||
self.assertTrue(
|
||||
ClusterValidator._can_update_release(
|
||||
curr_release, curr_release
|
||||
)
|
||||
)
|
||||
|
||||
self.assertTrue(
|
||||
ClusterValidator._can_update_release(
|
||||
curr_release, pend_release
|
||||
)
|
||||
)
|
||||
|
||||
self.assertTrue(
|
||||
ClusterValidator._can_update_release(
|
||||
pend_release, curr_release
|
||||
)
|
||||
)
|
||||
|
||||
def test_pending_release_validation_unsuccess(self):
|
||||
curr_release = Mock(
|
||||
id=1,
|
||||
operating_system='Ubuntu',
|
||||
version='2014.1',
|
||||
can_update_from_versions=[],
|
||||
)
|
||||
pend_release = Mock(
|
||||
id=2,
|
||||
operating_system='Ubuntu',
|
||||
version='2014.2',
|
||||
can_update_from_versions=[],
|
||||
)
|
||||
self.assertFalse(
|
||||
ClusterValidator._can_update_release(
|
||||
curr_release, pend_release
|
||||
)
|
||||
)
|
||||
|
||||
pend_release = Mock(
|
||||
id=2,
|
||||
operating_system='CentOS',
|
||||
version='2014.2',
|
||||
can_update_from_versions=['2014.1'],
|
||||
)
|
||||
self.assertFalse(
|
||||
ClusterValidator._can_update_release(
|
||||
curr_release, pend_release
|
||||
)
|
||||
)
|
||||
|
||||
curr_release = Mock(
|
||||
id=1,
|
||||
operating_system='Ubuntu',
|
||||
version='2014.1',
|
||||
can_update_from_versions=[],
|
||||
)
|
||||
pend_release = Mock(
|
||||
id=2,
|
||||
operating_system='Ubuntu',
|
||||
version='2014.2',
|
||||
can_update_from_versions=['2014.0'],
|
||||
)
|
||||
self.assertFalse(
|
||||
ClusterValidator._can_update_release(
|
||||
pend_release, curr_release
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user