mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
feature #457: Tests for the host hooks.
This commit is contained in:
parent
646cad78a9
commit
6b8855b0e3
120
src/host/test/HostHookTest.cc
Normal file
120
src/host/test/HostHookTest.cc
Normal file
@ -0,0 +1,120 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <fstream>
|
||||
|
||||
#include "HostPool.h"
|
||||
#include "PoolTest.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
class HostHookTest : public PoolTest
|
||||
{
|
||||
CPPUNIT_TEST_SUITE (HostHookTest);
|
||||
|
||||
CPPUNIT_TEST (allocate_hook);
|
||||
// CPPUNIT_TEST (error_hook);
|
||||
// CPPUNIT_TEST (disable_hook);
|
||||
CPPUNIT_TEST_SUITE_END ();
|
||||
|
||||
protected:
|
||||
|
||||
void bootstrap(SqlDB* db)
|
||||
{
|
||||
HostPool::bootstrap(db);
|
||||
};
|
||||
|
||||
PoolSQL* create_pool(SqlDB* db)
|
||||
{
|
||||
map<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","ERROR"));
|
||||
hook_value.insert(make_pair("COMMAND","/bin/touch"));
|
||||
hook_value.insert(make_pair("ARGUMENTS","/tmp/host_$HID"));
|
||||
hook_value.insert(make_pair("REMOTE","no"));
|
||||
|
||||
hook = new VectorAttribute("HOST_HOOK",hook_value);
|
||||
|
||||
|
||||
|
||||
host_hooks.push_back(hook);
|
||||
|
||||
return new HostPool(db,host_hooks,"./");
|
||||
};
|
||||
|
||||
int allocate(int index){return 0;};
|
||||
void check(int index, PoolObjectSQL* obj){};
|
||||
|
||||
public:
|
||||
HostHookTest(){xmlInitParser();};
|
||||
|
||||
~HostHookTest(){xmlCleanupParser();};
|
||||
|
||||
|
||||
/* ********************************************************************* */
|
||||
/* ********************************************************************* */
|
||||
|
||||
|
||||
void allocate_hook()
|
||||
{
|
||||
HostPool * hp = static_cast<HostPool *>(pool);
|
||||
|
||||
string err;
|
||||
int oid;
|
||||
|
||||
fstream fd;
|
||||
|
||||
hp->allocate(&oid, "host_test", "im_mad", "vmm_mad", "tm_mad", err);
|
||||
|
||||
Host* host = hp->get(oid, true);
|
||||
|
||||
CPPUNIT_ASSERT( host != 0 );
|
||||
|
||||
host->unlock();
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
oss << "/tmp/host_" << oid ;
|
||||
|
||||
fd.open(oss.str().c_str(), fstream::in | fstream::out );
|
||||
|
||||
CPPUNIT_ASSERT( fd.fail() == false );
|
||||
|
||||
fd.close();
|
||||
};
|
||||
|
||||
/* ********************************************************************* */
|
||||
};
|
||||
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
return PoolTest::main(argc, argv, HostHookTest::suite());
|
||||
}
|
@ -164,7 +164,9 @@ protected:
|
||||
|
||||
PoolSQL* create_pool(SqlDB* db)
|
||||
{
|
||||
return new HostPool(db);
|
||||
vector<const Attribute *> hook;
|
||||
|
||||
return new HostPool(db,hook,"./");
|
||||
};
|
||||
|
||||
int allocate(int index)
|
||||
|
@ -47,6 +47,8 @@ main_env.Append(LIBPATH=[
|
||||
cwd + '/src/pool',
|
||||
cwd + '/src/template',
|
||||
cwd + '/src/host',
|
||||
cwd + '/src/hm',
|
||||
cwd + '/src/mad',
|
||||
])
|
||||
|
||||
main_env.Append(LIBS=[
|
||||
@ -54,6 +56,8 @@ main_env.Append(LIBS=[
|
||||
'nebula_host',
|
||||
'nebula_template',
|
||||
'nebula_pool',
|
||||
'nebula_mad',
|
||||
'nebula_hm',
|
||||
'nebula_common',
|
||||
'nebula_core',
|
||||
'nebula_sql',
|
||||
@ -93,4 +97,5 @@ main_env.Append(CPPFLAGS=[
|
||||
main_env.Append(LDFLAGS=["-g "])
|
||||
|
||||
main_env.Program('test','HostPoolTest.cc')
|
||||
main_env.Program('test_hook','HostHookTest.cc')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user