mount_gpt_image.sh: Load partition numbers from the GPT

The recent break (https://chromium-review.googlesource.com/c/441109/)
was caused because the failing parrot test
(https://uberchromegw.corp.google.com/i/chromeos/builders/parrot-paladin/builds/22380/steps/VMTest%20%28attempt%202%29/logs/stdio)
copies a test qemu image out of the build area without also including
the partition script.

The mount_gpt_image.sh script tries to use --from to load the partition
script. When this fails (because it was not copied with the image), it
tries to use --rootfs_mountpt -- which also fails, because the rootfs
isn't actually mounted. This means all of the PARTITION_NUM_* variables
are not defined, which causes the parrot test error.

In general we handled this in the past by using cgpt_py to get the
partition number from the disk_layout.json, but it looks like we can
just read using ${GPT} directly. This avoids needing to supply the image
type needed to satisfy cgpt_py, since we're using the GPT directly.

BUG=b:35045101
TEST=Build parrot qemu test image, verify mount_gpt_image.sh against an
image, and verify the commands succeed:

  b=parrot
  ./build_packages --board=$b
  ./build_image --board=$b test
  ./image_to_vm.sh --board=$b --from=../build/images/$b/latest --test_image
  T=$(mktemp -d);mkdir -p $T/{s,m}
  cp ../build/images/$b/latest/chromiumos_qemu_image.bin $T
  ./mount_gpt_image.sh --from=$T --image=chromiumos_qemu_image.bin \
      --rootfs_mountpt=$T/m --stateful_mountpt=$T/s --safe
  ./mount_gpt_image.sh --from=$T --image=chromiumos_qemu_image.bin \
      --rootfs_mountpt=$T/m --stateful_mountpt=$T/s --safe -u

Change-Id: I90f444c1dd2077474a122d3fc93ca57282f94be5
Reviewed-on: https://chromium-review.googlesource.com/455576
Commit-Ready: Ian Coolidge <icoolidge@google.com>
Tested-by: Ian Coolidge <icoolidge@google.com>
Reviewed-by: Joshua Emele <jemele@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2 files changed