Statistics
| Branch: | Tag: | Revision:

one / src / host / test / HostPoolTest.cc @ 6329d8b3

History | View | Annotate | Download (18.8 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

    
17
#include <string>
18
#include <iostream>
19
#include <stdlib.h>
20

    
21
#include "HostPool.h"
22
#include "PoolTest.h"
23

    
24
using namespace std;
25

    
26
const string im_mad  = "im_mad";
27
const string vmm_mad = "vmm_mad";
28
const string tm_mad  = "tm_mad";
29

    
30
const string names[] = {"Host one", "Second host"};
31

    
32
const string xmls[] =
33
{
34
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE>"
35
    "<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
36
    "<LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE>"
37
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
38
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
39
    "<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
40
    "<USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU>"
41
    "<RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>",
42

    
43
    "<HOST><ID>1</ID><NAME>Second host</NAME><STATE>0</STATE>"
44
    "<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
45
    "<LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE>"
46
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
47
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
48
    "<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
49
    "<USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU>"
50
    "<RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>"
51
};
52

    
53
// This xml dump result has the LAST_MON_TIMEs modified to 0000000000
54
const string xml_dump =
55
    "<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
56
    "M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
57
    "</LAST_MON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
58
    "_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
59
    ">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
60
    "MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
61
    "SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST>"
62
    "<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
63
    "D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
64
    "ON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
65
    "M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
66
    "<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
67
    "U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
68
    "SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>2</ID><N"
69
    "AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
70
    "M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOS"
71
    "T_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
72
    "_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
73
    "MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
74
    "U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
75
    "NING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>3</ID><NAME>another "
76
    "name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
77
    "<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHAR"
78
    "E><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
79
    ">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
80
    "U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
81
    "D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
82
    "MS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>4</ID><NAME>host</NAME><ST"
83
    "ATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad"
84
    "</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE>"
85
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
86
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0"
87
    "</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED"
88
    "_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_"
89
    "VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST></HOST_POOL>";
90

    
91
const string xml_dump_like_a =
92
    "<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
93
    "M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
94
    "</LAST_MON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
95
    "_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
96
    ">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
97
    "MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
98
    "SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST>"
99
    "<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
100
    "D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
101
    "ON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
102
    "M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
103
    "<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
104
    "U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
105
    "SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>2</ID><N"
106
    "AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
107
    "M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOS"
108
    "T_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
109
    "_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
110
    "MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
111
    "U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
112
    "NING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>3</ID><NAME>another "
113
    "name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
114
    "<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHAR"
115
    "E><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
116
    ">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
117
    "U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
118
    "D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
119
    "MS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST></HOST_POOL>";
120

    
121
const string host0_updated =
122
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE><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>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE><ATT_A><![CDATA[VALUE_A]]></ATT_A><ATT_B><![CDATA[VALUE_B]]></ATT_B></TEMPLATE></HOST>";
123

    
124
const string cluster_default =
125
    "<CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER>";
126

    
127
const string cluster_xml_dump =
128
    "<CLUSTER_POOL><CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER><CLUSTER><ID>1</ID><NAME>cluster_a</NAME></CLUSTER><CLUSTER><ID>3</ID><NAME>cluster_c</NAME></CLUSTER><CLUSTER><ID>4</ID><NAME>cluster_d</NAME></CLUSTER></CLUSTER_POOL>";
129

    
130
const string host_0_cluster =
131
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>cluster_a</CLUSTER><HOST_SHARE><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>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>";
132
/* ************************************************************************* */
133
/* ************************************************************************* */
134

    
135
class HostPoolTest : public PoolTest
136
{
137
    CPPUNIT_TEST_SUITE (HostPoolTest);
138

    
139
    ALL_POOLTEST_CPPUNIT_TESTS();
140

    
141
    CPPUNIT_TEST (update);
142
    CPPUNIT_TEST (dump);
143
    CPPUNIT_TEST (dump_where);
144
    CPPUNIT_TEST (discover);
145
    CPPUNIT_TEST (duplicates);
146
    CPPUNIT_TEST (update_info);
147

    
148
//    CPPUNIT_TEST (scale_test);
149

    
150
    CPPUNIT_TEST_SUITE_END ();
151

    
152
protected:
153

    
154
    void bootstrap(SqlDB* db)
155
    {
156
        HostPool::bootstrap(db);
157
    };
158

    
159
    PoolSQL* create_pool(SqlDB* db)
160
    {
161
        vector<const Attribute *> hook;
162

    
163
        return new HostPool(db,hook,"./");
164
    };
165

    
166
    int allocate(int index)
167
    {
168
        int    oid;
169
        string err;
170
        return ((HostPool*)pool)->allocate(&oid, names[index], im_mad,
171
                                           vmm_mad, tm_mad, err);
172
    };
173

    
174
    void check(int index, PoolObjectSQL* obj)
175
    {
176
        Host * host = static_cast<Host *>(obj);
177

    
178
        CPPUNIT_ASSERT( obj != 0 );
179

    
180
        string xml_str = "";
181
        string name = host->get_name();
182

    
183
        CPPUNIT_ASSERT( name == names[index] );
184

    
185
        // Get the xml
186
        host->to_xml(xml_str);
187

    
188
//  A little help for debugging
189
/*
190
        if( xml_str != xmls[index] )
191
        {
192
            cout << endl << xml_str << endl << "========"
193
                 << endl << xmls[index];
194
        }
195
//*/
196
        CPPUNIT_ASSERT( xml_str == xmls[index]);
197
    };
198

    
199

    
200
public:
201
    HostPoolTest(){xmlInitParser();};
202

    
203
    ~HostPoolTest(){xmlCleanupParser();};
204

    
205

    
206
    /* ********************************************************************* */
207
    /* ********************************************************************* */
208

    
209

    
210
    void update()
211
    {
212
        HostPool * hp = static_cast<HostPool *>(pool);
213
        int oid_1 = allocate(0);
214

    
215
        Host* host = hp->get(oid_1, true);
216
        CPPUNIT_ASSERT( host != 0 );
217

    
218
        // Host object should be cached. Let's update its status
219
        host->set_state(Host::DISABLED);
220
        pool->update(host);
221

    
222
        host->unlock();
223

    
224
        host = hp->get(oid_1,false);
225
        CPPUNIT_ASSERT( host != 0 );
226
        CPPUNIT_ASSERT( host->get_state() == Host::DISABLED );
227

    
228
        //Now force access to DB
229

    
230
        pool->clean();
231
        host = hp->get(oid_1,false);
232

    
233
        CPPUNIT_ASSERT( host != 0 );
234
        CPPUNIT_ASSERT( host->get_state() == Host::DISABLED );
235
    };
236

    
237
    /* ********************************************************************* */
238

    
239
    void duplicates()
240
    {
241
        int rc, oid_0, oid_1;
242
        HostPool * hp = static_cast<HostPool *>(pool);
243
        Host * host;
244
        string err;
245

    
246
        string tm_mad_2 = "another_tm_mad";
247

    
248

    
249
        // If we try to allocate two hosts with the same name and drivers,
250
        // should fail
251
        rc = hp->allocate(&oid_0, names[0], im_mad, vmm_mad, tm_mad, err);
252
        CPPUNIT_ASSERT( oid_0 == 0 );
253
        CPPUNIT_ASSERT( rc    == oid_0 );
254

    
255
        rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad, err);
256
        CPPUNIT_ASSERT( oid_1 == -1 );
257
        CPPUNIT_ASSERT( rc    == oid_1 );
258

    
259
        // the hostname can not be repeated if the drivers change
260
        rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad_2, err);
261
        CPPUNIT_ASSERT( oid_1 == -1 );
262
        CPPUNIT_ASSERT( rc    == oid_1 );
263

    
264
        // Get the hosts and check them
265
        host = hp->get(oid_0, false);
266
        CPPUNIT_ASSERT( host != 0 );
267
        CPPUNIT_ASSERT( host->get_tm_mad() == tm_mad );
268
    }
269

    
270
    /* ********************************************************************* */
271

    
272
    void dump()
273
    {
274
        string names[] = {"a", "a name", "a_name", "another name", "host"};
275
        int rc, oid;
276
        string err;
277

    
278
        for(int i=0; i<5; i++)
279
        {
280
            ((HostPool*)pool)->allocate(&oid, names[i],
281
                                        im_mad, vmm_mad, tm_mad, err);
282
        }
283

    
284
        ostringstream oss;
285

    
286
        rc = ((HostPool*)pool)->dump(oss, "");
287
        CPPUNIT_ASSERT(rc == 0);
288

    
289
        string result = oss.str();
290

    
291
//  A little help for debugging
292
/*
293
        if( result != xml_dump )
294
        {
295
            cout << endl << result << endl << "========"
296
                 << endl << xml_dump;
297
        }
298
//*/
299

    
300
        CPPUNIT_ASSERT( result == xml_dump );
301
    }
302

    
303
    /* ********************************************************************* */
304

    
305
    void dump_where()
306
    {
307
        string names[] = {"a", "a name", "a_name", "another name", "host"};
308
        int rc, oid;
309
        string err;
310

    
311
        for(int i=0; i<5; i++)
312
        {
313
            ((HostPool*)pool)->allocate(&oid, names[i],
314
                                        im_mad, vmm_mad, tm_mad, err);
315
        }
316

    
317

    
318
        ostringstream oss;
319
        rc = ((HostPool*)pool)->dump(oss, "name LIKE 'a%' ORDER BY oid");
320
        CPPUNIT_ASSERT(rc == 0);
321

    
322

    
323
        string result = oss.str();
324

    
325
//  A little help for debugging
326
/*
327
        if( result != xml_dump_like_a )
328
        {
329
            cout << endl << result << endl << "========"
330
                 << endl << xml_dump_like_a;
331
        }
332
//*/
333

    
334
        CPPUNIT_ASSERT( result == xml_dump_like_a );
335
    }
336

    
337
    /* ********************************************************************* */
338

    
339
    void discover()
340
    {
341
        int  rc, oid, i;
342

    
343
        map<int, string>           dh;
344
        map<int, string>::iterator it;
345

    
346
        Host *     host;
347
        HostPool * hp = static_cast<HostPool *>(pool);
348
        ostringstream oss;
349
        string err;
350

    
351
        for(i=0, oss.str(""); i<20; i++,oss.str(""))
352
        {
353
            oss << "host" << i;
354

    
355
            hp->allocate(&oid, oss.str().c_str(), im_mad, vmm_mad, tm_mad, err);
356
            CPPUNIT_ASSERT(oid == i);
357

    
358
            if (i >=8 )
359
            {
360
                host = hp->get(oid, false);
361
                CPPUNIT_ASSERT(host!=0);
362
                host->disable();
363
                hp->update(host);
364
            }
365
        }
366

    
367
        // Discover the enabled hosts
368
        rc = hp->discover(&dh,100);
369

    
370
        CPPUNIT_ASSERT(rc == 0);
371
        CPPUNIT_ASSERT(dh.size() == 8);
372

    
373
        for(i=0,it=dh.begin(),oss.str("");it!=dh.end();it++,i++,oss.str(""))
374
        {
375
            CPPUNIT_ASSERT(it->first  == i);
376
            CPPUNIT_ASSERT(it->second == im_mad);
377

    
378
            host = hp->get(i, false);
379
            CPPUNIT_ASSERT(host!=0);
380
            CPPUNIT_ASSERT(host->isEnabled());
381
        }
382
    }
383

    
384
    /* ********************************************************************* */
385

    
386
    void scale_test()
387
    {
388
        time_t the_time, the_time2;
389
        int oid,i,j;
390

    
391
        ostringstream oss,ossdump;
392
        string        err;
393
        Host * host;
394

    
395
        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";
396

    
397
        cout << endl << "Allocate Test" << endl;
398

    
399
        tearDown();
400

    
401
        for (i=1000; i<30000 ; i = i + 5000)
402
        {
403
            setUp();
404
            
405
            HostPool * hp = static_cast<HostPool *>(pool);
406

    
407
            the_time = time(0);
408

    
409
            for (j=0,oss.str(""); j<i ; j=j+1,oss.str(""))
410
            {
411
                oss << "host" << j;
412

    
413
                hp->allocate(&oid, oss.str().c_str(),im_mad,vmm_mad,tm_mad,err);
414
            }
415

    
416
            the_time2 = time(0) - the_time;
417

    
418
            hp->clean();
419

    
420
            the_time = time(0);
421

    
422
            hp->dump(ossdump, "");
423

    
424
            cout <<"\t"<<i<<"\t"<<the_time2<<"\t"<<time(0)-the_time<< endl;
425

    
426
            tearDown();
427
        } 
428

    
429
        cout << endl << "Read Test" << endl;
430

    
431
        setUp();
432

    
433

    
434
        // Allocate a HostPool
435
        setUp();
436

    
437
        HostPool * hp = static_cast<HostPool *>(pool);
438

    
439
        for (i=10000,oss.str(""); i<30000 ; i++,oss.str(""))
440
        {
441
            oss << "host" << i;
442
            hp->allocate(&oid,oss.str().c_str(),im_mad,vmm_mad,tm_mad,err);
443

    
444
            host = hp->get(oid, false);
445

    
446
            host->update_info(monitor);
447
            hp->update(host);
448
        }
449
           
450
       //Load test 
451
        for (i=0; i<25000; i=i+5000)
452
        {
453
            hp->clean();
454

    
455
            the_time = time(0);
456

    
457
            for (j=0; j<i ; j++)
458
            {
459
                host = hp->get(j,true);
460
                host->unlock();
461
            }
462

    
463
            cout << "\t" << i << "\t" << time(0) - the_time << endl;
464
        }
465
    }
466

    
467
    /* ********************************************************************* */
468

    
469
    void update_info()
470
    {
471
        int         rc;
472
        int         oid_1;
473
        HostPool *  hp = static_cast<HostPool *>(pool);
474
        Host*       host;
475
        string      str;
476

    
477
        oid_1 = allocate(0);
478

    
479
        host = hp->get(oid_1, false);
480
        CPPUNIT_ASSERT( host != 0 );
481

    
482
        string info = "ATT_A=VALUE_A ATT_B=VALUE_B";
483
        rc = host->update_info(info);
484

    
485
        CPPUNIT_ASSERT(rc == 0);
486

    
487
        pool->update(host);
488

    
489
        host = hp->get(oid_1,false);
490
        CPPUNIT_ASSERT( host != 0 );
491
        CPPUNIT_ASSERT( host->to_xml(str) == host0_updated );
492

    
493
        //Now force access to DB
494
        pool->clean();
495
        host = hp->get(oid_1,false);
496

    
497
        CPPUNIT_ASSERT( host != 0 );
498
        CPPUNIT_ASSERT( host->to_xml(str) == host0_updated );
499
    }
500
};
501

    
502

    
503
/* ************************************************************************* */
504
/* ************************************************************************* */
505
/* ************************************************************************* */
506

    
507
int main(int argc, char ** argv)
508
{
509
    return PoolTest::main(argc, argv, HostPoolTest::suite(), "host_pool.xml");
510
}