From cf253a0a062f84f89dcc12bd2a2e666d0162fdcd Mon Sep 17 00:00:00 2001 From: Jef Steelant Date: Fri, 14 Nov 2025 09:59:09 +0100 Subject: [PATCH] ci: cram: add test 038-lcm-syslog.t Add a the 038-lcm-syslog.t test which tests the cthulhu-syslog plugin References: PCF-2122 Signed-off-by: Jef Steelant --- .../tests/cram/generic/lcm/038-lcm-syslog.t | 156 ++++++++++++++++++ .../cram/generic/lcm/script_functions.sh | 79 +++++++++ 2 files changed, 235 insertions(+) create mode 100644 .gitlab/tests/cram/generic/lcm/038-lcm-syslog.t diff --git a/.gitlab/tests/cram/generic/lcm/038-lcm-syslog.t b/.gitlab/tests/cram/generic/lcm/038-lcm-syslog.t new file mode 100644 index 0000000000..d59f4cbb74 --- /dev/null +++ b/.gitlab/tests/cram/generic/lcm/038-lcm-syslog.t @@ -0,0 +1,156 @@ +## Setup test configuration +Setup the test configuration: + + $ alias R="${CRAM_REMOTE_COMMAND:-}" + $ alias C="${CRAM_REMOTE_COPY:-}" + $ S=". /tmp/script_functions.sh" + $ C ${TESTDIR}/script_functions.sh root@${TARGET_LAN_IP}:/tmp/script_functions.sh 2>/dev/null + +### SYSLOG CONTAINER SECTION ### + +C-1: Syslog API UDS support +########################### +Test support for the Syslog API by defining a syslog source that maps to a UDS +socket (e.g., /tmp/volatile_log.sock and /lcm/persistent_log.sock). + +C-1-1 test /tmp/volatile_log.sock +################################# +Add the source + + $ R "ba-cli -l -j 'Device.Syslog.Source.+{Alias = \"C-1-1\", UnixDomainSocket.Enable = 1, UnixDomainSocket.Path = \"file:///tmp/volatile.sock\"}'" + + {"Device.Syslog.Source.*.":{"Alias":"C-1-1"}} (glob) + +Add the action + + $ R "ba-cli -l -j 'Device.Syslog.Action.+{Alias = \"C-1-1\", SourceRef = \"Device.Syslog.Source.[ Alias == \\\"C-1-1\\\" ]\", LogFile.Enable = 1, LogFile.FilePath = \"file:///tmp/volatile.log\"}'" + + {"Device.Syslog.Action.*.":{"Alias":"C-1-1"}} (glob) + +Sleep so the socket can be created + + $ R "sleep 1" + +Assert the socket file exists + + $ R "ls /tmp/volatile.sock" + /tmp/volatile.sock + +C-1-2 test /lcm/volatile_log.sock +################################# +Add the source + + $ R "ba-cli -l -j 'Device.Syslog.Source.+{Alias = \"C-1-2\", UnixDomainSocket.Enable = 1, UnixDomainSocket.Path = \"file:///lcm/volatile.sock\"}'" + + {"Device.Syslog.Source.*.":{"Alias":"C-1-2"}} (glob) + +Add the action + + $ R "ba-cli -l -j 'Device.Syslog.Action.+{Alias = \"C-1-2\", SourceRef = \"Device.Syslog.Source.[ Alias == \\\"C-1-2\\\" ]\", LogFile.Enable = 1, LogFile.FilePath = \"file:///lcm/volatile.log\"}'" + + {"Device.Syslog.Action.*.":{"Alias":"C-1-2"}} (glob) + +Sleep so the socket can be created + + $ R "sleep 1" + +Assert the socket file exists + + $ R "ls /lcm/volatile.sock" + /lcm/volatile.sock + +C-2: Test Syslog Plugin Default Configuration +############################################# +- Verify the existence of a default parameter (LogLocation) that defines the +default location for storing containers' logs. +- Check that the default value points to /lcm/cthulhu/syslog. + + $ R "ba-cli -l -j \"Cthulhu.Config.Syslog.LogLocation?\" | jsonfilter -e @[*].*.LogLocation" + /lcm/cthulhu/syslog + + +C-3: Test Syslog Configuration +############################## +Install a test container and verify the following: +- A dedicated entry is created under Syslog.Source.xxx, and the UDS socket is set. +- Dedicated Template and Action entries are also created. + +Create the container + + $ R "${S} && install_ctr --version prplos-v1 --ee --uuid --privileged true" + + SoftwareModules.InstallDU() returned + ["",{"err_code":0,"err_msg":""}] + +Check the syslog source + + $ R "ba-cli -l -j \"Device.Syslog.Source.[ Alias == \\\"cpe-917362a3-86e8-5332-bcfd-a4223f0e65e6\\\"].UnixDomainSocket.?\" | jsonfilter -e @[*].*.Enable -e @[*].*.Path" + 1 + file:///var/run/cthulhu/syslog/917362a3-86e8-5332-bcfd-a4223f0e65e6/log.sock + +Check the Template + + $ R "ba-cli -l -j \"Device.Syslog.Template.[ Alias == \\\"cpe-917362a3-86e8-5332-bcfd-a4223f0e65e6\\\"].?\" | jsonfilter -e @[*].*.Expression" + "${FULLDATE} 917362a3-86e8-5332-bcfd-a4223f0e65e6 ${MSGHDR}${MSG} + " + +Check the Action + + $ R "ba-cli -l -j \"Device.Syslog.Action.[ Alias == \\\"cpe-917362a3-86e8-5332-bcfd-a4223f0e65e6\\\"].?\" | jsonfilter -e @[*].*.Enable -e @[*].*.VendorLogFileRef -e @[*].*.FilePath -e @[*].*.SourceRef -e @[*].*.TemplateRef" + 1 + 0 + Device.DeviceInfo.VendorLogFile.* (glob) + file:///lcm/cthulhu/syslog/917362a3-86e8-5332-bcfd-a4223f0e65e6/messages + Device.Syslog.Source.* (glob) + Device.Syslog.Template.* (glob) + +Assert the socket file exists + + $ R "ls /var/run/cthulhu/syslog/917362a3-86e8-5332-bcfd-a4223f0e65e6/log.sock" + /var/run/cthulhu/syslog/917362a3-86e8-5332-bcfd-a4223f0e65e6/log.sock + +C-4: Test Logging From the Container +#################################### +- Install a test container that supports logger, and generate some logs. +- Verify that the generated logs are visible in the dedicated log file (combining +the default log location and a reference to the container, e.g., /lcm/cthulhu/syslog/xxxxxx/messages). + +reuse container from C-3 + +Generate log in container + + $ R "${S} && execute_in_container --uuid --cmd 'logger test-C-4'" + +Check content of the log file + + $ R "cat /lcm/cthulhu/syslog/917362a3-86e8-5332-bcfd-a4223f0e65e6/messages" + * 917362a3-86e8-5332-bcfd-a4223f0e65e6 root: test-C-4 (glob) + +C-5: Test VendorLog +################### +- Install a test container. +- Check that ExecutionUnit.{i}.VendorLogList points to a valid +Device.DeviceInfo.VendorLogFile entry. +- Generate logs from within the container and verify that VendorLogFile.{i}.Name +matches the file to which the container logs (which should be prefixed by the +default LogLocation and container reference). + +reuse container from C-3 + +Check the VendorLogFile of the ExecutionUnit + + $ R "${S} && get_container_parameter --uuid --param VendorLogList" + Device.DeviceInfo.VendorLogFile.* (glob) + +Check the VendorLogFile object + + $ R "${S} && get_vendorlogfile_name --uuid" + file:///lcm/cthulhu/syslog/917362a3-86e8-5332-bcfd-a4223f0e65e6/messages + +Check the VendorLogFile content + + $ R "${S} && execute_in_container --uuid --cmd 'logger test-C-5'" + $ R "${S} && get_vendorlogfile_content --uuid" + file:///lcm/cthulhu/syslog/917362a3-86e8-5332-bcfd-a4223f0e65e6/messages + * 917362a3-86e8-5332-bcfd-a4223f0e65e6 root: test-C-4 (glob) + * 917362a3-86e8-5332-bcfd-a4223f0e65e6 root: test-C-5 (glob) diff --git a/.gitlab/tests/cram/generic/lcm/script_functions.sh b/.gitlab/tests/cram/generic/lcm/script_functions.sh index 43cabb443d..16b18c9423 100755 --- a/.gitlab/tests/cram/generic/lcm/script_functions.sh +++ b/.gitlab/tests/cram/generic/lcm/script_functions.sh @@ -964,3 +964,82 @@ fake_fw_upgrade() { sleep 30 wait_ctr_up --uuid "${DEFAULT_UUID}" } + +get_vendorlogfile_name() { + uuid="" + while [ $# -gt 0 ]; do + key="$1" + value="" + value_missing=false + case $key in + --*) # If argument starts with "--" + key="${key#--}" + shift + if [ $# -gt 0 ] && case "$1" in --*) false ;; *) true ;; esac then + value="$1" + shift + elif [ $# -eq 0 ] || case "$1" in --*) true ;; *) false ;; esac then + value_missing=true + fi + + if [ "${key}" = "uuid" ]; then + uuid=$(value_or_default "${value_missing}" "${DEFAULT_UUID}" "${value}") + else + echo "Unknown argument: $key=${value}" + fi + ;; + *) + echo "Unknown argument: $1" + shift + ;; + esac + done + + if [ -z "${uuid}" ]; then + echo "Missing UUID parameter" + else + VendorLogFileRef=$(get_container_parameter --uuid ${uuid} --param VendorLogList) + ${CLI_JSON} "${VendorLogFileRef}.?" | jsonfilter -e @[*].*.Name + fi +} + +get_vendorlogfile_content() { + uuid="" + while [ $# -gt 0 ]; do + key="$1" + value="" + value_missing=false + case $key in + --*) # If argument starts with "--" + key="${key#--}" + shift + if [ $# -gt 0 ] && case "$1" in --*) false ;; *) true ;; esac then + value="$1" + shift + elif [ $# -eq 0 ] || case "$1" in --*) true ;; *) false ;; esac then + value_missing=true + fi + + if [ "${key}" = "uuid" ]; then + uuid=$(value_or_default "${value_missing}" "${DEFAULT_UUID}" "${value}") + else + echo "Unknown argument: $key=${value}" + fi + ;; + *) + echo "Unknown argument: $1" + shift + ;; + esac + done + + if [ -z "${uuid}" ]; then + echo "Missing UUID parameter" + else + VendorLogFileRef=$(get_container_parameter --uuid ${uuid} --param VendorLogList) + file=$(${CLI_JSON} "${VendorLogFileRef}.Name?" | jsonfilter -e @[*].*.Name) + echo ${file} + file_wo_prefix="${file:7}" + cat ${file_wo_prefix} + fi +}