From a5062dc68d58f5d1d31cf51c790aa873eadf15f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 8 Jun 2011 18:30:36 +0200 Subject: [PATCH] Feature #523, #662: Fix most of the Image unit tests. This comes from 35666985 --- src/host/test/NebulaTestHost.h | 23 ---------------- src/image/test/ImagePoolTest.cc | 47 ++++++++++++++++++++++++++++++--- src/image/test/SConstruct | 28 +++++++++++++------- src/mad/test/dummy | 26 ++++++++++++++++++ src/test/Nebula.cc | 16 ++++++++--- src/test/NebulaTest.cc | 14 +++++++--- 6 files changed, 112 insertions(+), 42 deletions(-) create mode 100755 src/mad/test/dummy diff --git a/src/host/test/NebulaTestHost.h b/src/host/test/NebulaTestHost.h index 5d7c00c787..a390432727 100644 --- a/src/host/test/NebulaTestHost.h +++ b/src/host/test/NebulaTestHost.h @@ -83,29 +83,6 @@ public: return new HostPool(db, host_hooks, hook_location); } - - // ----------------------------------------------------------- - // Managers - // ----------------------------------------------------------- - - HookManager* create_hm(VirtualMachinePool * vmpool) - { - map mad_value; - VectorAttribute * mad; - vector hm_mads; - - ostringstream oss; - - // we need the full path (i.e, starting with '/') - // for the dummy executable - oss << getenv("PWD") << "/../../hm_mad/test/dummy"; - mad_value.insert(make_pair("EXECUTABLE",oss.str())); - - mad = new VectorAttribute("HM_MAD",mad_value); - hm_mads.push_back(mad); - - return new HookManager(hm_mads,vmpool); - } }; #endif /*NEBULA_TEST_H_*/ diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index 12a8464235..771fda7b37 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -64,6 +64,24 @@ const string xml_dump_where = "001Image one0010000000000-40111Second Image0100000000000-40"; +/* ************************************************************************* */ +/* ************************************************************************* */ + +#include "NebulaTest.h" + +class NebulaTestImage: public NebulaTest +{ +public: + NebulaTestImage():NebulaTest() + { + NebulaTest::the_tester = this; + + need_image_pool = true; + need_imagem = true; + } +}; + + class ImagePoolFriend : public ImagePool { public: @@ -135,16 +153,18 @@ class ImagePoolTest : public PoolTest protected: + NebulaTestImage * tester; + ImagePool * ipool; + void bootstrap(SqlDB* db) { - ImagePool::bootstrap(db); + // setUp overwritten }; PoolSQL* create_pool(SqlDB* db) { - ImagePoolFriend * imp = - new ImagePoolFriend(db, "OS", "hd"); - return imp; + // setUp overwritten + return ipool; }; int allocate(int index) @@ -183,7 +203,26 @@ public: ~ImagePoolTest(){xmlCleanupParser();}; + void setUp() + { + create_db(); + tester = new NebulaTestImage(); + + Nebula& neb = Nebula::instance(); + neb.start(); + + ipool = neb.get_ipool(); + + pool = ipool; + }; + + void tearDown() + { + delete_db(); + + delete tester; + }; /* ********************************************************************* */ void names_initialization() diff --git a/src/image/test/SConstruct b/src/image/test/SConstruct index 4d5bc99d00..8827054f90 100644 --- a/src/image/test/SConstruct +++ b/src/image/test/SConstruct @@ -17,20 +17,30 @@ Import('env') env.Prepend(LIBS=[ - 'nebula_image', +### TODO: delete not needed + 'nebula_core_test', + 'nebula_host', + 'nebula_xml', + 'nebula_vmm', + 'nebula_im', + 'nebula_rm', + 'nebula_tm', 'nebula_um', - 'nebula_vm', - 'nebula_hm', - 'nebula_vnm', - 'nebula_authm', - 'nebula_template', - 'nebula_pool', 'nebula_mad', + 'nebula_template', + 'nebula_vm', + 'nebula_vmtemplate', + 'nebula_group', + 'nebula_vnm', + 'nebula_image', + 'nebula_pool', + 'nebula_hm', + 'nebula_authm', 'nebula_common', - 'nebula_core', + 'nebula_lcm', + 'nebula_dm', 'nebula_sql', 'nebula_log', - 'nebula_xml', 'crypto' ]) diff --git a/src/mad/test/dummy b/src/mad/test/dummy new file mode 100755 index 0000000000..8db81aaf4d --- /dev/null +++ b/src/mad/test/dummy @@ -0,0 +1,26 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +#echo "MAD started" >> mad.log + +while read COMMAND ARG1 ARG2 ARG3 +do +# echo "$COMMAND $ARG1 $ARG2 $ARG3" >> mad.log + + echo "$COMMAND SUCCESS" +done diff --git a/src/test/Nebula.cc b/src/test/Nebula.cc index 23dbe29bd0..4fb6df495c 100644 --- a/src/test/Nebula.cc +++ b/src/test/Nebula.cc @@ -122,6 +122,11 @@ void Nebula::start() delete hm; } + if ( imagem != 0 ) + { + delete imagem; + } + if ( authm != 0) { delete authm; @@ -185,8 +190,8 @@ void Nebula::start() { string mac_prefix = "00:00"; int size = 1; - string default_image_type; - string default_device_prefix; + string default_image_type = "OS"; + string default_device_prefix = "hd"; if (tester->need_vm_pool) { @@ -433,7 +438,7 @@ void Nebula::start() } } - // ---- Auth Manager ---- + // ---- Image Manager ---- if (tester->need_imagem) { try @@ -482,6 +487,11 @@ void Nebula::start() hm->load_mads(0); } + if( imagem != 0 ) + { + imagem->load_mads(0); + } + if( authm != 0 ) { authm->load_mads(0); diff --git a/src/test/NebulaTest.cc b/src/test/NebulaTest.cc index 3d4277ada9..f50cda3339 100644 --- a/src/test/NebulaTest.cc +++ b/src/test/NebulaTest.cc @@ -121,8 +121,12 @@ HookManager* NebulaTest::create_hm(VirtualMachinePool * vmpool) VectorAttribute * mad; vector hm_mads; + ostringstream oss; - mad_value.insert(make_pair("executable","one_hm")); + // we need the full path (i.e, starting with '/') + // for the dummy executable + oss << getenv("PWD") << "/../../hm_mad/test/dummy"; + mad_value.insert(make_pair("EXECUTABLE",oss.str())); mad = new VectorAttribute("HM_MAD",mad_value); hm_mads.push_back(mad); @@ -141,10 +145,14 @@ ImageManager* NebulaTest::create_imagem(ImagePool * ipool) VectorAttribute * mad; vector im_mads; + ostringstream oss; - mad_value.insert(make_pair("executable","one_image")); + // we need the full path (i.e, starting with '/') + // for the dummy executable + oss << getenv("PWD") << "/../../mad/test/dummy"; + mad_value.insert(make_pair("EXECUTABLE",oss.str())); - mad = new VectorAttribute("HM_MAD",mad_value); + mad = new VectorAttribute("IMAGE_MAD",mad_value); im_mads.push_back(mad); return new ImageManager(ipool,im_mads);