Skip to content

Commit 3146238

Browse files
committed
[IM] Augment router update script to allow skipping lock
1 parent 709e7a6 commit 3146238

File tree

3 files changed

+105
-46
lines changed

3 files changed

+105
-46
lines changed

tests/API/RouterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public function testApiRouterNotExists(): void
119119
$response->assertStatus( 404 );
120120
}
121121

122+
122123
public function testApiRouterGetLastUpdatedNulls(): void
123124
{
124125
$response = $this->withKey()->get( '/api/v4/router/updated/test-router' );
@@ -149,6 +150,19 @@ public function testApiRouterGetLastUpdatedNotNulls(): void
149150
$this->assertEquals( $now->toAtomString(), $response->json('last_updated') );
150151
$this->assertEquals( $now->format('U'), $response->json('last_updated_unix') );
151152
}
153+
154+
155+
public function testNoUpdateLockIfPaused(): void
156+
{
157+
$this->r->pause_updates = true;
158+
$this->r->save();
159+
160+
$response = $this->withKey()->post( '/api/v4/router/get-update-lock/test-router' );
161+
$response->assertStatus( 423 );
162+
$response->assertContent( 'Router not available for update' );
163+
}
164+
165+
152166
public function testApiRouterGetUpdateLockOnNulls(): void
153167
{
154168
$response = $this->withKey()->post( '/api/v4/router/get-update-lock/test-router' );

tools/runtime/router-reconfigure-scripts/api-reconfigure-example-birdv2.sh

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ ALLOWED_HANDLES="rs1-ipv4 rs1-ipv6"
4040

4141
# --- the following should be fine on a typical Debian / Ubuntu system:
4242

43-
BIRDBIN="/usr/sbin/bird"
4443
URL_LOCK="${URLROOT}/api/v4/router/get-update-lock"
4544
URL_CONF="${URLROOT}/api/v4/router/gen-config"
4645
URL_RELEASE="${URLROOT}/api/v4/router/release-update-lock"
4746
URL_DONE="${URLROOT}/api/v4/router/updated"
4847

48+
BIRDBIN="/usr/sbin/bird"
4949
ETCPATH="/usr/local/etc/bird"
5050
RUNPATH="/var/run/bird"
5151
LOGPATH="/var/log/bird"
@@ -64,13 +64,22 @@ LOCKPATH="/tmp/ixp-manager-locks"
6464
# Parse arguments
6565
export DEBUG=0
6666
export FORCE_RELOAD=0
67+
export LOCKING_ENABLED=1
6768

6869
function show_help {
69-
echo "$0 [-d] [-f] -h <handle> [-?]"
70+
cat <<END_HELP
71+
$0 [-d] [-f] [-s] -h <handle> [-?]
72+
73+
-d Enable debug mode, show all commands as they are run
74+
-f Force reload of BIRD, even if config is unchnaged
75+
-h Router handle to update (required)
76+
-s Skip lock - reads config, even if router is paused or locked
77+
78+
END_HELP
7079
}
7180

7281

73-
while getopts "?qdfh:" opt; do
82+
while getopts "?dfsh:" opt; do
7483
case "$opt" in
7584
\?)
7685
show_help
@@ -82,6 +91,8 @@ while getopts "?qdfh:" opt; do
8291
;;
8392
h) handle=$OPTARG
8493
;;
94+
s) export LOCKING_ENABLED=0
95+
;;
8596
esac
8697
done
8798

@@ -144,25 +155,32 @@ fi
144155
release_ixpmanager_lock() {
145156
### Tell IXP Manager that the config never started and release the lock
146157

147-
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_RELEASE}/${handle} >/dev/null"
148-
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
158+
if [[ $LOCKING_ENABLED -eq 1 ]]; then
159+
160+
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_RELEASE}/${handle} >/dev/null"
161+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
149162

150-
until eval $cmd; do
151-
echo "Warning - could not release lock on IXP Manager via API - sleeping 60 secs and trying again"
152-
sleep 60
153-
done
163+
until eval $cmd; do
164+
echo "Warning - could not release lock on IXP Manager via API - sleeping 60 secs and trying again"
165+
sleep 60
166+
done
167+
168+
fi
154169
}
155170

156-
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_LOCK}/${handle} >/dev/null"
171+
if [[ $LOCKING_ENABLED -eq 1 ]]; then
157172

158-
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
159-
eval $cmd
173+
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_LOCK}/${handle} >/dev/null"
160174

161-
if [[ $? -ne 0 ]]; then
162-
echo "ABORTING: router not available for update"
163-
exit 200
164-
fi
175+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
176+
eval $cmd
177+
178+
if [[ $? -ne 0 ]]; then
179+
echo "ABORTING: router not available for update"
180+
exit 200
181+
fi
165182

183+
fi
166184

167185
###########################################################################################
168186
###########################################################################################
@@ -302,13 +320,17 @@ fi
302320
###########################################################################################
303321
###########################################################################################
304322

305-
# tell IXP Manager the router has been updated:
306-
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_DONE}/${handle} >/dev/null"
307-
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
323+
if [[ $LOCKING_ENABLED -eq 1 ]]; then
308324

309-
until eval $cmd; do
310-
echo "Warning - could not inform IXP Manager via updated API - sleeping 60 secs and trying again"
311-
sleep 60
312-
done
325+
# tell IXP Manager the router has been updated:
326+
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_DONE}/${handle} >/dev/null"
327+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
328+
329+
until eval $cmd; do
330+
echo "Warning - could not inform IXP Manager via updated API - sleeping 60 secs and trying again"
331+
sleep 60
332+
done
333+
334+
fi
313335

314336
exit 0

tools/vagrant/scripts/ixpm-reconfigure-routers-bird2.sh

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
### CONFIGURE ME HERE
2727
###
2828
### This is where YOU need to set your specific IXP Manager installation details.
29-
### Typically you only need to edit the first four.
29+
### Typically you only need to edit the first three settings below.
3030
###
3131
###########################################################################################
3232
###########################################################################################
@@ -63,13 +63,22 @@ LOCKPATH="/tmp/ixp-manager-locks"
6363
# Parse arguments
6464
export DEBUG=0
6565
export FORCE_RELOAD=0
66+
export LOCKING_ENABLED=1
6667

6768
function show_help {
68-
echo "$0 [-d] [-f] -h <handle> [-?]"
69+
cat <<END_HELP
70+
$0 [-d] [-f] [-s] -h <handle> [-?]
71+
72+
-d Enable debug mode, show all commands as they are run
73+
-f Force reload of BIRD, even if config is unchnaged
74+
-h Router handle to update (required)
75+
-s Skip lock - reads config, even if router is paused or locked
76+
77+
END_HELP
6978
}
7079

7180

72-
while getopts "?qdfh:" opt; do
81+
while getopts "?dfsh:" opt; do
7382
case "$opt" in
7483
\?)
7584
show_help
@@ -81,6 +90,8 @@ while getopts "?qdfh:" opt; do
8190
;;
8291
h) handle=$OPTARG
8392
;;
93+
s) export LOCKING_ENABLED=0
94+
;;
8495
esac
8596
done
8697

@@ -92,6 +103,7 @@ fi
92103
# check we're allowed to use this handle here
93104
if [[ "$ALLOWED_HANDLES" != *"$handle"* ]]; then
94105
echo "$handle not allowed here. Should be one of $ALLOWED_HANDLES."
106+
exit 1
95107
fi
96108

97109

@@ -142,25 +154,32 @@ fi
142154
release_ixpmanager_lock() {
143155
### Tell IXP Manager that the config never started and release the lock
144156

145-
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_RELEASE}/${handle} >/dev/null"
146-
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
157+
if [[ $LOCKING_ENABLED -eq 1 ]]; then
147158

148-
until eval $cmd; do
149-
echo "Warning - could not release lock on IXP Manager via API - sleeping 60 secs and trying again"
150-
sleep 60
151-
done
159+
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_RELEASE}/${handle} >/dev/null"
160+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
161+
162+
until eval $cmd; do
163+
echo "Warning - could not release lock on IXP Manager via API - sleeping 60 secs and trying again"
164+
sleep 60
165+
done
166+
167+
fi
152168
}
153169

154-
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_LOCK}/${handle} >/dev/null"
170+
if [[ $LOCKING_ENABLED -eq 1 ]]; then
155171

156-
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
157-
eval $cmd
172+
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_LOCK}/${handle} >/dev/null"
158173

159-
if [[ $? -ne 0 ]]; then
160-
echo "ABORTING: router not available for update"
161-
exit 200
162-
fi
174+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
175+
eval $cmd
163176

177+
if [[ $? -ne 0 ]]; then
178+
echo "ABORTING: router not available for update"
179+
exit 200
180+
fi
181+
182+
fi
164183

165184
###########################################################################################
166185
###########################################################################################
@@ -300,13 +319,17 @@ fi
300319
###########################################################################################
301320
###########################################################################################
302321

303-
# tell IXP Manager the router has been updated:
304-
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_DONE}/${handle} >/dev/null"
305-
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
322+
if [[ $LOCKING_ENABLED -eq 1 ]]; then
306323

307-
until eval $cmd; do
308-
echo "Warning - could not inform IXP Manager via updated API - sleeping 60 secs and trying again"
309-
sleep 60
310-
done
324+
# tell IXP Manager the router has been updated:
325+
cmd="curl --fail -s -X POST -H \"X-IXP-Manager-API-Key: ${APIKEY}\" ${URL_DONE}/${handle} >/dev/null"
326+
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
327+
328+
until eval $cmd; do
329+
echo "Warning - could not inform IXP Manager via updated API - sleeping 60 secs and trying again"
330+
sleep 60
331+
done
332+
333+
fi
311334

312335
exit 0

0 commit comments

Comments
 (0)