Commit Graph

26 Commits

Author SHA1 Message Date
Olivier Gayot afd6fca8b4 kvm-test: allow kvm-test.yaml to add/modify profiles
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-11-12 22:02:20 +01:00
Olivier Gayot de4e126087 kvm-test: have different profiles for server and desktop
Booting Desktop and server live installer ISOs comes with different
platform requirements. When running kvm-test, we now accept the name of
a profile via the --profile option.

Profiles provide default settings for memory, disk size and extra QEMU
options. For now, two profiles are hard-coded: "server" - which is the
default and "desktop".

For desktop, we use two vCPU, 8 GiB of RAM, a 20 GiB disk and pass the
-device qxl option.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-11-07 14:36:07 +01:00
Olivier Gayot b0e1c57145 snapcraft: use snapcraft pack instead of snapcraft snap
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-10-20 15:41:24 +02:00
Olivier Gayot 5244890c5a kvm-test: support emulating a TPM 2.0
When invoking kvm-test.py, one can pass the --with-tpm2 option so that
we emulate a TPM and make it available in the guest.

This requires the swtpm package which is available in jammy and more
recent versions of Ubuntu.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-08-02 16:58:25 +02:00
Olivier Gayot 62a2f3104c kvm-test: allow to specify a cloud-init file not meant for autoinstall
The --cloud-config option now replaces the old --autoinstall-file
option.

The use of --autoinstall-file always made kvm-test pass the autoinstall
argument to the kernel command line. With the --cloud-config option, we
now determine if the autoinstall argument is needed by reading the cloud
config and checking if an autoinstall section is present.

The two new options --force-autoinstall and --force-no-autoinstall can
be used to override this behaviour.

The --autoinstall option is also dropped. If we want to use the default,
hardcoded cloud-config, one can use --cloud-config-default.

This can be useful to ease debugging of the VM using a config that looks
like:

    #cloud-config
    users:
        - default
        - name: root
          ssh_import_id: lp:ogayot

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-09-22 13:09:59 +02:00
Olivier Gayot e58d1d00c2 kvm-test: introduce ability to pass -nic options to QEMU
The only way we had to pass -nic options to QEMU was to specify the
number of networks using the --nets option. Depending on its value, the
option would instruct QEMU to:
 * instantiate *n* user host networks if --nets >= 1
 * instantiate no network if --nets is 0
 * instantiate a "dead" network if --nets < 0

To simulate more advanced networks (such as networks where HTTP proxy is
needed), we want to add the possibility to use TAP network interfaces.

This patch adds the ability to pass custom -nic options to QEMU.

Three new options are available:

 * The --nic option passes the argument as-is to QEMU -nic option
 * The --nic-user option passes a user host network -nic option to QEMU
   - with SSH forwarding enabled. This is just like we do when using the
     --nets >= 1 option)
 * The --net-tap takes the name of an existing tap interface and
   generates the following -nic argument:

    tap,id={ifname},ifname={ifname},script=no,downscript=no,model=e1000

In the example below:
 * the first network uses the tap0 interface.
 * the second network uses the tap1 interface (it is syntactically
   equivalent to the first one)
 * the third network uses a user host network (with SSH forwarding)

  $ kvm-test.py \
    --nic tap,id=tap0,ifname=tap0,script=no,downscript=no,model=e1000 \
    --nic-tap tap1 \
    --nic-user

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-28 14:48:51 +02:00
Olivier Gayot eb7dee2c9e kvm-test: get rid of unused import random
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-27 20:04:33 +02:00
Olivier Gayot 6165c0a423 kvm-test: don't require LIVEFS_EDITOR if not building
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-27 19:59:37 +02:00
Olivier Gayot 83dacb8c7c kvm-test: don't execute code if module is imported
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-27 19:56:42 +02:00
Dan Bungert a6901ddc25 kvm-test: allow deadnet simulation with --nets -1 2022-01-24 17:03:00 -07:00
Olivier Gayot 81bc59019c Remove --use-fuse switch and make it the default
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-01-20 12:01:44 +01:00
Olivier Gayot f1119b02a6 Add --use-fuse switch to kvm-test --install so it can run as non-root
Passing --use-fuse to scripts/kvm-test.py allows to run as non-root.

It requires installation of the package fuseiso so the switch is
disabled by default.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-01-19 10:10:33 +01:00
Olivier Gayot 82aeeecbc6 Fix kernel command line from kvm-test.sh
Since 06ac3f92, we invoke kvm directly through subprocess.run.
Therefore, we must not add extra quotes around the -append options,
otherwise they persist and are passed in the kernel command line:

  $ cat /proc/cmdline
  "autoinstall subiquity-channel=stable" initrd=initrd

Later on, we fail to parse "autoinstall" and "subiquity-channel=stable"
as two distinct options.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-01-13 12:33:50 -07:00
Olivier Gayot ed0e6861aa Fix -drive option from kvm-test.sh
The function drive() used to return a string in the following format:

  "-drive file=/path/to/iso,..."

However, qemu/kvm expects "-drive" to be an argument and
"file=/path/to/iso,..." to be another argument.

The command was constructed as below since the beginning:

  kvm = [
     "kvm",
     "-cdrom", "custom.iso",          # <- OK
     "-drive file=/path/to/iso,...",  # <- NOK
  ]

Before 06ac3f92, we would join all the arguments using spaces before
executing the kvm command. Therefore we would luckily end up with a
correct command:

  " ".join(kvm)  ->  "kvm -cdrom custom.iso -drive file=/path/to/iso,..."

However, now that we supply the command to subprocess.run directly, the
problem shows up.

Fixed by returning a tuple("-drive", "file=/path/to/iso,...") from
the drive() function.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-01-13 12:33:47 -07:00
Dan Bungert 3a696ca459
Update scripts/kvm-test.py
Co-authored-by: Olivier Gayot <duskcoder@gmail.com>
2022-01-13 12:25:12 -07:00
Dan Bungert 98bf2943aa kvm-test: pep8 fixes 2022-01-12 14:56:58 -07:00
Dan Bungert e5e5d69a2d kvm-test: proxy, livefs_edit, debug
* add http_proxy recognition.  Picks up from DEBOOTSTRAP_PROXY.
* fix livefs_edit invocation
* include --debug in snap construction
2022-01-12 14:56:58 -07:00
Dan Bungert 52ede053ac kvm-test: review feedback and fixes
* fix several syntax errors
* missing 'this' item was renamed to 'iso'
* change the simulated 'bash -x' output to stderr
* use shlex functions for join/split
2022-01-04 10:58:09 -07:00
Dan Bungert 06ac3f92b5 kvm-test: cleanups
* better command execution
* various build arguments imply --build, so one can do just '-q' where
  one would have to previously '--build -q'
2021-12-16 13:31:13 -07:00
Dan Bungert e31a3c31ac kvm-test: fix slimy invocation
We can't delete the snap file created by quick-test because we don't
have the path to it.  The with statement makes no sense.
2021-11-08 16:44:35 -07:00
Michael Hudson-Doyle ce94726a43 kvm-test: do not boot via -kernel/-initrd unless needed 2021-11-05 16:05:22 +13:00
Michael Hudson-Doyle b6e4181fe7 kvm-test: fix a typo 2021-11-05 16:05:00 +13:00
Michael Hudson-Doyle c3727ac506 kvm-test: fix assumption around snap name quick-test-this-branch.sh creates 2021-11-05 16:04:51 +13:00
Michael Hudson-Doyle 8b7662b0a3 kvm-test: add a --snap argument to inject a specific snap 2021-11-05 16:04:18 +13:00
Michael Hudson-Doyle 277e1fe173 kvm-test: add a --basenap argument
this is like --quick but updates a passed snap rather than the one
already in the iso
2021-11-05 16:03:41 +13:00
Dan Bungert a67b9d18dc scripts: add kvm-test
Updated version of the kvm-test script shown previously.
2021-11-04 17:32:52 -06:00