Gadget schema for ubuntu image parser might be broken

I am using ubuntu-image to make a ubuntu-core image. In the gadget.yaml definition, I added the update and edition definitions (link to documentation found in The gadget snap Snapcraft documentation.

The ubuntu_image/parser.py:181-236 does not include the this in the schema. As a result calling ubuntu_image will fail because of that added key that is not in the schema. Is it expected to not have an update when making an image for the first time?

If when building the image and this added definition should not be there, the documentation in the referred link should be updated to clearly state to not include that definition when building

If it is… I would constitute this as a bug, and the Schema should be updated.

Here is the Schema in parser.py

GadgetYAML = Schema({
    Optional('defaults'): {
        str: {
            str: object
        }
    },
    Optional('connections'): [Schema({
        Required('plug'): str,
        Optional('slot'): str,
        })
    ],
    Optional('device-tree-origin', default='gadget'): str,
    Optional('device-tree'): str,
    Optional('format'): YAMLFormat,
    Required('volumes'): {
        Match('^[a-zA-Z0-9][-a-zA-Z0-9]*$'): Schema({
            Optional('schema', default='gpt' if has_new_voluptuous()
                    else VolumeSchema.gpt):
                Enumify(VolumeSchema),
            Optional('bootloader'): Enumify(
                BootLoader, preprocessor=methodcaller('replace', '-', '')),
            Optional('id'): Coerce(Id),
            Required('structure'): [Schema({
                Optional('name'): str,
                Optional('offset'): Coerce(as_size),
                Optional('offset-write'): Any(
                    Coerce(Size32bit), RelativeOffset),
                Required('size'): Coerce(as_size),
                Required('type'): Any('mbr', 'bare', Coerce(HybridId)),
                Optional('role'): Enumify(
                    StructureRole,
                    preprocessor=methodcaller('replace', '-', '_')),
                Optional('id'): Coerce(UUID),
                Optional('filesystem', default='none' if has_new_voluptuous()
                        else FileSystemType.none):
                    Enumify(FileSystemType),
                Optional('filesystem-label'): str,
                Optional('content'): Any(
                    [Schema({
                        Required('source'): str,
                        Required('target'): str,
                        })
                    ],                                  # noqa: E124
                    [Schema({
                        Required('image'): str,
                        Optional('offset'): Coerce(as_size),
                        Optional('offset-write'): Any(
                            Coerce(Size32bit), RelativeOffset),
                        Optional('size'): Coerce(as_size),
                        })
                    ],
                )
            })]
        })
    }
})

Here is the YAML definition with the addition based off pc-amd64-gadget:gadget.yaml on the 18 branch

volumes:
  pc:
    bootloader: grub
    structure:
      - name: mbr
        type: mbr
        size: 440
        content:
          - image: pc-boot.img
      - name: BIOS Boot
        type: DA,21686148-6449-6E6F-744E-656564454649
        size: 1M
        offset: 1M
        offset-write: mbr+92
        content:
          - image: pc-core.img
      - name: EFI System
        type: EF,C12A7328-F81F-11D2-BA4B-00A0C93EC93B
        filesystem: vfat
        filesystem-label: system-boot
        size: 50M
        content:
          - source: grubx64.efi
            target: EFI/boot/grubx64.efi
          - source: shim.efi.signed
            target: EFI/boot/bootx64.efi
          - source: mmx64.efi
            target: EFI/boot/mmx64.efi
          - source: grub.cfg
            target: EFI/ubuntu/grub.cfg
        update:
          - edition: 0

looks like ubuntu-image is a bit behind, better file a bug at:

https://bugs.launchpad.net/ubuntu-image/+filebug

I’ll look into fixing this in ubuntu-image

Opened a PR with and update to the schema validator.