diff --git a/include/Image.h b/include/Image.h index d46696abf1..6ea5655df6 100644 --- a/include/Image.h +++ b/include/Image.h @@ -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); diff --git a/src/image/Image.cc b/src/image/Image.cc index ad8074808e..4bbd4c2e53 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -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; diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index 97b755ef33..1793ade0d6 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -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(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; }