-
Notifications
You must be signed in to change notification settings - Fork 506
188 lines (180 loc) · 6.39 KB
/
test.yml
File metadata and controls
188 lines (180 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Build and Test
on:
pull_request:
paths-ignore:
- '*.md'
- 'docs/*'
push:
branches:
- main
paths-ignore:
- '*.md'
- 'docs/*'
permissions:
contents: read
pull-requests: read
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.26.x"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Generate code
run: make generate
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.10.1
only-new-issues: true
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- {os: ubuntu-latest, go: 1.26}
- {os: windows-latest, go: 1.26}
- {os: macos-latest, go: 1.26}
timeout-minutes: 10
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
id: go
- name: Build
run: |
make build
- name: Test
run: |
make test
- uses: actions/upload-artifact@v7
with:
name: terraform-provider-libvirt-${{ matrix.os }}
path: ${{ github.workspace }}/terraform-provider-libvirt*
acceptance:
name: Acceptance Tests (${{ matrix.tf-binary }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tf-binary: [terraform, opentofu]
go-version: ["1.26.x"]
timeout-minutes: 30
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Install libvirt and QEMU
run: |
sudo apt-get update
sudo apt-get install -y \
qemu-system-x86 \
qemu-utils \
libvirt-daemon-system \
libvirt-clients \
libvirt-dev
- name: Start libvirtd and configure permissions
run: |
sudo systemctl start libvirtd
sudo systemctl status libvirtd
# Normalize qemu runtime user on ephemeral runners to avoid storage DAC
# mismatches (qemu uid cannot read newly created volume files).
sudo sed -i 's/^#\?user = .*/user = "root"/' /etc/libvirt/qemu.conf
sudo sed -i 's/^#\?group = .*/group = "root"/' /etc/libvirt/qemu.conf
sudo sed -i 's/^#\?dynamic_ownership = .*/dynamic_ownership = 0/' /etc/libvirt/qemu.conf
# Disable AppArmor confinement for QEMU so that VMs can access
# volumes in non-default pool paths during acceptance tests.
echo 'security_driver = "none"' | sudo tee -a /etc/libvirt/qemu.conf
sudo systemctl restart libvirtd
# Add runner to libvirt group
sudo usermod -a -G libvirt runner
# Change socket permissions to allow group access
sudo chmod 666 /var/run/libvirt/libvirt-sock
# Ensure default storage path is traversable by dynamically labeled qemu UIDs.
sudo mkdir -p /var/lib/libvirt/images
sudo chmod 1777 /var/lib/libvirt/images
# Ensure default pool exists and is active in this ephemeral runner.
if ! virsh -c qemu:///system pool-info default >/dev/null 2>&1; then
virsh -c qemu:///system pool-define-as --name default --type dir --target /var/lib/libvirt/images
fi
virsh -c qemu:///system pool-start default || true
virsh -c qemu:///system pool-autostart default || true
- name: Install Terraform
if: matrix.tf-binary == 'terraform'
uses: hashicorp/setup-terraform@v4
with:
terraform_version: latest
- name: Install OpenTofu
if: matrix.tf-binary == 'opentofu'
uses: opentofu/setup-opentofu@v2
with:
tofu_version: latest
- name: Cache acceptance test images
uses: actions/cache@v4
with:
path: .cache/test-images
key: ${{ runner.os }}-acc-images-alpine-3.23.3-r0
- name: Prepare Tiny Linux test image
run: |
make testdeps-acc-tinylinux
- name: Run Acceptance Tests
env:
TF_ACC: "1"
TF_PROVIDER_LIBVIRT_DOMAIN_TYPE: "qemu"
TF_ACC_PROVIDER_NAMESPACE: "dmacvicar"
TF_ACC_PROVIDER_HOST: "registry.terraform.io"
run: |
# Get absolute path to terraform/tofu binary
if [ "${{ matrix.tf-binary }}" = "opentofu" ]; then
export TF_ACC_TERRAFORM_PATH=$(which tofu)
else
export TF_ACC_TERRAFORM_PATH=$(which terraform)
fi
ACPI_IMAGE="$PWD/.cache/test-images/alpine-3.23.3-x86_64-bios-tiny-r0.qcow2"
if [ -f "$ACPI_IMAGE" ]; then
export LIBVIRT_TEST_ACPI_IMAGE="$ACPI_IMAGE"
fi
echo "Using Terraform CLI at: $TF_ACC_TERRAFORM_PATH"
if [ -n "${LIBVIRT_TEST_ACPI_IMAGE:-}" ]; then
echo "Using ACPI test image: $LIBVIRT_TEST_ACPI_IMAGE"
else
echo "LIBVIRT_TEST_ACPI_IMAGE not set; image-gated ACPI shutdown test will be skipped."
fi
make testacc
- name: Debug Libvirt/QEMU Storage Access
if: always()
run: |
echo "=== qemu.conf ==="
sudo grep -E '^(user|group|dynamic_ownership)[[:space:]]*=' /etc/libvirt/qemu.conf || true
echo
echo "=== libvirt daemon status ==="
sudo systemctl status libvirtd --no-pager || true
echo
echo "=== qemu processes ==="
ps -ef | grep -E '[q]emu-system|[l]ibvirtd|[v]irtqemud' || true
echo
echo "=== default pool info ==="
virsh -c qemu:///system pool-info default || true
virsh -c qemu:///system pool-dumpxml default || true
echo
echo "=== images dir permissions ==="
ls -ld /var/lib/libvirt/images || true
stat -c '%a %U:%G %n' /var/lib/libvirt/images || true
echo
echo "=== test volume file permissions ==="
ls -l /var/lib/libvirt/images/test-volume-shutdown-image.qcow2 || true
stat -c '%a %U:%G %n' /var/lib/libvirt/images/test-volume-shutdown-image.qcow2 || true