File: task.yaml

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (158 lines) | stat: -rw-r--r-- 8,492 bytes parent folder | download | duplicates (2)
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
summary: Check that preseeding of current ubuntu cloud image works.

details: |
  This test checks that preseeding of Ubuntu cloud images with snap-preseed
  command works, up to the point where the image is ready to be booted.
  The test assumes cloud image with a core and lxd snaps in its seeds/.

# Ubuntu 24.04: there is no longer any seeded snaps in base or minimal cloud images
# https://bugs.launchpad.net/ubuntu/+source/ubuntu-meta/+bug/2051346
# https://bugs.launchpad.net/ubuntu/+source/ubuntu-meta/+bug/2051572
systems: [ubuntu-20*, ubuntu-22*]

environment:
  IMAGE_MOUNTPOINT: /mnt/cloudimg

prepare: |
  # shellcheck source=tests/lib/image.sh
  . "$TESTSLIB"/image.sh

  # the get_image_url_for_vm is a convenient helper that returns
  # a cloud image url matching current $SPREAD_SYSTEM.
  wget --quiet "$(get_image_url_for_vm)" -O cloudimg.img
  mkdir -p "$IMAGE_MOUNTPOINT"

  #shellcheck source=tests/lib/preseed.sh
  . "$TESTSLIB/preseed.sh"
  mount_ubuntu_image "$(pwd)/cloudimg.img" "$IMAGE_MOUNTPOINT"

  # add snapd from this branch into the seed
  # shellcheck source=tests/lib/prepare.sh
  . "$TESTSLIB"/prepare.sh
  build_snapd_snap_with_run_mode_firstboot_tweaks "$PWD"
  mv snapd_*.snap snapd.snap
  inject_snap_into_seed "$IMAGE_MOUNTPOINT" snapd

  # for images that are already preseeded, we need to undo the preseeding there
  echo "Running preseed --reset for already preseeded cloud images"
  SNAP_PRESEED=/usr/lib/snapd/snap-preseed
  if tests.info is-snapd-from-archive; then
      SNAP_PRESEED="/snap/snapd/current$SNAP_PRESEED"
  fi
  SNAPD_DEBUG=1 "$SNAP_PRESEED" --reset "$IMAGE_MOUNTPOINT"

restore: |
  #shellcheck source=tests/lib/preseed.sh
  . "$TESTSLIB/preseed.sh"
  umount_ubuntu_image "$IMAGE_MOUNTPOINT" || true

execute: |
  LXD_BASE_SNAP=core20
  if os.query is-ubuntu-gt 22.04; then
      LXD_BASE_SNAP=core22
  fi

  SNAP_PRESEED=/usr/lib/snapd/snap-preseed
  if tests.info is-snapd-from-archive; then
      SNAP_PRESEED="/snap/snapd/current$SNAP_PRESEED"
  fi

  echo "Checking missing chroot path arg error"
  "$SNAP_PRESEED" 2>&1 | MATCH "error: need chroot path as argument"

  echo "Running pre-seeding"
  SNAPD_DEBUG=1 "$SNAP_PRESEED" "$IMAGE_MOUNTPOINT"

  # precondition, core snap mounted by snap-preseed got unmounted
  mount | NOMATCH "snap-preseed"

  snap debug state "$IMAGE_MOUNTPOINT"/var/lib/snapd/state.json --change=1 > tasks.log

  echo "Check that the tasks of preseeded snapd have expected statuses"
  # Note, these checks match statuses, but not the order
  # mark-preseeded task is where snap-preseed stopped, therefore it's in Doing.
  MATCH "Doing .+ mark-preseeded +Mark system pre-seeded" < tasks.log

  MATCH "Done .+ prerequisites +Ensure prerequisites for \"snapd\" are available" < tasks.log
  MATCH "Done .+ prepare-snap +Prepare snap \"/var/lib/snapd/seed/snaps/snapd.snap" < tasks.log
  MATCH "Done .+ mount-snap +Mount snap \"snapd\" \(unset\)" < tasks.log
  MATCH "Done .+ copy-snap-data +Copy snap \"snapd\" data" < tasks.log
  MATCH "Done .+ setup-profiles +Setup snap \"snapd\" \(unset\) security profiles" < tasks.log
  MATCH "Done .+ link-snap +Make snap \"snapd\" \(unset\) available to the system" < tasks.log
  MATCH "Done .+ auto-connect +Automatically connect eligible plugs and slots of snap \"snapd\"" < tasks.log
  MATCH "Done .+ set-auto-aliases +Set automatic aliases for snap \"snapd\"" < tasks.log
  MATCH "Done .+ setup-aliases +Setup snap \"snapd\" aliases" < tasks.log

  MATCH "Done .+ prerequisites +Ensure prerequisites for \"${LXD_BASE_SNAP}\" are available" < tasks.log
  MATCH "Done .+ prepare-snap +Prepare snap \"/var/lib/snapd/seed/snaps/${LXD_BASE_SNAP}_[0-9]+.snap" < tasks.log
  MATCH "Done .+ mount-snap +Mount snap \"${LXD_BASE_SNAP}\" \([0-9]+\)" < tasks.log
  MATCH "Done .+ copy-snap-data +Copy snap \"${LXD_BASE_SNAP}\" data" < tasks.log
  MATCH "Done .+ setup-profiles +Setup snap \"${LXD_BASE_SNAP}\" \([0-9]+\) security profiles" < tasks.log
  MATCH "Done .+ link-snap +Make snap \"${LXD_BASE_SNAP}\" \([0-9]+\) available to the system" < tasks.log
  MATCH "Done .+ auto-connect +Automatically connect eligible plugs and slots of snap \"${LXD_BASE_SNAP}\"" < tasks.log
  MATCH "Done .+ set-auto-aliases +Set automatic aliases for snap \"${LXD_BASE_SNAP}\"" < tasks.log
  MATCH "Done .+ setup-aliases +Setup snap \"${LXD_BASE_SNAP}\" aliases" < tasks.log

  MATCH "Done .+ prerequisites +Ensure prerequisites for \"lxd\" are available" < tasks.log
  MATCH "Done .+ prepare-snap +Prepare snap \"/var/lib/snapd/seed/snaps/lxd_[0-9]+.snap\" \([0-9]+\)" < tasks.log
  MATCH "Done .+ mount-snap +Mount snap \"lxd\" \([0-9]+\)" < tasks.log
  MATCH "Done .+ copy-snap-data +Copy snap \"lxd\" data" < tasks.log
  MATCH "Done .+ setup-profiles +Setup snap \"lxd\" \([0-9]+\) security profiles" < tasks.log
  MATCH "Done .+ link-snap +Make snap \"lxd\" \([0-9]+\) available to the system" < tasks.log
  MATCH "Done .+ auto-connect +Automatically connect eligible plugs and slots of snap \"lxd\"" < tasks.log
  MATCH "Done .+ connect +Connect lxd:network to snapd:network" < tasks.log
  MATCH "Done .+ connect +Connect lxd:lxd-support to snapd:lxd-support" < tasks.log
  MATCH "Done .+ connect +Connect lxd:system-observe to snapd:system-observe" < tasks.log
  MATCH "Done .+ connect +Connect lxd:network-bind to snapd:network-bind" < tasks.log
  MATCH "Done .+ setup-profiles +Setup snap \"lxd\" \([0-9]+\) security profiles for auto-connections" < tasks.log
  MATCH "Done .+ set-auto-aliases +Set automatic aliases for snap \"lxd\"" < tasks.log
  MATCH "Done .+ setup-aliases +Setup snap \"lxd\" aliases" < tasks.log

  echo "Checking that there were no other 'Done' tasks when preseeding"
  [ "$(grep -c ' Done ' tasks.log)" = "32" ]

  # everything below is pending execution on first boot
  MATCH "Do .+ run-hook +Run install hook of \"${LXD_BASE_SNAP}\" snap if present" < tasks.log
  MATCH "Do .+ start-snap-services +Start snap \"lxd\" \([0-9]+\) services" < tasks.log
  MATCH "Do .+ run-hook +Run configure hook of \"lxd\" snap if present" < tasks.log
  MATCH "Do .+ run-hook +Run health check of \"lxd\" snap" < tasks.log
  MATCH "Do .+ mark-seeded +Mark system seeded" < tasks.log
  MATCH "Do .+ run-hook +Run install hook of \"snapd\" snap if present" < tasks.log
  MATCH "Do .+ start-snap-services +Start snap \"snapd\" \(unset\) services" < tasks.log
  MATCH "Do .+ run-hook +Run configure hook of \"core\" snap if present" < tasks.log
  MATCH "Do .+ start-snap-services  +Start snap \"${LXD_BASE_SNAP}\" \([0-9]+\) services" < tasks.log
  MATCH "Do .+ run-hook +Run health check of \"${LXD_BASE_SNAP}\" snap" < tasks.log
  MATCH "Do .+ run-hook +Run install hook of \"lxd\" snap if present" < tasks.log

  echo "Checking that apparmor and seccomp profiles have been created on the target image"
  AA_PROFILES="$IMAGE_MOUNTPOINT"/var/lib/snapd/apparmor/profiles
  SECCOMP_PROFILES="$IMAGE_MOUNTPOINT"/var/lib/snapd/seccomp/bpf

  test -f "$AA_PROFILES"/snap-confine.snapd.*
  test -f "$AA_PROFILES"/snap-update-ns.lxd

  # the list of expected profiles isn't exhaustive, we're just checking some critical ones
  for prof in snap.lxd.lxd snap.lxd.hook.install snap.lxd.hook.configure snap.lxd.daemon; do
    test -f "$AA_PROFILES/$prof"
    test -f "$SECCOMP_PROFILES/$prof.bin2"
  done

  echo "Checking that mount units have been created and enabled on the target image"
  SYSTEMD_UNITS="$IMAGE_MOUNTPOINT"/etc/systemd
  test -f "$SYSTEMD_UNITS"/system/snap-lxd-*.mount
  test -L "$SYSTEMD_UNITS"/system/snapd.mounts.target.wants/snap-lxd-*.mount
  test -L "$SYSTEMD_UNITS"/system/multi-user.target.wants/snap-lxd-*.mount
  test -f "$SYSTEMD_UNITS"/system/snap-snapd-*.mount
  test -f "$SYSTEMD_UNITS"/system/snap-"${LXD_BASE_SNAP}"-*.mount
  test -L "$SYSTEMD_UNITS"/system/snapd.mounts.target.wants/snap-"${LXD_BASE_SNAP}"-*.mount
  test -L "$SYSTEMD_UNITS"/system/multi-user.target.wants/snap-"${LXD_BASE_SNAP}"-*.mount
  test -L "$SYSTEMD_UNITS"/system/snapd.mounts.target.wants/snap-snapd-*.mount
  test -L "$SYSTEMD_UNITS"/system/multi-user.target.wants/snap-snapd-*.mount

  for unit in snap.lxd.daemon.service snap.lxd.daemon.unix.socket snap.lxd.activate.service; do
    test -f "$SYSTEMD_UNITS/system/$unit"
  done

  echo "LXD service shouldn't be enabled at this point"
  test ! -e "$SYSTEMD_UNITS"/system/snapd.mounts.target.wants/snap.lxd.activate.service
  test ! -e "$SYSTEMD_UNITS"/system/multi-user.target.wants/snap.lxd.activate.service