Added rollback option to sw-deploy-strategy

This allows users to specify if the sw-deploy they want is going to be a
rollback.  Currently, this will fail the strategy because rollback is
not implemented.

TEST PLAN
PASS: --rollback option triggers strategy to fail
PASS: Without --rollback, strategy is not impacted

Story: 2011045
Tasks: 50066
Depends-On: https://review.opendev.org/c/starlingx/nfv/+/916648
Change-Id: Iba29db17c33699e3ae55ca1258f567ea2428a323
Signed-off-by: Joshua Kraitberg <joshua.kraitberg@windriver.com>
This commit is contained in:
Joshua Kraitberg 2024-05-09 10:14:37 -04:00
parent 93fd832c4b
commit aeeba1d11d
11 changed files with 85 additions and 16 deletions

View File

@ -304,6 +304,7 @@ def create_strategy(token_id,
api_cmd_payload['controller-apply-type'] = controller_apply_type
api_cmd_payload['default-instance-action'] = default_instance_action
api_cmd_payload['release'] = kwargs['release']
api_cmd_payload['rollback'] = kwargs['rollback']
api_cmd_payload['storage-apply-type'] = storage_apply_type
api_cmd_payload['worker-apply-type'] = worker_apply_type
if max_parallel_worker_hosts is not None:

View File

@ -51,7 +51,10 @@ def get_extra_create_args(cmd_area, args):
# no additional kwargs for patch
return {}
elif sw_update.CMD_NAME_SW_DEPLOY == cmd_area:
return {'release': args.release}
return {
'release': args.release,
'rollback': args.rollback
}
elif sw_update.CMD_NAME_FW_UPDATE == cmd_area:
# no additional kwargs for firmware update
return {}
@ -469,6 +472,11 @@ def setup_sw_deploy_parser(commands):
create_strategy_cmd.add_argument('release',
help='software release for deployment')
# sw-deploy optionally supports rollback flag
create_strategy_cmd.add_argument('--rollback',
help='Perform a rollback instead of upgrade',
action="store_true")
# define the delete command
_ = setup_delete_cmd(sub_cmds)
# define the apply command

View File

@ -252,9 +252,13 @@ class TestCLISwDeployStrategy(TestNFVClientShell,
self.set_strategy('sw-deploy-strategy')
def required_create_fields(self):
"""Kube Upgrade requires a to-version for create"""
"""Software deploy requires a release for create"""
return ['starlingx-24.03.1']
def optional_create_fields(self):
"""Software deploy also supports rollback"""
return ['--rollback']
class TestCLIPatchStrategy(TestNFVClientShell,
StrategyMixin):

View File

@ -50,6 +50,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
alarm_restrictions=SW_UPDATE_ALARM_RESTRICTION.STRICT,
default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,
release="123.1",
rollback=False,
nfvi_upgrade=None,
single_controller=False
):
@ -65,6 +66,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
default_instance_action=default_instance_action,
alarm_restrictions=alarm_restrictions,
release=release,
rollback=rollback,
ignore_alarms=[],
single_controller=single_controller,
)
@ -78,6 +80,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,
worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,
instances=None,
rollback=False,
**kwargs,
):
self.create_host('controller-0', aio=True, openstack_installed=openstack)
@ -94,6 +97,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
single_controller=True,
default_instance_action=default_instance_action,
worker_apply_type=worker_apply_type,
rollback=rollback,
**kwargs,
)
@ -105,6 +109,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,
worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,
instances=None,
rollback=False,
**kwargs,
):
self.create_host('controller-0', aio=True, openstack_installed=openstack)
@ -121,6 +126,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
strategy = self.create_sw_deploy_strategy(
default_instance_action=default_instance_action,
worker_apply_type=worker_apply_type,
rollback=rollback,
**kwargs,
)

View File

@ -54,6 +54,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
alarm_restrictions=SW_UPDATE_ALARM_RESTRICTION.STRICT,
default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,
release='starlingx-24.03.1',
rollback=False,
nfvi_upgrade=None,
single_controller=False
):
@ -69,6 +70,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
default_instance_action=default_instance_action,
alarm_restrictions=alarm_restrictions,
release=release,
rollback=rollback,
ignore_alarms=[],
single_controller=single_controller,
)
@ -91,6 +93,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
openstack=True,
default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,
worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,
rollback=False,
**kwargs,
):
self.create_host('controller-0', aio=True, openstack_installed=openstack)
@ -104,6 +107,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
single_controller=True,
default_instance_action=default_instance_action,
worker_apply_type=worker_apply_type,
rollback=rollback,
**kwargs,
)
@ -114,6 +118,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
openstack=True,
default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,
worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,
rollback=False,
**kwargs,
):
self.create_host('controller-0', aio=True, openstack_installed=openstack)
@ -127,6 +132,7 @@ class TestSwUpgradeStrategy(sw_update_testcase.SwUpdateStrategyTestCase):
strategy = self.create_sw_upgrade_strategy(
default_instance_action=default_instance_action,
worker_apply_type=worker_apply_type,
rollback=rollback,
**kwargs,
)

View File

@ -177,6 +177,8 @@ class SwUpgradeStrategyCreateData(wsme_types.Base):
name='controller-apply-type')
release = wsme_types.wsattr(six.text_type, mandatory=True,
name='release')
rollback = wsme_types.wsattr(bool, mandatory=True,
name='rollback')
storage_apply_type = wsme_types.wsattr(SwUpdateApplyTypes, mandatory=True,
name='storage-apply-type')
worker_apply_type = wsme_types.wsattr(SwUpdateApplyTypes, mandatory=True,
@ -675,6 +677,7 @@ class SwUpgradeStrategyAPI(SwUpdateStrategyAPI):
rpc_request.sw_update_type = _get_sw_update_type_from_path(
pecan.request.path)
rpc_request.release = request_data.release
rpc_request.rollback = request_data.rollback
rpc_request.controller_apply_type = request_data.controller_apply_type
rpc_request.storage_apply_type = request_data.storage_apply_type
rpc_request.swift_apply_type = SW_UPDATE_APPLY_TYPE.IGNORE

View File

@ -77,7 +77,7 @@ class SwMgmtDirector(object):
def create_sw_upgrade_strategy(self,
controller_apply_type, storage_apply_type, worker_apply_type,
max_parallel_worker_hosts, default_instance_action,
alarm_restrictions, release, callback):
alarm_restrictions, release, rollback, callback):
"""
Create Software Upgrade Strategy
"""
@ -94,7 +94,7 @@ class SwMgmtDirector(object):
success, reason = self._sw_update.strategy_build(
strategy_uuid, controller_apply_type, storage_apply_type,
worker_apply_type, max_parallel_worker_hosts, default_instance_action,
alarm_restrictions, release,
alarm_restrictions, release, rollback,
self._ignore_alarms, self._single_controller)
schedule.schedule_function_call(callback, success, reason,

View File

@ -100,10 +100,11 @@ def vim_sw_update_api_create_strategy(connection, msg):
alarm_restrictions, _vim_sw_update_api_create_strategy_callback)
elif 'sw-upgrade' == msg.sw_update_type:
release = msg.release
rollback = msg.rollback
uuid, reason = sw_mgmt_director.create_sw_upgrade_strategy(
controller_apply_type, storage_apply_type,
worker_apply_type, max_parallel_worker_hosts,
default_instance_action, alarm_restrictions, release,
default_instance_action, alarm_restrictions, release, rollback,
_vim_sw_update_api_create_strategy_callback)
elif 'fw-update' == msg.sw_update_type:
uuid, reason = sw_mgmt_director.create_fw_update_strategy(

View File

@ -31,7 +31,7 @@ class SwUpgrade(SwUpdate):
def strategy_build(self, strategy_uuid, controller_apply_type, storage_apply_type,
worker_apply_type, default_instance_action, max_parallel_worker_hosts,
alarm_restrictions, release,
alarm_restrictions, release, rollback,
ignore_alarms, single_controller):
"""
Create a software upgrade strategy
@ -51,6 +51,7 @@ class SwUpgrade(SwUpdate):
max_parallel_worker_hosts,
alarm_restrictions,
release,
rollback,
ignore_alarms,
single_controller,
)

View File

@ -72,10 +72,12 @@ class APIRequestCreateSwUpgradeStrategy(APIRequestCreateSwUpdateStrategy):
def serialize_payload(self, msg):
super(APIRequestCreateSwUpgradeStrategy, self).serialize_payload(msg)
msg['release'] = self.release
msg['rollback'] = self.rollback
def deserialize_payload(self, msg):
super(APIRequestCreateSwUpgradeStrategy, self).deserialize_payload(msg)
self.release = msg.get('release', None)
self.rollback = msg.get('rollback', None)
def __str__(self):
return "create-sw-deploy-strategy request: %s" % self.deserialize_payload

View File

@ -1762,7 +1762,7 @@ class SwUpgradeStrategy(
def __init__(self, uuid,
controller_apply_type, storage_apply_type, worker_apply_type,
max_parallel_worker_hosts, default_instance_action,
alarm_restrictions, release,
alarm_restrictions, release, rollback,
ignore_alarms, single_controller):
super(SwUpgradeStrategy, self).__init__(
uuid,
@ -1777,6 +1777,7 @@ class SwUpgradeStrategy(
ignore_alarms)
self._release = release
self._rollback = rollback
# The following alarms will not prevent a software upgrade operation
IGNORE_ALARMS = ['900.005', # Upgrade in progress
@ -1804,19 +1805,36 @@ class SwUpgradeStrategy(
"""
self._nfvi_upgrade = nfvi_upgrade
def build(self):
"""
Build the strategy
"""
def _build_normal(self):
from nfv_vim import strategy
stage = strategy.StrategyStage(strategy.STRATEGY_STAGE_NAME.SW_UPGRADE_QUERY)
stage.add_step(strategy.QueryAlarmsStep(ignore_alarms=self._ignore_alarms))
stage.add_step(strategy.QueryUpgradeStep(release=self._release))
self.build_phase.add_stage(stage)
super(SwUpgradeStrategy, self).build()
def _build_rollback(self):
reason = "Rollback not supported yet."
DLOG.warn(reason)
self._state = strategy.STRATEGY_STATE.BUILD_FAILED
self.build_phase.result = strategy.STRATEGY_PHASE_RESULT.FAILED
self.build_phase.result_reason = reason
self.sw_update_obj.strategy_build_complete(
False, self.build_phase.result_reason)
self.save()
super(SwUpgradeStrategy, self).build()
def build(self):
"""
Build the strategy
"""
if self._rollback:
return self._build_rollback()
return self._build_normal()
def _swact_fix(self, stage, controller_name):
"""Add a SWACT to a stage on DX systems
@ -1875,10 +1893,7 @@ class SwUpgradeStrategy(
stage.add_step(strategy.SystemStabilizeStep())
self.apply_phase.add_stage(stage)
def build_complete(self, result, result_reason):
"""
Strategy Build Complete
"""
def _build_complete_normal(self, result, result_reason):
from nfv_vim import strategy
from nfv_vim import tables
@ -2025,6 +2040,26 @@ class SwUpgradeStrategy(
self.sw_update_obj.strategy_build_complete(True, '')
self.save()
def _build_complete_rollback(self, result, result_reason):
reason = "Rollback not supported yet."
DLOG.warn(reason)
self._state = strategy.STRATEGY_STATE.BUILD_FAILED
self.build_phase.result = strategy.STRATEGY_PHASE_RESULT.FAILED
self.build_phase.result_reason = reason
self.sw_update_obj.strategy_build_complete(
False, self.build_phase.result_reason)
self.save()
super(SwUpgradeStrategy, self).build()
def build_complete(self, result, result_reason):
"""
Strategy Build Complete
"""
if self._rollback:
return self._build_complete_rollback(result, result_reason)
return self._build_complete_normal(result, result_reason)
def from_dict(self, data, build_phase=None, apply_phase=None, abort_phase=None):
"""
Initializes a software upgrade strategy object using the given dictionary
@ -2035,6 +2070,7 @@ class SwUpgradeStrategy(
abort_phase)
self._single_controller = data['single_controller']
self._release = data['release']
self._rollback = data['rollback']
nfvi_upgrade_data = data['nfvi_upgrade_data']
if nfvi_upgrade_data:
self._nfvi_upgrade = nfvi.objects.v1.Upgrade(
@ -2053,6 +2089,7 @@ class SwUpgradeStrategy(
data = super(SwUpgradeStrategy, self).as_dict()
data['single_controller'] = self._single_controller
data['release'] = self._release
data['rollback'] = self._rollback
if self._nfvi_upgrade:
nfvi_upgrade_data = self._nfvi_upgrade.as_dict()
else: