vmware / open-vmdk

Apache License 2.0
113 stars 46 forks source link

Cannot use `--param disk0=xxx` to specify a disk #64

Closed hjiajing closed 3 months ago

hjiajing commented 3 months ago

Describe the bug

When I use the command as follows to build from vmdk, I get an error shows no such file.

ova-compose -i /photon.yaml -o /src/photon-ova.ova --param disk0=/src/ova/photon-ova0.vmdk

Traceback (most recent call last):
  File "/usr/bin/ova-compose", line 1363, in <module>
    main()
  File "/usr/bin/ova-compose", line 1299, in main
    ovf = OVF.from_dict(config)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/ova-compose", line 958, in from_dict
    disk = OVFDisk(hw['disk_image'],
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/ova-compose", line 605, in __init__
    self.file = OVFFile(path)
                ^^^^^^^^^^^^^
  File "/usr/bin/ova-compose", line 542, in __init__
    self.size = os.path.getsize(self.path)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen genericpath>", line 50, in getsize
FileNotFoundError: [Errno 2] No such file or directory: 'photon-ova0.vmdk'

Reproduction steps

ova-compose --param disk0={SOME_PATH}

Expected behavior

Build successfully.

Additional context

I believe this is because we should not use a basename here:

class OVFFile(object):
    next_id = 0

    def __init__(self, path, file_id=None):
        self.path = os.path.basename(path)
        if file_id is None:
            self.id = f"file{OVFFile.next_id}"
            OVFFile.next_id += 1
        else:
            self.id = file_id
        self.size = os.path.getsize(self.path)
oliverkurth commented 3 months ago

Please see https://github.com/vmware/open-vmdk/pull/63 . Feel free to test it.