1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

Remove outdated core tests

This commit is contained in:
Carlos Martín 2013-10-25 16:05:53 +02:00
parent 1a57cbd5b7
commit 84ecfbeb7e
51 changed files with 0 additions and 11222 deletions

View File

@ -250,49 +250,6 @@ build_scripts=[
'src/im_mad/collectd/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/cluster/test/SConstruct',
'src/datastore/test/SConstruct',
'src/group/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',
'src/xml/test/SConstruct',
'src/vm_template/test/SConstruct',
])
else:
main_env.Append(testing='no')
for script in build_scripts:
env=main_env.Clone()
SConscript(script, exports='env')

View File

@ -1,156 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 "VMTemplatePool.h"
#include "DatastorePool.h"
#include "ClusterPool.h"
#include "DocumentPool.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"
#include "AclManager.h"
#include "ImageManager.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_template_pool(false),
need_group_pool(false), need_datastore_pool(false),
need_cluster_pool(false), need_document_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), need_aclm(false), need_imagem(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_template_pool;
bool need_group_pool;
bool need_datastore_pool;
bool need_cluster_pool;
bool need_document_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;
bool need_aclm;
bool need_imagem;
static NebulaTest * instance()
{
return the_tester;
};
// ------------------------------------------------------------------------
// Pools
// ------------------------------------------------------------------------
virtual VirtualMachinePool* create_vmpool(SqlDB* db,
string hook_location, string vloc);
virtual HostPool* create_hpool(SqlDB* db, string hook_location, string vloc);
virtual VirtualNetworkPool* create_vnpool(SqlDB* db,
string mac_prefix,
int size);
virtual UserPool* create_upool(SqlDB* db);
virtual ImagePool* create_ipool( SqlDB* db,
string default_image_type,
string default_device_prefix);
virtual VMTemplatePool* create_tpool(SqlDB* db);
virtual GroupPool* create_gpool(SqlDB* db);
virtual DatastorePool* create_dspool(SqlDB* db);
virtual ClusterPool* create_clpool(SqlDB* db);
virtual DocumentPool* create_docpool(SqlDB* db);
// ------------------------------------------------------------------------
// 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(string log_file);
virtual HookManager* create_hm(VirtualMachinePool * vmpool);
virtual AuthManager* create_authm(time_t timer_period);
virtual AclManager* create_aclm(SqlDB* db);
virtual ImageManager* create_imagem(ImagePool * ipool);
};
#endif /*NEBULA_TEST_H_*/

View File

@ -1,244 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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;
/* ************************************************************************* */
/* ************************************************************************* */
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",db_name);
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 set_one_auth(string path = "../../test/one_auth")
{
// The UserPool constructor checks if the DB contains at least
// one user, and adds one automatically from the ONE_AUTH file.
// So the ONE_AUTH environment is forced to point to a test one_auth
// file.
ostringstream oss;
oss << getenv("PWD") << "/" << path;
setenv("ONE_AUTH", oss.str().c_str(), 1);
}
// *****************************************************************************
// *****************************************************************************
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"
" -x --xml Create xml output files, for Hudson\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;
bool xml_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'},
{ "xml", 0, NULL, 'x'}
};
int c;
while ((c = getopt_long (argc, argv, "smlhx", long_opt, NULL)) != -1)
switch (c)
{
case 'm':
sqlite_flag = false;
break;
case 'l':
log_flag = true;
break;
case 'x':
xml_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");
// Set the opennebula install location to be the current dir.
// This will prevent some of the tests from writing the individual
// VM log files in an existing OpenNebula installation
setenv("ONE_LOCATION", ".", 1);
CppUnit::TextUi::TestRunner runner;
ofstream outputFile;
if( xml_flag )
{
outputFile.open(xml_name.c_str());
CppUnit::XmlOutputter* outputter =
new CppUnit::XmlOutputter(&runner.result(), outputFile);
runner.setOutputter(outputter);
}
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();
if( xml_flag )
{
outputFile.close();
}
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

@ -1,260 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 POOL_TEST_H_
#define POOL_TEST_H_
#include <string>
#include "PoolSQL.h"
#include "Nebula.h"
#include "OneUnitTest.h"
// Use this macro in sub-classes to add all the tests defined here
#define ALL_POOLTEST_CPPUNIT_TESTS() \
CPPUNIT_TEST (oid_assignment); \
CPPUNIT_TEST (get_from_cache); \
CPPUNIT_TEST (get_from_db); \
CPPUNIT_TEST (wrong_get); \
CPPUNIT_TEST (drop_and_get); \
using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
class PoolTest : public OneUnitTest
{
protected:
PoolSQL * pool;
PoolObjectSQL * obj;
/*
* Bootstrap the DB with the neccessary tables for the test
*/
virtual void bootstrap(SqlDB* db) = 0;
/*
* Create the appropiate pool
*/
virtual PoolSQL* create_pool(SqlDB* db) = 0;
/*
* Allocate the indexth sample pool object
*/
virtual int allocate(int index) = 0;
/*
* Check if the indexth sample object is equal to this one
*/
virtual void check(int index, PoolObjectSQL* obj) = 0;
PoolTest():pool(0){};
virtual ~PoolTest(){};
/**
* Replaces all <REGTIME> elements, padding them with 0
*/
string fix_regtimes(string& xml)
{
return fix_time(xml, "REGTIME");
}
string fix_stimes(string& xml)
{
return fix_time(xml, "STIME");
}
string fix_time(string& xml, string elem_name)
{
string start = "<" + elem_name + ">";
string replacement = "0000000000";
size_t pos = 0;
while( (pos = xml.find(start, pos)) != string::npos )
{
if ( xml[pos+start.size()] != '0' )
{
xml.replace( pos+start.size(), replacement.size(), replacement);
}
pos++;
}
return xml;
}
public:
void setUp()
{
create_db();
bootstrap(db);
pool = create_pool(db);
};
void tearDown()
{
delete_db();
if ( pool != 0 )
{
delete pool;
}
};
// *****************************************************************************
void oid_assignment()
{
int oid;
oid = allocate(0);
// first element in the pool should have oid=0
CPPUNIT_ASSERT(oid == 0);
oid = allocate(1);
// second element in the pool should have oid=1
CPPUNIT_ASSERT(oid == 1);
}
// Try to allocate two objects, and retrieve them
void get_from_cache()
{
int oid_0, oid_1;
// Allocate two objects
oid_0 = allocate(0);
oid_1 = allocate(1);
CPPUNIT_ASSERT(oid_0 != -1);
CPPUNIT_ASSERT(oid_1 != -1);
// ---------------------------------
// Get first object and check its integrity
obj = pool->get(oid_0, false);
check(0, obj);
// Same for the second, but ask it to be locked
obj = pool->get(oid_1, true);
if(obj != 0)
{
obj->unlock();
}
check(1, obj);
};
// Try to allocate two objects, and retrieve them
void get_from_db()
{
int oid_0, oid_1;
// Allocate two objects
oid_0 = allocate(0);
oid_1 = allocate(1);
CPPUNIT_ASSERT(oid_0 != -1);
CPPUNIT_ASSERT(oid_1 != -1);
// Clean the cache, forcing the pool to read the objects from the DB
pool->clean();
// ---------------------------------
// Get first object and check its integrity
obj = pool->get(oid_0, false);
check(0, obj);
// Same for the second one, but ask it to be locked
obj = pool->get(oid_1, true);
if(obj != 0)
{
obj->unlock();
}
check(1, obj);
};
void wrong_get()
{
// The pool is empty
// Non existing oid
obj = pool->get(13, false);
CPPUNIT_ASSERT( obj == 0 );
// Allocate an object
allocate(0);
// Ask again for a non-existing oid
obj = pool->get(213, false);
CPPUNIT_ASSERT( obj == 0 );
}
void drop_and_get()
{
int oid_0, oid_1;
string error_str;
// Allocate two objects
oid_0 = allocate(0);
oid_1 = allocate(1);
CPPUNIT_ASSERT(oid_0 != -1);
CPPUNIT_ASSERT(oid_1 != -1);
// Get the first object
obj = pool->get(oid_0, true);
if(obj != 0)
{
obj->unlock();
}
CPPUNIT_ASSERT(obj != 0);
obj->lock();
// Delete it
pool->drop(obj, error_str);
if(obj != 0)
{
obj->unlock();
}
// It should be gone now
obj = pool->get(oid_0, false);
CPPUNIT_ASSERT(obj == 0);
// The cache is cleaned, the object should be also gone from the DB
pool->clean();
obj = pool->get(oid_0, true);
CPPUNIT_ASSERT(obj == 0);
// But the other object must be accessible
obj = pool->get(oid_1, false);
check(1, obj);
};
};
// -----------------------------------------------------------------------------
#endif // POOL_TEST_H_

View File

@ -1,129 +0,0 @@
#!/bin/bash
#-------------------------------------------------------------------------------
# DEFINE THE TESTS
#-------------------------------------------------------------------------------
TWD_DIR="../../src"
BASE_DIR=$PWD
TESTS="$TWD_DIR/vnm/test \
$TWD_DIR/xml/test \
$TWD_DIR/scheduler/src/pool/test \
$TWD_DIR/common/test \
$TWD_DIR/host/test \
$TWD_DIR/template/test \
$TWD_DIR/image/test \
$TWD_DIR/authm/test \
$TWD_DIR/vm/test \
$TWD_DIR/um/test \
$TWD_DIR/lcm/test \
$TWD_DIR/pool/test \
$TWD_DIR/vm_template/test \
$TWD_DIR/group/test"
#-------------------------------------------------------------------------------
# COMMAND LINE PARSING
#-------------------------------------------------------------------------------
usage() {
echo
echo "Usage: do_test.sh [-smvgxclh]"
echo
echo "-m: use MyQSL backend (defaults to Sqlite)"
echo "-v: run tests using valgrind (memcheck) output will be memgrind.out"
echo "-g: run tests using valgrind (callgrind) output will be callgrind.out"
echo "-l: keep logs"
echo "-x: create xml output files, for Hudson"
echo "-c: clear output files from previous executions"
echo
echo "-h: prints this help"
}
#-------------------------------------------------------------------------------
TEMP_OPT=`getopt -o mvgclbhx -n 'install.sh' -- "$@"`
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- "$TEMP_OPT"
MYSQL="no"
VAL_MEM="no"
VAL_CALL="no"
LOGS="no"
XMLS="no"
CLEAR="no"
while true ; do
case "$1" in
-h) usage; exit 0;;
-m) MYSQL="yes" ; shift ;;
-v) VAL_MEM="yes" ; shift ;;
-g) VAL_CALL="yes"; shift ;;
-l) LOGS="yes" ; shift ;;
-x) XMLS="yes" ; shift ;;
-c) CLEAR="yes" ; shift ;;
--) shift ; break ;;
*) usage; exit 1 ;;
esac
done
#-------------------------------------------------------------------------------
# SETUP ARGUMENTS
#-------------------------------------------------------------------------------
if [ "$MYSQL" = "yes" ] ; then
TEST_ARGS="-m"
else
TEST_ARGS="-s"
fi
if [ "$LOGS" = "yes" ] ; then
TEST_ARGS="$TEST_ARGS -l"
fi
if [ "$XMLS" = "yes" ] ; then
TEST_ARGS="$TEST_ARGS -x"
fi
CALLER=""
if [ "$VAL_MEM" = "yes" ] ; then
CALLER="valgrind --show-reachable=yes --leak-check=full"
elif [ "$VAL_CALL" = "yes" ] ; then
CALLER="valgrind --tool=callgrind"
fi
for i in $TESTS ; do
cd $BASE_DIR
echo ; echo
echo "#####################################################################"
echo "#####################################################################"
echo "Doing $i ..."
echo "#####################################################################"
echo "#####################################################################"
echo ; echo
cd $i
if [ "$CLEAR" = "yes" ] ; then
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"
echo "---------------------------------------------------------------------"
$CALLER ./$j $TEST_ARGS
echo "---------------------------------------------------------------------"
fi
done
fi
done
cd $BASE_DIR
exit 0

View File

@ -1,374 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include "Nebula.h"
#include "NebulaTest.h"
#include "test/OneUnitTest.h"
#include "AuthManager.h"
#include "Template.h"
#include "NebulaLog.h"
#include "PoolObjectAuth.h"
#include <openssl/evp.h>
#include <openssl/bio.h>
using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
class NebulaTestAuth: public NebulaTest
{
public:
NebulaTestAuth():NebulaTest()
{
NebulaTest::the_tester = this;
need_authm = true;
need_aclm = true;
};
AuthManager* create_authm(time_t timer_period)
{
ostringstream oss;
vector<const Attribute *> am_mads;
char *error = 0;
oss << "AUTH_MAD = [ executable=\"/" << getenv("PWD")
<< "/dummy\"]" << endl;
Template * t = new Template();
t->parse(oss.str(),&error);
t->get("AUTH_MAD", am_mads);
return new AuthManager(1,am_mads);
};
};
/* ************************************************************************* */
/* ************************************************************************* */
class AuthManagerTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (AuthManagerTest);
CPPUNIT_TEST (timeout);
CPPUNIT_TEST (authenticate);
CPPUNIT_TEST (authorize);
CPPUNIT_TEST (self_authorize);
CPPUNIT_TEST (self_authenticate);
CPPUNIT_TEST_SUITE_END ();
private:
NebulaTestAuth * tester;
AuthManager * am;
public:
AuthManagerTest()
{
xmlInitParser();
};
~AuthManagerTest()
{
xmlCleanupParser();
// OpenSSL internal tables are allocated when an application starts up.
// Since such tables do not grow in size over time they are harmless.
EVP_cleanup();
CRYPTO_cleanup_all_ex_data();
};
/* ********************************************************************* */
/* ********************************************************************* */
void setUp()
{
create_db();
tester = new NebulaTestAuth();
Nebula& neb = Nebula::instance();
neb.start();
am = neb.get_authm();
};
void tearDown()
{
// -----------------------------------------------------------
// Stop the managers & free resources
// -----------------------------------------------------------
am->trigger(AuthManager::FINALIZE,0);
pthread_join(am->get_thread_id(),0);
//XML Library
xmlCleanupParser();
delete_db();
delete tester;
};
/* ********************************************************************* */
/* ********************************************************************* */
//This test needs a driver that takes more than 90 secs to AUTHENTICATE
void timeout()
{
AuthRequest ar(2, 2);
ar.add_authenticate("test","timeout","the_pass","the_secret");
am->trigger(AuthManager::AUTHENTICATE,&ar);
ar.wait();
CPPUNIT_ASSERT(ar.result==false);
CPPUNIT_ASSERT(ar.timeout==true);
}
void authenticate()
{
AuthRequest ar(2, 2);
ar.add_authenticate("test","the_user","the_pass","the_secret");
am->trigger(AuthManager::AUTHENTICATE,&ar);
ar.wait();
CPPUNIT_ASSERT(ar.result==true);
}
void authorize()
{
AuthRequest ar(2, 2);
//OBJECT:OBJECT_ID:ACTION:OWNER:PUBLIC:CORE_RESULT
string astr = "VM:VGhpcyBpcyBhIHRlbXBsYXRlCg==:CREATE:2:0 "
"IMAGE:2:USE:3:0 "
"NET:4:MANAGE:5:0 "
"HOST:6:MANAGE:7:0 "
"0";
PoolObjectAuth perm;
ar.add_create_auth(PoolObjectSQL::VM, "This is a template\n");
perm.oid = 2;
perm.gid = 0;
perm.uid = 3;
perm.obj_type = PoolObjectSQL::IMAGE;
ar.add_auth(AuthRequest::USE,perm);
perm.oid = 4;
perm.gid = 0;
perm.uid = 5;
perm.obj_type = PoolObjectSQL::NET;
ar.add_auth(AuthRequest::MANAGE,perm);
perm.oid = 6;
perm.gid = 0;
perm.uid = 7;
perm.obj_type = PoolObjectSQL::HOST;
ar.add_auth(AuthRequest::MANAGE,perm);
am->trigger(AuthManager::AUTHORIZE,&ar);
ar.wait();
//*
if ( ar.result != false )
{
cout << endl << "ar.result: " << ar.result << endl;
}
if ( ar.message.find(astr) == ar.message.npos )
{
cout << endl << "ar.message: " << ar.message;
cout << endl << "expected: " << astr << endl;
}
//*/
CPPUNIT_ASSERT(ar.result==false);
CPPUNIT_ASSERT(ar.message.find(astr) != ar.message.npos);
AuthRequest ar1(2, 2);
string astr1= "VM:VGhpcyBpcyBhIHRlbXBsYXRlCg==:CREATE:2:0 0";
ar1.add_create_auth(PoolObjectSQL::VM, "This is a template\n");
am->trigger(AuthManager::AUTHORIZE,&ar1);
ar1.wait();
//*
if ( ar1.result != false )
{
cout << endl << "ar.result: " << ar1.result << endl;
}
if ( ar1.message.find(astr1) == ar1.message.npos )
{
cout << endl << "ar.message: " << ar1.message;
cout << endl << "expected: " << astr1 << endl;
}
//*/
CPPUNIT_ASSERT(ar1.result==false);
CPPUNIT_ASSERT(ar1.message.find(astr1) != ar1.message.npos);
AuthRequest ar2(2, 2);
string astr2= "Empty authorization string";
am->trigger(AuthManager::AUTHORIZE,&ar2);
ar2.wait();
//*
if ( ar2.result != false )
{
cout << endl << "ar2.result: " << ar2.result << endl;
}
if ( ar2.message != astr2 )
{
cout << endl << "ar2.message: " << ar2.message;
cout << endl << "expected: " << astr2 << endl;
}
//*/
CPPUNIT_ASSERT(ar2.result==false);
CPPUNIT_ASSERT(ar2.message==astr2);
}
void self_authorize()
{
// Make all users belong to the USERS (1) group
AuthRequest ar(2, 1);
AuthRequest ar1(2, 1);
AuthRequest ar2(3, 1);
AuthRequest ar3(4, 1);
AuthRequest ar4(2, 1);
AuthRequest ar5(0, 1);
AuthRequest ar6(0, 1);
PoolObjectAuth perm;
ar.add_create_auth(PoolObjectSQL::VM,"dGhpcy");
perm.oid = 2;
perm.gid = 1;
perm.uid = 2;
perm.obj_type = PoolObjectSQL::NET;
ar.add_auth(AuthRequest::USE,perm);
perm.oid = 3;
perm.gid = 1;
perm.uid = 4;
perm.group_u = 1;
perm.obj_type = PoolObjectSQL::IMAGE;
ar.add_auth(AuthRequest::USE,perm);
CPPUNIT_ASSERT(ar.core_authorize() == true);
perm = PoolObjectAuth();
ar1.add_create_auth(PoolObjectSQL::VM,"dGhpcy");
perm.oid = 2;
perm.gid = 1;
perm.uid = 2;
perm.obj_type = PoolObjectSQL::NET;
ar1.add_auth(AuthRequest::USE,perm);
perm.oid = 3;
perm.gid = 1;
perm.uid = 4;
perm.obj_type = PoolObjectSQL::IMAGE;
ar1.add_auth(AuthRequest::USE,perm);
CPPUNIT_ASSERT(ar1.core_authorize() == false);
ar2.add_create_auth(PoolObjectSQL::HOST,"");
CPPUNIT_ASSERT(ar2.core_authorize() == false);
perm.oid = 5;
perm.gid = 1;
perm.uid = 2;
perm.obj_type = PoolObjectSQL::VM;
ar3.add_auth(AuthRequest::MANAGE,perm);
CPPUNIT_ASSERT(ar3.core_authorize() == false);
perm.oid = 4;
perm.gid = 1;
perm.uid = 2;
perm.obj_type = PoolObjectSQL::VM;
ar4.add_auth(AuthRequest::MANAGE,perm);
CPPUNIT_ASSERT(ar4.core_authorize() == true);
perm.oid = 4;
perm.gid = -1;
perm.uid = 0;
perm.obj_type = PoolObjectSQL::HOST;
ar5.add_auth(AuthRequest::MANAGE,perm);
CPPUNIT_ASSERT(ar5.core_authorize() == true);
ar6.add_create_auth(PoolObjectSQL::HOST,"");
CPPUNIT_ASSERT(ar6.core_authorize() == true);
}
void self_authenticate()
{
AuthRequest ar(2, 2);
AuthRequest ar1(2,2);
ar.add_authenticate("core","the_user","the_pass","the_secret");
CPPUNIT_ASSERT(ar.core_authenticate() == false);
ar1.add_authenticate("core","the_user","e2e509d8358df1d5fa3bc825173f93904baa4906", "the_pass");
CPPUNIT_ASSERT(ar1.core_authenticate() == true);
}
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, AuthManagerTest::suite());
}

View File

@ -1,50 +0,0 @@
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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_vmm',
'nebula_lcm',
'nebula_im',
'nebula_hm',
'nebula_rm',
'nebula_datastore',
'nebula_dm',
'nebula_tm',
'nebula_um',
'nebula_authm',
'nebula_group',
'nebula_acl',
'nebula_mad',
'nebula_template',
'nebula_image',
'nebula_pool',
'nebula_cluster',
'nebula_host',
'nebula_vnm',
'nebula_vm',
'nebula_vmtemplate',
'nebula_common',
'nebula_sql',
'nebula_log',
'nebula_xml',
'crypto'
])
nt = env.Object('NebulaTemplate.o','../../nebula/NebulaTemplate.cc')
env.Program('test',[nt,'AuthManagerTest.cc'])

View File

@ -1,49 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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" 1>&2 >> mad.log
while read COMMAND ARG1 ARG2 ARG3 ARG4 ARG5
do
echo "$COMMAND $ARG1 $ARG2 $ARG3 $ARG4 $ARG5" 1>&2 >> mad.log
case $COMMAND in
"INIT")
echo "INIT SUCCESS"
;;
"FINALIZE")
echo "FINALIZE SUCCESS"
exit 0
;;
"AUTHORIZE")
echo "AUTHORIZE FAILURE $ARG1 $ARG3 $ARG4 $ARG5"
;;
"AUTHENTICATE")
date 1>&2 >> mad.log
if [ "$ARG4" = "timeout" ] ; then
sleep 95
fi
date 1>&2 >> mad.log
echo "AUTHENTICATE SUCCESS $ARG1"
;;
*)
echo "$COMMAND - FAILURE Unknown command"
;;
esac
done

View File

@ -1,27 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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_common',
'nebula_log',
])
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,182 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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>
using namespace std;
extern "C" void * addsub_loop(void *arg);
class AddSub : public ActionListener
{
public:
AddSub(int i):am(),counter(i)
{
am.addListener(this);
};
~AddSub(){};
void add(int i)
{
int * p;
p = new int(i);
am.trigger("ADD",(void *) p);
}
void sub(int i)
{
int * p;
p = new int(i);
am.trigger("SUB",(void *) p);
}
int value()
{
return counter;
}
pthread_t id()
{
return pid;
}
void start()
{
pthread_attr_t pattr;
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
pthread_create(&pid,&pattr,addsub_loop,(void *) this);
}
void end()
{
am.trigger(ActionListener::ACTION_FINALIZE,0);
}
private:
ActionManager am;
int counter;
pthread_t pid;
friend void * addsub_loop(void *arg);
void do_action(const string &action, void * arg)
{
int * i = static_cast<int *>(arg);
if ( i == 0 )
{
return;
}
else if ( action == "ADD" )
{
counter = counter + *i;
}
else if ( action == "SUB" )
{
counter = counter - *i;
}
delete i;
}
};
extern "C" void * addsub_loop(void *arg)
{
AddSub *as;
as = static_cast<AddSub *>(arg);
as->am.loop(0,0);
return 0;
};
class ActionManagerTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (ActionManagerTest);
CPPUNIT_TEST (test_add);
CPPUNIT_TEST (test_sub);
CPPUNIT_TEST_SUITE_END ();
private:
AddSub *as;
public:
void setUp()
{
as = new AddSub(10);
as->start();
}
void tearDown()
{
delete as;
}
void test_add()
{
as->add(23);
as->add(5);
sleep(1);
CPPUNIT_ASSERT(as->value() == 38);
as->end();
pthread_join(as->id(),0);
CPPUNIT_ASSERT(as->value() == 38);
}
void test_sub()
{
as->sub(3);
as->sub(15);
sleep(1);
CPPUNIT_ASSERT(as->value() == -8);
as->end();
pthread_join(as->id(),0);
CPPUNIT_ASSERT(as->value() == -8);
}
};
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, ActionManagerTest::suite(),
"action_manager.xml");
}

View File

@ -1,102 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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. */
/* -------------------------------------------------------------------------- */
extern "C"
{
#include "mem_collector.h"
}
#include <string.h>
#include "test/OneUnitTest.h"
using namespace std;
class MemCollectorTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (MemCollectorTest);
CPPUNIT_TEST (test_all_free);
CPPUNIT_TEST (test_realloc);
CPPUNIT_TEST_SUITE_END ();
public:
void setUp()
{
}
void tearDown()
{
}
void test_all_free()
{
mem_collector mc;
mem_collector_init(&mc);
char * st1 = mem_collector_strdup(&mc,"HOLA");
char * st2 = mem_collector_strdup(&mc,"ADIOS");
char * st3 = mem_collector_strdup(&mc,"HELLO");
char * st4 = mem_collector_strdup(&mc,"BYE");
CPPUNIT_ASSERT(strcmp(mc.str_buffer[0],"HOLA")==0);
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);
CPPUNIT_ASSERT(strcmp(st3,"HELLO")==0);
CPPUNIT_ASSERT(strcmp(st4,"BYE")==0);
mem_collector_cleanup(&mc);
CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK);
}
void test_realloc()
{
mem_collector mc;
int max_size;
max_size = (MEM_COLLECTOR_CHUNK * 3) + 5;
mem_collector_init(&mc);
for (int i=0; i < max_size ; i++)
{
mem_collector_strdup(&mc,"HOLA");
}
for (int i=0; i < max_size ; i++)
{
CPPUNIT_ASSERT(strcmp(mc.str_buffer[i],"HOLA")==0);
}
mem_collector_cleanup(&mc);
CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK * 4);
}
};
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, MemCollectorTest::suite(),
"mem_collector.xml");
}

View File

@ -1,120 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 "test/OneUnitTest.h"
using namespace std;
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()
{
string a_name = "single_a";
string b_name = "single_b";
string b_value= "value_b";
a = new SingleAttribute(a_name);
b = new SingleAttribute(b_name, b_value);
}
void tearDown()
{
delete a;
delete b;
}
void test_type()
{
CPPUNIT_ASSERT(a->type() == Attribute::SIMPLE);
CPPUNIT_ASSERT(b->type() == Attribute::SIMPLE);
}
void test_name()
{
CPPUNIT_ASSERT(a->name() == "SINGLE_A");
CPPUNIT_ASSERT(b->name() == "SINGLE_B");
}
void test_value()
{
CPPUNIT_ASSERT(a->value().empty() == true);
CPPUNIT_ASSERT(b->value() == "value_b");
}
void test_marshall()
{
string *am, *bm;
am = a->marshall();
bm = b->marshall();
CPPUNIT_ASSERT(am->empty() == true);
CPPUNIT_ASSERT(*bm == "value_b");
delete am;
delete bm;
}
void test_xml()
{
string *am, *bm;
am = a->to_xml();
bm = b->to_xml();
CPPUNIT_ASSERT(*am == "<SINGLE_A><![CDATA[]]></SINGLE_A>");
CPPUNIT_ASSERT(*bm == "<SINGLE_B><![CDATA[value_b]]></SINGLE_B>");
delete am;
delete bm;
}
void test_replace()
{
string nv = "new_value_b";
b->replace(nv);
CPPUNIT_ASSERT(b->value() == "new_value_b");
}
};
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, SingleAttributeTest::suite(),
"single_attribute.xml");
}

View File

@ -1,150 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 "test/OneUnitTest.h"
using namespace std;
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;
public:
void setUp()
{
string a_name = "vector_a";
string b_name = "vector_b";
b_value.insert(make_pair("attr1","val1"));
b_value.insert(make_pair("attr2","val2"));
b_value.insert(make_pair("attr3","val3"));
a = new VectorAttribute(a_name);
b = new VectorAttribute(b_name, b_value);
}
void tearDown()
{
delete a;
delete b;
}
void test_type()
{
CPPUNIT_ASSERT(a->type() == Attribute::VECTOR);
CPPUNIT_ASSERT(b->type() == Attribute::VECTOR);
}
void test_name()
{
CPPUNIT_ASSERT(a->name() == "VECTOR_A");
CPPUNIT_ASSERT(b->name() == "VECTOR_B");
}
void test_value()
{
CPPUNIT_ASSERT(a->value().empty() == true);
CPPUNIT_ASSERT(b->value() == b_value);
CPPUNIT_ASSERT(a->vector_value("NAME").empty() == true);
CPPUNIT_ASSERT(b->vector_value("NAME").empty() == true);
CPPUNIT_ASSERT(b->vector_value("attr1") == "val1");
CPPUNIT_ASSERT(b->vector_value("attr2") == "val2");
CPPUNIT_ASSERT(b->vector_value("attr3") == "val3");
}
void test_marshall()
{
string *am, *bm;
am = a->marshall();
bm = b->marshall();
CPPUNIT_ASSERT(am == 0);
CPPUNIT_ASSERT(*bm == "attr1=val1@^_^@attr2=val2@^_^@attr3=val3");
VectorAttribute c("vector_c");
c.unmarshall(*bm);
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;
}
void test_xml()
{
string *am, *bm;
am = a->to_xml();
bm = b->to_xml();
CPPUNIT_ASSERT(*am == "<VECTOR_A></VECTOR_A>");
CPPUNIT_ASSERT(*bm == "<VECTOR_B><attr1><![CDATA[val1]]></attr1><attr2>"
"<![CDATA[val2]]></attr2><attr3><![CDATA[val3]]>"
"</attr3></VECTOR_B>");
delete am;
delete bm;
}
void test_replace()
{
map<string,string> nm;
string nv = "new_val1";
b->replace("attr1",nv);
CPPUNIT_ASSERT(b->vector_value("attr1") == "new_val1");
nm.insert(make_pair("other_attr1","other_val1"));
nm.insert(make_pair("other_attr2","other_val2"));
b->replace(nm);
CPPUNIT_ASSERT(b->vector_value("other_attr1") == "other_val1");
CPPUNIT_ASSERT(b->vector_value("other_attr2") == "other_val2");
CPPUNIT_ASSERT(b->vector_value("attr3").empty() == true);
CPPUNIT_ASSERT(b->value() == nm);
}
};
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, VectorAttributeTest::suite(),
"vector_attribute.xml");
}

View File

@ -1,230 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include "GroupPool.h"
#include "PoolTest.h"
using namespace std;
const string names[] = {"First name", "Second name"};
/* ************************************************************************* */
/* ************************************************************************* */
#include "NebulaTest.h"
class NebulaTestGroup: public NebulaTest
{
public:
NebulaTestGroup():NebulaTest()
{
NebulaTest::the_tester = this;
need_group_pool= true;
}
};
class GroupPoolTest : public PoolTest
{
CPPUNIT_TEST_SUITE (GroupPoolTest);
// Not all tests from PoolTest can be used. Because
// of the initial default groups added to the DB, the
// oid_assignment would fail.
CPPUNIT_TEST (get_from_cache);
CPPUNIT_TEST (get_from_db);
CPPUNIT_TEST (wrong_get);
CPPUNIT_TEST (drop_and_get);
CPPUNIT_TEST (duplicates);
CPPUNIT_TEST (name_index);
CPPUNIT_TEST_SUITE_END ();
protected:
NebulaTestGroup * tester;
GroupPool * gpool;
void bootstrap(SqlDB* db)
{
// setUp overwritten
};
PoolSQL* create_pool(SqlDB* db)
{
// setUp overwritten
return gpool;
};
int allocate(int index)
{
int oid;
string err;
return gpool->allocate(names[index], &oid, err);
};
void check(int index, PoolObjectSQL* obj)
{
Group * group = static_cast<Group *>(obj);
CPPUNIT_ASSERT( obj != 0 );
string name = group->get_name();
CPPUNIT_ASSERT( name == names[index] );
};
private:
public:
GroupPoolTest()
{
xmlInitParser();
};
~GroupPoolTest()
{
xmlCleanupParser();
};
void setUp()
{
create_db();
tester = new NebulaTestGroup();
Nebula& neb = Nebula::instance();
neb.start();
gpool = neb.get_gpool();
pool = gpool;
};
void tearDown()
{
delete_db();
delete tester;
};
/* ********************************************************************* */
/* ********************************************************************* */
void duplicates()
{
int rc, oid;
string err;
GroupPool * gpool = static_cast<GroupPool*>(pool);
// Allocate a group
rc = gpool->allocate(names[0], &oid, err);
CPPUNIT_ASSERT( oid == 100 );
CPPUNIT_ASSERT( oid == rc );
// Try to allocate twice the same group, should fail
rc = gpool->allocate(names[0], &oid, err);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == rc );
// Try again, this time with different uid. Should fail, groups can't
// repeat names
rc = gpool->allocate(names[0], &oid, err);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == rc );
}
/* ********************************************************************* */
void name_index()
{
Group *group_oid, *group_name;
int oid_0;
//int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
group_oid = gpool->get(oid_0, true);
CPPUNIT_ASSERT(group_oid != 0);
name_0 = group_oid->get_name();
//uid_0 = group_oid->get_uid();
group_oid->unlock();
// Get by name and check it is the same object
group_name = gpool->get(name_0, true);
CPPUNIT_ASSERT(group_name != 0);
group_name->unlock();
CPPUNIT_ASSERT(group_oid == group_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
gpool->clean();
// Get by oid
group_oid = gpool->get(oid_0, true);
CPPUNIT_ASSERT(group_oid != 0);
group_oid->unlock();
// Get by name and check it is the same object
group_name = gpool->get(name_0, true);
CPPUNIT_ASSERT(group_name != 0);
group_name->unlock();
CPPUNIT_ASSERT(group_oid == group_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
gpool->clean();
// Get by name
group_name = gpool->get(name_0, true);
CPPUNIT_ASSERT(group_name != 0);
group_name->unlock();
// Get by oid and check it is the same object
group_oid = gpool->get(oid_0, true);
CPPUNIT_ASSERT(group_oid != 0);
group_oid->unlock();
CPPUNIT_ASSERT(group_oid == group_name);
}
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return PoolTest::main(argc, argv, GroupPoolTest::suite());
}

View File

@ -1,49 +0,0 @@
# --------------------------------------------------------------------------
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
#
# 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_vmm',
'nebula_lcm',
'nebula_im',
'nebula_hm',
'nebula_rm',
'nebula_datastore',
'nebula_dm',
'nebula_tm',
'nebula_um',
'nebula_group',
'nebula_authm',
'nebula_acl',
'nebula_mad',
'nebula_template',
'nebula_image',
'nebula_pool',
'nebula_cluster',
'nebula_host',
'nebula_vnm',
'nebula_vm',
'nebula_vmtemplate',
'nebula_common',
'nebula_sql',
'nebula_log',
'nebula_xml',
'crypto'
])
env.Program('test','GroupPoolTest.cc')

View File

@ -1,229 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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",
"vnm_mad",
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
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",
"vnm_mad",
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
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",
"vnm_mad",
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
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",
"vnm_mad",
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
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)
{
OneUnitTest::set_one_auth();
return OneUnitTest::main(argc, argv, HostHookTest::suite(),"host_hook.xml");
}

View File

@ -1,408 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include "HostPool.h"
#include "PoolTest.h"
using namespace std;
const string im_mads[] = {"im_mad_one", "im_mad_2", "im_mad_3"};
const string im_mad = im_mads[0];
const string vmm_mad = "vmm_mad";
const string vnm_mad = "vnm_mad";
const string names[] = {"Host one", "Second host"};
/* ************************************************************************* */
/* ************************************************************************* */
class HostPoolTest : public PoolTest
{
CPPUNIT_TEST_SUITE (HostPoolTest);
ALL_POOLTEST_CPPUNIT_TESTS();
CPPUNIT_TEST (update);
CPPUNIT_TEST (discover);
CPPUNIT_TEST (duplicates);
CPPUNIT_TEST (name_index);
// CPPUNIT_TEST (scale_test);
CPPUNIT_TEST_SUITE_END ();
protected:
void bootstrap(SqlDB* db)
{
HostPool::bootstrap(db);
};
PoolSQL* create_pool(SqlDB* db)
{
vector<const Attribute *> hook;
return new HostPool(db,hook,"./", "./", 0);
};
int allocate(int index)
{
int oid;
string err;
return ((HostPool*)pool)->allocate(&oid, names[index], im_mads[index],
vmm_mad, vnm_mad,
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,err);
};
void check(int index, PoolObjectSQL* obj)
{
string st;
CPPUNIT_ASSERT( obj != 0 );
Host * host = static_cast<Host *>(obj);
ObjectXML xml(host->to_xml(st));
CPPUNIT_ASSERT( host->get_name() == names[index] );
xml.xpath(st, "/HOST/IM_MAD", "-");
CPPUNIT_ASSERT( st == im_mads[index] );
};
public:
HostPoolTest(){xmlInitParser();};
~HostPoolTest(){xmlCleanupParser();};
/* ********************************************************************* */
/* ********************************************************************* */
void update()
{
HostPool * hp = static_cast<HostPool *>(pool);
int oid_1 = allocate(0);
Host* host = hp->get(oid_1, true);
CPPUNIT_ASSERT( host != 0 );
// Host object should be cached. Let's update its status
host->set_state(Host::DISABLED);
pool->update(host);
host->unlock();
host = hp->get(oid_1,false);
CPPUNIT_ASSERT( host != 0 );
CPPUNIT_ASSERT( host->get_state() == Host::DISABLED );
//Now force access to DB
pool->clean();
host = hp->get(oid_1,false);
CPPUNIT_ASSERT( host != 0 );
CPPUNIT_ASSERT( host->get_state() == Host::DISABLED );
};
/* ********************************************************************* */
void duplicates()
{
int rc, oid_0, oid_1;
HostPool * hp = static_cast<HostPool *>(pool);
Host * host;
string err;
string im_mad_2 = "another_im_mad";
// If we try to allocate two hosts with the same name and drivers,
// should fail
rc = hp->allocate(&oid_0,
names[0],
im_mad,
vmm_mad,
vnm_mad,
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
err);
CPPUNIT_ASSERT( oid_0 == 0 );
CPPUNIT_ASSERT( rc == oid_0 );
rc = hp->allocate(&oid_1,
names[0],
im_mad,
vmm_mad,
vnm_mad,
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
err);
CPPUNIT_ASSERT( oid_1 == -1 );
CPPUNIT_ASSERT( rc == oid_1 );
// the hostname cannot be repeated if the drivers change
rc = hp->allocate(&oid_1,
names[0],
im_mad_2,
vmm_mad,
vnm_mad,
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
err);
CPPUNIT_ASSERT( oid_1 == -1 );
CPPUNIT_ASSERT( rc == oid_1 );
// Get the hosts and check them
host = hp->get(oid_0, false);
CPPUNIT_ASSERT( host != 0 );
CPPUNIT_ASSERT( host->get_im_mad() == im_mad );
}
/* ********************************************************************* */
void discover()
{
int rc, oid, i;
map<int, string> dh;
map<int, string>::iterator it;
Host * host;
HostPool * hp = static_cast<HostPool *>(pool);
ostringstream oss;
string err;
for(i=0, oss.str(""); i<20; i++,oss.str(""))
{
oss << "host" << i;
hp->allocate(&oid,
oss.str(),
im_mad,
vmm_mad,
vnm_mad,
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
err);
CPPUNIT_ASSERT(oid == i);
if (i >=8 )
{
host = hp->get(oid, false);
CPPUNIT_ASSERT(host!=0);
host->disable();
hp->update(host);
}
}
// Discover the enabled hosts
rc = hp->discover(&dh,100);
CPPUNIT_ASSERT(rc == 0);
CPPUNIT_ASSERT(dh.size() == 8);
for(i=0,it=dh.begin(),oss.str("");it!=dh.end();it++,i++,oss.str(""))
{
CPPUNIT_ASSERT(it->first == i);
CPPUNIT_ASSERT(it->second == im_mad);
host = hp->get(i, false);
CPPUNIT_ASSERT(host!=0);
CPPUNIT_ASSERT(host->isEnabled());
}
}
/* ********************************************************************* */
void scale_test()
{
time_t the_time, the_time2;
int oid,i,j;
ostringstream oss,ossdump;
string err;
Host * host;
string monitor = "ARCH=x86_64 MODELNAME=\"Intel(R) Core(TM)2 Duo CPU P9300 @ 2.26GHz\" HYPERVISOR=kvm TOTALCPU=200 CPUSPEED=800 TOTALMEMORY=4005416 USEDMEMORY=2351928 FREEMEMORY=2826904 FREECPU=188.4 USEDCPU=11.599999999999994 NETRX=0 NETTX=0 HOSTNAME=pc-ruben";
cout << endl << "Allocate Test" << endl;
tearDown();
for (i=1000; i<30000 ; i = i + 5000)
{
setUp();
HostPool * hp = static_cast<HostPool *>(pool);
the_time = time(0);
for (j=0,oss.str(""); j<i ; j=j+1,oss.str(""))
{
oss << "host" << j;
hp->allocate(&oid,
oss.str(),
im_mad,
vmm_mad,
vnm_mad,
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
err);
}
the_time2 = time(0) - the_time;
hp->clean();
the_time = time(0);
hp->dump(ossdump, "");
cout <<"\t"<<i<<"\t"<<the_time2<<"\t"<<time(0)-the_time<< endl;
tearDown();
}
cout << endl << "Read Test" << endl;
setUp();
// Allocate a HostPool
setUp();
HostPool * hp = static_cast<HostPool *>(pool);
for (i=10000,oss.str(""); i<30000 ; i++,oss.str(""))
{
oss << "host" << i;
hp->allocate(&oid,
oss.str(),
im_mad,
vmm_mad,
vnm_mad,
ClusterPool::NONE_CLUSTER_ID,
ClusterPool::NONE_CLUSTER_NAME,
err);
host = hp->get(oid, false);
host->update_info(monitor);
hp->update(host);
}
//Load test
for (i=0; i<25000; i=i+5000)
{
hp->clean();
the_time = time(0);
for (j=0; j<i ; j++)
{
host = hp->get(j,true);
host->unlock();
}
cout << "\t" << i << "\t" << time(0) - the_time << endl;
}
}
/* ********************************************************************* */
void name_index()
{
HostPool * hp = static_cast<HostPool *>(pool);
Host *host_oid, *host_name;
int oid_0;
//int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
host_oid = hp->get(oid_0, true);
CPPUNIT_ASSERT(host_oid != 0);
name_0 = host_oid->get_name();
//uid_0 = host_oid->get_uid();
host_oid->unlock();
// Get by name and check it is the same object
host_name = hp->get(name_0, true);
CPPUNIT_ASSERT(host_name != 0);
host_name->unlock();
CPPUNIT_ASSERT(host_oid == host_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
hp->clean();
// Get by oid
host_oid = hp->get(oid_0, true);
CPPUNIT_ASSERT(host_oid != 0);
host_oid->unlock();
// Get by name and check it is the same object
host_name = hp->get(name_0, true);
CPPUNIT_ASSERT(host_name != 0);
host_name->unlock();
CPPUNIT_ASSERT(host_oid == host_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
hp->clean();
// Get by name
host_name = hp->get(name_0, true);
CPPUNIT_ASSERT(host_name != 0);
host_name->unlock();
// Get by oid and check it is the same object
host_oid = hp->get(oid_0, true);
CPPUNIT_ASSERT(host_oid != 0);
host_oid->unlock();
CPPUNIT_ASSERT(host_oid == host_name);
}
};
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return PoolTest::main(argc, argv, HostPoolTest::suite(), "host_pool.xml");
}

View File

@ -1,88 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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_group_pool = true;
need_vnet_pool = true;
need_image_pool= true;
need_hm = true;
}
~NebulaTestHost(){};
// -----------------------------------------------------------
// Pools
// -----------------------------------------------------------
HostPool* create_hpool(SqlDB* db, string hook_location, string var_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, var_location, 0);
}
};
#endif /*NEBULA_TEST_H_*/

View File

@ -1,52 +0,0 @@
# SConstruct for src/host/test
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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_cluster',
'nebula_host',
'nebula_core_test',
'nebula_vmm',
'nebula_lcm',
'nebula_im',
'nebula_hm',
'nebula_rm',
'nebula_datastore',
'nebula_dm',
'nebula_tm',
'nebula_um',
'nebula_group',
'nebula_authm',
'nebula_acl',
'nebula_mad',
'nebula_template',
'nebula_image',
'nebula_pool',
'nebula_vnm',
'nebula_vm',
'nebula_vmtemplate',
'nebula_common',
'nebula_sql',
'nebula_log',
'nebula_xml',
'crypto'
])
env.Program('test','HostPoolTest.cc')
env.Program('test_hook','HostHookTest.cc')

View File

@ -1,443 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include "ImagePool.h"
#include "PoolTest.h"
#include "ObjectXML.h"
using namespace std;
const int uids[] = {0,1,2};
const char* unames[] = {"one","two","three"};
const char* gnames[] = {"oneadmin","group_two","users"};
const string names[] = {"Image one", "Second Image", "The third image"};
const string paths[] = {"/tmp/image_test", "/tmp/image_second_test", "/tmp/image_3_test"};
const string templates[] =
{
"NAME = \"Image one\"\n"
"PATH = /tmp/image_test\n"
"PERSISTENT = YES\n"
"DESCRIPTION = \"This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.\"\n",
"NAME = \"Second Image\"\n"
"PATH = /tmp/image_second_test\n"
"DESCRIPTION = \"This is a rather short description.\"\n",
"NAME = \"The third image\"\n"
"PATH = /tmp/image_3_test\n"
"# DESCRIPTION = \"An image description\"\n"
"BUS = SCSI\n"
"PROFILE = STUDENT\n"
};
/* ************************************************************************* */
/* ************************************************************************* */
#include "NebulaTest.h"
class NebulaTestImage: public NebulaTest
{
public:
NebulaTestImage():NebulaTest()
{
NebulaTest::the_tester = this;
need_image_pool = true;
need_imagem = true;
need_datastore_pool = true;
}
};
class ImagePoolFriend : public ImagePool
{
public:
ImagePoolFriend(SqlDB * db,
const string& _default_type,
const string& _default_dev_prefix,
vector<const Attribute *> _restricted_attrs):
ImagePool( db,
_default_type,
_default_dev_prefix,
_restricted_attrs){};
int allocate(const int& uid, const std::string& stemplate, int* oid)
{
ImageTemplate * img_template;
char * error_msg = 0;
int rc;
string err;
img_template = new ImageTemplate;
rc = img_template->parse(stemplate,&error_msg);
if( rc == 0 )
{
string uname = unames[uid];
string gname = gnames[uid];
return ImagePool::allocate(uid, 1, uname, gname,
img_template, 0,"none", Image::FILE, "ds_data", -1, oid, err);
}
else
{
if (error_msg != 0 )
{
free(error_msg);
}
delete img_template;
return -2;
}
};
};
/* ************************************************************************* */
/* ************************************************************************* */
class ImagePoolTest : public PoolTest
{
CPPUNIT_TEST_SUITE (ImagePoolTest);
ALL_POOLTEST_CPPUNIT_TESTS();
CPPUNIT_TEST ( names_initialization );
CPPUNIT_TEST ( get_using_name );
CPPUNIT_TEST ( wrong_get_name );
CPPUNIT_TEST ( name_index );
CPPUNIT_TEST ( chown_name_index );
CPPUNIT_TEST_SUITE_END ();
protected:
NebulaTestImage * tester;
ImagePool * ipool;
ImageManager * imagem;
void bootstrap(SqlDB* db)
{
// setUp overwritten
};
PoolSQL* create_pool(SqlDB* db)
{
// setUp overwritten
return ipool;
};
int allocate(int index)
{
int oid;
return ((ImagePoolFriend*)pool)->allocate(uids[index],
templates[index],
&oid);
};
void check(int index, PoolObjectSQL* obj)
{
string st;
CPPUNIT_ASSERT( obj != 0 );
Image* img = static_cast<Image*>(obj);
ObjectXML xml(img->to_xml(st));
CPPUNIT_ASSERT( img->get_name() == names[index] );
xml.xpath(st, "/IMAGE/UNAME", "-");
CPPUNIT_ASSERT( st == unames[index] );
xml.xpath(st, "/IMAGE/GNAME", "-");
CPPUNIT_ASSERT( st == gnames[index] );
xml.xpath(st, "/IMAGE/PATH", "-");
CPPUNIT_ASSERT( st == paths[index] );
};
public:
ImagePoolTest(){xmlInitParser();};
~ImagePoolTest(){xmlCleanupParser();};
void setUp()
{
create_db();
tester = new NebulaTestImage();
Nebula& neb = Nebula::instance();
neb.start();
ipool = neb.get_ipool();
imagem = neb.get_imagem();
pool = ipool;
};
void tearDown()
{
// -----------------------------------------------------------
// Stop the managers & free resources
// -----------------------------------------------------------
imagem->finalize();
pthread_join(imagem->get_thread_id(),0);
//XML Library
xmlCleanupParser();
delete_db();
delete tester;
};
/* ********************************************************************* */
void names_initialization()
{
ImagePool * imp;
Image * img;
// Allocate 2 images, so they are written to the DB.
allocate(0);
allocate(2);
// Create a new pool, using the same DB. This new pool should read the
// allocated images.
vector<const Attribute *> restricted_attrs;
imp = new ImagePool(db,"OS", "hd", restricted_attrs);
img = imp->get(0, false);
CPPUNIT_ASSERT( img != 0 );
img = imp->get(2, false);
CPPUNIT_ASSERT( img == 0 );
img = imp->get(1, false);
CPPUNIT_ASSERT( img != 0 );
delete imp;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void get_using_name()
{
int oid_0, oid_1;
ImagePool * imp = static_cast<ImagePool *>(pool);
// Allocate two objects
oid_0 = allocate(0);
oid_1 = allocate(1);
// ---------------------------------
// Get first object and check its integrity
obj = pool->get(oid_0, false);
CPPUNIT_ASSERT( obj != 0 );
check(0, obj);
// Get using its name
obj = imp->get(names[1], uids[1], true);
CPPUNIT_ASSERT( obj != 0 );
obj->unlock();
check(1, obj);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
pool->clean();
// Get first object and check its integrity
obj = imp->get(names[0], uids[0], false);
check(0, obj);
// Get using its name
obj = imp->get(oid_1, false);
check(1, obj);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void wrong_get_name()
{
ImagePool * imp = static_cast<ImagePool *>(pool);
// The pool is empty
// Non existing name
obj = imp->get("Wrong name", 0, true);
CPPUNIT_ASSERT( obj == 0 );
// Allocate an object
allocate(0);
// Ask again for a non-existing name
obj = imp->get("Non existing name",uids[0], true);
CPPUNIT_ASSERT( obj == 0 );
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void name_index()
{
Image *img_oid, *img_name;
int oid_0;
int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
img_oid = ipool->get(oid_0, true);
CPPUNIT_ASSERT(img_oid != 0);
name_0 = img_oid->get_name();
uid_0 = img_oid->get_uid();
img_oid->unlock();
// Get by name and check it is the same object
img_name = ipool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
ipool->clean();
// Get by oid
img_oid = ipool->get(oid_0, true);
CPPUNIT_ASSERT(img_oid != 0);
img_oid->unlock();
// Get by name and check it is the same object
img_name = ipool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
ipool->clean();
// Get by name
img_name = ipool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
// Get by oid and check it is the same object
img_oid = ipool->get(oid_0, true);
CPPUNIT_ASSERT(img_oid != 0);
img_oid->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void chown_name_index()
{
Image *img_oid, *img_name;
int oid;
int old_uid;
int new_uid = 3456;
string name;
oid = allocate(0);
CPPUNIT_ASSERT(oid != -1);
// ---------------------------------
// Get by oid
img_oid = ipool->get(oid, true);
CPPUNIT_ASSERT(img_oid != 0);
name = img_oid->get_name();
old_uid = img_oid->get_uid();
// Change owner and update cache index
img_oid->set_user(new_uid, "new_username");
ipool->update(img_oid);
img_oid->unlock();
ipool->update_cache_index(name, old_uid, name, new_uid);
// Get by name, new_uid and check it is the same object
img_name = ipool->get(name, new_uid, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
// Get by name, old_uid and check it does not exist
img_name = ipool->get(name, old_uid, true);
CPPUNIT_ASSERT(img_name == 0);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
ipool->clean();
// Get by name, old_uid and check it does not exist
img_name = ipool->get(name, old_uid, true);
CPPUNIT_ASSERT(img_name == 0);
// Get by oid
img_oid = ipool->get(oid, true);
CPPUNIT_ASSERT(img_oid != 0);
img_oid->unlock();
// Get by name, new_uid and check it is the same object
img_name = ipool->get(name, new_uid, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
}
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return PoolTest::main(argc, argv, ImagePoolTest::suite());
}

View File

@ -1,50 +0,0 @@
# --------------------------------------------------------------------------
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
#
# 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_vmm',
'nebula_lcm',
'nebula_im',
'nebula_hm',
'nebula_rm',
'nebula_datastore',
'nebula_dm',
'nebula_tm',
'nebula_um',
'nebula_group',
'nebula_authm',
'nebula_acl',
'nebula_mad',
'nebula_template',
'nebula_image',
'nebula_pool',
'nebula_cluster',
'nebula_host',
'nebula_vnm',
'nebula_vm',
'nebula_vmtemplate',
'nebula_common',
'nebula_sql',
'nebula_log',
'nebula_xml',
'crypto'
])
env.Program('test','ImagePoolTest.cc')

View File

@ -1 +0,0 @@
one_user_test:password

View File

@ -1,111 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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, 5, _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

@ -1,68 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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_group_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_*/

View File

@ -1,51 +0,0 @@
# SConstruct for src/lcm/test
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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_vmm',
'nebula_lcm',
'nebula_im',
'nebula_hm',
'nebula_rm',
'nebula_datastore',
'nebula_dm',
'nebula_tm',
'nebula_um',
'nebula_group',
'nebula_authm',
'nebula_acl',
'nebula_mad',
'nebula_template',
'nebula_image',
'nebula_pool',
'nebula_cluster',
'nebula_host',
'nebula_vnm',
'nebula_vm',
'nebula_vmtemplate',
'nebula_common',
'nebula_sql',
'nebula_log',
'nebula_xml',
'crypto'
])
env.Program('test','LifeCycleManagerTest.cc')

View File

@ -1,30 +0,0 @@
# --------------------------------------------------------------------------
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
#
# 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')
# Library dirs
env.Append(LIBPATH=[
'.'
])
env.Prepend(LIBS=[
'nebula_core_test',
'test_object'
])
env.StaticLibrary('test_object', ['TestPoolSQL.cc', 'TestPoolSQL.h'])
env.Program('test','pool.cc')

View File

@ -1,111 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <limits.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <openssl/evp.h>
#include <iomanip>
#include "TestPoolSQL.h"
/* ************************************************************************** */
/* Database Access Functions */
/* ************************************************************************** */
const char * TestObjectSQL::table = "test_pool";
const char * TestObjectSQL::db_names = "oid,name,body,uid,number";
const char * TestObjectSQL::db_bootstrap = "CREATE TABLE test_pool ("
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, "
"number INTEGER)";
/* -------------------------------------------------------------------------- */
int TestObjectSQL::insert(SqlDB *db, string& str)
{
return insert_replace(db, false);
}
/* -------------------------------------------------------------------------- */
int TestObjectSQL::update(SqlDB *db)
{
return insert_replace(db, true);
}
/* -------------------------------------------------------------------------- */
int TestObjectSQL::insert_replace(SqlDB *db, bool replace)
{
ostringstream oss;
int rc;
string xml_body;
char * sql_name;
char * sql_xml;
// Update the User
sql_name = db->escape_str(name.c_str());
if ( sql_name == 0 )
{
goto error_name;
}
sql_xml = db->escape_str(to_xml(xml_body).c_str());
if ( sql_xml == 0 )
{
goto error_body;
}
// Construct the SQL statement to Insert or Replace
if(replace)
{
oss << "REPLACE";
}
else
{
oss << "INSERT";
}
oss << " INTO " << table << " ("<< db_names <<") VALUES ("
<< oid << ","
<< "'" << sql_name << "',"
<< "'" << sql_xml << "',"
<< uid << ","
<< number << ")";
rc = db->exec(oss);
db->free_str(sql_name);
db->free_str(sql_xml);
return rc;
error_body:
db->free_str(sql_name);
error_name:
return -1;
}

View File

@ -1,150 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 TESTSQL_H_
#define TESTSQL_H_
#include <string>
#include "PoolSQL.h"
using namespace std;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
// THE OBJECT
class TestObjectSQL : public PoolObjectSQL
{
public:
//OBJECT ATTRIBUTES
TestObjectSQL(int n=-1, string t="default"):PoolObjectSQL(-1,VM,t,0,0,"","",table),number(n),text(t){};
~TestObjectSQL(){};
int number;
string text;
// OBJECTSQL INTERFACE
int unmarshall(void * nil, int num, char **names, char ** values);
int insert(SqlDB *db, string& err);
int update(SqlDB *db);
int insert_replace(SqlDB *db, bool replace);
int drop(SqlDB *db)
{
return PoolObjectSQL::drop(db);
}
static const char * db_names;
static const char * db_bootstrap;
static const char * table;
static void bootstrap(SqlDB * db)
{
ostringstream oss;
oss.str(TestObjectSQL::db_bootstrap);
db->exec(oss,0);
};
string& to_xml(string& xml) const
{
ostringstream oss;
oss << "<TEST>"
<< "<ID>" << oid << "</ID>"
<< "<UID>" << uid << "</UID>"
<< "<GID>" << gid << "</GID>"
<< "<UNAME>" << uname << "</UNAME>"
<< "<GNAME>" << gname << "</GNAME>"
<< "<NAME>" << name << "</NAME>"
<< "<NUMBER>" << number << "</NUMBER>"
<< "<TEXT>" << text << "</TEXT>"
<< "</TEST>";
xml = oss.str();
return xml;
};
int from_xml(const string &xml_str)
{
int rc = 0;
// Initialize the internal XML object
update_from_str(xml_str);
// Get class base attributes
rc += xpath(oid, "/TEST/ID", -1);
rc += xpath(uid, "/TEST/UID", -1);
rc += xpath(gid, "/TEST/GID", -1);
rc += xpath(uname, "/TEST/UNAME", "not_found");
rc += xpath(gname, "/TEST/GNAME", "not_found");
rc += xpath(name, "/TEST/NAME", "not_found");
rc += xpath(number, "/TEST/NUMBER", -1);
rc += xpath(text, "/TEST/TEXT", "not_found");
if ( rc != 0 )
{
return -1;
}
return 0;
};
};
// THE POOL
class TestPool : public PoolSQL
{
public:
TestPool(SqlDB *db):PoolSQL(db,"test_pool",true){};
~TestPool(){};
TestObjectSQL * get(
int oid,
bool lock)
{
return static_cast<TestObjectSQL *>(PoolSQL::get(oid,lock));
}
TestObjectSQL * get(
const string& name,
int ouid,
bool olock)
{
return static_cast<TestObjectSQL *>(PoolSQL::get(name, ouid, olock));
}
int dump(std::ostringstream&, const std::string&){return -1;};
private:
TestObjectSQL * create()
{
return new TestObjectSQL;
};
};
#endif

View File

@ -1,304 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <getopt.h>
#include "test/OneUnitTest.h"
#include "PoolSQL.h"
#include "TestPoolSQL.h"
using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
class PoolTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE (PoolTest);
CPPUNIT_TEST (allocate_get);
CPPUNIT_TEST (wrong_get);
CPPUNIT_TEST (search);
CPPUNIT_TEST (cache_test);
CPPUNIT_TEST (cache_name_test);
CPPUNIT_TEST_SUITE_END ();
private:
TestPool * pool;
int create_allocate(int n, string st)
{
string err;
TestObjectSQL *obj = new TestObjectSQL(n,st);
return pool->allocate(obj, err);
};
public:
PoolTest(){};
~PoolTest(){};
void setUp()
{
create_db();
TestObjectSQL::bootstrap(db);
pool = new TestPool(db);
};
void tearDown()
{
delete pool;
delete_db();
};
/* ********************************************************************* */
/* ********************************************************************* */
// Try to allocate two objects, and retrieve them
void allocate_get()
{
int n1 = 3;
int n2 = 7;
string st1 = "text number one";
string st2 = "another text";
TestObjectSQL *obj;
int oid;
oid = create_allocate(n1,st1);
// first element in the pool should have oid=0
CPPUNIT_ASSERT(oid == 0);
oid = create_allocate(n2,st2);
// second element in the pool should have oid=1
CPPUNIT_ASSERT(oid == 1);
// ---------------------------------
obj = pool->get(0, false);
CPPUNIT_ASSERT(obj != 0);
CPPUNIT_ASSERT(obj->number == n1);
CPPUNIT_ASSERT(obj->text == st1);
// ---------------------------------
obj = pool->get(1, true);
CPPUNIT_ASSERT(obj != 0);
CPPUNIT_ASSERT(obj->number == n2);
CPPUNIT_ASSERT(obj->text == st2);
obj->unlock();
};
void wrong_get()
{
int n1 = 2;
string st1 = "object 2";
TestObjectSQL *obj;
int oid;
oid = create_allocate(n1,st1);
obj = pool->get(oid,true);
CPPUNIT_ASSERT(obj != 0);
obj->drop(db);
obj->unlock();
obj = pool->get(oid,true);
CPPUNIT_ASSERT(obj == 0);
pool->clean();
obj = pool->get(oid,true);
CPPUNIT_ASSERT(obj == 0);
};
void search()
{
int nA = 13;
int nB = 17;
string stA = "String value for number 13";
string stB = "String value for number 17";
int oidA = create_allocate(nA, stA);
int oidB = create_allocate(nB, stB);
vector<int> results;
const char * table = "test_pool";
string where = "name = '" + stB + "'";
int ret;
ret = pool->search(results, table, where);
CPPUNIT_ASSERT(ret == 0);
CPPUNIT_ASSERT(results.size() == 1);
CPPUNIT_ASSERT(results.at(0) == oidB);
results.erase(results.begin(), results.end());
where = "number < 18";
ret = pool->search(results, table, where);
CPPUNIT_ASSERT(ret == 0);
CPPUNIT_ASSERT(results.size() == 2);
CPPUNIT_ASSERT(results.at(0) == oidA);
CPPUNIT_ASSERT(results.at(1) == oidB);
};
void cache_test()
{
TestObjectSQL *obj;
TestObjectSQL *obj_lock;
//pin object in the cache, it can't be removed -
//Should be set to MAX_POOL -1
for (int i=0 ; i < 14999 ; i++)
{
ostringstream name;
name << "A Test object " << i;
create_allocate(i,name.str());
obj_lock = pool->get(i, true);
CPPUNIT_ASSERT(obj_lock != 0);
}
for (int i=14999 ; i < 15200 ; i++) //Works with just 1 cache line
{
ostringstream name;
name << "A Test object " << i;
create_allocate(i,name.str());
}
for (int i=14999; i < 15200 ; i++)
{
ostringstream name;
name << "A Test object " << i;
obj = pool->get(i, true);
CPPUNIT_ASSERT(obj != 0);
CPPUNIT_ASSERT(obj->number == i);
CPPUNIT_ASSERT(obj->text == name.str());
obj->unlock();
}
for (int i=0 ; i < 14999 ; i++)
{
obj_lock = pool->get(i, false);
obj_lock->unlock();
}
};
void cache_name_test()
{
TestObjectSQL *obj;
TestObjectSQL *obj_lock;
ostringstream oss;
string err_str;
//pin object in the cache, it can't be removed -
//Should be set to MAX_POOL -1
for (int i=0 ; i < 14999 ; i++)
{
oss.str("");
oss << "obj_" << i;
create_allocate(i, oss.str());
obj_lock = pool->get(oss.str(), 0, true);
CPPUNIT_ASSERT(obj_lock != 0);
}
for (int i=14999 ; i < 15200 ; i++) //Works with just 1 cache line
{
oss.str("");
oss << "obj_" << i;
create_allocate(i, oss.str());
}
for (int i=14999; i < 15200 ; i++)
{
oss.str("");
oss << "obj_" << i;
obj = pool->get(oss.str(), 0, true);
CPPUNIT_ASSERT(obj != 0);
CPPUNIT_ASSERT(obj->number == i);
CPPUNIT_ASSERT(obj->get_name() == obj->text);
CPPUNIT_ASSERT(obj->get_name() == oss.str());
obj->unlock();
}
// Delete some of the locked objects, and create new with the same name
for (int i=10 ; i < 21 ; i++)
{
oss.str("");
oss << "obj_" << i;
obj_lock = pool->get(oss.str(), 0, false);
CPPUNIT_ASSERT(obj_lock != 0);
pool->drop(obj_lock, err_str);
obj_lock->unlock();
create_allocate(i, oss.str());
}
// Try to get the new objects
for (int i=10 ; i < 21 ; i++)
{
oss.str("");
oss << "obj_" << i;
obj = pool->get(oss.str(), 0, true);
CPPUNIT_ASSERT(obj != 0);
CPPUNIT_ASSERT(obj->number == i);
CPPUNIT_ASSERT(obj->get_oid() >= 15200);
CPPUNIT_ASSERT(obj->get_name() == oss.str());
obj->unlock();
}
for (int i=0 ; i < 14999 ; i++)
{
obj_lock = pool->get(i, false);
if ( obj_lock != 0 )
{
obj_lock->unlock();
}
}
};
};
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, PoolTest::suite());
}

View File

@ -43,11 +43,6 @@ build_scripts=[
'src/sched/SConstruct'
]
if env['testing']=='yes':
build_scripts.extend([
'src/pool/test/SConstruct',
])
for script in build_scripts:
sched_env=env.Clone()
SConscript(script, exports='sched_env')

View File

@ -1,407 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include <stdexcept>
#include "ObjectXML.h"
#include "HostPoolXML.h"
#include "test/OneUnitTest.h"
/* ************************************************************************* */
/* ************************************************************************* */
class FriendHostPool : public HostPoolXML
{
public:
FriendHostPool(Client* client):HostPoolXML(client, 0){};
friend class HostXMLTest;
static const string host_dump;
static const string xmls[];
protected:
void add_object(xmlNodePtr node)
{
xmlChar * str_ptr = xmlNodeGetContent(node->children->next);
int hid;
if (str_ptr != 0)
{
hid = atoi(reinterpret_cast<char *>(str_ptr));
xmlFree(str_ptr);
}
else
{
}
HostXML* vm = new HostXML( xmls[hid] );
objects.insert( pair<int,ObjectXML*>(hid, vm) );
};
int load_info(xmlrpc_c::value &result)
{
vector<xmlrpc_c::value> arrayData;
arrayData.push_back(xmlrpc_c::value_boolean(true));
arrayData.push_back(xmlrpc_c::value_string(host_dump));
// Make an XML-RPC array out of it
xmlrpc_c::value_array array(arrayData);
result = array;
return 0;
};
};
/* ************************************************************************* */
/* ************************************************************************* */
class HostXMLTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE( HostXMLTest );
CPPUNIT_TEST( initialization );
CPPUNIT_TEST( test_capacity );
CPPUNIT_TEST( add_capacity );
CPPUNIT_TEST_SUITE_END ();
private:
FriendHostPool * hp;
public:
void setUp()
{
xmlInitParser();
try
{
hp = new FriendHostPool(NULL);
}
catch(runtime_error& re)
{
cerr << re.what() << endl;
}
};
void tearDown()
{
xmlCleanupParser();
if (hp != 0)
{
delete hp;
}
};
HostXMLTest(){};
~HostXMLTest(){};
/* ********************************************************************* */
void initialization()
{
int rc;
CPPUNIT_ASSERT( hp != 0 );
rc = hp->set_up();
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( hp->objects.size() == 4 );
CPPUNIT_ASSERT( hp->objects.count(0) == 0);
CPPUNIT_ASSERT( hp->objects.count(1) == 1);
CPPUNIT_ASSERT( hp->objects.count(2) == 1);
CPPUNIT_ASSERT( hp->objects.count(3) == 0);
CPPUNIT_ASSERT( hp->objects.count(4) == 1);
CPPUNIT_ASSERT( hp->objects.count(5) == 1);
CPPUNIT_ASSERT( hp->objects.count(6) == 0);
CPPUNIT_ASSERT( hp->objects.count(7) == 0);
};
void test_capacity()
{
int rc;
CPPUNIT_ASSERT( hp != 0 );
rc = hp->set_up();
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( hp->objects.size() == 4 );
HostXML* host = (HostXML*) hp->objects[5];
CPPUNIT_ASSERT(host != 0);
/*
<DISK_USAGE>256</DISK_USAGE>"
<MEM_USAGE>128</MEM_USAGE>"
<CPU_USAGE>20</CPU_USAGE>"
<MAX_DISK>512</MAX_DISK>"
<MAX_MEM>512</MAX_MEM>"
<MAX_CPU>200</MAX_CPU>"
<FREE_DISK>256</FREE_DISK>"
<FREE_MEM>384</FREE_MEM>"
<FREE_CPU>180</FREE_CPU>"
*/
int n_test = 4;
int disk[] = {256, 260, 0, 100};
int mem[] = {384, 384, 0, 100};
int cpu[] = {180, 180, 0, 200};
bool result[] = {true, false, true, false};
for(int i = 0; i < n_test; i++)
{
bool test = host->test_capacity(cpu[i], mem[i], disk[i]);
CPPUNIT_ASSERT(test == result[i]);
}
};
void add_capacity()
{
int rc;
CPPUNIT_ASSERT( hp != 0 );
rc = hp->set_up();
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( hp->objects.size() == 4 );
HostXML* host = (HostXML*) hp->objects[5];
CPPUNIT_ASSERT(host != 0);
// add cpu, mem, disk
host->add_capacity(100, 128, 128);
int n_test = 2;
int disk[] = {256, 128};
int mem[] = {384, 256};
int cpu[] = {180, 80};
bool result[] = {false, true};
for(int i = 0; i < n_test; i++)
{
bool test = host->test_capacity(cpu[i], mem[i], disk[i]);
CPPUNIT_ASSERT(test == result[i]);
}
};
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, HostXMLTest::suite(),
"HostXMLTest.xml");
}
// ----------------------------------------------------------------------------
const string FriendHostPool::xmls[] =
{
"",
"<HOST>\
<ID>1</ID>\
<NAME>ursa12</NAME>\
<STATE>2</STATE>\
<IM_MAD>im_kvm</IM_MAD>\
<VM_MAD>vmm_kvm</VM_MAD>\
<TM_MAD>tm_shared</TM_MAD>\
<LAST_MON_TIME>1274107238</LAST_MON_TIME>\
<HOST_SHARE>\
<HID>1</HID>\
<DISK_USAGE>0</DISK_USAGE>\
<MEM_USAGE>0</MEM_USAGE>\
<CPU_USAGE>0</CPU_USAGE>\
<MAX_DISK>0</MAX_DISK>\
<MAX_MEM>8194368</MAX_MEM>\
<MAX_CPU>800</MAX_CPU>\
<FREE_DISK>0</FREE_DISK>\
<FREE_MEM>7954812</FREE_MEM>\
<FREE_CPU>800</FREE_CPU>\
<USED_DISK>0</USED_DISK>\
<USED_MEM>536220</USED_MEM>\
<USED_CPU>0</USED_CPU>\
<RUNNING_VMS>0</RUNNING_VMS>\
</HOST_SHARE>\
<TEMPLATE>\
<ARCH>x86_64</ARCH>\
<CPUSPEED>2326</CPUSPEED>\
<FREECPU>800.0</FREECPU>\
<FREEMEMORY>7954812</FREEMEMORY>\
<HOSTNAME>ursa12</HOSTNAME>\
<HYPERVISOR>kvm</HYPERVISOR>\
<MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>\
<NETRX>18584233465</NETRX>\
<NETTX>117426</NETTX>\
<TOTALCPU>800</TOTALCPU>\
<TOTALMEMORY>8194368</TOTALMEMORY>\
<USEDCPU>0.0</USEDCPU>\
<USEDMEMORY>536220</USEDMEMORY>\
</TEMPLATE>\
</HOST>",
"<HOST>\
<ID>2</ID>\
<NAME>ursa</NAME>\
<STATE>2</STATE>\
<IM_MAD>im_kvm</IM_MAD>\
<VM_MAD>vmm_kvm</VM_MAD>\
<TM_MAD>tm_shared</TM_MAD>\
<LAST_MON_TIME>1274107299</LAST_MON_TIME>\
<HOST_SHARE>\
<HID>2</HID>\
<DISK_USAGE>0</DISK_USAGE>\
<MEM_USAGE>4280320</MEM_USAGE>\
<CPU_USAGE>700</CPU_USAGE>\
<MAX_DISK>0</MAX_DISK>\
<MAX_MEM>16468252</MAX_MEM>\
<MAX_CPU>800</MAX_CPU>\
<FREE_DISK>0</FREE_DISK>\
<FREE_MEM>9104256</FREE_MEM>\
<FREE_CPU>613</FREE_CPU>\
<USED_DISK>0</USED_DISK>\
<USED_MEM>13897924</USED_MEM>\
<USED_CPU>186</USED_CPU>\
<RUNNING_VMS>7</RUNNING_VMS>\
</HOST_SHARE>\
<TEMPLATE>\
<ARCH>x86_64</ARCH>\
<CPUSPEED>2327</CPUSPEED>\
<FREECPU>613.6</FREECPU>\
<FREEMEMORY>9104256</FREEMEMORY>\
<HOSTNAME>ursa</HOSTNAME>\
<HYPERVISOR>kvm</HYPERVISOR>\
<MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>\
<NETRX>102804341287</NETRX>\
<NETTX>2186665283</NETTX>\
<TOTALCPU>800</TOTALCPU>\
<TOTALMEMORY>16468252</TOTALMEMORY>\
<USEDCPU>186.4</USEDCPU>\
<USEDMEMORY>13897924</USEDMEMORY>\
</TEMPLATE>\
</HOST>",
"",
"<HOST>\
<ID>4</ID>\
<NAME>ursa11</NAME>\
<STATE>2</STATE>\
<IM_MAD>im_kvm</IM_MAD>\
<VM_MAD>vmm_kvm</VM_MAD>\
<TM_MAD>tm_shared</TM_MAD>\
<LAST_MON_TIME>1274107328</LAST_MON_TIME>\
<HOST_SHARE>\
<HID>4</HID>\
<DISK_USAGE>0</DISK_USAGE>\
<MEM_USAGE>0</MEM_USAGE>\
<CPU_USAGE>0</CPU_USAGE>\
<MAX_DISK>0</MAX_DISK>\
<MAX_MEM>8194368</MAX_MEM>\
<MAX_CPU>800</MAX_CPU>\
<FREE_DISK>0</FREE_DISK>\
<FREE_MEM>7958684</FREE_MEM>\
<FREE_CPU>800</FREE_CPU>\
<USED_DISK>0</USED_DISK>\
<USED_MEM>621616</USED_MEM>\
<USED_CPU>0</USED_CPU>\
<RUNNING_VMS>0</RUNNING_VMS>\
</HOST_SHARE>\
<TEMPLATE>\
<ARCH>x86_64</ARCH>\
<CPUSPEED>2327</CPUSPEED>\
<FREECPU>800.0</FREECPU>\
<FREEMEMORY>7958684</FREEMEMORY>\
<HOSTNAME>ursa11</HOSTNAME>\
<HYPERVISOR>kvm</HYPERVISOR>\
<MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>\
<NETRX>26567502961</NETRX>\
<NETTX>4061</NETTX>\
<TOTALCPU>800</TOTALCPU>\
<TOTALMEMORY>8194368</TOTALMEMORY>\
<USEDCPU>0.0</USEDCPU>\
<USEDMEMORY>621616</USEDMEMORY>\
</TEMPLATE>\
</HOST>",
"<HOST>\
<ID>5</ID>\
<NAME>ursa10</NAME>\
<STATE>2</STATE>\
<IM_MAD>im_kvm</IM_MAD>\
<VM_MAD>vmm_kvm</VM_MAD>\
<TM_MAD>tm_shared</TM_MAD>\
<LAST_MON_TIME>1274107300</LAST_MON_TIME>\
<HOST_SHARE>\
<HID>5</HID>\
<DISK_USAGE>256</DISK_USAGE>\
<MEM_USAGE>128</MEM_USAGE>\
<CPU_USAGE>20</CPU_USAGE>\
<MAX_DISK>512</MAX_DISK>\
<MAX_MEM>512</MAX_MEM>\
<MAX_CPU>200</MAX_CPU>\
<FREE_DISK>256</FREE_DISK>\
<FREE_MEM>384</FREE_MEM>\
<FREE_CPU>180</FREE_CPU>\
<USED_DISK>0</USED_DISK>\
<USED_MEM>2191756</USED_MEM>\
<USED_CPU>6</USED_CPU>\
<RUNNING_VMS>0</RUNNING_VMS>\
</HOST_SHARE>\
<TEMPLATE>\
<ARCH>x86_64</ARCH>\
<CPUSPEED>2327</CPUSPEED>\
<FREECPU>793.6</FREECPU>\
<FREEMEMORY>7871464</FREEMEMORY>\
<HOSTNAME>ursa10</HOSTNAME>\
<HYPERVISOR>kvm</HYPERVISOR>\
<MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>\
<NETRX>42525516540</NETRX>\
<NETTX>144088</NETTX>\
<TOTALCPU>800</TOTALCPU>\
<TOTALMEMORY>8194368</TOTALMEMORY>\
<USEDCPU>6.39999999999998</USEDCPU>\
<USEDMEMORY>2191756</USEDMEMORY>\
</TEMPLATE>\
</HOST>"
};
const string FriendHostPool::host_dump =
"<HOST_POOL> <HOST> <ID>1</ID> <NAME>ursa12</NAME> <STATE>2</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107145</LAST_MON_TIME> <HOST_SHARE> <HID>1</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>0</MEM_USAGE> <CPU_USAGE>0</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>8194368</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>7955180</FREE_MEM> <FREE_CPU>800</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>535848</USED_MEM> <USED_CPU>0</USED_CPU> <RUNNING_VMS>0</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>2</ID> <NAME>ursa</NAME> <STATE>2</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107206</LAST_MON_TIME> <HOST_SHARE> <HID>2</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>4280320</MEM_USAGE> <CPU_USAGE>700</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>16468252</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>9109156</FREE_MEM> <FREE_CPU>628</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>13891232</USED_MEM> <USED_CPU>172</USED_CPU> <RUNNING_VMS>7</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>4</ID> <NAME>ursa11</NAME> <STATE>2</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107145</LAST_MON_TIME> <HOST_SHARE> <HID>4</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>0</MEM_USAGE> <CPU_USAGE>0</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>8194368</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>7958684</FREE_MEM> <FREE_CPU>800</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>621616</USED_MEM> <USED_CPU>0</USED_CPU> <RUNNING_VMS>0</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>5</ID> <NAME>ursa10</NAME> <STATE>2</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107207</LAST_MON_TIME> <HOST_SHARE> <HID>5</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>0</MEM_USAGE> <CPU_USAGE>0</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>8194368</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>7870776</FREE_MEM> <FREE_CPU>796</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>2192424</USED_MEM> <USED_CPU>4</USED_CPU> <RUNNING_VMS>0</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>6</ID> <NAME>ursa08</NAME> <STATE>3</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107176</LAST_MON_TIME> <HOST_SHARE> <HID>6</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>0</MEM_USAGE> <CPU_USAGE>0</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>0</MAX_MEM> <MAX_CPU>0</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>6585200</FREE_MEM> <FREE_CPU>0</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>1132608</USED_MEM> <USED_CPU>0</USED_CPU> <RUNNING_VMS>0</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>7</ID> <NAME>ursa09</NAME> <STATE>3</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107146</LAST_MON_TIME> <HOST_SHARE> <HID>7</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>524288</MEM_USAGE> <CPU_USAGE>100</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>8194368</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>7286128</FREE_MEM> <FREE_CPU>798</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>8011908</USED_MEM> <USED_CPU>1</USED_CPU> <RUNNING_VMS>1</RUNNING_VMS> </HOST_SHARE> </HOST> </HOST_POOL> ";

View File

@ -1,29 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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('sched_env')
# Libraries
sched_env.Prepend(LIBS=[
'nebula_xml',
'scheduler_pool',
'nebula_log',
'nebula_common',
'nebula_test_common',
])
sched_env.Program('test_vm','VirtualMachineXMLTest.cc')
sched_env.Program('test_host','HostXMLTest.cc')

View File

@ -1,500 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include <stdexcept>
#include "ObjectXML.h"
#include "VirtualMachinePoolXML.h"
#include "HostPoolXML.h"
#include "test/OneUnitTest.h"
/* ************************************************************************* */
/* ************************************************************************* */
class FriendHostPool : public HostPoolXML
{
public:
FriendHostPool(Client* client):HostPoolXML(client, 0.1){};
friend class HostXMLTest;
static const string host_dump;
static const string xmls[];
protected:
void add_object(xmlNodePtr node)
{
xmlChar * str_ptr = xmlNodeGetContent(node->children->next);
int hid;
if (str_ptr != 0)
{
hid = atoi(reinterpret_cast<char *>(str_ptr));
xmlFree(str_ptr);
}
else
{
}
HostXML* vm = new HostXML( xmls[hid] );
objects.insert( pair<int,ObjectXML*>(hid, vm) );
};
int load_info(xmlrpc_c::value &result)
{
vector<xmlrpc_c::value> arrayData;
arrayData.push_back(xmlrpc_c::value_boolean(true));
arrayData.push_back(xmlrpc_c::value_string(host_dump));
// Make an XML-RPC array out of it
xmlrpc_c::value_array array(arrayData);
result = array;
return 0;
};
};
class FriendVirtualMachinePool : public VirtualMachinePoolXML
{
public:
FriendVirtualMachinePool
(
Client* client,
unsigned int m_limit = 0
):VirtualMachinePoolXML(client, m_limit, false){};
friend class VirtualMachineXMLTest;
static const string vm_dump;
static const string xmls[];
protected:
void add_object(xmlNodePtr node)
{
xmlNodePtr nodeID;
nodeID = node->children->next;
xmlChar * str_ptr = xmlNodeGetContent(nodeID);
int vid;
if (str_ptr != 0)
{
vid = atoi(reinterpret_cast<char *>(str_ptr));
xmlFree(str_ptr);
}
else
{
// TODO
}
VirtualMachineXML* vm = new VirtualMachineXML( xmls[vid] );
objects.insert( pair<int,ObjectXML*>(vid, vm) );
};
int load_info(xmlrpc_c::value &result)
{
vector<xmlrpc_c::value> arrayData;
arrayData.push_back(xmlrpc_c::value_boolean(true));
arrayData.push_back(xmlrpc_c::value_string(vm_dump));
// Make an XML-RPC array out of it
xmlrpc_c::value_array array(arrayData);
result = array;
return 0;
};
};
/* ************************************************************************* */
/* ************************************************************************* */
class VirtualMachineXMLTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE( VirtualMachineXMLTest );
CPPUNIT_TEST( initialization );
CPPUNIT_TEST( add_host );
CPPUNIT_TEST( get_host );
CPPUNIT_TEST_SUITE_END ();
private:
static const string host_dump;
FriendVirtualMachinePool * vmp;
FriendHostPool* set_up_hpool()
{
FriendHostPool* hpool;
hpool = new FriendHostPool(NULL);
hpool->set_up();
return hpool;
};
public:
VirtualMachineXMLTest(){};
~VirtualMachineXMLTest(){};
void setUp()
{
xmlInitParser();
try
{
vmp = new FriendVirtualMachinePool(NULL);
}
catch(runtime_error& re)
{
cerr << re.what() << endl;
}
};
void tearDown()
{
xmlCleanupParser();
if (vmp != 0)
{
delete vmp;
}
};
/* ********************************************************************* */
void initialization()
{
int rc;
CPPUNIT_ASSERT( vmp != 0 );
rc = vmp->set_up();
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( vmp->objects.size() == 3 );
CPPUNIT_ASSERT( vmp->objects.count(0) == 1);
CPPUNIT_ASSERT( vmp->objects.count(1) == 1);
CPPUNIT_ASSERT( vmp->objects.count(2) == 1);
CPPUNIT_ASSERT( vmp->objects.count(3) == 0);
};
void add_host()
{
int rc;
VirtualMachineXML* vm;
vector<int> mh;
CPPUNIT_ASSERT( vmp != 0 );
rc = vmp->set_up();
CPPUNIT_ASSERT( rc == 0 );
vm = ((VirtualMachineXML*)vmp->objects[0]);
CPPUNIT_ASSERT( vm != 0 );
vm->get_matching_hosts(mh);
CPPUNIT_ASSERT( mh.size() == 0 );
vm->add_host( 2 );
vm->add_host( 9 );
vm->add_host( 4 );
mh.clear();
vm->get_matching_hosts(mh);
CPPUNIT_ASSERT( mh.size() == 3 );
CPPUNIT_ASSERT( mh[0] == 2 );
CPPUNIT_ASSERT( mh[1] == 9 );
CPPUNIT_ASSERT( mh[2] == 4 );
};
void get_host()
{
VirtualMachineXML* vm;
HostPoolXML* hpool;
vector<float> priorities;
int hid;
int rc;
map<int, int> host_vms;
CPPUNIT_ASSERT( vmp != 0 );
rc = vmp->set_up();
CPPUNIT_ASSERT( rc == 0 );
hpool = set_up_hpool();
CPPUNIT_ASSERT( hpool != 0 );
vm = vmp->get(0);
CPPUNIT_ASSERT( vm != 0 );
rc = vm->get_host(hid, hpool,host_vms,1);
CPPUNIT_ASSERT( rc == -1 );
// get_host will iterate in reverse order the available hosts, and
// return the first to fit the requirements; in this case
// cpu: 50 mem: 128
vm->add_host( 5 );
vm->add_host( 4 );
vm->add_host( 2 );
vm->add_host( 1 );
rc = vm->get_host(hid, hpool,host_vms,1);
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( hid == 4 );
// If we set host 5 to have the greatest priority, get_host should
// return it.
priorities.push_back(1.0); // hid 5
priorities.push_back(0.8); // hid 4
priorities.push_back(0.5); // hid 2
priorities.push_back(0.3); // hid 1
vm->set_priorities(priorities);
rc = vm->get_host(hid, hpool,host_vms,1);
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( hid == 5 );
delete hpool;
};
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, VirtualMachineXMLTest::suite(),
"VirtualMachineXMLTest.xml");
}
// ----------------------------------------------------------------------------
const string FriendVirtualMachinePool::xmls[] =
{
" <VM> <ID> 0 </ID> <UID> 0 </UID> <GID>2</GID> <NAME> vm-example </NAME> <LAST_POLL> 0 </LAST_POLL> <STATE> 1 </STATE> <LCM_STATE> 0 </LCM_STATE> <STIME> 1274087556 </STIME> <ETIME> 1274087589 </ETIME> <DEPLOY_ID/> <MEMORY> 0 </MEMORY> <CPU> 0 </CPU> <NET_TX> 0 </NET_TX> <NET_RX> 0 </NET_RX> <TEMPLATE> <CONTEXT> <HOSTNAME> vm-example </HOSTNAME> <IP_GEN> 10.0.0. </IP_GEN> <IP_PRIVATE> 10.0.0.1 </IP_PRIVATE> </CONTEXT> <CPU> 0.5 </CPU> <DISK> <READONLY> no </READONLY> <SOURCE> /local/xen/domains/etch/disk.img </SOURCE> <TARGET> sda1 </TARGET> </DISK> <DISK> <READONLY> no </READONLY> <SOURCE> /local/xen/domains/etch/swap.img </SOURCE> <TARGET> sda2 </TARGET> </DISK> <GRAPHICS> <LISTEN> 127.0.0.1 </LISTEN> <PORT> 5 </PORT> <TYPE> vnc </TYPE> </GRAPHICS> <MEMORY> 128 </MEMORY> <NAME> vm-example </NAME> <NIC> <BRIDGE> eth0 </BRIDGE> <IP> 10.0.0.1 </IP> <MAC> 00:03:0a:00:00:01 </MAC> <NETWORK> Private LAN </NETWORK> <VNID> 0 </VNID> </NIC> <OS> <INITRD> /initrd.img </INITRD> <KERNEL> /vmlinuz </KERNEL> <ROOT> sda1 </ROOT> </OS> <VMID> 0 </VMID> </TEMPLATE> <HISTORY> <SEQ> 0 </SEQ> <HOSTNAME> host16 </HOSTNAME> <HID> 15 </HID> <STIME> 1274087589 </STIME> <ETIME> 1274087589 </ETIME> <PSTIME> 1274087589 </PSTIME> <PETIME> 1274087589 </PETIME> <RSTIME> 0 </RSTIME> <RETIME> 0 </RETIME> <ESTIME> 0 </ESTIME> <EETIME> 0 </EETIME> <REASON> 1 </REASON> </HISTORY> </VM> ",
"<VM> <ID> 1 </ID> <UID> 0 </UID> <GID>2</GID> <NAME> vm-example </NAME> <LAST_POLL> 0 </LAST_POLL> <STATE> 1 </STATE> <LCM_STATE> 0 </LCM_STATE> <STIME> 1274087557 </STIME> <ETIME> 1274087590 </ETIME> <DEPLOY_ID/> <MEMORY> 0 </MEMORY> <CPU> 0 </CPU> <NET_TX> 0 </NET_TX> <NET_RX> 0 </NET_RX> <TEMPLATE> <CONTEXT> <HOSTNAME> vm-example </HOSTNAME> <IP_GEN> 10.0.0. </IP_GEN> <IP_PRIVATE> 10.0.0.2 </IP_PRIVATE> </CONTEXT> <CPU> 0.5 </CPU> <DISK> <READONLY> no </READONLY> <SOURCE> /local/xen/domains/etch/disk.img </SOURCE> <TARGET> sda1 </TARGET> </DISK> <DISK> <READONLY> no </READONLY> <SOURCE> /local/xen/domains/etch/swap.img </SOURCE> <TARGET> sda2 </TARGET> </DISK> <GRAPHICS> <LISTEN> 127.0.0.1 </LISTEN> <PORT> 5 </PORT> <TYPE> vnc </TYPE> </GRAPHICS> <MEMORY> 128 </MEMORY> <NAME> vm-example </NAME> <NIC> <BRIDGE> eth0 </BRIDGE> <IP> 10.0.0.2 </IP> <MAC> 00:03:0a:00:00:02 </MAC> <NETWORK> Private LAN </NETWORK> <VNID> 0 </VNID> </NIC> <OS> <INITRD> /initrd.img </INITRD> <KERNEL> /vmlinuz </KERNEL> <ROOT> sda1 </ROOT> </OS> <VMID> 1 </VMID> </TEMPLATE> <HISTORY> <SEQ> 0 </SEQ> <HOSTNAME> host16 </HOSTNAME> <HID> 15 </HID> <STIME> 1274087589 </STIME> <ETIME> 1274087589 </ETIME> <PSTIME> 1274087589 </PSTIME> <PETIME> 1274087589 </PETIME> <RSTIME> 0 </RSTIME> <RETIME> 0 </RETIME> <ESTIME> 0 </ESTIME> <EETIME> 0 </EETIME> <REASON> 1 </REASON> </HISTORY> </VM> ",
"<VM> <ID> 2 </ID> <UID> 0 </UID> <GID> 1 </GID> <NAME> vm-example </NAME> <LAST_POLL> 0 </LAST_POLL> <STATE> 1 </STATE> <LCM_STATE> 0 </LCM_STATE> <STIME> 1274087557 </STIME> <ETIME> 1274087590 </ETIME> <DEPLOY_ID/> <MEMORY> 0 </MEMORY> <CPU> 0 </CPU> <NET_TX> 0 </NET_TX> <NET_RX> 0 </NET_RX> <TEMPLATE> <CONTEXT> <HOSTNAME> vm-example </HOSTNAME> <IP_GEN> 10.0.0. </IP_GEN> <IP_PRIVATE> 10.0.0.3 </IP_PRIVATE> </CONTEXT> <CPU> 0.5 </CPU> <DISK> <READONLY> no </READONLY> <SOURCE> /local/xen/domains/etch/disk.img </SOURCE> <TARGET> sda1 </TARGET> </DISK> <DISK> <READONLY> no </READONLY> <SOURCE> /local/xen/domains/etch/swap.img </SOURCE> <TARGET> sda2 </TARGET> </DISK> <GRAPHICS> <LISTEN> 127.0.0.1 </LISTEN> <PORT> 5 </PORT> <TYPE> vnc </TYPE> </GRAPHICS> <MEMORY> 128 </MEMORY> <NAME> vm-example </NAME> <NIC> <BRIDGE> eth0 </BRIDGE> <IP> 10.0.0.3 </IP> <MAC> 00:03:0a:00:00:03 </MAC> <NETWORK> Private LAN </NETWORK> <VNID> 0 </VNID> </NIC> <OS> <INITRD> /initrd.img </INITRD> <KERNEL> /vmlinuz </KERNEL> <ROOT> sda1 </ROOT> </OS> <VMID> 2 </VMID> </TEMPLATE> <HISTORY> <SEQ> 0 </SEQ> <HOSTNAME> host16 </HOSTNAME> <HID> 15 </HID> <STIME> 1274087589 </STIME> <ETIME> 1274087590 </ETIME> <PSTIME> 1274087589 </PSTIME> <PETIME> 1274087590 </PETIME> <RSTIME> 0 </RSTIME> <RETIME> 0 </RETIME> <ESTIME> 0 </ESTIME> <EETIME> 0 </EETIME> <REASON> 1 </REASON> </HISTORY> </VM> "
};
const string FriendVirtualMachinePool::vm_dump =
"<VM_POOL> <VM> <ID> 0 </ID> <UID> 0 </UID> <GID> 0 </GID> <USERNAME> carlos </USERNAME> <NAME> vm-example </NAME> <LAST_POLL> 0 </LAST_POLL> <STATE> 1 </STATE> <LCM_STATE> 0 </LCM_STATE> <STIME> 1274087556 </STIME> <ETIME> 1274087589 </ETIME> <DEPLOY_ID/> <MEMORY> 0 </MEMORY> <CPU> 0 </CPU> <NET_TX> 0 </NET_TX> <NET_RX> 0 </NET_RX> <HISTORY> <SEQ> 0 </SEQ> <HOSTNAME> host16 </HOSTNAME> <HID> 15 </HID> <STIME> 1274087589 </STIME> <ETIME> 1274087589 </ETIME> <PSTIME> 1274087589 </PSTIME> <PETIME> 1274087589 </PETIME> <RSTIME> 0 </RSTIME> <RETIME> 0 </RETIME> <ESTIME> 0 </ESTIME> <EETIME> 0 </EETIME> <REASON> 1 </REASON> </HISTORY> </VM> <VM> <ID> 1 </ID> <UID> 0 </UID> <GID> 0 </GID> <USERNAME> carlos </USERNAME> <NAME> vm-example </NAME> <LAST_POLL> 0 </LAST_POLL> <STATE> 1 </STATE> <LCM_STATE> 0 </LCM_STATE> <STIME> 1274087557 </STIME> <ETIME> 1274087590 </ETIME> <DEPLOY_ID/> <MEMORY> 0 </MEMORY> <CPU> 0 </CPU> <NET_TX> 0 </NET_TX> <NET_RX> 0 </NET_RX> <HISTORY> <SEQ> 0 </SEQ> <HOSTNAME> host16 </HOSTNAME> <HID> 15 </HID> <STIME> 1274087589 </STIME> <ETIME> 1274087589 </ETIME> <PSTIME> 1274087589 </PSTIME> <PETIME> 1274087589 </PETIME> <RSTIME> 0 </RSTIME> <RETIME> 0 </RETIME> <ESTIME> 0 </ESTIME> <EETIME> 0 </EETIME> <REASON> 1 </REASON> </HISTORY> </VM> <VM> <ID> 2 </ID> <UID> 0 </UID> <GID> 1 </GID> <USERNAME> carlos </USERNAME> <NAME> vm-example </NAME> <LAST_POLL> 0 </LAST_POLL> <STATE> 1 </STATE> <LCM_STATE> 0 </LCM_STATE> <STIME> 1274087557 </STIME> <ETIME> 1274087590 </ETIME> <DEPLOY_ID/> <MEMORY> 0 </MEMORY> <CPU> 0 </CPU> <NET_TX> 0 </NET_TX> <NET_RX> 0 </NET_RX> <HISTORY> <SEQ> 0 </SEQ> <HOSTNAME> host16 </HOSTNAME> <HID> 15 </HID> <STIME> 1274087589 </STIME> <ETIME> 1274087590 </ETIME> <PSTIME> 1274087589 </PSTIME> <PETIME> 1274087590 </PETIME> <RSTIME> 0 </RSTIME> <RETIME> 0 </RETIME> <ESTIME> 0 </ESTIME> <EETIME> 0 </EETIME> <REASON> 1 </REASON> </HISTORY> </VM> </VM_POOL> ";
const string FriendHostPool::xmls[] =
{
"",
"<HOST>\
<ID>1</ID>\
<NAME>ursa12</NAME>\
<STATE>2</STATE>\
<IM_MAD>im_kvm</IM_MAD>\
<VM_MAD>vmm_kvm</VM_MAD>\
<TM_MAD>tm_shared</TM_MAD>\
<LAST_MON_TIME>1274107238</LAST_MON_TIME>\
<HOST_SHARE>\
<HID>1</HID>\
<DISK_USAGE>0</DISK_USAGE>\
<MEM_USAGE>262144</MEM_USAGE>\
<CPU_USAGE>80</CPU_USAGE>\
<MAX_DISK>0</MAX_DISK>\
<MAX_MEM>524288</MAX_MEM>\
<MAX_CPU>100</MAX_CPU>\
<FREE_DISK>0</FREE_DISK>\
<FREE_MEM>0</FREE_MEM>\
<FREE_CPU>0</FREE_CPU>\
<USED_DISK>0</USED_DISK>\
<USED_MEM>536220</USED_MEM>\
<USED_CPU>0</USED_CPU>\
<RUNNING_VMS>0</RUNNING_VMS>\
</HOST_SHARE>\
<TEMPLATE>\
<ARCH>x86_64</ARCH>\
<CPUSPEED>2326</CPUSPEED>\
<FREECPU>800.0</FREECPU>\
<FREEMEMORY>7954812</FREEMEMORY>\
<HOSTNAME>ursa12</HOSTNAME>\
<HYPERVISOR>kvm</HYPERVISOR>\
<MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>\
<NETRX>18584233465</NETRX>\
<NETTX>117426</NETTX>\
<TOTALCPU>800</TOTALCPU>\
<TOTALMEMORY>8194368</TOTALMEMORY>\
<USEDCPU>0.0</USEDCPU>\
<USEDMEMORY>536220</USEDMEMORY>\
</TEMPLATE>\
</HOST>",
"<HOST>\
<ID>2</ID>\
<NAME>ursa</NAME>\
<STATE>2</STATE>\
<IM_MAD>im_kvm</IM_MAD>\
<VM_MAD>vmm_kvm</VM_MAD>\
<TM_MAD>tm_shared</TM_MAD>\
<LAST_MON_TIME>1274107299</LAST_MON_TIME>\
<HOST_SHARE>\
<HID>2</HID>\
<DISK_USAGE>0</DISK_USAGE>\
<MEM_USAGE>458752</MEM_USAGE>\
<CPU_USAGE>20</CPU_USAGE>\
<MAX_DISK>0</MAX_DISK>\
<MAX_MEM>524288</MAX_MEM>\
<MAX_CPU>100</MAX_CPU>\
<FREE_DISK>0</FREE_DISK>\
<FREE_MEM>9104256</FREE_MEM>\
<FREE_CPU>613</FREE_CPU>\
<USED_DISK>0</USED_DISK>\
<USED_MEM>13897924</USED_MEM>\
<USED_CPU>186</USED_CPU>\
<RUNNING_VMS>7</RUNNING_VMS>\
</HOST_SHARE>\
<TEMPLATE>\
<ARCH>x86_64</ARCH>\
<CPUSPEED>2327</CPUSPEED>\
<FREECPU>613.6</FREECPU>\
<FREEMEMORY>9104256</FREEMEMORY>\
<HOSTNAME>ursa</HOSTNAME>\
<HYPERVISOR>kvm</HYPERVISOR>\
<MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>\
<NETRX>102804341287</NETRX>\
<NETTX>2186665283</NETTX>\
<TOTALCPU>800</TOTALCPU>\
<TOTALMEMORY>16468252</TOTALMEMORY>\
<USEDCPU>186.4</USEDCPU>\
<USEDMEMORY>13897924</USEDMEMORY>\
</TEMPLATE>\
</HOST>",
"",
"<HOST>\
<ID>4</ID>\
<NAME>ursa11</NAME>\
<STATE>2</STATE>\
<IM_MAD>im_kvm</IM_MAD>\
<VM_MAD>vmm_kvm</VM_MAD>\
<TM_MAD>tm_shared</TM_MAD>\
<LAST_MON_TIME>1274107328</LAST_MON_TIME>\
<HOST_SHARE>\
<HID>4</HID>\
<DISK_USAGE>0</DISK_USAGE>\
<MEM_USAGE>262144</MEM_USAGE>\
<CPU_USAGE>10</CPU_USAGE>\
<MAX_DISK>0</MAX_DISK>\
<MAX_MEM>524288</MAX_MEM>\
<MAX_CPU>100</MAX_CPU>\
<FREE_DISK>0</FREE_DISK>\
<FREE_MEM>7958684</FREE_MEM>\
<FREE_CPU>800</FREE_CPU>\
<USED_DISK>0</USED_DISK>\
<USED_MEM>621616</USED_MEM>\
<USED_CPU>0</USED_CPU>\
<RUNNING_VMS>0</RUNNING_VMS>\
</HOST_SHARE>\
<TEMPLATE>\
<ARCH>x86_64</ARCH>\
<CPUSPEED>2327</CPUSPEED>\
<FREECPU>800.0</FREECPU>\
<FREEMEMORY>7958684</FREEMEMORY>\
<HOSTNAME>ursa11</HOSTNAME>\
<HYPERVISOR>kvm</HYPERVISOR>\
<MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>\
<NETRX>26567502961</NETRX>\
<NETTX>4061</NETTX>\
<TOTALCPU>800</TOTALCPU>\
<TOTALMEMORY>8194368</TOTALMEMORY>\
<USEDCPU>0.0</USEDCPU>\
<USEDMEMORY>621616</USEDMEMORY>\
</TEMPLATE>\
</HOST>",
"<HOST>\
<ID>5</ID>\
<NAME>ursa10</NAME>\
<STATE>2</STATE>\
<IM_MAD>im_kvm</IM_MAD>\
<VM_MAD>vmm_kvm</VM_MAD>\
<TM_MAD>tm_shared</TM_MAD>\
<LAST_MON_TIME>1274107300</LAST_MON_TIME>\
<HOST_SHARE>\
<HID>5</HID>\
<DISK_USAGE>256</DISK_USAGE>\
<MEM_USAGE>0</MEM_USAGE>\
<CPU_USAGE>30</CPU_USAGE>\
<MAX_DISK>512</MAX_DISK>\
<MAX_MEM>524288</MAX_MEM>\
<MAX_CPU>100</MAX_CPU>\
<FREE_DISK>256</FREE_DISK>\
<FREE_MEM>384</FREE_MEM>\
<FREE_CPU>180</FREE_CPU>\
<USED_DISK>0</USED_DISK>\
<USED_MEM>2191756</USED_MEM>\
<USED_CPU>6</USED_CPU>\
<RUNNING_VMS>0</RUNNING_VMS>\
</HOST_SHARE>\
<TEMPLATE>\
<ARCH>x86_64</ARCH>\
<CPUSPEED>2327</CPUSPEED>\
<FREECPU>793.6</FREECPU>\
<FREEMEMORY>7871464</FREEMEMORY>\
<HOSTNAME>ursa10</HOSTNAME>\
<HYPERVISOR>kvm</HYPERVISOR>\
<MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>\
<NETRX>42525516540</NETRX>\
<NETTX>144088</NETTX>\
<TOTALCPU>800</TOTALCPU>\
<TOTALMEMORY>8194368</TOTALMEMORY>\
<USEDCPU>6.39999999999998</USEDCPU>\
<USEDMEMORY>2191756</USEDMEMORY>\
</TEMPLATE>\
</HOST>"
};
const string FriendHostPool::host_dump =
"<HOST_POOL> <HOST> <ID>1</ID> <NAME>ursa12</NAME> <STATE>2</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107145</LAST_MON_TIME> <HOST_SHARE> <HID>1</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>0</MEM_USAGE> <CPU_USAGE>0</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>8194368</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>7955180</FREE_MEM> <FREE_CPU>800</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>535848</USED_MEM> <USED_CPU>0</USED_CPU> <RUNNING_VMS>0</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>2</ID> <NAME>ursa</NAME> <STATE>2</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107206</LAST_MON_TIME> <HOST_SHARE> <HID>2</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>4280320</MEM_USAGE> <CPU_USAGE>700</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>16468252</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>9109156</FREE_MEM> <FREE_CPU>628</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>13891232</USED_MEM> <USED_CPU>172</USED_CPU> <RUNNING_VMS>7</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>4</ID> <NAME>ursa11</NAME> <STATE>2</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107145</LAST_MON_TIME> <HOST_SHARE> <HID>4</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>0</MEM_USAGE> <CPU_USAGE>0</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>8194368</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>7958684</FREE_MEM> <FREE_CPU>800</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>621616</USED_MEM> <USED_CPU>0</USED_CPU> <RUNNING_VMS>0</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>5</ID> <NAME>ursa10</NAME> <STATE>2</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107207</LAST_MON_TIME> <HOST_SHARE> <HID>5</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>0</MEM_USAGE> <CPU_USAGE>0</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>8194368</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>7870776</FREE_MEM> <FREE_CPU>796</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>2192424</USED_MEM> <USED_CPU>4</USED_CPU> <RUNNING_VMS>0</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>6</ID> <NAME>ursa08</NAME> <STATE>3</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107176</LAST_MON_TIME> <HOST_SHARE> <HID>6</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>0</MEM_USAGE> <CPU_USAGE>0</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>0</MAX_MEM> <MAX_CPU>0</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>6585200</FREE_MEM> <FREE_CPU>0</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>1132608</USED_MEM> <USED_CPU>0</USED_CPU> <RUNNING_VMS>0</RUNNING_VMS> </HOST_SHARE> </HOST> <HOST> <ID>7</ID> <NAME>ursa09</NAME> <STATE>3</STATE> <IM_MAD>im_kvm</IM_MAD> <VM_MAD>vmm_kvm</VM_MAD> <TM_MAD>tm_shared</TM_MAD> <LAST_MON_TIME>1274107146</LAST_MON_TIME> <HOST_SHARE> <HID>7</HID> <DISK_USAGE>0</DISK_USAGE> <MEM_USAGE>524288</MEM_USAGE> <CPU_USAGE>100</CPU_USAGE> <MAX_DISK>0</MAX_DISK> <MAX_MEM>8194368</MAX_MEM> <MAX_CPU>800</MAX_CPU> <FREE_DISK>0</FREE_DISK> <FREE_MEM>7286128</FREE_MEM> <FREE_CPU>798</FREE_CPU> <USED_DISK>0</USED_DISK> <USED_MEM>8011908</USED_MEM> <USED_CPU>1</USED_CPU> <RUNNING_VMS>1</RUNNING_VMS> </HOST_SHARE> </HOST> </HOST_POOL> ";

View File

@ -1,27 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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.Append(LIBS=[
'nebula_xml',
'nebula_template',
'nebula_common',
'nebula_core',
'nebula_log'
])
env.Program('test','template.cc')

View File

@ -1,366 +0,0 @@
#include "Template.h"
#include <string>
#include <iostream>
#include "test/OneUnitTest.h"
using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
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;
string test_ok;
string test_ok_marshall;
string test_ok_xml;
string test_ok_str;
public:
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
TemplateTest()
{
test_ok =
"#This line is a comment\n"
" # Other comment\n"
"MEMORY=345 # more comments behind an attribute\n"
" CPU = 4\n"
"#------------------------------\n"
"#Comments in the middle\n"
"#------------------------------\n"
" empty_var = \n"
"REQUIREMENTS = \"HOSTNAME = \\\"host*.com\\\"\"\n"
" DISK= [file = path1, extra = \"disk attribute \"]\n"
"DISK =[ FILE = \"path2\", EXTRA = str, TYPE=disk]\n"
" graphics = [\n"
" VNC = \"127.0.0.1\",\n"
" PORT = 12\n"
" ]\n";
test_ok_marshall="CPU=4\nDISK=EXTRA=disk attribute @^_^@FILE=path1\n"
"DISK=EXTRA=str@^_^@FILE=path2@^_^@TYPE=disk\nEMPTY_VAR=\n"
"GRAPHICS=PORT=12@^_^@VNC=127.0.0.1\nMEMORY=345\n"
"REQUIREMENTS=HOSTNAME = \"host*.com\"\n";
test_ok_xml="<TEMPLATE><CPU><![CDATA[4]]></CPU><DISK><EXTRA>"
"<![CDATA[disk attribute ]]></EXTRA><FILE><![CDATA[path1]]></FILE>"
"</DISK><DISK><EXTRA><![CDATA[str]]></EXTRA><FILE><![CDATA[path2]]>"
"</FILE><TYPE><![CDATA[disk]]></TYPE></DISK><EMPTY_VAR><![CDATA[]]>"
"</EMPTY_VAR><GRAPHICS><PORT><![CDATA[12]]></PORT><VNC>"
"<![CDATA[127.0.0.1]]></VNC></GRAPHICS><MEMORY><![CDATA[345]]>"
"</MEMORY><REQUIREMENTS><![CDATA[HOSTNAME = \"host*.com\"]]>"
"</REQUIREMENTS></TEMPLATE>";
test_ok_str=
"CPU=4\n"
"DISK=EXTRA=disk attribute ,FILE=path1\n"
"DISK=EXTRA=str,FILE=path2,TYPE=disk\n"
"EMPTY_VAR=\n"
"GRAPHICS=PORT=12,VNC=127.0.0.1\n"
"MEMORY=345\n"
"REQUIREMENTS=HOSTNAME = \"host*.com\"\n";
}
~TemplateTest(){};
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
void setUp()
{
char *error = 0;
t = new Template();
tr= new Template(true);
tr->parse(test_ok,&error);
t1= new Template();
t1->parse(test_ok,&error);
xmlInitParser();
}
void tearDown()
{
delete t;
delete tr;
delete t1;
xmlCleanupParser();
}
/* ********************************************************************* */
/* ********************************************************************* */
void test_parser()
{
char * error = 0;
int rc;
string tmp;
rc = t->parse(test_ok,&error);
if ( error != 0 )
{
cerr << error << endl;
free(error);
}
CPPUNIT_ASSERT( rc == 0);
}
/* --------------------------------------------------------------------- */
void test_marshall()
{
string tmp;
t1->marshall(tmp);
CPPUNIT_ASSERT(test_ok_marshall == tmp);
}
/* --------------------------------------------------------------------- */
void test_xml()
{
string tmp;
t1->to_xml(tmp);
CPPUNIT_ASSERT(test_ok_xml == tmp);
}
/* --------------------------------------------------------------------- */
void test_str()
{
string tmp;
t1->to_str(tmp);
CPPUNIT_ASSERT(test_ok_str == tmp);
}
/* --------------------------------------------------------------------- */
void test_get()
{
vector<Attribute*> attrs;
string *tmp;
CPPUNIT_ASSERT(t1->get("DISK",attrs) == 2 );
CPPUNIT_ASSERT(attrs[0]->type() == Attribute::VECTOR);
tmp = attrs[0]->to_xml();
CPPUNIT_ASSERT( *tmp ==
"<DISK><EXTRA><![CDATA[disk attribute ]]></EXTRA><FILE>"
"<![CDATA[path1]]></FILE></DISK>");
delete tmp;
CPPUNIT_ASSERT(attrs[1]->type() == Attribute::VECTOR);
tmp = attrs[1]->to_xml();
CPPUNIT_ASSERT( *tmp ==
"<DISK><EXTRA><![CDATA[str]]></EXTRA><FILE><![CDATA[path2]]>"
"</FILE><TYPE><![CDATA[disk]]></TYPE></DISK>");
delete tmp;
CPPUNIT_ASSERT(t1->get("CPU",attrs) == 1 );
CPPUNIT_ASSERT(attrs[2]->type() == Attribute::SIMPLE);
tmp = attrs[2]->to_xml();
CPPUNIT_ASSERT( *tmp == "<CPU><![CDATA[4]]></CPU>");
delete tmp;
string sval;
string sname = "REQUIREMENTS";
string iname = "MEMORY";
int ival;
t1->get(iname,ival);
t1->get(sname,sval);
CPPUNIT_ASSERT ( ival == 345 );
CPPUNIT_ASSERT ( sval == "HOSTNAME = \"host*.com\"");
}
/* --------------------------------------------------------------------- */
void test_remove()
{
vector<Attribute*> attrs;
string t1_xml;
string rm_xml="<TEMPLATE><CPU><![CDATA[4]]></CPU><EMPTY_VAR>"
"<![CDATA[]]></EMPTY_VAR><GRAPHICS><PORT><![CDATA[12]]></PORT><VNC>"
"<![CDATA[127.0.0.1]]></VNC></GRAPHICS><MEMORY><![CDATA[345]]>"
"</MEMORY><REQUIREMENTS><![CDATA[HOSTNAME = \"host*.com\"]]>"
"</REQUIREMENTS></TEMPLATE>";
t1->remove("DISK",attrs);
t1->to_xml(t1_xml);
CPPUNIT_ASSERT(t1_xml == rm_xml);
delete attrs[0];
delete attrs[1];
}
/* --------------------------------------------------------------------- */
void test_set()
{
string t1_xml="<TEMPLATE><CPU><![CDATA[4]]></CPU><DISK><EXTRA>"
"<![CDATA[disk attribute ]]></EXTRA><FILE><![CDATA[path1]]>"
"</FILE></DISK><DISK><EXTRA><![CDATA[str]]></EXTRA><FILE>"
"<![CDATA[path2]]></FILE><TYPE><![CDATA[disk]]></TYPE></DISK>"
"<EMPTY_VAR><![CDATA[]]></EMPTY_VAR><GRAPHICS><PORT><![CDATA[12]]>"
"</PORT><VNC><![CDATA[127.0.0.1]]></VNC></GRAPHICS><MEMORY>"
"<![CDATA[345]]></MEMORY><REQUIREMENTS>"
"<![CDATA[HOSTNAME = \"host*.com\"]]></REQUIREMENTS><XTRA>"
"<![CDATA[44]]></XTRA></TEMPLATE>";
string xml;
string nattr = "XTRA";
string vattr = "44";
SingleAttribute *a = new SingleAttribute(nattr,vattr);
t1->set(a);
t1->to_xml(xml);
CPPUNIT_ASSERT(t1_xml == xml);
nattr = "CPU";
vattr = "5";
t1_xml="<TEMPLATE><CPU><![CDATA[4]]></CPU><CPU><![CDATA[5]]></CPU><DISK"
"><EXTRA><![CDATA[disk attribute ]]></EXTRA><FILE><![CDATA[path1]]>"
"</FILE></DISK><DISK><EXTRA><![CDATA[str]]></EXTRA><FILE><![CDATA[path2"
"]]></FILE><TYPE><![CDATA[disk]]></TYPE></DISK><EMPTY_VAR><![CDATA[]]>"
"</EMPTY_VAR><GRAPHICS><PORT><![CDATA[12]]></PORT><VNC><![CDATA[127.0.0"
".1]]></VNC></GRAPHICS><MEMORY><![CDATA[345]]></MEMORY><REQUIREMENTS>"
"<![CDATA[HOSTNAME = \"host*.com\"]]></REQUIREMENTS><XTRA><![CDATA[44]]"
"></XTRA></TEMPLATE>";
SingleAttribute *b = new SingleAttribute(nattr,vattr);
t1->set(b);
t1->to_xml(xml);
CPPUNIT_ASSERT(t1_xml == xml);
string tr_xml="<TEMPLATE><CPU><![CDATA[5]]></CPU><DISK><EXTRA><![CDATA["
"str]]></EXTRA><FILE><![CDATA[path2]]></FILE><TYPE><![CDATA[disk]]></TY"
"PE></DISK><EMPTY_VAR><![CDATA[]]></EMPTY_VAR><GRAPHICS><PORT><![CDATA["
"12]]></PORT><VNC><![CDATA[127.0.0.1]]></VNC></GRAPHICS><MEMORY><![CDAT"
"A[345]]></MEMORY><REQUIREMENTS><![CDATA[HOSTNAME = \"host*.com\"]]></R"
"EQUIREMENTS></TEMPLATE>";
SingleAttribute *c = new SingleAttribute(nattr,vattr);
tr->set(c);
tr->to_xml(xml);
CPPUNIT_ASSERT(tr_xml == xml);
}
/* --------------------------------------------------------------------- */
void test_erase()
{
// There are Single and Vector type attributes, and any att. can be
// unique within the template, or not.
int n;
// Non-existing attribute
n = t1->erase("NON_EXISTING_ATT");
CPPUNIT_ASSERT( n == 0 );
// CPU is a Unique & Single Att.
n = t1->erase("CPU");
CPPUNIT_ASSERT( n == 1 );
// GRAPHICS is a Unique & Vector Att.
n = t1->erase("GRAPHICS");
CPPUNIT_ASSERT( n == 1 );
// MEMORY is now a Multiple & Single Att.
SingleAttribute* satt = new SingleAttribute("MEMORY", "123");
t1->set(satt);
n = t1->erase("MEMORY");
CPPUNIT_ASSERT( n == 2 );
// DISK is a Multiple & Vector Att.
n = t1->erase("DISK");
CPPUNIT_ASSERT( n == 2 );
}
/* --------------------------------------------------------------------- */
void test_from_xml()
{
string str1;
string str2;
Template t_xml;
int rc;
// Generate a xml from a Template generated from a text template
t1->to_xml(str1);
CPPUNIT_ASSERT(test_ok_xml == str1);
// Parse the xml in a new Template object
rc = t_xml.from_xml(str1);
CPPUNIT_ASSERT(rc == 0);
// Check correct output of this xml-generated Template object
t_xml.to_xml(str2);
CPPUNIT_ASSERT(str1 == str2);
str1 = "";
str2 = "";
t1->to_str(str1);
t_xml.to_str(str2);
CPPUNIT_ASSERT(str1 == str2);
}
};
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, TemplateTest::suite());
}

View File

@ -1,573 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 ( tpool != 0)
{
delete tpool;
}
if ( gpool != 0)
{
delete gpool;
}
if ( dspool != 0)
{
delete dspool;
}
if ( clpool != 0)
{
delete clpool;
}
if ( docpool != 0)
{
delete docpool;
}
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 ( imagem != 0 )
{
delete imagem;
}
if ( authm != 0)
{
delete authm;
}
if ( aclm != 0)
{
delete aclm;
}
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;
hook_location = nebula_location + "hooks/";
remotes_location = nebula_location + "var/remotes/";
/*if ( nebula_configuration != 0)
{
delete nebula_configuration;
}*/
nebula_configuration = new OpenNebulaTemplate(etc_location, var_location);
xmlInitParser();
// -----------------------------------------------------------
// Pools
// -----------------------------------------------------------
try
{
vector<const Attribute *> dbs;
db = OneUnitTest::get_db();
NebulaLog::log("ONE",Log::INFO,"Bootstraping OpenNebula database.");
bootstrap();
VirtualMachinePool::bootstrap(db);
HostPool::bootstrap(db);
VirtualNetworkPool::bootstrap(db);
UserPool::bootstrap(db);
ImagePool::bootstrap(db);
VMTemplatePool::bootstrap(db);
GroupPool::bootstrap(db);
AclManager::bootstrap(db);
DatastorePool::bootstrap(db);
ClusterPool::bootstrap(db);
DocumentPool::bootstrap(db);
}
catch (exception&)
{
throw;
}
// -----------------------------------------------------------
try
{
string mac_prefix = "00:02";
int size = 126;
string default_image_type = "OS";
string default_device_prefix = "hd";
if (tester->need_cluster_pool)
{
clpool = tester->create_clpool(db);
}
if (tester->need_document_pool)
{
docpool = tester->create_docpool(db);
}
if (tester->need_vm_pool)
{
vmpool = tester->create_vmpool(db,hook_location,var_location);
}
if (tester->need_host_pool)
{
hpool = tester->create_hpool(db,hook_location,var_location);
}
if (tester->need_vnet_pool)
{
vnpool = tester->create_vnpool(db,mac_prefix,size);
}
if (tester->need_group_pool)
{
gpool = tester->create_gpool(db);
}
if (tester->need_user_pool)
{
upool = tester->create_upool(db);
}
if (tester->need_image_pool)
{
ipool = tester->create_ipool(db,
default_image_type,
default_device_prefix);
}
if (tester->need_template_pool)
{
tpool = tester->create_tpool(db);
}
if (tester->need_datastore_pool)
{
dspool = tester->create_dspool(db);
}
}
catch (exception&)
{
throw;
}
// -----------------------------------------------------------
//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");
}
}
// ---- 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");
}
}
}
// ---- ACL Manager ----
if (tester->need_aclm)
{
try
{
aclm = new AclManager(db);
}
catch (bad_alloc&)
{
throw;
}
rc = aclm->start();
if ( rc != 0 )
{
throw runtime_error("Could not start the ACL Manager");
}
}
// ---- Image Manager ----
if (tester->need_imagem)
{
try
{
imagem = tester->create_imagem(ipool);
}
catch (bad_alloc&)
{
throw;
}
if (imagem != 0)
{
rc = imagem->start();
if ( rc != 0 )
{
throw runtime_error("Could not start the Image Manager");
}
}
}
// ---- Request Manager ----
if (tester->need_rm)
{
try
{
rm = tester->create_rm(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");
}
}
// -----------------------------------------------------------
// 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( imagem != 0 )
{
imagem->load_mads(0);
}
if( authm != 0 )
{
authm->load_mads(0);
}
// -----------------------------------------------------------
// Set DB pointer to null, to prevent its deletion on the destructor
// -----------------------------------------------------------
db = 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Nebula::bootstrap()
{
ostringstream oss;
oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, "
"last_oid BIGINT UNSIGNED)";
return db->exec(oss);
}

View File

@ -1,186 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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,
string vloc)
{
vector<const Attribute *> hooks;
vector<const Attribute *> restricted_attrs;
return new VirtualMachinePool(db, hooks, hook_location, vloc, restricted_attrs, 0);
}
HostPool* NebulaTest::create_hpool(SqlDB* db, string hook_location, string vloc)
{
vector<const Attribute *> hooks;
return new HostPool(db, hooks, hook_location, vloc, 0);
}
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,300);
}
ImagePool* NebulaTest::create_ipool( SqlDB* db,
string default_image_type,
string default_device_prefix)
{
vector<const Attribute *> restricted_attrs;
return new ImagePool(db, default_image_type, default_device_prefix, restricted_attrs);
}
VMTemplatePool* NebulaTest::create_tpool(SqlDB* db)
{
return new VMTemplatePool(db);
}
GroupPool* NebulaTest::create_gpool(SqlDB* db)
{
return new GroupPool(db);
}
DatastorePool* NebulaTest::create_dspool(SqlDB* db)
{
return new DatastorePool(db);
}
ClusterPool* NebulaTest::create_clpool(SqlDB* db)
{
return new ClusterPool(db);
}
DocumentPool* NebulaTest::create_docpool(SqlDB* db)
{
return new DocumentPool(db);
}
// -----------------------------------------------------------
// 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,
5,
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,
15,
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(string log_file)
{
int rm_port = 2633;
return new RequestManager(rm_port, log_file);
}
HookManager* NebulaTest::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);
}
AuthManager* NebulaTest::create_authm(time_t timer_period)
{
return 0;
}
AclManager* NebulaTest::create_aclm(SqlDB* db)
{
return new AclManager(db);
}
ImageManager* NebulaTest::create_imagem(ImagePool * ipool)
{
map<string,string> mad_value;
VectorAttribute * mad;
vector<const Attribute *> im_mads;
ostringstream oss;
// we need the full path (i.e, starting with '/')
// for the dummy executable
oss << getenv("PWD") << "/../../mad/test/dummy";
mad_value.insert(make_pair("EXECUTABLE",oss.str()));
mad = new VectorAttribute("IMAGE_MAD",mad_value);
im_mads.push_back(mad);
return new ImageManager(ipool,im_mads);
}

View File

@ -1,24 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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";

View File

@ -1,170 +0,0 @@
# SConstruct for src/test
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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'
if env['parsers']=='yes':
# LEX
parser=env.Lex(
source='../template/template_parser.l'
)
env.NoClean(parser)
# BISON
parser=env.Bison(
source='../template/template_syntax.y'
)
env.NoClean(parser)
# Sources to generate the library
source_files=[
'Nebula.cc',
'NebulaTest.cc',
'../acl/AclManager.cc',
'../acl/AclRule.cc',
'../authm/AuthManager.cc',
'../authm/AuthManagerDriver.cc',
'../cluster/Cluster.cc',
'../cluster/ClusterPool.cc',
'../common/mem_collector.c',
'../common/ActionManager.cc',
'../common/Attribute.cc',
'../common/SSLTools.cc',
'../datastore/Datastore.cc',
'../datastore/DatastorePool.cc',
'../dm/DispatchManager.cc',
'../dm/DispatchManagerActions.cc',
'../dm/DispatchManagerStates.cc',
'../document/Document.cc',
'../group/Group.cc',
'../group/GroupPool.cc',
'../hm/HookManager.cc',
'../hm/HookManagerDriver.cc',
'../host/Host.cc',
'../host/HostHook.cc',
'../host/HostPool.cc',
'../host/HostShare.cc',
'../im/InformationManager.cc',
'../im/InformationManagerDriver.cc',
'../image/Image.cc',
'../image/ImageManager.cc',
'../image/ImageManagerActions.cc',
'../image/ImageManagerDriver.cc',
'../image/ImagePool.cc',
'../image/ImageTemplate.cc',
'../lcm/LifeCycleActions.cc',
'../lcm/LifeCycleManager.cc',
'../lcm/LifeCycleStates.cc',
'../log/Log.cc',
'../log/NebulaLog.cc',
'../mad/Mad.cc',
'../mad/MadManager.cc',
# '../nebula/Nebula.cc',
'../nebula/NebulaTemplate.cc',
'../nebula/oned.cc',
'../pool/ObjectCollection.cc',
'../pool/PoolObjectAuth.cc',
'../pool/PoolObjectSQL.cc',
'../pool/PoolSQL.cc',
'../rm/Request.cc',
'../rm/RequestManager.cc',
'../rm/RequestManagerAcl.cc',
'../rm/RequestManagerAllocate.cc',
'../rm/RequestManagerChmod.cc',
'../rm/RequestManagerChown.cc',
'../rm/RequestManagerClone.cc',
'../rm/RequestManagerCluster.cc',
'../rm/RequestManagerDelete.cc',
'../rm/RequestManagerGroup.cc',
'../rm/RequestManagerHost.cc',
'../rm/RequestManagerImage.cc',
'../rm/RequestManagerInfo.cc',
'../rm/RequestManagerPoolInfoFilter.cc',
'../rm/RequestManagerUpdateTemplate.cc',
'../rm/RequestManagerUser.cc',
'../rm/RequestManagerVirtualMachine.cc',
'../rm/RequestManagerVirtualNetwork.cc',
'../rm/RequestManagerVMTemplate.cc',
# '../scheduler/src/client/Client.cc',
# '../scheduler/src/pool/AclXML.cc',
# '../scheduler/src/pool/HostPoolXML.cc',
# '../scheduler/src/pool/HostXML.cc',
# '../scheduler/src/pool/VirtualMachinePoolXML.cc',
# '../scheduler/src/pool/VirtualMachineXML.cc',
# '../scheduler/src/sched/mm_sched.cc',
# '../scheduler/src/sched/Scheduler.cc',
# '../scheduler/src/sched/SchedulerTemplate.cc',
'../sql/MySqlDB.cc',
'../sql/SqliteDB.cc',
'../template/Template.cc',
'../template/template_parser.c',
'../template/template_syntax.cc',
'../tm/TransferManager.cc',
'../tm/TransferManagerDriver.cc',
'../um/Quota.cc',
'../um/QuotaDatastore.cc',
'../um/QuotaImage.cc',
'../um/QuotaNetwork.cc',
'../um/Quotas.cc',
'../um/QuotaVirtualMachine.cc',
'../um/User.cc',
'../um/UserPool.cc',
'../vm/vm_var_parser.c',
'../vm/History.cc',
'../vm/VirtualMachine.cc',
'../vm/VirtualMachineHook.cc',
'../vm/VirtualMachinePool.cc',
'../vm/VirtualMachineTemplate.cc',
'../vm/vm_var_syntax.cc',
'../vm_template/VMTemplate.cc',
'../vm_template/VMTemplatePool.cc',
'../vmm/LibVirtDriverKVM.cc',
'../vmm/LibVirtDriverVMware.cc',
'../vmm/VirtualMachineManager.cc',
'../vmm/VirtualMachineManagerDriver.cc',
'../vmm/XenDriver.cc',
'../vmm/XMLDriver.cc',
'../vnm/FixedLeases.cc',
'../vnm/Leases.cc',
'../vnm/RangedLeases.cc',
'../vnm/VirtualNetwork.cc',
'../vnm/VirtualNetworkPool.cc',
'../xml/expr_parser.c',
'../xml/expr_arith.cc',
'../xml/expr_bool.cc',
'../xml/ObjectXML.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

@ -1 +0,0 @@
one_user_test:password

View File

@ -1,49 +0,0 @@
# --------------------------------------------------------------------------
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
#
# 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_vmm',
'nebula_lcm',
'nebula_im',
'nebula_hm',
'nebula_rm',
'nebula_datastore',
'nebula_dm',
'nebula_tm',
'nebula_um',
'nebula_group',
'nebula_authm',
'nebula_acl',
'nebula_mad',
'nebula_template',
'nebula_image',
'nebula_pool',
'nebula_cluster',
'nebula_host',
'nebula_vnm',
'nebula_vm',
'nebula_vmtemplate',
'nebula_common',
'nebula_sql',
'nebula_log',
'nebula_xml',
'crypto'
])
env.Program('test','UserPoolTest.cc')

View File

@ -1,385 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include "UserPool.h"
#include "PoolTest.h"
#include "SSLTools.h"
using namespace std;
/* ************************************************************************* */
/* ************************************************************************* */
const string usernames[] = { "A_user", "B_user", "C_user", "D_user", "E_user" };
const string passwords[] = { "A_pass", "B_pass", "C_pass", "D_pass", "E_pass" };
const string passwords_db[] = {
"a5ef2d19f923e1daf3f81a44707d0689c41d5118",
"d21f526a8032ed3e49e92f2abb134d0e113cffc7",
"49830f2084a232a65a75fc484bf6de614a8e2156",
"db3ee01bfda41592247491d69bf4208d4e79c102",
"3ecc357d5f8aa63b737e6201f05dfca11646ffbb"};
#include "NebulaTest.h"
class NebulaTestUser: public NebulaTest
{
public:
NebulaTestUser():NebulaTest()
{
NebulaTest::the_tester = this;
need_group_pool = true;
need_user_pool = true;
}
};
class UserPoolTest : public PoolTest
{
CPPUNIT_TEST_SUITE (UserPoolTest);
// Not all tests from PoolTest can be used. Because
// of the initial user added to the DB, the oid_assignment would fail.
CPPUNIT_TEST (get_from_cache);
CPPUNIT_TEST (get_from_db);
CPPUNIT_TEST (wrong_get);
CPPUNIT_TEST (drop_and_get);
CPPUNIT_TEST (sha1_digest);
CPPUNIT_TEST (split_secret);
CPPUNIT_TEST (initial_user);
CPPUNIT_TEST (authenticate);
CPPUNIT_TEST (get_using_name);
CPPUNIT_TEST (wrong_get_name);
CPPUNIT_TEST (update);
CPPUNIT_TEST (duplicates);
CPPUNIT_TEST (name_index);
CPPUNIT_TEST_SUITE_END ();
protected:
NebulaTestUser * tester;
UserPool * upool;
GroupPool * gpool;
void bootstrap(SqlDB* db)
{
// setUp overwritten
};
PoolSQL* create_pool(SqlDB* db)
{
// setUp overwritten
return upool;
};
int allocate(int index)
{
int oid;
string err;
return ((UserPool*)pool)->allocate(&oid, 0, usernames[index],"oneadmin",
passwords[index], UserPool::CORE_AUTH, true, err);
};
void check(int index, PoolObjectSQL* obj)
{
CPPUNIT_ASSERT( obj != 0 );
string name = ((User*)obj)->get_name();
CPPUNIT_ASSERT( name == usernames[index] );
CPPUNIT_ASSERT( ((User*)obj)->get_password() == passwords_db[index] );
};
public:
UserPoolTest(){xmlInitParser();};
~UserPoolTest(){xmlCleanupParser();};
void setUp()
{
create_db();
tester = new NebulaTestUser();
Nebula& neb = Nebula::instance();
neb.start();
upool = neb.get_upool();
gpool = neb.get_gpool();
pool = upool;
};
void tearDown()
{
delete_db();
delete tester;
};
/* ********************************************************************* */
/* ********************************************************************* */
void sha1_digest()
{
string st = "top_secret_string";
string sha1 = "773260f433f7fd6f89c1f1bfc32e080fc0748478";
CPPUNIT_ASSERT( sha1 == SSLTools::sha1_digest(st) );
}
void split_secret()
{
string secret = "left_part-user.N AME:pass--word..SECRET?";
string left = "";
string right = "";
User::split_secret(secret, left, right);
CPPUNIT_ASSERT( left == "left_part-user.N AME" );
CPPUNIT_ASSERT( right == "pass--word..SECRET?" );
}
void initial_user()
{
// When creating a new pool, the constructor will check if the DB
// contains at least one user.
// If it doesn't, it adds one automatically from:
// * The $ONE_AUTH file.
// * The ~/.one/one_auth file.
// The ONE_AUTH environment variable was forced to point to a prepared
// one_auth file at set-up, so the pool should contain the user
// one_user_test:password
User* user = (User*) pool->get(0, false);
CPPUNIT_ASSERT(user != 0);
CPPUNIT_ASSERT( user->get_oid() == 0 );
CPPUNIT_ASSERT( user->get_name() == "one_user_test" );
CPPUNIT_ASSERT( user->get_password() == SSLTools::sha1_digest("password") );
}
void authenticate()
{
UserPool* user_pool = (UserPool*) pool;
bool rc;
int oid, gid;
string uname, gname;
// There is an initial user, created with the one_auth file:
// one_user_test:password
string session="one_user_test:password";
rc = user_pool->authenticate( session, oid, gid, uname, gname);
CPPUNIT_ASSERT( rc == true );
CPPUNIT_ASSERT( oid == 0 );
CPPUNIT_ASSERT( gid == 0 );
CPPUNIT_ASSERT( uname == "one_user_test" );
CPPUNIT_ASSERT( gname == "oneadmin" );
session = "one_user_test:wrong_password";
rc = user_pool->authenticate( session, oid, gid , uname, gname);
CPPUNIT_ASSERT( rc == false );
CPPUNIT_ASSERT( oid == -1 );
CPPUNIT_ASSERT( gid == -1 );
session = "unknown_user:password";
rc = user_pool->authenticate( session, oid, gid, uname, gname);
CPPUNIT_ASSERT( rc == false );
CPPUNIT_ASSERT( oid == -1 );
CPPUNIT_ASSERT( gid == -1 );
}
void get_using_name()
{
int oid_0;
// Allocate two objects
oid_0 = allocate(0);
allocate(1);
// ---------------------------------
// Get first object and check its integrity
obj = pool->get(oid_0, false);
CPPUNIT_ASSERT( obj != 0 );
check(0, obj);
// Get using its name
obj = ((UserPool*)pool)->get(usernames[1], true);
check(1, obj);
obj->unlock();
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
pool->clean();
// Get first object and check its integrity
obj = pool->get(oid_0, false);
check(0, obj);
// Get using its name
obj = ((UserPool*)pool)->get(usernames[1], true);
check(1, obj);
obj->unlock();
};
void wrong_get_name()
{
// The pool is empty
// Non existing name
obj = ((UserPool*)pool)->get("Wrong name", true);
CPPUNIT_ASSERT( obj == 0 );
// Allocate an object
allocate(0);
// Ask again for a non-existing name
obj = ((UserPool*)pool)->get("Non existing name", true);
CPPUNIT_ASSERT( obj == 0 );
}
void update()
{
int oid;
User* user;
oid = allocate(2);
user = ((UserPool*)pool)->get(oid, true);
user->disable();
pool->update(user);
user->unlock();
// Check the cache
user = ((UserPool*)pool)->get(oid,false);
CPPUNIT_ASSERT( user->isEnabled() == false );
//Now force access to DB
pool->clean();
user = ((UserPool*)pool)->get(oid,false);
CPPUNIT_ASSERT( user != 0 );
CPPUNIT_ASSERT( user->isEnabled() == false );
};
void duplicates()
{
int rc, oid;
string err;
UserPool * up = static_cast<UserPool *>(pool);
// Allocate a user.
rc = up->allocate(&oid, 0,usernames[0], "oneadmin",passwords[0], UserPool::CORE_AUTH,true, err);
CPPUNIT_ASSERT( oid == 2 );
CPPUNIT_ASSERT( oid == rc );
// Try to allocate twice the same user, should fail
rc = up->allocate(&oid, 0,usernames[0], "oneadmin", passwords[0],UserPool::CORE_AUTH,true, err);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == rc );
// Try again, with different password
rc = up->allocate(&oid, 0, usernames[0], "oneadmin", passwords[1],UserPool::CORE_AUTH,true, err);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == rc );
}
void name_index()
{
User *user_oid, *user_name;
int oid_0;
//int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
user_oid = upool->get(oid_0, true);
CPPUNIT_ASSERT(user_oid != 0);
name_0 = user_oid->get_name();
//uid_0 = user_oid->get_uid();
user_oid->unlock();
// Get by name and check it is the same object
user_name = upool->get(name_0, true);
CPPUNIT_ASSERT(user_name != 0);
user_name->unlock();
CPPUNIT_ASSERT(user_oid == user_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
upool->clean();
// Get by oid
user_oid = upool->get(oid_0, true);
CPPUNIT_ASSERT(user_oid != 0);
user_oid->unlock();
// Get by name and check it is the same object
user_name = upool->get(name_0, true);
CPPUNIT_ASSERT(user_name != 0);
user_name->unlock();
CPPUNIT_ASSERT(user_oid == user_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
upool->clean();
// Get by name
user_name = upool->get(name_0, true);
CPPUNIT_ASSERT(user_name != 0);
user_name->unlock();
// Get by oid and check it is the same object
user_oid = upool->get(oid_0, true);
CPPUNIT_ASSERT(user_oid != 0);
user_oid->unlock();
CPPUNIT_ASSERT(user_oid == user_name);
}
};
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
OneUnitTest::set_one_auth();
return PoolTest::main(argc, argv, UserPoolTest::suite());
}

View File

@ -1,53 +0,0 @@
# --------------------------------------------------------------------------
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
#
# 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_lcm',
'nebula_tm',
'nebula_vmm',
'nebula_im',
'nebula_rm',
'nebula_dm',
'nebula_um',
'nebula_vm',
'nebula_hm',
'nebula_vnm',
'nebula_authm',
'nebula_acl',
'nebula_group',
'nebula_template',
'nebula_pool',
'nebula_host',
'nebula_vmtemplate',
'nebula_xml',
'nebula_image',
'nebula_datastore',
'nebula_cluster',
'nebula_um',
'nebula_mad',
'nebula_common',
'nebula_log',
'nebula_core',
'nebula_sql',
'crypto'
])
nt = env.Object('NebulaTemplateTest.o', '../../nebula/NebulaTemplate.cc')
env.Program('test',[nt,'VirtualMachinePoolTest.cc'])

View File

@ -1,317 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include "VirtualMachinePool.h"
#include "ImagePool.h"
#include "PoolTest.h"
using namespace std;
const int uids[] = {123, 261, 123};
const string names[] = {"VM one", "Second VM", "VM one"};
const string memory[] = {"128", "256", "1024"};
const string templates[] =
{
"NAME = \"VM one\"\n"
"MEMORY = 128\n"
"CPU = 1",
"NAME = \"Second VM\"\n"
"MEMORY = 256\n"
"CPU = 2",
"NAME = \"VM one\"\n"
"MEMORY = 1024\n"
"CPU = 1"
};
/* ************************************************************************* */
/* ************************************************************************* */
#include "NebulaTest.h"
class NebulaTestVM: public NebulaTest
{
public:
NebulaTestVM():NebulaTest()
{
NebulaTest::the_tester = this;
need_vm_pool = true;
}
};
class VirtualMachinePoolFriend : public VirtualMachinePool
{
public:
VirtualMachinePoolFriend(
SqlDB * db,
vector<const Attribute *> hook_mads,
vector<const Attribute *> restricted_attrs):
VirtualMachinePool(db, hook_mads,
"./", "./", restricted_attrs, 0)
{};
int allocate (
int uid,
const string& stemplate,
int * oid,
bool on_hold = false)
{
VirtualMachineTemplate * vm_template;
char * error_msg = 0;
int rc;
string err;
vm_template = new VirtualMachineTemplate;
rc = vm_template->parse(stemplate,&error_msg);
if( rc == 0 )
{
return VirtualMachinePool::allocate(uid, 1, "the_user", "users",vm_template,
oid, err, on_hold);
}
else
{
return -1;
}
};
};
/* ************************************************************************* */
/* ************************************************************************* */
class VirtualMachinePoolTest : public PoolTest
{
CPPUNIT_TEST_SUITE (VirtualMachinePoolTest);
// Not all PoolTest tests can be used. Drop method isn't defined for
// the VirtualMachinePool.
CPPUNIT_TEST (oid_assignment);
CPPUNIT_TEST (get_from_cache);
CPPUNIT_TEST (get_from_db);
CPPUNIT_TEST (wrong_get);
CPPUNIT_TEST (update);
CPPUNIT_TEST (history);
CPPUNIT_TEST_SUITE_END ();
protected:
NebulaTestVM * tester;
VirtualMachinePool * vmpool;
void bootstrap(SqlDB* db)
{
// setUp overwritten
};
PoolSQL* create_pool(SqlDB* db)
{
// setUp overwritten
return vmpool;
};
int allocate(int index)
{
int oid;
return ((VirtualMachinePoolFriend*)pool)->allocate( uids[index],
templates[index],
&oid, false);
};
void check(int index, PoolObjectSQL* obj)
{
string st;
CPPUNIT_ASSERT( obj != 0 );
VirtualMachine* vm = static_cast<VirtualMachine*>(obj);
ObjectXML xml(vm->to_xml(st));
CPPUNIT_ASSERT( vm->get_name() == names[index] );
xml.xpath(st, "/VM/TEMPLATE/MEMORY", "-");
CPPUNIT_ASSERT( st == memory[index] );
};
public:
VirtualMachinePoolTest(){xmlInitParser();};
~VirtualMachinePoolTest(){xmlCleanupParser();};
void setUp()
{
create_db();
tester = new NebulaTestVM();
Nebula& neb = Nebula::instance();
neb.start();
vmpool = neb.get_vmpool();
pool = vmpool;
};
void tearDown()
{
// -----------------------------------------------------------
// Stop the managers & free resources
// -----------------------------------------------------------
//XML Library
xmlCleanupParser();
delete_db();
delete tester;
};
/* ********************************************************************* */
/* ********************************************************************* */
void update()
{
VirtualMachinePool * vmp = static_cast<VirtualMachinePool*>(pool);
VirtualMachine * vm;
int oid;
string hostname = "hostname";
string vm_dir = "vm_dir";
string vmm_mad = "vm_mad";
// Allocate two VMs
oid = allocate(0);
CPPUNIT_ASSERT( oid != -1 );
// Get the first one, and change one of the templates attributes
vm = vmp->get(oid, true);
CPPUNIT_ASSERT( vm != 0 );
string attribute = "MEMORY";
string value = "1024";
vm->set_state(VirtualMachine::ACTIVE);
// VirtualMachine object should be cached. Let's update the DB
vm->replace_template_attribute(attribute, value);
vmp->update(vm);
//In memory (cache) check
string new_mem;
vm->get_template_attribute("MEMORY",new_mem);
CPPUNIT_ASSERT( new_mem == "1024" );
CPPUNIT_ASSERT( vm->get_state() == VirtualMachine::ACTIVE );
vm->unlock();
//Now force access to DB
pool->clean();
vm = vmp->get(oid,false);
new_mem.clear();
vm->get_template_attribute("MEMORY",new_mem);
CPPUNIT_ASSERT( new_mem == "1024" );
CPPUNIT_ASSERT( vm->get_state() == VirtualMachine::ACTIVE );
};
void history()
{
VirtualMachine * vm;
VirtualMachinePoolFriend * vmp =
static_cast<VirtualMachinePoolFriend*>(pool);
int rc, oid;
string hostname = "hostname";
string new_hostname = "new_hostname";
string vmm_mad = "vm_mad";
string vnm_mad = "vn_mad";
string tm_mad = "tm_mad";
int ds_id = 1;
// Allocate a VM
oid = allocate(0);
CPPUNIT_ASSERT( oid != -1 );
vm = vmp->get(oid, false);
CPPUNIT_ASSERT( vm != 0 );
// Add a history item
vm->add_history(0, hostname, vmm_mad, vnm_mad, tm_mad, ds_id);
rc = vmp->update(vm);
CPPUNIT_ASSERT( rc == 0 );
rc = vmp->update_history(vm);
CPPUNIT_ASSERT( rc == 0 );
vm->add_history(0, new_hostname, vmm_mad, vnm_mad, tm_mad, ds_id);
rc = vmp->update(vm);
CPPUNIT_ASSERT( rc == 0 );
vm->set_reason(History::USER);
vm->set_previous_reason(History::ERROR);
rc = vmp->update_history(vm);
rc = vmp->update_previous_history(vm);
CPPUNIT_ASSERT( rc == 0 );
// Clean the DB cache
pool->clean();
vm = vmp->get(oid, false);
CPPUNIT_ASSERT( vm != 0 );
CPPUNIT_ASSERT( vm->hasHistory() == true );
CPPUNIT_ASSERT( vm->hasPreviousHistory() == true );
CPPUNIT_ASSERT( vm->get_hostname() == new_hostname );
CPPUNIT_ASSERT( vm->get_previous_hostname() == hostname );
CPPUNIT_ASSERT( vm->get_vmm_mad() == vmm_mad );
CPPUNIT_ASSERT( vm->get_previous_vmm_mad() == vmm_mad );
CPPUNIT_ASSERT( vm->get_previous_reason() == History::ERROR );
}
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return PoolTest::main(argc, argv, VirtualMachinePoolTest::suite());
}

View File

@ -1,24 +0,0 @@
# --------------------------------------------------------------------------
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
#
# 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'
])
env.Program('test','VMTemplatePoolTest.cc')

View File

@ -1,512 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include "VMTemplatePool.h"
#include "PoolTest.h"
using namespace std;
const int uids[] = {0,1,2};
const string names[] = {"Template one", "Second Template", "Third Template"};
const string mojo[] = {"1", "2", "3"};
const string templates[] =
{
"NAME = \"Template one\"\n"
"MEMORY = 128\n"
"CPU = 1\n"
"MOJO = 1",
"NAME = \"Second Template\"\n"
"MEMORY = 256\n"
"CPU = 2\n"
"MOJO = 2",
"NAME = \"Third Template\"\n"
"MEMORY = 1024\n"
"CPU = 3\n"
"MOJO = 3",
};
class VMTemplatePoolFriend : public VMTemplatePool
{
public:
VMTemplatePoolFriend(SqlDB * db) : VMTemplatePool(db){};
int allocate(int uid,
const string& stemplate,
int * oid)
{
VirtualMachineTemplate * template_contents;
char * error_msg = 0;
int rc;
string err;
template_contents = new VirtualMachineTemplate();
rc = template_contents->parse(stemplate,&error_msg);
if( rc == 0 )
{
return VMTemplatePool::allocate(uid, 0,"the_user","oneadmin",template_contents, oid, err);
}
else
{
if (error_msg != 0 )
{
free(error_msg);
}
delete template_contents;
return -2;
}
};
};
/* ************************************************************************* */
/* ************************************************************************* */
class VMTemplatePoolTest : public PoolTest
{
CPPUNIT_TEST_SUITE (VMTemplatePoolTest);
ALL_POOLTEST_CPPUNIT_TESTS();
CPPUNIT_TEST ( names_initialization );
CPPUNIT_TEST ( clone_template );
CPPUNIT_TEST ( update );
CPPUNIT_TEST ( get_using_name );
CPPUNIT_TEST ( wrong_get_name );
CPPUNIT_TEST ( duplicates );
CPPUNIT_TEST ( name_index );
CPPUNIT_TEST ( chown_name_index );
CPPUNIT_TEST_SUITE_END ();
protected:
void bootstrap(SqlDB* db)
{
VMTemplatePool::bootstrap(db);
};
PoolSQL* create_pool(SqlDB* db)
{
return new VMTemplatePoolFriend(db);
};
int allocate(int index)
{
int oid;
return ((VMTemplatePoolFriend*)pool)->allocate(uids[index],
templates[index],
&oid);
};
void check(int index, PoolObjectSQL* obj)
{
string st;
CPPUNIT_ASSERT( obj != 0 );
VMTemplate* tmpl = static_cast<VMTemplate*>(obj);
ObjectXML xml(tmpl->to_xml(st));
CPPUNIT_ASSERT( tmpl->get_name() == names[index] );
xml.xpath(st, "/VMTEMPLATE/TEMPLATE/MOJO", "-");
CPPUNIT_ASSERT( st == mojo[index] );
};
public:
VMTemplatePoolTest(){xmlInitParser();};
~VMTemplatePoolTest(){xmlCleanupParser();};
/* ********************************************************************* */
void names_initialization()
{
VMTemplatePoolFriend * tpool;
VMTemplate * temp;
// Allocate 2 Templates, so they are written to the DB.
allocate(0);
allocate(2);
// Create a new pool, using the same DB. This new pool should read the
// allocated Templates.
tpool = new VMTemplatePoolFriend(db);
temp = tpool->get(names[0], uids[0], false);
CPPUNIT_ASSERT( temp != 0 );
temp = tpool->get(names[1], uids[1], false);
CPPUNIT_ASSERT( temp == 0 );
temp = tpool->get(names[2], uids[2], false);
CPPUNIT_ASSERT( temp != 0 );
delete tpool;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void clone_template()
{
string attr_temp;
string attr_vmt;
string name1 = "NAME";
string name2 = "MEMORY";
VMTemplatePoolFriend * tpool;
VMTemplate * temp;
VirtualMachineTemplate * vmt;
int oid_1;
tpool = static_cast<VMTemplatePoolFriend *>(pool);
oid_1 = allocate(0);
temp = tpool->get(oid_1, true);
CPPUNIT_ASSERT( temp != 0 );
vmt = temp->clone_template();
vmt->get(name1,attr_vmt);
CPPUNIT_ASSERT( attr_vmt == "Template one");
temp->get_template_attribute(name1.c_str(), attr_temp);
CPPUNIT_ASSERT( attr_temp == "Template one");
temp->replace_template_attribute(name2.c_str(), "1024");
vmt->get(name2,attr_vmt);
CPPUNIT_ASSERT( attr_vmt == "128");
temp->get_template_attribute(name2.c_str(), attr_temp);
CPPUNIT_ASSERT( attr_temp == "1024");
delete vmt;
temp->get_template_attribute(name2.c_str(), attr_temp);
CPPUNIT_ASSERT( attr_temp == "1024");
tpool->update(temp);
temp->unlock();
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void update()
{
string description_name = "DESCRIPTION";
string description_val = "";
string new_description = "A new description";
string attr_name = "NEW_ATTRIBUTE";
string attr_val = "";
string new_attr_value = "New value";
string no_value = "Some random value";
VMTemplatePoolFriend * tpool;
VMTemplate * temp;
int oid_1;
tpool = static_cast<VMTemplatePoolFriend *>(pool);
oid_1 = allocate(0);
temp = tpool->get(oid_1, true);
CPPUNIT_ASSERT( temp != 0 );
// Object should be cached. Let's change some template attributes
temp->replace_template_attribute(description_name, new_description);
temp->replace_template_attribute(attr_name, new_attr_value);
temp->remove_template_attribute("ORIGINAL_PATH");
tpool->update(temp);
temp->unlock();
temp = tpool->get(oid_1,false);
CPPUNIT_ASSERT( temp != 0 );
temp->get_template_attribute("DESCRIPTION", description_val);
temp->get_template_attribute("NEW_ATTRIBUTE", attr_val);
temp->get_template_attribute("ORIGINAL_PATH", no_value);
CPPUNIT_ASSERT( description_val == new_description );
CPPUNIT_ASSERT( attr_val == new_attr_value );
CPPUNIT_ASSERT( no_value == "" );
//Now force access to DB
pool->clean();
temp = tpool->get(oid_1,false);
CPPUNIT_ASSERT( temp != 0 );
description_val = "";
attr_val = "";
no_value = "Random value";
temp->get_template_attribute("DESCRIPTION", description_val);
temp->get_template_attribute("NEW_ATTRIBUTE", attr_val);
temp->get_template_attribute("ORIGINAL_PATH", no_value);
CPPUNIT_ASSERT( description_val == new_description );
CPPUNIT_ASSERT( attr_val == new_attr_value );
CPPUNIT_ASSERT( no_value == "" );
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void get_using_name()
{
int oid_0, oid_1;
VMTemplatePool * tpool = static_cast<VMTemplatePool*>(pool);
// Allocate two objects
oid_0 = allocate(0);
oid_1 = allocate(1);
// ---------------------------------
// Get first object and check its integrity
obj = tpool->get(oid_0, false);
CPPUNIT_ASSERT( obj != 0 );
check(0, obj);
// Get using its name
obj = tpool->get(names[1], uids[1], true);
CPPUNIT_ASSERT( obj != 0 );
obj->unlock();
check(1, obj);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
tpool->clean();
// Get first object and check its integrity
obj = tpool->get(names[0], uids[0], false);
check(0, obj);
// Get using its name
obj = tpool->get(oid_1, false);
check(1, obj);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void wrong_get_name()
{
VMTemplatePool * tpool = static_cast<VMTemplatePool*>(tpool);
// The pool is empty
// Non existing name
obj = tpool->get("Wrong name", 0, true);
CPPUNIT_ASSERT( obj == 0 );
// Allocate an object
allocate(0);
// Ask again for a non-existing name
obj = tpool->get("Non existing name",uids[0], true);
CPPUNIT_ASSERT( obj == 0 );
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void duplicates()
{
int rc, oid;
VMTemplatePoolFriend * tpool = static_cast<VMTemplatePoolFriend*>(pool);
// Allocate a template
rc = tpool->allocate(uids[0], templates[0], &oid);
CPPUNIT_ASSERT( oid == 0 );
CPPUNIT_ASSERT( oid == rc );
// Try to allocate twice the same template, should fail
rc = tpool->allocate(uids[0], templates[0], &oid);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == rc );
// Try again, this time with different uid. Should be allowed
rc = tpool->allocate(uids[1], templates[0], &oid);
CPPUNIT_ASSERT( rc >= 0 );
CPPUNIT_ASSERT( oid == rc );
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void name_index()
{
VMTemplatePool *tpool = static_cast<VMTemplatePool*>(pool);
VMTemplate *vnet_oid, *vnet_name;
int oid_0;
int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
vnet_oid = tpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
name_0 = vnet_oid->get_name();
uid_0 = vnet_oid->get_uid();
vnet_oid->unlock();
// Get by name and check it is the same object
vnet_name = tpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
tpool->clean();
// Get by oid
vnet_oid = tpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
vnet_oid->unlock();
// Get by name and check it is the same object
vnet_name = tpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
tpool->clean();
// Get by name
vnet_name = tpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
// Get by oid and check it is the same object
vnet_oid = tpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
vnet_oid->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void chown_name_index()
{
VMTemplatePool *tpool = static_cast<VMTemplatePool*>(pool);
VMTemplate *obj_oid, *obj_name;
int oid;
int old_uid;
int new_uid = 3456;
string name;
oid = allocate(0);
CPPUNIT_ASSERT(oid != -1);
// ---------------------------------
// Get by oid
obj_oid = tpool->get(oid, true);
CPPUNIT_ASSERT(obj_oid != 0);
name = obj_oid->get_name();
old_uid = obj_oid->get_uid();
// Change owner and update cache index
obj_oid->set_user(new_uid, "new_username");
tpool->update(obj_oid);
obj_oid->unlock();
tpool->update_cache_index(name, old_uid, name, new_uid);
// Get by name, new_uid and check it is the same object
obj_name = tpool->get(name, new_uid, true);
CPPUNIT_ASSERT(obj_name != 0);
obj_name->unlock();
CPPUNIT_ASSERT(obj_oid == obj_name);
// Get by name, old_uid and check it does not exist
obj_name = tpool->get(name, old_uid, true);
CPPUNIT_ASSERT(obj_name == 0);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
tpool->clean();
// Get by name, old_uid and check it does not exist
obj_name = tpool->get(name, old_uid, true);
CPPUNIT_ASSERT(obj_name == 0);
// Get by oid
obj_oid = tpool->get(oid, true);
CPPUNIT_ASSERT(obj_oid != 0);
obj_oid->unlock();
// Get by name, new_uid and check it is the same object
obj_name = tpool->get(name, new_uid, true);
CPPUNIT_ASSERT(obj_name != 0);
obj_name->unlock();
CPPUNIT_ASSERT(obj_oid == obj_name);
}
/* ********************************************************************* */
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return PoolTest::main(argc, argv, VMTemplatePoolTest::suite());
}

View File

@ -1,49 +0,0 @@
# --------------------------------------------------------------------------
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs
#
# 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_vmm',
'nebula_lcm',
'nebula_im',
'nebula_hm',
'nebula_rm',
'nebula_datastore',
'nebula_cluster',
'nebula_dm',
'nebula_tm',
'nebula_um',
'nebula_group',
'nebula_authm',
'nebula_acl',
'nebula_mad',
'nebula_template',
'nebula_image',
'nebula_pool',
'nebula_host',
'nebula_vnm',
'nebula_vm',
'nebula_vmtemplate',
'nebula_common',
'nebula_sql',
'nebula_log',
'nebula_xml',
'crypto'
])
env.Program('test','VirtualNetworkPoolTest.cc')

File diff suppressed because it is too large Load Diff

View File

@ -1,471 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include <stdexcept>
#include "ObjectXML.h"
#include "test/OneUnitTest.h"
/* ************************************************************************* */
/* ************************************************************************* */
class ObjectXMLTest : public OneUnitTest
{
CPPUNIT_TEST_SUITE( ObjectXMLTest );
CPPUNIT_TEST( xpath_access );
CPPUNIT_TEST( node_constructor );
CPPUNIT_TEST( doc_update );
CPPUNIT_TEST( requirements );
CPPUNIT_TEST( rank );
CPPUNIT_TEST( xpath );
CPPUNIT_TEST( xpath_value );
CPPUNIT_TEST_SUITE_END ();
public:
void setUp()
{
xmlInitParser();
};
void tearDown()
{
xmlCleanupParser();
};
ObjectXMLTest(){};
~ObjectXMLTest(){};
/* ********************************************************************* */
/* ********************************************************************* */
void xpath_access()
{
try
{
ObjectXML obj(xml_history_dump);
vector<string> hostnames;
hostnames = obj["/VM_POOL/VM/HISTORY/HOSTNAME"];
CPPUNIT_ASSERT(hostnames.size() == 2);
CPPUNIT_ASSERT(hostnames[0] == "A_hostname");
CPPUNIT_ASSERT(hostnames[1] == "C_hostname");
}
catch(runtime_error& re)
{
cerr << re.what() << endl;
CPPUNIT_ASSERT(1 == 0);
}
};
void xpath_value()
{
int rc;
string im_mad;
rc = ObjectXML::xpath_value(im_mad,host.c_str(),"/HOST/IM_MAD");
CPPUNIT_ASSERT(rc == 0);
CPPUNIT_ASSERT(im_mad == "im_kvm");
rc = ObjectXML::xpath_value(im_mad,host.c_str(),"/HOST/NO_IM_MAD");
CPPUNIT_ASSERT(rc == -1);
};
void xpath()
{
try
{
ObjectXML obj(xml_history_dump);
string str_exists;
string str_no_exists;
int int_exists;
int int_no_exists;
int int_malformed;
int rc;
rc = obj.xpath(str_exists,"/VM_POOL/VM/HISTORY/HOSTNAME","default_host");
CPPUNIT_ASSERT(str_exists == "A_hostname");
CPPUNIT_ASSERT(rc == 0);
rc = obj.xpath(str_no_exists,"/VM_POOL/NOT_AN_ELEMENT","default_host");
CPPUNIT_ASSERT(str_no_exists == "default_host");
CPPUNIT_ASSERT(rc == -1);
rc = obj.xpath(int_exists,"/VM_POOL/VM/STATE",35);
CPPUNIT_ASSERT(int_exists == 1);
CPPUNIT_ASSERT(rc == 0);
rc = obj.xpath(int_no_exists,"/VM_POOL/NOT_AN_ELEMENT",35);
CPPUNIT_ASSERT(int_no_exists == 35);
CPPUNIT_ASSERT(rc == -1);
rc = obj.xpath(int_malformed,"/VM_POOL/VM/USERNAME",33);
CPPUNIT_ASSERT(int_malformed == 33);
CPPUNIT_ASSERT(rc == -1);
}
catch(runtime_error& re)
{
cerr << re.what() << endl;
CPPUNIT_ASSERT(1 == 0);
}
};
void node_constructor()
{
try
{
ObjectXML obj(xml_history_dump);
vector<xmlNodePtr> vms;
int num_vms;
num_vms = obj.get_nodes("/VM_POOL/VM",vms);
CPPUNIT_ASSERT(num_vms == 3);
ObjectXML obj_vm_1(vms[0]);
ObjectXML obj_vm_2(vms[1]);
vector<string> results;
results = obj_vm_1["/VM/HISTORY/HOSTNAME"];
CPPUNIT_ASSERT(results.size() == 0);
results.clear();
results = obj_vm_2["/VM/HISTORY/HOSTNAME"];
CPPUNIT_ASSERT(results.size() == 1);
CPPUNIT_ASSERT(results[0] == "A_hostname");
obj.free_nodes(vms);
}
catch(runtime_error& re)
{
cerr << re.what() << endl;
CPPUNIT_ASSERT(1 == 0);
}
};
void doc_update()
{
try
{
ObjectXML obj(xml_history_dump);
vector<string> hostnames;
hostnames = obj["/VM_POOL/VM/HISTORY/HOSTNAME"];
CPPUNIT_ASSERT(hostnames.size() == 2);
CPPUNIT_ASSERT(hostnames[0] == "A_hostname");
CPPUNIT_ASSERT(hostnames[1] == "C_hostname");
obj.update_from_str(xml_history_dump2);
hostnames = obj["/VM_POOL/VM/HISTORY/HOSTNAME"];
CPPUNIT_ASSERT(hostnames.size() == 2);
CPPUNIT_ASSERT(hostnames[0] == "0_hostname");
CPPUNIT_ASSERT(hostnames[1] == "1_hostname");
}
catch(runtime_error& re)
{
cerr << re.what() << endl;
CPPUNIT_ASSERT(1 == 0);
}
};
void requirements()
{
try
{
ObjectXML obj(host);
char* err;
bool res;
int rc;
// -----------------------------------------------------------------
// REQUIREMENTS MATCHING
// -----------------------------------------------------------------
string reqs[] =
{
"TOTALCPU = 800", // exact value matching
"TOTALCPU != 800", // Not equal
"TOTALCPU > 5", // Greater than expr.
"! (TOTALCPU > 5)", // Not exp.
"HOSTNAME = \"ursa12\"", // Exact string matching
"HOSTNAME = \"ursa*\"", // Shell wildcard
"HOSTNAME = \"ursa\"",
"HID = 1",
"ARCH = \"*64*\"",
"RUNNING_VMS < 100",
"CLUSTER = \"cluster A\"",
"CLUSTER = \"default\"",
"CLUSTER = clusterA",
"CLUSTER = \"Cluster A\"",
/*
// Boolean operators
"HOSTNAME = \"ursa*\" & NETRX = \"13335836573\"",
// Operator precedence
"HOSTNAME = \"ursa*\" | HOSTNAME = \"no\" & HOSTNAME = \"no\"",
"( HOSTNAME = \"ursa*\" | HOSTNAME = \"no\" ) & HOSTNAME = \"no\"",
//*/
"END"
};
bool results[] = { true, false, true, false,
true, true, false,
true, true, true,
true, false, false, false
/*
true, true, false,
//*/
};
int i = 0;
while( reqs[i] != "END" )
{
// cout << endl << i << " - " << reqs[i];
rc = obj.eval_bool( reqs[i], res, &err );
// cout << "··· rc: " << rc << " result: " << res << " expected: " << results[i] << endl;
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( res == results[i] );
i++;
}
// Non-existing attribute compared to string value
rc = obj.eval_bool( "FOO = \"BAR\"", res, &err );
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( res == false );
// Non-existing attribute compared to numeric value
rc = obj.eval_bool( "FOO = 123", res, &err );
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( res == false );
// Existing string attribute compared to numeric value
rc = obj.eval_bool( "HOSTNAME = 123 ", res, &err );
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( res == false );
// Existing numeric attribute compared to string value should work
rc = obj.eval_bool( "TOTALCPU = \"800\"", res, &err );
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( res == true );
// Bad syntax
// TODO: Right now eval_bool returns 1 in case of error, and result
// is not set to false.
rc = obj.eval_bool( "TOTALCPU ^ * - = abc", res, &err );
CPPUNIT_ASSERT( rc != 0 );
CPPUNIT_ASSERT( res == false );
if (err != 0)
{
free( err );
}
}
catch(runtime_error& re)
{
cerr << re.what() << endl;
CPPUNIT_ASSERT(1 == 0);
}
};
void rank()
{
try
{
ObjectXML obj(host);
char* err;
int res;
int rc;
// -----------------------------------------------------------------
// RANK EXPRESSIONS
// -----------------------------------------------------------------
string rank_exp[] =
{
"RUNNING_VMS", // Single attribute
"MAX_CPU + NETTX", // Simple operations
"RUNNING_VMS * 10", // Operations with fixed values
"- FREE_MEM", // Unary operator
"2 + 4 * 10", // Operator precedence
"(2 + 4) * 10",
"END"
};
int results[] =
{
12,
47959 + 800,
12 * 10,
-7959232,
2 + 4 * 10,
(2 + 4) * 10,
};
int i = 0;
while( rank_exp[i] != "END" )
{
// cout << endl << i << " - " << rank_exp[i];
rc = obj.eval_arith( rank_exp[i], res, &err );
// cout << "··· rc: " << rc << " res: " << res << " expected: " << results[i] << endl;
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( res == results[i] );
i++;
}
// Non-existing attribute
rc = obj.eval_arith( "FOO", res, &err );
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( res == 0 );
// Non-existing attribute and operators
rc = obj.eval_arith( "FOO + 10", res, &err );
CPPUNIT_ASSERT( rc == 0 );
CPPUNIT_ASSERT( res == 10 );
}
catch(runtime_error& re)
{
cerr << re.what() << endl;
CPPUNIT_ASSERT(1 == 0);
}
};
static const string xml_history_dump;
static const string xml_history_dump2;
static const string host;
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return OneUnitTest::main(argc, argv, ObjectXMLTest::suite());
}
// ----------------------------------------------------------------------------
const string ObjectXMLTest::xml_history_dump =
"<VM_POOL><VM><ID>0</ID><UID>0</UID><USERNAME>one_user_test</USERNAME>"
"<NAME>VM one</NAME><LAST_POLL>0</LAST_POLL><STATE>1</STATE><LCM_STATE>"
"0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID>"
"</DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>"
"0</NET_RX></VM><VM><ID>1</ID><UID>0</UID><USERNAME>"
"one_user_test</USERNAME><NAME>Second VM</NAME><LAST_POLL>0</LAST_POLL>"
"<STATE>2</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME>"
"<ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU>"
"<NET_TX>0</NET_TX><NET_RX>0</NET_RX><HISTORY><SEQ>0</SEQ><HOSTNAME>"
"A_hostname</HOSTNAME><HID>0</HID><STIME>0</STIME><ETIME>0</ETIME><PSTIME>"
"0</PSTIME><PETIME>0</PETIME><RSTIME>0</RSTIME><RETIME>0</RETIME><ESTIME>"
"0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY></VM><VM><ID>2"
"</ID><UID>0</UID><USERNAME>one_user_test</USERNAME><NAME>VM one</NAME>"
"<LAST_POLL>0</LAST_POLL><STATE>2</STATE><LCM_STATE>0</LCM_STATE><STIME>"
"0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0"
"</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><HISTORY><SEQ>1"
"</SEQ><HOSTNAME>C_hostname</HOSTNAME><HID>2</HID><STIME>0</STIME><ETIME>0"
"</ETIME><PSTIME>0</PSTIME><PETIME>0</PETIME><RSTIME>0</RSTIME><RETIME>0"
"</RETIME><ESTIME>0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY>"
"</VM></VM_POOL>";
const string ObjectXMLTest::xml_history_dump2 =
"<VM_POOL><VM><ID>0</ID><UID>0</UID><USERNAME>one_user_test</USERNAME>"
"<NAME>VM one</NAME><LAST_POLL>0</LAST_POLL><STATE>1</STATE><LCM_STATE>"
"0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID>"
"</DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>"
"0</NET_RX></VM><VM><ID>1</ID><UID>0</UID><USERNAME>"
"one_user_test</USERNAME><NAME>Second VM</NAME><LAST_POLL>0</LAST_POLL>"
"<STATE>2</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME>"
"<ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU>"
"<NET_TX>0</NET_TX><NET_RX>0</NET_RX><HISTORY><SEQ>0</SEQ><HOSTNAME>"
"0_hostname</HOSTNAME><HID>0</HID><STIME>0</STIME><ETIME>0</ETIME><PSTIME>"
"0</PSTIME><PETIME>0</PETIME><RSTIME>0</RSTIME><RETIME>0</RETIME><ESTIME>"
"0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY></VM><VM><ID>2"
"</ID><UID>0</UID><USERNAME>one_user_test</USERNAME><NAME>VM one</NAME>"
"<LAST_POLL>0</LAST_POLL><STATE>2</STATE><LCM_STATE>0</LCM_STATE><STIME>"
"0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0"
"</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><HISTORY><SEQ>1"
"</SEQ><HOSTNAME>1_hostname</HOSTNAME><HID>2</HID><STIME>0</STIME><ETIME>0"
"</ETIME><PSTIME>0</PSTIME><PETIME>0</PETIME><RSTIME>0</RSTIME><RETIME>0"
"</RETIME><ESTIME>0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY>"
"</VM></VM_POOL>";
const string ObjectXMLTest::host =
"<HOST>"
"<ID>1</ID>"
"<NAME>ursa12</NAME>"
"<STATE>2</STATE>"
"<IM_MAD>im_kvm</IM_MAD>"
"<VM_MAD>vmm_kvm</VM_MAD>"
"<TM_MAD>tm_shared</TM_MAD>"
"<LAST_MON_TIME>1273799044</LAST_MON_TIME>"
"<CLUSTER>cluster A</CLUSTER>"
"<HOST_SHARE>"
" <HID>1</HID>"
" <DISK_USAGE>0</DISK_USAGE>"
" <MEM_USAGE>0</MEM_USAGE>"
" <CPU_USAGE>0</CPU_USAGE>"
" <MAX_DISK>0</MAX_DISK>"
" <MAX_MEM>8194368</MAX_MEM>"
" <MAX_CPU>800</MAX_CPU>"
" <FREE_DISK>0</FREE_DISK>"
" <FREE_MEM>7959232</FREE_MEM>"
" <FREE_CPU>800</FREE_CPU>"
" <USED_DISK>0</USED_DISK>"
" <USED_MEM>523080</USED_MEM>"
" <USED_CPU>0</USED_CPU>"
" <RUNNING_VMS>12</RUNNING_VMS>"
"</HOST_SHARE>"
"<TEMPLATE>"
" <ARCH>x86_64</ARCH>"
" <CPUSPEED>2326</CPUSPEED>"
" <FREECPU>800.0</FREECPU>"
" <FREEMEMORY>7959232</FREEMEMORY>"
" <HOSTNAME>ursa12</HOSTNAME>"
" <HYPERVISOR>kvm</HYPERVISOR>"
" <MODELNAME>Intel(R) Xeon(R) CPU E5410 @ 2.33GHz</MODELNAME>"
" <NETRX>13335836573</NETRX>"
" <NETTX>47959</NETTX>"
" <TOTALCPU>800</TOTALCPU>"
" <TOTALMEMORY>8194368</TOTALMEMORY>"
" <USEDCPU>0.0</USEDCPU>"
" <USEDMEMORY>523080</USEDMEMORY>"
"</TEMPLATE>"
"</HOST>";

View File

@ -1,27 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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')
# Libraries
env.Prepend(LIBS=[
'nebula_log',
'nebula_xml',
'nebula_common',
'nebula_test_common',
])
env.Program('test_xml','ObjectXMLTest.cc')