Commit 6bae8d66 authored by Jérome Perrin's avatar Jérome Perrin

slaprunner: dynamically guess table names in slapproxy database

Using `software11` breaks now that the version of the database was
increased in slapos.core!76

/reviewed-on !483
parent 9d700b96
...@@ -22,7 +22,7 @@ md5sum = d9096d49eda70f3aa02c44615077f6c9 ...@@ -22,7 +22,7 @@ md5sum = d9096d49eda70f3aa02c44615077f6c9
[template-runner-import-script] [template-runner-import-script]
filename = template/runner-import.sh.jinja2 filename = template/runner-import.sh.jinja2
md5sum = ed2e08c07a6727b2012f15da67c0705d md5sum = ed6dc50713c14e2527b9958d98674eed
[instance-runner-import] [instance-runner-import]
filename = instance-runner-import.cfg.in filename = instance-runner-import.cfg.in
......
...@@ -150,10 +150,18 @@ if [ ! -s "$DATABASE" ]; then ...@@ -150,10 +150,18 @@ if [ ! -s "$DATABASE" ]; then
echo 0 > $RESTORE_EXIT_CODE_FILE echo 0 > $RESTORE_EXIT_CODE_FILE
exit 0 exit 0
fi fi
# Slap proxy table contain version number, find the table name dynamically.
# This is known to work with version 11 or 12 of tables, but it will probably
# work with earlier versions as well.
DB_PARTITION_TABLE=$(db_query ".table partition__")
DB_PARTITION_NETWORK_TABLE=$(db_query ".table partition\_network__")
DB_SOFTWARE_TABLE=$(db_query ".table software__")
# Change slapproxy database to point instances to new software release # Change slapproxy database to point instances to new software release
# XXX hardcoded # XXX hardcoded
PARTITION=$(basename $HOME) PARTITION=$(basename $HOME)
OLD_SOFTWARE_RELEASE=$(db_query "select software_release from partition11 where reference='slappart0';") OLD_SOFTWARE_RELEASE=$(db_query "select software_release from $DB_PARTITION_TABLE where reference='slappart0';")
SOFTWARE_RELEASE=$({{ sys.executable }} - $OLD_SOFTWARE_RELEASE $PARTITION <<EOF SOFTWARE_RELEASE=$({{ sys.executable }} - $OLD_SOFTWARE_RELEASE $PARTITION <<EOF
if 1: if 1:
import os, re, sys import os, re, sys
...@@ -167,15 +175,15 @@ if 1: ...@@ -167,15 +175,15 @@ if 1:
EOF EOF
) )
db_query "update partition11 set software_release='$SOFTWARE_RELEASE' where software_release NOT NULL;" db_query "update $DB_PARTITION_TABLE set software_release='$SOFTWARE_RELEASE' where software_release NOT NULL;"
db_query "update software11 set url='$SOFTWARE_RELEASE' where url='$OLD_SOFTWARE_RELEASE';" || db_query "delete from software11 where url='$OLD_SOFTWARE_RELEASE';" db_query "update $DB_SOFTWARE_TABLE set url='$SOFTWARE_RELEASE' where url='$OLD_SOFTWARE_RELEASE';" || db_query "delete from $DB_SOFTWARE_TABLE where url='$OLD_SOFTWARE_RELEASE';"
# Change slapproxy database to have all instances stopped # Change slapproxy database to have all instances stopped
db_query "update partition11 set requested_state='stopped';" db_query "update $DB_PARTITION_TABLE set requested_state='stopped';"
# Change slapproxy database to get correct IPs # Change slapproxy database to get correct IPs
IPV4='{{ ipv4 }}' IPV4='{{ ipv4 }}'
IPV6='{{ ipv6 }}' IPV6='{{ ipv6 }}'
db_query "update partition_network11 set address='$IPV4' where netmask='255.255.255.255';" db_query "update $DB_PARTITION_NETWORK_TABLE set address='$IPV4' where netmask='255.255.255.255';"
db_query "update partition_network11 set address='$IPV6' where netmask='ffff:ffff:ffff::';" db_query "update $DB_PARTITION_NETWORK_TABLE set address='$IPV6' where netmask='ffff:ffff:ffff::';"
MASTERURL='http://{{ ipv4 }}:{{ proxy_port }}' MASTERURL='http://{{ ipv4 }}:{{ proxy_port }}'
...@@ -189,7 +197,7 @@ SLAPGRIDCPLOG='{{ supervisord["slapgrid-cp-log"] }}' ...@@ -189,7 +197,7 @@ SLAPGRIDCPLOG='{{ supervisord["slapgrid-cp-log"] }}'
contain_software_release=0 contain_software_release=0
SOFTWARE_RELEASES_COUNT=$("$SQLITE3" "$DATABASE" 'SELECT count(1) FROM software11 WHERE url != "";') SOFTWARE_RELEASES_COUNT=$(db_query "SELECT count(1) FROM $DB_SOFTWARE_TABLE WHERE url != '';")
if [ $SOFTWARE_RELEASES_COUNT -gt 0 ]; then if [ $SOFTWARE_RELEASES_COUNT -gt 0 ]; then
contain_software_release=1 contain_software_release=1
fi fi
...@@ -243,7 +251,7 @@ done ...@@ -243,7 +251,7 @@ done
# Change back slapproxy database to have all instances started # Change back slapproxy database to have all instances started
log_message "Set instances as to start after takeover..." log_message "Set instances as to start after takeover..."
db_query "update partition11 set requested_state='started';" db_query "update $DB_PARTITION_TABLE set requested_state='started';"
# Write exit code to an arbitrary file that will be checked by promise/monitor # Write exit code to an arbitrary file that will be checked by promise/monitor
log_message "Writing status file... End" log_message "Writing status file... End"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment