diff --git a/nfv/nfv-client/nfv_client/openstack/sw_update.py b/nfv/nfv-client/nfv_client/openstack/sw_update.py index fd51a3e7..536b0b9f 100755 --- a/nfv/nfv-client/nfv_client/openstack/sw_update.py +++ b/nfv/nfv-client/nfv_client/openstack/sw_update.py @@ -7,6 +7,7 @@ import json import os from nfv_client.openstack import rest_api +from nfv_client import sw_update class StrategyStep(object): @@ -272,14 +273,14 @@ def create_strategy(token_id, api_cmd_headers['X-Auth-Token'] = token_id api_cmd_payload = dict() - if 'sw-patch' == strategy_name: + if sw_update.STRATEGY_NAME_SW_PATCH == strategy_name: api_cmd_payload['controller-apply-type'] = controller_apply_type api_cmd_payload['swift-apply-type'] = swift_apply_type api_cmd_payload['default-instance-action'] = default_instance_action - elif 'fw-update' == strategy_name: + elif sw_update.STRATEGY_NAME_FW_UPDATE == strategy_name: api_cmd_payload['controller-apply-type'] = controller_apply_type api_cmd_payload['default-instance-action'] = default_instance_action - elif 'kube-rootca-update' == strategy_name: + elif sw_update.STRATEGY_NAME_KUBE_ROOTCA_UPDATE == strategy_name: # Note that the payload contains '-' and not '_' if 'expiry_date' in kwargs and kwargs['expiry_date']: api_cmd_payload['expiry-date'] = kwargs['expiry_date'] @@ -291,14 +292,15 @@ def create_strategy(token_id, # may not succeed if a SWACT occurs. api_cmd_payload['cert-file'] = os.path.abspath(kwargs['cert_file']) api_cmd_payload['default-instance-action'] = default_instance_action - elif 'kube-upgrade' == strategy_name: + elif sw_update.STRATEGY_NAME_KUBE_UPGRADE == strategy_name: # required: 'to_version' passed to strategy as 'to-version' api_cmd_payload['to-version'] = kwargs['to_version'] api_cmd_payload['default-instance-action'] = default_instance_action - elif 'system-config-update' == strategy_name: + elif sw_update.STRATEGY_NAME_SYSTEM_CONFIG_UPDATE == strategy_name: api_cmd_payload['controller-apply-type'] = controller_apply_type api_cmd_payload['default-instance-action'] = default_instance_action - elif 'sw-upgrade' == strategy_name: + # TODO(jkraitbe): Backend for sw-deploy will continue as old sw-upgrade for now + elif sw_update.STRATEGY_NAME_SW_UPGRADE == strategy_name: # for upgrade: default-instance-action is hardcoded to MIGRATE if 'start_upgrade' in kwargs and kwargs['start_upgrade']: api_cmd_payload['start-upgrade'] = True diff --git a/nfv/nfv-client/nfv_client/shell.py b/nfv/nfv-client/nfv_client/shell.py index 281aca23..b15fd4e0 100755 --- a/nfv/nfv-client/nfv_client/shell.py +++ b/nfv/nfv-client/nfv_client/shell.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2023 Wind River Systems, Inc. +# Copyright (c) 2016-2024 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -47,26 +47,27 @@ def get_extra_create_args(cmd_area, args): :returns: a dictionary of additional kwargs for the create_strategy command :raises: ValueError if a strategy has been registered but not update here """ - if 'patch-strategy' == cmd_area: + if sw_update.CMD_NAME_SW_PATCH == cmd_area: # no additional kwargs for patch return {} - elif 'upgrade-strategy' == cmd_area: + elif sw_update.CMD_NAME_SW_DEPLOY == cmd_area: + # TODO(jkraitbe): Args will be updated to use new release parameter # upgrade supports: complete_upgrade return {'complete_upgrade': args.complete_upgrade} - elif 'fw-update-strategy' == cmd_area: + elif sw_update.CMD_NAME_FW_UPDATE == cmd_area: # no additional kwargs for firmware update return {} - elif 'system-config-update-strategy' == cmd_area: + elif sw_update.CMD_NAME_SYSTEM_CONFIG_UPDATE == cmd_area: # no additional kwargs for system config update return {} - elif 'kube-rootca-update-strategy' == cmd_area: + elif sw_update.CMD_NAME_KUBE_ROOTCA_UPDATE == cmd_area: # kube rootca update supports expiry_date, subject and cert_file return { 'expiry_date': args.expiry_date, 'subject': args.subject, 'cert_file': args.cert_file } - elif 'kube-upgrade-strategy' == cmd_area: + elif sw_update.CMD_NAME_KUBE_UPGRADE == cmd_area: # kube upgrade supports: to_version return {'to_version': args.to_version} else: @@ -201,7 +202,7 @@ def setup_show_cmd(parser): def setup_fw_update_parser(commands): """Firmware Update Strategy Commands""" - cmd_area = 'fw-update-strategy' + cmd_area = sw_update.CMD_NAME_FW_UPDATE register_strategy(cmd_area, sw_update.STRATEGY_NAME_FW_UPDATE) cmd_parser = commands.add_parser(cmd_area, help='Firmware Update Strategy') @@ -242,7 +243,7 @@ def setup_fw_update_parser(commands): def setup_kube_rootca_update_parser(commands): """Kubernetes RootCA Update Strategy Commands""" - cmd_area = 'kube-rootca-update-strategy' + cmd_area = sw_update.CMD_NAME_KUBE_ROOTCA_UPDATE register_strategy(cmd_area, sw_update.STRATEGY_NAME_KUBE_ROOTCA_UPDATE) cmd_parser = commands.add_parser(cmd_area, help='Kubernetes RootCA Update Strategy') @@ -298,7 +299,7 @@ def setup_kube_rootca_update_parser(commands): def setup_kube_upgrade_parser(commands): """Kubernetes Upgrade Strategy Commands""" - cmd_area = 'kube-upgrade-strategy' + cmd_area = sw_update.CMD_NAME_KUBE_UPGRADE register_strategy(cmd_area, sw_update.STRATEGY_NAME_KUBE_UPGRADE) cmd_parser = commands.add_parser(cmd_area, help='Kubernetes Upgrade Strategy') @@ -347,7 +348,7 @@ def setup_kube_upgrade_parser(commands): def setup_patch_parser(commands): """Patch Strategy Commands""" - cmd_area = 'patch-strategy' + cmd_area = sw_update.CMD_NAME_SW_PATCH register_strategy(cmd_area, sw_update.STRATEGY_NAME_SW_PATCH) cmd_parser = commands.add_parser(cmd_area, help='Patch Strategy') @@ -390,7 +391,7 @@ def setup_patch_parser(commands): def setup_system_config_update_parser(commands): """System config update Strategy Commands""" - cmd_area = 'system-config-update-strategy' + cmd_area = sw_update.CMD_NAME_SYSTEM_CONFIG_UPDATE register_strategy(cmd_area, sw_update.STRATEGY_NAME_SYSTEM_CONFIG_UPDATE) cmd_parser = commands.add_parser(cmd_area, help='system config update Strategy') @@ -429,16 +430,17 @@ def setup_system_config_update_parser(commands): _ = setup_show_cmd(sub_cmds) -def setup_upgrade_parser(commands): - """Upgrade Strategy Commands""" +def setup_sw_deploy_parser(commands): + """Software Deploy Strategy Commands""" - cmd_area = 'upgrade-strategy' + cmd_area = sw_update.CMD_NAME_SW_DEPLOY + # TODO(jkraitbe): Backend for sw-deploy will continue as old sw-upgrade for now register_strategy(cmd_area, sw_update.STRATEGY_NAME_SW_UPGRADE) cmd_parser = commands.add_parser(cmd_area, - help='Upgrade Strategy') + help='Software Deploy Strategy') cmd_parser.set_defaults(cmd_area=cmd_area) - sub_cmds = cmd_parser.add_subparsers(title='Software Upgrade Commands', + sub_cmds = cmd_parser.add_subparsers(title='Software Deploy Commands', metavar='') sub_cmds.required = True @@ -457,10 +459,10 @@ def setup_upgrade_parser(commands): [sw_update.ALARM_RESTRICTIONS_STRICT, # alarm restrictions sw_update.ALARM_RESTRICTIONS_RELAXED], min_parallel=2, - max_parallel=10 # upgrade supports 2..10 workers in parallel + max_parallel=10 # SW Deploy supports 2..10 workers in parallel ) - # add upgrade specific arguments to the create command + # add sw-deploy specific arguments to the create command # The get_extra_create_args method is updated to align with these # Disable support for --start-upgrade as it was not completed @@ -468,6 +470,7 @@ def setup_upgrade_parser(commands): # action='store_true', # help=argparse.SUPPRESS) + # TODO(jkraitbe): Args will be updated to use new release parameter create_strategy_cmd.add_argument('--complete-upgrade', action='store_true', help=argparse.SUPPRESS) @@ -516,8 +519,8 @@ def process_main(argv=sys.argv[1:]): # pylint: disable=dangerous-default-value # Add system config update strategy commands setup_system_config_update_parser(commands) - # Add software upgrade strategy commands - setup_upgrade_parser(commands) + # Add software sw-deploy strategy commands + setup_sw_deploy_parser(commands) args = parser.parse_args(argv) diff --git a/nfv/nfv-client/nfv_client/sw_update/__init__.py b/nfv/nfv-client/nfv_client/sw_update/__init__.py index 44c06c3e..faf8c7a0 100755 --- a/nfv/nfv-client/nfv_client/sw_update/__init__.py +++ b/nfv/nfv-client/nfv_client/sw_update/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2023 Wind River Systems, Inc. +# Copyright (c) 2016-2024 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -9,6 +9,12 @@ from nfv_client.sw_update._sw_update import apply_strategy # noqa: F401 from nfv_client.sw_update._sw_update import APPLY_TYPE_IGNORE # noqa: F401 from nfv_client.sw_update._sw_update import APPLY_TYPE_PARALLEL # noqa: F401 from nfv_client.sw_update._sw_update import APPLY_TYPE_SERIAL # noqa: F401 +from nfv_client.sw_update._sw_update import CMD_NAME_FW_UPDATE # noqa: F401 +from nfv_client.sw_update._sw_update import CMD_NAME_KUBE_ROOTCA_UPDATE # noqa: F401 +from nfv_client.sw_update._sw_update import CMD_NAME_KUBE_UPGRADE # noqa: F401 +from nfv_client.sw_update._sw_update import CMD_NAME_SW_DEPLOY # noqa: F401 +from nfv_client.sw_update._sw_update import CMD_NAME_SW_PATCH # noqa: F401 +from nfv_client.sw_update._sw_update import CMD_NAME_SYSTEM_CONFIG_UPDATE # noqa: F401 from nfv_client.sw_update._sw_update import create_strategy # noqa: F401 from nfv_client.sw_update._sw_update import delete_strategy # noqa: F401 from nfv_client.sw_update._sw_update import INSTANCE_ACTION_MIGRATE # noqa: F401 diff --git a/nfv/nfv-client/nfv_client/sw_update/_sw_update.py b/nfv/nfv-client/nfv_client/sw_update/_sw_update.py index 398d9757..4f207cff 100755 --- a/nfv/nfv-client/nfv_client/sw_update/_sw_update.py +++ b/nfv/nfv-client/nfv_client/sw_update/_sw_update.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2023 Wind River Systems, Inc. +# Copyright (c) 2016-2024 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -13,6 +13,13 @@ STRATEGY_NAME_KUBE_ROOTCA_UPDATE = 'kube-rootca-update' STRATEGY_NAME_KUBE_UPGRADE = 'kube-upgrade' STRATEGY_NAME_SYSTEM_CONFIG_UPDATE = 'system-config-update' +CMD_NAME_SW_PATCH = 'patch-strategy' +CMD_NAME_SW_DEPLOY = 'sw-deploy-strategy' +CMD_NAME_FW_UPDATE = 'fw-update-strategy' +CMD_NAME_KUBE_ROOTCA_UPDATE = 'kube-rootca-update-strategy' +CMD_NAME_KUBE_UPGRADE = 'kube-upgrade-strategy' +CMD_NAME_SYSTEM_CONFIG_UPDATE = 'system-config-update-strategy' + APPLY_TYPE_SERIAL = 'serial' APPLY_TYPE_PARALLEL = 'parallel' APPLY_TYPE_IGNORE = 'ignore' @@ -123,8 +130,9 @@ def _display_strategy(strategy, details=False, active=False): """ if strategy.name == STRATEGY_NAME_SW_PATCH: print("Strategy Patch Strategy:") + # TODO(jkraitbe): Backend for sw-deploy will continue as old sw-upgrade for now elif strategy.name == STRATEGY_NAME_SW_UPGRADE: - print("Strategy Upgrade Strategy:") + print("Strategy Software Deploy Strategy:") elif strategy.name == STRATEGY_NAME_FW_UPDATE: print("Strategy Firmware Update Strategy:") elif strategy.name == STRATEGY_NAME_KUBE_ROOTCA_UPDATE: diff --git a/nfv/nfv-client/scripts/sw-manager.completion b/nfv/nfv-client/scripts/sw-manager.completion index 60add5a6..16c267e1 100755 --- a/nfv/nfv-client/scripts/sw-manager.completion +++ b/nfv/nfv-client/scripts/sw-manager.completion @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2023 Wind River Systems, Inc. +# Copyright (c) 2016-2024 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -20,7 +20,7 @@ function _swmanager() # local subcommands=" patch-strategy - upgrade-strategy + sw-deploy-strategy fw-update-strategy kube-rootca-update-strategy kube-upgrade-strategy @@ -109,7 +109,7 @@ function _swmanager() COMPREPLY=($(compgen -W "${actions}" -- ${cur})) return 0 ;; - upgrade-strategy) + sw-deploy-strategy) local actions=" create delete diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_nfv_client.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_nfv_client.py index 8a96ae99..2e6c2dd8 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_nfv_client.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_nfv_client.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2023 Wind River Systems, Inc. +# Copyright (c) 2023-2024 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -245,11 +245,11 @@ class StrategyMixin(object): self._test_shell_create(shell_args=shell_args) -class TestCLIUpgradeStrategy(TestNFVClientShell, +class TestCLISwDeployStrategy(TestNFVClientShell, StrategyMixin): def setUp(self): - super(TestCLIUpgradeStrategy, self).setUp() - self.set_strategy('upgrade-strategy') + super(TestCLISwDeployStrategy, self).setUp() + self.set_strategy('sw-deploy-strategy') class TestCLIPatchStrategy(TestNFVClientShell,