From f595d551f8a451fa13d0f94f532f087c8846b9d2 Mon Sep 17 00:00:00 2001 From: Victor Romano Date: Wed, 22 Mar 2023 00:56:09 -0300 Subject: [PATCH] Add release parameter to subcloud-backup restore Add optional --release parameter to subcloud-backup restore so that the user can specify which loaded image to use during the installation process triggered by --with-install. This parameter can only be used if --with-install is also provided. Test plan: Success cases: - PASS: Verify that the "subcloud-backup restore" command works with and without the release parameter. - PASS: Verify that, when provided, the release parameter is successfully passed to backend using "subcloud-backup restore". Failure cases: - PASS: Verify that using the release parameter without with-install it's not possible. Depends-On: https://review.opendev.org/c/starlingx/distcloud/+/878506 Story: 2010611 Task: 47693 Signed-off-by: Victor Romano Change-Id: Id86325ffab3a2a047af981cc218058a738293360 --- .../commands/v1/subcloud_backup_manager.py | 20 +++++- .../tests/v1/test_subcloud_backup_manager.py | 62 ++++++++++++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_backup_manager.py b/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_backup_manager.py index 75117df..0fe3a67 100644 --- a/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_backup_manager.py +++ b/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_backup_manager.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2022 Wind River Systems, Inc. +# Copyright (c) 2022-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -308,6 +308,14 @@ class RestoreSubcloudBackup(base.DCManagerShow): 'being restored from backup data.' ) + parser.add_argument( + '--release', + required=False, + help='Software release used to install, bootstrap and/or deploy ' + 'the subcloud with. If not specified, the current software ' + 'release of the system controller will be used.' + ) + parser.add_argument( '--local-only', required=False, @@ -383,6 +391,11 @@ class RestoreSubcloudBackup(base.DCManagerShow): '--local-only option.') raise exceptions.DCManagerClientException(error_msg) + if not parsed_args.with_install and parsed_args.release: + error_msg = ('Option --release cannot be used without ' + '--with-install option.') + raise exceptions.DCManagerClientException(error_msg) + if parsed_args.with_install: data['with_install'] = 'true' else: @@ -398,6 +411,9 @@ class RestoreSubcloudBackup(base.DCManagerShow): else: data['registry_images'] = 'false' + if parsed_args.release is not None: + data['release'] = parsed_args.release + if parsed_args.sysadmin_password is not None: data['sysadmin_password'] = base64.b64encode( parsed_args.sysadmin_password.encode("utf-8")).decode("utf-8") @@ -405,12 +421,14 @@ class RestoreSubcloudBackup(base.DCManagerShow): password = utils.prompt_for_password() data["sysadmin_password"] = base64.b64encode( password.encode("utf-8")).decode("utf-8") + if parsed_args.restore_values: if not os.path.isfile(parsed_args.restore_values): error_msg = "Restore_values file does not exist: %s" % \ parsed_args.restore_values raise exceptions.DCManagerClientException(error_msg) files['restore_values'] = parsed_args.restore_values + try: return dcmanager_client.subcloud_backup_manager.\ backup_subcloud_restore(data=data, files=files) diff --git a/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_backup_manager.py b/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_backup_manager.py index 1350918..a4f6875 100644 --- a/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_backup_manager.py +++ b/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_backup_manager.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2022 Wind River Systems, Inc. +# Copyright (c) 2022-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -499,3 +499,63 @@ class TestCLISubcloudBackUpManagerV1(base.BaseCommandTest): self.assertTrue(('Option --registry-images cannot be used without ' '--local-only option.') in str(e)) + + def test_backup_restore_with_install_no_release(self): + self.client.subcloud_backup_manager.backup_subcloud_restore.\ + return_value = [SUBCLOUD] + + backupPath = os.path.normpath(os.path.join(os.getcwd(), "test.yaml")) + with open(backupPath, mode='w') as f: + f.write(OVERRIDE_VALUES) + + actual_call = self.call( + subcloud_backup_cmd.RestoreSubcloudBackup, + app_args=['--subcloud', 'subcloud1', + '--with-install', + '--local-only', + '--registry-images', + '--restore-values', backupPath, + '--sysadmin-password', 'testpassword']) + + self.assertEqual(DEFAULT_SUBCLOUD_FIELD_RESULT, actual_call[1]) + + def test_backup_restore_with_install_with_release(self): + self.client.subcloud_backup_manager.backup_subcloud_restore.\ + return_value = [SUBCLOUD] + + backupPath = os.path.normpath(os.path.join(os.getcwd(), "test.yaml")) + with open(backupPath, mode='w') as f: + f.write(OVERRIDE_VALUES) + + actual_call = self.call( + subcloud_backup_cmd.RestoreSubcloudBackup, + app_args=['--subcloud', 'subcloud1', + '--with-install', + '--release', SOFTWARE_VERSION, + '--local-only', + '--registry-images', + '--restore-values', backupPath, + '--sysadmin-password', 'testpassword']) + + self.assertEqual(DEFAULT_SUBCLOUD_FIELD_RESULT, actual_call[1]) + + def test_backup_restore_no_install_with_release(self): + self.client.subcloud_backup_manager.backup_subcloud_restore.\ + return_value = [SUBCLOUD] + + backupPath = os.path.normpath(os.path.join(os.getcwd(), "test.yaml")) + with open(backupPath, mode='w') as f: + f.write(OVERRIDE_VALUES) + + e = self.assertRaises(DCManagerClientException, + self.call, + subcloud_backup_cmd.RestoreSubcloudBackup, + app_args=['--subcloud', 'subcloud1', + '--release', SOFTWARE_VERSION, + '--local-only', + '--registry-images', + '--restore-values', backupPath, + '--sysadmin-password', 'testpassword']) + + self.assertTrue(('Option --release cannot be used without ' + '--with-install option.') in str(e))