1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-22 17:57:46 +03:00

Merge branch 'feature-457'

Conflicts:
	src/nebula/SConstruct
	src/scheduler/SConstruct
	src/scheduler/src/pool/test/SConstruct
	src/scheduler/src/sched/SConstruct
	src/scheduler/src/xml/test/SConstruct
This commit is contained in:
Ruben S. Montero 2011-01-28 17:01:28 +01:00
commit 3ab03c4268
84 changed files with 4121 additions and 1706 deletions

View File

@ -98,6 +98,7 @@ sqlite=ARGUMENTS.get('sqlite', 'yes')
if sqlite=='yes':
main_env.Append(sqlite='yes')
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])
main_env.Append(LIBS=['sqlite3'])
else:
main_env.Append(sqlite='no')
@ -106,10 +107,10 @@ mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(mysql='yes')
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=['mysqlclient'])
else:
main_env.Append(mysql='no')
# xmlrpc
xmlrpc_dir=ARGUMENTS.get('xmlrpc', 'none')
if xmlrpc_dir!='none':
@ -188,8 +189,44 @@ build_scripts=[
'src/authm/SConstruct',
]
# Testing
testing=ARGUMENTS.get('tests', 'no')
if testing=='yes':
main_env.Append(testing='yes')
main_env.ParseConfig('cppunit-config --cflags --libs')
main_env.Append(CPPPATH=[
cwd+'/include/test',
'/usr/include/cppunit/' #not provided by cppunit-config command
])
main_env.Append(LIBPATH=[
cwd+'/src/test',
])
main_env.Append(LIBS=[
'nebula_test_common',
])
build_scripts.extend([
'src/authm/test/SConstruct',
'src/common/test/SConstruct',
'src/host/test/SConstruct',
'src/image/test/SConstruct',
'src/lcm/test/SConstruct',
'src/pool/test/SConstruct',
'src/template/test/SConstruct',
'src/test/SConstruct',
'src/um/test/SConstruct',
'src/vm/test/SConstruct',
'src/vnm/test/SConstruct',
])
else:
main_env.Append(testing='no')
for script in build_scripts:
env=main_env.Clone()
SConscript(script, exports='env')

View File

@ -44,10 +44,11 @@ public:
enum Actions
{
SUSPEND_SUCCESS, /**< Send by LCM when a VM is suspended*/
STOP_SUCCESS, /**< Send by LCM when a VM is stopped*/
DONE, /**< Send by LCM when a VM is shut down*/
FAILED, /**< Send by LCM when one of the execution steps fails*/
SUSPEND_SUCCESS,/**< Send by LCM when a VM is suspended*/
STOP_SUCCESS, /**< Send by LCM when a VM is stopped*/
DONE, /**< Send by LCM when a VM is shut down*/
FAILED, /**< Send by LCM when one of the execution steps fails*/
RESUBMIT, /**< Send by LCM when a VM is ready for resubmission*/
FINALIZE
};
@ -200,6 +201,15 @@ public:
int finalize(
int vid);
/**
* Moves a VM to PENDING state preserving any resource (i.e. leases) and id
* @param vid VirtualMachine identification
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
* in a wrong a state
*/
int resubmit(
int vid);
private:
/**
* Thread id for the Dispatch Manager
@ -247,7 +257,8 @@ private:
void done_action(int vid);
void failed_action(int vid);
void resubmit_action(int vid);
};
#endif /*DISPATCH_MANAGER_H*/

167
include/HostHook.h Normal file
View File

@ -0,0 +1,167 @@
/* -------------------------------------------------------------------------- */
/* 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 HOST_HOOK_H_
#define HOST_HOOK_H_
#include <vector>
#include <string>
#include "Hook.h"
#include "Host.h"
using namespace std;
/**
* This class is general Host Allocate Hook that executes a command when the
* Host is inserted in the database. The Host object is looked
*/
class HostAllocateHook : public Hook
{
public:
// -------------------------------------------------------------------------
// Init a LOCAL hook of ALLOCATE type
// -------------------------------------------------------------------------
HostAllocateHook(const string& name,
const string& cmd,
const string& args,
bool remote):
Hook(name, cmd, args, Hook::ALLOCATE, remote){};
~HostAllocateHook(){};
// -------------------------------------------------------------------------
// Hook methods
// -------------------------------------------------------------------------
void do_hook(void *arg);
};
/**
* This class provides basic functionality to store Hook states for state Hooks.
* The state Map is shared by all the State hooks. A maintenance hook that
* updates the map should be added.
*/
class HostStateMapHook: public Hook
{
public:
virtual void do_hook(void *arg) = 0;
protected:
// -------------------------------------------------------------------------
// Init the Map
// -------------------------------------------------------------------------
HostStateMapHook(const string& name,
const string& cmd,
const string& args,
bool remote):
Hook(name, cmd, args, Hook::UPDATE | Hook::ALLOCATE, remote){};
virtual ~HostStateMapHook(){};
// -------------------------------------------------------------------------
// Functions to handle the VM state map
// -------------------------------------------------------------------------
/**
* Gets the state associated to the Host
* @param id of the Host
* @param state (previous) of the Host
* @return 0 if the previous state for the Host has been recorded
*/
int get_state(int id, Host::HostState &state);
/**
* Updates the state associated to the Host
* @param id of the Host
* @param state (current) of the Host
*/
void update_state (int id, Host::HostState state);
/**
* Frees the resources associated with a host
* @param id of the Host
*/
void remove_host (int id);
private:
/**
* The state Map for the Hosts
*/
static map<int,Host::HostState> host_states;
};
/**
* This class is a general Host State Hook that executes a command locally or
* remotelly when the Host gets into a given state (one shot). The Host
* object is looked when the hook is invoked.
*/
class HostStateHook : public HostStateMapHook
{
public:
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
/**
* Creates a HostStateHook
* @param name of the hook
* @param cmd for the hook
* @param args for the hook
* @param remote the hook will be executed on the target resource
* @param _state the hook will be executed when the Host enters this
* state
*/
HostStateHook(const string& name,
const string& cmd,
const string& args,
bool remote,
Host::HostState _state):
HostStateMapHook(name,cmd,args,remote), state(_state){};
~HostStateHook(){};
// -------------------------------------------------------------------------
// Hook methods
// -------------------------------------------------------------------------
void do_hook(void *arg);
private:
/**
* The target Host state
*/
Host::HostState state;
};
/**
* This class implements a state Map updater, one hook of this type should be
* added in order to mantain the VM state map.
*/
class HostUpdateStateHook : public HostStateMapHook
{
public:
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
HostUpdateStateHook():
HostStateMapHook("","","",false){};
~HostUpdateStateHook(){};
// -------------------------------------------------------------------------
// Hook methods
// -------------------------------------------------------------------------
void do_hook(void *arg);
};
#endif

View File

@ -36,8 +36,9 @@ using namespace std;
class HostPool : public PoolSQL
{
public:
HostPool(SqlDB * db);
HostPool(SqlDB * db,
vector<const Attribute *> hook_mads,
const string& hook_location);
~HostPool(){};
@ -68,15 +69,6 @@ public:
return static_cast<Host *>(PoolSQL::get(oid,lock));
};
/** Update a particular Host
* @param host pointer to Host
* @return 0 on success
*/
int update(Host * host)
{
return host->update(db);
};
/**
* Bootstraps the database table(s) associated to the Host pool
*/

View File

@ -34,7 +34,7 @@ class LifeCycleManager : public ActionListener
public:
LifeCycleManager(VirtualMachinePool * _vmpool, HostPool * _hpool):
vmpool(_vmpool),hpool(_hpool)
vmpool(_vmpool),hpool(_hpool)
{
am.addListener(this);
};
@ -68,6 +68,7 @@ public:
SHUTDOWN, /**< Sent by the DM to shutdown a running VM */
RESTART, /**< Sent by the DM to restart a deployed VM */
DELETE, /**< Sent by the DM to delete a VM */
CLEAN, /**< Sent by the DM to cleanup a VM for resubmission*/
FINALIZE
};
@ -75,7 +76,7 @@ public:
* Triggers specific actions to the Life-cycle Manager. This function
* wraps the ActionManager trigger function.
* @param action the LCM action
* @param vid VM unique id. This is the argument of the passed to the
* @param vid VM unique id. This is the argument of the passed to the
* invoked action.
*/
void trigger(
@ -83,7 +84,7 @@ public:
int vid);
/**
* This functions starts a new thread for the Life-cycle Manager. This
* This functions starts a new thread for the Life-cycle Manager. This
* thread will wait in an action loop till it receives ACTION_FINALIZE.
* @return 0 on success.
*/
@ -108,11 +109,11 @@ private:
* Pointer to the Virtual Machine Pool, to access VMs
*/
VirtualMachinePool * vmpool;
/**
* Pointer to the Host Pool, to access hosts
*/
HostPool * hpool;
HostPool * hpool;
/**
* Action engine for the Manager
@ -120,7 +121,7 @@ private:
ActionManager am;
/**
* Function to execute the Manager action loop method within a new pthread
* Function to execute the Manager action loop method within a new pthread
* (requires C linkage)
*/
friend void * lcm_action_loop(void *arg);
@ -134,6 +135,13 @@ private:
const string & action,
void * arg);
/**
* Cleans up a VM, canceling any pending or ongoing action and closing
* the history registers
* @param vm with the lock aquired
*/
void clean_up_vm (VirtualMachine *vm);
void save_success_action(int vid);
void save_failure_action(int vid);
@ -145,24 +153,24 @@ private:
void shutdown_success_action(int vid);
void shutdown_failure_action(int vid);
void cancel_success_action(int vid);
void cancel_failure_action(int vid);
void monitor_failure_action(int vid);
void monitor_suspend_action(int vid);
void monitor_done_action(int vid);
void prolog_success_action(int vid);
void prolog_failure_action(int vid);
void epilog_success_action(int vid);
void epilog_failure_action(int vid);
void epilog_failure_action(int vid);
void deploy_action(int vid);
@ -173,7 +181,7 @@ private:
void stop_action(int vid);
void cancel_action(int vid);
void checkpoint_action(int vid);
void migrate_action(int vid);
@ -188,7 +196,9 @@ private:
void delete_action(int vid);
void timer_action();
void clean_action(int vid);
void timer_action();
};
#endif /*LIFE_CYCLE_MANAGER_H_*/

View File

@ -47,7 +47,7 @@ public:
int port,
const string& user,
const string& password,
char * database);
const char * database);
~MySqlDB();
@ -113,7 +113,7 @@ public:
int port,
string user,
string password,
char * database)
const char * database)
{
throw runtime_error("Aborting oned, MySQL support not compiled!");
};

View File

@ -65,7 +65,7 @@ public:
* @param vid VM unique id. This is the argument of the passed to the
* invoked action.
*/
void trigger(
virtual void trigger(
Actions action,
int vid);

View File

@ -38,7 +38,7 @@ class VirtualMachine : public PoolObjectSQL
{
public:
// -------------------------------------------------------------------------
// VM States
// VM States
// -------------------------------------------------------------------------
/**
@ -76,7 +76,7 @@ public:
SHUTDOWN = 12,
CANCEL = 13,
FAILURE = 14,
DELETE = 15,
CLEANUP = 15,
UNKNOWN = 16
};
@ -218,11 +218,11 @@ public:
* Adds a new history record an writes it in the database.
*/
void add_history(
int hid,
string& hostname,
string& vm_dir,
string& vmm_mad,
string& tm_mad);
int hid,
string& hostname,
string& vm_dir,
string& vmm_mad,
string& tm_mad);
/**
* Duplicates the last history record. Only the host related fields are
@ -300,9 +300,9 @@ public:
/**
* Returns the transfer filename. The transfer file is in the form:
* $ONE_LOCATION/var/$VM_ID/transfer.$SEQ
* $ONE_LOCATION/var/$VM_ID/transfer.$SEQ
* or, in case that OpenNebula is installed in root
* /var/lib/one/$VM_ID/transfer.$SEQ
* /var/lib/one/$VM_ID/transfer.$SEQ
* The hasHistory() function MUST be called before this one.
* @return the transfer filename
*/
@ -313,9 +313,9 @@ public:
/**
* Returns the deployment filename. The deployment file is in the form:
* $ONE_LOCATION/var/$VM_ID/deployment.$SEQ
* $ONE_LOCATION/var/$VM_ID/deployment.$SEQ
* or, in case that OpenNebula is installed in root
* /var/lib/one/$VM_ID/deployment.$SEQ
* /var/lib/one/$VM_ID/deployment.$SEQ
* The hasHistory() function MUST be called before this one.
* @return the deployment filename
*/
@ -339,7 +339,7 @@ public:
/**
* Returns the remote deployment filename. The file is in the form:
* $VM_DIR/$VM_ID/images/deployment.$SEQ
* $VM_DIR/$VM_ID/images/deployment.$SEQ
* The hasHistory() function MUST be called before this one.
* @return the deployment filename
*/
@ -351,7 +351,7 @@ public:
/**
* Returns the checkpoint filename for the current host. The checkpoint file
* is in the form:
* $VM_DIR/$VM_ID/images/checkpoint
* $VM_DIR/$VM_ID/images/checkpoint
* The hasHistory() function MUST be called before this one.
* @return the checkpoint filename
*/
@ -362,9 +362,9 @@ public:
/**
* Returns the remote VM directory. The VM remote dir is in the form:
* $VM_DIR/$VM_ID/
* $VM_DIR/$VM_ID/
* or, in case that OpenNebula is installed in root
* /var/lib/one/$VM_ID/
* /var/lib/one/$VM_ID/
* The hasHistory() function MUST be called before this one.
* @return the remote directory
*/
@ -375,7 +375,7 @@ public:
/**
* Returns the local VM directory. The VM local dir is in the form:
* $ONE_LOCATION/var/$VM_ID/
* $ONE_LOCATION/var/$VM_ID/
* The hasHistory() function MUST be called before this one.
* @return the remote directory
*/
@ -989,7 +989,7 @@ protected:
// DataBase implementation
// *************************************************************************
enum ColNames
enum ColNames
{
OID = 0,
UID = 1,

View File

@ -63,7 +63,7 @@ public:
* @param vid VM unique id. This is the argument of the passed to the
* invoked action.
*/
void trigger(
virtual void trigger(
Actions action,
int vid);

132
include/test/NebulaTest.h Normal file
View File

@ -0,0 +1,132 @@
/* -------------------------------------------------------------------------- */
/* 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
{
protected:
NebulaTest():mysql(false), need_host_pool(false), need_vm_pool(false),
need_vnet_pool(false), need_image_pool(false),
need_user_pool(false), need_vmm(false),
need_im(false), need_tm(false),
need_lcm(false), need_dm(false),
need_rm(false), need_hm(false),
need_authm(false)
{};
virtual ~NebulaTest(){};
static NebulaTest * the_tester; /*<< Pointer to the actual tester */
public:
bool mysql;
bool need_host_pool;
bool need_vm_pool;
bool need_vnet_pool;
bool need_image_pool;
bool need_user_pool;
bool need_vmm;
bool need_im;
bool need_tm;
bool need_lcm;
bool need_dm;
bool need_rm;
bool need_hm;
bool need_authm;
static NebulaTest * instance()
{
return the_tester;
};
// ------------------------------------------------------------------------
// Pools
// ------------------------------------------------------------------------
virtual VirtualMachinePool* create_vmpool(SqlDB* db, string hook_location);
virtual HostPool* create_hpool(SqlDB* db, string hook_location);
virtual VirtualNetworkPool* create_vnpool(SqlDB* db,
string mac_prefix,
int size);
virtual UserPool* create_upool(SqlDB* db);
virtual ImagePool* create_ipool( SqlDB* db,
string repository_path,
string default_image_type,
string default_device_prefix);
// ------------------------------------------------------------------------
// Managers
// ------------------------------------------------------------------------
virtual VirtualMachineManager* create_vmm(VirtualMachinePool* vmpool,
HostPool* hpool,
time_t timer_period,
time_t poll_period);
virtual LifeCycleManager* create_lcm(VirtualMachinePool* vmpool,
HostPool* hpool);
virtual InformationManager* create_im(HostPool* hpool,
time_t timer_period,
string remotes_location);
virtual TransferManager* create_tm(VirtualMachinePool* vmpool,
HostPool* hpool);
virtual DispatchManager* create_dm(VirtualMachinePool* vmpool,
HostPool* hpool);
virtual RequestManager* create_rm(
VirtualMachinePool * vmpool,
HostPool * hpool,
VirtualNetworkPool * vnpool,
UserPool * upool,
ImagePool * ipool,
string log_file);
virtual HookManager* create_hm(VirtualMachinePool * vmpool);
virtual AuthManager* create_authm(time_t timer_period);
};
#endif /*NEBULA_TEST_H_*/

220
include/test/OneUnitTest.h Normal file
View File

@ -0,0 +1,220 @@
/* -------------------------------------------------------------------------- */
/* 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 ONE_UNIT_TEST_H_
#define ONE_UNIT_TEST_H_
#include <string>
#include <iostream>
#include <stdlib.h>
#include <getopt.h>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/XmlOutputter.h>
#include <unistd.h>
#include "SqlDB.h"
#include "SqliteDB.h"
#include "MySqlDB.h"
using namespace std;
#define SETUP_XML_WRITER(runner, output) \
ofstream outputFile(output); \
CppUnit::XmlOutputter* outputter = \
new CppUnit::XmlOutputter(&runner.result(), outputFile); \
\
runner.setOutputter(outputter);
#define END_XML_WRITER outputFile.close();
/* ************************************************************************* */
/* ************************************************************************* */
class OneUnitTest : public CppUnit::TestFixture
{
protected:
// Global flag to use either Sqlite or MySQL
static bool mysql;
static SqlDB * db;
static string db_name;
static string xml_name;
public:
void create_db()
{
if (mysql)
{
db = new MySqlDB( "localhost",0,
"oneadmin","oneadmin",NULL);
ostringstream oss1;
oss1 << "DROP DATABASE IF EXISTS " << db_name;
db->exec(oss1);
ostringstream oss;
oss << "CREATE DATABASE " << db_name;
db->exec(oss);
ostringstream oss2;
oss2 << "use " << db_name;
db->exec(oss2);
}
else
{
unlink(db_name.c_str());
db = new SqliteDB(db_name);
}
};
void delete_db()
{
if (mysql)
{
ostringstream oss;
oss << "DROP DATABASE IF EXISTS " << db_name;
db->exec(oss);
}
else
{
unlink(db_name.c_str());
}
if ( db != 0 )
{
delete db;
}
};
static SqlDB * get_db()
{
return db;
}
// *****************************************************************************
// *****************************************************************************
static void show_options ()
{
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";
}
/*
* Not a true main, but a static method that can be called from the
* child classes' true main.
* Options:
* s: run sqlite tests
* m: run mysql tests
*/
static int main(int argc,
char ** argv,
CPPUNIT_NS::TestSuite* suite,
string xml_name = "output.xml")
{
// 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;
}
// When a DB query fails, it tries to log the error.
// 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, xml_name.c_str())
runner.addTest( suite );
if (sqlite_flag)
{
OneUnitTest::mysql = false;
NebulaLog::log("Test", Log::INFO, "Running Sqlite tests...");
cout << "\nRunning Sqlite tests...\n";
}
else
{
OneUnitTest::mysql = 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;
}
};
/* -----------------------------------------------------------------------------
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, TestClass::suite());
}
----------------------------------------------------------------------------- */
#endif // ONE_UNIT_TEST_H_

View File

@ -18,25 +18,10 @@
#define POOL_TEST_H_
#include <string>
#include <iostream>
#include <stdlib.h>
#include <getopt.h>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <unistd.h>
#include "SqlDB.h"
#include "SqliteDB.h"
#include "MySqlDB.h"
#include "PoolSQL.h"
#include "Nebula.h"
#include "test/one_test_common.h"
#include "OneUnitTest.h"
// Use this macro in sub-classes to add all the tests defined here
#define ALL_POOLTEST_CPPUNIT_TESTS() \
@ -52,21 +37,12 @@ using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
class PoolTest : public CppUnit::TestFixture
class PoolTest : public OneUnitTest
{
private:
// Global flag to use either Sqlite or MySQL
static bool mysql;
protected:
PoolSQL * pool;
SqlDB * db;
PoolObjectSQL* obj;
static string db_name;
PoolSQL * pool;
PoolObjectSQL * obj;
/*
* Bootstrap the DB with the neccessary tables for the test
@ -89,35 +65,14 @@ protected:
*/
virtual void check(int index, PoolObjectSQL* obj) = 0;
PoolTest():pool(0),db(0){};
PoolTest():pool(0){};
virtual ~PoolTest(){};
public:
void setUp()
{
if (mysql)
{
db = new MySqlDB("localhost",0,"oneadmin","oneadmin",NULL);
ostringstream oss1;
oss1 << "DROP DATABASE IF EXISTS " << db_name;
db->exec(oss1);
ostringstream oss;
oss << "CREATE DATABASE " << db_name;
db->exec(oss);
ostringstream oss2;
oss2 << "use " << db_name;
db->exec(oss2);
}
else
{
unlink(db_name.c_str());
db = new SqliteDB(db_name);
}
create_db();
bootstrap(db);
@ -126,27 +81,12 @@ public:
void tearDown()
{
delete_db();
if (mysql)
if ( pool != 0 )
{
ostringstream oss;
oss << "DROP DATABASE IF EXISTS " << db_name;
db->exec(oss);
}
else
{
unlink(db_name.c_str());
}
if ( pool != 0 )
{
delete pool;
}
if ( db != 0 )
{
delete db;
}
}
};
// *****************************************************************************
@ -281,103 +221,8 @@ public:
obj = pool->get(oid_1, false);
check(1, obj);
};
// *****************************************************************************
static void show_options ()
{
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";
}
/*
* Not a true main, but a static method that can be called from the
* child classes' true main.
* Options:
* s: run sqlite tests
* m: run mysql tests
*/
static int main(int argc, char ** argv, CPPUNIT_NS::TestSuite* 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;
}
// When a DB query fails, it tries to log the error.
// 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( suite );
if (sqlite_flag)
{
PoolTest::mysql = false;
NebulaLog::log("Test", Log::INFO, "Running Sqlite tests...");
cout << "\nRunning Sqlite tests...\n";
}
else
{
PoolTest::mysql = 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;
}
};
// -----------------------------------------------------------------------------
bool PoolTest::mysql;
string PoolTest::db_name = "ONE_test_database";
// -----------------------------------------------------------------------------
#endif // POOL_TEST_H_

View File

@ -1,12 +0,0 @@
#include <cppunit/XmlOutputter.h>
#define SETUP_XML_WRITER(runner, output) \
ofstream outputFile(output); \
CppUnit::XmlOutputter* outputter = \
new CppUnit::XmlOutputter(&runner.result(), outputFile); \
\
runner.setOutputter(outputter);
#define END_XML_WRITER outputFile.close();

View File

@ -527,6 +527,7 @@ TM_EXAMPLE_SHARE_FILES="share/examples/tm/tm_clone.sh \
HOOK_SHARE_FILES="share/hooks/ebtables-xen \
share/hooks/ebtables-kvm \
share/hooks/ebtables-flush \
share/hooks/host_error.rb \
share/hooks/image.rb"
#-------------------------------------------------------------------------------

View File

@ -119,15 +119,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",
@ -297,6 +301,22 @@ 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 = [
@ -314,6 +334,21 @@ VM_HOOK = [
#-------------------------------------------------------------------------------
#-------------------------------- Host Hook -----------------------------------
# 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 ]
#-------------------------------------------------------------------------------
#-------------------------------- Hook Examples --------------------------------
#VM_HOOK = [
# name = "dhcp",
@ -328,13 +363,25 @@ VM_HOOK = [
# arguments = '$NIC[MAC, Network = "Private"]',
# remote = "yes" ]
#-------------------------------------------------------------------------------
#VM_HOOK = [
# name = "mail",
# on = "running",
# command = "/usr/local/one/bin/send_mail",
# arguments = "$VMID $NAME",
#HOST_HOOK = [
# name = "bootstrap",
# on = "create",
# command = "set_up_host",
# arguments = "$HID",
# remote = "no" ]
#------------------------------------------------------------------------------
#VM_HOOK = [
# name = "on_failure_delete",
# on = "FAILURE",
# command = "onevm delete",
# arguments = "$VMID" ]
#-------------------------------------------------------------------------------
#VM_HOOK = [
# name = "on_failure_resubmit",
# on = "FAILURE",
# command = "onevm resubmit",
# arguments = "$VMID" ]
#-------------------------------------------------------------------------------
#*******************************************************************************
# Auth Manager Configuration

105
share/hooks/host_error.rb Executable file
View File

@ -0,0 +1,105 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
####################################################
# Script to implement host failure tolerance
# It can be set to
# -r resubmit VMs running in the host
# -d delete VMs running in the host
####################################################
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
VMDIR="/var/lib/one"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
VMDIR=ONE_LOCATION+"/var"
end
$: << RUBY_LIB_LOCATION
require 'OpenNebula'
include OpenNebula
if !(host_id=ARGV[0])
exit -1
end
if !(mode=ARGV[1]) # By default, resubmit VMs
mode = "-r"
end
if !(force=ARGV[2]) # By default, don't resubmit/finalize suspended VMs
force = "n"
end
begin
client = Client.new()
rescue Exception => e
puts "Error: #{e}"
exit -1
end
# Retrieve hostname
host = OpenNebula::Host.new_with_id(host_id, client)
exit -1 if OpenNebula.is_error?(host)
host.info
host_name = host.name
# Loop through all vms
vms = VirtualMachinePool.new(client)
exit -1 if OpenNebula.is_error?(vms)
vms.info
vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[STATE=3]/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
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

View File

@ -80,11 +80,30 @@ elif [ "$VAL_CALL" = "yes" ] ; then
CALLER="valgrind --tool=callgrind"
fi
TESTS=`find $TWD_DIR -name test -type d | grep -v ruby`
if [ "$BUILD" = "yes" ] ; then
cd ../..
scons tests=yes $BUILD_ARGS
cd $BASE_DIR
exit 0
fi
if [ "$CLEAR" = "yes" ] ; then
cd ../..
scons tests=yes -c
cd $BASE_DIR
fi
TESTS=`find $TWD_DIR -name test -type d`
for i in $TESTS ; do
cd $BASE_DIR
if [ ! -f "$i/SConstruct" ] ; then
continue
fi
echo ; echo
echo "#####################################################################"
echo "#####################################################################"
@ -95,17 +114,14 @@ for i in $TESTS ; do
cd $i
if [ "$CLEAR" = "yes" ] ; then
scons -c
rm -f callgrind.out* test.db* *.log* memgrid.out*
elif [ "$BUILD" = "yes" ] ; then
scons $BUILD_ARGS
rm -f callgrind.out* test.db* *.log* memgrid.out* *.xml ONE_test_database*
else
for j in `ls test*` ; do
if [ -x $j ] ; then
echo ; echo "---------------------------------------------------------------------"
echo "Test Program: $j"
if [ -x $j ] ; then
echo ; echo "---------------------------------------------------------------------"
echo "Test Program: $j"
echo "---------------------------------------------------------------------"
$CALLER ./$j $TEST_ARGS
$CALLER ./$j $TEST_ARGS
echo "---------------------------------------------------------------------"
fi
done

View File

@ -20,29 +20,21 @@
#include <unistd.h>
#include <pthread.h>
#include "test/OneUnitTest.h"
#include "AuthManager.h"
#include "Template.h"
#include "NebulaLog.h"
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include "test/one_test_common.h"
using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
class AuthManagerTest : public CppUnit::TestFixture
class AuthManagerTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (AuthManagerTest);
@ -288,20 +280,5 @@ private:
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner runner;
NebulaLog::init_log_system(NebulaLog::FILE, Log::DEBUG,"test.log");
NebulaLog::log("Test", Log::INFO, "Test started");
SETUP_XML_WRITER(runner, "AuthManagerTest.xml");
runner.addTest(AuthManagerTest::suite());
runner.run();
END_XML_WRITER
NebulaLog::finalize_log_system();
return 0;
return OneUnitTest::main(argc, argv, AuthManagerTest::suite());
}

View File

@ -15,41 +15,9 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
Import('env')
# This is the absolute path where the project is located
cwd="../../../"
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# Add builders for flex and bison
add_lex(main_env)
add_bison(main_env)
# Include dirs
main_env.Append(CPPPATH=[
cwd + '/include',
'/usr/include/cppunit/'
])
# Library dirs
main_env.Append(LIBPATH=[
cwd + '/src/common',
cwd + '/src/template',
cwd + '/src/mad',
cwd + '/src/nebula',
cwd + '/src/authm',
cwd + '/src/sql',
cwd + '/src/log',
])
main_env.Append(LIBS=[
env.Prepend(LIBS=[
'nebula_template',
'nebula_common',
'nebula_core',
@ -57,36 +25,7 @@ main_env.Append(LIBS=[
'nebula_authm',
'nebula_sql',
'nebula_log',
'cppunit',
'dl',
'pthread',
'ssl'
'crypto'
])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# MYSQL
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# 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', ])
# MySQL
mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=[ 'mysqlclient', ])
main_env.Program('test','AuthManagerTest.cc')
#
env.Program('test','AuthManagerTest.cc')

View File

@ -1,21 +1,20 @@
#!/bin/bash
# --------------------------------------------------------------------------
# Copyright 2002-2006 GridWay Team, Distributed Systems Architecture
# Group, Universidad Complutense de Madrid
#
# 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. #
#--------------------------------------------------------------------------- #
echo "MAD started" >> mad.log

View File

@ -359,12 +359,15 @@ Commands:
(Set a different type for the new Image)
onevm saveas <vm_id> <disk_id> <image_name> -t/--type <type>
* delete (Deletes a VM from the pool and DB)
* delete (Deletes a VM from the pool)
onevm delete <vm_id>
* restart (Resubmits the VM after failure)
* restart (Forces a re-deployment of a VM in UNKNOWN or BOOT state)
onevm restart <vm_id>
* resubmit (Resubmits a VM to PENDING state)
onevm resubmit <vm_id>
* list (Shows VMs in the pool)
onevm list <filter_flag>
where filter_flag can be
@ -673,6 +676,23 @@ when "restart"
end
end
when "resubmit"
check_parameters("resubmit", 1)
args=expand_args(ARGV)
args.each do |param|
vm_id=get_vm_id(param)
vm=OpenNebula::VirtualMachine.new_with_id(vm_id, get_one_client)
result=vm.resubmit
if is_successful?(result)
puts "Resubmitting VM" if ops[:verbose]
else
break
end
end
when "list"
ops.merge!(get_user_flags)
if !ops[:xml]

View File

@ -15,52 +15,14 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
Import('env')
# This is the absolute path where the project is located
cwd="../../../"
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# Add builders for flex and bison
add_lex(main_env)
add_bison(main_env)
# Include dirs
main_env.Append(CPPPATH=[
cwd + '/include',
'/usr/include/cppunit/'
])
# Library dirs
main_env.Append(LIBPATH=[
cwd + '/src/common',
])
main_env.Append(LIBS=[
env.Prepend(LIBS=[
'nebula_common',
'cppunit',
'dl',
'pthread'
'nebula_log',
])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# Linking flags
main_env.Append(LDFLAGS=["-g"])
main_env.Program('test_sa','single_attribute.cc')
main_env.Program('test_va','vector_attribute.cc')
main_env.Program('test_am','action_manager.cc')
main_env.Program('test_collector','mem_collector.cc')
env.Program('test_sa','single_attribute.cc')
env.Program('test_va','vector_attribute.cc')
env.Program('test_am','action_manager.cc')
env.Program('test_collector','mem_collector.cc')

View File

@ -1,17 +1,26 @@
/* -------------------------------------------------------------------------- */
/* 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 "test/OneUnitTest.h"
#include "ActionManager.h"
#include <string>
#include <iostream>
#include <map>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include "test/one_test_common.h"
using namespace std;
extern "C" void * addsub_loop(void *arg);
@ -23,7 +32,7 @@ public:
{
am.addListener(this);
};
~AddSub(){};
void add(int i)
@ -44,12 +53,12 @@ public:
am.trigger("SUB",(void *) p);
}
int value()
int value()
{
return counter;
}
pthread_t id()
pthread_t id()
{
return pid;
}
@ -63,7 +72,7 @@ public:
pthread_create(&pid,&pattr,addsub_loop,(void *) this);
}
void end()
{
am.trigger(ActionListener::ACTION_FINALIZE,0);
@ -109,8 +118,15 @@ extern "C" void * addsub_loop(void *arg)
return 0;
};
class ActionManagerTest : public CppUnit::TestFixture
class ActionManagerTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (ActionManagerTest);
CPPUNIT_TEST (test_add);
CPPUNIT_TEST (test_sub);
CPPUNIT_TEST_SUITE_END ();
private:
AddSub *as;
@ -157,33 +173,10 @@ public:
CPPUNIT_ASSERT(as->value() == -8);
}
static CppUnit::TestSuite * suite()
{
CppUnit::TestSuite *ts=new CppUnit::TestSuite("ActionManager Tests");
ts->addTest(new CppUnit::TestCaller<ActionManagerTest>(
"add() Test",
&ActionManagerTest::test_add));
ts->addTest(new CppUnit::TestCaller<ActionManagerTest>(
"sub() Test",
&ActionManagerTest::test_sub));
return ts;
}
};
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner tr;
SETUP_XML_WRITER(tr, "action_manager.xml");
tr.addTest(ActionManagerTest::suite());
tr.run();
END_XML_WRITER
return 0;
return OneUnitTest::main(argc, argv, ActionManagerTest::suite(),
"action_manager.xml");
}

View File

@ -21,18 +21,19 @@ extern "C"
#include <string.h>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include "test/one_test_common.h"
#include "test/OneUnitTest.h"
using namespace std;
class MemCollectorTest : public CppUnit::TestFixture
class MemCollectorTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (MemCollectorTest);
CPPUNIT_TEST (test_all_free);
CPPUNIT_TEST (test_realloc);
CPPUNIT_TEST_SUITE_END ();
public:
void setUp()
{
@ -57,7 +58,7 @@ public:
CPPUNIT_ASSERT(strcmp(mc.str_buffer[1],"ADIOS")==0);
CPPUNIT_ASSERT(strcmp(mc.str_buffer[2],"HELLO")==0);
CPPUNIT_ASSERT(strcmp(mc.str_buffer[3],"BYE")==0);
//Check the content of the strings
CPPUNIT_ASSERT(strcmp(st1,"HOLA")==0);
CPPUNIT_ASSERT(strcmp(st2,"ADIOS")==0);
@ -92,32 +93,10 @@ public:
CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK * 4);
}
static CppUnit::TestSuite * suite()
{
CppUnit::TestSuite *ts=new CppUnit::TestSuite("mem_collector Tests");
ts->addTest(new CppUnit::TestCaller<MemCollectorTest>(
"test_all_free() Test",
&MemCollectorTest::test_all_free));
ts->addTest(new CppUnit::TestCaller<MemCollectorTest>(
"test_realloc() Test",
&MemCollectorTest::test_realloc));
return ts;
}
};
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner tr;
SETUP_XML_WRITER(tr, "mem_collector.xml");
tr.addTest(MemCollectorTest::suite());
tr.run();
END_XML_WRITER
return 0;
return OneUnitTest::main(argc, argv, MemCollectorTest::suite(),
"mem_collector.xml");
}

View File

@ -1,23 +1,44 @@
/* -------------------------------------------------------------------------- */
/* 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 "Attribute.h"
#include <string>
#include <iostream>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include "test/one_test_common.h"
#include "test/OneUnitTest.h"
using namespace std;
class SingleAttributeTest : public CppUnit::TestFixture
class SingleAttributeTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (SingleAttributeTest);
CPPUNIT_TEST (test_type);
CPPUNIT_TEST (test_name);
CPPUNIT_TEST (test_value);
CPPUNIT_TEST (test_marshall);
CPPUNIT_TEST (test_xml);
CPPUNIT_TEST (test_replace);
CPPUNIT_TEST_SUITE_END ();
private:
SingleAttribute *a, *b;
public:
void setUp()
{
@ -90,48 +111,10 @@ public:
CPPUNIT_ASSERT(b->value() == "new_value_b");
}
static CppUnit::TestSuite * suite()
{
CppUnit::TestSuite *ts=new CppUnit::TestSuite("SingleAttribute Tests");
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
"type() Test",
&SingleAttributeTest::test_type));
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
"name() Test",
&SingleAttributeTest::test_name));
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
"value() Test",
&SingleAttributeTest::test_value));
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
"marshall() Test",
&SingleAttributeTest::test_marshall));
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
"to_xml() Test",
&SingleAttributeTest::test_xml));
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
"replace() Test",
&SingleAttributeTest::test_replace));
return ts;
}
};
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner tr;
SETUP_XML_WRITER(tr, "single_attribute.xml");
tr.addTest(SingleAttributeTest::suite());
tr.run();
END_XML_WRITER
return 0;
return OneUnitTest::main(argc, argv, SingleAttributeTest::suite(),
"single_attribute.xml");
}

View File

@ -1,21 +1,42 @@
/* -------------------------------------------------------------------------- */
/* 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 "Attribute.h"
#include <string>
#include <iostream>
#include <map>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include "test/one_test_common.h"
#include "test/OneUnitTest.h"
using namespace std;
class VectorAttributeTest : public CppUnit::TestFixture
class VectorAttributeTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (VectorAttributeTest);
CPPUNIT_TEST (test_type);
CPPUNIT_TEST (test_name);
CPPUNIT_TEST (test_value);
CPPUNIT_TEST (test_marshall);
CPPUNIT_TEST (test_xml);
CPPUNIT_TEST (test_replace);
CPPUNIT_TEST_SUITE_END ();
private:
VectorAttribute *a, *b;
map<string,string> b_value;
@ -81,7 +102,7 @@ public:
CPPUNIT_ASSERT(c.vector_value("attr1") == "val1");
CPPUNIT_ASSERT(c.vector_value("attr2") == "val2");
CPPUNIT_ASSERT(c.vector_value("attr3") == "val3");
delete am;
delete bm;
}
@ -120,51 +141,10 @@ public:
CPPUNIT_ASSERT(b->vector_value("attr3").empty() == true);
CPPUNIT_ASSERT(b->value() == nm);
}
static CppUnit::TestSuite * suite()
{
CppUnit::TestSuite *ts=new CppUnit::TestSuite("VectorAttribute Tests");
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
"type() Test",
&VectorAttributeTest::test_type));
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
"name() Test",
&VectorAttributeTest::test_name));
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
"value() Test",
&VectorAttributeTest::test_value));
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
"marshall() Test",
&VectorAttributeTest::test_marshall));
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
"to_xml() Test",
&VectorAttributeTest::test_xml));
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
"replace() Test",
&VectorAttributeTest::test_replace));
return ts;
}
};
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner tr;
SETUP_XML_WRITER(tr, "vector_attribute.xml");
tr.addTest(VectorAttributeTest::suite());
tr.run();
END_XML_WRITER
return 0;
return OneUnitTest::main(argc, argv, VectorAttributeTest::suite(),
"vector_attribute.xml");
}

View File

@ -85,6 +85,10 @@ void DispatchManager::trigger(Actions action, int _vid)
aname = "FAILED";
break;
case RESUBMIT:
aname = "RESUBMIT";
break;
case FINALIZE:
aname = ACTION_FINALIZE;
break;
@ -130,6 +134,10 @@ void DispatchManager::do_action(const string &action, void * arg)
{
failed_action(vid);
}
else if (action == "RESUBMIT")
{
resubmit_action(vid);
}
else if (action == ACTION_FINALIZE)
{
NebulaLog::log("DiM",Log::INFO,"Stopping Dispatch Manager...");

View File

@ -597,3 +597,58 @@ int DispatchManager::finalize(
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int DispatchManager::resubmit(int vid)
{
VirtualMachine * vm;
ostringstream oss;
int rc = 0;
Nebula& nd = Nebula::instance();
LifeCycleManager * lcm = nd.get_lcm();
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
switch (vm->get_state())
{
case VirtualMachine::SUSPENDED:
NebulaLog::log("DiM",Log::ERROR,
"Can not resubmit a suspended VM. Resume it first");
rc = -2;
break;
case VirtualMachine::INIT: // No need to do nothing here
case VirtualMachine::PENDING:
break;
case VirtualMachine::HOLD: // Move the VM to PENDING in any of these
case VirtualMachine::STOPPED:
case VirtualMachine::FAILED:
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_state(VirtualMachine::PENDING);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is PENDING.");
break;
case VirtualMachine::ACTIVE: //Cleanup VM resources before PENDING
lcm->trigger(LifeCycleManager::CLEAN,vid);
break;
case VirtualMachine::DONE:
NebulaLog::log("DiM",Log::ERROR,
"Can not resubmit a VM already in DONE state");
rc = -2;
break;
}
vm->unlock();
return rc;
}

View File

@ -28,7 +28,8 @@ void DispatchManager::suspend_success_action(int vid)
return;
}
if (vm->get_state() == VirtualMachine::ACTIVE )
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND))
{
vm->set_state(VirtualMachine::SUSPENDED);
@ -66,7 +67,8 @@ void DispatchManager::stop_success_action(int vid)
return;
}
if (vm->get_state() == VirtualMachine::ACTIVE )
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::EPILOG_STOP))
{
vm->set_state(VirtualMachine::STOPPED);
@ -95,7 +97,10 @@ void DispatchManager::stop_success_action(int vid)
void DispatchManager::done_action(int vid)
{
VirtualMachine * vm;
VirtualMachine * vm;
VirtualMachine::LcmState lcm_state;
VirtualMachine::VmState dm_state;
vm = vmpool->get(vid,true);
@ -104,7 +109,13 @@ void DispatchManager::done_action(int vid)
return;
}
if ( vm->get_state() == VirtualMachine::ACTIVE )
lcm_state = vm->get_lcm_state();
dm_state = vm->get_state();
if ((dm_state == VirtualMachine::ACTIVE) &&
(lcm_state == VirtualMachine::EPILOG ||
lcm_state == VirtualMachine::CANCEL ||
lcm_state == VirtualMachine::CLEANUP ))
{
vm->set_state(VirtualMachine::DONE);
@ -147,17 +158,21 @@ void DispatchManager::failed_action(int vid)
return;
}
vm->set_state(VirtualMachine::LCM_INIT);
if (vm->get_lcm_state() == VirtualMachine::FAILURE)
{
vm->set_state(VirtualMachine::FAILED);
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_exit_time(time(0));
vm->set_state(VirtualMachine::FAILED);
vmpool->update(vm);
vm->set_exit_time(time(0));
vm->log("DiM", Log::INFO, "New VM state is FAILED");
vmpool->update(vm);
vm->unlock();
vm->log("DiM", Log::INFO, "New VM state is FAILED");
vm->unlock();
}
return;
}
@ -165,3 +180,33 @@ void DispatchManager::failed_action(int vid)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::resubmit_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return;
}
if (vm->get_lcm_state() == VirtualMachine::CLEANUP)
{
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_state(VirtualMachine::PENDING);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is PENDING");
vm->unlock();
}
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -26,8 +26,6 @@ source_files=[
'HookManagerDriver.cc'
]
test_names=[]
# Build library
env.StaticLibrary(lib_name, source_files)

41
src/hm_mad/test/dummy Executable file
View File

@ -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

210
src/host/HostHook.cc Normal file
View File

@ -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. */
/* -------------------------------------------------------------------------- */
#include "HostHook.h"
#include "Host.h"
#include "Nebula.h"
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void HostAllocateHook::do_hook(void *arg)
{
Host * host;
string parsed_args = args;
size_t found;
host = static_cast<Host *>(arg);
if ( host == 0 )
{
return;
}
found = args.find("$HID");
if ( found !=string::npos )
{
ostringstream oss;
oss << host->get_oid();
parsed_args.replace(found,4,oss.str());
}
Nebula& ne = Nebula::instance();
HookManager * hm = ne.get_hm();
const HookManagerDriver * hmd = hm->get();
if ( hmd != 0 )
{
if ( remote == true )
{
hmd->execute(host->get_oid(),
name,
host->get_hostname(),
cmd,
parsed_args);
}
else
{
hmd->execute(host->get_oid(),name,cmd,parsed_args);
}
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
map<int,Host::HostState> HostStateMapHook::host_states;
// -----------------------------------------------------------------------------
int HostStateMapHook::get_state(int id, Host::HostState &state)
{
map<int,Host::HostState>::iterator it;
it = host_states.find(id);
if ( it == host_states.end() )
{
return -1;
}
state = it->second;
return 0;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void HostStateMapHook::update_state (int id, Host::HostState state)
{
map<int,Host::HostState>::iterator it;
it = host_states.find(id);
if ( it == host_states.end() )
{
host_states.insert(make_pair(id,state));
}
else
{
it->second = state;
}
}
// -----------------------------------------------------------------------------
void HostStateMapHook::remove_host (int id)
{
map<int,Host::HostState>::iterator it;
it = host_states.find(id);
if ( it != host_states.end() )
{
host_states.erase(it);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void HostStateHook::do_hook(void *arg)
{
Host * host;
int rc;
Host::HostState prev_state, cur_state;
host = static_cast<Host *>(arg);
if ( host == 0 )
{
return;
}
rc = get_state(host->get_oid(), prev_state);
if ( rc != 0 )
{
return;
}
cur_state = host->get_state();
if ( prev_state == cur_state ) //Still in the same state
{
return;
}
if ( cur_state == this->state )
{
string parsed_args = args;
size_t found;
found = args.find("$HID");
if ( found !=string::npos )
{
ostringstream oss;
oss << host->get_oid();
parsed_args.replace(found,4,oss.str());
}
Nebula& ne = Nebula::instance();
HookManager * hm = ne.get_hm();
const HookManagerDriver * hmd = hm->get();
if ( hmd != 0 )
{
if ( remote == true)
{
hmd->execute(host->get_oid(),
name,
host->get_hostname(),
cmd,
parsed_args);
}
else
{
hmd->execute(host->get_oid(),name,cmd,parsed_args);
}
}
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void HostUpdateStateHook::do_hook(void *arg)
{
Host * host = static_cast<Host *>(arg);
if ( host == 0 )
{
return;
}
update_state(host->get_oid(), host->get_state());
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

View File

@ -15,12 +15,13 @@
/* -------------------------------------------------------------------------- */
/* ************************************************************************** */
/* Host Pool */
/* Host Pool */
/* ************************************************************************** */
#include <stdexcept>
#include "HostPool.h"
#include "HostHook.h"
#include "ClusterPool.h"
#include "NebulaLog.h"
@ -41,8 +42,13 @@ int HostPool::init_cb(void *nil, int num, char **values, char **names)
/* -------------------------------------------------------------------------- */
HostPool::HostPool(SqlDB* db):PoolSQL(db,Host::table)
HostPool::HostPool(SqlDB* db,
vector<const Attribute *> hook_mads,
const string& hook_location)
: PoolSQL(db,Host::table)
{
// ------------------ Initialize Cluster Array ----------------------
ostringstream sql;
set_callback(static_cast<Callbackable::Callback>(&HostPool::init_cb));
@ -63,6 +69,103 @@ HostPool::HostPool(SqlDB* db):PoolSQL(db,Host::table)
throw runtime_error("Could not create default cluster HostPool");
}
}
// ------------------ Initialize Hooks fot the pool ----------------------
const VectorAttribute * vattr;
string name;
string on;
string cmd;
string arg;
string rmt;
bool remote;
bool state_hook = false;
for (unsigned int i = 0 ; i < hook_mads.size() ; i++ )
{
vattr = static_cast<const VectorAttribute *>(hook_mads[i]);
name = vattr->vector_value("NAME");
on = vattr->vector_value("ON");
cmd = vattr->vector_value("COMMAND");
arg = vattr->vector_value("ARGUMENTS");
rmt = vattr->vector_value("REMOTE");
transform (on.begin(),on.end(),on.begin(),(int(*)(int))toupper);
if ( on.empty() || cmd.empty() )
{
ostringstream oss;
oss << "Empty ON or COMMAND attribute in HOST_HOOK. Hook "
<< "not registered!";
NebulaLog::log("VM",Log::WARNING,oss);
continue;
}
if ( name.empty() )
{
name = cmd;
}
remote = false;
if ( !rmt.empty() )
{
transform(rmt.begin(),rmt.end(),rmt.begin(),(int(*)(int))toupper);
if ( rmt == "YES" )
{
remote = true;
}
}
if (cmd[0] != '/')
{
cmd = hook_location + cmd;
}
if ( on == "CREATE" )
{
HostAllocateHook * hook;
hook = new HostAllocateHook(name,cmd,arg,remote);
add_hook(hook);
}
else if ( on == "DISABLE" )
{
HostStateHook * hook;
hook = new HostStateHook(name, cmd, arg, remote, Host::DISABLED);
add_hook(hook);
state_hook = true;
}
else if ( on == "ERROR" )
{
HostStateHook * hook;
hook = new HostStateHook(name, cmd, arg, remote, Host::ERROR);
add_hook(hook);
state_hook = true;
}
}
if ( state_hook )
{
HostUpdateStateHook * hook;
hook = new HostUpdateStateHook();
add_hook(hook);
}
}
/* -------------------------------------------------------------------------- */

View File

@ -26,6 +26,7 @@ source_files=[
'HostShare.cc',
'HostPool.cc',
'ClusterPool.cc',
'HostHook.cc'
]
# Build library

View File

@ -0,0 +1,196 @@
/* -------------------------------------------------------------------------- */
/* 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 "OneUnitTest.h"
#include "Nebula.h"
#include "NebulaTestHost.h"
#include <string>
#include <iostream>
#include <stdlib.h>
using namespace std;
class HostHookTest : public OneUnitTest
{
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;
NebulaTestHost * tester;
int oid;
int rc;
public:
void setUp()
{
// Create var dir.
string command = "mkdir -p var";
std::system(command.c_str());
create_db();
tester = new NebulaTestHost();
Nebula& neb = Nebula::instance();
neb.start();
hpool = neb.get_hpool();
hm = static_cast<HookManager*>(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();
delete_db();
delete tester;
// Clean up 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 );
}
/* -------------------------------------------------------------------------- */
};
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, HostHookTest::suite(),"host_hook.xml");
}

View File

@ -164,7 +164,9 @@ protected:
PoolSQL* create_pool(SqlDB* db)
{
return new HostPool(db);
vector<const Attribute *> hook;
return new HostPool(db,hook,"./");
};
int allocate(int index)
@ -597,5 +599,5 @@ public:
int main(int argc, char ** argv)
{
return PoolTest::main(argc, argv, HostPoolTest::suite());
return PoolTest::main(argc, argv, HostPoolTest::suite(), "host_pool.xml");
}

View File

@ -0,0 +1,110 @@
/* -------------------------------------------------------------------------- */
/* 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_HOST_H_
#define NEBULA_TEST_HOST_H_
#include "NebulaTest.h"
class NebulaTestHost : public NebulaTest
{
public:
NebulaTestHost():NebulaTest()
{
NebulaTest::the_tester = this;
need_vm_pool = true;
need_host_pool = true;
need_user_pool = true;
need_vnet_pool = true;
need_image_pool= true;
need_hm = true;
}
~NebulaTestHost(){};
// -----------------------------------------------------------
// Pools
// -----------------------------------------------------------
HostPool* create_hpool(SqlDB* db, string hook_location)
{
map<string,string> hook_value;
VectorAttribute * hook;
vector<const Attribute *> 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<string,string> 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<string,string> 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);
}
// -----------------------------------------------------------
// Managers
// -----------------------------------------------------------
HookManager* create_hm(VirtualMachinePool * vmpool)
{
map<string,string> mad_value;
VectorAttribute * mad;
vector<const Attribute *> 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_*/

View File

@ -1,96 +1,46 @@
# --------------------------------------------------------------------------
# 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.
# --------------------------------------------------------------------------
# SConstruct for src/host/test
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
# This is the absolute path where the project is located
cwd="../../../"
Import('env')
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# 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/',
])
# 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',
])
main_env.Append(LIBS=[
'nebula_log',
env.Prepend(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_core',
'nebula_lcm',
'nebula_dm',
'nebula_sql',
'cppunit',
'dl',
'pthread',
'nebula_log',
'crypto'
])
# MYSQL
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# 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', ])
# MySQL
mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=[ 'mysqlclient', ])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# Linking flags
main_env.Append(LDFLAGS=["-g "])
main_env.Program('test','HostPoolTest.cc')
env.Program('test','HostPoolTest.cc')
env.Program('test_hook','HostHookTest.cc')

View File

@ -26,8 +26,6 @@ source_files=[
'InformationManagerDriver.cc'
]
test_names=[]
# Build library
env.StaticLibrary(lib_name, source_files)

View File

@ -32,6 +32,7 @@ $: << RUBY_LIB_LOCATION
require 'OpenNebulaDriver'
require 'CommandManager'
require 'getoptlong'
#-------------------------------------------------------------------------------
# The SSH Information Manager Driver
@ -41,13 +42,14 @@ class InformationManager < OpenNebulaDriver
#---------------------------------------------------------------------------
# Init the driver
#---------------------------------------------------------------------------
def initialize(hypervisor, num)
super(num, true)
def initialize(hypervisor, threads, retries)
super(threads, true)
@config = read_configuration
@hypervisor = hypervisor
@remote_dir = @config['SCRIPTS_REMOTE_DIR']
@retries = retries
# register actions
register_action(:MONITOR, method("action_monitor"))
@ -70,9 +72,13 @@ class InformationManager < OpenNebulaDriver
LocalCommand.run(sync_cmd, log_lambda)
end
cmd_string = "#{@remote_dir}/im/run_probes #{@hypervisor} #{host}"
cmd = RemotesCommand.run(cmd_string, host, @remote_dir, log_lambda)
cmd_string = "#{@remote_dir}/im/run_probes #{@hypervisor} #{host}"
cmd = RemotesCommand.run(cmd_string,
host,
@remote_dir,
log_lambda,
@retries)
if cmd.code == 0
send_message("MONITOR", RESULT[:success], number, cmd.stdout)
else
@ -89,6 +95,33 @@ end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
hypervisor = ARGV[0]||''
im = InformationManager.new(hypervisor, 15)
opts = GetoptLong.new(
[ '--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ]
)
hypervisor = ''
retries = 0
threads = 15
begin
opts.each do |opt, arg|
case opt
when '--retries'
retries = arg.to_i
when '--threads'
threads = arg.to_i
end
end
rescue Exception => e
exit(-1)
end
if ARGV.length >= 1
hypervisor = ARGV.shift
end
puts retries, threads, hypervisor
im = InformationManager.new(hypervisor, threads, retries)
im.start_driver

View File

@ -14,49 +14,9 @@
# limitations under the License.
# --------------------------------------------------------------------------
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
Import('env')
# This is the absolute path where the project is located
cwd="../../../"
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# 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/',
])
# 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/vm',
cwd + '/src/hm',
cwd + '/src/mad',
cwd + '/src/vnm',
cwd + '/src/um',
cwd + '/src/authm',
cwd + '/src/image',
'/usr/include/openssl/',
])
main_env.Append(LIBS=[
env.Prepend(LIBS=[
'nebula_image',
'nebula_um',
'nebula_vm',
@ -67,42 +27,11 @@ main_env.Append(LIBS=[
'nebula_pool',
'nebula_mad',
'nebula_common',
'nebula_log',
'nebula_core',
'nebula_sql',
'cppunit',
'dl',
'pthread',
'crypto',
'nebula_log',
'crypto'
])
# MYSQL
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# 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', ])
# MySQL
mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=[ 'mysqlclient', ])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# Linking flags
main_env.Append(LDFLAGS=["-g "])
main_env.Program('test','ImagePoolTest.cc')
env.Program('test','ImagePoolTest.cc')

View File

@ -33,8 +33,8 @@ void LifeCycleManager::deploy_action(int vid)
{
Nebula& nd = Nebula::instance();
TransferManager * tm = nd.get_tm();
time_t thetime = time(0);
int cpu,mem,disk;
time_t thetime = time(0);
int cpu,mem,disk;
VirtualMachine::LcmState vm_state;
TransferManager::Actions tm_action;
@ -48,11 +48,11 @@ void LifeCycleManager::deploy_action(int vid)
if (vm->hasPreviousHistory())
{
if (vm->get_previous_reason() == History::STOP_RESUME)
{
vm_state = VirtualMachine::PROLOG_RESUME;
tm_action = TransferManager::PROLOG_RESUME;
}
if (vm->get_previous_reason() == History::STOP_RESUME)
{
vm_state = VirtualMachine::PROLOG_RESUME;
tm_action = TransferManager::PROLOG_RESUME;
}
}
vm->set_state(vm_state);
@ -192,7 +192,7 @@ void LifeCycleManager::migrate_action(int vid)
{
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
int cpu,mem,disk;
int cpu,mem,disk;
//----------------------------------------------------
// SAVE_MIGRATE STATE
@ -246,7 +246,7 @@ void LifeCycleManager::live_migrate_action(int vid)
{
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
int cpu,mem,disk;
int cpu,mem,disk;
//----------------------------------------------------
// MIGRATE STATE
@ -343,8 +343,8 @@ void LifeCycleManager::restore_action(int vid)
{
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
int cpu,mem,disk;
time_t the_time = time(0);
int cpu,mem,disk;
time_t the_time = time(0);
vm->log("LCM", Log::INFO, "Restoring VM");
@ -487,6 +487,8 @@ void LifeCycleManager::delete_action(int vid)
{
VirtualMachine * vm;
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
vm = vmpool->get(vid,true);
@ -498,25 +500,72 @@ void LifeCycleManager::delete_action(int vid)
VirtualMachine::LcmState state = vm->get_lcm_state();
if ((state == VirtualMachine::LCM_INIT) ||
(state == VirtualMachine::DELETE) ||
(state == VirtualMachine::CLEANUP) ||
(state == VirtualMachine::FAILURE))
{
vm->unlock();
return;
}
int cpu;
int mem;
int disk;
clean_up_vm(vm);
dm->trigger(DispatchManager::DONE,vid);
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::clean_action(int vid)
{
VirtualMachine * vm;
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return;
}
VirtualMachine::LcmState state = vm->get_lcm_state();
if ((state == VirtualMachine::LCM_INIT) ||
(state == VirtualMachine::CLEANUP) ||
(state == VirtualMachine::FAILURE))
{
vm->unlock();
return;
}
clean_up_vm(vm);
dm->trigger(DispatchManager::RESUBMIT,vid);
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
{
int cpu, mem, disk;
time_t the_time = time(0);
Nebula& nd = Nebula::instance();
TransferManager * tm = nd.get_tm();
DispatchManager * dm = nd.get_dm();
VirtualMachineManager * vmm = nd.get_vmm();
vm->set_state(VirtualMachine::DELETE);
VirtualMachine::LcmState state = vm->get_lcm_state();
int vid = vm->get_oid();
vm->set_state(VirtualMachine::CLEANUP);
vmpool->update(vm);
vm->set_etime(the_time);
@ -535,6 +584,7 @@ void LifeCycleManager::delete_action(int vid)
tm->trigger(TransferManager::DRIVER_CANCEL,vid);
tm->trigger(TransferManager::EPILOG_DELETE,vid);
break;
case VirtualMachine::BOOT:
case VirtualMachine::RUNNING:
case VirtualMachine::UNKNOWN:
@ -567,6 +617,7 @@ void LifeCycleManager::delete_action(int vid)
tm->trigger(TransferManager::EPILOG_DELETE,vid);
break;
case VirtualMachine::SAVE_STOP:
case VirtualMachine::SAVE_SUSPEND:
vm->set_running_etime(the_time);
@ -577,6 +628,7 @@ void LifeCycleManager::delete_action(int vid)
tm->trigger(TransferManager::EPILOG_DELETE,vid);
break;
case VirtualMachine::SAVE_MIGRATE:
vm->set_running_etime(the_time);
vmpool->update_history(vm);
@ -593,6 +645,7 @@ void LifeCycleManager::delete_action(int vid)
tm->trigger(TransferManager::EPILOG_DELETE_PREVIOUS,vid);
break;
case VirtualMachine::PROLOG_MIGRATE:
vm->set_prolog_etime(the_time);
vmpool->update_history(vm);
@ -601,6 +654,7 @@ void LifeCycleManager::delete_action(int vid)
tm->trigger(TransferManager::EPILOG_DELETE,vid);
tm->trigger(TransferManager::EPILOG_DELETE_PREVIOUS,vid);
break;
case VirtualMachine::EPILOG_STOP:
case VirtualMachine::EPILOG:
vm->set_epilog_etime(the_time);
@ -609,14 +663,10 @@ void LifeCycleManager::delete_action(int vid)
tm->trigger(TransferManager::DRIVER_CANCEL,vid);
tm->trigger(TransferManager::EPILOG_DELETE,vid);
break;
default: //FAILURE,LCM_INIT,DELETE
default: //FAILURE,LCM_INIT,CLEANUP
break;
}
dm->trigger(DispatchManager::DONE,vid);
vm->unlock();
return;
}

View File

@ -36,8 +36,8 @@ extern "C" void * lcm_action_loop(void *arg)
lcm->am.loop(0,0);
NebulaLog::log("LCM",Log::INFO,"Life-cycle Manager stopped.");
return 0;
return 0;
}
/* -------------------------------------------------------------------------- */
@ -51,7 +51,7 @@ int LifeCycleManager::start()
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
NebulaLog::log("LCM",Log::INFO,"Starting Life-cycle Manager...");
rc = pthread_create(&lcm_thread,&pattr,lcm_action_loop,(void *) this);
return rc;
@ -88,7 +88,7 @@ void LifeCycleManager::trigger(Actions action, int _vid)
case SHUTDOWN_SUCCESS:
aname = "SHUTDOWN_SUCCESS";
break;
case SHUTDOWN_FAILURE:
aname = "SHUTDOWN_FAILURE";
break;
@ -96,7 +96,7 @@ void LifeCycleManager::trigger(Actions action, int _vid)
case CANCEL_SUCCESS:
aname = "CANCEL_SUCCESS";
break;
case CANCEL_FAILURE:
aname = "CANCEL_FAILURE";
break;
@ -104,7 +104,7 @@ void LifeCycleManager::trigger(Actions action, int _vid)
case MONITOR_FAILURE:
aname = "MONITOR_FAILURE";
break;
case MONITOR_SUSPEND:
aname = "MONITOR_SUSPEND";
break;
@ -132,7 +132,7 @@ void LifeCycleManager::trigger(Actions action, int _vid)
case DEPLOY:
aname = "DEPLOY";
break;
case SUSPEND:
aname = "SUSPEND";
break;
@ -160,7 +160,7 @@ void LifeCycleManager::trigger(Actions action, int _vid)
case SHUTDOWN:
aname = "SHUTDOWN";
break;
case RESTART:
aname = "RESTART";
break;
@ -169,10 +169,14 @@ void LifeCycleManager::trigger(Actions action, int _vid)
aname = "DELETE";
break;
case CLEAN:
aname = "CLEAN";
break;
case FINALIZE:
aname = ACTION_FINALIZE;
break;
default:
delete vid;
return;
@ -188,7 +192,7 @@ void LifeCycleManager::do_action(const string &action, void * arg)
{
int vid;
ostringstream oss;
if (arg == 0)
{
return;
@ -197,7 +201,7 @@ void LifeCycleManager::do_action(const string &action, void * arg)
vid = *(static_cast<int *>(arg));
delete static_cast<int *>(arg);
if (action == "SAVE_SUCCESS")
{
save_success_action(vid);
@ -232,16 +236,16 @@ void LifeCycleManager::do_action(const string &action, void * arg)
}
else if (action == "MONITOR_FAILURE")
{
monitor_failure_action(vid);
monitor_failure_action(vid);
}
else if (action == "MONITOR_SUSPEND")
{
monitor_suspend_action(vid);
monitor_suspend_action(vid);
}
else if (action == "MONITOR_DONE")
{
monitor_done_action(vid);
}
monitor_done_action(vid);
}
else if (action == "PROLOG_SUCCESS")
{
prolog_success_action(vid);
@ -256,7 +260,7 @@ void LifeCycleManager::do_action(const string &action, void * arg)
}
else if (action == "EPILOG_FAILURE")
{
epilog_failure_action(vid);
epilog_failure_action(vid);
}
else if (action == "DEPLOY")
{
@ -298,6 +302,10 @@ void LifeCycleManager::do_action(const string &action, void * arg)
{
delete_action(vid);
}
else if (action == "CLEAN")
{
clean_action(vid);
}
else if (action == ACTION_FINALIZE)
{
NebulaLog::log("LCM",Log::INFO,"Stopping Life-cycle Manager...");
@ -306,11 +314,10 @@ void LifeCycleManager::do_action(const string &action, void * arg)
{
ostringstream oss;
oss << "Unknown action name: " << action;
NebulaLog::log("LCM", Log::ERROR, oss);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -36,7 +36,7 @@ void LifeCycleManager::save_success_action(int vid)
{
Nebula& nd = Nebula::instance();
TransferManager * tm = nd.get_tm();
int cpu,mem,disk;
int cpu,mem,disk;
time_t the_time = time(0);
//----------------------------------------------------
@ -69,11 +69,11 @@ void LifeCycleManager::save_success_action(int vid)
tm->trigger(TransferManager::PROLOG_MIGR,vid);
}
else if ( vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND)
else if (vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND)
{
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
int cpu,mem,disk;
int cpu,mem,disk;
time_t the_time = time(0);
//----------------------------------------------------
@ -100,7 +100,7 @@ void LifeCycleManager::save_success_action(int vid)
{
Nebula& nd = Nebula::instance();
TransferManager * tm = nd.get_tm();
time_t the_time = time(0);
time_t the_time = time(0);
//----------------------------------------------------
// EPILOG_STOP STATE
@ -148,11 +148,11 @@ void LifeCycleManager::save_failure_action(int vid)
if ( vm->get_lcm_state() == VirtualMachine::SAVE_MIGRATE )
{
int cpu,mem,disk;
time_t the_time = time(0);
int cpu,mem,disk;
time_t the_time = time(0);
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
//----------------------------------------------------
// RUNNING STATE FROM SAVE_MIGRATE
@ -191,17 +191,17 @@ void LifeCycleManager::save_failure_action(int vid)
vmpool->update_history(vm);
vm->log("LCM", Log::INFO, "Fail to save VM state while migrating."
" Assuming that the VM is still RUNNING (will poll VM).");
" Assuming that the VM is still RUNNING (will poll VM).");
//----------------------------------------------------
vmm->trigger(VirtualMachineManager::POLL,vid);
}
else if ( vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND ||
vm->get_lcm_state() == VirtualMachine::SAVE_STOP )
vm->get_lcm_state() == VirtualMachine::SAVE_STOP )
{
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
//----------------------------------------------------
// RUNNING STATE FROM SAVE_SUSPEND OR SAVE_STOP
@ -212,7 +212,7 @@ void LifeCycleManager::save_failure_action(int vid)
vmpool->update(vm);
vm->log("LCM", Log::INFO, "Fail to save VM state."
" Assuming that the VM is still RUNNING (will poll VM).");
" Assuming that the VM is still RUNNING (will poll VM).");
//----------------------------------------------------
@ -242,8 +242,8 @@ void LifeCycleManager::deploy_success_action(int vid)
if ( vm->get_lcm_state() == VirtualMachine::MIGRATE )
{
int cpu,mem,disk;
time_t the_time = time(0);
int cpu,mem,disk;
time_t the_time = time(0);
vm->set_running_stime(the_time);
@ -288,10 +288,10 @@ void LifeCycleManager::deploy_failure_action(int vid)
if ( vm->get_lcm_state() == VirtualMachine::MIGRATE )
{
int cpu,mem,disk;
time_t the_time = time(0);
int cpu,mem,disk;
time_t the_time = time(0);
Nebula& nd = Nebula::instance();
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
//----------------------------------------------------
@ -339,7 +339,7 @@ void LifeCycleManager::deploy_failure_action(int vid)
}
else if (vm->get_lcm_state() == VirtualMachine::BOOT)
{
time_t the_time = time(0);
time_t the_time = time(0);
vm->set_running_etime(the_time);
@ -394,10 +394,10 @@ void LifeCycleManager::shutdown_success_action(int vid)
void LifeCycleManager::shutdown_failure_action(int vid)
{
VirtualMachine * vm;
VirtualMachine * vm;
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
vm = vmpool->get(vid,true);
@ -415,7 +415,7 @@ void LifeCycleManager::shutdown_failure_action(int vid)
vmpool->update(vm);
vm->log("LCM", Log::INFO, "Fail to shutdown VM."
" Assuming that the VM is still RUNNING (will poll VM).");
" Assuming that the VM is still RUNNING (will poll VM).");
//----------------------------------------------------
@ -452,7 +452,7 @@ void LifeCycleManager::prolog_success_action(int vid)
action = VirtualMachineManager::DEPLOY;
}
else if ( lcm_state == VirtualMachine::PROLOG_MIGRATE ||
lcm_state == VirtualMachine::PROLOG_RESUME )
lcm_state == VirtualMachine::PROLOG_RESUME )
{
action = VirtualMachineManager::RESTORE;
}
@ -495,7 +495,7 @@ void LifeCycleManager::prolog_success_action(int vid)
void LifeCycleManager::prolog_failure_action(int vid)
{
VirtualMachine * vm;
time_t the_time = time(0);
time_t the_time = time(0);
vm = vmpool->get(vid,true);
@ -523,7 +523,7 @@ void LifeCycleManager::epilog_success_action(int vid)
VirtualMachine * vm;
time_t the_time = time(0);
int cpu,mem,disk;
int cpu,mem,disk;
DispatchManager::Actions action;
@ -534,11 +534,11 @@ void LifeCycleManager::epilog_success_action(int vid)
return;
}
if ( vm->get_lcm_state() == VirtualMachine::EPILOG_STOP )
if (vm->get_lcm_state() == VirtualMachine::EPILOG_STOP)
{
action = DispatchManager::STOP_SUCCESS;
}
else if ( vm->get_lcm_state() == VirtualMachine::EPILOG)
else if (vm->get_lcm_state() == VirtualMachine::EPILOG)
{
action = DispatchManager::DONE;
}
@ -599,8 +599,8 @@ void LifeCycleManager::epilog_failure_action(int vid)
void LifeCycleManager::cancel_success_action(int vid)
{
VirtualMachine * vm;
time_t the_time = time(0);
int cpu,mem,disk;
time_t the_time = time(0);
int cpu,mem,disk;
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
@ -637,8 +637,8 @@ void LifeCycleManager::cancel_failure_action(int vid)
{
VirtualMachine * vm;
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
vm = vmpool->get(vid,true);
@ -656,7 +656,7 @@ void LifeCycleManager::cancel_failure_action(int vid)
vmpool->update(vm);
vm->log("LCM", Log::INFO, "Fail to cancel VM."
" Assuming that the VM is still RUNNING (will poll VM).");
" Assuming that the VM is still RUNNING (will poll VM).");
//----------------------------------------------------
@ -672,7 +672,7 @@ void LifeCycleManager::monitor_failure_action(int vid)
{
VirtualMachine * vm;
time_t the_time = time(0);
time_t the_time = time(0);
vm = vmpool->get(vid,true);
@ -695,10 +695,10 @@ void LifeCycleManager::monitor_suspend_action(int vid)
{
VirtualMachine * vm;
int cpu,mem,disk;
time_t the_time = time(0);
int cpu,mem,disk;
time_t the_time = time(0);
Nebula& nd = Nebula::instance();
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
vm = vmpool->get(vid,true);
@ -708,6 +708,14 @@ void LifeCycleManager::monitor_suspend_action(int vid)
return;
}
//----------------------------------------------------
// SAVE_SUSPEND STATE
//----------------------------------------------------
vm->set_state(VirtualMachine::SAVE_SUSPEND);
vmpool->update(vm);
vm->set_running_etime(the_time);
vm->set_etime(the_time);
@ -726,7 +734,6 @@ void LifeCycleManager::monitor_suspend_action(int vid)
dm->trigger(DispatchManager::SUSPEND_SUCCESS,vid);
vm->unlock();
}
@ -745,7 +752,7 @@ void LifeCycleManager::monitor_done_action(int vid)
}
//----------------------------------------------------
// EPILOG STATE
// UNKNWON STATE
//----------------------------------------------------
vm->set_state(VirtualMachine::UNKNOWN);
@ -765,12 +772,12 @@ void LifeCycleManager::monitor_done_action(int vid)
void LifeCycleManager::failure_action(VirtualMachine * vm)
{
Nebula& nd = Nebula::instance();
TransferManager * tm = nd.get_tm();
Nebula& nd = Nebula::instance();
TransferManager * tm = nd.get_tm();
DispatchManager * dm = nd.get_dm();
time_t the_time = time(0);
int cpu,mem,disk;
time_t the_time = time(0);
int cpu,mem,disk;
//----------------------------------------------------
// LCM FAILURE STATE
@ -799,4 +806,3 @@ void LifeCycleManager::failure_action(VirtualMachine * vm)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

111
src/lcm/test/DummyManager.h Normal file
View File

@ -0,0 +1,111 @@
/* -------------------------------------------------------------------------- */
/* 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 DUMMY_MANAGER_TEST_H
#define DUMMY_MANAGER_TEST_H
#include "TransferManager.h"
#include "VirtualMachineManager.h"
#include "LifeCycleManager.h"
#include "Nebula.h"
/**
* The Dummy Manager will ignore any trigger calls but FINALIZE, unless the lcm
* actions are set.
*/
class DummyManager
{
protected:
DummyManager():index(0){}
virtual ~DummyManager(){}
vector<LifeCycleManager::Actions> actions;
int index;
public:
void clear_actions()
{
index = 0;
actions.clear();
}
void set_actions(vector<LifeCycleManager::Actions>& _actions)
{
index = 0;
actions = _actions;
}
void trigger_lcm_action(int _vid)
{
if(index < (int) actions.size())
{
(Nebula::instance().get_lcm())->trigger(actions[index], _vid);
index++;
}
}
};
class TransferManagerTest:public TransferManager, public DummyManager
{
public:
TransferManagerTest(
VirtualMachinePool * _vmpool,
HostPool * _hpool,
vector<const Attribute*>& _mads):
TransferManager(_vmpool, _hpool, _mads){}
void trigger(Actions action, int _vid)
{
if( action == FINALIZE )
{
TransferManager::trigger(action, _vid);
}
else
{
trigger_lcm_action(_vid);
}
}
};
class VirtualMachineManagerTest:public VirtualMachineManager, public DummyManager
{
public:
VirtualMachineManagerTest(
VirtualMachinePool * _vmpool,
HostPool * _hpool,
time_t _timer_period,
time_t _poll_period,
vector<const Attribute*>& _mads):
VirtualMachineManager( _vmpool, _hpool, _timer_period,
_poll_period, _mads){}
void trigger(Actions action, int _vid)
{
if( action == FINALIZE )
{
VirtualMachineManager::trigger(action, _vid);
}
else
{
trigger_lcm_action(_vid);
}
}
};
#endif /* DUMMY_MANAGER_TEST_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,67 @@
/* -------------------------------------------------------------------------- */
/* 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_LCM_H_
#define NEBULA_TEST_LCM_H_
#include "NebulaTest.h"
class NebulaTestLCM: public NebulaTest
{
public:
NebulaTestLCM():NebulaTest()
{
NebulaTest::the_tester = this;
need_vm_pool = true;
need_host_pool = true;
need_user_pool = true;
need_vnet_pool = true;
need_image_pool= true;
need_vmm = true;
need_lcm = true;
need_tm = true;
need_dm = true;
}
~NebulaTestLCM(){};
TransferManager* create_tm(VirtualMachinePool* vmpool,
HostPool* hpool)
{
vector<const Attribute *> tm_mads;
return new TransferManagerTest(vmpool, hpool, tm_mads);
}
VirtualMachineManager* create_vmm(VirtualMachinePool* vmpool,
HostPool* hpool,
time_t timer_period,
time_t poll_period)
{
vector<const Attribute *> vmm_mads;
return new VirtualMachineManagerTest(vmpool,
hpool,
timer_period,
poll_period,
vmm_mads);
}
};
#endif /*NEBULA_TEST_LCM_H_*/

45
src/lcm/test/SConstruct Normal file
View File

@ -0,0 +1,45 @@
# SConstruct for src/lcm/test
# -------------------------------------------------------------------------- #
# 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('env')
env.Prepend(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',
'nebula_dm',
'crypto'
])
env.Program('test','LifeCycleManagerTest.cc')

View File

@ -150,7 +150,7 @@ class RemotesCommand < SSHCommand
MAGIC_RC = 42
# Creates a command and runs it
def self.run(command, host, remote_dir, logger=nil, stdin=nil)
def self.run(command, host, remote_dir, logger=nil, stdin=nil, retries=0)
cmd_file = command.split(' ')[0]
cmd_string = "'if [ -x \"#{cmd_file}\" ]; then #{command}; else\
@ -158,13 +158,19 @@ class RemotesCommand < SSHCommand
cmd = self.new(cmd_string, host, logger, stdin)
cmd.run
if cmd.code == MAGIC_RC
cmd.update_remotes(host, remote_dir, logger)
@command = command
cmd.run
end
while cmd.code != 0 or retries != 0
sleep 1
cmd.run
retries = retries - 1
end
cmd
end

View File

@ -65,10 +65,11 @@ class VirtualMachineDriver < OpenNebulaDriver
# -------------------------------------------------------------------------
# Register default actions for the protocol
# -------------------------------------------------------------------------
def initialize(concurrency=10, threaded=true)
def initialize(concurrency=10, threaded=true, retries=0)
super(concurrency,threaded)
@hosts = Array.new
@hosts = Array.new
@retries = retries
register_action(ACTION[:deploy].to_sym, method("deploy"))
register_action(ACTION[:shutdown].to_sym, method("shutdown"))
@ -108,9 +109,13 @@ class VirtualMachineDriver < OpenNebulaDriver
# Execute a command associated to an action and id in a remote host.
# -------------------------------------------------------------------------
def remotes_action(command, id, host, action, remote_dir, std_in=nil)
command_exe = RemotesCommand.run(
command, host, remote_dir, log_method(id), std_in)
command_exe = RemotesCommand.run(command,
host,
remote_dir,
log_method(id),
std_in,
@retries)
if command_exe.code == 0
result = :success
info = command_exe.stdout

View File

@ -249,11 +249,13 @@ void Nebula::start()
string default_device_prefix;
vector<const Attribute *> vm_hooks;
vector<const Attribute *> host_hooks;
nebula_configuration->get("VM_HOOK", vm_hooks);
nebula_configuration->get("HOST_HOOK", host_hooks);
vmpool = new VirtualMachinePool(db, vm_hooks,hook_location);
hpool = new HostPool(db);
vmpool = new VirtualMachinePool(db, vm_hooks, hook_location);
hpool = new HostPool(db, host_hooks, hook_location);
nebula_configuration->get("MAC_PREFIX", mac_prefix);
nebula_configuration->get("NETWORK_SIZE", size);

View File

@ -31,7 +31,7 @@ source_files=[
env.StaticLibrary(lib_name, source_files)
# Build daemon
env.Append(LIBS=[
env.Prepend(LIBS=[
'nebula_core',
'nebula_vmm',
'nebula_lcm',
@ -55,14 +55,6 @@ env.Append(LIBS=[
'crypto'
])
# Sources to generate the library
if env['sqlite']=='yes':
env.Append(LIBS=['sqlite3'])
if env['mysql']=='yes':
env.Append(LIBS=['mysqlclient'])
if not env.GetOption('clean'):
env.ParseConfig(("LDFLAGS='%s' ../../share/scons/get_xmlrpc_config"+
" server") % (os.environ['LDFLAGS'],))

View File

@ -74,7 +74,7 @@ public class VirtualMachine extends PoolElement{
"SHUTDOWN",
"CANCEL",
"FAILURE",
"DELETE",
"CLEANUP",
"UNKNOWN" };
private static final String[] SHORT_LCM_STATES =
@ -220,7 +220,7 @@ public class VirtualMachine extends PoolElement{
/**
* Sets the specified vm's disk to be saved in a new image when the
* VirtualMachine shutdowns.
*
*
* @param diskId ID of the disk to be saved.
* @param imageId ID of the image where the disk will be saved.
* @return If an error occurs the error message contains the reason.
@ -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).
* <br/>

View File

@ -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()
{

View File

@ -34,7 +34,7 @@ module OpenNebula
LCM_STATE=%w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND
SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG
SHUTDOWN CANCEL FAILURE DELETE UNKNOWN}
SHUTDOWN CANCEL FAILURE CLEANUP UNKNOWN}
SHORT_VM_STATES={
"INIT" => "init",
@ -62,7 +62,7 @@ module OpenNebula
"SHUTDOWN" => "shut",
"CANCEL" => "shut",
"FAILURE" => "fail",
"DELETE" => "dele",
"CLEANUP" => "clea",
"UNKNOWN" => "unkn"
}
@ -118,14 +118,14 @@ module OpenNebula
def info()
super(VM_METHODS[:info], 'VM')
end
# Allocates a new VirtualMachine in OpenNebula
#
# +description+ A string containing the template of the VirtualMachine.
def allocate(description)
super(VM_METHODS[:allocate],description)
end
# Initiates the instance of the VM on the target host.
#
# +host_id+ The host id (hid) of the target host where
@ -174,16 +174,21 @@ module OpenNebula
action('resume')
end
# Deletes a VM from the pool and DB
# Deletes a VM from the pool
def finalize
action('finalize')
end
# Resubmits the VM after failure
# Forces a re-deployment of a VM in UNKNOWN or BOOT state
def restart
action('restart')
end
# Resubmits a VM to PENDING state
def resubmit
action('resubmit')
end
# Saves a running VM and starts it again in the specified host
def migrate(host_id)
return Error.new('ID not defined') if !@pe_id
@ -203,8 +208,8 @@ module OpenNebula
return rc
end
# Set the specified vm's disk to be saved in a new image
# Set the specified vm's disk to be saved in a new image
# when the VirtualMachine shutdowns
#
# +disk_id+ ID of the disk to be saved

View File

@ -31,7 +31,7 @@ module OpenNebula
#######################################################################
# +client+ a Client object that represents a XML-RPC connection
# +user_id+ is to refer to a Pool with VirtualNetworks from that user
# +user_id+ is to refer to a Pool with VirtualMachines from that user
def initialize(client, user_id=0)
super('VM_POOL','VM',client)

View File

@ -93,6 +93,23 @@ module OpenNebula
element.text
end
end
def retrieve_elements(filter)
ids_array = Array.new
if NOKOGIRI
elements=@xml.xpath(filter.to_s)
if elements.size == 0
return nil
end
elements.each{ |e| ids_array << e.text }
else
@xml.each(filter.to_s) { |e| ids_array << e.text }
end
return ids_array
end
# Gets an attribute from an elemenT
# key:: _String_ xpath for the element

View File

@ -14,74 +14,21 @@
# limitations under the License.
# --------------------------------------------------------------------------
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
# This is the absolute path where the project is located
cwd="../../../"
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# Add builders for flex and bison
add_lex(main_env)
add_bison(main_env)
# Include dirs
main_env.Append(CPPPATH=[
cwd + '/include',
'/usr/include/cppunit/',
])
Import('env')
# Library dirs
main_env.Append(LIBPATH=[
cwd + '/src/common',
cwd + '/src/log',
cwd + '/src/pool',
cwd + '/src/sql',
cwd + '/src/pool/test',
cwd + '/src/nebula',
env.Append(LIBPATH=[
'.'
])
main_env.Append(LIBS=[
env.Prepend(LIBS=[
'nebula_pool',
'nebula_common',
'nebula_log',
'nebula_core',
'nebula_sql',
'cppunit',
'dl',
'pthread',
'test_object'
])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# MYSQL
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
sqlite=ARGUMENTS.get('sqlite', 'yes')
if sqlite=='yes':
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])
main_env.Append(LIBS=[ 'sqlite3', ])
# MySQL
mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=[ 'mysqlclient', ])
main_env.StaticLibrary('test_object', ['TestPoolSQL.cc', 'TestPoolSQL.h'])
main_env.Program('test','pool.cc')
env.StaticLibrary('test_object', ['TestPoolSQL.cc', 'TestPoolSQL.h'])
env.Program('test','pool.cc')

View File

@ -35,7 +35,7 @@ const char * TestObjectSQL::table = "test_pool";
const char * TestObjectSQL::db_names = "(oid,number,text)";
const char * TestObjectSQL::db_bootstrap = "CREATE TABLE test_pool ("
"oid INTEGER, number INTEGER, text TEXT, PRIMARY KEY(oid))";
"oid INTEGER, number INTEGER, text TEXT, PRIMARY KEY(oid))";
/* -------------------------------------------------------------------------- */

View File

@ -21,7 +21,7 @@
#include "PoolSQL.h"
using namespace std;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -31,7 +31,7 @@ class TestObjectSQL : public PoolObjectSQL
public:
//OBJECT ATTRIBUTES
TestObjectSQL(int n=-1, string t="default"):number(n),text(t){};
~TestObjectSQL(){};
int number;
@ -40,7 +40,7 @@ public:
// OBJECTSQL INTERFACE
int unmarshall(void * nil, int num, char **names, char ** values);
int select(SqlDB *db);
int insert(SqlDB *db, string& err);

View File

@ -18,29 +18,16 @@
#include <iostream>
#include <getopt.h>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <unistd.h>
#include "test/OneUnitTest.h"
#include "PoolSQL.h"
#include "TestPoolSQL.h"
#include "SqliteDB.h"
#include "MySqlDB.h"
#include "SqlDB.h"
#include "test/one_test_common.h"
using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
bool mysql;
class PoolTest : public CppUnit::TestFixture
class PoolTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (PoolTest);
CPPUNIT_TEST (allocate_get);
@ -51,7 +38,6 @@ class PoolTest : public CppUnit::TestFixture
private:
TestPool * pool;
SqlDB * db;
int create_allocate(int n, string st)
{
@ -68,30 +54,7 @@ public:
void setUp()
{
string db_name = "testdb";
if (mysql)
{
db = new MySqlDB("localhost",0,"oneadmin","oneadmin",NULL);
ostringstream oss1;
oss1 << "DROP DATABASE IF EXISTS " << db_name;
db->exec(oss1);
ostringstream oss;
oss << "CREATE DATABASE " << db_name;
db->exec(oss);
ostringstream oss2;
oss2 << "use " << db_name;
db->exec(oss2);
}
else
{
unlink(db_name.c_str());
db = new SqliteDB(db_name);
}
create_db();
TestObjectSQL::bootstrap(db);
@ -100,7 +63,7 @@ public:
void tearDown()
{
delete db;
delete_db();
delete pool;
};
@ -202,13 +165,13 @@ public:
TestObjectSQL *obj;
TestObjectSQL *obj_lock;
//pin object in the cache, it can't be removed -
//pin object in the cache, it can't be removed -
//Should be set to MAX_POOL -1
for (int i=0 ; i < 14999 ; i++)
for (int i=0 ; i < 14999 ; i++)
{
create_allocate(i,"A Test object");
obj_lock = pool->get(i, true);
obj_lock = pool->get(i, true);
CPPUNIT_ASSERT(obj_lock != 0);
}
@ -227,10 +190,10 @@ public:
obj->unlock();
}
for (int i=0 ; i < 14999 ; i++)
for (int i=0 ; i < 14999 ; i++)
{
obj_lock = pool->get(i, false);
obj_lock->unlock();
obj_lock = pool->get(i, false);
obj_lock->unlock();
}
};
};
@ -241,65 +204,5 @@ public:
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner runner;
// 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':
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";
return 0;
}
NebulaLog::init_log_system(NebulaLog::FILE, Log::ERROR, "test.log");
if (sqlite_flag)
{
mysql = false;
NebulaLog::log("Test", Log::INFO, "Running Sqlite tests...");
cout << "\nRunning Sqlite tests...\n";
}
else
{
mysql = true;
NebulaLog::log("Test", Log::INFO, "Running MySQL tests...");
cout << "\nRunning MySQL tests...\n";
}
SETUP_XML_WRITER(runner, "pool.xml")
runner.addTest( PoolTest::suite() );
runner.run();
if (!log_flag)
remove("test.log");
END_XML_WRITER
NebulaLog::finalize_log_system();
return 0;
}
return OneUnitTest::main(argc, argv, PoolTest::suite());
}

View File

@ -120,6 +120,10 @@ void RequestManager::VirtualMachineAction::execute(
{
rc = dm->finalize(vid);
}
else if (action == "resubmit")
{
rc = dm->resubmit(vid);
}
else
{
rc = -3;

View File

@ -14,49 +14,25 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
Import('env')
import os
import sys
import shutil
sys.path.append("../../share/scons")
from lex_bison import *
# This is the absolute path where the project is located
cwd=os.getcwd()
# Environment that will be applied to each scons child set in the main SConstruct
Import('env')
main_env=env
# Add builders for flex and bison
add_lex(main_env)
add_bison(main_env)
# Include dirs
main_env.Replace(CPPPATH=[
env.Append(CPPPATH=[
cwd + '/include/',
cwd + '../../../include/'
])
# Library dirs
main_env.Replace(LIBPATH=[
env.Append(LIBPATH=[
cwd+'/src/xml',
cwd+'/src/pool',
cwd+'/src/sched',
cwd+'/../log',
cwd+'/../common',
cwd+'/src/sched'
])
################################################################################
# EXTRA CONFIGURATION
################################################################################
#-------------------------------------------------------------------------------
# libxml2
#-------------------------------------------------------------------------------
main_env.ParseConfig('xml2-config --libs --cflags')
################################################################################
# SCONS scripts to build
################################################################################
@ -67,6 +43,12 @@ build_scripts=[
'src/sched/SConstruct'
]
if env['testing']=='yes':
build_scripts.extend([
'src/pool/test/SConstruct',
'src/xml/test/SConstruct',
])
for script in build_scripts:
env=main_env.Clone()
SConscript(script, exports='env')
sched_env=env.Clone()
SConscript(script, exports='sched_env')

View File

@ -16,7 +16,7 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
Import('env')
Import('sched_env')
lib_name='scheduler_pool'
@ -27,4 +27,4 @@ source_files=[
'VirtualMachineXML.cc']
# Build library
env.StaticLibrary(lib_name, source_files)
sched_env.StaticLibrary(lib_name, source_files)

View File

@ -19,19 +19,10 @@
#include <stdlib.h>
#include <stdexcept>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <unistd.h>
#include "ObjectXML.h"
#include "HostPoolXML.h"
#include "test/one_test_common.h"
#include "test/OneUnitTest.h"
/* ************************************************************************* */
/* ************************************************************************* */
@ -86,7 +77,7 @@ protected:
/* ************************************************************************* */
/* ************************************************************************* */
class HostXMLTest : public CppUnit::TestFixture
class HostXMLTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE( HostXMLTest );
@ -259,25 +250,8 @@ public:
int main(int argc, char ** argv)
{
// We need to set the log file
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, "HostXMLTest.xml")
runner.addTest(HostXMLTest::suite());
runner.run();
END_XML_WRITER
// remove("test.log");
NebulaLog::finalize_log_system();
return 0;
return OneUnitTest::main(argc, argv, HostXMLTest::suite(),
"HostXMLTest.xml");
}
// ----------------------------------------------------------------------------

View File

@ -14,85 +14,16 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
import os
import sys
import shutil
sys.path.append("../../../../../share/scons")
# This is the absolute path where the project is located
cwd=os.getcwd()
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# Include dirs
main_env.Append(CPPPATH=[
cwd+'/../../../include',
cwd+'/../../../../../include',
'/usr/include/cppunit/'
])
# Library dirs
main_env.Append(LIBPATH=[
cwd+'/..',
cwd+'/../../xml',
cwd+'/../../../../log',
cwd+'/../../../../common'
])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# Linking flags
main_env.Append(LDFLAGS=["-g"])
Import('sched_env')
# Libraries
main_env.Append(LIBS=[
'cppunit',
sched_env.Prepend(LIBS=[
'scheduler_xml',
'scheduler_pool',
'nebula_log',
'nebula_common'
'nebula_common',
'nebula_test_common',
])
main_env.Program('test_vm','VirtualMachineXMLTest.cc')
main_env.Program('test_host','HostXMLTest.cc')
################################################################################
# EXTRA CONFIGURATION
################################################################################
#-------------------------------------------------------------------------------
# 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"])
main_env.ParseConfig(("LDFLAGS='%s' ../../../../../share/scons/"+
"get_xmlrpc_config client") % (os.environ['LDFLAGS'],))
#-------------------------------------------------------------------------------
# build lex/bison
#-------------------------------------------------------------------------------
build_parsers=ARGUMENTS.get('parsers', 'no')
if build_parsers=='yes':
main_env.Append(parsers='yes')
else:
main_env.Append(parsers='no')
#-------------------------------------------------------------------------------
# libxml2
#-------------------------------------------------------------------------------
main_env.ParseConfig('xml2-config --libs --cflags')
sched_env.Program('test_vm','VirtualMachineXMLTest.cc')
sched_env.Program('test_host','HostXMLTest.cc')

View File

@ -19,20 +19,11 @@
#include <stdlib.h>
#include <stdexcept>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <unistd.h>
#include "ObjectXML.h"
#include "VirtualMachinePoolXML.h"
#include "HostPoolXML.h"
#include "test/one_test_common.h"
#include "test/OneUnitTest.h"
/* ************************************************************************* */
/* ************************************************************************* */
@ -142,7 +133,7 @@ protected:
/* ************************************************************************* */
/* ************************************************************************* */
class VirtualMachineXMLTest : public CppUnit::TestFixture
class VirtualMachineXMLTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE( VirtualMachineXMLTest );
@ -313,23 +304,8 @@ public:
int main(int argc, char ** argv)
{
// We need to set the log file
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, "VirtualMachineXMLTest.xml")
runner.addTest(VirtualMachineXMLTest::suite());
runner.run();
END_XML_WRITER
remove("test.log");
NebulaLog::finalize_log_system();
return 0;
return OneUnitTest::main(argc, argv, VirtualMachineXMLTest::suite(),
"VirtualMachineXMLTest.xml");
}
// ----------------------------------------------------------------------------

View File

@ -16,30 +16,26 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
import os
Import('env')
Import('sched_env')
lib_name='scheduler_sched'
source_files=['Scheduler.cc']
# Build library
env.StaticLibrary(lib_name, source_files)
sched_env.StaticLibrary(lib_name, source_files)
# Build daemon
env.Append(LIBS=[
sched_env.Prepend(LIBS=[
'scheduler_sched',
'scheduler_pool',
'nebula_log',
'scheduler_xml',
'nebula_common',
'crypto',
'pthread'
])
if not env.GetOption('clean'):
env.ParseConfig(("LDFLAGS='%s' ../../../../share/scons/get_xmlrpc_config"+
" client") % (os.environ['LDFLAGS'],))
if not sched_env.GetOption('clean'):
sched_env.ParseConfig(("LDFLAGS='%s' ../../../../share/scons/get_xmlrpc_config" + " client") % (os.environ['LDFLAGS'],))
env.Program('mm_sched.cc')
sched_env.Program('mm_sched.cc')

View File

@ -16,27 +16,27 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
Import('env')
Import('sched_env')
lib_name='scheduler_xml'
if env['parsers']=='yes':
if sched_env['parsers']=='yes':
# LEX
parser=env.Lex(
parser=sched_env.Lex(
source='expr_parser.l'
)
env.NoClean(parser)
sched_env.NoClean(parser)
# BISON
parser=env.Bison(
parser=sched_env.Bison(
source='expr_arith.y'
)
env.NoClean(parser)
sched_env.NoClean(parser)
parser=env.Bison(
parser=sched_env.Bison(
source='expr_bool.y'
)
env.NoClean(parser)
sched_env.NoClean(parser)
source_files=['ObjectXML.cc',
'Client.cc',
@ -45,4 +45,4 @@ source_files=['ObjectXML.cc',
'expr_arith.cc']
# Build library
env.StaticLibrary(lib_name, source_files)
sched_env.StaticLibrary(lib_name, source_files)

View File

@ -19,23 +19,13 @@
#include <stdlib.h>
#include <stdexcept>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <unistd.h>
#include "ObjectXML.h"
#include "test/one_test_common.h"
#include "test/OneUnitTest.h"
/* ************************************************************************* */
/* ************************************************************************* */
class ObjectXMLTest : public CppUnit::TestFixture
class ObjectXMLTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE( ObjectXMLTest );
@ -331,16 +321,7 @@ public:
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner runner;
SETUP_XML_WRITER(runner, "ObjectXMLTest.xml");
runner.addTest(ObjectXMLTest::suite());
runner.run();
END_XML_WRITER
return 0;
return OneUnitTest::main(argc, argv, ObjectXMLTest::suite());
}
// ----------------------------------------------------------------------------

View File

@ -14,79 +14,14 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
import os
import sys
import shutil
sys.path.append("../../../../../share/scons")
# This is the absolute path where the project is located
cwd=os.getcwd()
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# Include dirs
main_env.Append(CPPPATH=[
cwd+'/../../../include',
cwd+'/../../../../../include',
'/usr/include/cppunit/'
])
# Library dirs
main_env.Append(LIBPATH=[
cwd+'/../../../../common',
'../'
])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# Linking flags
main_env.Append(LDFLAGS=["-g"])
Import('sched_env')
# Libraries
main_env.Append(LIBS=[
'cppunit',
sched_env.Prepend(LIBS=[
'nebula_log',
'scheduler_xml',
'nebula_common'
'nebula_common',
'nebula_test_common',
])
main_env.Program('test_xml','ObjectXMLTest.cc')
################################################################################
# EXTRA CONFIGURATION
################################################################################
#-------------------------------------------------------------------------------
# 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"])
main_env.ParseConfig(("LDFLAGS='%s' ../../../../../share/scons/"+
"get_xmlrpc_config client") % (os.environ['LDFLAGS'],))
#-------------------------------------------------------------------------------
# build lex/bison
#-------------------------------------------------------------------------------
build_parsers=ARGUMENTS.get('parsers', 'no')
if build_parsers=='yes':
main_env.Append(parsers='yes')
else:
main_env.Append(parsers='no')
#-------------------------------------------------------------------------------
# libxml2
#-------------------------------------------------------------------------------
main_env.ParseConfig('xml2-config --libs --cflags')
sched_env.Program('test_xml','ObjectXMLTest.cc')

View File

@ -27,7 +27,7 @@ MySqlDB::MySqlDB(
int port,
const string& user,
const string& password,
char * database)
const char * database)
{
// Initialize the MySQL library

View File

@ -30,4 +30,4 @@ if env['mysql']=='yes':
source_files.append('MySqlDB.cc')
# Build library
env.StaticLibrary(lib_name, source_files)
env.StaticLibrary(lib_name, source_files)

View File

@ -15,71 +15,13 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
Import('env')
# This is the absolute path where the project is located
cwd="../../../"
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# Add builders for flex and bison
add_lex(main_env)
add_bison(main_env)
# Include dirs
main_env.Append(CPPPATH=[
cwd + '/include',
'/usr/include/cppunit/'
])
# Library dirs
main_env.Append(LIBPATH=[
cwd + '/src/common',
cwd + '/src/template',
cwd + '/src/nebula',
cwd + '/src/log',
])
main_env.Append(LIBS=[
env.Append(LIBS=[
'nebula_template',
'nebula_common',
'nebula_core',
'nebula_log',
'cppunit',
'dl',
'pthread'
'nebula_log'
])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# libxml2
main_env.ParseConfig('xml2-config --libs --cflags')
# MYSQL
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
sqlite=ARGUMENTS.get('sqlite', 'yes')
if sqlite=='yes':
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])
main_env.Append(LIBS=[ 'sqlite3', ])
# MySQL
mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=[ 'mysqlclient', ])
main_env.Program('test','template.cc')
#
env.Program('test','template.cc')

View File

@ -3,13 +3,7 @@
#include <string>
#include <iostream>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
#include "test/one_test_common.h"
#include "test/OneUnitTest.h"
using namespace std;
@ -17,8 +11,22 @@ using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
class TemplateTest : public CppUnit::TestFixture
class TemplateTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (TemplateTest);
CPPUNIT_TEST (test_parser);
CPPUNIT_TEST (test_marshall);
CPPUNIT_TEST (test_xml);
CPPUNIT_TEST (test_str);
CPPUNIT_TEST (test_get);
CPPUNIT_TEST (test_remove);
CPPUNIT_TEST (test_set);
CPPUNIT_TEST (test_erase);
CPPUNIT_TEST (test_from_xml);
CPPUNIT_TEST_SUITE_END ();
private:
Template *t, *tr, *t1;
@ -346,52 +354,6 @@ public:
CPPUNIT_ASSERT(str1 == str2);
}
/* ********************************************************************* */
/* ********************************************************************* */
static CppUnit::TestSuite * suite()
{
CppUnit::TestSuite *ts=new CppUnit::TestSuite("Template Tests");
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"parse() Test",
&TemplateTest::test_parser));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"marshall() Test",
&TemplateTest::test_marshall));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"xml() Test",
&TemplateTest::test_xml));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"str() Test",
&TemplateTest::test_str));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"get() Test",
&TemplateTest::test_get));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"remove() Test",
&TemplateTest::test_remove));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"set() Test",
&TemplateTest::test_set));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"erase() Test",
&TemplateTest::test_erase));
ts->addTest(new CppUnit::TestCaller<TemplateTest>(
"from_xml() Test",
&TemplateTest::test_from_xml));
return ts;
}
};
/* ************************************************************************* */
@ -400,14 +362,5 @@ public:
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner tr;
SETUP_XML_WRITER(tr, "template.xml")
tr.addTest(TemplateTest::suite());
tr.run();
END_XML_WRITER
return 0;
return OneUnitTest::main(argc, argv, TemplateTest::suite());
}

446
src/test/Nebula.cc Normal file
View File

@ -0,0 +1,446 @@
/* -------------------------------------------------------------------------- */
/* 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 "NebulaLog.h"
#include "VirtualMachine.h"
#include "SqliteDB.h"
#include "MySqlDB.h"
#include "OneUnitTest.h"
#include "NebulaTest.h"
#include <stdlib.h>
#include <stdexcept>
#include <libxml/parser.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
using namespace std;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Nebula::start()
{
int rc;
sigset_t mask;
time_t timer_period;
NebulaTest * tester;
tester = NebulaTest::instance();
// Because Nebula is accessed only using ::instance(), it can't be
// deleted. Tests use the start method several times before the
// destructor is invoked, so this clean-up is necessary
if ( vmpool != 0)
{
delete vmpool;
}
if ( vnpool != 0)
{
delete vnpool;
}
if ( hpool != 0)
{
delete hpool;
}
if ( upool != 0)
{
delete upool;
}
if ( ipool != 0)
{
delete ipool;
}
if ( vmm != 0)
{
delete vmm;
}
if ( lcm != 0)
{
delete lcm;
}
if ( im != 0)
{
delete im;
}
if ( tm != 0)
{
delete tm;
}
if ( dm != 0)
{
delete dm;
}
if ( rm != 0)
{
delete rm;
}
if ( hm != 0)
{
delete hm;
}
if ( authm != 0)
{
delete authm;
}
if ( nebula_configuration != 0)
{
delete nebula_configuration;
}
// -----------------------------------------------------------
// Configuration
// -----------------------------------------------------------
// A self-contained structure in current directory is assumed
nebula_location = "./";
mad_location = nebula_location + "lib/mads/";
etc_location = nebula_location + "etc/";
log_location = nebula_location + "var/";
var_location = nebula_location + "var/";
hook_location = nebula_location + "share/hooks/";
remotes_location = nebula_location + "lib/remotes/";
if ( nebula_configuration != 0)
{
delete nebula_configuration;
}
xmlInitParser();
// -----------------------------------------------------------
// Pools
// -----------------------------------------------------------
try
{
vector<const Attribute *> dbs;
db = OneUnitTest::get_db();
NebulaLog::log("ONE",Log::INFO,"Bootstraping OpenNebula database.");
VirtualMachinePool::bootstrap(db);
HostPool::bootstrap(db);
VirtualNetworkPool::bootstrap(db);
UserPool::bootstrap(db);
ImagePool::bootstrap(db);
}
catch (exception&)
{
throw;
}
// -----------------------------------------------------------
try
{
string mac_prefix = "00:00";
int size = 1;
string repository_path;
string default_image_type;
string default_device_prefix;
if (tester->need_vm_pool)
{
vmpool = tester->create_vmpool(db,hook_location);
}
if (tester->need_host_pool)
{
hpool = tester->create_hpool(db,hook_location);
}
if (tester->need_vnet_pool)
{
vnpool = tester->create_vnpool(db,mac_prefix,size);
}
if (tester->need_user_pool)
{
upool = tester->create_upool(db);
}
if (tester->need_image_pool)
{
ipool = tester->create_ipool(db,
repository_path,
default_image_type,
default_device_prefix);
}
}
catch (exception&)
{
throw;
}
// Set pointer to null, to prevent its deletion on the destructor
db = 0;
// -----------------------------------------------------------
//Managers
// -----------------------------------------------------------
timer_period = 0;
rc = 0;
sigfillset(&mask);
pthread_sigmask(SIG_BLOCK, &mask, NULL);
MadManager::mad_manager_system_init();
// ---- Virtual Machine Manager ----
if (tester->need_vmm)
{
try
{
time_t poll_period = 0;
vmm = tester->create_vmm(vmpool,hpool,timer_period,poll_period);
}
catch (bad_alloc&)
{
throw;
}
if( vmm != 0)
{
rc = vmm->start();
}
if ( rc != 0 )
{
throw runtime_error("Could not start the Virtual Machine Manager");
}
}
// ---- Life-cycle Manager ----
if (tester->need_lcm)
{
try
{
lcm = tester->create_lcm(vmpool,hpool);
}
catch (bad_alloc&)
{
throw;
}
if( lcm != 0 )
{
rc = lcm->start();
}
if ( rc != 0 )
{
throw runtime_error("Could not start the Life-cycle Manager");
}
}
// ---- Information Manager ----
if (tester->need_im)
{
try
{
im = tester->create_im(hpool,timer_period,remotes_location);
}
catch (bad_alloc&)
{
throw;
}
if( im != 0 )
{
rc = im->start();
}
if ( rc != 0 )
{
throw runtime_error("Could not start the Information Manager");
}
}
// ---- Transfer Manager ----
if (tester->need_tm)
{
try
{
tm = tester->create_tm(vmpool, hpool);
}
catch (bad_alloc&)
{
throw;
}
if( tm != 0 )
{
rc = tm->start();
}
if ( rc != 0 )
{
throw runtime_error("Could not start the Transfer Manager");
}
}
// ---- Dispatch Manager ----
if ( tester->need_dm )
{
try
{
dm = tester->create_dm(vmpool,hpool);
}
catch (bad_alloc&)
{
throw;
}
if( dm != 0 )
{
rc = dm->start();
}
if ( rc != 0 )
{
throw runtime_error("Could not start the Dispatch Manager");
}
}
// ---- Request Manager ----
if (tester->need_rm)
{
try
{
rm = tester->create_rm(vmpool,hpool,vnpool,upool,ipool,
log_location + "one_xmlrpc.log");
}
catch (bad_alloc&)
{
NebulaLog::log("ONE", Log::ERROR, "Error starting RM");
throw;
}
if( rm != 0 )
{
rc = rm->start();
}
if ( rc != 0 )
{
throw runtime_error("Could not start the Request Manager");
}
}
// ---- Hook Manager ----
if (tester->need_hm)
{
try
{
hm = tester->create_hm(vmpool);
}
catch (bad_alloc&)
{
throw;
}
if( hm != 0 )
{
rc = hm->start();
}
if ( rc != 0 )
{
throw runtime_error("Could not start the Hook Manager");
}
}
// ---- Auth Manager ----
if (tester->need_authm)
{
try
{
authm = tester->create_authm(timer_period);
}
catch (bad_alloc&)
{
throw;
}
if (authm != 0)
{
rc = authm->start();
if ( rc != 0 )
{
throw runtime_error("Could not start the Auth Manager");
}
}
}
// -----------------------------------------------------------
// Load mads
// -----------------------------------------------------------
sleep(2);
if( vmm != 0 )
{
vmm->load_mads(0);
}
if( im != 0 )
{
im->load_mads(0);
}
if( tm != 0 )
{
tm->load_mads(0);
}
if( hm != 0 )
{
hm->load_mads(0);
}
if( authm != 0 )
{
authm->load_mads(0);
}
};

140
src/test/NebulaTest.cc Normal file
View File

@ -0,0 +1,140 @@
/* -------------------------------------------------------------------------- */
/* 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 "NebulaTest.h"
NebulaTest* NebulaTest::the_tester;
VirtualMachinePool* NebulaTest::create_vmpool(SqlDB* db, string hook_location)
{
vector<const Attribute *> hooks;
return new VirtualMachinePool(db, hooks, hook_location);
}
HostPool* NebulaTest::create_hpool(SqlDB* db, string hook_location)
{
vector<const Attribute *> hooks;
return new HostPool(db, hooks, hook_location);
}
VirtualNetworkPool* NebulaTest::create_vnpool(SqlDB* db, string mac_prefix, int size)
{
return new VirtualNetworkPool(db,mac_prefix,size);
}
UserPool* NebulaTest::create_upool(SqlDB* db)
{
return new UserPool(db);
}
ImagePool* NebulaTest::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
// -----------------------------------------------------------
VirtualMachineManager* NebulaTest::create_vmm(VirtualMachinePool* vmpool,
HostPool* hpool,
time_t timer_period,
time_t poll_period)
{
vector<const Attribute *> vmm_mads;
return new VirtualMachineManager(vmpool,
hpool,
timer_period,
poll_period,
vmm_mads);
}
LifeCycleManager* NebulaTest::create_lcm(VirtualMachinePool* vmpool,
HostPool* hpool)
{
return new LifeCycleManager(vmpool,hpool);
}
InformationManager* NebulaTest::create_im(HostPool* hpool,
time_t timer_period,
string remotes_location)
{
vector<const Attribute *> im_mads;
time_t monitor_period = 0;
return new InformationManager(hpool,
timer_period,
monitor_period,
remotes_location,
im_mads);
}
TransferManager* NebulaTest::create_tm(VirtualMachinePool* vmpool,
HostPool* hpool)
{
vector<const Attribute *> tm_mads;
return new TransferManager(vmpool, hpool, tm_mads);
}
DispatchManager* NebulaTest::create_dm(VirtualMachinePool* vmpool,
HostPool* hpool)
{
return new DispatchManager(vmpool, hpool);
}
RequestManager* NebulaTest::create_rm(
VirtualMachinePool * vmpool,
HostPool * hpool,
VirtualNetworkPool * vnpool,
UserPool * upool,
ImagePool * ipool,
string log_file)
{
int rm_port = 2633;
return new RequestManager(vmpool,
hpool,
vnpool,
upool,
ipool,
rm_port,
log_file);
}
HookManager* NebulaTest::create_hm(VirtualMachinePool * vmpool)
{
map<string,string> mad_value;
VectorAttribute * mad;
vector<const Attribute *> hm_mads;
mad_value.insert(make_pair("executable","one_hm"));
mad = new VectorAttribute("HM_MAD",mad_value);
hm_mads.push_back(mad);
return new HookManager(hm_mads,vmpool);
}
AuthManager* NebulaTest::create_authm(time_t timer_period)
{
return 0;
}

24
src/test/OneUnitTest.cc Normal file
View File

@ -0,0 +1,24 @@
/* -------------------------------------------------------------------------- */
/* 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 "OneUnitTest.h"
bool OneUnitTest::mysql;
SqlDB * OneUnitTest::db = 0;
string OneUnitTest::db_name = "ONE_test_database";

42
src/test/SConstruct Normal file
View File

@ -0,0 +1,42 @@
# SConstruct for src/test
# -------------------------------------------------------------------------- #
# 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('env')
# Build a modified Nebula lib
lib_name='nebula_core_test'
# Sources to generate the library
source_files=[
'Nebula.cc',
'NebulaTest.cc'
]
# Build library
env.StaticLibrary(lib_name, source_files)
# Build a modified Nebula lib
lib_name='nebula_test_common'
# Sources to generate the library
source_files=[
'OneUnitTest.cc',
]
# Build library
env.StaticLibrary(lib_name, source_files)

View File

@ -26,8 +26,8 @@
/* ************************************************************************** */
void TransferManagerDriver::transfer (
const int oid,
const string& xfr_file) const
const int oid,
const string& xfr_file) const
{
ostringstream os;
@ -96,8 +96,8 @@ void TransferManagerDriver::protocol(
return;
}
if ( vm->get_lcm_state() == VirtualMachine::DELETE ||
vm->get_lcm_state() == VirtualMachine::FAILURE||
if ( vm->get_lcm_state() == VirtualMachine::CLEANUP ||
vm->get_lcm_state() == VirtualMachine::FAILURE ||
vm->get_lcm_state() == VirtualMachine::LCM_INIT )
{
os.str("");
@ -118,22 +118,22 @@ void TransferManagerDriver::protocol(
if (result == "SUCCESS")
{
switch (vm->get_lcm_state())
{
case VirtualMachine::PROLOG:
case VirtualMachine::PROLOG_MIGRATE:
case VirtualMachine::PROLOG_RESUME:
lcm_action = LifeCycleManager::PROLOG_SUCCESS;
break;
switch (vm->get_lcm_state())
{
case VirtualMachine::PROLOG:
case VirtualMachine::PROLOG_MIGRATE:
case VirtualMachine::PROLOG_RESUME:
lcm_action = LifeCycleManager::PROLOG_SUCCESS;
break;
case VirtualMachine::EPILOG:
case VirtualMachine::EPILOG_STOP:
lcm_action = LifeCycleManager::EPILOG_SUCCESS;
break;
case VirtualMachine::EPILOG:
case VirtualMachine::EPILOG_STOP:
lcm_action = LifeCycleManager::EPILOG_SUCCESS;
break;
default:
goto error_state;
}
default:
goto error_state;
}
}
else
{
@ -146,22 +146,22 @@ void TransferManagerDriver::protocol(
vm->log("TM",Log::ERROR,os);
switch (vm->get_lcm_state())
{
case VirtualMachine::PROLOG:
case VirtualMachine::PROLOG_MIGRATE:
case VirtualMachine::PROLOG_RESUME:
lcm_action = LifeCycleManager::PROLOG_FAILURE;
break;
switch (vm->get_lcm_state())
{
case VirtualMachine::PROLOG:
case VirtualMachine::PROLOG_MIGRATE:
case VirtualMachine::PROLOG_RESUME:
lcm_action = LifeCycleManager::PROLOG_FAILURE;
break;
case VirtualMachine::EPILOG:
case VirtualMachine::EPILOG_STOP:
lcm_action = LifeCycleManager::EPILOG_FAILURE;
break;
case VirtualMachine::EPILOG:
case VirtualMachine::EPILOG_STOP:
lcm_action = LifeCycleManager::EPILOG_FAILURE;
break;
default:
goto error_state;
}
default:
goto error_state;
}
}
lcm->trigger(lcm_action, id);
@ -179,14 +179,14 @@ void TransferManagerDriver::protocol(
return;
error_state:
os.str("");
os << "Wrong state in TM answer for VM " << id;
os.str("");
os << "Wrong state in TM answer for VM " << id;
vm->log("TM",Log::ERROR,os);
vm->log("TM",Log::ERROR,os);
vm->unlock();
vm->unlock();
return;
return;
}
/* -------------------------------------------------------------------------- */

View File

@ -14,44 +14,9 @@
# limitations under the License.
# --------------------------------------------------------------------------
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
Import('env')
# This is the absolute path where the project is located
cwd="../../../"
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# 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/',
])
# Library dirs
main_env.Append(LIBPATH=[
cwd + '/src/common',
cwd + '/src/mad',
cwd + '/src/log',
cwd + '/src/nebula',
cwd + '/src/pool',
cwd + '/src/sql',
cwd + '/src/authm',
cwd + '/src/um',
'/usr/include/openssl/',
])
main_env.Append(LIBS=[
env.Prepend(LIBS=[
'nebula_um',
'nebula_pool',
'nebula_log',
@ -60,38 +25,7 @@ main_env.Append(LIBS=[
'nebula_mad',
'nebula_core',
'nebula_sql',
'cppunit',
'dl',
'pthread',
'crypto'
])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# Linking flags
main_env.Append(LDFLAGS=["-g "])
main_env.Program('test','UserPoolTest.cc')
# MYSQL
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# 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', ])
# MySQL
mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=[ 'mysqlclient', ])
env.Program('test','UserPoolTest.cc')

View File

@ -14,49 +14,9 @@
# limitations under the License.
# --------------------------------------------------------------------------
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
Import('env')
# This is the absolute path where the project is located
cwd="../../../"
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# 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/',
])
# 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/vm',
cwd + '/src/hm',
cwd + '/src/authm',
cwd + '/src/mad',
cwd + '/src/vnm',
cwd + '/src/um',
cwd + '/src/image',
'/usr/include/openssl/',
])
main_env.Append(LIBS=[
env.Prepend(LIBS=[
'nebula_um',
'nebula_vm',
'nebula_hm',
@ -70,39 +30,7 @@ main_env.Append(LIBS=[
'nebula_log',
'nebula_core',
'nebula_sql',
'cppunit',
'dl',
'pthread',
'crypto',
'crypto'
])
# MYSQL
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# 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', ])
# MySQL
mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=[ 'mysqlclient', ])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# Linking flags
main_env.Append(LDFLAGS=["-g "])
main_env.Program('test','VirtualMachinePoolTest.cc')
env.Program('test','VirtualMachinePoolTest.cc')

View File

@ -282,8 +282,8 @@ void VirtualMachineManagerDriver::protocol(
return;
}
if ( vm->get_lcm_state() == VirtualMachine::DELETE ||
vm->get_lcm_state() == VirtualMachine::FAILURE||
if ( vm->get_lcm_state() == VirtualMachine::CLEANUP ||
vm->get_lcm_state() == VirtualMachine::FAILURE ||
vm->get_lcm_state() == VirtualMachine::LCM_INIT )
{
os.str("");
@ -608,4 +608,3 @@ void VirtualMachineManagerDriver::recover()
{
NebulaLog::log("VMM",Log::INFO,"Recovering VMM drivers");
}

View File

@ -14,45 +14,9 @@
# limitations under the License.
# --------------------------------------------------------------------------
import os
import sys
import shutil
sys.path.append("../../../share/scons")
from lex_bison import *
Import('env')
# This is the absolute path where the project is located
cwd="../../../"
# Environment that will be applied to each scons child
main_env=Environment()
main_env['ENV']['PATH']=os.environ['PATH']
# 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/',
])
# Library dirs
main_env.Append(LIBPATH=[
cwd + '/src/authm',
cwd + '/src/common',
cwd + '/src/mad',
cwd + '/src/nebula',
cwd + '/src/sql',
cwd + '/src/log',
cwd + '/src/pool',
cwd + '/src/template',
cwd + '/src/um',
cwd + '/src/vnm',
])
main_env.Append(LIBS=[
env.Prepend(LIBS=[
'nebula_log',
'nebula_um',
'nebula_vnm',
@ -63,39 +27,7 @@ main_env.Append(LIBS=[
'nebula_core',
'nebula_common',
'nebula_sql',
'cppunit',
'dl',
'pthread',
'crypto',
'crypto'
])
# MYSQL
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# 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', ])
# MySQL
mysql=ARGUMENTS.get('mysql', 'no')
if mysql=='yes':
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
main_env.Append(LIBS=[ 'mysqlclient', ])
# Compile flags
main_env.Append(CPPFLAGS=[
"-g",
"-Wall",
"-Werror"
])
# Linking flags
main_env.Append(LDFLAGS=["-g "])
main_env.Program('test','VirtualNetworkPoolTest.cc')
env.Program('test','VirtualNetworkPoolTest.cc')