[train-only] Add ipa config check to _cleanup_ipa

This adds a check to determine if this system is a properly configured
ipa client, if not the _cleanup_ipa code will be bypassed. This should
eliminate the need to pass -s on non TLS-e environments.

This commit also defensively bypasses IPA cleanup if tripleoclient can't
generate a reasonable inventory file. It's better to bail early and
inform the user that they need to manually clean-up IPA instead of
munging the data in IPA based on assumptions. This is especially true if
IPA is a shared resource and not specific to the OpenStack deployment.

Change-Id: I093faee1d136d1fa697d45647c8311fe82379c5c
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1865900
This commit is contained in:
Dave Wilde (d34dh0r53) 2020-08-17 15:52:48 -05:00 committed by Lance Bragstad
parent afcd9abf7e
commit 5e3097e419
2 changed files with 42 additions and 2 deletions

View File

@ -15,6 +15,7 @@
import mock
from tripleoclient import exceptions
from tripleoclient.tests.v1.overcloud_deploy import fakes
from tripleoclient.v1 import overcloud_delete
@ -143,3 +144,25 @@ class TestDeleteOvercloud(fakes.TestDeployOvercloud):
self.cmd.take_action(parsed_args)
mock_overcloud_delete.assert_not_called()
@mock.patch('os.path.exists')
@mock.patch('tripleoclient.utils.get_tripleo_ansible_inventory')
def test_skip_ipa_cleanup_without_inventory(self, inventory_mock, os_mock):
arglist = ["overcloud", "-y"]
verifylist = [
("stack", "overcloud"),
("yes", True)
]
os_mock.return_value = True
inventory_mock.side_effect = exceptions.InvalidConfiguration()
self.cmd.log.warning = mock.MagicMock()
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.cmd.log.warning.assert_called_with(
"Unable to generate the necessary ansible inventory required to "
"cleanup IPA. Ignoring IPA cleanup. Please cleanup IPA resources "
"for overcloud stack manually."
)

View File

@ -26,6 +26,7 @@ from osc_lib import utils as osc_utils
from tripleoclient import command
from tripleoclient import constants
from tripleoclient import exceptions
from tripleoclient import utils
from tripleoclient.workflows import plan_management
from tripleoclient.workflows import stack_management
@ -101,6 +102,14 @@ class DeleteOvercloud(command.Command):
python_interpreter = \
"/usr/bin/python{}".format(sys.version_info[0])
playbook = '/usr/share/ansible/tripleo-playbooks/cli-cleanup-ipa.yml'
ipa_config = '/etc/ipa/default.conf'
if not os.path.exists(ipa_config):
self.log.debug(
"{} doesn't exist on system. "
"Ignoring IPA cleanup.".format(playbook)
)
return
if not os.path.exists(playbook):
self.log.debug(
@ -109,8 +118,16 @@ class DeleteOvercloud(command.Command):
)
return
static_inventory = utils.get_tripleo_ansible_inventory(
return_inventory_file_path=True)
try:
static_inventory = utils.get_tripleo_ansible_inventory(
return_inventory_file_path=True)
except exceptions.InvalidConfiguration:
self.log.warning(
"Unable to generate the necessary ansible inventory required "
"to cleanup IPA. Ignoring IPA cleanup. Please cleanup IPA "
"resources for {} stack manually.".format(stack_name)
)
return
# We don't technically need remote_user to generate an ansible.cfg for
# stack. The write_default_ansible_cfg() method treats this as an