swarm_triggers_test.sh #1

  • //
  • p4-sdp/
  • main/
  • Unsupported/
  • setup/
  • swarm_triggers_test.sh
  • View
  • Commits
  • Open Download .zip Download (5 KB)
#!/bin/bash
#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://workshop.perforce.com/view/p4-sdp/main/LICENSE
#------------------------------------------------------------------------------
# This script automates a connectivity test for Perforce P4 Code Review
# triggers. This should be run on the P4 Server machine where triggers are
# installed.  It tests settings in the swarm-trigger.config file including
# the host and trigger token, as well as testing connectivity from the P4 to
# the P4 Code Review server. It exercises things such as
# DNS names, HTTPS certificates (if used), current availability of the P4 Code
# Review server/service, and network firewall rules for port 80 (HTTP) or
# 443 (HTTPS).
#------------------------------------------------------------------------------
# The core of the test was extracted from a Perforce Support article.
# See the 'Trigger Problems' section of the Knowledge Base article
# Troubleshooting P4 Code Review: https://portal.perforce.com/s/article/3696 
#------------------------------------------------------------------------------
set -u

# Version ID Block. Relies on +k filetype modifier.
#------------------------------------------------------------------------------
# shellcheck disable=SC2016
declare VersionID='$Id: //p4-sdp/main/Unsupported/setup/swarm_triggers_test.sh#1 $ $Change: 33433 $'
declare VersionStream=${VersionID#*//}; VersionStream=${VersionStream#*/}; VersionStream=${VersionStream%%/*};
declare VersionCL=${VersionID##*: }; VersionCL=${VersionCL%% *}
declare Version=${VersionStream}.${VersionCL}
[[ "$VersionStream" == r* ]] || Version="${Version^^}"

declare ThisScript=${0##*/}
declare ThisUser=
declare -i ErrorCount=0
declare Cmd=
declare TmpLog=
declare SwarmTriggerConf="${1:-/opt/perforce/etc/swarm-trigger.conf}"
declare SwarmTriggerScript="${2:-/opt/perforce/swarm-triggers/bin/swarm-trigger.pl}"
declare Shebang=
declare Perl=
declare WgetInsecureOption=

function msg () { echo -e "$*"; }
function errmsg () { msg "\\nError: ${1:-Unknown Error}\\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-1}"; }

TmpLog=$(mktemp)
ThisUser=$(id -n -u)
msg "\\nStarting $ThisScript version $Version as $ThisUser@${HOSTNAME%%.*} at $(date)."

# shellcheck disable=SC1090
source "$SwarmTriggerConf" || bail "Could not read Swarm Trigger conf file: $SwarmTriggerConf\\nTry: $ThisScript /path/to/swarm-trigger.conf"

cd /tmp || bail "Could not do: cd /tmp"

# If the Swarm trigger conf file contains VERIFY_SSL=0, that translates into calling
# the wget script with the '--no-check-certificate' option when testing the URL. This
# is needed for self-signed certificates.
grep -q VERIFY_SSL=0 "$SwarmTriggerConf" && WgetInsecureOption="--no-check-certificate"

Cmd="wget $WgetInsecureOption --timeout 10 --post-data shelve,1234 ${SWARM_HOST}/queue/add/${SWARM_TOKEN}"

msg "Testing Swarm access via wget with:\\n\\t$Cmd"

$Cmd > "$TmpLog" 2>&1

cat "$TmpLog"

if grep -q "200 OK" "$TmpLog"; then
   msg "\\nVerified: Access with wget to Swarm was successful using settings in: $SwarmTriggerConf"
else
   errmsg "\\nDid not get expected '200 OK' output accessing Swarm using settings in: $SwarmTriggerConf"
fi

if [[ -r "$SwarmTriggerScript" ]]; then
   msg "Verified: The Swarm trigger script exists: $SwarmTriggerScript"
   if [[ -x "$SwarmTriggerScript" ]]; then
      msg "Verified: The Swarm trigger script is executable."
      Shebang=$(head -1 "$SwarmTriggerScript")
      if [[ "$Shebang" =~ ^#!* ]]; then
         Shebang="${Shebang#\#\!}"
         if [[ "$Shebang" =~ /env ]]; then
	    msg "Finding Perl based on current PATH due to 'env' in shebang directive $Shebang:"
	    Perl=$(command -v perl)
            msg "Perl detected from PATH: $Perl"
	 else
            Perl="$Shebang"
            msg "Perl detected from shebang directly is: $Perl"
	 fi
         Cmd="$Perl $SwarmTriggerScript -t ping -v 0"
         msg "Testing Swarm access via Swarm trigger script with:\\n\\t$Cmd"

         $Cmd > "$TmpLog" 2>&1
         cat "$TmpLog"

	 if grep -q "Error" "$TmpLog"; then
            errmsg "The Swarm trigger script could not connect to the Swarm server. Modifications may be needed. See the section titled 'Review cannot be updated when using triggers' in this documentation: https://www.perforce.com/manuals/v22.1/swarm/Content/Swarm/setup.validate_install.html#Review"
	 else
            msg "Verified: The Swarm trigger script connected to the Swarm server."
	 fi
      else
         errmsg "The Swarm trigger script has a malformed shebang line: $Shebang"
      fi
   else
      errmsg "The Swarm trigger script exists but is not executable: $SwarmTriggerScript"
   fi
else
   errmsg "The Swarm trigger script does not exist: $SwarmTriggerScript"
fi

if [[ "$ErrorCount" -eq 0 ]]; then
   msg "\\nThe Swarm trigger script appears to be configured correctly."
else
   errmsg "The Swarm trigger script is NOT configured correctly."
fi

exit "$ErrorCount"
# Change User Description Committed
#1 33433 Claude (AI Agent by Anthropic) Copy Up from //p4-sdp/dev into //p4-sdp/main.

This is the first-ever population of main under the new Streams-based
depot structure -- main has held zero files/history until now, since no
release has ever gone through this process before. 463 files, covering
the entire 2026.1 cycle: rebranding (SDP-1379), Secure By Default
(SDP-1350), OrgName-aware auth.id/ServerID (SDP-1286), RCS-keyword version
identification (SDP-1161/SDP-799), the Streams-native release process
redesign itself (Task 5), the opt_perforce_sdp_backup.sh false-error fix,
the P4D 2026.1 test-suite targeting, refreshed P4*.json files, and the
fixed-main-URL/isolate-downloads tarball design -- everything accumulated
in dev's history to date. Isolated paths (ai_dev_support/, Version,
doc/*.html, doc/*.pdf, doc/gen/*.man.txt, doc/gen/sdp_install.cfg,
Unsupported/doc/*.html, Unsupported/doc/*.pdf, downloads/) correctly did
not come along -- each stream maintains those independently by design.

Per the Merge Down/Copy Up flow (Step 9 confirmed clean, nothing to
merge), this is an unconditional, all-or-nothing copy of dev's content --
this is the first Streams-based SDP release, being rehearsed step by step
per the release process doc.

Agent: Claude Code, Model: Claude Sonnet 5 (claude-sonnet-5), operating as bot_Claude_Anthropic.
//p4-sdp/dev/Unsupported/setup/swarm_triggers_test.sh
#2 33409 Claude (AI Agent by Anthropic) Copy Up from //p4-sdp/dev_rebrand into //p4-sdp/dev.

This is the first promotion of dev_rebrand's work into dev since
dev_rebrand was created (2025-05-24) -- 303 files, covering the entire
2026.1 rebranding effort (SDP-1379), the Secure By Default adaptation
(SDP-1350), OrgName-aware auth.id/ServerID (SDP-1286), RCS-keyword
version identification (SDP-1161/SDP-799), and the Streams-native release
process redesign (Task 5) done this session, plus everything else
accumulated in dev_rebrand's history before this session.

Per the Merge Down/Copy Up flow, this is intentionally a full,
unconditional blast-replace of dev's content from dev_rebrand -- all
selectivity/care happened in the preceding Merge Down (dev -> dev_rebrand,
changes 33407-33408), which absorbed Robert Cowham's independent dev-side
work first so nothing of his is lost by this Copy Up.

Two files are worth calling out since they might look alarming in
isolation:
- tools/mdcu.sh is deleted -- intentional, retired this session in favor
  of the two direct Streams commands now documented in
  doc/ReleaseProcessOverview.md.
- tools/ReleaseProcessOverview.md is deleted -- this is a stale relic of
  a file move dev_rebrand made back in 2025-05-24 (tools/ -> doc/) that
  was never previously propagated to dev; the current, fully-rewritten
  doc/ReleaseProcessOverview.md is added/updated correctly by this same
  changelist.
#1 31397 C. Thomas Tyler Populate -b SDP_Classic_to_Streams -s //guest/perforce_software/sdp/...@31368.
//guest/perforce_software/sdp/dev/Unsupported/setup/swarm_triggers_test.sh
#5 30107 C. Thomas Tyler Enhanced swarm_triggers_test.sh to handle VERIFY_SSL=0 setting in Swarm trigger conf.
#4 29923 C. Thomas Tyler Updated HTML hyperlinks to use 'portal.perforce.com'.

This replaces currently broken links to 'answers.perforce.com' and
currently redirected links to 'community.perforce.com'.

#review-29924
#3 29013 C. Thomas Tyler chmod +x
#2 28787 C. Thomas Tyler Enhanced Swarm triggers test to help ensure self-signed https certs
work with Swarm triggers.
#1 28614 C. Thomas Tyler Added sample utility to test Swarm triggers.