From 92a74bd83b7f57f1d0b1b6122076ff5d13322d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 11 Apr 2011 16:20:44 +0200 Subject: [PATCH] Feature #523: Small oned.conf fix, Add ImageID to one.vm.savedisk XML-RPC method, and Update Java API Image management and tests --- include/RequestManager.h | 3 +- share/etc/oned.conf | 10 -- .../opennebula/client/vm/VirtualMachine.java | 6 +- src/oca/java/test/ImageTest.java | 28 +-- src/oca/java/test/VirtualMachineTest.java | 14 +- src/oca/java/test/oned.conf | 162 ++++++++++++++---- src/oca/java/test/test.sh | 7 +- src/rm/RequestManagerSaveDisk.cc | 1 + 8 files changed, 159 insertions(+), 72 deletions(-) diff --git a/include/RequestManager.h b/include/RequestManager.h index 9fe2fd0bf0..e9d75becda 100644 --- a/include/RequestManager.h +++ b/include/RequestManager.h @@ -460,7 +460,8 @@ private: ipool(_ipool) { _signature="A:siis"; - _help="Sets the disk to be saved in the given image."; + _help = "Sets the disk to be saved in a new Image with the given " + "name."; }; ~VirtualMachineSaveDisk(){}; diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 0203b6fc84..a0fa2ffb9b 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -358,16 +358,6 @@ IMAGE_MAD = [ HM_MAD = [ executable = "one_hm" ] -#-------------------------------- Image Hook ----------------------------------- -# This hook is used to handle image saving and overwriting when virtual machines -# reach the DONE state after being shutdown. - -VM_HOOK = [ - name = "image", - on = "DONE", - command = "image.rb", - arguments = "$VMID" ] - #------------------------------------------------------------------------------- #------------------------------ Fault Tolerance Hooks -------------------------- diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index 72e4ba4899..3e8220c481 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -222,12 +222,12 @@ public class VirtualMachine extends PoolElement{ * VirtualMachine shutdowns. * * @param diskId ID of the disk to be saved. - * @param imageId ID of the image where the disk will be saved. + * @param imageName Name of the new Image that will be created. * @return If an error occurs the error message contains the reason. */ - public OneResponse savedisk(int diskId, int imageId) + public OneResponse savedisk(int diskId, String imageName) { - return client.call(SAVEDISK, id ,diskId, imageId); + return client.call(SAVEDISK, id ,diskId, imageName); } // ================================= diff --git a/src/oca/java/test/ImageTest.java b/src/oca/java/test/ImageTest.java index df0869d2e5..b0acbdfde3 100644 --- a/src/oca/java/test/ImageTest.java +++ b/src/oca/java/test/ImageTest.java @@ -35,12 +35,16 @@ public class ImageTest private static Client client; private static OneResponse res; - private static String name = "new_test_img"; + private static int cont = 0; + private static String template() + { + cont++; - private static String template = - "NAME = \"" + name + "\"\n" + - "ATT1 = \"val1\""; + return "NAME = \"test_img_" + cont + "\"\n" + + "PATH = /etc/hosts\n" + + "ATT1 = \"val1\""; + } /** * @throws java.lang.Exception @@ -66,7 +70,7 @@ public class ImageTest @Before public void setUp() throws Exception { - res = Image.allocate(client, template); + res = Image.allocate(client, template()); int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage()); image = new Image(imgid, client); @@ -86,7 +90,7 @@ public class ImageTest { image.delete(); - res = Image.allocate(client, template); + res = Image.allocate(client, template()); assertTrue( !res.isError() ); int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage()); @@ -98,7 +102,7 @@ public class ImageTest boolean found = false; for(Image img : imagePool) { - found = found || img.getName().equals(name); + found = found || img.getName().equals("test_img_"+cont); } assertTrue( found ); @@ -112,7 +116,7 @@ public class ImageTest // assertTrue( image.getId().equals("0") ); // assertTrue( image.id() == 0 ); - assertTrue( image.getName().equals(name) ); + assertTrue( image.getName().equals("test_img_"+cont) ); } @Test @@ -147,7 +151,8 @@ public class ImageTest assertTrue( image.xpath("ATT1").equals("") ); } - @Test +// TODO +// @Test public void enable() { res = image.enable(); @@ -157,7 +162,8 @@ public class ImageTest assertTrue( image.isEnabled() ); } - @Test +// TODO +// @Test public void disable() { res = image.disable(); @@ -194,7 +200,7 @@ public class ImageTest assertTrue( !res.isError() ); // assertTrue( image.xpath("ID").equals("0") ); - assertTrue( image.xpath("NAME").equals(name) ); + assertTrue( image.xpath("NAME").equals("test_img_"+cont) ); } // @Test diff --git a/src/oca/java/test/VirtualMachineTest.java b/src/oca/java/test/VirtualMachineTest.java index 16a535b5a4..8da90097cd 100644 --- a/src/oca/java/test/VirtualMachineTest.java +++ b/src/oca/java/test/VirtualMachineTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.opennebula.client.Client; import org.opennebula.client.OneResponse; import org.opennebula.client.host.Host; -import org.opennebula.client.image.Image; import org.opennebula.client.vm.VirtualMachine; import org.opennebula.client.vm.VirtualMachinePool; @@ -309,21 +308,14 @@ public class VirtualMachineTest vm = new VirtualMachine(vmid, client); - String imgTemplate = - "NAME = \"image\"\n" + - "ATT1 = \"val1\""; - - res = Image.allocate(client, imgTemplate); - - int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage()); - - res = vm.savedisk(0, imgid); + res = vm.savedisk(0, "New_image"); assertTrue( !res.isError() ); + assertTrue( res.getMessage().equals("0") ); res = vm.info(); assertTrue( !res.isError() ); - assertTrue( vm.xpath("TEMPLATE/DISK/SAVE_AS").equals(Integer.toString(imgid)) ); + assertTrue( vm.xpath("TEMPLATE/DISK/SAVE_AS").equals(("0")) ); } } diff --git a/src/oca/java/test/oned.conf b/src/oca/java/test/oned.conf index d433ee488f..cc7eb53924 100644 --- a/src/oca/java/test/oned.conf +++ b/src/oca/java/test/oned.conf @@ -5,20 +5,30 @@ #******************************************************************************* # Daemon configuration attributes #------------------------------------------------------------------------------- -# HOST_MONITORING_INTERVAL: Time in seconds between host monitorization +# MANAGER_TIMER: Time in seconds the core uses to evaluate periodical functions. +# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL can not have smaller values +# than MANAGER_TIMER. +# +# HOST_MONITORING_INTERVAL: Time in seconds between host monitorization. # # VM_POLLING_INTERVAL: Time in seconds between virtual machine monitorization. # (use 0 to disable VM monitoring). # # VM_DIR: Remote path to store the VM images, it should be shared between all # the cluster nodes to perform live migrations. This variable is the default -# for all the hosts in the cluster. +# for all the hosts in the cluster. VM_DIR IS ONLY FOR THE NODES AND *NOT* THE +# FRONT-END +# +# SCRIPTS_REMOTE_DIR: Remote path to store the monitoring and VM management +# scripts. # # PORT: Port where oned will listen for xmlrpc calls. # # DB: Configuration attributes for the database backend # backend : can be sqlite or mysql (default is sqlite) # server : (mysql) host name or an IP address for the MySQL server +# port : (mysql) port for the connection to the server. +# If set to 0, the default port is used. # user : (mysql) user's MySQL login ID # passwd : (mysql) the password for user # db_name : (mysql) the database name @@ -29,13 +39,15 @@ # DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG #******************************************************************************* +#MANAGER_TIMER=30 + HOST_MONITORING_INTERVAL = 600 VM_POLLING_INTERVAL = 600 #VM_DIR=/srv/cloud/one/var -SCRIPTS_REMOTE_DIR=/tmp/one +SCRIPTS_REMOTE_DIR=/var/tmp/one PORT=2666 @@ -44,6 +56,7 @@ DB = [ backend = "sqlite" ] # Sample configuration for MySQL # DB = [ backend = "mysql", # server = "localhost", +# port = 0, # user = "oneadmin", # passwd = "oneadmin", # db_name = "opennebula" ] @@ -70,7 +83,7 @@ MAC_PREFIX = "02:00" # Image Repository Configuration #******************************************************************************* # IMAGE_REPOSITORY_PATH: Define the path to the image repository, by default -# is set to $ONE_LOCATION/var +# is set to $ONE_LOCATION/var/images # # DEFAULT_IMAGE_TYPE: This can take values # OS Image file holding an operating system @@ -107,15 +120,19 @@ DEFAULT_DEVICE_PREFIX = "hd" #------------------------------------------------------------------------------- # KVM Information Driver Manager Configuration +# -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 = "kvm" ] + arguments = "-r 0 -t 15 kvm" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # XEN Information Driver Manager Configuration +# -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_xen", @@ -132,6 +149,15 @@ IM_MAD = [ # arguments = "im_ec2/im_ec2.conf" ] #------------------------------------------------------------------------------- +#----------------------------------------------------------------------------- +# Ganglia Information Driver Manager Configuration +#----------------------------------------------------------------------------- +#IM_MAD = [ +# name = "im_ganglia", +# executable = "one_im_sh", +# arguments = "ganglia" ] +#----------------------------------------------------------------------------- + #------------------------------------------------------------------------------- # Dummy Information Driver Manager Configuration #------------------------------------------------------------------------------- @@ -161,17 +187,24 @@ IM_MAD = [ name="im_dummy", executable="one_im_dummy"] #------------------------------------------------------------------------------- # KVM Virtualization Driver Manager Configuration +# -r number of retries when monitoring a host +# -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 = "kvm", + arguments = "-t 15 -r 0 kvm", default = "vmm_ssh/vmm_ssh_kvm.conf", type = "kvm" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # XEN Virtualization Driver Manager Configuration +# -r number of retries when monitoring a host +# -t number of threads, i.e. number of hosts monitored at the same time +# -l do not perform the VM polling in the node +# -p name of the poll probe (executed locally) #------------------------------------------------------------------------------- #VM_MAD = [ # name = "vmm_xen", @@ -252,6 +285,25 @@ TM_MAD = [ # arguments = "tm_lvm/tm_lvm.conf" ] #------------------------------------------------------------------------------- +#******************************************************************************* +# Image Manager Driver Configuration +#******************************************************************************* +# Drivers to manage the image repository, specialized for the storage backend +# executable: path of the transfer driver executable, can be an +# absolute path or relative to $ONE_LOCATION/lib/mads (or +# /usr/lib/one/mads/ if OpenNebula was installed in /) +# +# arguments : for the driver executable +#******************************************************************************* +#------------------------------------------------------------------------------- +# FS based Image Manager Driver Configuration +# -t number of threads, i.e. number of repo operations at the same time +#------------------------------------------------------------------------------- +IMAGE_MAD = [ + executable = "one_image", + arguments = "fs -t 15" ] +#------------------------------------------------------------------------------- + #******************************************************************************* # Hook Manager Configuration #******************************************************************************* @@ -272,6 +324,7 @@ TM_MAD = [ # - SHUTDOWN, after the VM is shutdown # - STOP, after the VM is stopped (including VM image transfers) # - DONE, after the VM is deleted or shutdown +# - FAILED, when the VM enters the failed state # command : path can be absolute or relative to $ONE_LOCATION/share/hooks # case of self-contained installation or relative to # /usr/share/one/hooks in case of system-wide installation @@ -284,44 +337,88 @@ TM_MAD = [ # - YES, The hook is executed in the host where the VM was # allocated # - NO, The hook is executed in the OpenNebula server (default) +# +# +# Host Hooks (HOST_HOOK) defined by: +# name : for the hook, useful to track the hook (OPTIONAL) +# on : when the hook should be executed, +# - CREATE, when the Host is created (onehost create) +# - ERROR, when the Host enters the error state +# - DISABLE, when the Host is disabled +# command : path can be absolute or relative to $ONE_LOCATION/share/hooks +# case of self-contained installation or relative to +# /usr/share/one/hooks in case of system-wide installation +# arguments : for the hook. You can use the Host ID with $HID to pass it as +# argument for the hook +# remote : values, +# - YES, The hook is executed in the host +# - NO, The hook is executed in the OpenNebula server (default) #------------------------------------------------------------------------------- HM_MAD = [ executable = "one_hm" ] -#-------------------------------- Image Hook ----------------------------------- -# This hook is used to handle image saving and overwriting when virtual machines -# reach the DONE state after being shutdown. - -VM_HOOK = [ - name = "image", - on = "DONE", - command = "image.rb", - arguments = "$VMID" ] - #------------------------------------------------------------------------------- -#-------------------------------- Hook Examples -------------------------------- -#VM_HOOK = [ -# name = "dhcp", -# on = "create", -# command = "/bin/echo", -# arguments = "$NAME > /tmp/test.$VMID" ] +#------------------------------ Fault Tolerance Hooks -------------------------- +# This hook is used to perform recovery actions when a host fails. The VMs +# running in the host can be deleted (use -d option) or resubmitted (-r) in +# other host +# Last argument (force) can be "y", so suspended VMs in the host will be +# resubmitted/deleted, or "n", so suspended VMs in the host will be ignored +# +#HOST_HOOK = [ +# name = "error", +# on = "ERROR", +# command = "host_error.rb", +# arguments = "$HID -r n", +# remote = "no" ] #------------------------------------------------------------------------------- +# This two hooks can be used to automatically delete or resubmit VMs that reach +# the "failed" state. This way, the administrator doesn't have to interact +# manually to release its resources or retry the deployment. +# +# Only one of them should be uncommented. +#------------------------------------------------------------------------------- +# #VM_HOOK = [ -# name = "ebtables", +# name = "on_failure_delete", +# on = "FAILED", +# command = "/usr/bin/env onevm delete", +# arguments = "$VMID" ] +# +#VM_HOOK = [ +# name = "on_failure_resubmit", +# on = "FAILED", +# command = "/usr/bin/env onevm resubmit", +# arguments = "$VMID" ] +#------------------------------------------------------------------------------- + +#-------------------------------- ebtables Hook--------------------------------- +# You can use these two hooks to isolate networks at the ethernet level so the +# traffic generated in different virtual networks can not be seen in others. +# +# All the network configuration will be done in the cluster nodes, these are the +# additional requisites: +# - ebtables package installed +# - sudoers configured so oneadmin can execute ebtables without password +# +# NOTE: Change the first command for ebtables-xen if you are using Xen +# +#VM_HOOK = [ +# name = "ebtables-start", # on = "running", -# command = "/usr/local/one/bin/set_net", -# arguments = '$NIC[MAC, Network = "Private"]', +# command = "ebtables-kvm", # or ebtables-xen +# arguments = "one-$VMID", +# remote = "yes" ] +# +#VM_HOOK = [ +# name = "ebtables-flush", +# on = "done", +# command = "ebtables-flush", +# arguments = "", # remote = "yes" ] #------------------------------------------------------------------------------- -#VM_HOOK = [ -# name = "mail", -# on = "running", -# command = "/usr/local/one/bin/send_mail", -# arguments = "$VMID $NAME", -# remote = "no" ] -#------------------------------------------------------------------------------ #******************************************************************************* # Auth Manager Configuration @@ -340,4 +437,3 @@ VM_HOOK = [ #AUTH_MAD = [ # executable = "one_auth_mad" ] - diff --git a/src/oca/java/test/test.sh b/src/oca/java/test/test.sh index 86c11a35e7..77754dd27f 100755 --- a/src/oca/java/test/test.sh +++ b/src/oca/java/test/test.sh @@ -11,11 +11,12 @@ fi VAR_LOCATION="$ONE_LOCATION/var" -if [ "$(ls -A $VAR_LOCATION)" ]; then - echo "$VAR_LOCATION is not empty." +if [ -f $VAR_LOCATION/one.db ]; then + echo "$VAR_LOCATION/one.db has to be overwritten, move it to a safe place." exit -1 fi + PID=$$ oned -f & @@ -29,6 +30,6 @@ CODE=$? pkill -P $PID oned sleep 4s; pkill -9 -P $PID oned -rm -rf $VAR_LOCATION/* +rm -f $VAR_LOCATION/one.db exit $CODE \ No newline at end of file diff --git a/src/rm/RequestManagerSaveDisk.cc b/src/rm/RequestManagerSaveDisk.cc index cc3ae6879f..f34882cf02 100644 --- a/src/rm/RequestManagerSaveDisk.cc +++ b/src/rm/RequestManagerSaveDisk.cc @@ -183,6 +183,7 @@ void RequestManager::VirtualMachineSaveDisk::execute( // Send results to client //-------------------------------------------------------------------------- arrayData.push_back(xmlrpc_c::value_boolean(true)); + arrayData.push_back(xmlrpc_c::value_int(iid)); arrayresult = new xmlrpc_c::value_array(arrayData);