CP-5923: Add the test input as an argument to extract_output

Signed-off-by: John Else <john.else@citrix.com>
CP-5923: Add a couple of basic tests of get_remaining_capacity

Signed-off-by: John Else <john.else@citrix.com>
CP-5845: Fix partially applied helper function

The call_api_functions was only partially applied and so the function couldn't
be used as a comparitor for the Schwarzian transform sort.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Don't allow changing of VGPUs for running VMs

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Change how PGPU.set_GPU_group is called via the CLI

Instead of

  xe pgpu-set-gpu-group uuid=... gpu-group-uuid=...

a user now needs to call

  xe pgpu-param-set uuid=... gpu-group-uuid=...

for consistency with other CLI setters.

Signed-off-by: John Else <john.else@citrix.com>
Check VGPU type is supported when checking enabled

Required a re-order of function definitions.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Allow moving last PGPU out of GPU group with VGPUs

With the new API, it is perfectly reasonably to create VGPUs on GPU groups with
no pGPUs in them since vGPU -> pGPU allocation is done at VM start time. As
such we can loosen the requirements on moving the last pGPU out of a GPU group.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Disallow moving of PGPUs with resident VGPUs

The precondition was checking for PCI.attached_VMs on the PGPU's PCI. This
isn't used for VGPU and so the check was not robust. Now we check using the
resident_VGPUs field of the PGPU from the new API.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Add assert_raises_api_error to unit test helpers

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
CP-5923: Unit tests for Xapi_pgpu module

Tests for assert_can_run_VGPU, get_remaining_capacity and set_GPU_group.

Modifications are made to the mock-PGPU creation to also craete a mock PCI
device.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
CP-5932: Ensure videoram is at least 16MiB for vGPU

Signed-off-by: John Else <john.else@citrix.com>
Refactor the xenops metadata unit tests

Signed-off-by: John Else <john.else@citrix.com>
CP-5932: Add tests for handling of videoram with vGPU

Signed-off-by: John Else <john.else@citrix.com>
Add VGPU_type.{supported,enabled}_on_PGPUs to CLI

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Fix VM.allowed_operations for VMs with VGPUs

Block migrate/suspend/checkpoint for VMs with any kind of VGPU (not just
for VMs with passthrough VGPUs).

Signed-off-by: John Else <john.else@citrix.com>
Block migrate_send for VMs with attached PCIs

Signed-off-by: John Else <john.else@citrix.com>
Improve PGPU capacity error reporting

* Change error PGPU_INSUFFICIENT_CAPACITY_FOR_VGPU to be parameterised
  with a VGPU type, rather than with a VGPU.
* Modify Xapi_pgpu_helpers.assert_capacity_exists_for_VGPU_type to
  return a (exn, int64) Either.t so we can more easily find out why a
  VGPU is not able to run on a PGPU.
* Add Xapi_gpu_group.get_remaining_capacity_internal, which calls the
  same function for each PGPU in the group and, if there are no
  available PGPU, chooses an error to return.
* Fix the tests so that they still compile (and pass).

Signed-off-by: John Else <john.else@citrix.com>
Improve exception handling for VMs with VGPUs

Raise the exception newly returned from
Xapi_gpu_group.get_remaining_capacity_internal, rather than raising the
same exception whatever happened.

Signed-off-by: John Else <john.else@citrix.com>
Rename a group of tests

Signed-off-by: John Else <john.else@citrix.com>
Improve unit tests for passthrough VGPUs

When creating a passthrough VGPU on a PGPU, create a VM and mark it as
attached to the PGPU's PCI device.

Signed-off-by: John Else <john.else@citrix.com>