mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
feature #192: New tests for ImagePool::disk_attribute and tests fixed for new ImagePool::allocate parameters (#203).
This commit is contained in:
parent
f3fc078b6c
commit
d68855a4c6
@ -65,6 +65,40 @@ const string xml_dump_where =
|
||||
|
||||
const string replacement = "0000000000";
|
||||
|
||||
class ImagePoolFriend : public ImagePool
|
||||
{
|
||||
public:
|
||||
ImagePoolFriend(SqlDB * db,
|
||||
const string& _source_prefix,
|
||||
const string& _default_type,
|
||||
const string& _default_dev_prefix):
|
||||
|
||||
ImagePool( db,
|
||||
_source_prefix,
|
||||
_default_type,
|
||||
_default_dev_prefix){};
|
||||
|
||||
|
||||
int allocate(const int& uid, const std::string& stemplate, int* oid)
|
||||
{
|
||||
ImageTemplate * img_template;
|
||||
char * error_msg = 0;
|
||||
int rc;
|
||||
|
||||
img_template = new ImageTemplate;
|
||||
rc = img_template->parse(stemplate,&error_msg);
|
||||
|
||||
if( rc == 0 )
|
||||
{
|
||||
return ImagePool::allocate(uid, img_template, oid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
@ -86,6 +120,7 @@ class ImagePoolTest : public PoolTest
|
||||
CPPUNIT_TEST ( bus_source_assignment );
|
||||
CPPUNIT_TEST ( public_attribute );
|
||||
CPPUNIT_TEST ( disk_overwrite );
|
||||
CPPUNIT_TEST ( imagepool_disk_attribute );
|
||||
CPPUNIT_TEST ( dump );
|
||||
CPPUNIT_TEST ( dump_where );
|
||||
|
||||
@ -100,13 +135,15 @@ protected:
|
||||
|
||||
PoolSQL* create_pool(SqlDB* db)
|
||||
{
|
||||
return new ImagePool(db, "source_prefix", "OS", "hd");
|
||||
ImagePoolFriend * imp =
|
||||
new ImagePoolFriend(db, "source_prefix", "OS", "hd");
|
||||
return imp;
|
||||
};
|
||||
|
||||
int allocate(int index)
|
||||
{
|
||||
int oid;
|
||||
return ((ImagePool*)pool)->allocate(uids[index],
|
||||
return ((ImagePoolFriend*)pool)->allocate(uids[index],
|
||||
templates[index],
|
||||
&oid);
|
||||
|
||||
@ -320,7 +357,7 @@ public:
|
||||
void duplicates()
|
||||
{
|
||||
int rc, oid;
|
||||
ImagePool * imp = static_cast<ImagePool *>(pool);
|
||||
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(pool);
|
||||
|
||||
// Allocate an image.
|
||||
rc = imp->allocate(uids[0], templates[0], &oid);
|
||||
@ -371,7 +408,7 @@ public:
|
||||
void wrong_templates()
|
||||
{
|
||||
int rc;
|
||||
ImagePool * imp = static_cast<ImagePool *>(pool);
|
||||
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(pool);
|
||||
|
||||
string templates[] =
|
||||
{
|
||||
@ -410,7 +447,7 @@ public:
|
||||
|
||||
void target_generation()
|
||||
{
|
||||
ImagePool * imp = static_cast<ImagePool *>(pool);
|
||||
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(pool);
|
||||
Image * img;
|
||||
|
||||
VectorAttribute * disk;
|
||||
@ -682,13 +719,85 @@ public:
|
||||
delete disk;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void imagepool_disk_attribute()
|
||||
{
|
||||
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(pool);
|
||||
Image * img;
|
||||
|
||||
VectorAttribute * disk;
|
||||
int oid_0, oid_1;
|
||||
string value;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Allocate 2 images, with different dev_prefix
|
||||
|
||||
string template_0 = "NAME = \"Image 0\"\n"
|
||||
"DEV_PREFIX = \"hd\"\n";
|
||||
|
||||
string template_1 = "NAME = \"Image 1\"\n"
|
||||
"DEV_PREFIX = \"sd\"\n";
|
||||
|
||||
|
||||
imp->allocate(0, template_0, &oid_0);
|
||||
CPPUNIT_ASSERT( oid_0 == 0 );
|
||||
|
||||
imp->allocate(0, template_1, &oid_1);
|
||||
CPPUNIT_ASSERT( oid_1 == 1 );
|
||||
|
||||
|
||||
img = imp->get(oid_0, false);
|
||||
CPPUNIT_ASSERT( img != 0 );
|
||||
img->enable(true);
|
||||
|
||||
img = imp->get(oid_1, false);
|
||||
CPPUNIT_ASSERT( img != 0 );
|
||||
img->enable(true);
|
||||
|
||||
|
||||
// Disk using image 0
|
||||
disk = new VectorAttribute("DISK");
|
||||
disk->replace("IMAGE", "Image 0");
|
||||
|
||||
((ImagePool*)imp)->disk_attribute(disk, 0);
|
||||
|
||||
value = "";
|
||||
value = disk->vector_value("TARGET");
|
||||
CPPUNIT_ASSERT( value == "hda" );
|
||||
|
||||
value = "";
|
||||
value = disk->vector_value("IMAGE_ID");
|
||||
CPPUNIT_ASSERT( value == "0" );
|
||||
|
||||
delete disk;
|
||||
|
||||
|
||||
// Disk using image 1 index
|
||||
disk = new VectorAttribute("DISK");
|
||||
disk->replace("IMAGE_ID", "1");
|
||||
|
||||
((ImagePool*)imp)->disk_attribute(disk, 0);
|
||||
|
||||
value = "";
|
||||
value = disk->vector_value("TARGET");
|
||||
CPPUNIT_ASSERT( value == "sda" );
|
||||
|
||||
value = "";
|
||||
value = disk->vector_value("IMAGE");
|
||||
CPPUNIT_ASSERT( value == "Image 1" );
|
||||
|
||||
delete disk;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void public_attribute()
|
||||
{
|
||||
int oid;
|
||||
ImagePool * imp = static_cast<ImagePool *>(pool);
|
||||
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(pool);
|
||||
Image * img;
|
||||
|
||||
string templates[] =
|
||||
@ -754,7 +863,14 @@ public:
|
||||
img = imp->get( oid, false );
|
||||
CPPUNIT_ASSERT( img != 0 );
|
||||
//cout << endl << i << " : exp. " << results[i] << " got " << img->is_public();
|
||||
CPPUNIT_ASSERT( img->is_public() == results[i] );
|
||||
|
||||
// =============================================================================
|
||||
// =============================================================================
|
||||
// Branch feature 203 doesn't have is_public method, but this test is
|
||||
// still valid for master.
|
||||
// CPPUNIT_ASSERT( img->is_public() == results[i] );
|
||||
// =============================================================================
|
||||
// =============================================================================
|
||||
|
||||
i++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user