From 6a9ac5ae0d59e717d4b751013b7ee952631fe769 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 2 Dec 2011 12:44:11 +0100 Subject: [PATCH 1/4] =?UTF-8?q?feature-#863:=20=C3Change=20arguments=20for?= =?UTF-8?q?=20onehost=20create=20to=20ensure=20compatiblity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli/onehost | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/onehost b/src/cli/onehost index adf060ba36..c002900274 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -60,10 +60,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Host EOT - command :create, create_desc, :hostname, :im_mad, :vmm_mad, :vnm_mad, - :tm_mad do + command :create, create_desc, :hostname, :im_mad, :vmm_mad, + :tm_mad, :vnm_mad do helper.create_resource(options) do |host| - host.allocate(args[0], args[1], args[2], args[3], args[4]) + host.allocate(args[0], args[1], args[2], args[4], args[3]) end end From cb1c13c4b7089f119f5bc65a8a2bea8fb1c94968 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 16:59:51 +0100 Subject: [PATCH 2/4] feature #863: fix tests --- src/vnm_mad/remotes/802.1Q/HostManaged.rb | 2 +- src/vnm_mad/remotes/Firewall.rb | 2 +- src/vnm_mad/remotes/OpenNebulaNetwork.rb | 4 +- src/vnm_mad/remotes/OpenNebulaNic.rb | 8 +- .../remotes/test/OpenNebulaNetwork_spec.rb | 76 ++++++++++--------- src/vnm_mad/remotes/test/SystemMock.rb | 5 +- 6 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/vnm_mad/remotes/802.1Q/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb index 8d5194b869..47a65a3cce 100644 --- a/src/vnm_mad/remotes/802.1Q/HostManaged.rb +++ b/src/vnm_mad/remotes/802.1Q/HostManaged.rb @@ -64,7 +64,7 @@ class OpenNebulaHM < OpenNebulaNetwork def device_exists?(dev, vlan=nil) dev = "#{dev}.#{vlan}" if vlan - system("#{COMMANDS[:ip]} link show #{dev}") + OpenNebula.exec_and_log("#{COMMANDS[:ip]} link show #{dev}") end def create_dev_vlan(dev, vlan) diff --git a/src/vnm_mad/remotes/Firewall.rb b/src/vnm_mad/remotes/Firewall.rb index 586481ef05..2cc4f98eca 100644 --- a/src/vnm_mad/remotes/Firewall.rb +++ b/src/vnm_mad/remotes/Firewall.rb @@ -104,7 +104,7 @@ class OpenNebulaFirewall < OpenNebulaNetwork def run_rules(rules) rules.flatten.each do |rule| - system(rule) + OpenNebula.exec_and_log(rule) end end diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index 79c8e14fa4..a6cb14ca55 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -52,7 +52,7 @@ class VM nics = Nics.new(@hypervisor) - @vm_root.elements.each("TEMPLATE/NIC[VLAN=yes]") do |nic_element| + @vm_root.elements.each("TEMPLATE/NIC[VLAN=YES]") do |nic_element| nic = nics.new_nic nic_element.elements.each('*') do |nic_attribute| @@ -98,7 +98,7 @@ class OpenNebulaNetwork def initialize(vm_tpl, hypervisor=nil) if !hypervisor - @hypervisor = detect_hypervisor + @hypervisor = detect_hypervisor else @hypervisor = hypervisor end diff --git a/src/vnm_mad/remotes/OpenNebulaNic.rb b/src/vnm_mad/remotes/OpenNebulaNic.rb index 2872de52ee..84214bd154 100644 --- a/src/vnm_mad/remotes/OpenNebulaNic.rb +++ b/src/vnm_mad/remotes/OpenNebulaNic.rb @@ -31,8 +31,8 @@ class Nics < Array end -# A NIC using KVM. This class implements functions to get the physical interface -# that the NIC is using +# A NIC using KVM. This class implements functions to get the physical interface +# that the NIC is using class NicKVM < Hash def initialize super(nil) @@ -70,8 +70,8 @@ class NicKVM < Hash end -# A NIC using Xen. This class implements functions to get the physical interface -# that the NIC is using +# A NIC using Xen. This class implements functions to get the physical interface +# that the NIC is using class NicXen < Hash def initialize super(nil) diff --git a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb index c8e7c14ccd..3875bd403f 100644 --- a/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb +++ b/src/vnm_mad/remotes/test/OpenNebulaNetwork_spec.rb @@ -1,18 +1,18 @@ #!/usr/bin/env ruby -$: << File.dirname(__FILE__) + '/..' \ - << './' +$: << File.dirname(__FILE__) +$: << File.join(File.dirname(__FILE__), '..') +$: << File.join(File.dirname(__FILE__),'../../../mad/ruby/') require 'rubygems' require 'rspec' -require 'SystemMock' require 'pp' require 'OpenNebulaNetwork' -require 'Ebtables' +require 'ebtables/Ebtables' require 'Firewall' -require 'HostManaged' -require 'OpenvSwitch' +require '802.1Q/HostManaged' +require 'ovswitch/OpenvSwitch' OUTPUT = Hash.new Dir[File.dirname(__FILE__) + "/output/**"].each do |f| @@ -20,6 +20,9 @@ Dir[File.dirname(__FILE__) + "/output/**"].each do |f| OUTPUT[key] = File.read(f) end +require 'scripts_common' +require 'SystemMock' +include OpenNebula include SystemMock RSpec.configure do |config| @@ -56,21 +59,6 @@ describe 'networking' do onevlan.vm.nics.should == nics_expected end - it "filter nics in kvm" do - $capture_commands = { - /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml] - } - onevlan = OpenNebulaNetwork.new(OUTPUT[:onevm_show],"kvm") - onevlan.filter(:bridge => "br1") - nics_expected = [{:bridge=>"br1", - :ip=>"10.1.1.1", - :mac=>"02:00:0a:01:01:01", - :network=>"r1", - :network_id=>"1", - :tap=>"vnet1"}] - - onevlan.vm.filtered_nics.should == nics_expected - end end describe 'ebtables' do @@ -88,7 +76,10 @@ describe 'ebtables' do "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:01:01 -i vnet1 -j DROP", "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:02:00/ff:ff:ff:ff:ff:00 -o vnet2 -j DROP", "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:02:01 -i vnet2 -j DROP"] - $collector[:system].should == ebtables_cmds + + ebtables_cmds.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end end @@ -106,7 +97,9 @@ describe 'openvswitch' do "sudo /usr/local/bin/ovs-vsctl set Port vnet2 tag=4" ] - $collector[:system].should == openvswitch_tags + openvswitch_tags.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end it "force VLAN_ID for Open vSwitch vlans in kvm" do @@ -117,12 +110,14 @@ describe 'openvswitch' do } onevlan = OpenvSwitchVLAN.new(OUTPUT[:onevm_show_vlan_id_kvm],"kvm") onevlan.activate - + onevlan_rules = ["sudo /usr/local/bin/ovs-vsctl set Port vnet0 tag=6", "sudo /usr/local/bin/ovs-vsctl set Port vnet1 tag=50", "sudo /usr/local/bin/ovs-vsctl set Port vnet1 tag=51"] - $collector[:system].should == onevlan_rules + onevlan_rules.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end end @@ -146,7 +141,9 @@ describe 'firewall' do "sudo /sbin/iptables -A one-36-3 -p icmp -m state --state ESTABLISHED -j ACCEPT", "sudo /sbin/iptables -A one-36-3 -p icmp -j DROP"] - $collector[:system].should == fw_activate_rules + fw_activate_rules.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end end @@ -155,20 +152,23 @@ describe 'host-managed' do $capture_commands = { /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml_phydev], /brctl show/ => OUTPUT[:brctl_show], - /brctl add/ => nil, - /vconfig/ => nil, - /ip link/ => nil + /brctl add/ => nil, + /vconfig/ => nil, + /ip link/ => nil } hm = OpenNebulaHM.new(OUTPUT[:onevm_show_phydev_kvm],"kvm") hm.activate - hm_activate_rules = ["sudo /usr/sbin/brctl addbr onebr6", + hm_activate_rules = ["sudo /sbin/brctl addbr onebr6", "sudo /sbin/ip link set onebr6 up", "sudo /sbin/ip link show eth0.8", "sudo /sbin/vconfig add eth0 8", "sudo /sbin/ip link set eth0.8 up", - "sudo /usr/sbin/brctl addif onebr6 eth0.8"] - $collector[:system].should == hm_activate_rules + "sudo /sbin/brctl addif onebr6 eth0.8"] + + hm_activate_rules.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end it "force VLAN_ID for vlans in kvm" do @@ -182,19 +182,21 @@ describe 'host-managed' do hm = OpenNebulaHM.new(OUTPUT[:onevm_show_vlan_id_kvm],"kvm") hm.activate - hm_vlan_id = ["sudo /usr/sbin/brctl addbr onebr10", + hm_vlan_id = ["sudo /sbin/brctl addbr onebr10", "sudo /sbin/ip link set onebr10 up", "sudo /sbin/ip link show eth0.50", "sudo /sbin/vconfig add eth0 50", "sudo /sbin/ip link set eth0.50 up", - "sudo /usr/sbin/brctl addif onebr10 eth0.50", - "sudo /usr/sbin/brctl addbr specialbr", + "sudo /sbin/brctl addif onebr10 eth0.50", + "sudo /sbin/brctl addbr specialbr", "sudo /sbin/ip link set specialbr up", "sudo /sbin/ip link show eth0.51", "sudo /sbin/vconfig add eth0 51", "sudo /sbin/ip link set eth0.51 up", - "sudo /usr/sbin/brctl addif specialbr eth0.51"] + "sudo /sbin/brctl addif specialbr eth0.51"] - $collector[:system].should == hm_vlan_id + hm_vlan_id.map{|c| c + " 2>&1 1>/dev/null"}.each do |cmd| + $collector[:backtick].include?(cmd).should == true + end end end diff --git a/src/vnm_mad/remotes/test/SystemMock.rb b/src/vnm_mad/remotes/test/SystemMock.rb index 9c2d122d47..6e83e85411 100644 --- a/src/vnm_mad/remotes/test/SystemMock.rb +++ b/src/vnm_mad/remotes/test/SystemMock.rb @@ -1,14 +1,15 @@ module SystemMock - require 'open3' + def execute_cmd(cmd) if $capture_commands $capture_commands.each do |regex, output| if cmd.match(regex) + Kernel.send(:`,":;exit 0") return output end end end - Open3.popen3(cmd){|stdin, stdout, stderr| stdout.read} + Kernel.send(:`,cmd) end def `(cmd) From 8649233487bd99b6dd71c7144f003fbb6a7cd431 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 2 Dec 2011 17:37:49 +0100 Subject: [PATCH 3/4] feature 863: fix install.sh --- install.sh | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/install.sh b/install.sh index 151e6fcd5e..e24347fdb8 100755 --- a/install.sh +++ b/install.sh @@ -122,9 +122,9 @@ if [ -z "$ROOT" ] ; then elif [ "$OZONES" = "yes" ]; then MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $VAR_LOCATION $OZONES_LOCATION \ $ETC_LOCATION" - + DELETE_DIRS="$MAKE_DIRS" - + CHOWN_DIRS="" else MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \ @@ -162,8 +162,8 @@ else elif [ "$OZONES" = "yes" ]; then MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $VAR_LOCATION $OZONES_LOCATION \ $ETC_LOCATION" - - DELETE_DIRS="$MAKE_DIRS" + + DELETE_DIRS="$MAKE_DIRS" else MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \ $INCLUDE_LOCATION $SHARE_LOCATION $IMAGES_LOCATION \ @@ -259,7 +259,7 @@ SUNSTONE_DIRS="$SUNSTONE_LOCATION/models \ $SUNSTONE_LOCATION/public/images \ $SUNSTONE_LOCATION/templates \ $SUNSTONE_LOCATION/views" - + OZONES_DIRS="$OZONES_LOCATION/lib \ $OZONES_LOCATION/lib/OZones \ $OZONES_LOCATION/models \ @@ -338,8 +338,8 @@ INSTALL_FILES=( AUTH_SERVER_X509_FILES:$VAR_LOCATION/remotes/auth/server_x509 AUTH_SERVER_CIPHER_FILES:$VAR_LOCATION/remotes/auth/server_cipher AUTH_DUMMY_FILES:$VAR_LOCATION/remotes/auth/dummy - AUTH_PLAIN_FILES:$VAR_LOCATION/remotes/auth/plain - AUTH_QUOTA_FILES:$VAR_LOCATION/remotes/auth/quota + AUTH_PLAIN_FILES:$VAR_LOCATION/remotes/auth/plain + AUTH_QUOTA_FILES:$VAR_LOCATION/remotes/auth/quota VMM_EXEC_KVM_SCRIPTS:$VAR_LOCATION/remotes/vmm/kvm VMM_EXEC_XEN_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen SHARED_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/shared @@ -628,7 +628,8 @@ AUTH_QUOTA_FILES="src/authm_mad/remotes/quota/authorize" #------------------------------------------------------------------------------- NETWORK_FILES="src/vnm_mad/remotes/OpenNebulaNetwork.rb \ - src/vnm_mad/remotes/OpenNebulaNic.rb" + src/vnm_mad/remotes/Firewall.rb \ + src/vnm_mad/remotes/OpenNebulaNic.rb" NETWORK_8021Q_FILES="src/vnm_mad/remotes/802.1Q/clean \ src/vnm_mad/remotes/802.1Q/post \ @@ -644,8 +645,9 @@ NETWORK_EBTABLES_FILES="src/vnm_mad/remotes/ebtables/clean \ src/vnm_mad/remotes/ebtables/pre \ src/vnm_mad/remotes/ebtables/Ebtables.rb" -NETWORK_FW_FILES="src/vnm_mad/remotes/fw/firewall \ - src/vnm_mad/remotes/fw/Firewall.rb" +NETWORK_FW_FILES="src/vnm_mad/remotes/fw/post \ + src/vnm_mad/remotes/fw/pre \ + src/vnm_mad/remotes/fw/clean" NETWORK_OVSWITCH_FILES="src/vnm_mad/remotes/ovswitch/clean \ src/vnm_mad/remotes/ovswitch/post \ @@ -1066,7 +1068,7 @@ SUNSTONE_PUBLIC_IMAGES_FILES="src/sunstone/public/images/ajax-loader.gif \ src/sunstone/public/images/Refresh-icon.png \ src/sunstone/public/images/vnc_off.png \ src/sunstone/public/images/vnc_on.png" - + #----------------------------------------------------------------------------- # Ozones files #----------------------------------------------------------------------------- @@ -1081,10 +1083,10 @@ OZONES_ETC_FILES="src/ozones/Server/etc/ozones-server.conf" OZONES_MODELS_FILES="src/ozones/Server/models/OzonesServer.rb \ src/ozones/Server/models/Auth.rb \ src/sunstone/models/OpenNebulaJSON/JSONUtils.rb" - + OZONES_TEMPLATE_FILES="src/ozones/Server/templates/index.html \ src/ozones/Server/templates/login.html" - + OZONES_LIB_FILES="src/ozones/Server/lib/OZones.rb" OZONES_LIB_ZONE_FILES="src/ozones/Server/lib/OZones/Zones.rb \ @@ -1098,7 +1100,7 @@ OZONES_LIB_ZONE_FILES="src/ozones/Server/lib/OZones/Zones.rb \ src/ozones/Server/lib/OZones/AggregatedPool.rb \ src/ozones/Server/lib/OZones/AggregatedImages.rb \ src/ozones/Server/lib/OZones/AggregatedTemplates.rb" - + OZONES_LIB_API_FILES="src/ozones/Client/lib/zona.rb" OZONES_LIB_API_ZONA_FILES="src/ozones/Client/lib/zona/ZoneElement.rb \ @@ -1110,7 +1112,7 @@ OZONES_LIB_API_ZONA_FILES="src/ozones/Client/lib/zona/ZoneElement.rb \ src/ozones/Client/lib/zona/ZonePool.rb" OZONES_PUBLIC_VENDOR_JQUERY=$SUNSTONE_PUBLIC_VENDOR_JQUERY - + OZONES_PUBLIC_VENDOR_DATATABLES=$SUNSTONE_PUBLIC_VENDOR_DATATABLES OZONES_PUBLIC_VENDOR_JGROWL=$SUNSTONE_PUBLIC_VENDOR_JGROWL @@ -1118,18 +1120,18 @@ OZONES_PUBLIC_VENDOR_JGROWL=$SUNSTONE_PUBLIC_VENDOR_JGROWL OZONES_PUBLIC_VENDOR_JQUERYUI=$SUNSTONE_PUBLIC_VENDOR_JQUERYUI OZONES_PUBLIC_VENDOR_JQUERYLAYOUT=$SUNSTONE_PUBLIC_VENDOR_JQUERYLAYOUT - + OZONES_PUBLIC_JS_FILES="src/ozones/Server/public/js/ozones.js \ src/ozones/Server/public/js/login.js \ src/ozones/Server/public/js/ozones-util.js \ src/sunstone/public/js/layout.js \ src/sunstone/public/js/sunstone.js \ src/sunstone/public/js/sunstone-util.js" - + OZONES_PUBLIC_CSS_FILES="src/ozones/Server/public/css/application.css \ src/ozones/Server/public/css/layout.css \ src/ozones/Server/public/css/login.css" - + OZONES_PUBLIC_IMAGES_FILES="src/ozones/Server/public/images/panel.png \ src/ozones/Server/public/images/login.png \ src/ozones/Server/public/images/login_over.png \ @@ -1143,16 +1145,16 @@ OZONES_PUBLIC_JS_PLUGINS_FILES="src/ozones/Server/public/js/plugins/zones-tab.js src/ozones/Server/public/js/plugins/vdcs-tab.js \ src/ozones/Server/public/js/plugins/aggregated-tab.js \ src/ozones/Server/public/js/plugins/dashboard-tab.js" - -OZONES_LIB_CLIENT_CLI_FILES="src/ozones/Client/lib/cli/ozones_helper.rb" - + +OZONES_LIB_CLIENT_CLI_FILES="src/ozones/Client/lib/cli/ozones_helper.rb" + OZONES_LIB_CLIENT_CLI_HELPER_FILES="\ src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb \ - src/ozones/Client/lib/cli/ozones_helper/zones_helper.rb" + src/ozones/Client/lib/cli/ozones_helper/zones_helper.rb" OZONES_BIN_CLIENT_FILES="src/ozones/Client/bin/onevdc \ src/ozones/Client/bin/onezone" - + OZONES_RUBY_LIB_FILES="src/oca/ruby/OpenNebula.rb" #----------------------------------------------------------------------------- @@ -1229,7 +1231,7 @@ if [ "$CLIENT" = "yes" ]; then elif [ "$SUNSTONE" = "yes" ]; then INSTALL_SET="${INSTALL_SUNSTONE_RUBY_FILES[@]} ${INSTALL_SUNSTONE_FILES[@]}" elif [ "$OZONES" = "yes" ]; then - INSTALL_SET="${INSTALL_OZONES_RUBY_FILES[@]} ${INSTALL_OZONES_FILES[@]}" + INSTALL_SET="${INSTALL_OZONES_RUBY_FILES[@]} ${INSTALL_OZONES_FILES[@]}" else INSTALL_SET="${INSTALL_FILES[@]} ${INSTALL_OZONES_FILES[@]} \ ${INSTALL_SUNSTONE_FILES[@]}" From d0c3ef099c821b331ba6c2cf61f59b8c7b9ebc94 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Dec 2011 17:46:51 +0100 Subject: [PATCH 4/4] bug: fixes show of history records with some XML parsers --- src/cli/one_helper/onevm_helper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 9ecc4425eb..fdbc07a86e 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -99,9 +99,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false) puts vm.template_str - if vm['/VM/HISTORY_RECORDS/HISTORY'] + if vm.has_elements?("/VM/HISTORY_RECORDS/") puts - + + CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE HISTORY",false) format_history(vm) end