Debian: Fix patch controller prior to bootstrap

If /etc/resolv.conf is empty  the patch controller
will raise an uncaught exception due to osprofiler
attempting to validate dns.

osprofiler is unused by patching, so the module is
disabled by the patch controller.

All sw-patch CLI commands will fail prior to
setting up resolv.conf (bootstrapping) without this
fix, since there is no working patch controller

sysinv.common.utils also pulls in dns, so the two
utility methods are cloned into patching repo.

Test Plan:
 PASS Build/Install AIO-SX Debian
 PASS upload a patch

Story: 2009969
Task: 45838
Signed-off-by: Al Bailey <al.bailey@windriver.com>
Change-Id: I0975f5b54a17a0989a78f6ac39160af0b3e26013
This commit is contained in:
Al Bailey 2022-07-20 17:23:45 +00:00
parent 3d0d3566c7
commit 70afae2b0e
5 changed files with 61 additions and 20 deletions

View File

@ -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__":

View File

@ -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):

View File

@ -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):

View File

@ -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 = {}

View File

@ -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
try:
# Python3
from socket import if_nametoindex as if_nametoindex_func
except ImportError:
# Python2
import ctypes
import ctypes.util
libc = ctypes.CDLL(ctypes.util.find_library('c'))
if_nametoindex_func = libc.if_nametoindex
import cgcs_patch.constants as constants
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