Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.12] OCPBUGS-3340: Fix compatibility with ansible-core 2.13 #12424

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
@@ -1,7 +1,7 @@
[flake8]
# TODO: cleanup flake8 issues with utils/test/*
# bundled ansible modules are copied as-is, have their own standards
exclude=.tox,inventory,ini_file.py,seboolean.py,sysctl.py
exclude=.tox,inventory,ini_file.py,profile_tasks.py,seboolean.py,sysctl.py
max_line_length = 120
ignore = E501,T003
per-file-ignores =
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -8,7 +8,7 @@

# Add files or directories to the ignore list. They should be base names, not
# paths.
ignore=CVS,setup.py,ini_file.py,seboolean.py,sysctl.py
ignore=CVS,setup.py,ini_file.py,profile_tasks.py,seboolean.py,sysctl.py

# Pickle collected data for later comparisons.
persistent=no
Expand Down
2 changes: 1 addition & 1 deletion ansible.cfg
Expand Up @@ -21,7 +21,7 @@ gathering = smart
fact_caching = jsonfile
fact_caching_connection = $HOME/ansible/facts
fact_caching_timeout = 600
callback_whitelist = profile_tasks
callback_enabled = profile_tasks
inventory_ignore_extensions = secrets.py, .pyc, .cfg, .crt, .ini
# work around privilege escalation timeouts in ansible:
timeout = 30
Expand Down
4 changes: 2 additions & 2 deletions hack/update-ansible-modules.sh
Expand Up @@ -5,7 +5,7 @@ set -o nounset
set -o pipefail

ANSIBLE_POSIX_REPO="https://raw.githubusercontent.com/ansible-collections/ansible.posix"
ANSIBLE_POSIX_MODULES=(seboolean.py sysctl.py)
ANSIBLE_POSIX_MODULES=(callback/profile_tasks.py modules/seboolean.py modules/sysctl.py)
ANSIBLE_POSIX_VERSION=1.4.0

COMMUNITY_GENERAL_REPO="https://raw.githubusercontent.com/ansible-collections/community.general"
Expand All @@ -18,7 +18,7 @@ pushd ${srcdir}/roles/openshift_node/library

for ap in ${ANSIBLE_POSIX_MODULES[*]} ; do
echo "*** Updating ${ap##*/} from ${ANSIBLE_POSIX_REPO##*/} ${ANSIBLE_POSIX_VERSION}"
curl -sO ${ANSIBLE_POSIX_REPO}/${ANSIBLE_POSIX_VERSION}/plugins/modules/${ap}
curl -sO ${ANSIBLE_POSIX_REPO}/${ANSIBLE_POSIX_VERSION}/plugins/${ap}
done

for cg in ${COMMUNITY_GENERAL_MODULES[*]} ; do
Expand Down
2 changes: 1 addition & 1 deletion inventory/dynamic/aws/ansible.cfg
Expand Up @@ -23,7 +23,7 @@ gathering = smart
fact_caching = jsonfile
fact_caching_connection = $HOME/ansible/facts
fact_caching_timeout = 600
callback_whitelist = profile_tasks
callback_enabled = profile_tasks
inventory_ignore_extensions = secrets.py, .pyc, .cfg, .crt
# work around privilege escalation timeouts in ansible:
timeout = 30
Expand Down
2 changes: 1 addition & 1 deletion inventory/dynamic/azure/ansible.cfg
Expand Up @@ -21,7 +21,7 @@ gathering = smart
fact_caching = jsonfile
fact_caching_connection = $HOME/ansible/facts
fact_caching_timeout = 600
callback_whitelist = profile_tasks
callback_enabled = profile_tasks
inventory_ignore_extensions = secrets.py, .pyc, .cfg, .crt, .ini
# work around privilege escalation timeouts in ansible:
timeout = 30
Expand Down
2 changes: 1 addition & 1 deletion inventory/dynamic/gcp/ansible.cfg
Expand Up @@ -23,7 +23,7 @@ gathering = smart
fact_caching = jsonfile
fact_caching_connection = $HOME/ansible/facts
fact_caching_timeout = 600
callback_whitelist = profile_tasks
callback_enabled = profile_tasks
inventory_ignore_extensions = secrets.py, .pyc, .cfg, .crt
# work around privilege escalation timeouts in ansible:
timeout = 30
Expand Down
Expand Up @@ -21,7 +21,7 @@ def display(*args, **kwargs):


# Set to minimum required Ansible version
REQUIRED_VERSION = '2.9.5'
REQUIRED_VERSION = '2.12.2'
DESCRIPTION = "Supported versions: %s or newer" % REQUIRED_VERSION


Expand Down
2 changes: 1 addition & 1 deletion roles/openshift_node/library/oc_csr_approve.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python
"""oc_csr_approve module"""
# Copyright 2020 Red Hat, Inc. and/or its affiliates
# and other contributors as indicated by the @author tags.
Expand Down
201 changes: 201 additions & 0 deletions roles/openshift_node/library/profile_tasks.py
@@ -0,0 +1,201 @@
# (C) 2016, Joel, https://github.com/jjshoe
# (C) 2015, Tom Paine, <github@aioue.net>
# (C) 2014, Jharrod LaFon, @JharrodLaFon
# (C) 2012-2013, Michael DeHaan, <michael.dehaan@gmail.com>
# (C) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

DOCUMENTATION = '''
name: profile_tasks
type: aggregate
short_description: adds time information to tasks
description:
- Ansible callback plugin for timing individual tasks and overall execution time.
- "Mashup of 2 excellent original works: https://github.com/jlafon/ansible-profile,
https://github.com/junaid18183/ansible_home/blob/master/ansible_plugins/callback_plugins/timestamp.py.old"
- "Format: C(<task start timestamp> (<length of previous task>) <current elapsed playbook execution time>)"
- It also lists the top/bottom time consuming tasks in the summary (configurable)
- Before 2.4 only the environment variables were available for configuration.
requirements:
- whitelisting in configuration - see examples section below for details.
options:
output_limit:
description: Number of tasks to display in the summary
default: 20
env:
- name: PROFILE_TASKS_TASK_OUTPUT_LIMIT
ini:
- section: callback_profile_tasks
key: task_output_limit
sort_order:
description: Adjust the sorting output of summary tasks
choices: ['descending', 'ascending', 'none']
default: 'descending'
env:
- name: PROFILE_TASKS_SORT_ORDER
ini:
- section: callback_profile_tasks
key: sort_order
'''

EXAMPLES = '''
example: >
To enable, add this to your ansible.cfg file in the defaults block
[defaults]
callback_whitelist = ansible.posix.profile_tasks
sample output: >
#
# TASK: [ensure messaging security group exists] ********************************
# Thursday 11 June 2017 22:50:53 +0100 (0:00:00.721) 0:00:05.322 *********
# ok: [localhost]
#
# TASK: [ensure db security group exists] ***************************************
# Thursday 11 June 2017 22:50:54 +0100 (0:00:00.558) 0:00:05.880 *********
# changed: [localhost]
#
'''

import collections
import time

from ansible.module_utils.six.moves import reduce
from ansible.plugins.callback import CallbackBase


# define start time
t0 = tn = time.time()


def secondsToStr(t):
# http://bytes.com/topic/python/answers/635958-handy-short-cut-formatting-elapsed-time-floating-point-seconds
def rediv(ll, b):
return list(divmod(ll[0], b)) + ll[1:]

return "%d:%02d:%02d.%03d" % tuple(reduce(rediv, [[t * 1000, ], 1000, 60, 60]))


def filled(msg, fchar="*"):
if len(msg) == 0:
width = 79
else:
msg = "%s " % msg
width = 79 - len(msg)
if width < 3:
width = 3
filler = fchar * width
return "%s%s " % (msg, filler)


def timestamp(self):
if self.current is not None:
elapsed = time.time() - self.stats[self.current]['started']
self.stats[self.current]['elapsed'] += elapsed


def tasktime():
global tn
time_current = time.strftime('%A %d %B %Y %H:%M:%S %z')
time_elapsed = secondsToStr(time.time() - tn)
time_total_elapsed = secondsToStr(time.time() - t0)
tn = time.time()
return filled('%s (%s)%s%s' % (time_current, time_elapsed, ' ' * 7, time_total_elapsed))


class CallbackModule(CallbackBase):
"""
This callback module provides per-task timing, ongoing playbook elapsed time
and ordered list of top 20 longest running tasks at end.
"""
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'aggregate'
CALLBACK_NAME = 'ansible.posix.profile_tasks'
CALLBACK_NEEDS_WHITELIST = True

def __init__(self):
self.stats = collections.OrderedDict()
self.current = None

self.sort_order = None
self.task_output_limit = None

super(CallbackModule, self).__init__()

def set_options(self, task_keys=None, var_options=None, direct=None):

super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)

self.sort_order = self.get_option('sort_order')
if self.sort_order is not None:
if self.sort_order == 'ascending':
self.sort_order = False
elif self.sort_order == 'descending':
self.sort_order = True
elif self.sort_order == 'none':
self.sort_order = None

self.task_output_limit = self.get_option('output_limit')
if self.task_output_limit is not None:
if self.task_output_limit == 'all':
self.task_output_limit = None
else:
self.task_output_limit = int(self.task_output_limit)

def _record_task(self, task):
"""
Logs the start of each task
"""
self._display.display(tasktime())
timestamp(self)

# Record the start time of the current task
# stats[TASK_UUID]:
# started: Current task start time. This value will be updated each time a task
# with the same UUID is executed when `serial` is specified in a playbook.
# elapsed: Elapsed time since the first serialized task was started
self.current = task._uuid
if self.current not in self.stats:
self.stats[self.current] = {'started': time.time(), 'elapsed': 0.0, 'name': task.get_name()}
else:
self.stats[self.current]['started'] = time.time()
if self._display.verbosity >= 2:
self.stats[self.current]['path'] = task.get_path()

def v2_playbook_on_task_start(self, task, is_conditional):
self._record_task(task)

def v2_playbook_on_handler_task_start(self, task):
self._record_task(task)

def playbook_on_setup(self):
self._display.display(tasktime())

def playbook_on_stats(self, stats):
self._display.display(tasktime())
self._display.display(filled("", fchar="="))

timestamp(self)
self.current = None

results = list(self.stats.items())

# Sort the tasks by the specified sort
if self.sort_order is not None:
results = sorted(
self.stats.items(),
key=lambda x: x[1]['elapsed'],
reverse=self.sort_order,
)

# Display the number of tasks specified or the default of 20
results = list(results)[:self.task_output_limit]

# Print the timings
for uuid, result in results:
msg = u"{0:-<{2}}{1:->9}".format(result['name'] + u' ', u' {0:.02f}s'.format(result['elapsed']), self._display.columns - 9)
if 'path' in result:
msg += u"\n{0:-<{1}}".format(result['path'] + u' ', self._display.columns)
self._display.display(msg)
2 changes: 1 addition & 1 deletion roles/openshift_node/library/swapoff.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/python
# pylint: disable=missing-docstring
#
# Copyright 2017 Red Hat, Inc. and/or its affiliates
Expand Down