From e2f2c25ee3c21f8d79e93b5b42184059864abe4b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 14 Oct 2011 17:15:20 +0200 Subject: [PATCH] bug #847 - #913: Fixes Network tests and some core bugs --- src/test/Nebula.cc | 4 +- src/vnm/VirtualNetwork.cc | 4 +- src/vnm/test/SConstruct | 25 +++++++--- src/vnm/test/VirtualNetworkPoolTest.cc | 67 ++++++++++++++++++++------ 4 files changed, 74 insertions(+), 26 deletions(-) diff --git a/src/test/Nebula.cc b/src/test/Nebula.cc index c0794b1ce2..b65c65fb92 100644 --- a/src/test/Nebula.cc +++ b/src/test/Nebula.cc @@ -194,8 +194,8 @@ void Nebula::start() try { - string mac_prefix = "00:00"; - int size = 1; + string mac_prefix = "00:02"; + int size = 126; string default_image_type = "OS"; string default_device_prefix = "hd"; diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 6a1db4f7fb..520ba533b5 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -294,14 +294,14 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str) int size = 0; // retrieve specific information from template - erase_template_attribute("NETWORK_ADDRESS",naddr); + get_template_attribute("NETWORK_ADDRESS",naddr); if (naddr.empty()) { goto error_addr; } - erase_template_attribute("NETWORK_SIZE",nclass); + get_template_attribute("NETWORK_SIZE",nclass); if ( nclass == "B" || nclass == "b" ) { diff --git a/src/vnm/test/SConstruct b/src/vnm/test/SConstruct index 0854a0e939..97149a99b2 100644 --- a/src/vnm/test/SConstruct +++ b/src/vnm/test/SConstruct @@ -17,19 +17,30 @@ Import('env') env.Prepend(LIBS=[ - 'nebula_log', + 'nebula_core_test', + 'nebula_host', + 'nebula_xml', + 'nebula_vmm', + 'nebula_im', + 'nebula_rm', + 'nebula_tm', 'nebula_um', + 'nebula_mad', + 'nebula_template', + 'nebula_vm', + 'nebula_vmtemplate', + 'nebula_group', 'nebula_vnm', + 'nebula_image', + 'nebula_pool', + 'nebula_hm', 'nebula_authm', 'nebula_acl', - 'nebula_group', - 'nebula_template', - 'nebula_pool', - 'nebula_xml', - 'nebula_mad', - 'nebula_core', 'nebula_common', + 'nebula_lcm', + 'nebula_dm', 'nebula_sql', + 'nebula_log', 'crypto' ]) diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index df43e47678..e7854565e1 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -71,18 +71,33 @@ const string templates[] = const string xmls[] = { - "01230the_useroneadminNet number one1br100130.10.0.150:20:20:20:20:200-1", + "01230the_useroneadminNet number one1br100130.10.0.150:20:20:20:20:200-1", - "12610the_useroneadminA virtual network0br010", + "12610the_useroneadminA virtual network0br010", - "01330the_useroneadminNet number two1br100130.10.2.150:20:20:20:20:200-1" + "01330the_useroneadminNet number two1br100130.10.2.150:20:20:20:20:200-1", }; const string xml_dump = - "010the_useroneadminNet number one1br100120the_useroneadminA virtual network0br010"; + "010the_useroneadminNet number one1br100120the_useroneadminA virtual network0br010"; const string xml_dump_where = - "120the_useroneadminA virtual network0br010"; + "120the_useroneadminA virtual network0br010"; + +/* ************************************************************************* */ +/* ************************************************************************* */ +#include "NebulaTest.h" + +class NebulaTestVNet: public NebulaTest +{ +public: + NebulaTestVNet():NebulaTest() + { + NebulaTest::the_tester = this; + + need_vnet_pool = true; + }; +}; /* ************************************************************************* */ /* ************************************************************************* */ @@ -168,19 +183,19 @@ class VirtualNetworkPoolTest : public PoolTest CPPUNIT_TEST_SUITE_END (); protected: + NebulaTestVNet *tester; + VirtualNetworkPool *vnpool; void bootstrap(SqlDB* db) { - VirtualNetworkPool::bootstrap(db); }; PoolSQL* create_pool(SqlDB* db) { - // VNet pool constructor needs DB, default mac prefix, - // and default network size - return new VirtualNetworkPool(db, "00:01", 126); + return vnpool; }; + int allocate(int index) { int oid; @@ -204,7 +219,7 @@ protected: } //*/ - CPPUNIT_ASSERT( ((VirtualNetwork*)obj)->get_uid() == uids[index] ); + CPPUNIT_ASSERT( ((VirtualNetwork*)obj)->get_uid() == uids[index] ); CPPUNIT_ASSERT( xml_str == xmls[index] ); }; @@ -214,6 +229,28 @@ public: ~VirtualNetworkPoolTest(){xmlCleanupParser();}; + void setUp() + { + create_db(); + + tester = new NebulaTestVNet(); + + Nebula& neb = Nebula::instance(); + neb.start(); + + vnpool = neb.get_vnpool(); + + pool = vnpool; + }; + + void tearDown() + { + // ----------------------------------------------------------- + + delete_db(); + + delete tester; + }; /* ********************************************************************* */ /* ********************************************************************* */ @@ -273,9 +310,8 @@ public: }; string phydev_xml[] = { - "000the_useroneadminBRIDGE and PHYDEV1br0eth000130.10.0.150:20:20:20:20:200-1", - - "100the_useroneadminNo BRIDGE only PHYDEV1onebr1eth000130.10.0.150:20:20:20:20:200-1" + "000the_useroneadminBRIDGE and PHYDEV1br0eth000130.10.0.150:20:20:20:20:200-1", + "100the_useroneadminNo BRIDGE only PHYDEV1onebr1eth000130.10.0.150:20:20:20:20:200-1" }; // test vm with bridge and phydev @@ -286,6 +322,7 @@ public: CPPUNIT_ASSERT( vn != 0 ); ((VirtualNetwork*)vn)->to_xml_extended(xml_str); + CPPUNIT_ASSERT( xml_str == phydev_xml[0] ); // test vm with phydev only @@ -640,7 +677,7 @@ public: // Check that it is valid IP CPPUNIT_ASSERT( rc == 0 ); CPPUNIT_ASSERT( ip == "192.168.50.1" ); - CPPUNIT_ASSERT( mac == "00:01:c0:a8:32:01" ); + CPPUNIT_ASSERT( mac == "00:02:c0:a8:32:01" ); CPPUNIT_ASSERT( bridge == "bridge0" ); // Clean the cache @@ -697,7 +734,7 @@ public: CPPUNIT_ASSERT( rc == 0 ); CPPUNIT_ASSERT( ip == "192.168.50.2" ); - CPPUNIT_ASSERT( mac == "00:01:c0:a8:32:02" ); + CPPUNIT_ASSERT( mac == "00:02:c0:a8:32:02" ); CPPUNIT_ASSERT( bridge == "bridge0" ); }