From fa514fd886ad875b849cc5998801654fad485ad6 Mon Sep 17 00:00:00 2001 From: Gustavo Herzmann Date: Tue, 27 Jun 2023 17:17:43 -0300 Subject: [PATCH] Move DC ansible override files to dc-vault This commit moves the ansible override files from /var/opt/dc/ansible to /opt/dc-vault/ansible, which is replicated across both controllers. This is done to address issues that arise when a subcloud is first created on one controller, followed by a swact, and the user attempts to perform another operation (such as subcloud reconfig). This situation leads to operation failures because the necessary ansible override files, such as the subcloud inventory file, are not available on the current active controller. Test Plan: 1. PASS - Verify that /opt/dc-vault/ansible directory gets created automatically with the correct mode (600) and owned by root; 2. PASS - Create a subcloud on controller-0 with 'dcmanager subcloud deploy create', passing the bootstrap-values, deploy-config and install-values parameters, swact to controller-1 and then run the deploy install, bootstrap and config without passing the parameters again. Verify that the subcloud is deployed correctly and that the operations are reading the files stored in dc-vault/ansible; 3. PASS - Deploy a subcloud with 'dcmanager subcloud add', passing the bootstrap-values, deploy-config and install-values, parameters, swact to controller-1 and run 'dcmanager subcloud reconfig' and verify that the operation completes successfully (the operation should use the subcloud inventory file stored inside dc-vault); Story: 2010756 Task: 48243 Change-Id: I6ac25bcd07f19a14f1bb5523d913a9e51b708d35 Signed-off-by: Gustavo Herzmann --- distributedcloud/dcmanager/common/consts.py | 2 +- distributedcloud/dcmanager/manager/service.py | 2 ++ .../v1/controllers/test_subcloud_deploy.py | 6 ++--- .../unit/api/v1/controllers/test_subclouds.py | 6 ++--- .../unit/manager/test_subcloud_manager.py | 26 +++++++++---------- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/distributedcloud/dcmanager/common/consts.py b/distributedcloud/dcmanager/common/consts.py index b0c64dd70..f94c7b3ba 100644 --- a/distributedcloud/dcmanager/common/consts.py +++ b/distributedcloud/dcmanager/common/consts.py @@ -282,7 +282,7 @@ ALARM_DEGRADED_STATUS = "degraded" ALARM_CRITICAL_STATUS = "critical" # subcloud deploy file options -ANSIBLE_OVERRIDES_PATH = '/var/opt/dc/ansible' +ANSIBLE_OVERRIDES_PATH = '/opt/dc-vault/ansible' DEPLOY_PLAYBOOK = "deploy_playbook" DEPLOY_OVERRIDES = "deploy_overrides" DEPLOY_CHART = "deploy_chart" diff --git a/distributedcloud/dcmanager/manager/service.py b/distributedcloud/dcmanager/manager/service.py index 2041ea714..a54853641 100644 --- a/distributedcloud/dcmanager/manager/service.py +++ b/distributedcloud/dcmanager/manager/service.py @@ -92,6 +92,8 @@ class DCManagerService(service.Service): if not os.path.isdir(consts.DC_ANSIBLE_LOG_DIR): os.mkdir(consts.DC_ANSIBLE_LOG_DIR, 0o755) + os.makedirs(consts.ANSIBLE_OVERRIDES_PATH, 0o600, exist_ok=True) + self.subcloud_manager.handle_subcloud_operations_in_progress() super(DCManagerService, self).start() diff --git a/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subcloud_deploy.py b/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subcloud_deploy.py index 0d10ce6cc..765a5949b 100644 --- a/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subcloud_deploy.py +++ b/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subcloud_deploy.py @@ -254,8 +254,8 @@ class TestSubcloudDeploy(testroot.DCManagerApiTest): deploy_config = psd_common.get_config_file_path("subcloud1", consts.DEPLOY_CONFIG) self.assertEqual(bootstrap_file, - "/var/opt/dc/ansible/subcloud1.yml") + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1.yml') self.assertEqual(install_values, - "/var/opt/dc/ansible/subcloud1/install_values.yml") + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1/install_values.yml') self.assertEqual(deploy_config, - "/var/opt/dc/ansible/subcloud1_deploy_config.yml") + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_deploy_config.yml') diff --git a/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subclouds.py b/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subclouds.py index e4cb4508d..28e158a3c 100644 --- a/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subclouds.py +++ b/distributedcloud/dcmanager/tests/unit/api/v1/controllers/test_subclouds.py @@ -1591,11 +1591,11 @@ class TestSubcloudAPIOther(testroot.DCManagerApiTest): install_values = sc._get_config_file_path("subcloud1", "install_values") deploy_config = sc._get_config_file_path("subcloud1", consts.DEPLOY_CONFIG) self.assertEqual(bootstrap_file, - "/var/opt/dc/ansible/subcloud1.yml") + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1.yml') self.assertEqual(install_values, - "/var/opt/dc/ansible/subcloud1/install_values.yml") + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1/install_values.yml') self.assertEqual(deploy_config, - "/var/opt/dc/ansible/subcloud1_deploy_config.yml") + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_deploy_config.yml') @mock.patch.object(rpc_client, 'ManagerClient') def test_format_ip_address(self, mock_rpc_client): diff --git a/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py b/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py index b6fda3b13..48c01a4e6 100644 --- a/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py +++ b/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py @@ -1581,22 +1581,22 @@ class TestSubcloudManager(base.DCManagerTestCase): filename = sm._get_ansible_filename('subcloud1', consts.INVENTORY_FILE_POSTFIX) self.assertEqual(filename, - '/var/opt/dc/ansible/subcloud1_inventory.yml') + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml') def test_compose_install_command(self): sm = subcloud_manager.SubcloudManager() install_command = sm.compose_install_command( 'subcloud1', - '/var/opt/dc/ansible/subcloud1_inventory.yml', + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', FAKE_PREVIOUS_SW_VERSION) self.assertEqual( install_command, [ 'ansible-playbook', subcloud_manager.ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK, - '-i', '/var/opt/dc/ansible/subcloud1_inventory.yml', + '-i', f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', '--limit', 'subcloud1', - '-e', "@/var/opt/dc/ansible/subcloud1/install_values.yml", + '-e', f"@{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1/install_values.yml", '-e', "install_release_version=%s" % FAKE_PREVIOUS_SW_VERSION ] ) @@ -1607,7 +1607,7 @@ class TestSubcloudManager(base.DCManagerTestCase): sm = subcloud_manager.SubcloudManager() apply_command = sm.compose_apply_command( 'subcloud1', - '/var/opt/dc/ansible/subcloud1_inventory.yml', + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', FAKE_PREVIOUS_SW_VERSION) self.assertEqual( apply_command, @@ -1616,9 +1616,9 @@ class TestSubcloudManager(base.DCManagerTestCase): cutils.get_playbook_for_software_version( subcloud_manager.ANSIBLE_SUBCLOUD_PLAYBOOK, FAKE_PREVIOUS_SW_VERSION), - '-i', '/var/opt/dc/ansible/subcloud1_inventory.yml', + '-i', f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', '--limit', 'subcloud1', '-e', - "override_files_dir='/var/opt/dc/ansible' region_name=subcloud1", + f"override_files_dir='{consts.ANSIBLE_OVERRIDES_PATH}' region_name=subcloud1", '-e', "install_release_version=%s" % FAKE_PREVIOUS_SW_VERSION ] ) @@ -1632,14 +1632,14 @@ class TestSubcloudManager(base.DCManagerTestCase): "deploy_config": "subcloud1.yaml"} deploy_command = sm.compose_deploy_command( 'subcloud1', - '/var/opt/dc/ansible/subcloud1_inventory.yml', + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', fake_payload) self.assertEqual( deploy_command, [ 'ansible-playbook', 'test_playbook.yaml', '-e', - '@/var/opt/dc/ansible/subcloud1_deploy_values.yml', '-i', - '/var/opt/dc/ansible/subcloud1_inventory.yml', + f'@{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_deploy_values.yml', '-i', + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', '--limit', 'subcloud1' ] ) @@ -1650,7 +1650,7 @@ class TestSubcloudManager(base.DCManagerTestCase): sm = subcloud_manager.SubcloudManager() rehome_command = sm.compose_rehome_command( 'subcloud1', - '/var/opt/dc/ansible/subcloud1_inventory.yml', + f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', FAKE_PREVIOUS_SW_VERSION) self.assertEqual( rehome_command, @@ -1659,11 +1659,11 @@ class TestSubcloudManager(base.DCManagerTestCase): cutils.get_playbook_for_software_version( subcloud_manager.ANSIBLE_SUBCLOUD_REHOME_PLAYBOOK, FAKE_PREVIOUS_SW_VERSION), - '-i', '/var/opt/dc/ansible/subcloud1_inventory.yml', + '-i', f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', '--limit', 'subcloud1', '--timeout', subcloud_manager.REHOME_PLAYBOOK_TIMEOUT, '-e', - "override_files_dir='/var/opt/dc/ansible' region_name=subcloud1" + f"override_files_dir='{consts.ANSIBLE_OVERRIDES_PATH}' region_name=subcloud1" ] )