Skip to content

Commit

Permalink
Merge pull request #55 from SUNET/patlu-fleetlock-lock-timeouts
Browse files Browse the repository at this point in the history
fleetlock: configurable lock/unlock timeout
  • Loading branch information
eest committed Jul 4, 2024
2 parents 443611d + aa88795 commit 770a5ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions global/overlay/usr/local/bin/run-cosmos
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,40 @@ fleetlock_lock() {
# called.
fleetlock_enable_unlock_service || return 1
local fleetlock_group=""
local optional_args=()
# shellcheck source=/dev/null
. $FLEETLOCK_CONFIG || return 1
if [ -z "$fleetlock_group" ]; then
echo "Unable to set fleetlock_group"
return 1
fi
if [ -n "$fleetlock_lock_timeout" ]; then
optional_args+=("--timeout")
optional_args+=("$fleetlock_lock_timeout")
fi
echo "Getting fleetlock lock"
$FLEETLOCK_TOOL --lock-group "$fleetlock_group" --lock || return 1
$FLEETLOCK_TOOL --lock-group "$fleetlock_group" --lock "${optional_args[@]}" || return 1
fi
return 0
}

fleetlock_unlock() {
if [ ! -f $FLEETLOCK_DISABLE_FILE ] && [ -f $FLEETLOCK_CONFIG ] && [ -x $FLEETLOCK_TOOL ]; then
local fleetlock_group=""
local optional_args=()
# shellcheck source=/dev/null
. $FLEETLOCK_CONFIG || return 1
if [ -z "$fleetlock_group" ]; then
echo "Unable to set fleetlock_group"
return 1
fi
if [ -n "$fleetlock_unlock_timeout" ]; then
optional_args+=("--timeout")
optional_args+=("$fleetlock_unlock_timeout")
fi
machine_is_healthy || return 1
echo "Releasing fleetlock lock"
$FLEETLOCK_TOOL --lock-group "$fleetlock_group" --unlock || return 1
$FLEETLOCK_TOOL --lock-group "$fleetlock_group" --unlock "${optional_args[@]}" || return 1
fi
return 0
}
Expand Down
5 changes: 4 additions & 1 deletion global/overlay/usr/local/bin/sunet-fleetlock
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def do_fleetlock_request(
timeout=args.request_timeout,
auth=("", config[args.lock_group]["password"]),
)
except requests.exceptions.ConnectionError as e:
except (
requests.exceptions.ConnectionError,
requests.exceptions.ReadTimeout,
) as e:
print(f"POST request failed: {e}")
time.sleep(retry_sleep_delay)
continue
Expand Down

0 comments on commit 770a5ca

Please sign in to comment.