From f7442c98b9b24a0cfc6110b0bde3a7ae7b512a61 Mon Sep 17 00:00:00 2001 From: Al Bailey Date: Mon, 16 May 2022 16:33:15 +0000 Subject: [PATCH] Debian: sw-patch cleanup and repair of old code - Assign 'system_mode' to 'simplex' when it is unknown. The system_mode is not set until after bootstrap. Without this change, it defaults to duplex. - Remove the Clean RPMS step from sw-patch init Debian does not use rpm, so this method can be removed. - Remove rpm-audit utility. Debian does not use rpm, so this utility can be removed. - Remove 'ID' as a 'required' field for make_test_patch since the utility has a default, and will not use an ID for some of its sub-commands. - Remove the SafeConfigParser workaround which is no longer needed in Debian env. - Add a fix for install-local so that the feed commit is not sent if the host has not been provisioned. Test Plan: Debian: Build / Bootstrap / Unlock / Reboot AIO-SX Verify logs clean Verify no patch alarms Verify make_test_patch prepare does not prompt for ID Story: 2009969 Task: 45409 Signed-off-by: Al Bailey Change-Id: I75ada6e262533d9c6477721836b6ecdf213c25dc --- sw-patch/bin/rpm-audit | 183 ------------------ sw-patch/bin/sw-patch-init.sh | 16 +- sw-patch/cgcs-patch/cgcs_patch/config.py | 27 +-- .../cgcs-patch/cgcs_patch/patch_controller.py | 5 + sw-patch/debian/deb_folder/cgcs-patch.install | 1 - sw-patch/debian/deb_folder/rules | 4 +- sw-patch/scripts/make_test_patch.py | 2 +- 7 files changed, 23 insertions(+), 215 deletions(-) delete mode 100755 sw-patch/bin/rpm-audit diff --git a/sw-patch/bin/rpm-audit b/sw-patch/bin/rpm-audit deleted file mode 100755 index 3ae2755c..00000000 --- a/sw-patch/bin/rpm-audit +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2016 Wind River Systems, Inc. -# -# SPDX-License-Identifier: Apache-2.0 -# - -if [[ $EUID -ne 0 ]]; then - echo "This utility must be run as root." >&2 - exit 1 -fi - -function show_usage() -{ - cat <> $logfile } @@ -86,13 +93,6 @@ if [ -f /etc/platform/installation_failed ] ; then exit 1 fi -# Clean up the RPM DB -if [ ! -f /var/run/.rpmdb_cleaned ]; then - LOG_TO_FILE "Cleaning RPM DB" - rm -f /var/lib/rpm/__db* - touch /var/run/.rpmdb_cleaned -fi - # For AIO-SX, abort if config is not yet applied and this is running in init if [ "${system_mode}" = "simplex" -a ! -f ${INITIAL_CONTROLLER_CONFIG_COMPLETE} -a "$1" = "start" ]; then LOG_TO_FILE "Config is not yet applied. Skipping init patching" @@ -106,8 +106,10 @@ DELAY_SEC=120 START=`date +%s` FOUND=0 while [ $(date +%s) -lt $(( ${START} + ${DELAY_SEC} )) ]; do + LOG_TO_FILE "Waiting for controller to be pingable" ping -c 1 controller > /dev/null 2>&1 || ping6 -c 1 controller > /dev/null 2>&1 if [ $? -eq 0 ]; then + LOG_TO_FILE "controller is pingable" FOUND=1 break fi diff --git a/sw-patch/cgcs-patch/cgcs_patch/config.py b/sw-patch/cgcs-patch/cgcs_patch/config.py index 1eb5bdcd..0a7d4d5f 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/config.py +++ b/sw-patch/cgcs-patch/cgcs_patch/config.py @@ -4,16 +4,16 @@ Copyright (c) 2014-2022 Wind River Systems, Inc. SPDX-License-Identifier: Apache-2.0 """ - -import os -import six -from six.moves import configparser import io import logging +import os +from six.moves import configparser import socket + +import tsconfig.tsconfig as tsc + import cgcs_patch.utils as utils import cgcs_patch.constants as constants -import tsconfig.tsconfig as tsc controller_mcast_group = None agent_mcast_group = None @@ -49,17 +49,7 @@ def read_config(): global controller_port global agent_port - # In python3 configparser uses strict mode by default. It doesn't - # agree duplicate keys, and will throw an error - # In python2 the strict argument is missing - # TODO(dsafta): the logic branching here can be removed once - # https://bugs.launchpad.net/starlingx/+bug/1931529 is fixed, allowing - # python3 parser to work in strict mode. - - if six.PY2: - config = configparser.SafeConfigParser(defaults) - elif six.PY3: - config = configparser.SafeConfigParser(defaults, strict=False) + config = configparser.SafeConfigParser(defaults) config.read(patching_conf) patching_conf_mtime = os.stat(patching_conf).st_mtime @@ -115,10 +105,7 @@ def get_mgmt_iface(): # so return the cached value. return mgmt_if - if six.PY2: - config = configparser.SafeConfigParser() - elif six.PY3: - config = configparser.SafeConfigParser(strict=False) + config = configparser.SafeConfigParser() # The platform.conf file has no section headers, which causes problems # for ConfigParser. So we'll fake it out. diff --git a/sw-patch/cgcs-patch/cgcs_patch/patch_controller.py b/sw-patch/cgcs-patch/cgcs_patch/patch_controller.py index 9f6946b0..63b1e75b 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/patch_controller.py +++ b/sw-patch/cgcs-patch/cgcs_patch/patch_controller.py @@ -1555,6 +1555,11 @@ class PatchController(PatchService): Notify the patch agent that the latest commit on the feed repo has been updated """ + # Skip sending messages if host not yet provisioned + if self.sock_out is None: + LOG.info("Skipping send feed commit to agent") + return + send_commit_to_agent = PatchMessageSendLatestFeedCommit() self.socket_lock.acquire() send_commit_to_agent.send(self.sock_out) diff --git a/sw-patch/debian/deb_folder/cgcs-patch.install b/sw-patch/debian/deb_folder/cgcs-patch.install index 6329f142..2c5ea99e 100644 --- a/sw-patch/debian/deb_folder/cgcs-patch.install +++ b/sw-patch/debian/deb_folder/cgcs-patch.install @@ -1,4 +1,3 @@ -usr/sbin/rpm-audit etc/patching/policy.json etc/patching/patching.conf etc/patching/patch-functions diff --git a/sw-patch/debian/deb_folder/rules b/sw-patch/debian/deb_folder/rules index c8d126ba..4bebe172 100755 --- a/sw-patch/debian/deb_folder/rules +++ b/sw-patch/debian/deb_folder/rules @@ -31,8 +31,6 @@ override_dh_install: ${DEBIAN_DESTDIR}/usr/sbin/sw-patch-controller-daemon install -m 555 bin/sw-patch \ ${DEBIAN_DESTDIR}/usr/sbin/sw-patch - install -m 555 bin/rpm-audit \ - ${DEBIAN_DESTDIR}/usr/sbin/rpm-audit install -m 500 bin/sw-patch-controller-daemon-init.sh \ ${DEBIAN_DESTDIR}/etc/init.d/sw-patch-controller-daemon install -m 500 bin/sw-patch-agent-init.sh \ @@ -73,6 +71,6 @@ override_dh_python3: dh_python3 --shebang=/usr/bin/python3 override_dh_fixperms: - dh_fixperms -Xsw-patch-* -Xrpm-audit -Xpatching.conf -Xpolicy.json \ + dh_fixperms -Xsw-patch-* -Xpatching.conf -Xpolicy.json \ -Xpatch-functions -Xpatch-tmpdirs.conf -Xrun-patch-scripts \ -Xpatch_check_goenabled.sh -Xpatching -Xupgrade-start-pkg-extract diff --git a/sw-patch/scripts/make_test_patch.py b/sw-patch/scripts/make_test_patch.py index 57bf52ed..f115d786 100755 --- a/sw-patch/scripts/make_test_patch.py +++ b/sw-patch/scripts/make_test_patch.py @@ -335,7 +335,7 @@ if __name__ == "__main__": parser.add_argument('-c', '--create', action='store_true', help='Create patch, should be executed after changes are done to the environment') parser.add_argument('-i', '--id', type=str, - help='Patch ID', default='PATCH_0001', required=True) + help='Patch ID', default='PATCH_0001') parser.add_argument('-cl', '--clean-mode', action='store_true', help='Whether to clean the delta directory automatically')