Merge "Fix update run to not run update on excluded nodes" into stable/zed

This commit is contained in:
Zuul 2023-03-24 23:23:02 +00:00 committed by Gerrit Code Review
commit bb858ea048
2 changed files with 61 additions and 4 deletions

View File

@ -210,6 +210,40 @@ def makedirs(dir_path):
return True
def compare_limit_nodes_with_excluded_hosts(limit_nodes, excluded_hosts):
"""Compare limit nodes list with excluded hosts list.
This will compare the limit nodes list with the excluded hosts list
and raise an Exception if there is a match to inform user that the
host is in both lists. If user marks a host in limit option as
excluded with exclamatory mark (!) then it will be ignored during
the comparison.
:param limit_hosts: list of hosts to limit the playbook to.
:type limit_hosts: `list`
:param excluded_hosts: list of hosts to exclude from the playbook.
:type excluded_hosts: `list`
:raises:
RuntimeError if there is a match between the limit nodes and the
excluded hosts.
"""
if limit_nodes and excluded_hosts:
matching_hosts_found = []
for limit_node in re.split(':', limit_nodes):
if not limit_node.startswith('!') and limit_node in \
excluded_hosts:
matching_hosts_found.append(limit_node)
if matching_hosts_found:
raise RuntimeError(
'Hosts {} are in both the limit nodes and the '
'excluded hosts list. Please remove it from one of '
'the lists.'.format(','.join(matching_hosts_found))
)
def playbook_limit_parse(limit_nodes):
"""Return a parsed string for limits.
@ -1012,6 +1046,11 @@ def get_excluded_ip_addresses(working_dir):
'BlacklistedIpAddresses', working_dir)
def get_excluded_hostnames(working_dir):
return get_stack_saved_output_item(
'BlacklistedHostnames', working_dir)
def get_role_net_ip_map(working_dir):
return get_stack_saved_output_item(
'RoleNetIpMap', working_dir)

View File

@ -95,9 +95,12 @@ class UpdateRun(command.Command):
action='store',
required=True,
help=_("A string that identifies a single node or comma-separated"
"list of nodes the config-download Ansible playbook "
"execution will be limited to. For example: --limit"
" \"compute-0,compute-1,compute-5\".")
" list of nodes the config-download Ansible playbook"
" execution will be limited to. For example: --limit"
" \"compute-0,compute-1,compute-5\". When"
" DeploymentServerBlacklist is defined, excluded_overcloud"
" group is added at the end of the string and nodes from"
" the group will be skipped during the execution.")
)
parser.add_argument('--playbook',
nargs="*",
@ -190,6 +193,19 @@ class UpdateRun(command.Command):
ansible_cfg = os.path.join(ansible_dir, 'ansible.cfg')
key_file = oooutils.get_key(parsed_args.stack)
limit_hosts = oooutils.playbook_limit_parse(parsed_args.limit)
excluded_hostnames = oooutils.get_excluded_hostnames(
oooutils.get_default_working_dir(
parsed_args.stack))
if any(excluded_hostname.strip() for excluded_hostname in
excluded_hostnames):
oooutils.compare_limit_nodes_with_excluded_hosts(
limit_nodes=limit_hosts, excluded_hosts=excluded_hostnames)
self.log.info("Excluded hostnames detected. Added"
" excluded_overcloud host group to --limit flag.")
limit_hosts += ':!excluded_overcloud'
oooutils.run_ansible_playbook(
playbook=playbook,
inventory=inventory,
@ -199,7 +215,9 @@ class UpdateRun(command.Command):
tags=parsed_args.tags,
ansible_cfg=ansible_cfg,
ssh_user='tripleo-admin',
limit_hosts=parsed_args.limit,
limit_hosts=oooutils.playbook_limit_parse(
limit_nodes=limit_hosts
),
reproduce_command=True,
forks=parsed_args.ansible_forks,
extra_env_variables={