From 9d384d63b10a2f6da938470d837d0e6d50670d63 Mon Sep 17 00:00:00 2001 From: Gustavo Herzmann Date: Tue, 7 Nov 2023 10:43:57 -0300 Subject: [PATCH] Add --migrate option to subcloud unmanage This commit adds the --migrate option to the subcloud unmanage command, besides unmanaging the subcloud it also changes its deploy status to 'rehome-pending'. It should be used when unmanaging a subcloud before the rehoming/migration operation. This new status will then be used by cert-mon to determine when it should stop auditing an unmanaged subcloud, to avoid certificate issues during the rehoming operation. It's only possible to use this option when the subcloud's deploy status is 'complete'. It's possible to manage it back in case the rehoming operation is not going to be executed anymore; in this case the deploy-status will be reverted back to 'complete'. Example usage: dcmanager subcloud unmanage --migrate subcloud1 Test Plan: 1. PASS - Unmanage a subcloud without --migrate and verify that it still works and that cert-mon continues to audit it; 2. PASS - Manage a subcloud, verify that the operation still works as expected; 3. PASS - Try to unmanage with --migrate when the subcloud's deploy status is different than 'complete' and verify that it doesn't allow it; 4. PASS - Unmanage a subcloud using the --migrate option and verify that its deploy status changes to 'rehome-pending', all the sync statuses change to 'unknown', and that cert-mon stops auditing the subcloud; 5. PASS - Manage a 'rehome-pending' subcloud and verify that it succeeds while also reverting its deploy_status to 'complete'; Depends-on: https://review.opendev.org/c/starlingx/distcloud/+/900288 Story: 2010852 Task: 49060 Signed-off-by: Gustavo Herzmann Change-Id: I1d761c1a0ae401a11443d80df70338acb2a0a14a --- .../dcmanagerclient/commands/v1/subcloud_manager.py | 12 ++++++++++++ .../tests/v1/test_subcloud_manager.py | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_manager.py b/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_manager.py index 4482080..fa1111d 100644 --- a/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_manager.py +++ b/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_manager.py @@ -422,6 +422,14 @@ class UnmanageSubcloud(base.DCManagerShowOne): 'subcloud', help='Name or ID of the subcloud to unmanage.' ) + + parser.add_argument( + '--migrate', + required=False, + action='store_true', + help='Mark the subcloud for an upcoming migration.' + ) + return parser def _get_resources(self, parsed_args): @@ -429,6 +437,10 @@ class UnmanageSubcloud(base.DCManagerShowOne): dcmanager_client = self.app.client_manager.subcloud_manager kwargs = dict() kwargs['management-state'] = 'unmanaged' + + if parsed_args.migrate: + kwargs['migrate'] = 'true' + try: result = dcmanager_client.subcloud_manager.update_subcloud( subcloud_ref, files=None, data=kwargs) diff --git a/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_manager.py b/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_manager.py index e31bc2e..b09a31a 100644 --- a/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_manager.py +++ b/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_manager.py @@ -221,6 +221,15 @@ class TestCLISubcloudManagerV1(base.BaseCommandTest): base.SUBCLOUD_FIELD_RESULT_LIST_WITH_PEERID, actual_call[1]) + def test_unmanage_subcloud_with_migrate(self): + self.client.subcloud_manager.update_subcloud.\ + return_value = [base.SUBCLOUD_RESOURCE] + actual_call = self.call( + subcloud_cmd.UnmanageSubcloud, app_args=[base.ID, '--migrate']) + self.assertEqual( + base.SUBCLOUD_FIELD_RESULT_LIST_WITH_PEERID, + actual_call[1]) + def test_unmanage_subcloud_without_subcloud_id(self): self.assertRaises(SystemExit, self.call, subcloud_cmd.UnmanageSubcloud, app_args=[])