Eli Mesika has posted comments on this change.
Change subject: core: Don't try to modify template0
......................................................................
Patch Set 1: (40 inline comments)
....................................................
File backend/manager/dbscripts/create_db_devel.sh
Line 45: printf "Failed to create database ${DATABASE}\n"
Line 46: exit 1;
Line 47: fi
Line 48: printf "Setting development configuration values ...\n"
Line 49: execute_file "config_devel.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT}> /dev/null
same
Line 50: ret=$?
Line 51: printf "Development setting done.\n"
....................................................
File backend/manager/dbscripts/create_db.sh
Line 6: #setting defaults
Line 7: set_defaults
Line 8:
Line 9: usage() {
Line 10: printf "Usage: ${ME} [-h] [-s SERVERNAME [-p PORT]] [-d DATABASE]
[-u USERNAME] [-f UUID] [-l LOGFILE] [-v]\n"
You should add the new parameter also here as an optional parameter
Line 11: printf "\n"
Line 12: printf "\t-s SERVERNAME - The database servername for the database
(def. ${SERVERNAME})\n"
Line 13: printf "\t-p PORT - The database port for the database
(def. ${PORT})\n"
Line 14: printf "\t-d DATABASE - The database name
(def. ${DATABASE})\n"
Line 45: done
Line 46:
Line 47: printf "Creating the database: ${DATABASE}\n"
Line 48: #try to drop the database first (if exists)
Line 49: dropdb --username=${ADMINNAME} --host=${SERVERNAME} --port=${PORT}
${DATABASE} -e > /dev/null
prior to that please check if ADMINNAME was given , if not , set ADMINNAME to
the value of USERNAME
Line 50: createdb --username=${ADMINNAME} --host=${SERVERNAME} --port=${PORT}
--owner=${USERNAME} ${DATABASE} -e -E UTF8 -T template0 > /dev/null
Line 51: if [ $? -ne 0 ]
Line 52: then
Line 53: printf "Failed to create database ${DATABASE}\n"
Line 55: fi
Line 56: createlang --host=${SERVERNAME} --port=${PORT} --dbname=${DATABASE}
--echo --username=${ADMINNAME} plpgsql >& /dev/null
Line 57: #set database min error level
Line 58: CMD="ALTER DATABASE \"${DATABASE}\" SET client_min_messages=ERROR;"
Line 59: execute_command "${CMD}" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT}> /dev/null
I prefer that USERNAME will be the last parameter , will explain in dbfunctions
review
Line 60: printf "Inserting UUID functions...\n"
Line 61:
Line 62: echo user name is: ${USERNAME}
Line 63:
Line 63:
Line 64: check_and_install_uuid_osspa ${UUID}
Line 65:
Line 66: printf "Creating tables...\n"
Line 67: execute_file "create_tables.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
same
Line 68:
Line 69: printf "Creating functions...\n"
Line 70: execute_file "create_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 71:
Line 66: printf "Creating tables...\n"
Line 67: execute_file "create_tables.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
Line 68:
Line 69: printf "Creating functions...\n"
Line 70: execute_file "create_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 71:
Line 72: printf "Creating common functions...\n"
Line 73: execute_file "common_sp.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
Line 74:
Line 69: printf "Creating functions...\n"
Line 70: execute_file "create_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 71:
Line 72: printf "Creating common functions...\n"
Line 73: execute_file "common_sp.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
same
Line 74:
Line 75: #inserting initial data
Line 76: insert_initial_data
Line 77:
....................................................
File backend/manager/dbscripts/dbcustomfunctions.sh
Line 1: #!/bin/bash
Line 2:
Line 3: insert_initial_data() {
Line 4: printf "Inserting data ...\n"
Line 5: execute_file "insert_data.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 6: printf "Inserting pre-defined roles ...\n"
Line 7: execute_file "insert_predefined_roles.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 8: }
Line 9:
Line 3: insert_initial_data() {
Line 4: printf "Inserting data ...\n"
Line 5: execute_file "insert_data.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 6: printf "Inserting pre-defined roles ...\n"
Line 7: execute_file "insert_predefined_roles.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 8: }
Line 9:
Line 10: set_defaults() {
Line 11: ME=$(basename $0)
Line 12: SERVERNAME="localhost"
Line 13: PORT="5432"
Line 14: DATABASE="engine"
Line 15: USERNAME="engine"
Line 16: ADMINNAME="postgres"
I think that this must be empty , having ADMINNAME=USERNAME if not given
explicitly and get all development scripts run without any change
Line 17: VERBOSE=false
Line 18: LOGFILE="$ME.log"
Line 19: export PGPASSFILE="/etc/ovirt-engine/.pgpass"
Line 20: }
Line 21:
Line 22: #refreshes views
Line 23: refresh_views() {
Line 24: printf "Creating views...\n"
Line 25: execute_file "create_views.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 26: execute_file "create_dwh_views.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 27: }
Line 22: #refreshes views
Line 23: refresh_views() {
Line 24: printf "Creating views...\n"
Line 25: execute_file "create_views.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 26: execute_file "create_dwh_views.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 27: }
....................................................
File backend/manager/dbscripts/dbfunctions.sh
Line 1: #!/bin/bash
Line 2:
Line 3: # $1 - the command to execute
Line 4: # $2 - the user name to use to connect to the database
put that as last parameter
Line 5: # $3 - the database to use
Line 6: # $4 - db hostname (default 'localhost' or '')
Line 7: # $5 - db port (default '5432')
Line 8: execute_command () {
Line 6: # $4 - db hostname (default 'localhost' or '')
Line 7: # $5 - db port (default '5432')
Line 8: execute_command () {
Line 9: local command=${1}
Line 10: local dbuser=${2}
same
Line 11: local dbname=${3}
Line 12: local dbhost=${4}
Line 13: local dbport=${5}
Line 14: local filename=$(mktemp)
Line 14: local filename=$(mktemp)
Line 15:
Line 16: printf "${command}\n" > $filename
Line 17:
Line 18: execute_file $filename $dbuser $dbname $dbhost $dbport
same
Line 19:
Line 20: rm $filename
Line 21: }
Line 22:
Line 20: rm $filename
Line 21: }
Line 22:
Line 23: # $1 - the file to execute
Line 24: # $2 - the user name to use to connect to the database
same
Line 25: # $3 - the database to use
Line 26: # $4 - db hostname (default 'localhost' or '')
Line 27: # $5 - db port (default '5432')
Line 28: execute_file () {
Line 26: # $4 - db hostname (default 'localhost' or '')
Line 27: # $5 - db port (default '5432')
Line 28: execute_file () {
Line 29: local filename=${1}
Line 30: local dbuser=${2}
same
Line 31: local dbname=${3}
Line 32: local dbhost=${4}
Line 33: local dbport=${5}
Line 34: local ret_instead_exit=${6}
Line 40: if [[ -n "${dbname}" ]]; then
Line 41: cmdline="${cmdline} --dbname=${dbname} "
Line 42: fi
Line 43:
Line 44: if [[ -n "${dbuser}" ]]; then
Now that dbuser is the last parameter, you can omit it in some calls and take
the $USERNAME default if not given explicitly
Line 45: cmdline="${cmdline} --username=${dbuser} "
Line 46: fi
Line 47:
Line 48: if [[ -n "${dbhost}" ]]; then
Line 74:
Line 75: #drops views before upgrade or refresh operations
Line 76: drop_views() {
Line 77: # common stored procedures are executed first (for new added functions
to be valid)
Line 78: execute_file "common_sp.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
not needed
Line 79: CMD="select * from generate_drop_all_views_syntax();"
Line 80: execute_command "$CMD" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > drop_all_views.sql
Line 81: execute_file "drop_all_views.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT}> /dev/null
Line 82: \rm -f drop_all_views.sql
Line 76: drop_views() {
Line 77: # common stored procedures are executed first (for new added functions
to be valid)
Line 78: execute_file "common_sp.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
Line 79: CMD="select * from generate_drop_all_views_syntax();"
Line 80: execute_command "$CMD" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > drop_all_views.sql
same
Line 81: execute_file "drop_all_views.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT}> /dev/null
Line 82: \rm -f drop_all_views.sql
Line 83: }
Line 84:
Line 77: # common stored procedures are executed first (for new added functions
to be valid)
Line 78: execute_file "common_sp.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
Line 79: CMD="select * from generate_drop_all_views_syntax();"
Line 80: execute_command "$CMD" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > drop_all_views.sql
Line 81: execute_file "drop_all_views.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT}> /dev/null
same
Line 82: \rm -f drop_all_views.sql
Line 83: }
Line 84:
Line 85: #drops sps before upgrade or refresh operations
Line 84:
Line 85: #drops sps before upgrade or refresh operations
Line 86: drop_sps() {
Line 87: # common stored procedures are executed first (for new added functions
to be valid)
Line 88: execute_file "common_sp.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
same
Line 89: CMD="select * from generate_drop_all_functions_syntax();"
Line 90: execute_command "$CMD" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > drop_all_functions.sql
Line 91: execute_file "drop_all_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 92: \rm -f drop_all_functions.sql
Line 86: drop_sps() {
Line 87: # common stored procedures are executed first (for new added functions
to be valid)
Line 88: execute_file "common_sp.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
Line 89: CMD="select * from generate_drop_all_functions_syntax();"
Line 90: execute_command "$CMD" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > drop_all_functions.sql
same
Line 91: execute_file "drop_all_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 92: \rm -f drop_all_functions.sql
Line 93: # recreate generic functions
Line 94: execute_file "create_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 87: # common stored procedures are executed first (for new added functions
to be valid)
Line 88: execute_file "common_sp.sql" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
Line 89: CMD="select * from generate_drop_all_functions_syntax();"
Line 90: execute_command "$CMD" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > drop_all_functions.sql
Line 91: execute_file "drop_all_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 92: \rm -f drop_all_functions.sql
Line 93: # recreate generic functions
Line 94: execute_file "create_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 95: }
Line 90: execute_command "$CMD" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > drop_all_functions.sql
Line 91: execute_file "drop_all_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 92: \rm -f drop_all_functions.sql
Line 93: # recreate generic functions
Line 94: execute_file "create_functions.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 95: }
Line 96:
Line 97: #refreshes sps
Line 98: refresh_sps() {
Line 98: refresh_sps() {
Line 99: printf "Creating stored procedures...\n"
Line 100: for sql in $(ls *sp.sql); do
Line 101: printf "Creating stored procedures from $sql ...\n"
Line 102: execute_file $sql ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
same
Line 103: done
Line 104: execute_file "common_sp.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 105: }
Line 106:
Line 105: }
Line 106:
Line 107: install_common_func() {
Line 108: # common stored procedures are executed first (for new added
functions to be valid)
Line 109: execute_file "common_sp.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 110: }
Line 111:
Line 112: delete_async_tasks_and_compensation_data() {
Line 113: execute_file "delete_async_tasks_and_compensation_data.sql"
${USERNAME} ${DATABASE} ${SERVERNAME} ${PORT}> /dev/null
Line 109: execute_file "common_sp.sql" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 110: }
Line 111:
Line 112: delete_async_tasks_and_compensation_data() {
Line 113: execute_file "delete_async_tasks_and_compensation_data.sql"
${USERNAME} ${DATABASE} ${SERVERNAME} ${PORT}> /dev/null
same
Line 114: }
Line 115:
Line 116: run_pre_upgrade() {
Line 117: #Dropping all views & sps
Line 152: export DATABASE="${DATABASE}" SERVERNAME="${SERVERNAME}"
PORT="${PORT}" USERNAME="${USERNAME}"
Line 153: ./$execFile
Line 154: else
Line 155: echo "Running $2 upgrade sql script $execFile ..."
Line 156: execute_file $execFile ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT} > /dev/null
same
Line 157: fi
Line 158: }
Line 159:
Line 160: set_version() {
Line 157: fi
Line 158: }
Line 159:
Line 160: set_version() {
Line 161: execute_file upgrade/03_00_0000_add_schema_version.sql
${USERNAME} ${DATABASE} ${SERVERNAME} ${PORT} > /dev/null
same
Line 162: if [ -n "${VERSION}" ]; then
Line 163: CMD="update schema_version set current=true where
version=trim('${VERSION}');"
Line 164: execute_command "${CMD}" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
Line 165: fi
Line 160: set_version() {
Line 161: execute_file upgrade/03_00_0000_add_schema_version.sql
${USERNAME} ${DATABASE} ${SERVERNAME} ${PORT} > /dev/null
Line 162: if [ -n "${VERSION}" ]; then
Line 163: CMD="update schema_version set current=true where
version=trim('${VERSION}');"
Line 164: execute_command "${CMD}" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 165: fi
Line 166: }
Line 167:
Line 168: get_current_version() {
Line 181: }
Line 182: set_last_version() {
Line 183: id=$(get_last_installed_id)
Line 184: CMD="update schema_version set current=(id=$id);"
Line 185: execute_command "${CMD}" ${USERNAME} ${DATABASE} ${SERVERNAME}
${PORT}> /dev/null
same
Line 186: }
Line 187:
Line 188: get_db_time(){
Line 189: echo "select now();" | psql -U ${USERNAME} --pset=tuples_only=on
${DATABASE} -h ${SERVERNAME} -p ${PORT}
Line 297: fi
Line 298: CMD="insert into
schema_version(version,script,checksum,installed_by,started_at,ended_at,state,current,comment)
Line 299: values
(trim('$ver'),'$file','$checksum','${USERNAME}',
Line 300: cast(trim('$before') as
timestamp),cast(trim('$after') as timestamp),'$state',false,'$comment');"
Line 301: execute_command "${CMD}" ${USERNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
same
Line 302: fi
Line 303: done
Line 304: set_last_version
Line 305:
Line 332:
Line 333: check_and_install_uuid_osspa_pg9() {
Line 334: # Checks that the extension is installed
Line 335: CMD_CHECK_INSTALLED="SELECT COUNT(extname) FROM pg_extension
WHERE extname='uuid-ossp';"
Line 336: UUID_INSTALLED=$(expr `execute_command "${CMD_CHECK_INSTALLED}"
${ADMINNAME} ${DATABASE} ${SERVERNAME} ${PORT}`)
set ADMINNAME as last parameter , it should be equal to USERNAME if not set
explicitly
Line 337: # Checks that the extension can be installed
Line 338: CMD_CHECK_AVAILABLE="SELECT COUNT(name) FROM
pg_available_extensions WHERE name='uuid-ossp';"
Line 339: UUID_AVAILABLE=$(expr `execute_command "${CMD_CHECK_AVAILABLE}"
${ADMINNAME} ${DATABASE} ${SERVERNAME} ${PORT}`)
Line 340:
Line 335: CMD_CHECK_INSTALLED="SELECT COUNT(extname) FROM pg_extension
WHERE extname='uuid-ossp';"
Line 336: UUID_INSTALLED=$(expr `execute_command "${CMD_CHECK_INSTALLED}"
${ADMINNAME} ${DATABASE} ${SERVERNAME} ${PORT}`)
Line 337: # Checks that the extension can be installed
Line 338: CMD_CHECK_AVAILABLE="SELECT COUNT(name) FROM
pg_available_extensions WHERE name='uuid-ossp';"
Line 339: UUID_AVAILABLE=$(expr `execute_command "${CMD_CHECK_AVAILABLE}"
${ADMINNAME} ${DATABASE} ${SERVERNAME} ${PORT}`)
set ADMINNAME as last parameter , it should be equal to USERNAME if not set
explicitly
Line 340:
Line 341: # If uuid is not installed, check whether it's available and
install
Line 342: if [ $UUID_INSTALLED -eq 1 ]; then
Line 343: return 0
Line 345: if [ $UUID_AVAILABLE -eq 0 ]; then
Line 346: return 1
Line 347: else
Line 348: CMD="CREATE EXTENSION \"uuid-ossp\";"
Line 349: execute_command "${CMD}" ${ADMINNAME} ${DATABASE}
${SERVERNAME} ${PORT} > /dev/null
set ADMINNAME as last parameter , it should be equal to USERNAME if not set
explicitly
Line 350: return $?
Line 351: fi
Line 352: fi
Line 353: }
Line 391: local user=${3}
Line 392: msg="System user ${user} run unlock_entity script on
${object_type} ${id} with db user ${USERNAME}"
Line 393: CMD="insert into
audit_log(log_time,log_type_name,log_type,severity,message)
Line 394: values(now(), 'USER_RUN_UNLOCK_ENTITY_SCRIPT', 2024, 10,
'${msg}')"
Line 395: execute_command "${CMD}" "${USERNAME}" "${DATABASE}"
"${SERVERNAME}" "${PORT}"
USERNAME is not needed here
Line 396: }
Line 397:
Line 398:
Line 399: #unlocks the given VM/Template and its disks or a given disk
Line 416: fi
Line 417:
Line 418: if [ "${CMD}" != "" ]; then
Line 419: echo "${CMD}"
Line 420: execute_command "${CMD}" "${USERNAME}" "${DATABASE}"
"${SERVERNAME}" "${PORT}"
same
Line 421: if [ $? -eq 0 ]; then
Line 422: log_unlock_entity ${object_type} ${id} ${user}
Line 423: printf "unlock ${object_type} ${id} completed
successfully."
Line 424: else
....................................................
File backend/manager/dbscripts/upgrade/03_00_0420_encrypt_pm_passwd.sh
Line 1: #!/bin/bash
Line 2:
Line 3: #include db general functions
We can not change existent upgrade scripts since it will not install again if
already installed , you should leave the file as is since the USERNAME
parameter is not mandatory here , we can use the one that was given
Line 4: source ./dbfunctions.sh
Line 5:
Line 6: # get configuration values needed for password encryption from DB
Line 7:
....................................................
File backend/manager/dbscripts/upgrade/03_01_1440_encrypt_chap_password.sh
Line 1: #!/bin/sh
Line 2:
Line 3: #include db general functions
We can not change existent upgrade scripts since it will not install again if
already installed , you should leave the file as is since the USERNAME
parameter is not mandatory here , we can use the one that was given
Line 4: source ./dbfunctions.sh
Line 5:
Line 6: # get configuration values needed for password encryption from DB
Line 7: certificate="$(get_config_value "CertificateFileName" "general")"
--
To view, visit http://gerrit.ovirt.org/8926
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I646702a3af5013a8950f45fa507ceb29796583e1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
Gerrit-Reviewer: Eli Mesika <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches