mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Feature #407: Better duplicated name detection for Hosts
This commit is contained in:
parent
546aa9e8f6
commit
3c3edb9c36
@ -67,7 +67,19 @@ public:
|
||||
{
|
||||
return static_cast<Host *>(PoolSQL::get(oid,lock));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Function to get a Host from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param hostname
|
||||
* @param lock locks the Host mutex
|
||||
* @return a pointer to the Host, 0 if the Host could not be loaded
|
||||
*/
|
||||
Host * get(string name, bool lock)
|
||||
{
|
||||
return static_cast<Host *>(PoolSQL::get(name,-1,lock));
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Host pool
|
||||
*/
|
||||
|
@ -144,18 +144,32 @@ int HostPool::allocate (
|
||||
{
|
||||
Host * host;
|
||||
|
||||
// Build a new Host object
|
||||
host = get(hostname,false);
|
||||
|
||||
host = new Host(-1,
|
||||
hostname,
|
||||
im_mad_name,
|
||||
vmm_mad_name,
|
||||
tm_mad_name,
|
||||
ClusterPool::DEFAULT_CLUSTER_NAME);
|
||||
if ( host !=0)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
// Insert the Object in the pool
|
||||
oss << "NAME is already taken by HOST " << host->get_oid() << ".";
|
||||
error_str = oss.str();
|
||||
|
||||
*oid = PoolSQL::allocate(host, error_str);
|
||||
*oid = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Build a new Host object
|
||||
|
||||
host = new Host(-1,
|
||||
hostname,
|
||||
im_mad_name,
|
||||
vmm_mad_name,
|
||||
tm_mad_name,
|
||||
ClusterPool::DEFAULT_CLUSTER_NAME);
|
||||
|
||||
// Insert the Object in the pool
|
||||
|
||||
*oid = PoolSQL::allocate(host, error_str);
|
||||
}
|
||||
|
||||
return *oid;
|
||||
}
|
||||
|
@ -409,12 +409,12 @@ public:
|
||||
CPPUNIT_ASSERT( rc == oid_0 );
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
// Allocate the same vnet twice, with the same user ID
|
||||
// Allocate the same vnet twice, with the same user ID. Should fail
|
||||
rc = vnpool->allocate(uids[0], user_names[0], templates[0], &oid_1);
|
||||
CPPUNIT_ASSERT( rc == oid_1 );
|
||||
CPPUNIT_ASSERT( rc == -1 );
|
||||
|
||||
// Same VNet, with different user ID
|
||||
// Same VNet, with different user ID. Should succeed
|
||||
rc = vnpool->allocate(uids[1], user_names[1], templates[0], &oid_2);
|
||||
CPPUNIT_ASSERT( rc == oid_2 );
|
||||
CPPUNIT_ASSERT( rc == 1 );
|
||||
@ -425,7 +425,7 @@ public:
|
||||
CPPUNIT_ASSERT( rc == 2 );
|
||||
|
||||
|
||||
// Make sure the table contains only one vnet with name[0]
|
||||
// Make sure the table contains two vnets with name[0]
|
||||
vector<int> results;
|
||||
int ret;
|
||||
const char * table = "network_pool";
|
||||
|
Loading…
Reference in New Issue
Block a user