feature #200: Image's get_disk_attribute now adds SOURCE attribute as well.

This commit is contained in:
Carlos Martín authored and Constantino Vázquez Blanco committed 2010-05-31 15:17:14 +02:00
1 parent 5dcb81c27c
commit 2cb9de488d
3 files changed
+46 -16

No files matched your search

+10 -9
View File
@@ -141,15 +141,16 @@ public:
void release_image();
/**
* Modifies the given disk attribute to set the target value.
* * OS images will be mounted at prefix + a: hda, sda.
* * Prefix + b is reserved for the contex cdrom.
* * CDROM images will be at prefix + c: hdc, sdc.
* * Several DATABLOCK images can be mounted, they will be set to
* prefix + (d + index) : hdd, hde, hdf...
* returns: 0 if the disk was not modified
* 1 if the disk was modified correctly
* -1 in case of error
* Modifies the given disk attribute adding the following attributes:
* * SOURCE: the file-path.
* * BUS: will only be set if the Image's definition includes it.
* * TARGET: the value set depends on:
* - OS images will be mounted at prefix + a: hda, sda.
* - Prefix + b is reserved for the contex cdrom.
* - CDROM images will be at prefix + c: hdc, sdc.
* - Several DATABLOCK images can be mounted, they will be set to
* prefix + (d + index) : hdd, hde, hdf...
* returns: 0 on success, -1 in case of error.
*/
int get_disk_attribute(VectorAttribute * disk, int index);
+5 -2
View File
@@ -420,6 +420,11 @@ int Image::get_disk_attribute(VectorAttribute * disk, int index)
string target = "";
string bus = "";
// SOURCE attribute
disk->replace("SOURCE", source);
// The BUS attribute isn't mandatory.
get_template_attribute("BUS", bus);
@@ -470,8 +475,6 @@ int Image::get_disk_attribute(VectorAttribute * disk, int index)
// "Replace" inserts the name-value pair even if it doesn't exist.
disk->replace("TARGET", target);
return 1;
}
return 0;
+31 -5
View File
@@ -81,7 +81,7 @@ class ImagePoolTest : public PoolTest
CPPUNIT_TEST ( extra_attributes );
CPPUNIT_TEST ( wrong_templates );
CPPUNIT_TEST ( target_generation );
CPPUNIT_TEST ( bus_assignment );
CPPUNIT_TEST ( bus_source_assignment );
CPPUNIT_TEST ( dump );
CPPUNIT_TEST ( dump_where );
@@ -440,7 +440,7 @@ public:
}
void bus_assignment()
void bus_source_assignment()
{
ImagePool * imp = static_cast<ImagePool *>(pool);
Image * img;
@@ -449,18 +449,44 @@ public:
int oid;
string value;
disk = new VectorAttribute("DISK");
disk->replace("BUS", "SCSI");
// Allocate an OS type image
oid = allocate(0);
img = imp->get(oid, false);
// ---------------------------------------------------------------------
// A disk without a BUS attribute should not have it added.
disk = new VectorAttribute("DISK");
img->get_disk_attribute(disk, 0);
value = "";
value = disk->vector_value("BUS");
CPPUNIT_ASSERT( value == "" );
value = "";
value = disk->vector_value("SOURCE");
CPPUNIT_ASSERT( value ==
"source_prefix/7e997f5fdc26712ac64eac8385fc81632b4bf024" );
// clean up
delete disk;
// ---------------------------------------------------------------------
// A disk with a BUS attribute should not have it overwritten.
disk = new VectorAttribute("DISK");
disk->replace("BUS", "SCSI");
img->get_disk_attribute(disk, 0);
value = disk->vector_value("BUS");
CPPUNIT_ASSERT( value == "SCSI" );
value = "";
value = disk->vector_value("SOURCE");
CPPUNIT_ASSERT( value ==
"source_prefix/7e997f5fdc26712ac64eac8385fc81632b4bf024" );
// clean up
delete disk;
}