Skip to content

Commit

Permalink
Test for skipping custom sqls based on $SQLS_SIDS
Browse files Browse the repository at this point in the history
This should not alter the current behaviour, just document it.

Change-Id: I3e575caba790d603787f797d37888a9d466e78d0
  • Loading branch information
BenediktSeidl committed Oct 18, 2023
1 parent 897ad61 commit 2a0b111
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 8 additions & 4 deletions agents/plugins/mk_oracle
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,13 @@ unset_custom_sqls_vars() {
unset SQLS_DBUSER SQLS_DBPASSWORD SQLS_DBSYSCONNECT SQLS_TNSALIAS SQLS_ITEM_SID
}

sid_matches_defined_sids() {
# first parameter is a list of coma separated values (SQLS_SIDS)
# second parameter is a single value (current sid)
sids=${1//,/ }
echo "$sids" | "${GREP}" -q "$2"
}

do_custom_sqls() {
for section in $custom_sqls_sections; do
if ! type "$section" >/dev/null 2>&1; then
Expand All @@ -2134,11 +2141,8 @@ do_custom_sqls() {

$section

local sids=${SQLS_SIDS:-$custom_sqls_sids}
sids=${sids//,/ }

# If SID is not part of sids we can skip the rest
if ! echo "$sids" | "${GREP}" -q "$MK_SID"; then
if ! sid_matches_defined_sids "${SQLS_SIDS:-$custom_sqls_sids}" "$MK_SID"; then
logging -w "[${MK_SID}] [custom_sql] [${section}]" \
"Skipping this section, runs only on SIDs '$sids'"
unset_custom_sqls_vars
Expand Down
11 changes: 11 additions & 0 deletions tests/unit-shell/agents/plugins/test_mk_oracle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -866,5 +866,16 @@ test_mk_oracle_mk_ora_db_connect_sqls_tnsalias_tnsping_ok_sid_specific_prefix_br
teardown_tnsping
}

test_mk_oracle_sid_matches_defined_sids() {
assertTrue 'sid_matches_defined_sids "prefixed_value" "prefix"' # THIS IS BROKEN! TODO: should not match!
assertTrue 'sid_matches_defined_sids "some,value,here" "value"'
assertFalse 'sid_matches_defined_sids "some,hello,here" "value"'
# documentation says, that customer may us "$SIDS" when the section should
# be executed for all elements, but this variable contains a newline
# seperated list of sids:
assertTrue 'sid_matches_defined_sids "some\nvalue\nhere" "value"'
assertTrue 'sid_matches_defined_sids "some\nprefixed_value\nhere" "value"' # THIS IS BROKEN! TODO: should not match!
}

# shellcheck disable=SC1090 # Can't follow
. "$UNIT_SH_SHUNIT2"

0 comments on commit 2a0b111

Please sign in to comment.