From e97d88602eb7e835afe4328edfd2554ee28dfc6c Mon Sep 17 00:00:00 2001 From: rabi Date: Wed, 22 Jun 2022 14:07:36 +0530 Subject: [PATCH] Fix upgrade/external_update/external_upgrade These commands still reference heat stack which does not exist. Also fixes missing option extra_vars. Deprecates --static-inventory option, as the inventory can't be generated without stack. If required users have to run `update/upgrade prepare` to generate it which would be in working_dir. Change-Id: Ibaa42fa7ac6ebb7212dd19997bd6d01541be988c (cherry picked from commit 6d18e27d28a93da87d3db9080d13cb0d624cd06f) --- ...tic-inventory-option-4342b01aebaa4af8.yaml | 6 ++ tripleoclient/command.py | 24 ------ tripleoclient/v1/overcloud_external_update.py | 84 +++++++------------ .../v1/overcloud_external_upgrade.py | 47 ++++++----- tripleoclient/v1/overcloud_update.py | 13 +-- tripleoclient/v1/overcloud_upgrade.py | 40 ++++----- 6 files changed, 79 insertions(+), 135 deletions(-) create mode 100644 releasenotes/notes/deprecate-static-inventory-option-4342b01aebaa4af8.yaml diff --git a/releasenotes/notes/deprecate-static-inventory-option-4342b01aebaa4af8.yaml b/releasenotes/notes/deprecate-static-inventory-option-4342b01aebaa4af8.yaml new file mode 100644 index 000000000..7aa1cba4c --- /dev/null +++ b/releasenotes/notes/deprecate-static-inventory-option-4342b01aebaa4af8.yaml @@ -0,0 +1,6 @@ +--- +deprecations: + - | + The --static-inventory argument to the openstack update/upgrade commands + has been deprecated and would be ignored. The inventory generated in + work_dir with update/upgrade prepare would be used instead. diff --git a/tripleoclient/command.py b/tripleoclient/command.py index 8a32c9a28..9267c1868 100644 --- a/tripleoclient/command.py +++ b/tripleoclient/command.py @@ -18,8 +18,6 @@ import logging from osc_lib.command import command from osc_lib import exceptions as oscexc -from tripleo_common.utils import config - from tripleoclient import exceptions from tripleoclient import utils @@ -38,28 +36,6 @@ class Command(command.Command): self.log.exception("Exception occured while running the command") raise - @staticmethod - def get_ansible_key_and_dir(stack, orchestration): - """Return the ansible directory and key path. - - :oaram stack: Name of a given stack to run against. - :type stack: String - - :param orchestration: Orchestration client object. - :type orchestration: Object - - :returns: Tuple - """ - key = utils.get_key(stack=stack) - stack_config = config.Config(orchestration) - with utils.TempDirs(chdir=False) as tmp: - stack_config.write_config( - stack_config.fetch_config(stack), - stack, - tmp - ) - return key, tmp - def get_key_pair(self, parsed_args): """Autodetect or return a user defined key file. diff --git a/tripleoclient/v1/overcloud_external_update.py b/tripleoclient/v1/overcloud_external_update.py index 8a23a1cad..b91af3af4 100644 --- a/tripleoclient/v1/overcloud_external_update.py +++ b/tripleoclient/v1/overcloud_external_update.py @@ -50,10 +50,8 @@ class ExternalUpdateRun(command.Command): dest='static_inventory', action="store", default=None, - help=_('Path to an existing ansible inventory to ' - 'use. If not specified, one will be ' - 'generated in ' - '~/tripleo-ansible-inventory.yaml') + help=_('DEPRECATED: tripleo-ansible-inventory.yaml' + ' in working dir will be used.') ) parser.add_argument("--ssh-user", dest="ssh_user", @@ -114,7 +112,9 @@ class ExternalUpdateRun(command.Command): parser.add_argument( '--refresh', action='store_true', - help=_('Refresh the config-download playbooks') + help=_('DEPRECATED: Refresh the config-download playbooks.' + 'Use `overcloud update prepare` instead to refresh ' + 'playbooks.') ) return parser @@ -130,56 +130,28 @@ class ExternalUpdateRun(command.Command): constants.UPDATE_PROMPT, self.log)): raise OvercloudUpdateNotConfirmed(constants.UPDATE_NO) - if parsed_args.refresh: - _, ansible_dir = self.get_ansible_key_and_dir( - stack=parsed_args.stack, - orchestration=self.app.client_manager.orchestration - ) - deployment.config_download( - log=self.log, - clients=self.app.client_manager, - stack_name=parsed_args.stack, - output_dir=ansible_dir, - verbosity=oooutils.playbook_verbosity(self=self), - ansible_playbook_name=constants.EXTERNAL_UPDATE_PLAYBOOKS, - extra_vars=oooutils.parse_extra_vars( - extra_var_strings=parsed_args.extra_vars - ), - inventory_path=oooutils.get_tripleo_ansible_inventory( - parsed_args.static_inventory, - parsed_args.ssh_user, - parsed_args.stack, - return_inventory_file_path=True - ), - tags=parsed_args.tags, - skip_tags=parsed_args.skip_tags, - limit_hosts=oooutils.playbook_limit_parse( - limit_nodes=parsed_args.limit - ), - forks=parsed_args.ansible_forks - ) - else: - working_dir = oooutils.get_default_working_dir(parsed_args.stack) - config_download_dir = os.path.join(working_dir, 'config-download') - ansible_dir = os.path.join(config_download_dir, parsed_args.stack) - inventory_path = os.path.join(ansible_dir, - 'tripleo-ansible-inventory.yaml') - key = oooutils.get_key(parsed_args.stack) - playbooks = [os.path.join(ansible_dir, p) - for p in constants.EXTERNAL_UPDATE_PLAYBOOKS] - oooutils.run_ansible_playbook( - playbook=playbooks, - inventory=inventory_path, - workdir=config_download_dir, - tags=parsed_args.tags, - skip_tags=parsed_args.skip_tags, - limit_hosts=oooutils.playbook_limit_parse( - limit_nodes=parsed_args.limit - ), - forks=parsed_args.ansible_forks, - key=key, - reproduce_command=True - ) - deployment.snapshot_dir(ansible_dir) + working_dir = oooutils.get_default_working_dir(parsed_args.stack) + config_download_dir = os.path.join(working_dir, 'config-download') + ansible_dir = os.path.join(config_download_dir, parsed_args.stack) + inventory_path = os.path.join(ansible_dir, + 'tripleo-ansible-inventory.yaml') + key = oooutils.get_key(parsed_args.stack) + playbooks = [os.path.join(ansible_dir, p) + for p in constants.EXTERNAL_UPDATE_PLAYBOOKS] + oooutils.run_ansible_playbook( + playbook=playbooks, + inventory=inventory_path, + workdir=config_download_dir, + tags=parsed_args.tags, + extra_vars=parsed_args.extra_vars, + skip_tags=parsed_args.skip_tags, + limit_hosts=oooutils.playbook_limit_parse( + limit_nodes=parsed_args.limit + ), + forks=parsed_args.ansible_forks, + key=key, + reproduce_command=True + ) + deployment.snapshot_dir(ansible_dir) self.log.info("Completed Overcloud External Update Run.") diff --git a/tripleoclient/v1/overcloud_external_upgrade.py b/tripleoclient/v1/overcloud_external_upgrade.py index 41fd4adde..fab536adb 100644 --- a/tripleoclient/v1/overcloud_external_upgrade.py +++ b/tripleoclient/v1/overcloud_external_upgrade.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. # +import os + from oslo_config import cfg from oslo_log import log as logging @@ -47,10 +49,8 @@ class ExternalUpgradeRun(command.Command): dest='static_inventory', action="store", default=None, - help=_('Path to an existing ansible inventory to ' - 'use. If not specified, one will be ' - 'generated in ' - '~/tripleo-ansible-inventory.yaml') + help=_('DEPRECATED: tripleo-ansible-inventory.yaml' + ' in working dir will be used.') ) parser.add_argument("--ssh-user", dest="ssh_user", @@ -123,27 +123,28 @@ class ExternalUpgradeRun(command.Command): constants.UPGRADE_PROMPT, self.log)): raise OvercloudUpgradeNotConfirmed(constants.UPGRADE_NO) - _, ansible_dir = self.get_ansible_key_and_dir( - stack=parsed_args.stack, - orchestration=self.app.client_manager.orchestration - ) - deployment.config_download( - log=self.log, - clients=self.app.client_manager, - stack_name=parsed_args.stack, - output_dir=ansible_dir, - verbosity=oooutils.playbook_verbosity(self=self), - ansible_playbook_name=constants.EXTERNAL_UPGRADE_PLAYBOOKS, - inventory_path=oooutils.get_tripleo_ansible_inventory( - parsed_args.static_inventory, - parsed_args.ssh_user, - parsed_args.stack, - return_inventory_file_path=True - ), + working_dir = oooutils.get_default_working_dir(parsed_args.stack) + config_download_dir = os.path.join(working_dir, 'config-download') + ansible_dir = os.path.join(config_download_dir, parsed_args.stack) + inventory_path = os.path.join(ansible_dir, + 'tripleo-ansible-inventory.yaml') + key = oooutils.get_key(parsed_args.stack) + playbooks = [os.path.join(ansible_dir, p) + for p in constants.EXTERNAL_UPGRADE_PLAYBOOKS] + oooutils.run_ansible_playbook( + playbook=playbooks, + inventory=inventory_path, + workdir=config_download_dir, tags=parsed_args.tags, skip_tags=parsed_args.skip_tags, + extra_vars=parsed_args.extra_vars, limit_hosts=oooutils.playbook_limit_parse( - limit_nodes=parsed_args.limit), - forks=parsed_args.ansible_forks + limit_nodes=parsed_args.limit + ), + forks=parsed_args.ansible_forks, + key=key, + reproduce_command=True ) + + deployment.snapshot_dir(ansible_dir) self.log.info("Completed Overcloud External Upgrade Run.") diff --git a/tripleoclient/v1/overcloud_update.py b/tripleoclient/v1/overcloud_update.py index 01f8add21..2d5c8ea04 100644 --- a/tripleoclient/v1/overcloud_update.py +++ b/tripleoclient/v1/overcloud_update.py @@ -119,10 +119,8 @@ class UpdateRun(command.Command): dest='static_inventory', action="store", default=None, - help=_('Path to an existing ansible inventory to ' - 'use. If not specified, one will be ' - 'generated in ' - '~/tripleo-ansible-inventory.yaml') + help=_('DEPRECATED: tripleo-ansible-inventory.yaml' + ' in working dir will be used.') ) parser.add_argument('--stack', dest='stack', help=_('Name or ID of heat stack ' @@ -185,12 +183,7 @@ class UpdateRun(command.Command): 'config-download', parsed_args.stack) - if not parsed_args.static_inventory: - inventory = os.path.join(ansible_dir, - 'tripleo-ansible-inventory.yaml') - else: - inventory = parsed_args.static_inventory - + inventory = os.path.join(ansible_dir, 'tripleo-ansible-inventory.yaml') ansible_cfg = os.path.join(ansible_dir, 'ansible.cfg') key_file = oooutils.get_key(parsed_args.stack) diff --git a/tripleoclient/v1/overcloud_upgrade.py b/tripleoclient/v1/overcloud_upgrade.py index 9b04709e6..1bcad04f5 100644 --- a/tripleoclient/v1/overcloud_upgrade.py +++ b/tripleoclient/v1/overcloud_upgrade.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. # +import os + from oslo_config import cfg from oslo_log import log as logging @@ -147,10 +149,8 @@ class UpgradeRun(command.Command): dest='static_inventory', action="store", default=None, - help=_('Path to an existing ansible inventory to ' - 'use. If not specified, one will be ' - 'generated in ' - '~/tripleo-ansible-inventory.yaml') + help=_('DEPRECATED: tripleo-ansible-inventory.yaml' + ' in working dir will be used.') ) parser.add_argument("--ssh-user", dest="ssh_user", @@ -222,30 +222,26 @@ class UpgradeRun(command.Command): else: playbook = parsed_args.playbook - _, ansible_dir = self.get_ansible_key_and_dir( - stack=parsed_args.stack, - orchestration=self.app.client_manager.orchestration - ) - deployment.config_download( - log=self.log, - clients=self.app.client_manager, - stack_name=parsed_args.stack, - output_dir=ansible_dir, - verbosity=oooutils.playbook_verbosity(self=self), - ansible_playbook_name=playbook, - inventory_path=oooutils.get_tripleo_ansible_inventory( - parsed_args.static_inventory, - parsed_args.ssh_user, - parsed_args.stack, - return_inventory_file_path=True - ), + working_dir = oooutils.get_default_working_dir(parsed_args.stack) + config_download_dir = os.path.join(working_dir, 'config-download') + ansible_dir = os.path.join(config_download_dir, parsed_args.stack) + inventory_path = os.path.join(ansible_dir, + 'tripleo-ansible-inventory.yaml') + key = oooutils.get_key(parsed_args.stack) + oooutils.run_ansible_playbook( + playbook=playbook, + inventory=inventory_path, + workdir=config_download_dir, tags=parsed_args.tags, skip_tags=parsed_args.skip_tags, limit_hosts=oooutils.playbook_limit_parse( limit_nodes=parsed_args.limit ), - forks=parsed_args.ansible_forks + forks=parsed_args.ansible_forks, + key=key, + reproduce_command=True ) + deployment.snapshot_dir(ansible_dir) self.log.info("Completed Overcloud Major Upgrade Run.")