forked from canonical/lxd
-
Notifications
You must be signed in to change notification settings - Fork 0
1384 lines (1205 loc) · 48.2 KB
/
tests.yml
File metadata and controls
1384 lines (1205 loc) · 48.2 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Tests
on:
push:
branches:
- main
- stable-*
pull_request:
workflow_dispatch:
inputs:
static-analysis:
description: Whether to run `make static-analysis`
required: true
type: boolean
default: true
unit-tests:
description: Whether to run `make check-unit`
required: true
type: boolean
default: true
coverage:
description: Whether to enable Go coverage collection
required: true
type: boolean
default: false
ubuntu-releases:
description: Ubuntu releases to run the tests against. In JSON format, i.e. '["22.04", "24.04"]'.
type: choice
default: '["24.04"]'
options:
- '["22.04", "24.04"]'
- '["22.04"]'
- '["24.04"]'
snap-risk:
description: Snap risk level, `edge`, `candidate` or `stable`
type: choice
default: 'edge'
options:
- 'edge'
- 'candidate'
- 'stable'
tmate-debug:
description: Use tmate debugging session on integration test failure.
type: boolean
default: false
schedule:
- cron: '0 0 * * *' # Test TICS daily
env:
LXD_SKIP_TESTS: "concurrent" # concurrent is too unreliable/racy
LXD_REQUIRED_TESTS: "storage_buckets network_ovn"
GOCOVERAGE: ${{ (( github.event_name == 'workflow_dispatch' && github.event.inputs.coverage == 'true' ) || ( github.event_name == 'schedule' && github.repository == 'canonical/lxd' )) && 'true' || 'false' }}
GOCOVERDIR: '' # Later set to the fully qualified path if needed
IMAGE_CACHE_DIR: "/home/runner/image-cache"
SNAP_CACHE_DIR: "/home/runner/snap-cache"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
defaults:
run:
# Make sure bash is always invoked with `-eo pipefail`
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
shell: bash
jobs:
code-tests:
outputs:
fast-backend: ${{ steps.pick-fast-backend.outputs.fast-backend }}
env:
CGO_CFLAGS: "-I/home/runner/go/bin/dqlite/include/ -I/home/runner/go/bin/liblxc/include/"
CGO_LDFLAGS: "-L/home/runner/go/bin/dqlite/libs/"
LD_LIBRARY_PATH: "/home/runner/go/bin/dqlite/libs/"
LD_RUN_PATH: "/home/runner/go/bin/dqlite/libs/"
CGO_LDFLAGS_ALLOW: "(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"
SUDO_PRESERVE_ENV: "CGO_CFLAGS,CGO_LDFLAGS,CGO_LDFLAGS_ALLOW,GOCOVERDIR,PKG_CONFIG_PATH,LD_LIBRARY_PATH,PATH"
if: ${{ github.event_name != 'schedule' || github.repository == 'canonical/lxd' }}
name: Code
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# A non-shallow clone is needed for the Differential ShellCheck
fetch-depth: 0
persist-credentials: false
- name: Require GHA pinning
uses: ./.github/actions/require-gha-pinning
- name: Tune disk performance
uses: ./.github/actions/tune-disk-performance
- name: Dependency Review
uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # v4.8.2
if: github.event_name == 'pull_request'
# XXX: `make static-analysis` also run shellcheck but this one provides
# useful feedback in the PR through github-code-scanning bot
- id: ShellCheck
name: Differential ShellCheck
uses: redhat-plumbers-in-action/differential-shellcheck@d965e66ec0b3b2f821f75c8eff9b12442d9a7d1e # v5.5.6
with:
token: ${{ secrets.GITHUB_TOKEN }}
strict-check-on-push: true
if: github.event_name == 'pull_request'
- name: Upload artifact with ShellCheck defects in SARIF format
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: Differential ShellCheck SARIF
path: ${{ steps.ShellCheck.outputs.sarif }}
retention-days: 1
if: ${{ github.event_name == 'pull_request' && runner.debug == '1' && !cancelled() }}
- name: Install Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version-file: 'go.mod'
- name: Install Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
if: github.event_name != 'pull_request'
with:
cache: 'pip' # caching pip dependencies
cache-dependency-path: |
doc/requirements.txt
doc/conf.py
python-version: '3.x' # satisfied by any 3.x version already installed
- name: Install build dependencies
uses: ./.github/actions/install-lxd-builddeps
- name: Download go dependencies
run: |
set -eux
# Resolve dependencies and download modules
go mod download
# Check compatibility with min Go version
make check-gomin
# Ensure go.mod and go.sum were not modified by the above
# commands which would indicate an issue (hint: run `make update-gomod`)
git diff --exit-code
- name: Make GOCOVERDIR
run: |
set -eux
mkdir -p coverage
chmod 0777 coverage
cd coverage
echo "GOCOVERDIR=$(pwd)" >> "${GITHUB_ENV}"
if: env.GOCOVERAGE == 'true'
- name: Make LXD tarball and unpack it
env:
CUSTOM_VERSION: "test"
run: |
set -eux
make dist
tar -xzf lxd-test.tar.gz -C /home/runner/work/lxd/
rm lxd-test.tar.gz
# In code-tests, this action warms the cache for the system-tests job
- name: Build or restore dqlite/liblxc dependencies
uses: ./.github/actions/cache-dqlite-liblxc
- name: Update env variables for deps
run: |
set -eux
LIBLXC_ARCH_LIBS="$(readlink -e /home/runner/go/bin/liblxc/libs/*-linux-gnu)"
echo "CGO_LDFLAGS=${CGO_LDFLAGS} -L${LIBLXC_ARCH_LIBS}" >> "${GITHUB_ENV}"
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIBLXC_ARCH_LIBS}" >> "${GITHUB_ENV}"
echo "LD_RUN_PATH=${LD_RUN_PATH}:${LIBLXC_ARCH_LIBS}" >> "${GITHUB_ENV}"
echo "PKG_CONFIG_PATH=${LIBLXC_ARCH_LIBS}/pkgconfig" >> "${GITHUB_ENV}"
- name: Build binaries
run: |
set -eux
# Build from unpacked dist tarball.
cd /home/runner/work/lxd/lxd-test
make
# XXX: `make static-analysis` also run golangci-lint but this one provides
# useful feedback in the PR through github-code-scanning bot
- name: Run golangci-lint
if: github.event_name == 'pull_request' || github.event_name == 'schedule'
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v8
- name: Run static analysis
if: ${{ github.event_name != 'workflow_dispatch' || inputs.static-analysis == 'true' }}
run: |
set -eux
# For `make update-api`
sudo chmod o+w ./doc/rest-api.yaml
# For `make update-auth`
sudo chmod o+w ./lxd/auth/entitlements_generated.go ./lxd/auth/drivers/openfga_model.openfga
# For `make update-metadata`
sudo chmod o+w ./lxd/metadata/configuration.json ./doc/metadata.txt
make static-analysis
# If `git diff` does not come out clean, you likely forgot a `make update-*`
git diff --exit-code
# If coverage data collection is enabled, run schema checks to
# exercise `lxd-generate` code paths.
if [ "${GOCOVERDIR}" != "" ]; then
make check-schema
git diff --exit-code
fi
- name: Unit tests
if: ${{ github.event_name != 'workflow_dispatch' || inputs.unit-tests == 'true' }}
run: |
set -eux
chmod +x ~
echo "root:1000000:1000000000" | sudo tee /etc/subuid /etc/subgid
sudo --preserve-env="${SUDO_PRESERVE_ENV}" LD_LIBRARY_PATH=${LD_LIBRARY_PATH} env "PATH=${PATH}" make check-unit
git diff --exit-code
- name: Upload coverage data
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: coverage-unit
path: ${{env.GOCOVERDIR}}
retention-days: 1
if: env.GOCOVERDIR != ''
- name: Prime cache with external test images
uses: ./.github/actions/download-images
with:
prime-cache-only: true
image-cache-dir: ${{ env.IMAGE_CACHE_DIR }}
- name: Prime cache with snap dependencies
uses: ./.github/actions/download-snaps
with:
prime-cache-only: true
snap-cache-dir: ${{ env.SNAP_CACHE_DIR }}
- name: Prime cache with minio/mc
uses: ./.github/actions/download-minio
with:
prime-cache-only: true
- name: Upload system test dependencies
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: system-test-deps
path: |
/home/runner/go/bin/devlxd-client
/home/runner/go/bin/fuidshift
/home/runner/go/bin/lxc
/home/runner/go/bin/lxd
/home/runner/go/bin/lxd-agent
/home/runner/go/bin/lxd-benchmark
/home/runner/go/bin/lxd-client
/home/runner/go/bin/lxd-convert
/home/runner/go/bin/lxd-user
/home/runner/go/bin/mini-oidc
/home/runner/go/bin/sysinfo
retention-days: 1
- name: Pick fast backend for system tests
id: pick-fast-backend
run: |
set -eux
fast_backend="btrfs"
if [ $(( "${GITHUB_RUN_ID:-"${RANDOM}"}" % 2 )) -eq 0 ]; then
fast_backend="dir"
fi
echo "fast-backend=${fast_backend}" >> "$GITHUB_OUTPUT"
system-tests:
env:
LXD_CEPH_CLUSTER: "ceph"
LXD_CEPH_CEPHFS: "cephfs"
LXD_CEPH_CEPHOBJECT_RADOSGW: "http://127.0.0.1"
LXD_OVN_NB_CONNECTION: "ssl:127.0.0.1:6641"
LXD_VERBOSE: "1"
LXD_OFFLINE: "1"
LXD_TMPFS: "1"
GOTRACEBACK: "crash"
SUDO_PRESERVE_ENV: "PATH,GOPATH,GOCOVERDIR,GOTRACEBACK,GITHUB_ACTIONS,GITHUB_STEP_SUMMARY,SNAP_CACHE_DIR,IMAGE_CACHE_DIR,LXD_VERBOSE,LXD_REPEAT_TESTS,LXD_BACKENDS,LXD_BACKEND,LXD_CEPH_CLUSTER,LXD_CEPH_CEPHFS,LXD_CEPH_CEPHOBJECT_RADOSGW,LXD_OVN_NB_CONNECTION,LXD_OVN_NB_CLIENT_CRT_FILE,LXD_OVN_NB_CLIENT_KEY_FILE,LXD_OVN_NB_CA_CRT_FILE,LXD_OFFLINE,LXD_SKIP_TESTS,LXD_REQUIRED_TESTS,LXD_TMPFS"
if: ${{ github.event_name != 'schedule' || github.repository == 'canonical/lxd' }}
name: System
runs-on: ubuntu-24.04
needs: code-tests
strategy:
fail-fast: false
matrix:
include:
- group: cluster
backends: ${{ needs.code-tests.outputs.fast-backend }}
- group: cluster_storage
backends: all
- group: image
backends: fasts
- group: instance
backends: fasts
- group: network
backends: ${{ needs.code-tests.outputs.fast-backend }}
- group: standalone
backends: ${{ needs.code-tests.outputs.fast-backend }}
- group: snap
backends: all
- group: standalone_storage
backends: ceph
- group: standalone_storage
backends: fasts
- group: standalone_storage
backends: lvm
- group: standalone_storage
backends: zfs
- group: standalone_storage
backends: random
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Tune disk performance
uses: ./.github/actions/tune-disk-performance
- name: Reclaim some memory
uses: ./.github/actions/reclaim-memory
- name: Remove docker
uses: ./.github/actions/disable-docker
- name: Install runtime dependencies
uses: ./.github/actions/install-lxd-runtimedeps
# Restore the cache warmed in code-tests job
- name: Build or restore dqlite/liblxc dependencies
uses: ./.github/actions/cache-dqlite-liblxc
# Restore the cache warmed in code-tests job
- name: Download external test images
uses: ./.github/actions/download-images
with:
image-cache-dir: ${{ env.IMAGE_CACHE_DIR }}
# Restore the cache warmed in code-tests job
- name: Download snap dependencies
uses: ./.github/actions/download-snaps
with:
snap-cache-dir: ${{ env.SNAP_CACHE_DIR }}
# Restore the cache warmed in code-tests job
- name: Download minio/mc
uses: ./.github/actions/download-minio
- name: Download system test dependencies
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: system-test-deps
merge-multiple: true
path: /home/runner/go/bin
- name: Set exec perms on LXD binaries
run: |
set -eux
ls -lR /home/runner/go/bin/
chmod uog+x /home/runner/go/bin/*
- name: Setup MicroCeph
if: ${{ contains(matrix.backends, 'ceph') || matrix.backends == 'all' }}
uses: ./.github/actions/setup-microceph
with:
osd-count: 3
snap-cache-dir: ${{ env.SNAP_CACHE_DIR }}
- name: Setup MicroOVN
uses: ./.github/actions/setup-microovn
with:
snap-cache-dir: ${{ env.SNAP_CACHE_DIR }}
- name: Make GOCOVERDIR
run: |
set -eux
mkdir -p coverage
chmod 0777 coverage
cd coverage
echo "GOCOVERDIR=$(pwd)" >> "${GITHUB_ENV}"
if: env.GOCOVERAGE == 'true'
- name: Sanitize Artifact Name
id: sanitize
env:
ID: ${{ matrix.group }}-${{ matrix.backends }}
run: |
set -eux
echo "artifact_name=$(echo "${ID}" | tr ': /' '-_-')" >> "${GITHUB_OUTPUT}"
- name: System Environment Setup
run: |
set -eux
chmod +x ~
echo "root:1000000:1000000000" | sudo tee /etc/subuid /etc/subgid
# Check if there are existing coredumps
if [ -n "$(ls -A /var/crash/)" ]; then
echo "WARNING: coredumps found before running the system tests, removing them"
sudo rm /var/crash/*
fi
- name: "Run system tests (${{ matrix.group }}, btrfs)"
if: matrix.backends == 'all' || matrix.backends == 'fasts' || matrix.backends == 'btrfs'
env:
LXD_BACKEND: btrfs
LXD_BACKENDS: ${{ matrix.backends }}
GROUP: ${{ matrix.group }}
working-directory: test
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH:/snap/microovn/current/commands"
# Run the tests for the selected backend
sudo --preserve-env="${SUDO_PRESERVE_ENV}" ./main.sh "group:${GROUP}"
- name: "Run system tests (${{ matrix.group }}, ceph)"
if: matrix.backends == 'all' || matrix.backends == 'ceph'
env:
LXD_BACKEND: ceph
LXD_BACKENDS: ${{ matrix.backends }}
GROUP: ${{ matrix.group }}
working-directory: test
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH:/snap/microovn/current/commands"
# Run the tests for the selected backend
sudo --preserve-env="${SUDO_PRESERVE_ENV}" ./main.sh "group:${GROUP}"
- name: "Run system tests (${{ matrix.group }}, dir)"
if: matrix.backends == 'all' || matrix.backends == 'fasts' || matrix.backends == 'dir'
env:
LXD_BACKEND: dir
LXD_BACKENDS: ${{ matrix.backends }}
GROUP: ${{ matrix.group }}
working-directory: test
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH:/snap/microovn/current/commands"
# Run the tests for the selected backend
sudo --preserve-env="${SUDO_PRESERVE_ENV}" ./main.sh "group:${GROUP}"
- name: "Run system tests (${{ matrix.group }}, lvm)"
if: matrix.backends == 'all' || matrix.backends == 'lvm'
env:
LXD_BACKEND: lvm
LXD_BACKENDS: ${{ matrix.backends }}
GROUP: ${{ matrix.group }}
working-directory: test
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH:/snap/microovn/current/commands"
# Run the tests for the selected backend
sudo --preserve-env="${SUDO_PRESERVE_ENV}" ./main.sh "group:${GROUP}"
- name: "Run system tests (${{ matrix.group }}, zfs)"
if: matrix.backends == 'all' || matrix.backends == 'zfs'
env:
LXD_BACKEND: zfs
LXD_BACKENDS: ${{ matrix.backends }}
GROUP: ${{ matrix.group }}
working-directory: test
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH:/snap/microovn/current/commands"
# Run the tests for the selected backend
sudo --preserve-env="${SUDO_PRESERVE_ENV}" ./main.sh "group:${GROUP}"
- name: "Run system tests (${{ matrix.group }}, random)"
if: matrix.backends == 'all' || matrix.backends == 'random'
env:
LXD_BACKEND: random
LXD_BACKENDS: ${{ matrix.backends }}
GROUP: ${{ matrix.group }}
working-directory: test
run: |
set -eux
export PATH="/home/runner/go/bin:$PATH:/snap/microovn/current/commands"
# Run the tests for the selected backend
sudo --preserve-env="${SUDO_PRESERVE_ENV}" ./main.sh "group:${GROUP}"
- name: Upload crash dumps
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: crash-dumps-${{ steps.sanitize.outputs.artifact_name }}
path: |
/var/crash/core-*
retention-days: 5
if-no-files-found: ignore
- name: Upload coverage data
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: coverage-${{ steps.sanitize.outputs.artifact_name }}
path: ${{ env.GOCOVERDIR }}
retention-days: 1
if: env.GOCOVERDIR != ''
- name: Tmate debugging session
if: ${{ failure() && inputs.tmate-debug }}
timeout-minutes: 30
uses: mxschmitt/action-tmate@c0afd6f790e3a5564914980036ebf83216678101 # v3.23
with:
# Never allow public SSH access
limit-access-to-actor: true
snap-tests:
if: github.event_name != 'schedule' || github.repository == 'canonical/lxd'
needs: code-tests
env:
BRANCH_NAME: ${{ github.ref_name }}
SNAP_RISK: ${{ inputs.snap-risk || 'edge' }}
SNAP_TRACK: "latest"
SUDO_PRESERVE_ENV: "GOCOVERDIR,GITHUB_ACTIONS,GITHUB_STEP_SUMMARY,SNAP_CACHE_DIR,OVN_SOURCE"
name: Snap
runs-on: ubuntu-${{ matrix.os }}
# avoid runaway test burning 6 hours of CI
timeout-minutes: 60
permissions:
# need that to manipulate caches
actions: write
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(inputs.ubuntu-releases || '["24.04"]') }}
test:
- cgroup
- cloud-init
- cluster
- container
- container-copy
- container-nesting
- conversion
- cpu-vm
- devlxd-container
- devlxd-vm
- docker
- efi-vars-editor-vm
- lxd-installer
- lxd-user
- interception
- network-bridge-firewall
- network-ovn ovn:deb
- network-ovn ovn:latest/edge
- network-routed
# XXX: Skip pylxd tests until https://github.com/canonical/pylxd/pull/677 is merged.
#- pylxd
- qemu-external-vm
- snapd
- storage-buckets
- storage-disks-vm
- storage-metadata
- storage-vm btrfs
- storage-vm ceph
- storage-vm dir
- storage-vm lvm
- storage-vm lvm-thin
- storage-vm zfs
- storage-volumes-vm
- tpm-vm
# Skip UI tests as they are unreliable and similar ones are done
# against the non-snap daemon
#- ui chromium
#- ui firefox
- vm
- vm-migration
- vm-nesting
exclude:
# some tests are not worth testing on specific OSes
- os: 22.04
test: lxd-installer
- os: 22.04
test: qemu-external-vm
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Tune disk performance
uses: ./.github/actions/tune-disk-performance
- name: Checkout lxd-ci
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: 'canonical/lxd-ci'
ref: main
path: lxd-ci
persist-credentials: false
- name: Reclaim some memory
uses: ./.github/actions/reclaim-memory
- name: Reclaim disk space
# This can take multiple minutes if the runner is busy/slow so only run it when/where absolutely needed.
# Storage tests need it except when using ceph as it uses the ephemeral disk.
if: ${{ matrix.test == 'conversion' || matrix.test == 'vm-nesting' || (startsWith(matrix.test, 'storage-') && !contains(matrix.test, ' ceph')) }}
uses: ./.github/actions/reclaim-disk-space
- name: Remove docker
uses: ./.github/actions/disable-docker
- name: "Disable br_netfilter"
run: |
set -eux
# XXX: br_netfilter causes subtle issues by subjecting internal
# bridge traffic to NAT/MASQUERADING and IP filtering. This
# modules is not normally loaded on stock Ubuntu installs but it
# is on GHA runners.
if lsmod | grep -qw ^br_netfilter; then
sudo modprobe -r br_netfilter
fi
# Restore the cache warmed in code-tests job
- name: Build or restore dqlite/liblxc dependencies
uses: ./.github/actions/cache-dqlite-liblxc
# Restore the cache warmed in code-tests job
- name: Download external test images
uses: ./.github/actions/download-images
with:
image-cache-dir: ${{ env.IMAGE_CACHE_DIR }}
# Restore the cache warmed in code-tests job
- name: Download snap dependencies
uses: ./.github/actions/download-snaps
with:
snap-cache-dir: ${{ env.SNAP_CACHE_DIR }}
# Restore the cache warmed in code-tests job
- name: Download minio/mc
uses: ./.github/actions/download-minio
- name: Download system test dependencies
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: system-test-deps
merge-multiple: true
path: /home/runner/go/bin
- name: Set exec perms on LXD binaries
run: |
set -eux
ls -lR /home/runner/go/bin/
chmod uog+x /home/runner/go/bin/*
- name: Get Date
id: get-date
if: ${{ matrix.test == 'qemu-external-vm' }}
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
# for simplicity, just use one cache directory
# and make it valid for one day
- uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
id: cache-restore
if: ${{ matrix.test == 'qemu-external-vm' }}
with:
path: /home/runner/work/cache
key: cache-${{ steps.get-date.outputs.date }}
- name: Setup MicroCeph
if: ${{ matrix.test == 'conversion' || matrix.test == 'storage-buckets' || matrix.test == 'storage-vm ceph' || matrix.test == 'storage-volumes-vm' }}
uses: ./.github/actions/setup-microceph
with:
osd-count: 3
snap-cache-dir: ${{ env.SNAP_CACHE_DIR }}
- name: Setup MicroOVN
uses: ./.github/actions/setup-microovn
with:
snap-cache-dir: ${{ env.SNAP_CACHE_DIR }}
- name: Make GOCOVERDIR
run: |
set -eux
mkdir -p coverage
chmod 0777 coverage
cd coverage
echo "GOCOVERDIR=$(pwd)" >> "${GITHUB_ENV}"
if: env.GOCOVERAGE == 'true'
- name: Sanitize Artifact Name
id: sanitize
env:
ID: ${{ matrix.test }}-${{ matrix.os }}
run: |
set -eux
echo "artifact_name=$(echo "${ID}" | tr ': /' '-_-')" >> "${GITHUB_OUTPUT}"
- name: Snap track selection
run: |
set -eux
if [[ "${BRANCH_NAME}" =~ ^stable- ]]; then
SNAP_TRACK="${BRANCH_NAME#stable-}"
echo "SNAP_TRACK=${SNAP_TRACK}" >> "${GITHUB_ENV}"
fi
- name: Adapt lxd-ci test for sideloading and coverage collection
working-directory: './lxd-ci'
run: |
set -eux
# Avoid lxd-installer getting in the way
sudo rm -f /usr/sbin/lxd /usr/sbin/lxc
cat << EOF > /tmp/install_lxd.sh
# install_lxd replacement that sideloads the built snap and enables coverage collection
install_lxd() (
# Ensure our custom binaries are found first
export PATH="/home/runner/go/bin:${PATH}"
sideload_lxd_snap "${SNAP_TRACK}/${SNAP_RISK}"
gocoverage_lxd_snap
)
EOF
# Add snap helpers from the main repo
sed -i '1 r ../test/includes/snap.sh' bin/helpers
# Replace the install_lxd helper
sed -i '/^# install_lxd:/,/^)$/d' bin/helpers
cat /tmp/install_lxd.sh >> bin/helpers
rm -f /tmp/install_lxd.sh
cat bin/helpers
- name: ${{ matrix.test }}
working-directory: './lxd-ci'
run: |
set -eux
# XXX: prevent accidental usage of `images:` in CI test jobs.
# All tests should be done using officially supported images.
echo '127.0.0.1 images.lxd.canonical.com' | sudo tee /etc/hosts
TEST_SCRIPT="$(echo ${{ matrix.test }} | cut -d " " -f 1)"
EXTRA_ARGS="$(echo ${{ matrix.test }} | cut -d " " -f 2- --only-delimited)"
if [ "${TEST_SCRIPT}" = "cluster" ]; then
dst_track="${SNAP_TRACK}/${SNAP_RISK}"
src_track="${SNAP_TRACK}/stable"
EXTRA_ARGS="${EXTRA_ARGS:-3} ${src_track} ${dst_track}"
elif [ "${TEST_SCRIPT}" = "network-ovn" ]; then
if [ -n "${EXTRA_ARGS}" ]; then
# Strip the `ovn:` prefix
export OVN_SOURCE="${EXTRA_ARGS##ovn:}"
EXTRA_ARGS=""
fi
fi
sudo --preserve-env="${SUDO_PRESERVE_ENV}" ./bin/local-run "tests/${TEST_SCRIPT}" "${SNAP_TRACK}/${SNAP_RISK}" ${EXTRA_ARGS:-}
# Cleanly stopping `snap.lxd.daemon.service` will ensure that any Go
# coverage data is flushed to disk and can be collected by the upload
# step below. If the service is not stopped, we might end up with
# partial or no coverage data at all.
if [ -n "${GOCOVERDIR:-}" ] && systemctl is-active --quiet snap.lxd.daemon.service; then
sudo systemctl stop snap.lxd.daemon.service
fi
# always update cache as we have our own logic of
# cache invalidation and updates in addition to a date check
- name: Delete previous cache
if: ${{ steps.cache-restore.outputs.cache-hit }}
continue-on-error: true
run: |
gh cache delete "cache-${{ steps.get-date.outputs.date }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
if: ${{ matrix.test == 'qemu-external-vm' }}
with:
path: /home/runner/work/cache
key: cache-${{ steps.get-date.outputs.date }}
- name: Upload ${{ matrix.test }} test reports
if: ${{ always() && startsWith(matrix.test, 'ui ') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: test-report-${{ matrix.test }}-lxd-${{ env.SNAP_TRACK }}-${{ env.SNAP_RISK }}-os-${{ matrix.os }}
path: lxd-ui/test-results
retention-days: 1
- name: Upload crash dumps
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: crash-dumps-${{ steps.sanitize.outputs.artifact_name }}
path: |
/var/crash/core-*
retention-days: 5
if-no-files-found: ignore
- name: Upload coverage data
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: coverage-${{ steps.sanitize.outputs.artifact_name }}
path: ${{ env.GOCOVERDIR }}
retention-days: 1
if: env.GOCOVERDIR != ''
- name: Tmate debugging session
if: ${{ failure() && inputs.tmate-debug }}
timeout-minutes: 30
uses: mxschmitt/action-tmate@c0afd6f790e3a5564914980036ebf83216678101 # v3.23
with:
# Never allow public SSH access
limit-access-to-actor: true
tics:
name: Tiobe TICS
runs-on: ubuntu-24.04
needs: [client, system-tests, snap-tests, ui-e2e-tests]
env:
CGO_CFLAGS: "-I/home/runner/go/bin/dqlite/include/ -I/home/runner/go/bin/liblxc/include/"
CGO_LDFLAGS: "-L/home/runner/go/bin/dqlite/libs/"
LD_LIBRARY_PATH: "/home/runner/go/bin/dqlite/libs/"
LD_RUN_PATH: "/home/runner/go/bin/dqlite/libs/"
CGO_LDFLAGS_ALLOW: "(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"
GOTOOLCHAIN: "local"
if: ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && github.ref_name == 'main' && github.repository == 'canonical/lxd' }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Tune disk performance
uses: ./.github/actions/tune-disk-performance
- name: Reclaim some memory
uses: ./.github/actions/reclaim-memory
- name: Remove docker
uses: ./.github/actions/disable-docker
- name: Install Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version-file: 'go.mod'
- name: Make GOCOVERDIR
run: |
set -eux
mkdir -p coverage
cd coverage
echo "GOCOVERDIR=$(pwd)" >> "${GITHUB_ENV}"
if: env.GOCOVERAGE == 'true'
- name: Download coverage data
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
pattern: coverage-*
path: ${{env.GOCOVERDIR}}
merge-multiple: true
# Restore the cache warmed in code-tests job
- name: Build or restore dqlite/liblxc dependencies
uses: ./.github/actions/cache-dqlite-liblxc
- name: Download system test dependencies
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: system-test-deps
merge-multiple: true
path: /home/runner/go/bin
- name: Prepare for running LXD daemon
run: |
set -eux
# Update env variables for liblxc
LIBLXC_ARCH_LIBS="$(readlink -e /home/runner/go/bin/liblxc/libs/*-linux-gnu)"
echo "CGO_LDFLAGS=${CGO_LDFLAGS} -L${LIBLXC_ARCH_LIBS}" >> "${GITHUB_ENV}"
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIBLXC_ARCH_LIBS}" >> "${GITHUB_ENV}"
echo "LD_RUN_PATH=${LD_RUN_PATH}:${LIBLXC_ARCH_LIBS}" >> "${GITHUB_ENV}"
echo "PKG_CONFIG_PATH=${LIBLXC_ARCH_LIBS}/pkgconfig" >> "${GITHUB_ENV}"
- name: Install build dependencies
uses: ./.github/actions/install-lxd-builddeps
- name: Install dependencies
run: |
set -eux
go install github.com/afunix/gocov/gocov@latest
go install github.com/b-dean/gocov-xml@v1.2.1-bdd.0 # XXX: Using this repo is a temporary workaround until https://github.com/AlekSi/gocov-xml/pull/20 is merged. See https://github.com/AlekSi/gocov-xml/pull/20#issuecomment-3275134132 for more details.
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Convert coverage files
run: |
set -eux
go tool covdata percent -i="${GOCOVERDIR}"
go tool covdata textfmt -i="${GOCOVERDIR}" -o "${GOCOVERDIR}"/coverage.out
head "${GOCOVERDIR}"/coverage.out
# Convert to Cobertura XML format.
gocov convert "${GOCOVERDIR}"/coverage.out > "${GOCOVERDIR}"/coverage.json
gocov-xml < "${GOCOVERDIR}"/coverage.json > "${GOCOVERDIR}"/coverage-go.xml
- name: Run TICS
uses: tiobe/tics-github-action@faf5066082a31b2517574270b45e3df92aa39a35 # v3.7.1
with:
mode: qserver
project: LXD
viewerUrl: https://canonical.tiobe.com/tiobeweb/TICS/api/cfg?name=GoProjects
branchdir: ${{ github.workspace }}
ticsAuthToken: ${{ secrets.TICSAUTHTOKEN }}
installTics: true
calc: ALL
tmpdir: /tmp/tics
client:
name: Client
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
needs: code-tests
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version-file: 'go.mod'
- name: Create build directory
run: |
set -eux
mkdir bin
- name: Make GOCOVERDIR
run: |
set -eux
mkdir -p coverage
cd coverage
DIR="$(pwd)"
if [ "${{ runner.os }}" = "Windows" ]; then
DIR="$(cygpath -m "$DIR")"
fi
echo "GOCOVERDIR=$DIR" >> "${GITHUB_ENV}"
if: env.GOCOVERAGE == 'true'
- name: Build static lxc
env:
CGO_ENABLED: 0
COVER: ${{ ( env.GOCOVERDIR != '' ) && '-cover' || '' }}
run: |
set -eux
# Using `go env -w` to avoid dealing with setting variables on Windows
go env -w GOARCH=arm64
go build -ldflags "-s -w" -trimpath -o bin/lxc.aarch64 ${COVER} ./lxc
go env -w GOARCH=amd64
go build -ldflags "-s -w" -trimpath -o bin/lxc.x86_64 ${COVER} ./lxc
- name: Build static lxd-benchmark
if: runner.os == 'Linux'
env:
CGO_ENABLED: 0
COVER: ${{ ( env.GOCOVERDIR != '' ) && '-cover' || '' }}
run: |
set -eux
GOARCH=amd64 go build -ldflags "-s -w" -trimpath -o bin/lxd-benchmark.x86_64 ${COVER} ./lxd-benchmark
GOARCH=arm64 go build -ldflags "-s -w" -trimpath -o bin/lxd-benchmark.aarch64 ${COVER} ./lxd-benchmark
- name: Build static lxd-convert
if: runner.os == 'Linux'
env:
CGO_ENABLED: 0
COVER: ${{ ( env.GOCOVERDIR != '' ) && '-cover' || '' }}
run: |
set -eux