diff --git a/src/onedb/test/compare_schema.rb b/src/onedb/test/compare_schema.rb deleted file mode 100644 index f57128fa30..0000000000 --- a/src/onedb/test/compare_schema.rb +++ /dev/null @@ -1,40 +0,0 @@ - -if ARGV.length != 2 - puts "This script requires two file paths to sqlite DBs" - exit -1 -end - - -file_path_a = ARGV[0] -file_path_b = ARGV[1] - -lines_a = Array.new -lines_b = Array.new - - -# The sqlite3 command is used to dump the DB schema it to -# a file - -`sqlite3 #{file_path_a} ".schema" > #{file_path_a}.schema` -`sqlite3 #{file_path_b} ".schema" > #{file_path_b}.schema` - -# Read the lines into an array -File.open( "#{file_path_a}.schema" ) do |f| - lines_a = f.readlines -end - -File.open( "#{file_path_b}.schema" ) do |f| - lines_b = f.readlines -end - - -diff_array = (lines_a | lines_b) - (lines_a & lines_b) - -if !diff_array.empty? - puts "Schema does not match. Conflictive lines:" - puts diff_array - - exit -1 -end - -exit 0 \ No newline at end of file diff --git a/src/onedb/test/create.sh b/src/onedb/test/create.sh index d40c5437b3..c6f817eb76 100755 --- a/src/onedb/test/create.sh +++ b/src/onedb/test/create.sh @@ -27,8 +27,6 @@ for i in 0 1 2; do ) > $TMP_FILE onevnet create $TMP_FILE - - rm $TMP_FILE done # 2 Ranged VNets @@ -42,8 +40,6 @@ for i in 3 4; do ) > $TMP_FILE onevnet create $TMP_FILE - - rm $TMP_FILE done # 5 Images @@ -55,8 +51,6 @@ for i in 0 1 2 3 4; do ) > $TMP_FILE oneimage create $TMP_FILE - - rm $TMP_FILE done # 5 Users @@ -100,6 +94,8 @@ for i in 0 1 2 3 4; do onevm deploy $i $i done +rm $TMP_FILE + echo -n "Waiting until all VMs are running " while [ $(onevm list | grep -c runn) -ne 5 ]; do diff --git a/src/onedb/test/oned.conf b/src/onedb/test/oned.conf index e65954acec..1394fcdd2a 100644 --- a/src/onedb/test/oned.conf +++ b/src/onedb/test/oned.conf @@ -118,10 +118,10 @@ DEFAULT_DEVICE_PREFIX = "hd" # -r number of retries when monitoring a host # -t number of threads, i.e. number of hosts monitored at the same time #------------------------------------------------------------------------------- -IM_MAD = [ - name = "im_kvm", - executable = "one_im_ssh", - arguments = "-r 0 -t 15 kvm" ] +#IM_MAD = [ +# name = "im_kvm", +# executable = "one_im_ssh", +# arguments = "-r 0 -t 15 kvm" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- @@ -186,12 +186,12 @@ IM_MAD = [ name="im_dummy", executable="one_im_dummy"] # -t number of threads, i.e. number of hosts monitored at the same time # -p name of the poll probe (executed locally) #------------------------------------------------------------------------------- -VM_MAD = [ - name = "vmm_kvm", - executable = "one_vmm_ssh", - arguments = "-t 15 -r 0 kvm", - default = "vmm_ssh/vmm_ssh_kvm.conf", - type = "kvm" ] +#VM_MAD = [ +# name = "vmm_kvm", +# executable = "one_vmm_ssh", +# arguments = "-t 15 -r 0 kvm", +# default = "vmm_ssh/vmm_ssh_kvm.conf", +# type = "kvm" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- @@ -247,10 +247,10 @@ VM_MAD = [ name="vmm_dummy", executable="one_vmm_dummy", type="xml" ] #------------------------------------------------------------------------------- # NFS Transfer Manager Driver Configuration #------------------------------------------------------------------------------- -TM_MAD = [ - name = "tm_nfs", - executable = "one_tm", - arguments = "tm_nfs/tm_nfs.conf" ] +#TM_MAD = [ +# name = "tm_nfs", +# executable = "one_tm", +# arguments = "tm_nfs/tm_nfs.conf" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- diff --git a/src/onedb/test/test.sh b/src/onedb/test/test.sh index f3db5d19e1..4af12bc809 100755 --- a/src/onedb/test/test.sh +++ b/src/onedb/test/test.sh @@ -1,5 +1,9 @@ #!/bin/bash +################################################################################ +# Initialization +################################################################################ + if [ -z $ONE_LOCATION ]; then echo "ONE_LOCATION not defined." exit -1 @@ -12,16 +16,6 @@ if [ -f $ONEDCONF_LOCATION ]; then exit -1 fi -cp oned.conf $ONEDCONF_LOCATION - -export ONE_XMLRPC=http://localhost:2888/RPC2 -export PATH=$ONE_LOCATION/bin:$PATH - -if [ -z $ONE_LOCATION ]; then - echo "ONE_LOCATION not defined." - exit -1 -fi - VAR_LOCATION="$ONE_LOCATION/var" if [ -f $VAR_LOCATION/one.db ]; then @@ -30,34 +24,112 @@ if [ -f $VAR_LOCATION/one.db ]; then fi -echo "Starting oned, some resources will be created" +cp oned.conf $ONEDCONF_LOCATION + +export ONE_XMLRPC=http://localhost:2888/RPC2 +export PATH=$ONE_LOCATION/bin:$PATH PID=$$ -oned -f & - -sleep 2s; - mkdir results +################################################################################ +# Start OpenNebula and populate a DB +################################################################################ + +echo "Starting oned, some resources will be created" + +oned -f & +sleep 2s; + ./create.sh pkill -P $PID oned sleep 2s; pkill -9 -P $PID oned +################################################################################ +# Upgrade the 2.2 sample DB, and compare schemas +################################################################################ + echo "All resources created, now 2.2 DB will be upgraded." cp $VAR_LOCATION/one.db results/one.db.3.0 cp 2.2/one.db results/one.db.upgraded -onedb upgrade --sqlite results/one.db.upgraded --backup results/one.db.backup +onedb upgrade -v --sqlite results/one.db.upgraded --backup results/one.db.backup -echo "Done. Upgraded DB and the one created will be compared." +echo "Done. Upgraded DB and the one just created will be compared." -ruby compare_schema.rb results/one.db.upgraded results/one.db.3.0 +# Dump both DB schemas +sqlite3 results/one.db.upgraded ".schema" > results/one.db.upgraded.schema +sqlite3 results/one.db.3.0 ".schema" > results/one.db.3.0.schema -CODE=$? +# Sort the files contents, to avoid false diff errors +sort results/one.db.upgraded.schema > results/one.db.upgraded.schema +sort results/one.db.3.0.schema > results/one.db.3.0.schema -exit $CODE \ No newline at end of file +# Perform a diff +FILE=results/schema.diff +diff results/one.db.upgraded.schema results/one.db.3.0.schema > $FILE + + +if [[ -s $FILE ]] ; then + echo "Error: Schemas do not match. Check file $FILE" + exit -1 +fi + + +################################################################################ +# Start oned using the upgraded DB and compare objects XMLs +################################################################################ + +echo "Schemas match. OpenNebula 3.0 will be started with the upgraded 2.2 DB." + +cp results/one.db.upgraded $VAR_LOCATION/one.db + +oned -f & +sleep 2s; + +for obj in host vnet image vm; do + for i in 0 1 2 3 4; do + one$obj show -x $i > results/xml_files/$obj-$i-upgraded.xml + done +done + +pkill -P $PID oned +sleep 2s; +pkill -9 -P $PID oned + +echo "XML output collected. A diff will be performed." + +mkdir results/diff_files + +for i in 0 1 2 3 4; do + diff <(grep -v -e "" -e "" -e "NAME>" results/xml_files/host-$i.xml) <(grep -v -e "" -e "" -e "NAME>" results/xml_files/host-$i-upgraded.xml) > results/diff_files/host-$i.diff + + diff <(cat results/xml_files/vnet-$i.xml) <(cat results/xml_files/vnet-$i-upgraded.xml) > results/diff_files/vnet-$i.diff + + diff <(grep -v -e "" -e "" results/xml_files/image-$i.xml) <(grep -v -e "" -e "" results/xml_files/image-$i-upgraded.xml) > results/diff_files/image-$i.diff + + diff <(grep -v -e "" -e "TIME>" -e "" -e "" -e "" results/xml_files/vm-$i.xml) <(grep -v -e "" -e "TIME>" -e "" -e "" -e "" results/xml_files/vm-$i-upgraded.xml) > results/diff_files/vm-$i.diff +done + +CODE=0 + +for obj in host vnet image vm; do + for i in 0 1 2 3 4; do + FILE=results/diff_files/$obj-$i.diff + if [[ -s $FILE ]] ; then + echo "Error: diff file $FILE is not empty." + CODE=-1 + fi + done +done + +if [ $CODE -eq 0 ]; then + echo "Done, all tests passed." +fi + +exit $CODE