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 6d18e27d28)
This commit is contained in:
rabi 2022-06-22 14:07:36 +05:30 committed by Rabi Mishra
parent d451aaa291
commit e97d88602e
6 changed files with 79 additions and 135 deletions

View File

@ -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.

View File

@ -18,8 +18,6 @@ import logging
from osc_lib.command import command from osc_lib.command import command
from osc_lib import exceptions as oscexc from osc_lib import exceptions as oscexc
from tripleo_common.utils import config
from tripleoclient import exceptions from tripleoclient import exceptions
from tripleoclient import utils from tripleoclient import utils
@ -38,28 +36,6 @@ class Command(command.Command):
self.log.exception("Exception occured while running the command") self.log.exception("Exception occured while running the command")
raise 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): def get_key_pair(self, parsed_args):
"""Autodetect or return a user defined key file. """Autodetect or return a user defined key file.

View File

@ -50,10 +50,8 @@ class ExternalUpdateRun(command.Command):
dest='static_inventory', dest='static_inventory',
action="store", action="store",
default=None, default=None,
help=_('Path to an existing ansible inventory to ' help=_('DEPRECATED: tripleo-ansible-inventory.yaml'
'use. If not specified, one will be ' ' in working dir will be used.')
'generated in '
'~/tripleo-ansible-inventory.yaml')
) )
parser.add_argument("--ssh-user", parser.add_argument("--ssh-user",
dest="ssh_user", dest="ssh_user",
@ -114,7 +112,9 @@ class ExternalUpdateRun(command.Command):
parser.add_argument( parser.add_argument(
'--refresh', '--refresh',
action='store_true', 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 return parser
@ -130,35 +130,6 @@ class ExternalUpdateRun(command.Command):
constants.UPDATE_PROMPT, self.log)): constants.UPDATE_PROMPT, self.log)):
raise OvercloudUpdateNotConfirmed(constants.UPDATE_NO) 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) working_dir = oooutils.get_default_working_dir(parsed_args.stack)
config_download_dir = os.path.join(working_dir, 'config-download') config_download_dir = os.path.join(working_dir, 'config-download')
ansible_dir = os.path.join(config_download_dir, parsed_args.stack) ansible_dir = os.path.join(config_download_dir, parsed_args.stack)
@ -172,6 +143,7 @@ class ExternalUpdateRun(command.Command):
inventory=inventory_path, inventory=inventory_path,
workdir=config_download_dir, workdir=config_download_dir,
tags=parsed_args.tags, tags=parsed_args.tags,
extra_vars=parsed_args.extra_vars,
skip_tags=parsed_args.skip_tags, skip_tags=parsed_args.skip_tags,
limit_hosts=oooutils.playbook_limit_parse( limit_hosts=oooutils.playbook_limit_parse(
limit_nodes=parsed_args.limit limit_nodes=parsed_args.limit
@ -180,6 +152,6 @@ class ExternalUpdateRun(command.Command):
key=key, key=key,
reproduce_command=True reproduce_command=True
) )
deployment.snapshot_dir(ansible_dir)
deployment.snapshot_dir(ansible_dir)
self.log.info("Completed Overcloud External Update Run.") self.log.info("Completed Overcloud External Update Run.")

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
import os
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -47,10 +49,8 @@ class ExternalUpgradeRun(command.Command):
dest='static_inventory', dest='static_inventory',
action="store", action="store",
default=None, default=None,
help=_('Path to an existing ansible inventory to ' help=_('DEPRECATED: tripleo-ansible-inventory.yaml'
'use. If not specified, one will be ' ' in working dir will be used.')
'generated in '
'~/tripleo-ansible-inventory.yaml')
) )
parser.add_argument("--ssh-user", parser.add_argument("--ssh-user",
dest="ssh_user", dest="ssh_user",
@ -123,27 +123,28 @@ class ExternalUpgradeRun(command.Command):
constants.UPGRADE_PROMPT, self.log)): constants.UPGRADE_PROMPT, self.log)):
raise OvercloudUpgradeNotConfirmed(constants.UPGRADE_NO) raise OvercloudUpgradeNotConfirmed(constants.UPGRADE_NO)
_, ansible_dir = self.get_ansible_key_and_dir( working_dir = oooutils.get_default_working_dir(parsed_args.stack)
stack=parsed_args.stack, config_download_dir = os.path.join(working_dir, 'config-download')
orchestration=self.app.client_manager.orchestration ansible_dir = os.path.join(config_download_dir, parsed_args.stack)
) inventory_path = os.path.join(ansible_dir,
deployment.config_download( 'tripleo-ansible-inventory.yaml')
log=self.log, key = oooutils.get_key(parsed_args.stack)
clients=self.app.client_manager, playbooks = [os.path.join(ansible_dir, p)
stack_name=parsed_args.stack, for p in constants.EXTERNAL_UPGRADE_PLAYBOOKS]
output_dir=ansible_dir, oooutils.run_ansible_playbook(
verbosity=oooutils.playbook_verbosity(self=self), playbook=playbooks,
ansible_playbook_name=constants.EXTERNAL_UPGRADE_PLAYBOOKS, inventory=inventory_path,
inventory_path=oooutils.get_tripleo_ansible_inventory( workdir=config_download_dir,
parsed_args.static_inventory,
parsed_args.ssh_user,
parsed_args.stack,
return_inventory_file_path=True
),
tags=parsed_args.tags, tags=parsed_args.tags,
skip_tags=parsed_args.skip_tags, skip_tags=parsed_args.skip_tags,
extra_vars=parsed_args.extra_vars,
limit_hosts=oooutils.playbook_limit_parse( limit_hosts=oooutils.playbook_limit_parse(
limit_nodes=parsed_args.limit), 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 External Upgrade Run.") self.log.info("Completed Overcloud External Upgrade Run.")

View File

@ -119,10 +119,8 @@ class UpdateRun(command.Command):
dest='static_inventory', dest='static_inventory',
action="store", action="store",
default=None, default=None,
help=_('Path to an existing ansible inventory to ' help=_('DEPRECATED: tripleo-ansible-inventory.yaml'
'use. If not specified, one will be ' ' in working dir will be used.')
'generated in '
'~/tripleo-ansible-inventory.yaml')
) )
parser.add_argument('--stack', dest='stack', parser.add_argument('--stack', dest='stack',
help=_('Name or ID of heat stack ' help=_('Name or ID of heat stack '
@ -185,12 +183,7 @@ class UpdateRun(command.Command):
'config-download', 'config-download',
parsed_args.stack) parsed_args.stack)
if not parsed_args.static_inventory: inventory = os.path.join(ansible_dir, 'tripleo-ansible-inventory.yaml')
inventory = os.path.join(ansible_dir,
'tripleo-ansible-inventory.yaml')
else:
inventory = parsed_args.static_inventory
ansible_cfg = os.path.join(ansible_dir, 'ansible.cfg') ansible_cfg = os.path.join(ansible_dir, 'ansible.cfg')
key_file = oooutils.get_key(parsed_args.stack) key_file = oooutils.get_key(parsed_args.stack)

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
import os
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -147,10 +149,8 @@ class UpgradeRun(command.Command):
dest='static_inventory', dest='static_inventory',
action="store", action="store",
default=None, default=None,
help=_('Path to an existing ansible inventory to ' help=_('DEPRECATED: tripleo-ansible-inventory.yaml'
'use. If not specified, one will be ' ' in working dir will be used.')
'generated in '
'~/tripleo-ansible-inventory.yaml')
) )
parser.add_argument("--ssh-user", parser.add_argument("--ssh-user",
dest="ssh_user", dest="ssh_user",
@ -222,30 +222,26 @@ class UpgradeRun(command.Command):
else: else:
playbook = parsed_args.playbook playbook = parsed_args.playbook
_, ansible_dir = self.get_ansible_key_and_dir( working_dir = oooutils.get_default_working_dir(parsed_args.stack)
stack=parsed_args.stack, config_download_dir = os.path.join(working_dir, 'config-download')
orchestration=self.app.client_manager.orchestration ansible_dir = os.path.join(config_download_dir, parsed_args.stack)
) inventory_path = os.path.join(ansible_dir,
deployment.config_download( 'tripleo-ansible-inventory.yaml')
log=self.log, key = oooutils.get_key(parsed_args.stack)
clients=self.app.client_manager, oooutils.run_ansible_playbook(
stack_name=parsed_args.stack, playbook=playbook,
output_dir=ansible_dir, inventory=inventory_path,
verbosity=oooutils.playbook_verbosity(self=self), workdir=config_download_dir,
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
),
tags=parsed_args.tags, tags=parsed_args.tags,
skip_tags=parsed_args.skip_tags, skip_tags=parsed_args.skip_tags,
limit_hosts=oooutils.playbook_limit_parse( limit_hosts=oooutils.playbook_limit_parse(
limit_nodes=parsed_args.limit 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.") self.log.info("Completed Overcloud Major Upgrade Run.")