Use sm-query of service-group to determine controller activity state

Several collect plugins were using the 'sm-query service' with
'management-ip' as the target service to determine if the host
collect is running on is the active controller.

    sm-query service management-ip

Unfortunately, a recent update changed the name of the 'management-ip'
service. This change lead to that query always returning a 'disabled'
status.

This update changes to use 'sm-query service-group controller-services'
instead of a specific service query that might change again in the
future. It also migrates the replicated is_service_active function to
the collect_utils file making it common and reusable by all aspects of
collect. This function was renamed to 'is_controller_active' because
it's no longer representing the activity state of a particular service.

Test Plan:

PASS: Verify 'sysinv' plugin creates var/extra/inventory.info file
      on active controller. sysinv CLI command output.
PASS: Verify 'fm' plugin creates var/extra/alarm.info file
      on active controller. FM alarm and event listings.
PASS: Verify 'ceph' plugin creates var/extra/ceph.info file
      on active controller with 'ceph df' output content.
PASS: Verify 'dc' plugin creates var/extra/distributed_cloud.info file
      on active controller of a system controller or subcloud.

Closes-Bug: 2070496

Change-Id: I9989708f1d87a5ef312129cfe3ede8c862764cb0
Signed-off-by: Eric MacDonald <eric.macdonald@windriver.com>
This commit is contained in:
Eric MacDonald 2024-06-26 19:41:43 +00:00
parent 2f17b903ce
commit f87df98a96
5 changed files with 13 additions and 39 deletions

View File

@ -14,15 +14,6 @@ SERVICE="ceph"
LOGFILE="${extradir}/ceph.info"
echo "${hostname}: Ceph Info .........: ${LOGFILE}"
function is_service_active {
active=`sm-query service management-ip | grep "enabled-active"`
if [ -z "$active" ] ; then
return 0
else
return 1
fi
}
function exit_if_timeout {
if [ "$?" = "124" ] ; then
echo "Exiting due to ceph command timeout" >> ${LOGFILE}
@ -59,7 +50,7 @@ if [ "$nodetype" = "controller" ] ; then
timeout 30 ceph osd crush dump >> ${LOGFILE} 2>>${COLLECT_ERROR_LOG}
exit_if_timeout
is_service_active
is_active_controller
if [ "$?" = "0" ] ; then
exit 0
fi

View File

@ -13,15 +13,6 @@ source /usr/local/sbin/collect_utils
SERVICE="distributed_cloud"
LOGFILE="${extradir}/${SERVICE}.info"
function is_active_controller {
active_controller=`sm-query service management-ip | grep "enabled-active"`
if [ -z "$active_controller" ] ; then
return 0
else
return 1
fi
}
function is_distributed_cloud_env {
distributed_cloud=`sm-query service-group distributed-cloud-services | grep "active"`
if [ -z "$distributed_cloud" ] ; then

View File

@ -12,21 +12,12 @@ source /usr/local/sbin/collect_utils
SERVICE="alarms"
LOGFILE="${extradir}/${SERVICE}.info"
function is_service_active {
active=`sm-query service management-ip | grep "enabled-active"`
if [ -z "$active" ] ; then
return 0
else
return 1
fi
}
###############################################################################
# Only Controller
###############################################################################
if [ "$nodetype" = "controller" ] ; then
is_service_active
is_active_controller
if [ "$?" = "0" ] ; then
exit 0
fi

View File

@ -14,17 +14,8 @@ SERVICE="inventory"
LOGFILE="${extradir}/${SERVICE}.info"
INVENTORY=${4}
function is_service_active {
active=`sm-query service management-ip | grep "enabled-active"`
if [ -z "$active" ] ; then
return 0
else
return 1
fi
}
function collect_inventory {
is_service_active
is_active_controller
if [ "$?" = "0" ] ; then
exit 0
fi

View File

@ -111,6 +111,16 @@ HOST_COLLECT_ERROR_LOG="/tmp/host_collect_error.log"
DCROLE_SYSTEMCONTROLLER="systemcontroller"
DCROLE_SUBCLOUD="subcloud"
function is_active_controller
{
active=`sm-query service-group controller-services | grep "controller-services active"`
if [ -z "$active" ] ; then
return 0
else
return 1
fi
}
function source_openrc_if_needed
{
# get the node and subfunction types