From de97dfd90325908aef252800e9f11d1f8352eddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 19 Jan 2011 18:17:25 +0100 Subject: [PATCH 1/2] Feature #457: Unit testing for Host Hooks --- src/hm_mad/test/dummy | 41 ++++++ src/host/test/HostHookTest.cc | 168 ++++++++++------------ src/host/test/HostHookTest.h | 209 +++++++++++++++++++++++++++ src/host/test/NebulaTest.h | 210 +++++++++++++++++++++++++++ src/host/test/SConstruct | 262 ++++++++++++++++++++++++++-------- 5 files changed, 734 insertions(+), 156 deletions(-) create mode 100755 src/hm_mad/test/dummy create mode 100644 src/host/test/HostHookTest.h create mode 100644 src/host/test/NebulaTest.h diff --git a/src/hm_mad/test/dummy b/src/hm_mad/test/dummy new file mode 100755 index 0000000000..abf3a50e96 --- /dev/null +++ b/src/hm_mad/test/dummy @@ -0,0 +1,41 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, 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 + + case $COMMAND in + "INIT") + echo "INIT SUCCESS" + ;; + "FINALIZE") + echo "FINALIZE SUCCESS" + exit 0 + ;; + "EXECUTE") + `echo $ARG3 | cut -d ' ' -f 2-` + echo "EXECUTE SUCCESS" + ;; + *) + echo "$COMMAND - FAILURE Unknown command" + ;; + esac +done diff --git a/src/host/test/HostHookTest.cc b/src/host/test/HostHookTest.cc index 88d9581198..32be98f998 100644 --- a/src/host/test/HostHookTest.cc +++ b/src/host/test/HostHookTest.cc @@ -14,107 +14,85 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -#include -#include -#include -#include +#include "HostHookTest.h" -#include "HostPool.h" -#include "PoolTest.h" +string HostHookTest::db_name; -using namespace std; +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ -/* ************************************************************************* */ -/* ************************************************************************* */ - -class HostHookTest : public PoolTest +void show_options () { - CPPUNIT_TEST_SUITE (HostHookTest); - - CPPUNIT_TEST (allocate_hook); -// CPPUNIT_TEST (error_hook); -// CPPUNIT_TEST (disable_hook); - CPPUNIT_TEST_SUITE_END (); - -protected: - - void bootstrap(SqlDB* db) - { - HostPool::bootstrap(db); - }; - - PoolSQL* create_pool(SqlDB* db) - { - map hook_value; - VectorAttribute * hook; - - vector host_hooks; - - hook_value.insert(make_pair("NAME","create_test")); - hook_value.insert(make_pair("ON","ERROR")); - hook_value.insert(make_pair("COMMAND","/bin/touch")); - hook_value.insert(make_pair("ARGUMENTS","/tmp/host_$HID")); - hook_value.insert(make_pair("REMOTE","no")); - - hook = new VectorAttribute("HOST_HOOK",hook_value); - - - - host_hooks.push_back(hook); - - return new HostPool(db,host_hooks,"./"); - }; - - int allocate(int index){return 0;}; - void check(int index, PoolObjectSQL* obj){}; - -public: - HostHookTest(){xmlInitParser();}; - - ~HostHookTest(){xmlCleanupParser();}; - - - /* ********************************************************************* */ - /* ********************************************************************* */ - - - void allocate_hook() - { - HostPool * hp = static_cast(pool); - - string err; - int oid; - - fstream fd; - - hp->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); - - Host* host = hp->get(oid, true); - - CPPUNIT_ASSERT( host != 0 ); - - host->unlock(); - - ostringstream oss; - - oss << "/tmp/host_" << oid ; - - fd.open(oss.str().c_str(), fstream::in | fstream::out ); - - CPPUNIT_ASSERT( fd.fail() == false ); - - fd.close(); - }; - - /* ********************************************************************* */ + cout << "Options:\n"; + cout << " -h --help Show this help\n" + " -s --sqlite Run Sqlite tests (default)\n" + " -m --mysql Run MySQL tests\n" + " -l --log Keep the log file, test.log\n"; }; -/* ************************************************************************* */ -/* ************************************************************************* */ -/* ************************************************************************* */ - int main(int argc, char ** argv) { - return PoolTest::main(argc, argv, HostHookTest::suite()); -} + // Option flags + bool sqlite_flag = true; + bool log_flag = false; + + // Long options + const struct option long_opt[] = + { + { "sqlite", 0, NULL, 's'}, + { "mysql", 0, NULL, 'm'}, + { "log", 0, NULL, 'l'}, + { "help", 0, NULL, 'h'} + }; + + int c; + while ((c = getopt_long (argc, argv, "smlh", long_opt, NULL)) != -1) + switch (c) + { + case 'm': + sqlite_flag = false; + break; + case 'l': + log_flag = true; + break; + case 'h': + show_options(); + return 0; + } + + // We need to set the log file, otherwise it will end in a dead-lock + NebulaLog::init_log_system(NebulaLog::FILE, Log::DEBUG, "test.log"); + NebulaLog::log("Test", Log::INFO, "Test started"); + + + CppUnit::TextUi::TestRunner runner; + + SETUP_XML_WRITER(runner, "output.xml") + + runner.addTest( HostHookTest::suite() ); + + if (sqlite_flag) + { + NebulaTest::instance().setMysql(false); + NebulaLog::log("Test", Log::INFO, "Running Sqlite tests..."); + cout << "\nRunning Sqlite tests...\n"; + } + else + { + NebulaTest::instance().setMysql(true); + NebulaLog::log("Test", Log::INFO, "Running MySQL tests..."); + cout << "\nRunning MySQL tests...\n"; + } + + runner.run(); + + END_XML_WRITER + + if (!log_flag) + remove("test.log"); + + NebulaLog::finalize_log_system(); + + return 0; +} \ No newline at end of file diff --git a/src/host/test/HostHookTest.h b/src/host/test/HostHookTest.h new file mode 100644 index 0000000000..a4c4ea494b --- /dev/null +++ b/src/host/test/HostHookTest.h @@ -0,0 +1,209 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2010, 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. */ +/* -------------------------------------------------------------------------- */ + +#include "Nebula.h" +#include "NebulaTest.h" + +#include "SqliteDB.h" +#include "MySqlDB.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "test/one_test_common.h" + +using namespace std; + + +class HostHookTest : public CppUnit::TestFixture +{ + + CPPUNIT_TEST_SUITE (HostHookTest); + + CPPUNIT_TEST (allocate_hook); + CPPUNIT_TEST (monitoring_error); + CPPUNIT_TEST (error_imd); + CPPUNIT_TEST (disable_hook); + + CPPUNIT_TEST_SUITE_END (); + +private: + + Host * host; + HostPool * hpool; + HookManager * hm; + + int oid; + int rc; + +public: + static string db_name; + + + void setUp() + { + // Create var dir. + string command = "mkdir -p var"; + std::system(command.c_str()); + + Nebula& neb = Nebula::instance(); + neb.start(); + + hpool = neb.get_hpool(); + hm = static_cast(neb.get_hm()); + } + + void tearDown() + { + // ----------------------------------------------------------- + // Stop the managers & free resources + // ----------------------------------------------------------- + + hm->finalize(); + + //sleep to wait drivers??? + pthread_join(hm->get_thread_id(),0); + + //XML Library + xmlCleanupParser(); + + if (NebulaTest::instance().isMysql()) + { + SqlDB * db; + + db = new MySqlDB("localhost",0,"oneadmin","oneadmin",db_name.c_str()); + + ostringstream oss; + oss << "DROP DATABASE IF EXISTS " << db_name; + db->exec(oss); + + delete db; + } + + // Clean var dir. + string command = "rm -r var"; + std::system(command.c_str()); + } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void allocate_hook() + { + string err; + + hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); + CPPUNIT_ASSERT( oid >= 0 ); + + sleep(1); + + ostringstream oss; + oss << "ls ./var/hook_create_" << oid << " > /dev/null 2>&1"; + rc = std::system(oss.str().c_str()); + + CPPUNIT_ASSERT( rc == 0 ); + } + +/* -------------------------------------------------------------------------- */ + + void monitoring_error() + { + string err; + + hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); + CPPUNIT_ASSERT( oid >= 0 ); + + host = hpool->get(oid, true); + CPPUNIT_ASSERT( host != 0 ); + + host->touch(false); + hpool->update(host); + + host->unlock(); + + sleep(1); + + ostringstream oss; + oss << "ls ./var/hook_error_" << oid << " > /dev/null 2>&1"; + rc = std::system(oss.str().c_str()); + + CPPUNIT_ASSERT( rc == 0 ); + } + +/* -------------------------------------------------------------------------- */ + + void error_imd() + { + string err; + + hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); + CPPUNIT_ASSERT( oid >= 0 ); + + host = hpool->get(oid, true); + CPPUNIT_ASSERT( host != 0 ); + + host->set_state(Host::ERROR); + hpool->update(host); + + host->unlock(); + + sleep(1); + + ostringstream oss; + oss << "ls ./var/hook_error_" << oid << " > /dev/null 2>&1"; + rc = std::system(oss.str().c_str()); + + CPPUNIT_ASSERT( rc == 0 ); + } + +/* -------------------------------------------------------------------------- */ + + void disable_hook() + { + string err; + + hpool->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err); + CPPUNIT_ASSERT( oid >= 0 ); + + host = hpool->get(oid, true); + CPPUNIT_ASSERT( host != 0 ); + + host->disable(); + hpool->update(host); + + host->unlock(); + + sleep(1); + + ostringstream oss; + oss << "ls ./var/hook_disable_" << oid << " > /dev/null 2>&1"; + rc = std::system(oss.str().c_str()); + + CPPUNIT_ASSERT( rc == 0 ); + } + +/* -------------------------------------------------------------------------- */ +}; diff --git a/src/host/test/NebulaTest.h b/src/host/test/NebulaTest.h new file mode 100644 index 0000000000..b28ba6aa8b --- /dev/null +++ b/src/host/test/NebulaTest.h @@ -0,0 +1,210 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2010, 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. */ +/* -------------------------------------------------------------------------- */ + +#ifndef NEBULA_TEST_H_ +#define NEBULA_TEST_H_ + +#include "SqlDB.h" + +#include "NebulaTemplate.h" + +#include "VirtualMachinePool.h" +#include "VirtualNetworkPool.h" +#include "HostPool.h" +#include "UserPool.h" + +#include "VirtualMachineManager.h" +#include "LifeCycleManager.h" +#include "InformationManager.h" +#include "TransferManager.h" +#include "DispatchManager.h" +#include "RequestManager.h" +#include "HookManager.h" +#include "AuthManager.h" + +class NebulaTest +{ +private: + bool mysql; + + NebulaTest() + { + mysql = false; + }; + +public: + + static NebulaTest& instance() + { + static NebulaTest instance; + + return instance; + }; + + void setMysql(bool _mysql) + { + mysql = _mysql; + } + + bool isMysql() + { + return mysql; + } + + // ----------------------------------------------------------- + // Pools + // ----------------------------------------------------------- + + static VirtualMachinePool* create_vmpool(SqlDB* db, string hook_location) + { + vector hooks; + return new VirtualMachinePool(db, hooks, hook_location); + } + + static HostPool* create_hpool(SqlDB* db, string hook_location) + { + map hook_value; + VectorAttribute * hook; + + vector host_hooks; + + hook_value.insert(make_pair("NAME","create_test")); + hook_value.insert(make_pair("ON","CREATE")); + hook_value.insert(make_pair("COMMAND","/bin/touch")); + hook_value.insert(make_pair("ARGUMENTS","./var/hook_create_$HID")); + hook_value.insert(make_pair("REMOTE","no")); + + hook = new VectorAttribute("HOST_HOOK",hook_value); + host_hooks.push_back(hook); + + map hook_value2; + + hook_value2.insert(make_pair("NAME","error_test")); + hook_value2.insert(make_pair("ON","ERROR")); + hook_value2.insert(make_pair("COMMAND","/bin/touch")); + hook_value2.insert(make_pair("ARGUMENTS","./var/hook_error_$HID")); + hook_value2.insert(make_pair("REMOTE","no")); + + hook = new VectorAttribute("HOST_HOOK",hook_value2); + host_hooks.push_back(hook); + + map hook_value3; + + hook_value3.insert(make_pair("NAME","create_test")); + hook_value3.insert(make_pair("ON","DISABLE")); + hook_value3.insert(make_pair("COMMAND","/bin/touch")); + hook_value3.insert(make_pair("ARGUMENTS","./var/hook_disable_$HID")); + hook_value3.insert(make_pair("REMOTE","no")); + + hook = new VectorAttribute("HOST_HOOK",hook_value3); + host_hooks.push_back(hook); + + + return new HostPool(db, host_hooks, hook_location); + } + + static VirtualNetworkPool* create_vnpool(SqlDB* db, string mac_prefix, int size) + { + return new VirtualNetworkPool(db,mac_prefix,size); + } + + static UserPool* create_upool(SqlDB* db) + { + return new UserPool(db); + } + + static ImagePool* create_ipool( SqlDB* db, + string repository_path, + string default_image_type, + string default_device_prefix) + { + return new ImagePool(db,repository_path,default_image_type, + default_device_prefix); + } + + // ----------------------------------------------------------- + // Managers + // ----------------------------------------------------------- + + static VirtualMachineManager* create_vmm(VirtualMachinePool* vmpool, + HostPool* hpool, + time_t timer_period, + time_t poll_period) + { + return NULL; + } + + static LifeCycleManager* create_lcm(VirtualMachinePool* vmpool, HostPool* hpool) + { + return NULL; + } + + static InformationManager* create_im( HostPool* hpool, + time_t timer_period, + string remotes_location) + { + return NULL; + } + + static TransferManager* create_tm( VirtualMachinePool* vmpool, + HostPool* hpool) + { + return NULL; + } + + static DispatchManager* create_dm( VirtualMachinePool* vmpool, + HostPool* hpool) + { + return NULL; + } + + static RequestManager* create_rm( + VirtualMachinePool * vmpool, + HostPool * hpool, + VirtualNetworkPool * vnpool, + UserPool * upool, + ImagePool * ipool, + string log_file) + { + return NULL; + } + + static 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); + } + + static AuthManager* create_authm(time_t timer_period) + { + return NULL; + } +}; + +#endif /*NEBULA_TEST_H_*/ \ No newline at end of file diff --git a/src/host/test/SConstruct b/src/host/test/SConstruct index 96d3beb668..05a1447640 100644 --- a/src/host/test/SConstruct +++ b/src/host/test/SConstruct @@ -1,18 +1,18 @@ -# -------------------------------------------------------------------------- -# Copyright 2002-2010, 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. -# -------------------------------------------------------------------------- +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, 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. # +#--------------------------------------------------------------------------- # import os import sys @@ -21,81 +21,221 @@ sys.path.append("../../../share/scons") from lex_bison import * # This is the absolute path where the project is located -cwd="../../../" +cwd="../../.." # Environment that will be applied to each scons child main_env=Environment() main_env['ENV']['PATH']=os.environ['PATH'] +# snippet borrowed from http://dev.gentoo.org/~vapier/scons-blows.txt +# makes scons aware of build related environment variables +if os.environ.has_key('CC'): + main_env['CC'] = os.environ['CC'] +if os.environ.has_key('CFLAGS'): + main_env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS']) +if os.environ.has_key('CXX'): + main_env['CXX'] = os.environ['CXX'] +if os.environ.has_key('CXXFLAGS'): + main_env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS']) +if os.environ.has_key('LDFLAGS'): + main_env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS']) + # Add builders for flex and bison add_lex(main_env) add_bison(main_env) # Include dirs main_env.Append(CPPPATH=[ - cwd + '/include', - cwd + '/include/test', - '/usr/include/cppunit/', + '.', + cwd+'/include', + cwd+'/include/test', + cwd+'/src/hm/test', + '/usr/include/cppunit/' ]) # Library dirs main_env.Append(LIBPATH=[ - cwd + '/src/common', - cwd + '/src/log', - cwd + '/src/nebula', - cwd + '/src/sql', - cwd + '/src/pool', - cwd + '/src/template', - cwd + '/src/host', - cwd + '/src/hm', - cwd + '/src/mad', + cwd+'/src/common', + cwd+'/src/log', + cwd+'/src/sql', + cwd+'/src/host', + cwd+'/src/mad', + cwd+'/src/nebula', + cwd+'/src/pool', + cwd+'/src/template', + cwd+'/src/vm', + cwd+'/src/vmm', + cwd+'/src/lcm', + cwd+'/src/tm', + cwd+'/src/dm', + cwd+'/src/im', + cwd+'/src/image', + cwd+'/src/rm', + cwd+'/src/vnm', + cwd+'/src/hm', + cwd+'/src/um', + cwd+'/src/authm', + '.', ]) -main_env.Append(LIBS=[ - 'nebula_log', - 'nebula_host', - 'nebula_template', - 'nebula_pool', - 'nebula_mad', - 'nebula_hm', - 'nebula_common', - 'nebula_core', - 'nebula_sql', - 'cppunit', - 'dl', - 'pthread', +# Compile flags +main_env.Append(CPPFLAGS=[ + "-g", + "-Wall", + "-Werror", ]) -# MYSQL -main_env.Append(LIBPATH=["/usr/lib/mysql"]) -main_env.Append(CPPPATH=["/usr/include/mysql"]) +# Linking flags +main_env.Append(LINKFLAGS=['-g', '-pthread']) + +####################### +# EXTRA CONFIGURATION # +####################### + +# SQLITE +sqlite_dir=ARGUMENTS.get('sqlite_dir', 'none') +if sqlite_dir!='none': + main_env.Append(LIBPATH=[sqlite_dir+"/lib"]) + main_env.Append(CPPPATH=[sqlite_dir+"/include"]) + +sqlite=ARGUMENTS.get('sqlite', 'yes') +if sqlite=='yes': + main_env.Append(sqlite='yes') + main_env.Append(CPPFLAGS=["-DSQLITE_DB"]) +else: + main_env.Append(sqlite='no') + +# MySQL +mysql=ARGUMENTS.get('mysql', 'no') +if mysql=='yes': + main_env.Append(mysql='yes') + main_env.Append(CPPFLAGS=["-DMYSQL_DB"]) +else: + main_env.Append(mysql='no') + + +# xmlrpc +xmlrpc_dir=ARGUMENTS.get('xmlrpc', 'none') +if xmlrpc_dir!='none': + main_env.Append(LIBPATH=[xmlrpc_dir+"/lib"]) + main_env.Append(CPPPATH=[xmlrpc_dir+"/include"]) + +# build lex/bison +build_parsers=ARGUMENTS.get('parsers', 'no') +if build_parsers=='yes': + main_env.Append(parsers='yes') +else: + main_env.Append(parsers='no') + +if not main_env.GetOption('clean'): + try: + main_env.ParseConfig('../../../share/scons/get_xmlrpc_config server') + main_env.ParseConfig('../../../share/scons/get_xmlrpc_config client') + + if mysql=='yes': + main_env.ParseConfig('mysql_config --cflags --libs') + + except Exception, e: + print "" + print "Error searching for xmlrpc-c libraries. Please check this"+\ + " things:" + print "" + print " * You have installed development libraries for xmlrpc-c. One"+\ + " way to check" + print " this is calling xmlrpc-c-config that is provided with the"+\ + " development" + print " package." + print " * Check that the version of xmlrpc-c is at least 1.06. You"+\ + " can do this also" + print " calling:" + print " $ xmlrpc-c-config --version" + print " * If all this requirements are already met please send log"+\ + " files located in" + print " .xmlrpc_test to the mailing list." + print "" + exit(-1) +else: + main_env.Replace(mysql='yes') + shutil.rmtree('.xmlrpc_test', True) + shutil.rmtree('src/nebula/.xmlrpc_test', True) + shutil.rmtree('src/scheduler/.xmlrpc_test', True) # libxml2 main_env.ParseConfig('xml2-config --libs --cflags') -sqlite=ARGUMENTS.get('sqlite', 'yes') -if sqlite=='yes': - main_env.Append(CPPFLAGS=["-DSQLITE_DB"]) - main_env.Append(LIBS=[ 'sqlite3', ]) +# Build LCM and DM toguether in a lib -# MySQL -mysql=ARGUMENTS.get('mysql', 'no') -if mysql=='yes': - main_env.Append(CPPFLAGS=["-DMYSQL_DB"]) - main_env.Append(LIBS=[ 'mysqlclient', ]) +lib_name='nebula_lcm_dm' -# Compile flags -main_env.Append(CPPFLAGS=[ - "-g", - "-Wall", - "-Werror" +# Sources to generate the library +source_files=[ + '../../lcm/LifeCycleManager.cc', + '../../lcm/LifeCycleActions.cc', + '../../lcm/LifeCycleStates.cc', + '../../dm/DispatchManager.cc', + '../../dm/DispatchManagerActions.cc', + '../../dm/DispatchManagerStates.cc', +] + +# Build library +main_env.StaticLibrary(lib_name, source_files) + + +# Build a modified Nebula lib + +lib_name='nebula_core_test' + +# Sources to generate the library +source_files=[ + '../../nebula/test/Nebula.cc', + '../../nebula/NebulaTemplate.cc', +] + +# Build library +main_env.StaticLibrary(lib_name, source_files) + + +# Build daemon +main_env.Append(LIBS=[ + 'nebula_core_test', + + 'nebula_host', + 'nebula_vmm', + 'nebula_im', + 'nebula_rm', + 'nebula_tm', + 'nebula_um', + 'nebula_mad', + 'nebula_template', + 'nebula_vm', + 'nebula_vnm', + 'nebula_image', + 'nebula_pool', + 'nebula_hm', + 'nebula_authm', + 'nebula_common', + 'nebula_sql', + 'nebula_log', + + 'nebula_lcm_dm', + + 'crypto', + 'cppunit', ]) -# Linking flags -main_env.Append(LDFLAGS=["-g "]) +# Sources to generate the library +if main_env['sqlite']=='yes': + main_env.Append(LIBS=['sqlite3']) + +if main_env['mysql']=='yes': + main_env.Append(LIBS=['mysqlclient']) + + +if not main_env.GetOption('clean'): + main_env.ParseConfig('../../../share/scons/get_xmlrpc_config server') + main_env.Program('test','HostPoolTest.cc') main_env.Program('test_hook','HostHookTest.cc') - From a381a5c71565bb52bcaf06ef9c180993e27c6a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 19 Jan 2011 18:52:26 +0100 Subject: [PATCH 2/2] Features #457 & #455: Resubmit action for VMs added to Java API --- .../src/org/opennebula/client/vm/VirtualMachine.java | 11 ++++++++++- src/oca/java/test/VirtualMachineTest.java | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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 f1a8b7c84b..a14d52e005 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -310,7 +310,7 @@ public class VirtualMachine extends PoolElement{ } /** - * Resubmits the virtual machine after failure. + * Forces a re-deployment of a VM in UNKNOWN or BOOT state. * @return If an error occurs the error message contains the reason. */ public OneResponse restart() @@ -318,6 +318,15 @@ public class VirtualMachine extends PoolElement{ return action("shutdown"); } + /** + * Resubmits a VM to PENDING state. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse resubmit() + { + return action("resubmit"); + } + /** * Migrates the virtual machine to the target host (hid). *
diff --git a/src/oca/java/test/VirtualMachineTest.java b/src/oca/java/test/VirtualMachineTest.java index 8e9f6d100f..7ca7ed02e5 100644 --- a/src/oca/java/test/VirtualMachineTest.java +++ b/src/oca/java/test/VirtualMachineTest.java @@ -271,6 +271,17 @@ public class VirtualMachineTest // TODO } + @Test + public void resubmit() + { + vm.deploy(hid_A); + waitAssert(vm, "ACTIVE", "RUNNING"); + res = vm.resubmit(); + + assertTrue( !res.isError() ); + waitAssert(vm, "PENDING", "-"); + } + @Test public void attributes() {