Revision fc15b997 src/host/test/HostPoolTest.cc

View differences:

src/host/test/HostPoolTest.cc
33 33
{
34 34
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE>"
35 35
    "<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
36
    "<LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHARE><HID>0</HID>"
36
    "<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID>"
37 37
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
38 38
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
39 39
    "<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
......
42 42

  
43 43
    "<HOST><ID>1</ID><NAME>Second host</NAME><STATE>0</STATE>"
44 44
    "<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
45
    "<LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHARE><HID>1</HID>"
45
    "<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>1</HID>"
46 46
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
47 47
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
48 48
    "<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
......
53 53
// This xml dump result has the LAST_MON_TIMEs modified to 0000000000
54 54
const string xml_dump =
55 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>000000"
57
    "0000</LAST_MON_TIME><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
56
    "M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
57
    "</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
58 58
    "_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
59 59
    ">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
60 60
    "MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
61 61
    "SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST>"
62 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>0000000000</LAST_M"
64
    "ON_TIME><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
63
    "D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
64
    "ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
65 65
    "M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
66 66
    "<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
67 67
    "U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
68 68
    "SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>2</ID><N"
69 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>0000000000</LAST_MON_TIME><HOS"
70
    "M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
71 71
    "T_SHARE><HID>2</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
72 72
    "_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
73 73
    "MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
74 74
    "U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
75 75
    "NING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>3</ID><NAME>another "
76 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>0000000000</LAST_MON_TIME><HOST_SHAR"
77
    "<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
78 78
    "E><HID>3</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
79 79
    ">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
80 80
    "U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
81 81
    "D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
82 82
    "MS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>4</ID><NAME>host</NAME><ST"
83 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>0000000000</LAST_MON_TIME><HOST_SHARE><HID>4</HID>"
84
    "</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>4</HID>"
85 85
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
86 86
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0"
87 87
    "</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED"
......
90 90

  
91 91
const string xml_dump_like_a =
92 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>000000"
94
    "0000</LAST_MON_TIME><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
93
    "M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
94
    "</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
95 95
    "_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
96 96
    ">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
97 97
    "MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
98 98
    "SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST>"
99 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>0000000000</LAST_M"
101
    "ON_TIME><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
100
    "D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
101
    "ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
102 102
    "M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
103 103
    "<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
104 104
    "U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
105 105
    "SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>2</ID><N"
106 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>0000000000</LAST_MON_TIME><HOS"
107
    "M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
108 108
    "T_SHARE><HID>2</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
109 109
    "_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
110 110
    "MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
111 111
    "U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
112 112
    "NING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>3</ID><NAME>another "
113 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>0000000000</LAST_MON_TIME><HOST_SHAR"
114
    "<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
115 115
    "E><HID>3</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
116 116
    ">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
117 117
    "U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
118 118
    "D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
119 119
    "MS>0</RUNNING_VMS></HOST_SHARE></HOST></HOST_POOL>";
120 120

  
121
const string replacement = "0000000000";
122 121

  
122
const string cluster_default =
123
    "<CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER>";
123 124

  
125
const string cluster_xml_dump =
126
    "<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>";
127

  
128
const string host_0_cluster =
129
    "<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><HID>0</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>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>";
124 130
/* ************************************************************************* */
125 131
/* ************************************************************************* */
126 132

  
......
136 142
    CPPUNIT_TEST (discover);
137 143
    CPPUNIT_TEST (duplicates);
138 144

  
145
    CPPUNIT_TEST (cluster_init);
146
    CPPUNIT_TEST (cluster_allocate);
147
    CPPUNIT_TEST (cluster_drop);
148
    CPPUNIT_TEST (cluster_id);
149
    CPPUNIT_TEST (cluster_dump);
150
    CPPUNIT_TEST (set_cluster);
151
    CPPUNIT_TEST (remove_cluster);
152

  
139 153
    CPPUNIT_TEST_SUITE_END ();
140 154

  
141 155
protected:
......
168 182

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

  
171
        // Get the xml and replace the LAST_MON_TIME to 0, so we can compare
172
        // it with a prepared string.
185
        // Get the xml
173 186
        host->to_xml(xml_str);
174
        xml_str.replace( xml_str.find("<LAST_MON_TIME>")+15, 10, "0000000000");
175

  
176 187
        CPPUNIT_ASSERT( xml_str == xmls[index]);
177

  
178 188
    };
179 189

  
180 190

  
......
215 225
        CPPUNIT_ASSERT( host->get_state() == Host::DISABLED );
216 226
    };
217 227

  
228
    /* ********************************************************************* */
229

  
218 230
    void duplicates()
219 231
    {
220 232
        int rc, oid_0, oid_1;
......
249 261
        CPPUNIT_ASSERT( host->get_tm_mad() == tm_mad_2 );
250 262
    }
251 263

  
264
    /* ********************************************************************* */
252 265

  
253 266
    void dump()
254 267
    {
......
265 278
        rc = ((HostPool*)pool)->dump(oss, "");
266 279
        CPPUNIT_ASSERT(rc == 0);
267 280

  
268
        // To be able to compare one string to another, the monitoring times
269
        // have to be changed
270 281
        string result = oss.str();
271
        result.replace( 142, 10, replacement);
272
        result.replace( 648, 10, replacement);
273
        result.replace(1154, 10, replacement);
274
        result.replace(1666, 10, replacement);
275
        result.replace(2170, 10, replacement);
276 282

  
277 283
        CPPUNIT_ASSERT( result == xml_dump );
278 284
    }
279 285

  
286
    /* ********************************************************************* */
287

  
280 288
    void dump_where()
281 289
    {
282 290
        string names[] = {"a", "a name", "a_name", "another name", "host"};
......
292 300
        rc = ((HostPool*)pool)->dump(oss, "host_name LIKE 'a%'");
293 301
        CPPUNIT_ASSERT(rc == 0);
294 302

  
295
        // To be able to compare one string to another, the monitoring times
296
        // have to be changed
297
        string result = oss.str();
298
        result.replace( 142, 10, replacement);
299
        result.replace( 648, 10, replacement);
300
        result.replace(1154, 10, replacement);
301
        result.replace(1666, 10, replacement);
302 303

  
304
        string result = oss.str();
303 305

  
304 306
        CPPUNIT_ASSERT( result == xml_dump_like_a );
305 307
    }
306 308

  
309
    /* ********************************************************************* */
310

  
307 311
    void discover()
308 312
    {
309 313
        int  rc, oid, i;
......
332 336
        }
333 337

  
334 338
        // Discover the enabled hosts
335
        rc = hp->discover(&dh);
339
        rc = hp->discover(&dh, 100);
336 340
        CPPUNIT_ASSERT(rc == 0);
337 341
        CPPUNIT_ASSERT(dh.size() == 8);
338 342

  
......
346 350
            CPPUNIT_ASSERT(host->isEnabled());
347 351
        }
348 352
    }
353

  
354
    /* ********************************************************************* */
355
    /* ********************************************************************* */
356

  
357
    void cluster_init()
358
    {
359
        HostPool * hp = static_cast<HostPool *>(pool);
360

  
361
        CPPUNIT_ASSERT( hp->info_cluster(0) == cluster_default );
362
    }
363

  
364
    /* ********************************************************************* */
365

  
366
    void cluster_allocate()
367
    {
368
        HostPool * hp = static_cast<HostPool *>(pool);
369
        int clid, rc;
370

  
371
        rc = hp->allocate_cluster(&clid, "new_cluster");
372
        CPPUNIT_ASSERT( rc == clid );
373
        CPPUNIT_ASSERT( clid == 1 );
374

  
375
        CPPUNIT_ASSERT( hp->info_cluster(clid) ==
376
                "<CLUSTER><ID>1</ID><NAME>new_cluster</NAME></CLUSTER>");
377

  
378
        // Try to allocate using the same name
379
        rc = hp->allocate_cluster(&clid, "new_cluster");
380
        CPPUNIT_ASSERT( rc == clid );
381
        CPPUNIT_ASSERT( clid == -1 );
382
    }
383

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

  
386
    void cluster_drop()
387
    {
388
        HostPool * hp = static_cast<HostPool *>(pool);
389
        int clid, rc;
390

  
391
        // Drop a non-existing cluster
392
        rc = hp->drop_cluster(20);
393
        CPPUNIT_ASSERT( rc == -1 );
394

  
395
        // Allocate a cluster and drop it
396
        rc = hp->allocate_cluster(&clid, "new_cluster");
397
        CPPUNIT_ASSERT( clid == 1);
398

  
399
        rc = hp->drop_cluster(clid);
400
        CPPUNIT_ASSERT( rc == 0 );
401

  
402
        // Try to drop the default cluster, should fail
403
        rc = hp->drop_cluster(0);
404
        CPPUNIT_ASSERT( rc == -1 );
405
    }
406

  
407
    /* ********************************************************************* */
408

  
409
    void cluster_id()
410
    {
411
        HostPool * hp = static_cast<HostPool *>(pool);
412
        int clid, rc;
413
        ostringstream oss;
414

  
415
        // Allocate some clusters
416
        rc = hp->allocate_cluster(&clid, "cluster_a");
417
        CPPUNIT_ASSERT( rc == 1 );
418

  
419
        rc = hp->allocate_cluster(&clid, "cluster_b");
420
        CPPUNIT_ASSERT( rc == 2 );
421

  
422
        rc = hp->allocate_cluster(&clid, "cluster_c");
423
        CPPUNIT_ASSERT( rc == 3 );
424

  
425
        rc = hp->allocate_cluster(&clid, "cluster_d");
426
        CPPUNIT_ASSERT( rc == 4 );
427

  
428
        // Drop id 2
429
        rc = hp->drop_cluster(2);
430
        CPPUNIT_ASSERT( rc == 0 );
431

  
432
        // Next one should use id 5, because the biggest id is 4
433
        rc = hp->allocate_cluster(&clid, "cluster_e");
434
        CPPUNIT_ASSERT( rc == 5 );
435

  
436
        // Drop id 5
437
        rc = hp->drop_cluster(5);
438
        CPPUNIT_ASSERT( rc == 0 );
439

  
440
        // Next one should use id 5, because the biggest id is 4 again
441
        rc = hp->allocate_cluster(&clid, "cluster_f");
442
        CPPUNIT_ASSERT( rc == 5 );
443

  
444
    }
445

  
446
    /* ********************************************************************* */
447

  
448
    void cluster_dump()
449
    {
450
        HostPool * hp = static_cast<HostPool *>(pool);
451
        int clid, rc;
452
        ostringstream oss;
453

  
454
        // Allocate some clusters
455
        rc = hp->allocate_cluster(&clid, "cluster_a");
456
        CPPUNIT_ASSERT( rc == 1 );
457

  
458
        rc = hp->allocate_cluster(&clid, "cluster_b");
459
        CPPUNIT_ASSERT( rc == 2 );
460

  
461
        rc = hp->allocate_cluster(&clid, "cluster_c");
462
        CPPUNIT_ASSERT( rc == 3 );
463

  
464
        rc = hp->allocate_cluster(&clid, "cluster_d");
465
        CPPUNIT_ASSERT( rc == 4 );
466

  
467

  
468
        // Drop one of them
469
        rc = hp->drop_cluster(2);
470
        CPPUNIT_ASSERT( rc == 0 );
471

  
472
        // dump the pool
473
        rc = hp->dump_cluster(oss);
474
        CPPUNIT_ASSERT( oss.str() == cluster_xml_dump );
475
    }
476

  
477
    /* ********************************************************************* */
478

  
479
    void set_cluster()
480
    {
481
        HostPool *  hp = static_cast<HostPool *>(pool);
482
        Host*       host;
483
        int         clid, rc, oid;
484
        string      xml_str;
485

  
486
        // Allocate a host
487
        oid = allocate(0);
488

  
489
        host = hp->get(0, false);
490

  
491
        rc = hp->allocate_cluster(&clid, "cluster_a");
492
        CPPUNIT_ASSERT( rc == 1 );
493

  
494
        rc = hp->set_cluster(host, clid);
495
        CPPUNIT_ASSERT( rc == 0 );
496

  
497
        host->to_xml(xml_str);
498
        CPPUNIT_ASSERT( xml_str == host_0_cluster);
499

  
500

  
501
        // Try to set a non-existing cluster
502
        rc = hp->set_cluster(host, 20);
503
        CPPUNIT_ASSERT( rc == -1 );
504

  
505
        CPPUNIT_ASSERT( xml_str == host_0_cluster);
506

  
507
    }
508

  
509
    /* ********************************************************************* */
510

  
511
    void remove_cluster()
512
    {
513
        HostPool *  hp = static_cast<HostPool *>(pool);
514
        Host*       host;
515
        int         clid, rc, oid;
516
        string      xml_str;
517

  
518
        // Allocate a host
519
        oid = allocate(0);
520

  
521
        host = hp->get(0, false);
522

  
523
        rc = hp->allocate_cluster(&clid, "cluster_a");
524
        CPPUNIT_ASSERT( rc == 1 );
525

  
526
        // Set host 0 to cluster 1
527
        rc = hp->set_cluster(host, clid);
528
        CPPUNIT_ASSERT( rc == 0 );
529

  
530
        // Check
531
        host->to_xml(xml_str);
532
        CPPUNIT_ASSERT( xml_str == host_0_cluster);
533

  
534
        // Remove the cluster
535
        rc = hp->set_default_cluster(host);
536
        CPPUNIT_ASSERT( rc == 0 );
537

  
538
        // The host should have been moved to the default cluster
539
        host->to_xml(xml_str);
540
        check(0, host);
541
    }
349 542
};
350 543

  
544

  
351 545
/* ************************************************************************* */
352 546
/* ************************************************************************* */
353 547
/* ************************************************************************* */

Also available in: Unified diff