Check health policy v1.0 before upgrade
Stein introduces health policy version 1.1 which is incompatible with health policy version 1.0. Users are required to delete version 1.0 health policies before upgrade and recreate them in version 1.1 format after upgrading. Change-Id: If319caed128b928a9d60fb0e8cee75bb601a09e3
This commit is contained in:
parent
929b9697ad
commit
30cf0e33a9
|
@ -18,6 +18,9 @@ from oslo_config import cfg
|
|||
from oslo_upgradecheck import upgradecheck
|
||||
|
||||
from senlin.common.i18n import _
|
||||
from senlin.db import api
|
||||
|
||||
from sqlalchemy import MetaData, Table, select, column
|
||||
|
||||
|
||||
class Checks(upgradecheck.UpgradeCommands):
|
||||
|
@ -28,10 +31,35 @@ class Checks(upgradecheck.UpgradeCommands):
|
|||
and added to _upgrade_checks tuple.
|
||||
"""
|
||||
|
||||
def _check_placeholder(self):
|
||||
# This is just a placeholder for upgrade checks, it should be
|
||||
# removed when the actual checks are added
|
||||
return upgradecheck.Result(upgradecheck.Code.SUCCESS)
|
||||
def _check_healthpolicy(self):
|
||||
"""Check if version 1.0 health policies exists
|
||||
|
||||
Stein introduces health policy version 1.1 which is incompatible with
|
||||
health policy version 1.0. Users are required to delete version 1.0
|
||||
health policies before upgrade and recreate them in version 1.1 format
|
||||
after upgrading.
|
||||
"""
|
||||
|
||||
engine = api.get_engine()
|
||||
metadata = MetaData(bind=engine)
|
||||
policy = Table('policy', metadata, autoload=True)
|
||||
|
||||
healthpolicy_select = (
|
||||
select([column('name')])
|
||||
.select_from(policy)
|
||||
.where(column('type') == 'senlin.policy.health-1.0')
|
||||
)
|
||||
healthpolicy_rows = engine.execute(healthpolicy_select).fetchall()
|
||||
|
||||
if not healthpolicy_rows:
|
||||
return upgradecheck.Result(upgradecheck.Code.SUCCESS)
|
||||
|
||||
healthpolicy_names = [row[0] for row in healthpolicy_rows]
|
||||
error_msg = _('The following version 1.0 health policies must be '
|
||||
'deleted before upgrade: \'{}\'. After upgrading, the '
|
||||
'health policies can be recreated in version 1.1 '
|
||||
'format.').format(', '.join(healthpolicy_names))
|
||||
return upgradecheck.Result(upgradecheck.Code.FAILURE, error_msg)
|
||||
|
||||
# The format of the check functions is to return an
|
||||
# oslo_upgradecheck.upgradecheck.Result
|
||||
|
@ -42,7 +70,7 @@ class Checks(upgradecheck.UpgradeCommands):
|
|||
# summary will be rolled up at the end of the check() method.
|
||||
_upgrade_checks = (
|
||||
# In the future there should be some real checks added here
|
||||
(_('Placeholder'), _check_placeholder),
|
||||
(_('HealthPolicy'), _check_healthpolicy),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -15,16 +15,61 @@
|
|||
from oslo_upgradecheck.upgradecheck import Code
|
||||
|
||||
from senlin.cmd import status
|
||||
from senlin.db.sqlalchemy import api as db_api
|
||||
from senlin.tests.unit.common import base
|
||||
from senlin.tests.unit.common import utils
|
||||
|
||||
|
||||
class TestUpgradeChecks(base.SenlinTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestUpgradeChecks, self).setUp()
|
||||
self.ctx = utils.dummy_context()
|
||||
self.cmd = status.Checks()
|
||||
|
||||
def test__check_placeholder(self):
|
||||
check_result = self.cmd._check_placeholder()
|
||||
self.assertEqual(
|
||||
Code.SUCCESS, check_result.code)
|
||||
self.healthpolv1_0_data = {
|
||||
'name': 'test_healthpolicy',
|
||||
'type': 'senlin.policy.health-1.0',
|
||||
'user': self.ctx.user_id,
|
||||
'project': self.ctx.project_id,
|
||||
'domain': self.ctx.domain_id,
|
||||
'data': None,
|
||||
}
|
||||
|
||||
self.healthpolv1_1_data = {
|
||||
'name': 'test_healthpolicy',
|
||||
'type': 'senlin.policy.health-1.1',
|
||||
'user': self.ctx.user_id,
|
||||
'project': self.ctx.project_id,
|
||||
'domain': self.ctx.domain_id,
|
||||
'data': None,
|
||||
}
|
||||
|
||||
self.scalepol_data = {
|
||||
'name': 'test_scalepolicy',
|
||||
'type': 'senlin.policy.scaling-1.0',
|
||||
'user': self.ctx.user_id,
|
||||
'project': self.ctx.project_id,
|
||||
'domain': self.ctx.domain_id,
|
||||
'data': None,
|
||||
}
|
||||
|
||||
def test__check_healthpolicy_success(self):
|
||||
healthpolv1_1 = db_api.policy_create(self.ctx, self.healthpolv1_1_data)
|
||||
self.addCleanup(db_api.policy_delete, self.ctx, healthpolv1_1.id)
|
||||
|
||||
scalepol = db_api.policy_create(self.ctx, self.scalepol_data)
|
||||
self.addCleanup(db_api.policy_delete, self.ctx, scalepol.id)
|
||||
|
||||
check_result = self.cmd._check_healthpolicy()
|
||||
self.assertEqual(Code.SUCCESS, check_result.code)
|
||||
|
||||
def test__check_healthpolicy_failed(self):
|
||||
healthpolv1_0 = db_api.policy_create(self.ctx, self.healthpolv1_0_data)
|
||||
self.addCleanup(db_api.policy_delete, self.ctx, healthpolv1_0.id)
|
||||
|
||||
scalepol = db_api.policy_create(self.ctx, self.scalepol_data)
|
||||
self.addCleanup(db_api.policy_delete, self.ctx, scalepol.id)
|
||||
|
||||
check_result = self.cmd._check_healthpolicy()
|
||||
self.assertEqual(Code.FAILURE, check_result.code)
|
||||
|
|
Loading…
Reference in New Issue