diff --git a/sw-patch/bin/sw-patch-controller-daemon b/sw-patch/bin/sw-patch-controller-daemon index 5c0f0a8c..61add52d 100755 --- a/sw-patch/bin/sw-patch-controller-daemon +++ b/sw-patch/bin/sw-patch-controller-daemon @@ -1,7 +1,7 @@ #!/usr/bin/python """ -Copyright (c) 2014 Wind River Systems, Inc. +Copyright (c) 2014-2022 Wind River Systems, Inc. SPDX-License-Identifier: Apache-2.0 @@ -9,6 +9,9 @@ SPDX-License-Identifier: Apache-2.0 import sys +# prevent patch_controller from importing osprofiler +sys.modules['osprofiler'] = None + from cgcs_patch.patch_controller import main if __name__ == "__main__": diff --git a/sw-patch/cgcs-patch/cgcs_patch/authapi/auth_token.py b/sw-patch/cgcs-patch/cgcs_patch/authapi/auth_token.py index 8b375fc4..ada2c1d3 100755 --- a/sw-patch/cgcs-patch/cgcs_patch/authapi/auth_token.py +++ b/sw-patch/cgcs-patch/cgcs_patch/authapi/auth_token.py @@ -11,9 +11,13 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +# +# Copyright (c) 2022 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# from keystonemiddleware import auth_token -from sysinv.common import utils +from cgcs_patch import utils class AuthTokenMiddleware(auth_token.AuthProtocol): diff --git a/sw-patch/cgcs-patch/cgcs_patch/authapi/hooks.py b/sw-patch/cgcs-patch/cgcs_patch/authapi/hooks.py index d3147dc6..e7434ac4 100755 --- a/sw-patch/cgcs-patch/cgcs_patch/authapi/hooks.py +++ b/sw-patch/cgcs-patch/cgcs_patch/authapi/hooks.py @@ -18,15 +18,16 @@ # # Copyright (c) 2013-2022 Wind River Systems, Inc. # - - +# SPDX-License-Identifier: Apache-2.0 +# from oslo_config import cfg from pecan import hooks +from webob import exc from sysinv.common import context -from sysinv.common import utils from sysinv.openstack.common import policy -from webob import exc + +from cgcs_patch import utils class ConfigHook(hooks.PecanHook): diff --git a/sw-patch/cgcs-patch/cgcs_patch/authapi/policy.py b/sw-patch/cgcs-patch/cgcs_patch/authapi/policy.py index 285c6a16..cb529c5e 100755 --- a/sw-patch/cgcs-patch/cgcs_patch/authapi/policy.py +++ b/sw-patch/cgcs-patch/cgcs_patch/authapi/policy.py @@ -22,9 +22,10 @@ import os.path from sysinv.common import exception -from sysinv.common import utils from sysinv.openstack.common import policy +from cgcs_patch import utils + _POLICY_PATH = None _POLICY_CACHE = {} diff --git a/sw-patch/cgcs-patch/cgcs_patch/utils.py b/sw-patch/cgcs-patch/cgcs_patch/utils.py index c21167cc..340592fc 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/utils.py +++ b/sw-patch/cgcs-patch/cgcs_patch/utils.py @@ -1,24 +1,19 @@ """ -Copyright (c) 2016-2019 Wind River Systems, Inc. +Copyright (c) 2016-2022 Wind River Systems, Inc. SPDX-License-Identifier: Apache-2.0 """ - +import logging from netaddr import IPAddress -import cgcs_patch.constants as constants +import os import socket +from socket import if_nametoindex as if_nametoindex_func -try: - # Python3 - from socket import if_nametoindex as if_nametoindex_func -except ImportError: - # Python2 - import ctypes - import ctypes.util +import cgcs_patch.constants as constants - libc = ctypes.CDLL(ctypes.util.find_library('c')) - if_nametoindex_func = libc.if_nametoindex + +LOG = logging.getLogger('main_logger') def if_nametoindex(name): @@ -81,3 +76,40 @@ def ip_to_versioned_localhost(ip_address_string): return "::1" else: return "localhost" + + +def read_cached_file(filename, cache_info, reload_func=None): + """Read from a file if it has been modified. + + :param cache_info: dictionary to hold opaque cache. + :param reload_func: optional function to be called with data when + file is reloaded due to a modification. + + :returns: data from file + + """ + mtime = os.path.getmtime(filename) + if not cache_info or mtime != cache_info.get('mtime'): + LOG.debug("Reloading cached file %s", filename) + with open(filename) as fap: + cache_info['data'] = fap.read() + cache_info['mtime'] = mtime + if reload_func: + reload_func(cache_info['data']) + return cache_info['data'] + + +def safe_rstrip(value, chars=None): + """Removes trailing characters from a string if that does not make it empty + + :param value: A string value that will be stripped. + :param chars: Characters to remove. + :return: Stripped value. + + """ + if not isinstance(value, str): + LOG.warn("Failed to remove trailing character. Returning original " + "object. Supplied object is not a string: %s", value) + return value + + return value.rstrip(chars) or value