From 697ac59538a7544fe036283b6b299dbef24587a8 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 12 Jul 2011 19:27:01 +0200 Subject: [PATCH 1/3] feature #450: disable bundler gem checking --- share/bundler/install_gems | 7 ------- 1 file changed, 7 deletions(-) diff --git a/share/bundler/install_gems b/share/bundler/install_gems index f4ed69a02a..75edf783d4 100755 --- a/share/bundler/install_gems +++ b/share/bundler/install_gems @@ -83,13 +83,6 @@ try_library :rubygems, <<-EOT.unindent * Follow the instructions from http://rubygems.org/pages/download EOT -try_library :bundler, <<-EOT.unindent - bundler needed to install gems - - execute this to install it: - - [sudo] gem install bundler -EOT if ARGV.include?('-h') help From 32e10726d45429eb3e35e95a409d7d2bf04f40d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 12 Jul 2011 19:30:00 +0200 Subject: [PATCH 2/3] Bug: Image and VNet creation with an already used name reported a DB error, instead of a nice reason like Templates --- include/ImagePool.h | 14 ++++++++++++ include/VirtualNetworkPool.h | 14 ++++++++++++ src/image/ImagePool.cc | 16 ++++++++++++++ src/vnm/VirtualNetworkPool.cc | 41 +++++++++++++++++++++++++++++++++-- 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/include/ImagePool.h b/include/ImagePool.h index 1162653c09..d69a2f3a60 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -78,6 +78,20 @@ public: return static_cast(PoolSQL::get(oid,lock)); }; + /** + * Gets an object from the pool (if needed the object is loaded from the + * database). + * @param name of the object + * @param uid id of owner + * @param lock locks the object if true + * + * @return a pointer to the object, 0 in case of failure + */ + Image * get(const string& name, int uid, bool lock) + { + return static_cast(PoolSQL::get(name,uid,lock)); + }; + /** * Update a particular Image * @param image pointer to Image diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h index 776297601b..e77438acd0 100644 --- a/include/VirtualNetworkPool.h +++ b/include/VirtualNetworkPool.h @@ -69,6 +69,20 @@ public: return static_cast(PoolSQL::get(oid,lock)); }; + /** + * Gets an object from the pool (if needed the object is loaded from the + * database). + * @param name of the object + * @param uid id of owner + * @param lock locks the object if true + * + * @return a pointer to the object, 0 in case of failure + */ + VirtualNetwork * get(const string& name, int uid, bool lock) + { + return static_cast(PoolSQL::get(name,uid,lock)); + }; + //-------------------------------------------------------------------------- // Virtual Network DB access functions //-------------------------------------------------------------------------- diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 5dfb6c6915..bafdfd4abb 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -64,6 +64,7 @@ int ImagePool::allocate ( string& error_str) { Image * img; + Image * img_aux = 0; string name; ostringstream oss; @@ -77,6 +78,14 @@ int ImagePool::allocate ( goto error_name; } + // Check for duplicates + img_aux = get(name,uid,false); + + if( img_aux != 0 ) + { + goto error_duplicated; + } + // --------------------------------------------------------------------- // Insert the Object in the pool & Register the image in the repository // --------------------------------------------------------------------- @@ -100,6 +109,13 @@ int ImagePool::allocate ( error_name: oss << "NAME cannot be empty."; + goto error_common; + +error_duplicated: + oss << "NAME is already taken by IMAGE " + << img_aux->get_oid() << "."; + +error_common: delete img; *oid = -1; diff --git a/src/vnm/VirtualNetworkPool.cc b/src/vnm/VirtualNetworkPool.cc index 30f5350c37..eaa5294079 100644 --- a/src/vnm/VirtualNetworkPool.cc +++ b/src/vnm/VirtualNetworkPool.cc @@ -78,13 +78,50 @@ int VirtualNetworkPool::allocate ( int * oid, string& error_str) { - VirtualNetwork * vn; - string name; + VirtualNetwork * vn; + VirtualNetwork * vn_aux = 0; + string name; + ostringstream oss; + + vn = new VirtualNetwork(uid, gid, uname, gname, vn_template); + + // Check name + vn->get_template_attribute("NAME", name); + + if ( name.empty() ) + { + goto error_name; + } + + // Check for duplicates + vn_aux = get(name,uid,false); + + if( vn_aux != 0 ) + { + goto error_duplicated; + } vn = new VirtualNetwork(uid, gid, uname, gname, vn_template); *oid = PoolSQL::allocate(vn, error_str); + return *oid; + +error_name: + oss << "NAME cannot be empty."; + + goto error_common; + +error_duplicated: + oss << "NAME is already taken by NET " + << vn_aux->get_oid() << "."; + +error_common: + delete vn; + + *oid = -1; + error_str = oss.str(); + return *oid; } From 81d9a077b3489c139753f8237358d43e6e02d9a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 12 Jul 2011 19:30:26 +0200 Subject: [PATCH 3/3] Fix core unit testing tests for ImagePool: duplicated image names are not allowed --- src/image/test/ImagePoolTest.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index b3f5e7c8f9..ceef84f48c 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -333,15 +333,15 @@ public: CPPUNIT_ASSERT( oid == 0 ); CPPUNIT_ASSERT( oid == rc ); - // Try to allocate twice the same image, should work + // Try to allocate twice the same image, shouldn't work rc = imp->allocate(uids[0], templates[0], &oid); - CPPUNIT_ASSERT( rc == 1 ); - CPPUNIT_ASSERT( oid == 1 ); + CPPUNIT_ASSERT( rc == -1 ); + CPPUNIT_ASSERT( oid == -1 ); // Try again, this time with different uid. Should be allowed rc = imp->allocate(uids[1], templates[0], &oid); CPPUNIT_ASSERT( rc >= 0 ); - CPPUNIT_ASSERT( oid == 2 ); + CPPUNIT_ASSERT( oid == 1 ); } /* -------------------------------------------------------------------------- */