[Kimchi-devel] [PATCH] tests/iso_gen.py: adding fake bootable PowerPC ISO

Royce Lv lvroyce at linux.vnet.ibm.com
Thu Jan 29 07:55:49 UTC 2015


Comments inline.
On 01/28/2015 12:54 PM, Daniel Henrique Barboza wrote:
> There was no support for ppc fake ISOs in iso_gen.py, which led
> to several tests crashing in Power systems when the test tries
> to create a template with a fake Intel ISO.
>
> Signed-off-by: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
> ---
>   tests/iso_gen.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 47 insertions(+), 2 deletions(-)
>
> diff --git a/tests/iso_gen.py b/tests/iso_gen.py
> index 34f091d..1d1262f 100644
> --- a/tests/iso_gen.py
> +++ b/tests/iso_gen.py
> @@ -17,6 +17,7 @@
>   # License along with this library; if not, write to the Free Software
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>
> +import platform
>   import struct
>
>   from kimchi.isoinfo import IsoImage
> @@ -57,9 +58,12 @@ iso_des = [
>
>   class FakeIsoImage(object):
>       def _build_iso(self, fd, iso_volid, bootable):
> -        self._build_el_boot(fd, bootable)
>           self._build_prim_vol(fd, iso_volid)
> -        self._build_el_torito(fd)
> +        if platform.machine().startswith('ppc'):
> +            self._build_bootable_ppc_path_table(fd)
> +        else:
> +            self._build_el_boot(fd, bootable)
> +            self._build_el_torito(fd)
I don't think this will work for x86_64, because three calls 
_build_el_boot, _build_prim_vol and _build_el_torito write file in 
sequence without "fd.seek".
That is to say we can't put _build_el_boot after _build_prim_vol.

Below is a centos ISO generated by this patch, isoinfo.py cannot read 
its format because the record is not right.

royce at royce-cn:~/kimchi-2/kimchi$ PYTHONPATH=./src python 
./src/kimchi/isoinfo.py /home/royce/kimchi-2/kimchi/tests/centos.iso
Traceback (most recent call last):
   File "./src/kimchi/isoinfo.py", line 504, in <module>
     probe_iso(None, dict(path=sys.argv[1], updater=updater))
   File "./src/kimchi/isoinfo.py", line 490, in probe_iso
     iso_img = IsoImage(loc)
   File "./src/kimchi/isoinfo.py", line 153, in __init__
     raise IsoFormatError('KCHISO0009E', {'filename': self.path})
kimchi.exception.IsoFormatError: KCHISO0009E: Incomplete record while 
reading ISO /home/royce/kimchi-2/kimchi/tests/centos.iso.

Before:
royce at royce-cn:~/kimchi-2/kimchi/tests$ PYTHONPATH=../src python 
../src/kimchi/isoinfo.py ./centos.iso
[{'path': '/home/royce/kimchi-2/kimchi/tests/centos.iso', 'version': 
'6.1', 'distro': 'centos'}]
>
>       def _build_prim_vol(self, fd, iso_volid):
>           fd.seek(16 * IsoImage.SECTOR_SIZE)
> @@ -125,6 +129,47 @@ class FakeIsoImage(object):
>           s = 'a' * IsoImage.SECTOR_SIZE
>           fd.write(s)
>
> +    def _build_bootable_ppc_path_table(self, fd):
> +        # write path table locator
> +        PATH_TABLE_LOC_OFFSET = 16 * IsoImage.SECTOR_SIZE + 132
> +        PATH_TABLE_SIZE_LOC = struct.Struct("<I 4s I")
> +        path_table_size = 64
> +        path_table_loc = 18
> +        fd.seek(PATH_TABLE_LOC_OFFSET)
> +        fmt = PATH_TABLE_SIZE_LOC
> +        data = (path_table_size, 4*'0', path_table_loc)
> +        s = fmt.pack(*data)
> +        fd.write(s)
> +        # write path table entry
> +        fd.seek(path_table_loc * IsoImage.SECTOR_SIZE)
> +        DIR_NAMELEN_LOCATION_PARENT = struct.Struct("<B B I H 3s")
> +        dir_struct_size = DIR_NAMELEN_LOCATION_PARENT.size
> +        dir_namelen = 3
> +        dir_loc = 19
> +        dir_parent = 1
> +        dir_name = 'ppc'
> +        data = (dir_namelen, 0, dir_loc, dir_parent, dir_name)
> +        fmt = DIR_NAMELEN_LOCATION_PARENT
> +        s = fmt.pack(*data)
> +        fd.write(s)
> +        # write 'ppc' dir record
> +        ppc_dir_offset = dir_loc * IsoImage.SECTOR_SIZE
> +        fd.seek(ppc_dir_offset)
> +        STATIC_DIR_RECORD_FMT = struct.Struct("<B 9s I 11s B 6s B 12s")
> +        dir_rec_len = 1
> +        unused1 = 9 * '0'
> +        dir_size = 100
> +        unused2 = 11 * '0'
> +        file_flags = 0
> +        unused3 = 6 * '0'
> +        file_name_len = 12
> +        boot_file_name = "bootinfo.txt"
> +        data = (dir_rec_len, unused1, dir_size, unused2, file_flags,
> +                unused3, file_name_len, boot_file_name)
> +        fmt = STATIC_DIR_RECORD_FMT
> +        s = fmt.pack(*data)
> +        fd.write(s)
> +
>
>   def construct_fake_iso(path, bootable, version, distro):
>       iso = FakeIsoImage()




More information about the Kimchi-devel mailing list