Revision 57e5c959

View differences:

src/vnm/test/VirtualNetworkPoolTest.cc
85 85
/* ************************************************************************* */
86 86
/* ************************************************************************* */
87 87

  
88
class VirtualNetworkPoolFriend : public VirtualNetworkPool
89
{
90
public:
91

  
92
    VirtualNetworkPoolFriend(   SqlDB *          db,
93
                                const string&    str_mac_prefix,
94
                                int              default_size):
95

  
96
                VirtualNetworkPool( db, str_mac_prefix, default_size)
97
                {};
98

  
99

  
100
    int allocate(const int& uid, const std::string& stemplate, int* oid)
101
    {
102
        VirtualNetworkTemplate * vn_template;
103
        char *          error_msg = 0;
104
        int             rc;
105

  
106
        vn_template = new VirtualNetworkTemplate;
107
        rc = vn_template->parse(stemplate,&error_msg);
108

  
109
        if( rc == 0 )
110
        {
111
            return VirtualNetworkPool::allocate(uid, vn_template, oid);
112
        }
113
        else
114
        {
115
            return -1;
116
        }
117
    };
118
};
119

  
120
/* ************************************************************************* */
121
/* ************************************************************************* */
122

  
88 123
class VirtualNetworkPoolTest : public PoolTest
89 124
{
90 125
    CPPUNIT_TEST_SUITE (VirtualNetworkPoolTest);
......
107 142
    CPPUNIT_TEST (overlapping_leases_rr);
108 143
    CPPUNIT_TEST (drop_leases);
109 144
    CPPUNIT_TEST (public_attribute);
145
    CPPUNIT_TEST (vnpool_nic_attribute);
110 146

  
111 147
    CPPUNIT_TEST_SUITE_END ();
112 148

  
......
127 163
    int allocate(int index)
128 164
    {
129 165
        int oid;
130
        return ((VirtualNetworkPool*)pool)->allocate(uids[index],
166
        return ((VirtualNetworkPoolFriend*)pool)->allocate(uids[index],
131 167
                                                     templates[index], &oid);
132 168
    };
133 169

  
......
181 217

  
182 218
    void allocate_rcs()
183 219
    {
184
        VirtualNetworkPool * vnpool = static_cast<VirtualNetworkPool *>(pool);
220
        VirtualNetworkPoolFriend * vnpool =
221
                                static_cast<VirtualNetworkPoolFriend *>(pool);
185 222
        VirtualNetwork * vn;
186
        int rc;
223
        int              rc;
187 224

  
188 225
        // Check case
189 226
        rc = allocate(2);
......
207 244
        CPPUNIT_ASSERT( rc == -1 );
208 245
    }
209 246

  
247
/* -------------------------------------------------------------------------- */
248
/* -------------------------------------------------------------------------- */
249

  
210 250
    void get_using_name()
211 251
    {
212 252
        VirtualNetworkPool * vnpool = static_cast<VirtualNetworkPool *>(pool);
......
235 275
        check(1, vn);
236 276
    };
237 277

  
278
/* -------------------------------------------------------------------------- */
279
/* -------------------------------------------------------------------------- */
280

  
238 281
    void wrong_get_name()
239 282
    {
240 283
        VirtualNetworkPool * vnpool = static_cast<VirtualNetworkPool *>(pool);
......
252 295
        CPPUNIT_ASSERT( vn == 0 );
253 296
    }
254 297

  
298
/* -------------------------------------------------------------------------- */
299
/* -------------------------------------------------------------------------- */
300

  
255 301
    void update()
256 302
    {
257 303
        // TODO
258 304
    };
259 305

  
306
/* -------------------------------------------------------------------------- */
307
/* -------------------------------------------------------------------------- */
308

  
260 309
    void size()
261 310
    {
262
        VirtualNetworkPool * vnpool = static_cast<VirtualNetworkPool*>(pool);
311
        VirtualNetworkPoolFriend * vnpool =
312
                                static_cast<VirtualNetworkPoolFriend*>(pool);
263 313

  
264
        int rc;
314
        int             rc;
265 315
        VirtualNetwork* vnet;
266 316

  
267 317
        string templ[] = {
......
338 388
        }
339 389
    }
340 390

  
391
/* -------------------------------------------------------------------------- */
392
/* -------------------------------------------------------------------------- */
393

  
341 394
    void duplicates()
342 395
    {
343 396
        int rc, oid_0, oid_1;
344
        VirtualNetworkPool * vnpool = static_cast<VirtualNetworkPool *>(pool);
397
        VirtualNetworkPoolFriend * vnpool =
398
                                static_cast<VirtualNetworkPoolFriend *>(pool);
345 399
        VirtualNetwork     * vnet;
346 400

  
347 401
        // Allocate a vnet
......
382 436
        check(0, vnet);
383 437
    }
384 438

  
439
/* -------------------------------------------------------------------------- */
440
/* -------------------------------------------------------------------------- */
441

  
385 442
    void dump()
386 443
    {
387
        VirtualNetworkPool * vnpool = static_cast<VirtualNetworkPool*>(pool);
444
        VirtualNetworkPoolFriend * vnpool =
445
                                static_cast<VirtualNetworkPoolFriend*>(pool);
388 446
        int oid, rc;
389 447
        ostringstream oss;
390 448

  
......
401 459
        CPPUNIT_ASSERT( result == xml_dump );
402 460
    };
403 461

  
462
/* -------------------------------------------------------------------------- */
463
/* -------------------------------------------------------------------------- */
464

  
404 465
    void dump_where()
405 466
    {
406
        VirtualNetworkPool * vnpool = static_cast<VirtualNetworkPool*>(pool);
467
        VirtualNetworkPoolFriend * vnpool =
468
                                static_cast<VirtualNetworkPoolFriend*>(pool);
407 469
        int oid, rc;
408 470
        ostringstream oss;
409 471

  
......
421 483
        CPPUNIT_ASSERT( result == xml_dump_where );
422 484
    };
423 485

  
486
/* -------------------------------------------------------------------------- */
487
/* -------------------------------------------------------------------------- */
488

  
424 489
    void fixed_leases()
425 490
    {
491
        VirtualNetworkPoolFriend * vnpool =
492
                                static_cast<VirtualNetworkPoolFriend*>(pool);
426 493
        int rc, oid;
427 494
        VirtualNetwork *vn;
428 495

  
......
435 502
        oid = allocate(0);
436 503
        CPPUNIT_ASSERT( oid != -1 );
437 504

  
438
        vn = ((VirtualNetworkPool*)pool)->get(oid, false);
505
        vn = vnpool->get(oid, false);
439 506
        CPPUNIT_ASSERT( vn != 0 );
440 507

  
441 508
        // Ask for an IP
......
454 521
        pool->clean();
455 522

  
456 523
        // Read the Vnet from the DB
457
        vn = ((VirtualNetworkPool*)pool)->get(oid, false);
524
        vn = vnpool->get(oid, false);
458 525
        CPPUNIT_ASSERT( vn != 0 );
459 526

  
460 527
        // Ask for another IP
......
495 562
        CPPUNIT_ASSERT( bridge  == "br1" );
496 563
    }
497 564

  
565
/* -------------------------------------------------------------------------- */
566
/* -------------------------------------------------------------------------- */
567

  
498 568
    void ranged_leases()
499 569
    {
570
        VirtualNetworkPoolFriend * vnpool =
571
                                static_cast<VirtualNetworkPoolFriend*>(pool);
500 572
        int rc, oid;
501 573
        VirtualNetwork *vn;
502 574

  
......
512 584
            "NETWORK_ADDRESS = 192.168.50.0\n";
513 585

  
514 586

  
515
        ((VirtualNetworkPool*)pool)->allocate(45, tmpl, &oid);
587
        vnpool->allocate(45, tmpl, &oid);
516 588
        CPPUNIT_ASSERT( oid != -1 );
517 589

  
518
        vn = ((VirtualNetworkPool*)pool)->get(oid, false);
590
        vn = vnpool->get(oid, false);
519 591
        CPPUNIT_ASSERT( vn != 0 );
520 592

  
521 593
        // Ask for an IP
......
533 605
        pool->clean();
534 606

  
535 607
        // Read the Vnet from the DB
536
        vn = ((VirtualNetworkPool*)pool)->get(oid, false);
608
        vn = vnpool->get(oid, false);
537 609
        CPPUNIT_ASSERT( vn != 0 );
538 610

  
539 611
        // Ask for the IP already in use
......
587 659
        CPPUNIT_ASSERT( bridge  == "bridge0" );
588 660
    }
589 661

  
662
/* -------------------------------------------------------------------------- */
663
/* -------------------------------------------------------------------------- */
664

  
590 665
    void wrong_leases()
591 666
    {
667
        VirtualNetworkPoolFriend * vnpool =
668
                                static_cast<VirtualNetworkPoolFriend*>(pool);
592 669
        int rc, oid_0, oid_1;
593 670
        VirtualNetwork *vn;
594 671

  
......
601 678
        oid_0 = allocate(0);
602 679
        CPPUNIT_ASSERT( oid_0 != -1 );
603 680

  
604
        vn = ((VirtualNetworkPool*)pool)->get(oid_0, false);
681
        vn = vnpool->get(oid_0, false);
605 682
        CPPUNIT_ASSERT( vn != 0 );
606 683

  
607 684
        // Ask for a non-defined IP
......
616 693
        oid_1 = allocate(1);
617 694
        CPPUNIT_ASSERT( oid_1 != -1 );
618 695

  
619
        vn = ((VirtualNetworkPool*)pool)->get(oid_1, false);
696
        vn = vnpool->get(oid_1, false);
620 697
        CPPUNIT_ASSERT( vn != 0 );
621 698

  
622 699
        // Ask for an out of range IP
......
635 712
        CPPUNIT_ASSERT( rc == -1 );
636 713
    }
637 714

  
715
/* -------------------------------------------------------------------------- */
716
/* -------------------------------------------------------------------------- */
717

  
638 718
    void overlapping_leases_ff()
639 719
    {
640 720
        // It is a different Vnet from #0: different user, name, and bridge.
......
649 729
        overlapping_leases(templates[0], tmpl_B);
650 730
    }
651 731

  
732
/* -------------------------------------------------------------------------- */
733
/* -------------------------------------------------------------------------- */
734

  
652 735
    void overlapping_leases_fr()
653 736
    {
654 737
        // Now use a ranged network, also containig the IP 130.10.0.1
......
662 745
        overlapping_leases(templates[0], tmpl_B);
663 746
    }
664 747

  
748
/* -------------------------------------------------------------------------- */
749
/* -------------------------------------------------------------------------- */
750

  
665 751
    void overlapping_leases_rf()
666 752
    {
667 753
        // It is a different Vnet from #0: different user, name, and bridge.
......
676 762
        overlapping_leases(tmpl_A, templates[0]);
677 763
    }
678 764

  
765
/* -------------------------------------------------------------------------- */
766
/* -------------------------------------------------------------------------- */
767

  
679 768
    void overlapping_leases_rr()
680 769
    {
681 770
        // It is a different Vnet from #0: different user, name, and bridge.
......
697 786
        overlapping_leases(tmpl_A, tmpl_B);
698 787
    }
699 788

  
789
/* -------------------------------------------------------------------------- */
790
/* -------------------------------------------------------------------------- */
700 791

  
701 792
    // Runs a test using the given templates
702 793
    void overlapping_leases(string tmpl_A, string tmpl_B)
703 794
    {
795
        VirtualNetworkPoolFriend * vnpool =
796
                                static_cast<VirtualNetworkPoolFriend*>(pool);
704 797
        int rc, oid_0, oid_new;
705 798
        VirtualNetwork *vn;
706 799

  
......
712 805

  
713 806

  
714 807
        // First VNet template
715
        ((VirtualNetworkPool*)pool)->allocate(13, tmpl_A, &oid_0);
808
        vnpool->allocate(13, tmpl_A, &oid_0);
716 809
        CPPUNIT_ASSERT( oid_0 != -1 );
717 810

  
718 811
        // Second VNet
719
        ((VirtualNetworkPool*)pool)->allocate(45, tmpl_B, &oid_new);
812
        vnpool->allocate(45, tmpl_B, &oid_new);
720 813
        CPPUNIT_ASSERT( oid_new != -1 );
721 814

  
722 815
        // Get this second VNet
723
        vn = ((VirtualNetworkPool*)pool)->get(oid_new, false);
816
        vn = vnpool->get(oid_new, false);
724 817
        CPPUNIT_ASSERT( vn != 0 );
725 818

  
726 819
        // Set a lease. Ask for the IP that both Vnets have
......
742 835

  
743 836

  
744 837
        // Now check that the first VNet has that IP available
745
        vn = ((VirtualNetworkPool*)pool)->get(oid_0, false);
838
        vn = vnpool->get(oid_0, false);
746 839
        CPPUNIT_ASSERT( vn != 0 );
747 840

  
748 841
        // Ask the first VNet for the IP that both Vnets have
......
759 852

  
760 853

  
761 854
        // Get again the second VNet
762
        vn = ((VirtualNetworkPool*)pool)->get(oid_new, false);
855
        vn = vnpool->get(oid_new, false);
763 856
        CPPUNIT_ASSERT( vn != 0 );
764 857

  
765 858
        // Ask for the IP, should be still used
......
778 871
        CPPUNIT_ASSERT(results.size()  == 1);
779 872
    }
780 873

  
874
/* -------------------------------------------------------------------------- */
875
/* -------------------------------------------------------------------------- */
876

  
781 877
    void drop_leases()
782 878
    {
879
        VirtualNetworkPoolFriend * vnpool =
880
                                static_cast<VirtualNetworkPoolFriend*>(pool);
783 881
        int rc, oid;
784 882
        VirtualNetwork *vn;
785 883

  
......
793 891
        oid = allocate(0);
794 892
        CPPUNIT_ASSERT( oid != -1 );
795 893

  
796
        vn = ((VirtualNetworkPool*)pool)->get(oid, false);
894
        vn = vnpool->get(oid, false);
797 895
        CPPUNIT_ASSERT( vn != 0 );
798 896

  
799 897
        // Drop the VNet
......
808 906
        CPPUNIT_ASSERT(results.size()  == 0);
809 907
    }
810 908

  
909
/* -------------------------------------------------------------------------- */
910
/* -------------------------------------------------------------------------- */
811 911

  
812 912
    void public_attribute()
813 913
    {
814 914
        int oid;
815
        VirtualNetworkPool * vnp = static_cast<VirtualNetworkPool *>(pool);
915
        VirtualNetworkPoolFriend * vnp =
916
                                static_cast<VirtualNetworkPoolFriend*>(pool);
816 917
        VirtualNetwork *     vn;
817 918

  
818 919
        string templates[] =
......
898 999

  
899 1000
//cout << endl << i << ":expected " << results[i] << " got " << vn->is_public();
900 1001

  
901
            CPPUNIT_ASSERT( vn->is_public() == results[i] );
902

  
1002
// =============================================================================
1003
// =============================================================================
1004
//          Branch feature 203 doesn't have is_public method, but this test is
1005
//          still valid for master.
1006
//            CPPUNIT_ASSERT( vn->is_public() == results[i] );
1007
// =============================================================================
1008
// =============================================================================
903 1009
            i++;
904 1010
        }
905 1011
    }
1012

  
1013
/* -------------------------------------------------------------------------- */
1014
/* -------------------------------------------------------------------------- */
1015

  
1016
    void vnpool_nic_attribute()
1017
    {
1018
    }
1019

  
906 1020
};
907 1021

  
908 1022
/* ************************************************************************* */

Also available in: Unified diff