1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-27 14:03:40 +03:00

Merge branch 'feature-407' of dsa-research.org:one into feature-407

This commit is contained in:
Ruben S. Montero 2011-03-08 17:55:50 +01:00
commit b227ef8ad3
4 changed files with 26 additions and 7 deletions

View File

@ -81,7 +81,7 @@ public:
* @return a pointer to the object, 0 in case of failure
*/
PoolObjectSQL * get(const string& name, int uid, bool lock);
/**
* Finds a set objects that satisfies a given condition
* @param oids a vector with the oids of the objects.
@ -220,7 +220,7 @@ private:
* back of the queue.
*/
void replace();
/**
* Generate an index key for the object
* @param name of the object

View File

@ -73,7 +73,7 @@ const char * Image::db_names = "oid, name, body, uid, public";
const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool ("
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, "
"public INTEGER, UNIQUE(name) )";
"public INTEGER, UNIQUE(name,uid) )";
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */

View File

@ -64,6 +64,7 @@ int ImagePool::allocate (
string& error_str)
{
Image * img;
Image * img_aux;
string name;
// ---------------------------------------------------------------------
@ -72,9 +73,27 @@ int ImagePool::allocate (
img = new Image(uid, user_name, img_template);
// ---------------------------------------------------------------------
// Insert the Object in the pool
// Check for duplicates
// ---------------------------------------------------------------------
*oid = PoolSQL::allocate(img, error_str);
img->get_template_attribute("NAME", name);
img_aux = get(name,uid,false);
if( img_aux != 0 )
{
ostringstream oss;
oss << "NAME is already taken by image " << img_aux->get_oid() << ".";
error_str = oss.str();
*oid = -1;
}
else
{
// ---------------------------------------------------------------------
// Insert the Object in the pool
// ---------------------------------------------------------------------
*oid = PoolSQL::allocate(img, error_str);
}
return *oid;
}

View File

@ -355,9 +355,9 @@ public:
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == rc );
// Try again, with different uid
// Try again, this time with different uid. Should be allowed
rc = imp->allocate(uids[1], templates[0], &oid);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( rc >= 0 );
CPPUNIT_ASSERT( oid == rc );
}