From 7d266cc63e920b1c5248d50c66785d5e136b3024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 11 Jul 2011 17:52:51 +0200 Subject: [PATCH 1/8] onedb: more thorough tests --- src/onedb/test/2.2/one.db | Bin 35840 -> 39936 bytes src/onedb/test/create.sh | 90 ++++++++++++++++++++++++++++++++------ src/onedb/test/test.sh | 49 ++++++++++++++++++--- 3 files changed, 119 insertions(+), 20 deletions(-) diff --git a/src/onedb/test/2.2/one.db b/src/onedb/test/2.2/one.db index 5e62d3ad7ddb7dca834c28f8bab144b79e311fc3..62d34ebc1fcc2f47ade38e84f4426988e061ccf9 100644 GIT binary patch delta 2966 zcmb7GU2IfE6rP{EKlF#vHKp=Xb}L)DHc{@qdw=b}6%9!Nsimw`}OA2d7>B0d;IK#c*TBGm|zf_3KJ-D;PZY&V%bb7tmz z=bJg_%-qQj(B!9RW_=0V2fSZxHhK%=&3M6q@7~30oRe2c}i2U(# zi@NRA?ymNM_U`VMrrN%a7uvhq`@Er^_Rc-qA}{XhiuCN<)*TW0`&*i}F0Ce+-4SQk z?mAf30hSOUnd~Yak$((vlXJDJ0R|C7lrTgY`(F8!j46CQB|P2C5qnQ-(S+j#@Yz?Y z$dx@GmUW;dzL-q*6wg;I0L<*Be0v(8AEJu@UCi3&QFuz`mgxG%hEt;hhmGL_DRV#q zV~N8&$@GMYl~`T$CZqzNY!hE~pPB9E9ByzL<#OQlT%chaKxbfE)|OyosvoWfa09I) z&hCZqcr$u!$T*N15D)+~S8kHay)7}pOe9m5De_XvGUCa&C~CYZCS}DCO-a`+O;>e3 zVWi0FUP)Ps{r_jm_8l)hmMCq#YstjkzHmQS&IfvYc#qF@#;3uOEMBuj!(>Gv=u%uX z6S`@{1w}9gNirxcIi<#V1j(9Su~(Et*`il;ll8lvftO!YXi6YTw@3{Tyi= znTzqo250Tif?Pxv_w0xi#-?Iea-KhY9?p(Xmj|8tA`6F94LvNa1Rwm)-{^?)(0&9b6r zOWelZx^xx!Bxopf=vUhA=j0tKS-VfI)76y_t~(0DH5`4AIr^iw$>55{+cQ^qJ!nQtLV3fri5xfOGYU8ix^>6Ow@ z#Ip^doTNAm%hlN!qTe2icntvM3=v!cXdd1KmooN+*r@=j1hCrOPBnxGLehv24X2(F zDUSs|V|1G$_{e9YZq5i#ax?j4hP>oR~e2N2kbC~xFnK?bckb*G<`H^(Kb&hapl@bSa<>&!G;06FU;O`mxO6*h+ z=K;7JKr_bx;!DJTqEG=!{2cKed{*)@c>9iaini%wnq$`NF@WXtpR#ZEF>47xw&$Pe zA^;XC>)blj5tbu)f`DOXR98?Zk?G7FOW0 z;7xEUChoxidIaz|dX%;25lTnNbg8k49?o5MuAXFlPj^#wGvR|q9Uc0OF7bJi_47I# b3$c$;07&Ds6D#`SF8=5W?ro>y#60{5FoO)@ delta 2056 zcma)7U2GIp6h3$Ev|BbUb@_2ie`pnI7qxW$e-bUh7h`l4h!TO6GCOysR?{tkZBv@I z=@da08`IrO6nIkOo6)qL7hfd4Xn6FI5dRVg`X&!ZDm7j2o!xCK_MwwKb9U}I=ljk* z_sp5;Z-nWq!d!D49zyxrv#|GfjN9>Yh^Fu3rro#!KLIi52H~pEj6O#aEJ8P)DI84V zKxn2@pE!HcOLzWGFWrT*=KrhDeC;m4L=(kRPItv#`mf)e5&%A(Odz!D9BOY95kg#O zVd`*#c`_>p<_bo4&<`h_Bzs)pYb#aZwux=DVbU?!(o$ua>#D3Uj?u<74pHPBNQ8HW z&*u6ydTP*kP8=N?>L(*ZL+5f8%>W*8qDM@Yxo{$OohbxaVWNeWK6d1?IodpTs|edP z;5fU*@J+x=_(yyn-^735-|($4AueM2U1M!8O2&8=fObS$gvLl?Xo<7{&5=gX6ls8M zH4IU}(NVQ5oX+FI9I1T@v&H7Hv^`c=Z()22TlgZrjlW(99ta|ygnfk|g=G3w`+oXj zd*{(-ghoJ^ZC&6$PG1K=0P%!7stN#giQF%8TJuA5Rga24b7X;gG3{;NyVxPt#}ST- z^kk)f(9W>bGZ|w<;gor-F6H?;aaEsKnl5L2M^Y?_Sca_Vx-40erV(4$b=S4R(t(<~ zDp*qmOh^iguhojR_dqxc_X@%7hVyZ>1yCp2i7pHR4c_jhGbdVUe!M>HIM#yd=FpK&^%l!1mhhuox)Z?Exh}JV+hTp zVQ|P9@cI=YYV?P!7kg8Nsb^G^c#chE*U@#!P-Rz^iD9U=?dhH`Im9s}LVp<4XmL2p zP|=2{@+#`kfqlA96vtCM;wh%<8LDJuh^PAsE4peKn(O(dW!av9=*>ZeD(?=rcfy9K zQW^Cxp6j!U1mGRW?b9WO_sl}RbY$nLGXsSssM<+r{yv$ zrsbH9Mr7hTu1W}TGnTE`wnD6os@T41__FURepF^9n=R%HS;O3dlh!<`z?%-ui0#qb&Uiv0j90fK$RD zGy>NOK|Yl~j1z#8Y?6s$5+U}g7vF&4tkz+DSL8}7`%E)7leemUa&&!TD614#!_5zkh~j$G8DY)zGDh$(_$6 one_auth$i + oneuser create user_$i pass_$i +done + + +# 5 Hosts for i in 0 1 2 3 4; do onehost create host_$i im_dummy vmm_dummy tm_dummy @@ -18,7 +31,9 @@ done for i in 0 1 2; do ( echo "NAME = vnet_fixed_$i" echo "TYPE = FIXED" + echo "PUBLIC = FIXED" echo "BRIDGE = vbr1" + echo "EXTRA_ATT = \"EXTRA_VALUE FOR VNET $i\"" echo "LEASES = [IP=192.168.$i.1]" echo "LEASES = [IP=192.168.$i.2]" echo "LEASES = [IP=192.168.$i.3]" @@ -26,6 +41,9 @@ for i in 0 1 2; do echo "LEASES = [IP=192.168.$i.5]" ) > $TMP_FILE + # Change auth + export ONE_AUTH="`pwd`/one_auth$i" + onevnet create $TMP_FILE done @@ -37,9 +55,14 @@ for i in 3 4; do echo "BRIDGE = vbr0" echo "NETWORK_SIZE = C" echo "NETWORK_ADDRESS = 192.168.$i.0" + echo "EXTRA_ATT = \"EXTRA_VALUE FOR VNET $i\"" ) > $TMP_FILE + # Change auth + export ONE_AUTH="`pwd`/one_auth$i" + onevnet create $TMP_FILE + onevnet publish $i done # 5 Images @@ -48,17 +71,14 @@ for i in 0 1 2 3 4; do ( echo "NAME = image_$i" echo "TYPE = DATABLOCK" echo "PATH = /dev/null" + echo "EXTRA_ATT = \"EXTRA_VALUE FOR IMG $i\"" ) > $TMP_FILE + export ONE_AUTH="`pwd`/one_auth$i" + oneimage create $TMP_FILE done -# 5 Users - -for i in 0 1 2 3 4; do - oneuser create user_$i pass_$i -done - # 5 VMs for i in 0 1 2 3 4; do @@ -82,23 +102,38 @@ for i in 0 1 2 3 4; do echo "REQUIREMENTS = \"CPUSPEED > 1000\" " echo "RANK = FREECPU " echo "CONTEXT = [ files = \"/dev/null\" ] " + + echo "EXTRA_ATT = \"EXTRA_VALUE FOR VM $i\"" ) > $TMP_FILE + export ONE_AUTH="`pwd`/one_auth$i" + if [ $TWO_SERIES == "yes" ]; then onevm create $TMP_FILE else onetemplate create $TMP_FILE onetemplate instantiate $i fi +done + +if [ -n "$ONEADMIN_AUTH" ] ; then + export ONE_AUTH=$ONEADMIN_AUTH +else + # Unset the one_auth file, cli will look for it in ~/.one/one_auth + unset ONE_AUTH +fi + +for i in 0 1 2 3; 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 +while [ $(onevm list | grep -c runn) -ne 4 ]; do echo -n "." sleep 0.5s done @@ -108,17 +143,34 @@ echo " ok" # Wait for some monitorization data sleep 3s + onevm migrate 0 1 -while [ $(onevm list | grep -c runn) -ne 5 ]; do sleep 0.5s; done +while [ $(onevm list a | grep -c runn) -ne 4 ]; do sleep 0.5s; done + onevm livemigrate 1 2 -while [ $(onevm list | grep -c runn) -ne 5 ]; do sleep 0.5s; done +while [ $(onevm list a | grep -c runn) -ne 4 ]; do sleep 0.5s; done + +onevm stop 1 +while [ $(onevm list a | grep -c stop) -ne 1 ]; do sleep 0.5s; done + +onevm resume 1 +while [ $(onevm list a | grep -c pend) -ne 2 ]; do sleep 0.5s; done + +onevm deploy 1 0 +while [ $(onevm list a | grep -c runn) -ne 4 ]; do sleep 0.5s; done + +onevm migrate 1 3 +while [ $(onevm list a | grep -c runn) -ne 4 ]; do sleep 0.5s; done + +onevm shutdown 1 +while [ $(onevm list a | grep -c runn) -ne 3 ]; do sleep 0.5s; done onevm shutdown 2 -while [ $(onevm list | grep -c runn) -ne 4 ]; do sleep 0.5s; done +while [ $(onevm list a | grep -c runn) -ne 2 ]; do sleep 0.5s; done onevm delete 3 -while [ $(onevm list | grep -c runn) -ne 3 ]; do sleep 0.5s; done +while [ $(onevm list a | grep -c runn) -ne 1 ]; do sleep 0.5s; done onehost disable 3 oneimage persistent 3 @@ -130,8 +182,20 @@ sleep 3s mkdir -p results/xml_files -for obj in host vnet image vm; do +for obj in host vnet image vm user; do + one$obj list -x > results/xml_files/$obj-pool.xml + for i in 0 1 2 3 4; do one$obj show -x $i > results/xml_files/$obj-$i.xml done done + +if [ $TWO_SERIES == "no" ]; then + oneacl list -x > results/xml_files/acl-pool.xml + onegroup list -x > results/xml_files/group-pool.xml +fi + +# Clean one auth files +for i in 0 1 2 3 4; do + rm one_auth$i +done diff --git a/src/onedb/test/test.sh b/src/onedb/test/test.sh index 4af12bc809..274e293b9a 100755 --- a/src/onedb/test/test.sh +++ b/src/onedb/test/test.sh @@ -26,8 +26,12 @@ fi cp oned.conf $ONEDCONF_LOCATION + +echo "oneadmin:oneadmin" > oneadmin_auth export ONE_XMLRPC=http://localhost:2888/RPC2 export PATH=$ONE_LOCATION/bin:$PATH +export ONE_AUTH="`pwd`/oneadmin_auth" + PID=$$ @@ -62,12 +66,16 @@ onedb upgrade -v --sqlite results/one.db.upgraded --backup results/one.db.backup echo "Done. Upgraded DB and the one just created will be compared." # 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 +sqlite3 results/one.db.upgraded ".schema" > results/one.db.upgraded.tmpschema +sqlite3 results/one.db.3.0 ".schema" > results/one.db.3.0.tmpschema # 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 +sort results/one.db.upgraded.tmpschema > results/one.db.upgraded.schema +sort results/one.db.3.0.tmpschema > results/one.db.3.0.schema + +rm results/one.db.upgraded.tmpschema +rm results/one.db.3.0.tmpschema + # Perform a diff @@ -92,12 +100,17 @@ cp results/one.db.upgraded $VAR_LOCATION/one.db oned -f & sleep 2s; -for obj in host vnet image vm; do +for obj in host vnet image vm user; do for i in 0 1 2 3 4; do one$obj show -x $i > results/xml_files/$obj-$i-upgraded.xml done done +for obj in host vnet image vm acl group user; do + one$obj list -x > results/xml_files/$obj-pool-upgraded.xml +done + + pkill -P $PID oned sleep 2s; pkill -9 -P $PID oned @@ -106,6 +119,14 @@ echo "XML output collected. A diff will be performed." mkdir results/diff_files +diff <(grep -v -e "" -e "" -e "NAME>" results/xml_files/host-pool.xml) <(grep -v -e "" -e "" -e "NAME>" results/xml_files/host-pool-upgraded.xml) > results/diff_files/host-pool.diff +diff <(grep -v -e "" -e "" results/xml_files/image-pool.xml) <(grep -v -e "" -e "" results/xml_files/image-pool-upgraded.xml) > results/diff_files/image-pool.diff +diff <(grep -v -e "" -e "TIME>" -e "" -e "" -e "" results/xml_files/vm-pool.xml) <(grep -v -e "" -e "TIME>" -e "" -e "" -e "" results/xml_files/vm-pool-upgraded.xml) > results/diff_files/vm-pool.diff + +for obj in vnet acl group user; do + diff <(cat results/xml_files/$obj-pool.xml) <(cat results/xml_files/$obj-pool-upgraded.xml) > results/diff_files/$obj-pool.diff +done + 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 @@ -113,12 +134,15 @@ for i in 0 1 2 3 4; do 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 + diff <(grep -v -e "" -e "TIME>" -e "" -e "" -e "" -e "" results/xml_files/vm-$i.xml) <(grep -v -e "" -e "TIME>" -e "" -e "" -e "" -e "" results/xml_files/vm-$i-upgraded.xml) > results/diff_files/vm-$i.diff + + diff <(cat results/xml_files/user-$i.xml) <(cat results/xml_files/user-$i-upgraded.xml) > results/diff_files/user-$i.diff done + CODE=0 -for obj in host vnet image vm; do +for obj in host vnet image vm user; do for i in 0 1 2 3 4; do FILE=results/diff_files/$obj-$i.diff if [[ -s $FILE ]] ; then @@ -128,8 +152,19 @@ for obj in host vnet image vm; do done done +for obj in host vnet image vm acl group user; do + FILE=results/diff_files/$obj-pool.diff + if [[ -s $FILE ]] ; then + echo "Error: diff file $FILE is not empty." + CODE=-1 + fi +done + + if [ $CODE -eq 0 ]; then echo "Done, all tests passed." fi +rm oneadmin_auth + exit $CODE From 81054bce3b195020919d420b8d7072c92b5a0316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 11 Jul 2011 17:54:05 +0200 Subject: [PATCH 2/8] onedb: update to latest data structures --- src/onedb/1.rb | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/onedb/1.rb b/src/onedb/1.rb index 86c07f0c04..43260e22b3 100644 --- a/src/onedb/1.rb +++ b/src/onedb/1.rb @@ -46,14 +46,16 @@ module Migrator if( oid == 0 ) gid = 0 + groupname = "oneadmin" else gid = 1 + groupname = "users" user_group_ids += "#{oid}" end name = row[:user_name] - body = "#{oid}#{gid}#{name}#{row[:password]}#{row[:enabled]}#{gid}" + body = "#{oid}#{gid}#{groupname}#{name}#{row[:password]}#{row[:enabled]}" @db.run "INSERT INTO user_pool VALUES(#{oid},'#{name}','#{body}');" end @@ -131,11 +133,12 @@ module Migrator name = row[:name] uid = row[:uid] gid = (uid == 0) ? 0 : 1 + group = (uid == 0) ? "oneadmin" : "users" public = row[:public] # In OpenNebula 2.0 Image States go from 0 to 3, in 3.0 go # from 0 to 5, but the meaning is the same for states 0 to 3 - body = "#{oid}#{row[:uid]}#{gid}#{name}#{row[:type]}#{public}#{row[:persistent]}#{row[:regtime]}#{row[:source]}#{row[:state]}#{row[:running_vms]}#{row[:template]}" + body = "#{oid}#{row[:uid]}#{gid}#{get_username(row[:uid])}#{group}#{name}#{row[:type]}#{public}#{row[:persistent]}#{row[:regtime]}#{row[:source]}#{row[:state]}#{row[:running_vms]}#{row[:template]}" @db.run "INSERT INTO image_pool VALUES(#{oid},'#{name}','#{body}', #{uid}, #{gid}, #{public});" end @@ -177,6 +180,7 @@ module Migrator name = row[:name] uid = row[:uid] gid = (uid == 0) ? 0 : 1 + group = (uid == 0) ? "oneadmin" : "users" last_poll = row[:last_poll] state = row[:state] lcm_state = row[:lcm_state] @@ -187,7 +191,11 @@ module Migrator history = history_row[:body] end - body = "#{oid}#{uid}#{gid}#{name}#{last_poll}#{state}#{lcm_state}#{row[:stime]}#{row[:etime]}#{row[:deploy_id]}#{row[:memory]}#{row[:cpu]}#{row[:net_tx]}#{row[:net_rx]}#{row[:template]}#{history}" + if ( history != "" ) + history = "#{history}" + end + + body = "#{oid}#{uid}#{gid}#{get_username(uid)}#{group}#{name}#{last_poll}#{state}#{lcm_state}#{row[:stime]}#{row[:etime]}#{row[:deploy_id]}#{row[:memory]}#{row[:cpu]}#{row[:net_tx]}#{row[:net_rx]}#{row[:template]}#{history}" @db[:vm_pool].insert( :oid => oid, @@ -228,12 +236,13 @@ module Migrator name = row[:name] uid = row[:uid] gid = (uid == 0) ? 0 : 1 + group = (uid == 0) ? "oneadmin" : "users" public = row[:public] # is stored in the DB, but it is not used to rebuild # the VirtualNetwork object, and it is generated each time the # network is listed. So setting it to 0 is safe - body = "#{oid}#{uid}#{gid}#{name}#{row[:type]}#{row[:bridge]}#{public}0#{row[:template]}" + body = "#{oid}#{uid}#{gid}#{get_username(uid)}#{group}#{name}#{row[:type]}#{row[:bridge]}#{public}0#{row[:template]}" @db.run "INSERT INTO network_pool VALUES(#{oid},'#{name}','#{body}', #{uid}, #{gid}, #{public});" end @@ -259,11 +268,12 @@ module Migrator @db.run "CREATE TABLE db_versioning (oid INTEGER PRIMARY KEY, version INTEGER, timestamp INTEGER, comment VARCHAR(256));" @db.run "CREATE TABLE template_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER);" + @db.run "CREATE TABLE acl (oid INT PRIMARY KEY, user BIGINT, resource BIGINT, rights BIGINT);" # The group pool has two default ones @db.run "CREATE TABLE group_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, UNIQUE(name));" - @db.run "INSERT INTO group_pool VALUES(0,'oneadmin','00oneadmin0');" - @db.run "INSERT INTO group_pool VALUES(1,'users','10users#{user_group_ids}');" + @db.run "INSERT INTO group_pool VALUES(0,'oneadmin','0oneadmin0');" + @db.run "INSERT INTO group_pool VALUES(1,'users','1users#{user_group_ids}');" # New pool_control table contains the last_oid used, must be rebuilt @db.run "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, last_oid BIGINT UNSIGNED)" @@ -282,4 +292,14 @@ module Migrator return true end + + def get_username(uid) + username = "" + + @db.fetch("SELECT name FROM user_pool WHERE oid=#{uid}") do |user| + username = user[:name] + end + + return username + end end From 5a6af308dc2f46ebb1b2d9a613ea5858bf8bb55d Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 11 Jul 2011 17:54:28 +0200 Subject: [PATCH 3/8] CLI list now show objects from your group by default --- src/cli/one_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 683d71f83f..aa67841b22 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -81,8 +81,8 @@ EOT end end - def list_pool(options, top=false, filter_flag=-2) - filter_flag ||= -2 + def list_pool(options, top=false, filter_flag=nil) + filter_flag ||= OpenNebula::Pool::INFO_GROUP pool = factory_pool(filter_flag) From ec1025014859cbd8e0e20311d90aecc576cf9170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 11 Jul 2011 18:31:16 +0200 Subject: [PATCH 4/8] onedb: use sequel interface to sanitize sql strings --- src/onedb/1.rb | 54 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/src/onedb/1.rb b/src/onedb/1.rb index 43260e22b3..98db3116c3 100644 --- a/src/onedb/1.rb +++ b/src/onedb/1.rb @@ -57,7 +57,10 @@ module Migrator body = "#{oid}#{gid}#{groupname}#{name}#{row[:password]}#{row[:enabled]}" - @db.run "INSERT INTO user_pool VALUES(#{oid},'#{name}','#{body}');" + @db[:user_pool].insert( + :oid => oid, + :name => name, + :body => body) end # Delete old user_pool @@ -100,7 +103,12 @@ module Migrator body = "#{oid}#{name}#{state}#{row[:im_mad]}#{row[:vm_mad]}#{row[:tm_mad]}#{last_mon_time}#{host_share}#{ template_doc.to_s }" - @db.run "INSERT INTO host_pool VALUES(#{oid},'#{name}','#{body}', #{state}, #{last_mon_time});" + @db[:host_pool].insert( + :oid => oid, + :name => name, + :body => body, + :state => state, + :last_mon_time => last_mon_time) end # Delete old table @@ -140,7 +148,13 @@ module Migrator # from 0 to 5, but the meaning is the same for states 0 to 3 body = "#{oid}#{row[:uid]}#{gid}#{get_username(row[:uid])}#{group}#{name}#{row[:type]}#{public}#{row[:persistent]}#{row[:regtime]}#{row[:source]}#{row[:state]}#{row[:running_vms]}#{row[:template]}" - @db.run "INSERT INTO image_pool VALUES(#{oid},'#{name}','#{body}', #{uid}, #{gid}, #{public});" + @db[:image_pool].insert( + :oid => oid, + :name => name, + :body => body, + :uid => uid, + :gid => gid, + :public => public) end # Delete old table @@ -170,7 +184,10 @@ module Migrator body = "#{seq}#{row[:host_name]}#{row[:vm_dir]}#{row[:hid]}#{row[:stime]}#{row[:etime]}#{row[:vm_mad]}#{row[:tm_mad]}#{row[:pstime]}#{row[:petime]}#{row[:rstime]}#{row[:retime]}#{row[:estime]}#{row[:eetime]}#{row[:reason]}" - @db.run "INSERT INTO history VALUES(#{vid},'#{seq}','#{body}');" + @db[:history].insert( + :vid => vid, + :seq => seq, + :body => body) end @@ -198,14 +215,14 @@ module Migrator body = "#{oid}#{uid}#{gid}#{get_username(uid)}#{group}#{name}#{last_poll}#{state}#{lcm_state}#{row[:stime]}#{row[:etime]}#{row[:deploy_id]}#{row[:memory]}#{row[:cpu]}#{row[:net_tx]}#{row[:net_rx]}#{row[:template]}#{history}" @db[:vm_pool].insert( - :oid => oid, - :name => name, - :body => body, - :uid => uid, - :gid => gid, - :last_poll => last_poll, - :state => state, - :lcm_state => lcm_state) + :oid => oid, + :name => name, + :body => body, + :uid => uid, + :gid => gid, + :last_poll => last_poll, + :state => state, + :lcm_state => lcm_state) end @@ -244,7 +261,13 @@ module Migrator # network is listed. So setting it to 0 is safe body = "#{oid}#{uid}#{gid}#{get_username(uid)}#{group}#{name}#{row[:type]}#{row[:bridge]}#{public}0#{row[:template]}" - @db.run "INSERT INTO network_pool VALUES(#{oid},'#{name}','#{body}', #{uid}, #{gid}, #{public});" + @db[:network_pool].insert( + :oid => oid, + :name => name, + :body => body, + :uid => uid, + :gid => gid, + :public => public) end # Read each entry in the old table, and insert into new table @@ -254,7 +277,10 @@ module Migrator body = "#{ip}#{row[:mac_prefix]}#{row[:mac_suffix]}#{row[:used]}#{row[:vid]}" - @db.run "INSERT INTO leases VALUES(#{oid}, #{ip}, '#{body}');" + @db[:leases].insert( + :oid => oid, + :ip => ip, + :body => body) end # Delete old tables From 9c1ab345ed83f31fcee8b3aa91a47366f778c8a5 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 11 Jul 2011 18:39:28 +0200 Subject: [PATCH 5/8] Change EC2 user_flags --- src/cloud/ec2/lib/EC2QueryServer.rb | 5 ++--- src/cloud/ec2/lib/views/describe_images.erb | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cloud/ec2/lib/EC2QueryServer.rb b/src/cloud/ec2/lib/EC2QueryServer.rb index 03e7f44ecf..1d8c786729 100644 --- a/src/cloud/ec2/lib/EC2QueryServer.rb +++ b/src/cloud/ec2/lib/EC2QueryServer.rb @@ -161,11 +161,10 @@ class EC2QueryServer < CloudServer end def describe_images(params, one_client) - user_flag=-1 + user_flag = OpenNebula::Pool::INFO_GROUP impool = ImagePool.new(one_client, user_flag) impool.info - erb_user_name = params['AWSAccessKeyId'] erb_version = params['Version'] response = ERB.new(File.read(@config[:views]+"/describe_images.erb")) @@ -221,7 +220,7 @@ class EC2QueryServer < CloudServer end def describe_instances(params, one_client) - user_flag=-1 + user_flag = OpenNebula::Pool::INFO_MINE vmpool = VirtualMachinePool.new(one_client, user_flag) vmpool.info diff --git a/src/cloud/ec2/lib/views/describe_images.erb b/src/cloud/ec2/lib/views/describe_images.erb index 5ef277ad1a..163241c670 100644 --- a/src/cloud/ec2/lib/views/describe_images.erb +++ b/src/cloud/ec2/lib/views/describe_images.erb @@ -13,7 +13,7 @@ <% elsif im['STATE'] == '4'%> pending <% end %> - <%= erb_user_name %> + <%= im['UNAME'] %> <% if im['PUBLIC'] == '0' %> false <% elsif im['PUBLIC'] == '1' %> From 216b798a6cfeb2a581b28918e0f088f297372ff8 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 11 Jul 2011 18:42:22 +0200 Subject: [PATCH 6/8] Fix host_error hook for the new OCA --- share/hooks/host_error.rb | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/share/hooks/host_error.rb b/share/hooks/host_error.rb index 5bf785204f..b4f7864233 100755 --- a/share/hooks/host_error.rb +++ b/share/hooks/host_error.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # @@ -18,9 +18,9 @@ #################################################### # Script to implement host failure tolerance -# It can be set to +# It can be set to # -r resubmit VMs running in the host -# -d delete VMs running in the host +# -d delete VMs running in the host #################################################### ONE_LOCATION=ENV["ONE_LOCATION"] @@ -64,16 +64,18 @@ host.info host_name = host.name # Loop through all vms -vms = VirtualMachinePool.new(client, -2) +vms = VirtualMachinePool.new(client) exit -1 if OpenNebula.is_error?(vms) -vms.info +vms.info_all -vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[STATE=3]/HISTORY[HOSTNAME=\"#{host_name}\"]/../ID") +state = "STATE=3" +state += " or STATE=5" if force == "y" +vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[#{state}]/HISTORY_RECORDS/HISTORY[HOSTNAME=\"#{host_name}\" and last()]/../../ID") if vm_ids_array - vm_ids_array.each do |vm_id| + vm_ids_array.each do |vm_id| vm=OpenNebula::VirtualMachine.new_with_id(vm_id, client) vm.info @@ -85,21 +87,3 @@ if vm_ids_array end end -if force == "y" - vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[STATE=5]/HISTORY[HOSTNAME=\"#{host_name}\"]/../ID") - - if vm_ids_array - vm_ids_array.each do |vm_id| - vm=OpenNebula::VirtualMachine.new_with_id(vm_id, client) - vm.info - - if mode == "-r" - vm.resubmit - elsif mode == "-d" - vm.finalize - end - end - end -end - - From 31cf1331253aab032ae5549f299b8d1a33e66886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 11 Jul 2011 19:10:50 +0200 Subject: [PATCH 7/8] onedb: small fix, one* list now has a different default and needs the 'a' argument --- src/onedb/test/create.sh | 8 ++++---- src/onedb/test/test.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/onedb/test/create.sh b/src/onedb/test/create.sh index 957fe7e463..6a49a6b070 100755 --- a/src/onedb/test/create.sh +++ b/src/onedb/test/create.sh @@ -133,7 +133,7 @@ rm $TMP_FILE echo -n "Waiting until all VMs are running " -while [ $(onevm list | grep -c runn) -ne 4 ]; do +while [ $(onevm list a | grep -c runn) -ne 4 ]; do echo -n "." sleep 0.5s done @@ -183,7 +183,7 @@ sleep 3s mkdir -p results/xml_files for obj in host vnet image vm user; do - one$obj list -x > results/xml_files/$obj-pool.xml + one$obj list a -x > results/xml_files/$obj-pool.xml for i in 0 1 2 3 4; do one$obj show -x $i > results/xml_files/$obj-$i.xml @@ -191,8 +191,8 @@ for obj in host vnet image vm user; do done if [ $TWO_SERIES == "no" ]; then - oneacl list -x > results/xml_files/acl-pool.xml - onegroup list -x > results/xml_files/group-pool.xml + oneacl list a -x > results/xml_files/acl-pool.xml + onegroup list a -x > results/xml_files/group-pool.xml fi # Clean one auth files diff --git a/src/onedb/test/test.sh b/src/onedb/test/test.sh index 274e293b9a..0a7cd2f9cf 100755 --- a/src/onedb/test/test.sh +++ b/src/onedb/test/test.sh @@ -107,7 +107,7 @@ for obj in host vnet image vm user; do done for obj in host vnet image vm acl group user; do - one$obj list -x > results/xml_files/$obj-pool-upgraded.xml + one$obj list a -x > results/xml_files/$obj-pool-upgraded.xml done From 9730e8084cc8be203050e29f4f840726f80a1188 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 11 Jul 2011 19:11:50 +0200 Subject: [PATCH 8/8] Use constants for filter_flag parameters in CLI --- src/cli/one_helper.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index aa67841b22..1a918b89ef 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -219,15 +219,19 @@ EOT def filterflag_to_i(str) filter_flag = case str - when "a", "all" then -2 - when "m", "mine" then -3 - when "g", "group" then -1 + when "a", "all" then OpenNebula::Pool::INFO_ALL + when "m", "mine" then OpenNebula::Pool::INFO_MINE + when "g", "group" then OpenNebula::Pool::INFO_GROUP else if str.match(/^[0123456789]+$/) str.to_i else user = translation_hash[:users].select { |k,v| v==str } - user.length > 0 ? user.first.first.to_i : -2 + if user.length > 0 + user.first.first.to_i + else + OpenNebula::Pool::INFO_GROUP + end end end