Overcloud export with ephemeral Heat

Update the overcloud export command to handle the exception when using
ephemeral Heat and the Heat endpoint does not exist. In that scenario,
the command will just copy the already generated export file from the
working directory for the stack to the location specified by
parsed_args.output_file.

Change-Id: I42d1ddf76db189fe55063ecc056b910e3886c679
Signed-off-by: James Slagle <jslagle@redhat.com>
This commit is contained in:
James Slagle 2021-07-16 08:16:04 -04:00
parent ec411b9329
commit 80c43280a8
2 changed files with 48 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import os
from unittest import mock
from keystoneauth1.exceptions.catalog import EndpointNotFound
from osc_lib.tests import utils
from tripleoclient.v1 import overcloud_export
@ -142,3 +143,21 @@ class TestOvercloudExport(utils.TestCommand):
'foo',
False,
'/tmp/bar')
@mock.patch('shutil.copy')
@mock.patch('os.path.exists')
@mock.patch('tripleoclient.utils.get_default_working_dir')
def test_export_ephemeral_heat(self, mock_working_dir, mock_exists,
mock_copy):
argslist = ['--force-overwrite']
verifylist = [('force_overwrite', True)]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
mock_exists.return_value = True
mock_working_dir.return_value = 'wd'
heat = self.app.client_manager.orchestration
heat.stacks.client.session.get_endpoint.side_effect = EndpointNotFound
with mock.patch('six.moves.builtins.open', self.mock_open):
self.cmd.take_action(parsed_args)
mock_working_dir.assert_called()
mock_copy.assert_called_with(
'wd/overcloud-export.yaml', 'overcloud-export.yaml')

View File

@ -13,13 +13,17 @@
from datetime import datetime
import logging
import os.path
import shutil
import sys
import yaml
from keystoneauth1.exceptions.catalog import EndpointNotFound
from osc_lib.i18n import _
from osc_lib import utils as osc_utils
from tripleoclient import command
from tripleoclient import export
from tripleoclient import utils
class ExportOvercloud(command.Command):
@ -86,7 +90,31 @@ class ExportOvercloud(command.Command):
# prepare clients to access the environment
clients = self.app.client_manager
heat = clients.orchestration
try:
heat = clients.orchestration
heat.stacks.client.session.get_endpoint(
service_type='orchestration')
except EndpointNotFound:
self.log.warning(
"Heat endpoint not found. When using ephemeral Heat, "
"the export file exists in the stack working directory "
"as $HOME/overlcoud-deploy/<stack>/<stack>-export.yaml. "
"(default). The existing export file will be copied "
"to {}".format(output_file))
export_file_path = os.path.join(
utils.get_default_working_dir(parsed_args.stack),
'{}-export.yaml'.format(parsed_args.stack))
if os.path.exists(export_file_path):
print(
"Export file found at {}, copying to {}.".format(
export_file_path, output_file))
shutil.copy(export_file_path, output_file)
else:
print("Export file not found at {}.".format(
export_file_path))
sys.exit(1)
return
data = export.export_overcloud(
heat, stack, excludes=not parsed_args.no_password_excludes,
should_filter=False, config_download_dir=config_download_dir)