Unverified Commit 55890046 authored by Adam C. Stephens's avatar Adam C. Stephens
Browse files

nixos/tests/incus: migrate test suite to runTest modules

parent a4c85a90
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -743,12 +743,17 @@ in
  immich-vectorchord-reindex = runTest ./web-apps/immich-vectorchord-reindex.nix;
  incron = runTest ./incron.nix;
  incus = recurseIntoAttrs (
    handleTest ./incus {
    import ./incus {
      inherit runTest;
      lts = false;
      inherit system pkgs;
    }
  );
  incus-lts = recurseIntoAttrs (handleTest ./incus { inherit system pkgs; });
  incus-lts = recurseIntoAttrs (
    import ./incus {
      inherit runTest;
      lts = true;
    }
  );
  influxdb = runTest ./influxdb.nix;
  influxdb2 = runTest ./influxdb2.nix;
  initrd-luks-empty-passphrase = runTest ./initrd-luks-empty-passphrase.nix;
+27 −34
Original line number Diff line number Diff line
{
  system ? builtins.currentSystem,
  config ? { },
  pkgs ? import ../../.. { inherit system config; },
  runTest,
  lts ? true,
  ...
}:
let
  incusTest = import ./incus-tests.nix;
  incusTest =
    config:
    runTest {
      imports = [
        ./incus-tests-module.nix
        ./incus-tests.nix
      ];

      tests.incus = {
        inherit lts;
      }
      // config;
    };
in
{
  all = incusTest {
    inherit lts pkgs system;
    allTests = true;
  };
  all = incusTest { all = true; };

  container = incusTest {
    inherit lts pkgs system;
    instanceContainer = true;
  appArmor = incusTest {
    all = true;
    appArmor = true;
  };

  lvm = incusTest {
    inherit lts pkgs system;
    storageLvm = true;
  };
  container = incusTest { instance.container = true; };

  openvswitch = incusTest {
    inherit lts pkgs system;
    networkOvs = true;
  };
  lvm = incusTest { storage.lvm = true; };

  ui = import ./ui.nix {
    inherit lts pkgs system;
  };
  openvswitch = incusTest { network.ovs = true; };

  virtual-machine = incusTest {
    inherit lts pkgs system;
    instanceVm = true;
  };
  ui = runTest {
    imports = [ ./ui.nix ];

  zfs = incusTest {
    inherit lts pkgs system;
    storageZfs = true;
    _module.args = { inherit lts; };
  };

  appArmor = incusTest {
    inherit lts pkgs system;
    appArmor = true;
    allTests = true;
  };
  virtual-machine = incusTest { instance.virtual-machine = true; };

  zfs = incusTest { storage.zfs = true; };
}
+56 −0
Original line number Diff line number Diff line
{ config, lib, ... }:
let
  cfg = config.tests.incus;
in
{
  options.tests.incus = {
    lts = lib.mkEnableOption "LTS package testing";

    all = lib.mkEnableOption "All tests";
    appArmor = lib.mkEnableOption "AppArmor during tests";

    feature.user = lib.mkEnableOption "Validate incus user access feature";

    init = {
      legacy = lib.mkEnableOption "Validate non-systemd init";
      systemd = lib.mkEnableOption "Validate systemd init";
    };

    instance = {
      container = lib.mkEnableOption "Validate container functionality";
      virtual-machine = lib.mkEnableOption "Validate virtual machine functionality";
    };

    network.ovs = lib.mkEnableOption "Validate OVS network integration";

    storage = {
      lvm = lib.mkEnableOption "Validate LVM storage integration";
      zfs = lib.mkEnableOption "Validate ZFS storage integration";
    };
  };

  config = {
    tests.incus = {
      lts = lib.mkDefault true;

      feature.user = lib.mkDefault cfg.all;

      init = {
        legacy = lib.mkDefault cfg.all;
        systemd = lib.mkDefault true;
      };

      instance = {
        container = lib.mkDefault cfg.all;
        virtual-machine = lib.mkDefault cfg.all;
      };

      network.ovs = lib.mkDefault cfg.all;

      storage = {
        lvm = lib.mkDefault cfg.all;
        zfs = lib.mkDefault cfg.all;
      };
    };
  };
}
+392 −405
Original line number Diff line number Diff line
import ../make-test-python.nix (
{
  config,
  pkgs,
  lib,

    lts ? true,

    allTests ? false,

    appArmor ? false,
    featureUser ? allTests,
    initLegacy ? true,
    initSystemd ? true,
    instanceContainer ? allTests,
    instanceVm ? allTests,
    networkOvs ? allTests,
    storageLvm ? allTests,
    storageZfs ? allTests,
  ...
}:

let
  cfg = config.tests.incus;

  releases =
    init:
    import ../../release.nix {
@@ -52,12 +40,13 @@ import ../make-test-python.nix (
    };
  };

    initVariants = lib.optionals initLegacy [ "legacy" ] ++ lib.optionals initSystemd [ "systemd" ];
  initVariants =
    lib.optionals cfg.init.legacy [ "legacy" ] ++ lib.optionals cfg.init.systemd [ "systemd" ];

    canTestVm = instanceVm && pkgs.stdenv.isLinux && pkgs.stdenv.isx86_64;
  canTestVm = cfg.instance.virtual-machine && pkgs.stdenv.isLinux && pkgs.stdenv.isx86_64;
in
{
    name = "incus" + lib.optionalString lts "-lts";
  name = "incus" + lib.optionalString cfg.lts "-lts";

  meta = {
    maintainers = lib.teams.lxc.members;
@@ -66,7 +55,7 @@ import ../make-test-python.nix (
  nodes.machine = {
    virtualisation = {
      cores = 2;
        memorySize = 2048;
      memorySize = 4096;
      diskSize = 12 * 1024;
      emptyDiskImages = [
        # vdb for zfs
@@ -77,7 +66,7 @@ import ../make-test-python.nix (

      incus = {
        enable = true;
          package = if lts then pkgs.incus-lts else pkgs.incus;
        package = if cfg.lts then pkgs.incus-lts else pkgs.incus;

        preseed = {
          networks = [
@@ -90,7 +79,7 @@ import ../make-test-python.nix (
              };
            }
          ]
            ++ lib.optionals networkOvs [
          ++ lib.optionals cfg.network.ovs [
            {
              name = "ovsbr0";
              type = "bridge";
@@ -128,27 +117,26 @@ import ../make-test-python.nix (
        };
      };

        vswitch.enable = networkOvs;
      vswitch.enable = cfg.network.ovs;
    };

      boot.supportedFilesystems = lib.optionals storageZfs [ "zfs" ];
    boot.supportedFilesystems = { inherit (cfg.storage) zfs; };
    boot.zfs.forceImportRoot = false;

    environment.systemPackages = [ pkgs.parted ];

    networking.hostId = "01234567";
    networking.firewall.trustedInterfaces = [ "incusbr0" ];
    networking.nftables.enable = true;

      security.apparmor.enable = appArmor;
      services.dbus.apparmor = (if appArmor then "enabled" else "disabled");
    security.apparmor.enable = cfg.appArmor;
    services.dbus.apparmor = (if cfg.appArmor then "enabled" else "disabled");

    services.lvm = {
        boot.thin.enable = storageLvm;
        dmeventd.enable = storageLvm;
      boot.thin.enable = cfg.storage.lvm;
      dmeventd.enable = cfg.storage.lvm;
    };

      networking.nftables.enable = true;

    users.users.testuser = {
      isNormalUser = true;
      shell = pkgs.bashInteractive;
@@ -220,7 +208,7 @@ import ../make-test-python.nix (
        machine.succeed("incus storage show default")

  ''
    + lib.optionalString appArmor ''
  + lib.optionalString cfg.appArmor ''
    with subtest("Verify AppArmor service is started without issue"):
        # restart AppArmor service since the Incus AppArmor folders are
        # created after AA service is started
@@ -228,7 +216,7 @@ import ../make-test-python.nix (
        machine.succeed("systemctl --no-pager -l status apparmor.service")
        machine.wait_for_unit("apparmor.service")
  ''
    + lib.optionalString instanceContainer (
  + lib.optionalString cfg.instance.container (
    lib.foldl (
      acc: variant:
      acc
@@ -423,7 +411,7 @@ import ../make-test-python.nix (
      ''
  )
  +
      lib.optionalString featureUser # python
    lib.optionalString cfg.feature.user # python
      ''
        with subtest("incus-user allows restricted access for users"):
            machine.fail("incus project show user-1000")
@@ -442,7 +430,7 @@ import ../make-test-python.nix (
        cleanup()
      ''
  +
      lib.optionalString networkOvs # python
    lib.optionalString cfg.network.ovs # python
      ''
        with subtest("Verify openvswitch bridge"):
            machine.succeed("incus network info ovsbr0")
@@ -453,7 +441,7 @@ import ../make-test-python.nix (
      ''

  +
      lib.optionalString storageZfs # python
    lib.optionalString cfg.storage.zfs # python
      ''
        with subtest("Verify zfs pool created and usable"):
            machine.succeed(
@@ -478,7 +466,7 @@ import ../make-test-python.nix (
      ''

  +
      lib.optionalString storageLvm # python
    lib.optionalString cfg.storage.lvm # python
      ''
        with subtest("Verify lvm pool created and usable"):
            machine.succeed("incus storage create lvm_pool lvm source=/dev/vdc lvm.vg_name=incus_pool")
@@ -497,4 +485,3 @@ import ../make-test-python.nix (
            machine.succeed("incus list lvm1")
      '';
}
)
+76 −78
Original line number Diff line number Diff line
import ../make-test-python.nix (
{
  pkgs,
  lib,
@@ -81,4 +80,3 @@ import ../make-test-python.nix (
    machine.succeed("PYTHONUNBUFFERED=1 selenium-script")
  '';
}
)