From 191438f7435aa19e9656a2052bbb6fa5ce7b6b32 Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Tue, 21 Apr 2020 16:13:07 +0530 Subject: [PATCH] Don't use mistral directory as WORK_DIR for config-download As part of mistral removal all config-downloaded playbooks are run from tripleoclient. This changes the download location to $HOME/config-download. Documentation for default location will be changed along with all doc changes for mistral removal. Closes-Bug: #1874432 Depends-On: https://review.opendev.org/721568/ Change-Id: Ib4c9c47baabd64f008c4f61e4fa8c37a311350a3 --- tripleoclient/constants.py | 7 ++++--- tripleoclient/export.py | 3 ++- tripleoclient/tests/test_export.py | 14 ++++++++++---- .../v1/overcloud_deploy/test_overcloud_deploy.py | 3 ++- .../v1/overcloud_node/test_overcloud_node.py | 3 ++- tripleoclient/tests/v1/test_overcloud_export.py | 15 +++++++++++---- tripleoclient/v1/overcloud_deploy.py | 6 ++---- tripleoclient/v1/overcloud_export.py | 5 +++-- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/tripleoclient/constants.py b/tripleoclient/constants.py index 9775b18fb..d804fade1 100644 --- a/tripleoclient/constants.py +++ b/tripleoclient/constants.py @@ -89,10 +89,11 @@ DEFAULT_VALIDATIONS_BASEDIR = '/usr/share/openstack-tripleo-validations' VALIDATIONS_LOG_BASEDIR = '/var/log/validations' -DEFAULT_WORK_DIR = '/var/lib/mistral' +DEFAULT_WORK_DIR = os.path.join(os.environ.get('HOME', '~/'), + 'config-download') -ANSIBLE_INVENTORY = \ - '/var/lib/mistral/overcloud/tripleo-ansible-inventory.yaml' +ANSIBLE_INVENTORY = os.path.join(DEFAULT_WORK_DIR, + 'overcloud/tripleo-ansible-inventory.yaml') ANSIBLE_VALIDATION_DIR = \ '/usr/share/openstack-tripleo-validations/playbooks' diff --git a/tripleoclient/export.py b/tripleoclient/export.py index 41d095eb3..e32cc353d 100644 --- a/tripleoclient/export.py +++ b/tripleoclient/export.py @@ -53,7 +53,7 @@ def export_passwords(swift, stack, excludes=True): def export_stack(heat, stack, should_filter=False, - config_download_dir='/var/lib/mistral/overcloud'): + config_download_dir=constants.DEFAULT_WORK_DIR): # data to export # parameter: Parameter to be exported @@ -90,6 +90,7 @@ def export_stack(heat, stack, should_filter=False, if "file" in export_param: # get file data file = os.path.join(config_download_dir, + stack, export_param["file"]) with open(file, 'r') as ff: try: diff --git a/tripleoclient/tests/test_export.py b/tripleoclient/tests/test_export.py index 9d396db22..86861e346 100644 --- a/tripleoclient/tests/test_export.py +++ b/tripleoclient/tests/test_export.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. # - +import os from io import StringIO import mock @@ -57,7 +57,10 @@ class TestExport(TestCase): self.assertEqual(expected, data) self.mock_open.assert_called_once_with( - '/var/lib/mistral/overcloud/group_vars/overcloud.json', 'r') + os.path.join( + os.environ.get('HOME'), + 'config-download/overcloud/group_vars/overcloud.json'), + 'r') @mock.patch('tripleoclient.utils.get_stack') def test_export_stack_should_filter(self, mock_get_stack): @@ -76,7 +79,10 @@ class TestExport(TestCase): self.assertEqual(expected, data) self.mock_open.assert_called_once_with( - '/var/lib/mistral/overcloud/group_vars/overcloud.json', 'r') + os.path.join( + os.environ.get('HOME'), + 'config-download/overcloud/group_vars/overcloud.json'), + 'r') @mock.patch('tripleoclient.utils.get_stack') def test_export_stack_cd_dir(self, mock_get_stack): @@ -84,7 +90,7 @@ class TestExport(TestCase): mock_get_stack.return_value = self.mock_stack with mock.patch('six.moves.builtins.open', self.mock_open): export.export_stack(heat, "overcloud", - config_download_dir='/foo/overcloud') + config_download_dir='/foo') self.mock_open.assert_called_once_with( '/foo/overcloud/group_vars/overcloud.json', 'r') diff --git a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py index 95cc2b6c9..0619f154d 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py +++ b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py @@ -1624,7 +1624,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) - playbook = '/var/lib/mistral/overcloud/deploy_steps_playbook.yaml' + playbook = os.path.join(os.environ.get( + 'HOME'), 'config-download/overcloud/deploy_steps_playbook.yaml') self.assertIn( [mock.call( ansible_cfg=None, ansible_timeout=42, diff --git a/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py b/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py index 101cf7d69..52aa52af7 100644 --- a/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py +++ b/tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py @@ -233,7 +233,8 @@ class TestDeleteNode(fakes.TestDeleteNode): playbook_dir='/usr/share/ansible/tripleo-playbooks', verbosity=mock.ANY, extra_vars={ - 'access_path': '/var/lib/mistral', + 'access_path': os.path.join(os.environ.get('HOME'), + 'config-download'), 'execution_user': mock.ANY}, ), mock.call( diff --git a/tripleoclient/tests/v1/test_overcloud_export.py b/tripleoclient/tests/v1/test_overcloud_export.py index 54357971b..f47680e37 100644 --- a/tripleoclient/tests/v1/test_overcloud_export.py +++ b/tripleoclient/tests/v1/test_overcloud_export.py @@ -11,6 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import os import mock @@ -37,7 +38,8 @@ class TestOvercloudExport(utils.TestCommand): @mock.patch('tripleoclient.export.export_passwords') def test_export(self, mock_export_passwords, mock_export_stack, - mock_safe_dump, mock_exists): + mock_safe_dump, + mock_exists): argslist = [] verifylist = [] parsed_args = self.check_parser(self.cmd, argslist, verifylist) @@ -49,11 +51,13 @@ class TestOvercloudExport(utils.TestCommand): mock_export_passwords.assert_called_once_with( self.app.client_manager.tripleoclient.object_store, 'overcloud', True) + path = os.path.join(os.environ.get('HOME'), + 'config-download/overcloud') mock_export_stack.assert_called_once_with( self.app.client_manager.orchestration, 'overcloud', False, - '/var/lib/mistral/overcloud') + path) self.assertEqual( {'parameter_defaults': {'key': 'value', 'key0': 'value0'}}, @@ -65,7 +69,8 @@ class TestOvercloudExport(utils.TestCommand): @mock.patch('tripleoclient.export.export_passwords') def test_export_stack_name(self, mock_export_passwords, mock_export_stack, - mock_safe_dump, mock_exists): + mock_safe_dump, + mock_exists): argslist = ['--stack', 'foo'] verifylist = [('stack', 'foo')] parsed_args = self.check_parser(self.cmd, argslist, verifylist) @@ -75,11 +80,13 @@ class TestOvercloudExport(utils.TestCommand): mock_export_passwords.assert_called_once_with( self.app.client_manager.tripleoclient.object_store, 'foo', True) + path = os.path.join(os.environ.get('HOME'), + 'config-download/foo') mock_export_stack.assert_called_once_with( self.app.client_manager.orchestration, 'foo', False, - '/var/lib/mistral/foo') + path) @mock.patch('os.path.exists') @mock.patch('yaml.safe_dump') diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index 2fd4893f5..47c542c0b 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -923,10 +923,8 @@ class DeployOvercloud(command.Command): action='store', default=None, help=_('Directory to use for saved output when using ' - '--config-download. The directory must be ' - 'writeable by the mistral user. When not ' - 'specified, the default server side value ' - 'will be used (/var/lib/mistral/.') + '--config-download. When not ' + 'specified, $HOME/config-download will be used.') ) parser.add_argument( '--override-ansible-cfg', diff --git a/tripleoclient/v1/overcloud_export.py b/tripleoclient/v1/overcloud_export.py index e1448552f..074a4efeb 100644 --- a/tripleoclient/v1/overcloud_export.py +++ b/tripleoclient/v1/overcloud_export.py @@ -51,7 +51,7 @@ class ExportOvercloud(command.Command): action='store', help=_('Directory to search for config-download ' 'export data. Defaults to ' - '/var/lib/mistral/')) + '$HOME/config-download/')) parser.add_argument('--no-password-excludes', action='store_true', dest='no_password_excludes', @@ -78,7 +78,8 @@ class ExportOvercloud(command.Command): "File '%s' already exists, not exporting." % output_file) if not parsed_args.config_download_dir: - config_download_dir = os.path.join('/var/lib/mistral', + config_download_dir = os.path.join(os.environ.get('HOME'), + 'config-download', parsed_args.stack) else: config_download_dir = parsed_args.config_download_dir