mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Feature #379: Testing for Life Cycle Manager.
This commit is contained in:
parent
6b8855b0e3
commit
07ce708c3e
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
109
src/lcm/test/DummyManager.h
Normal file
109
src/lcm/test/DummyManager.h
Normal file
@ -0,0 +1,109 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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"
|
||||
|
||||
/**
|
||||
* The Dummy Manager will ignore any trigger calls but FINALIZE, unless the lcm
|
||||
* actions are set.
|
||||
*/
|
||||
class DummyManager
|
||||
{
|
||||
protected:
|
||||
vector<LifeCycleManager::Actions> actions;
|
||||
int index;
|
||||
|
||||
DummyManager():index(0){}
|
||||
|
||||
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 */
|
99
src/lcm/test/LifeCycleManagerTest.cc
Normal file
99
src/lcm/test/LifeCycleManagerTest.cc
Normal file
@ -0,0 +1,99 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 "LifeCycleManagerTest.h"
|
||||
|
||||
string LifeCycleManagerTest::db_name;
|
||||
bool LifeCycleManagerTest::mysql;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
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";
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
// Option flags
|
||||
bool sqlite_flag = true;
|
||||
bool log_flag = false;
|
||||
|
||||
// Long options
|
||||
const struct option long_opt[] =
|
||||
{
|
||||
{ "sqlite", 0, NULL, 's'},
|
||||
{ "mysql", 0, NULL, 'm'},
|
||||
{ "log", 0, NULL, 'l'},
|
||||
{ "help", 0, NULL, 'h'}
|
||||
};
|
||||
|
||||
int c;
|
||||
while ((c = getopt_long (argc, argv, "smlh", long_opt, NULL)) != -1)
|
||||
switch (c)
|
||||
{
|
||||
case 'm':
|
||||
sqlite_flag = false;
|
||||
break;
|
||||
case 'l':
|
||||
log_flag = true;
|
||||
break;
|
||||
case 'h':
|
||||
show_options();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We need to set the log file, otherwise it will end in a dead-lock
|
||||
NebulaLog::init_log_system(NebulaLog::FILE, Log::DEBUG, "test.log");
|
||||
NebulaLog::log("Test", Log::INFO, "Test started");
|
||||
|
||||
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
|
||||
SETUP_XML_WRITER(runner, "output.xml")
|
||||
|
||||
runner.addTest( LifeCycleManagerTest::suite() );
|
||||
|
||||
if (sqlite_flag)
|
||||
{
|
||||
LifeCycleManagerTest::mysql = false;
|
||||
NebulaLog::log("Test", Log::INFO, "Running Sqlite tests...");
|
||||
cout << "\nRunning Sqlite tests...\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
LifeCycleManagerTest::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;
|
||||
}
|
836
src/lcm/test/LifeCycleManagerTest.h
Normal file
836
src/lcm/test/LifeCycleManagerTest.h
Normal file
@ -0,0 +1,836 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 "DummyManager.h"
|
||||
|
||||
#include "SqliteDB.h"
|
||||
#include "MySqlDB.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 "test/one_test_common.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int uids[] = {123, 261, 123};
|
||||
|
||||
const string names[] = {"VM one", "Second VM", "VM 3"};
|
||||
|
||||
const string templates[] =
|
||||
{
|
||||
"NAME = \"VM one\"\n"
|
||||
"MEMORY = 128\n"
|
||||
"CPU = 1",
|
||||
|
||||
"NAME = \"Second VM\"\n"
|
||||
"MEMORY = 256\n"
|
||||
"CPU = 2",
|
||||
|
||||
"NAME = \"VM 3\"\n"
|
||||
"MEMORY = 1024\n"
|
||||
"CPU = 1"
|
||||
};
|
||||
|
||||
static int hid = 123;
|
||||
static string hostname = "test_hostname";
|
||||
static string vmm_mad = "vmm_mad";
|
||||
static string tm_mad = "tm_mad";
|
||||
static string vmdir = "vmdir";
|
||||
|
||||
|
||||
class LifeCycleManagerTest : public CppUnit::TestFixture
|
||||
{
|
||||
|
||||
CPPUNIT_TEST_SUITE (LifeCycleManagerTest);
|
||||
|
||||
CPPUNIT_TEST ( lcm_init_to_prolog );
|
||||
CPPUNIT_TEST ( lcm_init_to_prolog_resume );
|
||||
|
||||
CPPUNIT_TEST ( prolog_to_boot );
|
||||
CPPUNIT_TEST ( prolog_to_failed );
|
||||
|
||||
CPPUNIT_TEST ( prolog_resume_to_boot );
|
||||
CPPUNIT_TEST ( prolog_resume_to_failed );
|
||||
|
||||
CPPUNIT_TEST ( boot_to_running );
|
||||
CPPUNIT_TEST ( boot_to_failed );
|
||||
|
||||
CPPUNIT_TEST ( running_to_save_migrate );
|
||||
CPPUNIT_TEST ( running_to_save_stop );
|
||||
CPPUNIT_TEST ( running_to_shutdown );
|
||||
CPPUNIT_TEST ( running_to_save_suspend );
|
||||
CPPUNIT_TEST ( running_to_migrate );
|
||||
CPPUNIT_TEST ( running_to_cancel );
|
||||
|
||||
CPPUNIT_TEST ( save_migrate_to_prolog_migrate );
|
||||
CPPUNIT_TEST ( save_migrate_to_running );
|
||||
|
||||
CPPUNIT_TEST ( prolog_migrate_to_boot );
|
||||
CPPUNIT_TEST ( prolog_migrate_to_failed );
|
||||
|
||||
CPPUNIT_TEST ( cancel_to_done );
|
||||
CPPUNIT_TEST ( cancel_to_running );
|
||||
|
||||
CPPUNIT_TEST ( migrate_to_running );
|
||||
CPPUNIT_TEST ( migrate_to_failed );
|
||||
|
||||
CPPUNIT_TEST ( save_suspend_to_suspended );
|
||||
CPPUNIT_TEST ( save_suspend_to_running );
|
||||
|
||||
CPPUNIT_TEST ( shutdown_to_epilog );
|
||||
CPPUNIT_TEST ( shutdown_to_running );
|
||||
|
||||
CPPUNIT_TEST ( save_stop_to_epilog_stop );
|
||||
CPPUNIT_TEST ( save_stop_to_running );
|
||||
|
||||
CPPUNIT_TEST ( epilog_to_done );
|
||||
CPPUNIT_TEST ( epilog_to_failed );
|
||||
|
||||
CPPUNIT_TEST ( epilog_stop_to_stop );
|
||||
CPPUNIT_TEST ( epilog_stop_to_failed );
|
||||
|
||||
CPPUNIT_TEST_SUITE_END ();
|
||||
|
||||
private:
|
||||
|
||||
VirtualMachine * vm;
|
||||
VirtualMachinePool * vmpool;
|
||||
HostPool * hpool;
|
||||
|
||||
LifeCycleManager * lcm;
|
||||
VirtualMachineManagerTest * vmm;
|
||||
TransferManagerTest * tm;
|
||||
DispatchManager * dm;
|
||||
|
||||
int oid;
|
||||
int rc;
|
||||
|
||||
vector<LifeCycleManager::Actions> tm_actions;
|
||||
vector<LifeCycleManager::Actions> vmm_actions;
|
||||
|
||||
void wait(int nullllll)
|
||||
{
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the VM changes to the specified state.
|
||||
* There is a time-out of 3 seconds.
|
||||
*/
|
||||
void wait_assert( VirtualMachine* vm,
|
||||
VirtualMachine::VmState state,
|
||||
VirtualMachine::LcmState lcm_state = VirtualMachine::RUNNING)
|
||||
{
|
||||
int n_steps = 100;
|
||||
int step = 30000;
|
||||
|
||||
int i = 0;
|
||||
|
||||
while( !(
|
||||
(
|
||||
vm->get_state() == state
|
||||
&&
|
||||
(
|
||||
state != VirtualMachine::ACTIVE
|
||||
||
|
||||
vm->get_lcm_state() == lcm_state
|
||||
)
|
||||
)
|
||||
||
|
||||
i > n_steps ))
|
||||
{
|
||||
usleep(step);
|
||||
i++;
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT( vm->get_state() == state );
|
||||
|
||||
if( state == VirtualMachine::ACTIVE)
|
||||
{
|
||||
CPPUNIT_ASSERT( vm->get_lcm_state() == lcm_state );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates the indexth VM template
|
||||
*/
|
||||
int allocate(int index)
|
||||
{
|
||||
VirtualMachineTemplate * vm_template;
|
||||
int oid;
|
||||
char * error_msg = 0;
|
||||
int rc;
|
||||
string err;
|
||||
|
||||
vm_template = new VirtualMachineTemplate;
|
||||
rc = vm_template->parse(templates[index],&error_msg);
|
||||
|
||||
if( rc == 0 )
|
||||
{
|
||||
return vmpool->allocate(uids[index], vm_template, &oid,
|
||||
err, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Allocates a VM and sets it to pending state, creaing a history entry.
|
||||
* The VM returned is locked
|
||||
*/
|
||||
VirtualMachine* allocate_pending(int index)
|
||||
{
|
||||
oid = allocate(index);
|
||||
|
||||
CPPUNIT_ASSERT(oid >= 0);
|
||||
|
||||
vm = vmpool->get(oid,true);
|
||||
vm->unlock();
|
||||
|
||||
CPPUNIT_ASSERT( vm != 0 );
|
||||
CPPUNIT_ASSERT( vm->get_state() == VirtualMachine::PENDING );
|
||||
|
||||
vm->lock();
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
rc = vmpool->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a VM and sets it to running state.
|
||||
* The VM returned is unlocked
|
||||
*/
|
||||
VirtualMachine* allocate_running(int index)
|
||||
{
|
||||
vm = allocate_pending(index);
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::PROLOG_SUCCESS);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::DEPLOY_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
rc = dm->deploy(vm);
|
||||
vm->unlock();
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::RUNNING);
|
||||
|
||||
tm->clear_actions();
|
||||
vmm->clear_actions();
|
||||
|
||||
tm_actions.clear();
|
||||
vmm_actions.clear();
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
public:
|
||||
static bool mysql;
|
||||
static string db_name;
|
||||
|
||||
static bool isMysql()
|
||||
{
|
||||
return mysql;
|
||||
}
|
||||
|
||||
void setUp()
|
||||
{
|
||||
// Create var dir.
|
||||
string command = "mkdir -p var";
|
||||
std::system(command.c_str());
|
||||
|
||||
Nebula& neb = Nebula::instance();
|
||||
neb.start();
|
||||
|
||||
lcm = neb.get_lcm();
|
||||
|
||||
vmpool = neb.get_vmpool();
|
||||
hpool = neb.get_hpool();
|
||||
|
||||
vmm = static_cast<VirtualMachineManagerTest*>(neb.get_vmm());
|
||||
tm = static_cast<TransferManagerTest*>(neb.get_tm());
|
||||
dm = neb.get_dm();
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
tm_actions.clear();
|
||||
vmm_actions.clear();
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Stop the managers & free resources
|
||||
// -----------------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::FINALIZE,0);
|
||||
lcm->trigger(LifeCycleManager::FINALIZE,0);
|
||||
|
||||
tm->trigger(TransferManager::FINALIZE,0);
|
||||
dm->trigger(DispatchManager::FINALIZE,0);
|
||||
|
||||
//sleep to wait drivers???
|
||||
pthread_join(vmm->get_thread_id(),0);
|
||||
pthread_join(lcm->get_thread_id(),0);
|
||||
pthread_join(tm->get_thread_id(),0);
|
||||
pthread_join(dm->get_thread_id(),0);
|
||||
|
||||
//XML Library
|
||||
xmlCleanupParser();
|
||||
|
||||
if (mysql)
|
||||
{
|
||||
SqlDB * db;
|
||||
db = new MySqlDB("localhost","oneadmin","oneadmin",NULL);
|
||||
|
||||
ostringstream oss;
|
||||
oss << "DROP DATABASE IF EXISTS " << db_name;
|
||||
db->exec(oss);
|
||||
|
||||
delete db;
|
||||
}
|
||||
|
||||
// Clean var dir.
|
||||
string command = "rm -r var";
|
||||
std::system(command.c_str());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void lcm_init_to_prolog()
|
||||
{
|
||||
vm = allocate_pending(0);
|
||||
|
||||
rc = dm->deploy(vm);
|
||||
vm->unlock();
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::PROLOG );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void lcm_init_to_prolog_resume()
|
||||
{
|
||||
vm = allocate_pending(0);
|
||||
vm->set_reason(History::STOP_RESUME);
|
||||
vm->cp_history();
|
||||
|
||||
rc = dm->deploy(vm);
|
||||
vm->unlock();
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::PROLOG_RESUME );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void prolog_to_boot()
|
||||
{
|
||||
vm = allocate_pending(0);
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::PROLOG_SUCCESS);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
rc = dm->deploy(vm);
|
||||
vm->unlock();
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::BOOT );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void prolog_to_failed()
|
||||
{
|
||||
vm = allocate_pending(0);
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::PROLOG_FAILURE);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
rc = dm->deploy(vm);
|
||||
vm->unlock();
|
||||
|
||||
wait_assert(vm, VirtualMachine::FAILED );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void prolog_resume_to_boot()
|
||||
{
|
||||
vm = allocate_pending(0);
|
||||
vm->set_reason(History::STOP_RESUME);
|
||||
vm->cp_history();
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::PROLOG_SUCCESS);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
rc = dm->deploy(vm);
|
||||
vm->unlock();
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::BOOT );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void prolog_resume_to_failed()
|
||||
{
|
||||
vm = allocate_pending(0);
|
||||
vm->set_reason(History::STOP_RESUME);
|
||||
vm->cp_history();
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::PROLOG_FAILURE);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
rc = dm->deploy(vm);
|
||||
vm->unlock();
|
||||
|
||||
wait_assert(vm, VirtualMachine::FAILED );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void boot_to_running()
|
||||
{
|
||||
allocate_running(0);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void boot_to_failed()
|
||||
{
|
||||
vm = allocate_pending(0);
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::PROLOG_SUCCESS);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::DEPLOY_FAILURE);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
rc = dm->deploy(vm);
|
||||
vm->unlock();
|
||||
|
||||
wait_assert(vm, VirtualMachine::FAILED );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void running_to_save_migrate()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
|
||||
rc = vmpool->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
dm->migrate(vm);
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::SAVE_MIGRATE );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void running_to_save_stop()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
dm->stop(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::SAVE_STOP );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void running_to_shutdown()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
dm->shutdown(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::SHUTDOWN );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void running_to_save_suspend()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
dm->suspend(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::SAVE_SUSPEND );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void running_to_migrate()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
dm->live_migrate(vm);
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::MIGRATE );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void running_to_cancel()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
dm->cancel(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::CANCEL );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void save_migrate_to_prolog_migrate()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
|
||||
rc = vmpool->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->migrate(vm);
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE,VirtualMachine::PROLOG_MIGRATE );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void save_migrate_to_running()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
|
||||
rc = vmpool->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_FAILURE);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->migrate(vm);
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::RUNNING );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void prolog_migrate_to_boot()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
|
||||
rc = vmpool->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::PROLOG_SUCCESS);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->migrate(vm);
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::BOOT );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void prolog_migrate_to_failed()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
|
||||
rc = vmpool->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::PROLOG_FAILURE);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->migrate(vm);
|
||||
|
||||
wait_assert(vm, VirtualMachine::FAILED);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void cancel_to_done()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::CANCEL_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->cancel(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::DONE);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void cancel_to_running()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::CANCEL_FAILURE);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->cancel(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::RUNNING );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void migrate_to_running()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
rc = vmpool->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
CPPUNIT_ASSERT( vm->hasHistory() );
|
||||
CPPUNIT_ASSERT( vm->hasPreviousHistory() );
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::DEPLOY_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->live_migrate(vm);
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::RUNNING );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void migrate_to_failed()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
rc = vmpool->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
CPPUNIT_ASSERT( vm->hasHistory() );
|
||||
CPPUNIT_ASSERT( vm->hasPreviousHistory() );
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::DEPLOY_FAILURE);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->live_migrate(vm);
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::RUNNING );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void save_suspend_to_suspended()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->suspend(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::SUSPENDED);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void save_suspend_to_running()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_FAILURE);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->suspend(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::RUNNING );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void shutdown_to_epilog()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SHUTDOWN_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->shutdown(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::EPILOG );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void shutdown_to_running()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SHUTDOWN_FAILURE);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->shutdown(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::RUNNING );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void save_stop_to_epilog_stop()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->stop(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::EPILOG_STOP );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void save_stop_to_running()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_FAILURE);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
dm->stop(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::ACTIVE, VirtualMachine::RUNNING );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void epilog_to_done()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SHUTDOWN_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::EPILOG_SUCCESS);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
dm->shutdown(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::DONE );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void epilog_to_failed()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SHUTDOWN_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::EPILOG_FAILURE);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
dm->shutdown(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::FAILED );
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void epilog_stop_to_stop()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::EPILOG_SUCCESS);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
dm->stop(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::STOPPED );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void epilog_stop_to_failed()
|
||||
{
|
||||
vm = allocate_running(0);
|
||||
|
||||
vmm_actions.push_back(LifeCycleManager::SAVE_SUCCESS);
|
||||
vmm->set_actions(vmm_actions);
|
||||
|
||||
tm_actions.push_back(LifeCycleManager::EPILOG_FAILURE);
|
||||
tm->set_actions(tm_actions);
|
||||
|
||||
dm->stop(vm->get_oid());
|
||||
|
||||
wait_assert(vm, VirtualMachine::FAILED );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
};
|
330
src/lcm/test/Nebula.cc
Normal file
330
src/lcm/test/Nebula.cc
Normal file
@ -0,0 +1,330 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 "LifeCycleManagerTest.h"
|
||||
#include "DummyManager.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()
|
||||
{
|
||||
|
||||
// Clean up
|
||||
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;
|
||||
}
|
||||
|
||||
if ( db != 0 )
|
||||
{
|
||||
delete db;
|
||||
}
|
||||
|
||||
|
||||
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/";
|
||||
|
||||
|
||||
int rc;
|
||||
sigset_t mask;
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Initialize the XML library
|
||||
// -----------------------------------------------------------
|
||||
xmlInitParser();
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Pools
|
||||
// -----------------------------------------------------------
|
||||
|
||||
try
|
||||
{
|
||||
vector<const Attribute *> dbs;
|
||||
int rc;
|
||||
|
||||
bool db_is_sqlite = ! LifeCycleManagerTest::isMysql();
|
||||
|
||||
string server = "localhost";
|
||||
string user = "oneadmin";
|
||||
string passwd = "oneadmin";
|
||||
string db_name = "ONE_test_database";
|
||||
|
||||
if ( db_is_sqlite )
|
||||
{
|
||||
string db_name = var_location + "one.db";
|
||||
|
||||
db = new SqliteDB(db_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
db = new MySqlDB(server,user,passwd,0);
|
||||
|
||||
oss << "DROP DATABASE IF EXISTS " << db_name;
|
||||
db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
|
||||
oss << "CREATE DATABASE IF NOT EXISTS " << db_name;
|
||||
rc = db->exec(oss);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not create database.");
|
||||
}
|
||||
|
||||
oss.str("");
|
||||
oss << "USE " << db_name;
|
||||
rc = db->exec(oss);
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not open database.");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
vector<const Attribute *> vm_hooks;
|
||||
|
||||
vmpool = new VirtualMachinePool(db, vm_hooks,hook_location);
|
||||
hpool = new HostPool(db);
|
||||
vnpool = new VirtualNetworkPool(db,mac_prefix,size);
|
||||
upool = new UserPool(db);
|
||||
ipool = new ImagePool(db,
|
||||
repository_path,
|
||||
default_image_type,
|
||||
default_device_prefix);
|
||||
}
|
||||
catch (exception&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Block all signals before creating any Nebula thread
|
||||
// -----------------------------------------------------------
|
||||
|
||||
sigfillset(&mask);
|
||||
|
||||
pthread_sigmask(SIG_BLOCK, &mask, NULL);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
//Managers
|
||||
// -----------------------------------------------------------
|
||||
|
||||
MadManager::mad_manager_system_init();
|
||||
|
||||
time_t timer_period = 0;
|
||||
|
||||
// ---- Virtual Machine Manager ----
|
||||
try
|
||||
{
|
||||
time_t poll_period = 0;
|
||||
vector<const Attribute *> vmm_mads;
|
||||
|
||||
vmm = new VirtualMachineManagerTest(
|
||||
vmpool,
|
||||
hpool,
|
||||
timer_period,
|
||||
poll_period,
|
||||
vmm_mads);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
rc = vmm->start();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Virtual Machine Manager");
|
||||
}
|
||||
|
||||
// ---- Transfer Manager ----
|
||||
try
|
||||
{
|
||||
vector<const Attribute *> tm_mads;
|
||||
|
||||
tm = new TransferManagerTest(vmpool, hpool, tm_mads);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
rc = tm->start();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Transfer Manager");
|
||||
}
|
||||
|
||||
// ---- Dispatch Manager ----
|
||||
try
|
||||
{
|
||||
dm = new DispatchManager(vmpool,hpool);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
rc = dm->start();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Dispatch Manager");
|
||||
}
|
||||
|
||||
// ---- Life-cycle Manager ----
|
||||
try
|
||||
{
|
||||
// lcm = new LifeCycleManager(vmpool,hpool,vmm,tm,dm);
|
||||
lcm = new LifeCycleManager(vmpool,hpool);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
rc = lcm->start();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Life-cycle Manager");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Load mads
|
||||
// -----------------------------------------------------------
|
||||
|
||||
sleep(2);
|
||||
|
||||
vmm->load_mads(0);
|
||||
};
|
||||
|
236
src/lcm/test/SConstruct
Normal file
236
src/lcm/test/SConstruct
Normal file
@ -0,0 +1,236 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
import os
|
||||
import sys
|
||||
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']
|
||||
|
||||
# snippet borrowed from http://dev.gentoo.org/~vapier/scons-blows.txt
|
||||
# makes scons aware of build related environment variables
|
||||
if os.environ.has_key('CC'):
|
||||
main_env['CC'] = os.environ['CC']
|
||||
if os.environ.has_key('CFLAGS'):
|
||||
main_env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
|
||||
if os.environ.has_key('CXX'):
|
||||
main_env['CXX'] = os.environ['CXX']
|
||||
if os.environ.has_key('CXXFLAGS'):
|
||||
main_env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
|
||||
if os.environ.has_key('LDFLAGS'):
|
||||
main_env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
|
||||
|
||||
# Add builders for flex and bison
|
||||
add_lex(main_env)
|
||||
add_bison(main_env)
|
||||
|
||||
# Include dirs
|
||||
main_env.Append(CPPPATH=[
|
||||
cwd+'/include',
|
||||
'/usr/include/cppunit/'
|
||||
])
|
||||
|
||||
# Library dirs
|
||||
main_env.Append(LIBPATH=[
|
||||
cwd+'/src/common',
|
||||
cwd+'/src/log',
|
||||
cwd+'/src/sql',
|
||||
cwd+'/src/host',
|
||||
cwd+'/src/mad',
|
||||
cwd+'/src/nebula',
|
||||
cwd+'/src/pool',
|
||||
cwd+'/src/template',
|
||||
cwd+'/src/vm',
|
||||
cwd+'/src/vmm',
|
||||
cwd+'/src/lcm',
|
||||
cwd+'/src/tm',
|
||||
cwd+'/src/dm',
|
||||
cwd+'/src/im',
|
||||
cwd+'/src/image',
|
||||
cwd+'/src/rm',
|
||||
cwd+'/src/vnm',
|
||||
cwd+'/src/hm',
|
||||
cwd+'/src/um',
|
||||
cwd+'/src/authm',
|
||||
'.',
|
||||
])
|
||||
|
||||
# Compile flags
|
||||
main_env.Append(CPPFLAGS=[
|
||||
"-g",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
])
|
||||
|
||||
# Linking flags
|
||||
main_env.Append(LINKFLAGS=['-g', '-pthread'])
|
||||
|
||||
#######################
|
||||
# EXTRA CONFIGURATION #
|
||||
#######################
|
||||
|
||||
# SQLITE
|
||||
sqlite_dir=ARGUMENTS.get('sqlite_dir', 'none')
|
||||
if sqlite_dir!='none':
|
||||
main_env.Append(LIBPATH=[sqlite_dir+"/lib"])
|
||||
main_env.Append(CPPPATH=[sqlite_dir+"/include"])
|
||||
|
||||
sqlite=ARGUMENTS.get('sqlite', 'yes')
|
||||
if sqlite=='yes':
|
||||
main_env.Append(sqlite='yes')
|
||||
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])
|
||||
else:
|
||||
main_env.Append(sqlite='no')
|
||||
|
||||
# MySQL
|
||||
mysql=ARGUMENTS.get('mysql', 'no')
|
||||
if mysql=='yes':
|
||||
main_env.Append(mysql='yes')
|
||||
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
|
||||
else:
|
||||
main_env.Append(mysql='no')
|
||||
|
||||
|
||||
# xmlrpc
|
||||
xmlrpc_dir=ARGUMENTS.get('xmlrpc', 'none')
|
||||
if xmlrpc_dir!='none':
|
||||
main_env.Append(LIBPATH=[xmlrpc_dir+"/lib"])
|
||||
main_env.Append(CPPPATH=[xmlrpc_dir+"/include"])
|
||||
|
||||
# build lex/bison
|
||||
build_parsers=ARGUMENTS.get('parsers', 'no')
|
||||
if build_parsers=='yes':
|
||||
main_env.Append(parsers='yes')
|
||||
else:
|
||||
main_env.Append(parsers='no')
|
||||
|
||||
if not main_env.GetOption('clean'):
|
||||
try:
|
||||
main_env.ParseConfig('../../../share/scons/get_xmlrpc_config server')
|
||||
main_env.ParseConfig('../../../share/scons/get_xmlrpc_config client')
|
||||
|
||||
if mysql=='yes':
|
||||
main_env.ParseConfig('mysql_config --cflags --libs')
|
||||
|
||||
except Exception, e:
|
||||
print ""
|
||||
print "Error searching for xmlrpc-c libraries. Please check this"+\
|
||||
" things:"
|
||||
print ""
|
||||
print " * You have installed development libraries for xmlrpc-c. One"+\
|
||||
" way to check"
|
||||
print " this is calling xmlrpc-c-config that is provided with the"+\
|
||||
" development"
|
||||
print " package."
|
||||
print " * Check that the version of xmlrpc-c is at least 1.06. You"+\
|
||||
" can do this also"
|
||||
print " calling:"
|
||||
print " $ xmlrpc-c-config --version"
|
||||
print " * If all this requirements are already met please send log"+\
|
||||
" files located in"
|
||||
print " .xmlrpc_test to the mailing list."
|
||||
print ""
|
||||
exit(-1)
|
||||
else:
|
||||
main_env.Replace(mysql='yes')
|
||||
shutil.rmtree('.xmlrpc_test', True)
|
||||
shutil.rmtree('src/nebula/.xmlrpc_test', True)
|
||||
shutil.rmtree('src/scheduler/.xmlrpc_test', True)
|
||||
|
||||
|
||||
# libxml2
|
||||
main_env.ParseConfig('xml2-config --libs --cflags')
|
||||
|
||||
|
||||
# Build LCM and DM toguether in a lib
|
||||
|
||||
lib_name='nebula_lcm_dm'
|
||||
|
||||
# Sources to generate the library
|
||||
source_files=[
|
||||
'../LifeCycleManager.cc',
|
||||
'../LifeCycleActions.cc',
|
||||
'../LifeCycleStates.cc',
|
||||
'../../dm/DispatchManager.cc',
|
||||
'../../dm/DispatchManagerActions.cc',
|
||||
'../../dm/DispatchManagerStates.cc',
|
||||
]
|
||||
|
||||
# Build library
|
||||
main_env.StaticLibrary(lib_name, source_files)
|
||||
|
||||
|
||||
# Build a modified Nebula lib
|
||||
|
||||
lib_name='nebula_core_test'
|
||||
|
||||
# Sources to generate the library
|
||||
source_files=[
|
||||
'Nebula.cc',
|
||||
'../../nebula/NebulaTemplate.cc',
|
||||
]
|
||||
|
||||
# Build library
|
||||
main_env.StaticLibrary(lib_name, source_files)
|
||||
|
||||
|
||||
# Build daemon
|
||||
main_env.Append(LIBS=[
|
||||
'nebula_lcm_dm',
|
||||
'nebula_core_test',
|
||||
|
||||
'nebula_vmm',
|
||||
'nebula_im',
|
||||
'nebula_rm',
|
||||
'nebula_tm',
|
||||
'nebula_um',
|
||||
'nebula_mad',
|
||||
'nebula_template',
|
||||
'nebula_host',
|
||||
'nebula_vm',
|
||||
'nebula_vnm',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
'nebula_hm',
|
||||
'nebula_authm',
|
||||
'nebula_common',
|
||||
'nebula_sql',
|
||||
'nebula_log',
|
||||
|
||||
'crypto',
|
||||
'cppunit',
|
||||
])
|
||||
|
||||
# Sources to generate the library
|
||||
if main_env['sqlite']=='yes':
|
||||
main_env.Append(LIBS=['sqlite3'])
|
||||
|
||||
if main_env['mysql']=='yes':
|
||||
main_env.Append(LIBS=['mysqlclient'])
|
||||
|
||||
|
||||
if not main_env.GetOption('clean'):
|
||||
main_env.ParseConfig('../../../share/scons/get_xmlrpc_config server')
|
||||
|
||||
|
||||
main_env.Program('test','LifeCycleManagerTest.cc')
|
Loading…
Reference in New Issue
Block a user