mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-03-04 06:34:43 +01:00
tests: add Justile, used as integration environment helper.
Some checks are pending
Ubuntu / check (push) Waiting to run
Ubuntu / build (default, ubuntu-22.04) (push) Blocked by required conditions
Ubuntu / build (default, ubuntu-24.04) (push) Blocked by required conditions
Ubuntu / build (full-system-policy, ubuntu-22.04) (push) Blocked by required conditions
Ubuntu / build (full-system-policy, ubuntu-24.04) (push) Blocked by required conditions
Ubuntu / tests (push) Blocked by required conditions
Some checks are pending
Ubuntu / check (push) Waiting to run
Ubuntu / build (default, ubuntu-22.04) (push) Blocked by required conditions
Ubuntu / build (default, ubuntu-24.04) (push) Blocked by required conditions
Ubuntu / build (full-system-policy, ubuntu-22.04) (push) Blocked by required conditions
Ubuntu / build (full-system-policy, ubuntu-24.04) (push) Blocked by required conditions
Ubuntu / tests (push) Blocked by required conditions
This commit is contained in:
parent
0b029ec42f
commit
1392b078ab
4 changed files with 162 additions and 140 deletions
162
Justfile
Normal file
162
Justfile
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
# apparmor.d - Full set of apparmor profiles
|
||||||
|
# Copyright (C) 2025 Alexandre Pujol <alexandre@pujol.io>
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
|
# Integration environment for apparmor.d
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# just
|
||||||
|
# just img ubuntu24 server
|
||||||
|
# just vm ubuntu24 server
|
||||||
|
# just up ubuntu24 server
|
||||||
|
# just ssh ubuntu24 server
|
||||||
|
# just halt ubuntu24 server
|
||||||
|
# just destroy ubuntu24 server
|
||||||
|
# just list
|
||||||
|
# just images
|
||||||
|
# just available
|
||||||
|
# just clean
|
||||||
|
|
||||||
|
base_dir := home_dir() / ".libvirt/base"
|
||||||
|
vm := home_dir() / ".vm"
|
||||||
|
output := base_dir / "packer"
|
||||||
|
disk_size := "15G"
|
||||||
|
prefix := "aa-"
|
||||||
|
c := "--connect=qemu:///system"
|
||||||
|
sshopt := "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||||
|
|
||||||
|
[doc('Show this help message')]
|
||||||
|
default:
|
||||||
|
@echo -e "Integration environment helper for apparmor.d\n"
|
||||||
|
@just --list --unsorted
|
||||||
|
@echo -e "\nSee https://apparmor.pujol.io/development/vm/ for more information."
|
||||||
|
|
||||||
|
[doc('Build the apparmor.d package')]
|
||||||
|
package dist:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eu -o pipefail
|
||||||
|
dist="{{dist}}"
|
||||||
|
[[ $dist =~ ubuntu* ]] && dist=ubuntu
|
||||||
|
[[ $dist =~ debian* ]] && dist=debian
|
||||||
|
make package dist=$dist
|
||||||
|
|
||||||
|
[doc('Build the image')]
|
||||||
|
img dist flavor: (package dist)
|
||||||
|
@mkdir -p {{base_dir}}
|
||||||
|
packer build -force \
|
||||||
|
-var dist={{dist}} \
|
||||||
|
-var flavor={{flavor}} \
|
||||||
|
-var disk_size={{disk_size}} \
|
||||||
|
-var prefix={{prefix}} \
|
||||||
|
-var base_dir={{base_dir}} \
|
||||||
|
-var output={{output}} \
|
||||||
|
tests/packer/
|
||||||
|
|
||||||
|
[doc('Create the machine')]
|
||||||
|
vm dist flavor:
|
||||||
|
@cp -f {{base_dir}}/{{prefix}}{{dist}}-{{flavor}}.qcow2 {{vm}}/{{prefix}}{{dist}}-{{flavor}}.qcow2
|
||||||
|
virt-install {{c}} \
|
||||||
|
--import \
|
||||||
|
--name {{prefix}}{{dist}}-{{flavor}} \
|
||||||
|
--vcpus 6 \
|
||||||
|
--ram 4096 \
|
||||||
|
--machine q35 \
|
||||||
|
--boot uefi \
|
||||||
|
--memorybacking source.type=memfd,access.mode=shared \
|
||||||
|
--disk path={{vm}}/{{prefix}}{{dist}}-{{flavor}}.qcow2,format=qcow2,bus=virtio \
|
||||||
|
--filesystem "`pwd`,0a31bc478ef8e2461a4b1cc10a24cc4",accessmode=passthrough,driver.type=virtiofs \
|
||||||
|
--os-variant "`just get_osinfo {{dist}}`" \
|
||||||
|
--graphics spice \
|
||||||
|
--audio id=1,type=spice \
|
||||||
|
--sound model=ich9 \
|
||||||
|
--noautoconsole
|
||||||
|
|
||||||
|
[doc('Start a machine')]
|
||||||
|
up dist flavor:
|
||||||
|
@virsh {{c}} start {{prefix}}{{dist}}-{{flavor}}
|
||||||
|
|
||||||
|
[doc('Stops the machine')]
|
||||||
|
halt dist flavor:
|
||||||
|
@virsh {{c}} shutdown {{prefix}}{{dist}}-{{flavor}}
|
||||||
|
|
||||||
|
[doc('Destroy the machine')]
|
||||||
|
destroy dist flavor:
|
||||||
|
@virsh {{c}} destroy {{prefix}}{{dist}}-{{flavor}} || true
|
||||||
|
@virsh {{c}} undefine {{prefix}}{{dist}}-{{flavor}} --nvram
|
||||||
|
@rm -fv {{vm}}/{{prefix}}{{dist}}-{{flavor}}.qcow2
|
||||||
|
|
||||||
|
[doc('Connect to the machine')]
|
||||||
|
ssh dist flavor:
|
||||||
|
@ssh {{sshopt}} user@`just get_ip {{dist}} {{flavor}}`
|
||||||
|
|
||||||
|
[doc('List the machines')]
|
||||||
|
list:
|
||||||
|
@echo -e '\033[1m Id Name State\033[0m'
|
||||||
|
@virsh {{c}} list --all | grep {{prefix}}
|
||||||
|
|
||||||
|
[doc('List the machine images')]
|
||||||
|
images:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eu -o pipefail
|
||||||
|
ls -lh {{base_dir}} | awk '
|
||||||
|
BEGIN {
|
||||||
|
printf("\033[1m%-18s %-10s %-5s %s\033[0m\n", "Distribution", "Flavor", "Size", "Date")
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if ($9 ~ /^{{prefix}}.*\.qcow2$/) {
|
||||||
|
split($9, arr, "-|\\.")
|
||||||
|
printf("%-18s %-10s %-5s %s %s %s\n", arr[2], arr[3], $5, $6, $7, $8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
||||||
|
|
||||||
|
[doc('List the machine that can be created')]
|
||||||
|
available:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eu -o pipefail
|
||||||
|
ls -lh tests/cloud-init | awk '
|
||||||
|
BEGIN {
|
||||||
|
printf("\033[1m%-18s %s\033[0m\n", "Distribution", "Flavor")
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if ($9 ~ /^.*\.user-data.yml$/) {
|
||||||
|
split($9, arr, "-|\\.")
|
||||||
|
printf("%-18s %s\n", arr[1], arr[2])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
||||||
|
|
||||||
|
[doc('Run the integration tests on the machine')]
|
||||||
|
integration dist flavor:
|
||||||
|
@ssh {{sshopt}} user@`just get_ip {{dist}} {{flavor}}` \
|
||||||
|
cp -rf /home/user/Projects/apparmor.d/tests/integration/ /home/user/Projects
|
||||||
|
@ssh {{sshopt}} user@`just get_ip {{dist}} {{flavor}}` \
|
||||||
|
sudo umount /home/user/Projects/apparmor.d
|
||||||
|
@ssh {{sshopt}} user@`just get_ip {{dist}} {{flavor}}` \
|
||||||
|
@bats --recursive --timing --print-output-on-failure Projects/integration/
|
||||||
|
|
||||||
|
[doc('Run the linters')]
|
||||||
|
lint:
|
||||||
|
@packer fmt packer/
|
||||||
|
@packer validate --syntax-only packer/
|
||||||
|
|
||||||
|
[doc('Remove the machine images')]
|
||||||
|
clean:
|
||||||
|
@rm -fv {{base_dir}}/{{prefix}}*.qcow2
|
||||||
|
|
||||||
|
get_ip dist flavor:
|
||||||
|
@virsh --quiet --readonly {{c}} domifaddr {{prefix}}{{dist}}-{{flavor}} | \
|
||||||
|
grep -E -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'
|
||||||
|
|
||||||
|
get_osinfo dist:
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
osinfo = {
|
||||||
|
"archlinux": "archlinux",
|
||||||
|
"debian12": "debian12",
|
||||||
|
"debian13": "debian13",
|
||||||
|
"ubuntu22": "ubuntu22.04",
|
||||||
|
"ubuntu24": "ubuntu24.04",
|
||||||
|
"ubuntu25": "ubuntu25.04",
|
||||||
|
"opensuse": "opensusetumbleweed",
|
||||||
|
}
|
||||||
|
print(osinfo.get("{{dist}}", "{{dist}}"))
|
|
@ -1,27 +0,0 @@
|
||||||
#!/usr/bin/make -f
|
|
||||||
# apparmor.d - Full set of apparmor profiles
|
|
||||||
# Copyright (C) 2023-2024 Alexandre Pujol <alexandre@pujol.io>
|
|
||||||
# SPDX-License-Identifier: GPL-2.0-only
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# make archlinux flavor=gnome
|
|
||||||
# vagrant up arch-gnome
|
|
||||||
# vagrant ssh archl-gnome
|
|
||||||
|
|
||||||
# Build variables
|
|
||||||
flavor ?=
|
|
||||||
disk ?= 10G
|
|
||||||
|
|
||||||
BASE = archlinux debian ubuntu22 ubuntu24 opensuse fedora
|
|
||||||
|
|
||||||
.PHONY: ${BASE} lint
|
|
||||||
|
|
||||||
$(BASE):
|
|
||||||
@make --directory=../ package dist=${@}
|
|
||||||
@packer build -force \
|
|
||||||
-var disk_size=${disk} -var flavor="${flavor}" \
|
|
||||||
-only=qemu.${@} packer/
|
|
||||||
|
|
||||||
lint:
|
|
||||||
@packer fmt --check packer/
|
|
||||||
@packer validate --syntax-only packer/
|
|
62
tests/Vagrantfile
vendored
62
tests/Vagrantfile
vendored
|
@ -1,62 +0,0 @@
|
||||||
# -*- mode: ruby -*-
|
|
||||||
# apparmor.d - Full set of apparmor profiles
|
|
||||||
# Copyright (C) 2023-2024 Alexandre Pujol <alexandre@pujol.io>
|
|
||||||
# SPDX-License-Identifier: GPL-2.0-only
|
|
||||||
|
|
||||||
require 'yaml'
|
|
||||||
|
|
||||||
machines = YAML.load_file(File.join(File.dirname(__FILE__), 'boxes.yml'))
|
|
||||||
default = machines['defaults']
|
|
||||||
|
|
||||||
Vagrant.require_version '>= 2.0.0'
|
|
||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
|
||||||
|
|
||||||
config.ssh.keys_only = true
|
|
||||||
config.ssh.insert_key = false
|
|
||||||
config.ssh.private_key_path = [ '~/.ssh/id_ed25519' ]
|
|
||||||
config.ssh.username = 'user'
|
|
||||||
|
|
||||||
machines['boxes'].each do |instance|
|
|
||||||
|
|
||||||
# Configure the VMs per details in boxes.yml
|
|
||||||
config.vm.define instance['name'] do |srv|
|
|
||||||
srv.vm.box = instance['box']
|
|
||||||
srv.vm.box_check_update = false
|
|
||||||
srv.vm.post_up_message = instance.to_yaml
|
|
||||||
srv.vm.synced_folder '.', '/vagrant', disabled: true
|
|
||||||
if !ENV['AA_INTEGRATION']
|
|
||||||
srv.vm.synced_folder '../', '/home/user/Projects/apparmor.d', type: 'virtiofs', mount: false
|
|
||||||
end
|
|
||||||
|
|
||||||
# Configure Libvirt provider
|
|
||||||
srv.vm.provider 'libvirt' do |libvirt|
|
|
||||||
libvirt.driver = 'kvm'
|
|
||||||
libvirt.default_prefix = 'aa-'
|
|
||||||
libvirt.connect_via_ssh = false
|
|
||||||
libvirt.storage_pool_name = 'ssd'
|
|
||||||
libvirt.memory = instance.fetch('ram', default['ram'])
|
|
||||||
libvirt.cpus = instance.fetch('cpu', default['cpu'])
|
|
||||||
libvirt.cpu_mode = 'host-passthrough'
|
|
||||||
libvirt.machine_type = 'q35'
|
|
||||||
libvirt.video_type = 'virtio'
|
|
||||||
libvirt.graphics_type = 'spice'
|
|
||||||
libvirt.sound_type = 'ich9'
|
|
||||||
libvirt.tpm_model = 'tpm-crb'
|
|
||||||
libvirt.tpm_type = 'emulator'
|
|
||||||
libvirt.tpm_version = '2.0'
|
|
||||||
libvirt.random model: 'random'
|
|
||||||
libvirt.memorybacking 'source', type: 'memfd'
|
|
||||||
libvirt.memorybacking 'access', mode: 'shared'
|
|
||||||
libvirt.channel type: 'unix', target_name: 'org.qemu.guest_agent.0', target_type: 'virtio'
|
|
||||||
(1..2).each do
|
|
||||||
libvirt.redirdev :type => "spicevmc"
|
|
||||||
end
|
|
||||||
if instance.fetch('uefi', default['uefi'])
|
|
||||||
libvirt.loader = '/usr/share/edk2/x64/OVMF_CODE.fd'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,51 +0,0 @@
|
||||||
---
|
|
||||||
|
|
||||||
defaults:
|
|
||||||
uefi: true
|
|
||||||
ram: '3072'
|
|
||||||
cpu: '6'
|
|
||||||
|
|
||||||
boxes:
|
|
||||||
- name: arch-gnome
|
|
||||||
box: aa-archlinux-gnome
|
|
||||||
uefi: false
|
|
||||||
|
|
||||||
- name: arch-kde
|
|
||||||
box: aa-archlinux-kde
|
|
||||||
uefi: false
|
|
||||||
|
|
||||||
- name: arch-xfce
|
|
||||||
box: aa-archlinux-xfce
|
|
||||||
uefi: false
|
|
||||||
|
|
||||||
- name: arch-cosmic
|
|
||||||
box: aa-archlinux-cosmic
|
|
||||||
uefi: false
|
|
||||||
|
|
||||||
- name: arch-server
|
|
||||||
box: aa-archlinux-server
|
|
||||||
uefi: false
|
|
||||||
|
|
||||||
- name: ubuntu22-desktop
|
|
||||||
box: aa-ubuntu22-desktop
|
|
||||||
|
|
||||||
- name: ubuntu24-desktop
|
|
||||||
box: aa-ubuntu24-desktop
|
|
||||||
|
|
||||||
- name: ubuntu22-server
|
|
||||||
box: aa-ubuntu22-server
|
|
||||||
|
|
||||||
- name: ubuntu24-server
|
|
||||||
box: aa-ubuntu24-server24
|
|
||||||
|
|
||||||
- name: debian-server
|
|
||||||
box: aa-debian-server
|
|
||||||
|
|
||||||
- name: debian-gnome
|
|
||||||
box: aa-debian-gnome
|
|
||||||
|
|
||||||
- name: debian-kde
|
|
||||||
box: aa-debian-kde
|
|
||||||
|
|
||||||
- name: opensuse-kde
|
|
||||||
box: aa-opensuse-kde
|
|
Loading…
Add table
Reference in a new issue