Merge "Fix upgrade/external_update/external_upgrade"

This commit is contained in:
Zuul 2022-06-28 19:55:45 +00:00 committed by Gerrit Code Review
commit d219b5d91c
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 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.

View File

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

View File

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

View File

@ -122,10 +122,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 '
@ -188,12 +186,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)

View File

@ -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
@ -150,10 +152,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",
@ -225,28 +225,24 @@ 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.")