Add script to refresh deploy plug-in post patching

Utility script is created to update deploy plug-in automatically
post patching. This involves:
1. run ansible playbook to upgrade static images
   - pull deploy plug-in image from configured source
   - push its image to local registry
2. run ansible playbook to refresh deploy plug-in

Test Plan:
PASS: Verify deploy plug-in is refreshed after script execution.
 - Create restart script to invoke the utility script
 - Copy the new debian files onto the controller
 - Create sneaky patch with debian files and restart script
 - Check deploy plug-in image version before applying sneaky patch
 - Apply the sneaky patch
 - Check deploy plug-in image version after applying sneaky patch
PASS: Verify utility script is in debian package
PASS: Verify error handling is done for playbook
PASS: Verify sneaky patch remove is successful
PASS: Verify deploy pod is running new image after the patch
      containing deploy plug-in update is applied
PASS: Verify script logs generated in /var/log/platform.log

Story: 2010718
Task: 48412

Change-Id: Ifd348f005117aca5cf18e16719123410d86d027d
Signed-off-by: Susendra Selvaraj <Susendra.Selvaraj@windriver.com>
This commit is contained in:
Susendra Selvaraj 2023-06-28 06:43:18 -04:00
parent e5d9077c39
commit 7a371e65a2
4 changed files with 55 additions and 1 deletions
utilities/platform-util

@ -4,5 +4,6 @@ scripts/show-certs.sh usr/local/bin
scripts/stx-iso-utils.sh usr/local/bin
scripts/stx-iso-utils-centos.sh usr/local/bin
scripts/update-iso.sh usr/local/bin
scripts/update-dm.sh usr/local/bin
scripts/update_docker_registry_auth.sh usr/local/bin
scripts/change_system_private_registry.sh usr/local/bin

@ -4,5 +4,6 @@
/usr/local/bin/stx-iso-utils.sh
/usr/local/bin/stx-iso-utils-centos.sh
/usr/local/bin/update-iso.sh
/usr/local/bin/update-dm.sh
/usr/local/bin/update_docker_registry_auth.sh
/usr/local/bin/change_system_private_registry.sh

@ -30,6 +30,7 @@ override_dh_auto_install:
install -d $(DEBIAN_BUILDDIR)/usr/local/bin/
install -m 555 scripts/update-iso.sh $(DEBIAN_BUILDDIR)/usr/local/bin/
install -m 555 scripts/update-dm.sh $(DEBIAN_BUILDDIR)/usr/local/bin/
install -m 555 scripts/gen-bootloader-iso.sh $(DEBIAN_BUILDDIR)/usr/local/bin/
install -m 555 scripts/gen-bootloader-iso-centos.sh $(DEBIAN_BUILDDIR)/usr/local/bin/
install -m 555 scripts/stx-iso-utils.sh $(DEBIAN_BUILDDIR)/usr/local/bin/
@ -49,6 +50,6 @@ override_dh_auto_install:
dh_install
override_dh_fixperms:
dh_fixperms -Xupdate-iso.sh -Xgen-bootloader-iso.sh -Xstx-iso-utils.sh \
dh_fixperms -Xupdate-iso.sh -Xpatch-dm.sh -Xgen-bootloader-iso.sh -Xstx-iso-utils.sh \
-Xshow-certs.sh -Xupdate_docker_registry_auth.sh -Xchange_system_private_registry.sh \
-Xis-rootdisk-device.sh -Xpatch-restart-* -Xconnectivity_test -Xset_keystone_user_option.sh

@ -0,0 +1,51 @@
#!/bin/bash
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# This script automates deploy plug-in update to
# 1. run ansible playbook to upgrade static images
# - pull image from configured source
# - push image to local registry
# 2. run ansible playbook to refresh deploy plug-in
#
export KUBECONFIG=/etc/kubernetes/admin.conf
UPGRADE_STATIC_IMAGE_PLAYBOOK=/usr/share/ansible/stx-ansible/playbooks/upgrade-static-images.yml
DEPLOY_OVERRIDES=$1
DEPLOY_CHART=$2
DEPLOY_PLAYBOOK=$3
# This will log to /var/log/platform.log
function log {
logger -p local1.info $1
}
# Step-1
log "Run upgrade-static-images playbook to pull image from remote registry & push to local registry"
K8S_VERSION=$(kubectl get nodes|tail -1|awk '{print $5}')
ansible-playbook -e "kubernetes_version=${K8S_VERSION}" $UPGRADE_STATIC_IMAGE_PLAYBOOK
RC=$?
if [ $RC -eq 0 ]; then
log "The upgrade static image playbook was executed successfully"
else
log "The upgrade static image playbook failed with error: $RC"
exit $RC
fi
# Step-2
log "Run ansible playbook to refresh deploy plug-in"
ansible-playbook -e "deployment_manager_overrides=$DEPLOY_OVERRIDES deployment_manager_chart=$DEPLOY_CHART" $DEPLOY_PLAYBOOK
RC=$?
if [ $RC -eq 0 ]; then
log "The deployment playbook was executed successfully"
else
log "The deployment playbook failed with error: $RC"
exit $RC
fi
exit 0