bd998017d5
Create host inventory services (api, conductor and agent) and
python-inventoryclient.
The inventory service collects the host resources and provides a
REST API and client to expose the host resources.
Create plugin for integration with system configuration (sysinv)
service.
This is the initial inventory service infratructure commit.
Puppet configuration, SM integration and host integration with
sysinv(systemconfig) changes are pending and planned to be
delivered in future commits.
Tests Performed:
Verify the changes are inert on config_controller installation
and provisioning.
Puppet and spec changes are required in order to create keystone,
database and activate inventory services.
Unit tests performed (when puppet configuration for keystone, database
is applied):
Trigger host configure_check, configure signals into
systemconfig(sysinv).
Verify python-inventoryclient and api service:
Disks and related storage resources are pending.
inventory host-cpu-list/show
inventory host-device-list/show/modify
inventory host-ethernetport-list/show
inventory host-lldp-neighbor-list
inventory host-lldp-agent-list/show
inventory host-memory-list/show
inventory host-node-list/show
inventory host-port-list/show
Tox Unit tests:
inventory: pep8
python-inventoryclient: py27, pep8, cover, pylint
Change-Id: I744ac0de098608c55b9356abf180cc36601cfb8d
Story: 2002950
Task: 22952
Signed-off-by: John Kung <john.kung@windriver.com>
205 lines
6.1 KiB
Bash
Executable File
205 lines
6.1 KiB
Bash
Executable File
#! /bin/sh
|
|
#
|
|
# Copyright (c) 2018 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
#
|
|
# chkconfig: 2345 75 25
|
|
#
|
|
### BEGIN INIT INFO
|
|
# Provides: inventory-agent
|
|
# Default-Start: 3 5
|
|
# Default-Stop: 0 1 2 6
|
|
# Short-Description: inventory-agent daemon
|
|
### END INIT INFO
|
|
|
|
. /etc/init.d/functions
|
|
. /etc/build.info
|
|
|
|
|
|
PLATFORM_CONF="/etc/platform/platform.conf"
|
|
NODETYPE=""
|
|
DAEMON_NAME="inventory-agent"
|
|
INVENTORYAGENT="/usr/bin/${DAEMON_NAME}"
|
|
INVENTORY_CONF_DIR="/etc/inventory"
|
|
INVENTORY_CONF_FILE="${INVENTORY_CONF_DIR}/inventory.conf"
|
|
INVENTORY_CONF_DEFAULT_FILE="/opt/platform/inventory/${SW_VERSION}/inventory.conf.default"
|
|
INVENTORY_READY_FLAG=/var/run/.inventory_ready
|
|
|
|
DELAY_SEC=20
|
|
|
|
daemon_pidfile="/var/run/${DAEMON_NAME}.pid"
|
|
|
|
if [ -f ${PLATFORM_CONF} ] ; then
|
|
NODETYPE=`cat ${PLATFORM_CONF} | grep nodetype | cut -f2 -d'='`
|
|
else
|
|
logger "$0: ${PLATFORM_CONF} is missing"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -e "${INVENTORYAGENT}" ] ; then
|
|
logger "$0: ${INVENTORYAGENT} is missing"
|
|
exit 1
|
|
fi
|
|
|
|
RETVAL=0
|
|
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
|
|
export PATH
|
|
|
|
mount_and_copy_config_file()
|
|
{
|
|
echo "Mount /opt/platform"
|
|
logger "$0: Info: nfs-mount controller:/opt/platform/inventory/${SW_VERSION} /mnt/inventory"
|
|
mkdir /mnt/inventory
|
|
timeout 10s nfs-mount controller:/opt/platform/inventory/${SW_VERSION} /mnt/inventory &> /dev/null
|
|
RETVAL=$?
|
|
# 0 = true
|
|
if [ ${RETVAL} -ne 0 ] ; then
|
|
logger "$0: Warn: nfs-mount controller:/opt/platform/inventory/${SW_VERSION} /mnt/inventory"
|
|
else
|
|
mkdir -p $INVENTORY_CONF_DIR
|
|
cp /mnt/inventory/inventory.conf.default ${INVENTORY_CONF_FILE}
|
|
RETVAL=$?
|
|
if [ $? -ne 0 ] ; then
|
|
logger "$0: Warn: cp /mnt/inventory/inventory.conf.default ${INVENTORY_CONF_FILE}"
|
|
fi
|
|
timeout 5s umount /mnt/inventory
|
|
rmdir /mnt/inventory
|
|
fi
|
|
|
|
return ${RETVAL}
|
|
}
|
|
|
|
|
|
case "$1" in
|
|
start)
|
|
# Check for installation failure
|
|
if [ -f /etc/platform/installation_failed ] ; then
|
|
logger "$0: /etc/platform/installation_failed flag is set. Aborting."
|
|
exit 1
|
|
fi
|
|
|
|
echo -n "Setting up config for inventory-agent: "
|
|
if [ -e ${INVENTORY_READY_FLAG} ] ; then
|
|
# clear it on every restart, so agent can update it
|
|
rm -f ${INVENTORY_READY_FLAG}
|
|
fi
|
|
|
|
if [ -f ${INVENTORY_CONF_FILE} ] ; then
|
|
logger "$0: ${INVENTORY_CONF_FILE} already exists"
|
|
RETVAL=0
|
|
else
|
|
# Avoid self-mount due to potential nfs issues
|
|
echo "Checking for controller-platform-nfs "
|
|
|
|
# try for DELAY_SEC seconds to reach controller-platform-nfs
|
|
START=`date +%s`
|
|
FOUND=0
|
|
while [ $(date +%s) -lt $(( ${START} + ${DELAY_SEC} )) ] ; do
|
|
ping -c 1 controller-platform-nfs > /dev/null 2>&1 || ping6 -c 1 controller-platform-nfs > /dev/null 2>&1
|
|
if [ $? -eq 0 ] ; then
|
|
FOUND=1
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
CONF_COPIED=0
|
|
if [ ${FOUND} -eq 0 ] ; then
|
|
# 'controller-platform-nfs' is not available; continue other setup
|
|
echo "controller-platform-nfs is not available"
|
|
else
|
|
# Only required if conf file does not already exist
|
|
if [ -f ${INVENTORY_CONF_DEFAULT_FILE} ] ; then
|
|
echo "Copying self inventory.conf without mount"
|
|
mkdir -p $INVENTORY_CONF_DIR
|
|
cp ${INVENTORY_CONF_DEFAULT_FILE} ${INVENTORY_CONF_FILE}
|
|
RETVAL=$?
|
|
if [ $? -ne 0 ] ; then
|
|
logger "$0: Warn: cp /mnt/inventory/inventory.conf.default ${INVENTORY_CONF_FILE} failed. Try mount."
|
|
else
|
|
CONF_COPIED=1
|
|
fi
|
|
fi
|
|
if [ ${CONF_COPIED} -eq 0 ] ; then
|
|
CONF_COPY_COUNT=0
|
|
while [ $CONF_COPY_COUNT -lt 3 ]; do
|
|
if mount_and_copy_config_file ; then
|
|
logger "$0: Info: Mount and copy config file PASSED. Attempt: ${CONF_COPY_COUNT}"
|
|
break
|
|
fi
|
|
let CONF_COPY_COUNT=CONF_COPY_COUNT+1
|
|
logger "$0: Warn: Mount and copy config file failed. Attempt: ${CONF_COPY_COUNT}"
|
|
done
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ -e ${daemon_pidfile} ] ; then
|
|
echo "Killing existing process before starting new"
|
|
pid=`cat ${daemon_pidfile}`
|
|
kill -TERM $pid
|
|
rm -f ${daemon_pidfile}
|
|
fi
|
|
|
|
echo -n "Starting inventory-agent: "
|
|
/bin/sh -c "${INVENTORYAGENT}"' >> /dev/null 2>&1 & echo $!' > ${daemon_pidfile}
|
|
RETVAL=$?
|
|
if [ $RETVAL -eq 0 ] ; then
|
|
echo "OK"
|
|
touch /var/lock/subsys/${DAEMON_NAME}
|
|
else
|
|
echo "FAIL"
|
|
fi
|
|
;;
|
|
|
|
stop)
|
|
echo -n "Stopping inventory-agent: "
|
|
if [ -e ${daemon_pidfile} ] ; then
|
|
pid=`cat ${daemon_pidfile}`
|
|
kill -TERM $pid
|
|
rm -f ${daemon_pidfile}
|
|
rm -f /var/lock/subsys/${DAEMON_NAME}
|
|
echo "OK"
|
|
else
|
|
echo "FAIL"
|
|
fi
|
|
;;
|
|
|
|
restart)
|
|
$0 stop
|
|
sleep 1
|
|
$0 start
|
|
;;
|
|
|
|
status)
|
|
if [ -e ${daemon_pidfile} ] ; then
|
|
pid=`cat ${daemon_pidfile}`
|
|
ps -p $pid | grep -v "PID TTY" >> /dev/null 2>&1
|
|
if [ $? -eq 0 ] ; then
|
|
echo "inventory-agent is running"
|
|
RETVAL=0
|
|
else
|
|
echo "inventory-agent is not running"
|
|
RETVAL=1
|
|
fi
|
|
else
|
|
echo "inventory-agent is not running ; no pidfile"
|
|
RETVAL=1
|
|
fi
|
|
;;
|
|
|
|
condrestart)
|
|
[ -f /var/lock/subsys/$DAEMON_NAME ] && $0 restart
|
|
;;
|
|
|
|
*)
|
|
echo "usage: $0 { start | stop | status | restart | condrestart | status }"
|
|
;;
|
|
esac
|
|
|
|
exit $RETVAL
|