Fix overcloud cell export paths
This was silently failing with the warning:
File /home/stack/overcloud-deploy/overcloud/config-download/overcloud/overcloud/group_vars/overcloud.json was not found during export
No data returned to export AllNodesExtraMapData from.
Since the stack name was appended to config_download_dir twice.
Also the working_dir, if given, was ignored when exporting passwords
and the default config_download_dir was based on the working_dir instead of
the documented default.
(Squashes I02a89ce65d3ba1449360f2def96baedd64ac2653 and partial squash of
I9610ce51213ca2ad191d60914398131f11016453)
Change-Id: I77442878a6cc0fb7fb2bae71b888678099466300
(cherry picked from commit bcafdf7114
)
This commit is contained in:
parent
ffb494a776
commit
f9ab99cf04
|
@ -0,0 +1,119 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# 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
|
||||
from unittest import mock
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from tripleoclient.v1 import overcloud_cell
|
||||
from tripleoclient.exceptions import CellExportError
|
||||
from tripleoclient import utils as oooutils
|
||||
|
||||
|
||||
class TestExportCell(utils.TestCommand):
|
||||
def setUp(self):
|
||||
super(TestExportCell, self).setUp()
|
||||
self.cmd = overcloud_cell.ExportCell(self.app, None)
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
|
||||
@mock.patch('tripleoclient.v1.overcloud_cell.yaml.safe_dump')
|
||||
@mock.patch('tripleoclient.v1.overcloud_cell.print')
|
||||
@mock.patch('tripleoclient.v1.overcloud_cell.open')
|
||||
@mock.patch('tripleoclient.v1.overcloud_cell.export.export_stack')
|
||||
@mock.patch(
|
||||
'tripleoclient.v1.overcloud_cell.export.export_passwords',
|
||||
autospec=True)
|
||||
@mock.patch(
|
||||
'tripleoclient.v1.overcloud_cell.os.path.exists',
|
||||
autospec=True, return_value=False)
|
||||
def test_export_cell_defaults(self, mock_path_exists,
|
||||
mock_export_passwords, mock_export_stack,
|
||||
mock_open, mock_print, mock_yaml_dump):
|
||||
"""Test class methods with all default parameters.
|
||||
The test approximates the behavior of the CLI under assumption that no
|
||||
alternative values are provided and no exceptions are raised.
|
||||
"""
|
||||
argslist = []
|
||||
verifylist = []
|
||||
|
||||
mock_export_passwords._return_value = {'foo': 'bar'}
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
mock_path_exists.assert_any_call('overcloud-cell-export.yaml')
|
||||
mock_export_passwords.assert_called_once_with(
|
||||
oooutils.get_default_working_dir('overcloud'),
|
||||
'overcloud')
|
||||
mock_export_stack.assert_called_once_with(
|
||||
oooutils.get_default_working_dir('overcloud'),
|
||||
'overcloud',
|
||||
True,
|
||||
os.path.join(
|
||||
os.environ.get('HOME'),
|
||||
'overcloud-deploy',
|
||||
'overcloud',
|
||||
'config-download'))
|
||||
mock_print.assert_called()
|
||||
mock_open.assert_called_once_with('overcloud-cell-export.yaml', 'w')
|
||||
mock_yaml_dump.assert_called_once()
|
||||
|
||||
@mock.patch('tripleoclient.v1.overcloud_cell.yaml.safe_dump')
|
||||
@mock.patch('tripleoclient.v1.overcloud_cell.print')
|
||||
@mock.patch('tripleoclient.v1.overcloud_cell.open')
|
||||
@mock.patch('tripleoclient.v1.overcloud_cell.export.export_stack')
|
||||
@mock.patch(
|
||||
'tripleoclient.v1.overcloud_cell.export.export_passwords',
|
||||
autospec=True)
|
||||
@mock.patch(
|
||||
'tripleoclient.v1.overcloud_cell.os.path.exists',
|
||||
autospec=True, return_value=False)
|
||||
def test_export_cell_stack_config_dir(self, mock_path_exists,
|
||||
mock_export_passwords,
|
||||
mock_export_stack,
|
||||
mock_open,
|
||||
mock_print, mock_yaml_dump):
|
||||
"""Test class methods with alternative 'cells_stack'
|
||||
and 'config_download_dir' argument values.
|
||||
|
||||
The test approximates CLI behavior with no exceptions raised.
|
||||
"""
|
||||
argslist = ['--cell-stack', 'fizz', '--config-download-dir', 'buzz']
|
||||
verifylist = [('cell_stack', 'fizz'), ('config_download_dir', 'buzz')]
|
||||
|
||||
mock_export_passwords._return_value = {'foo': 'bar'}
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
mock_path_exists.assert_any_call('fizz-cell-export.yaml')
|
||||
mock_export_passwords.assert_called_once_with(
|
||||
oooutils.get_default_working_dir('fizz'),
|
||||
'fizz')
|
||||
mock_export_stack.assert_called_once_with(
|
||||
oooutils.get_default_working_dir('fizz'),
|
||||
'fizz',
|
||||
False,
|
||||
'buzz')
|
||||
mock_print.assert_called()
|
||||
mock_open.assert_called_once_with('fizz-cell-export.yaml', 'w')
|
||||
mock_yaml_dump.assert_called_once()
|
||||
|
||||
@mock.patch(
|
||||
'tripleoclient.v1.overcloud_cell.os.path.exists',
|
||||
return_value=True)
|
||||
def test_cell_exception(self, mock_exists):
|
||||
"""Test exception triggering behavior of the 'take_action' method.
|
||||
If the output file exists and the 'forced-overwrite' flag isn't set,
|
||||
the method must raise CellExportError to notify the operator.
|
||||
"""
|
||||
argslist = []
|
||||
verifylist = []
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
self.assertRaises(CellExportError, self.cmd.take_action, parsed_args)
|
||||
mock_exists.assert_any_call('overcloud-cell-export.yaml')
|
|
@ -82,10 +82,6 @@ class ExportCell(command.Command):
|
|||
raise exceptions.CellExportError(
|
||||
"File '%s' already exists, not exporting." % output_file)
|
||||
|
||||
data = export.export_passwords(
|
||||
oooutils.get_default_working_dir(control_plane_stack),
|
||||
control_plane_stack)
|
||||
|
||||
stack_to_export = control_plane_stack
|
||||
should_filter = True
|
||||
if cell_stack:
|
||||
|
@ -98,14 +94,17 @@ class ExportCell(command.Command):
|
|||
working_dir = parsed_args.working_dir
|
||||
|
||||
if not parsed_args.config_download_dir:
|
||||
download_dir = os.path.join(working_dir, 'config-download')
|
||||
config_download_dir = os.path.join(os.environ.get('HOME'),
|
||||
"overcloud-deploy",
|
||||
stack_to_export,
|
||||
'config-download')
|
||||
else:
|
||||
download_dir = parsed_args.config_download_dir
|
||||
config_download_dir = parsed_args.config_download_dir
|
||||
|
||||
config_download_dir = os.path.join(download_dir, stack_to_export)
|
||||
data = export.export_passwords(working_dir, stack_to_export)
|
||||
|
||||
data.update(export.export_stack(
|
||||
oooutils.get_default_working_dir(stack_to_export),
|
||||
working_dir,
|
||||
stack_to_export, should_filter,
|
||||
config_download_dir))
|
||||
data = dict(parameter_defaults=data)
|
||||
|
|
Loading…
Reference in New Issue