Skip to content

Commit f3467a3

Browse files
vinceaperriCopilot
andcommitted
fix TestBaseConfigsFullRun() for azl4
Co-authored-by: Copilot <copilot@github.com>
1 parent 9a90d76 commit f3467a3

4 files changed

Lines changed: 362 additions & 13 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/baseconfigs_test.go

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package imagecustomizerlib
22

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
67
"runtime"
@@ -85,7 +86,7 @@ func TestBaseConfigsFullRun(t *testing.T) {
8586
buildDir := filepath.Join(testTmpDir, "build")
8687
outImageFilePath := filepath.Join(testTmpDir, "image.raw")
8788

88-
currentConfigFile := filepath.Join(testDir, "hierarchical-config.yaml")
89+
currentConfigFile := filepath.Join(testDir, hierarchicalConfigFile(t, baseImageInfo))
8990

9091
err = CustomizeImageWithConfigFile(t.Context(), buildDir, currentConfigFile, baseImage, nil,
9192
outImageFilePath, "raw", true, "")
@@ -169,22 +170,33 @@ func TestBaseConfigsFullRun(t *testing.T) {
169170
nginxInstalled := isPackageInstalled(imageConnection.Chroot(), "nginx")
170171
assert.True(t, nginxInstalled)
171172

172-
nginxVersionOutput, err := getPkgVersionFromChroot(imageConnection, "nginx")
173-
assert.NoError(t, err, "failed to retrieve nginx version from chroot")
174-
175-
nginxExpectedVersion := "nginx-1.25.4-5"
176-
assert.Containsf(t, nginxVersionOutput, nginxExpectedVersion,
177-
"should install nginx version %s, but got: %s", nginxExpectedVersion, nginxVersionOutput)
173+
// AZL4 uses dnf which does not support snapshot time, so versions are not pinned.
174+
if baseImageInfo.Version != baseImageVersionAzl4 {
175+
nginxVersionOutput, err := getPkgVersionFromChroot(imageConnection, "nginx")
176+
assert.NoError(t, err, "failed to retrieve nginx version from chroot")
177+
nginxExpectedVersion := "nginx-1.25.4-5"
178+
assert.Containsf(t, nginxVersionOutput, nginxExpectedVersion,
179+
"should install nginx version %s, but got: %s", nginxExpectedVersion, nginxVersionOutput)
180+
}
178181

179182
sshdInstalled := isPackageInstalled(imageConnection.Chroot(), "openssh-server")
180183
assert.True(t, sshdInstalled)
181184

182-
systemdBootVersionOutput, err := getPkgVersionFromChroot(imageConnection, "systemd-boot")
183-
assert.NoError(t, err, "failed to retrieve systemd-boot version from chroot")
184-
185-
systemdBootExpectedVersion := "systemd-boot-255-24"
186-
assert.Containsf(t, systemdBootVersionOutput, systemdBootExpectedVersion,
187-
"should install systemd-boot version %s, but got: %s", systemdBootExpectedVersion, systemdBootVersionOutput)
185+
systemdBootPkgName := "systemd-boot"
186+
if baseImageInfo.Version == baseImageVersionAzl4 {
187+
systemdBootPkgName = "systemd-boot-unsigned"
188+
}
189+
systemdBootInstalled := isPackageInstalled(imageConnection.Chroot(), systemdBootPkgName)
190+
assert.True(t, systemdBootInstalled, "expected %s to be installed", systemdBootPkgName)
191+
192+
// AZL4 uses dnf which does not support snapshot time, so versions are not pinned.
193+
if baseImageInfo.Version != baseImageVersionAzl4 {
194+
systemdBootVersionOutput, err := getPkgVersionFromChroot(imageConnection, systemdBootPkgName)
195+
assert.NoError(t, err, "failed to retrieve %s version from chroot", systemdBootPkgName)
196+
systemdBootExpectedVersion := "systemd-boot-255-24"
197+
assert.Containsf(t, systemdBootVersionOutput, systemdBootExpectedVersion,
198+
"should install systemd-boot version %s, but got: %s", systemdBootExpectedVersion, systemdBootVersionOutput)
199+
}
188200

189201
// Verify services
190202
sshdEnabled, err := systemd.IsServiceEnabled("sshd", imageConnection.Chroot())
@@ -262,6 +274,28 @@ func TestBaseConfigsFullRun(t *testing.T) {
262274
verifyFileContentsEqual(t, animalsFilePath, "cockatoo\npelican\nquoll\nbandicoot\n")
263275
}
264276

277+
// hierarchicalConfigFile returns the hierarchical-config test config file appropriate for the
278+
// given base image distro and version.
279+
func hierarchicalConfigFile(t *testing.T, baseImageInfo testBaseImageInfo) string {
280+
switch baseImageInfo.Distro {
281+
case baseImageDistroAzureLinux:
282+
switch baseImageInfo.Version {
283+
case baseImageVersionAzl2, baseImageVersionAzl3:
284+
return "hierarchical-config.yaml"
285+
case baseImageVersionAzl4:
286+
return fmt.Sprintf("hierarchical-config-%s-azl4.yaml", runtime.GOARCH)
287+
default:
288+
t.Fatalf("unsupported Azure Linux version for hierarchical-config test: %s", baseImageInfo.Version)
289+
return ""
290+
}
291+
case baseImageDistroUbuntu:
292+
return "hierarchical-config.yaml"
293+
default:
294+
t.Fatalf("unsupported distro for hierarchical-config test: %s", baseImageInfo.Distro)
295+
return ""
296+
}
297+
}
298+
265299
func TestBaseConfigsStorageInBaseConfig(t *testing.T) {
266300
baseImage, _ := checkSkipForCustomizeDefaultAzureLinuxImage(t)
267301

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Differs from hierarchical-config-base in the absence of the package-snapshot-time preview feature and os.packages.snapshotTime config; and its use of selinux-policy-targeted (not selinux-policy-modules), systemd-boot-unsigned (not systemd-boot), grub2-efi-x64 (not grub2-efi-binary), and hierarchical-config-base-azl4 (not hierarchical-config-base)
2+
storage:
3+
disks:
4+
- partitionTableType: gpt
5+
partitions:
6+
- id: esp
7+
type: esp
8+
size: 100M
9+
10+
- id: boot
11+
size: 100M
12+
13+
- id: rootfs
14+
size: 2G
15+
16+
bootType: efi
17+
18+
filesystems:
19+
- deviceId: esp
20+
type: fat32
21+
mountPoint:
22+
path: /boot/efi
23+
options: umask=0077
24+
25+
- deviceId: boot
26+
type: ext4
27+
mountPoint:
28+
path: /boot
29+
30+
- deviceId: rootfs
31+
type: ext4
32+
mountPoint:
33+
path: /
34+
35+
previewFeatures:
36+
- output-artifacts
37+
- base-configs
38+
- uki
39+
40+
baseConfigs:
41+
- path: hierarchical-config-base-azl4.yaml
42+
43+
os:
44+
additionalFiles:
45+
- source: files/b.txt
46+
destination: /mnt/b/b.txt
47+
48+
additionalDirs:
49+
- source: dirs/b
50+
destination: /
51+
52+
groups:
53+
- name: test-group
54+
55+
users:
56+
- name: test-user
57+
hostname: test-hostname
58+
bootloader:
59+
resetType: hard-reset
60+
61+
uki:
62+
mode: create
63+
64+
packages:
65+
remove:
66+
- grub2-efi-x64
67+
install:
68+
- systemd-boot-unsigned
69+
- openssh-server
70+
- selinux-policy
71+
- selinux-policy-targeted
72+
73+
services:
74+
enable:
75+
- sshd
76+
disable:
77+
- console-getty
78+
79+
modules:
80+
- name: vfio
81+
loadMode: disable
82+
83+
selinux:
84+
mode: disabled
85+
86+
overlays:
87+
- mountPoint: /etc
88+
lowerDirs:
89+
- /etc
90+
upperDir: /var/overlays/etc/upper
91+
workDir: /var/overlays/etc/work
92+
93+
kernelCommandLine:
94+
extraCommandLine:
95+
- console=tty0
96+
- console=ttyS0
97+
98+
scripts:
99+
postCustomization:
100+
- content: |
101+
set -eux
102+
echo "pelican" >> "/animals.txt"
103+
104+
finalizeCustomization:
105+
- content: |
106+
set -eux
107+
echo "bandicoot" >> "/animals.txt"
108+
109+
input:
110+
image:
111+
path: testimages/empty.vhdx
112+
113+
output:
114+
image:
115+
path: ./out/output-image-2.vhdx
116+
format: vhdx
117+
artifacts:
118+
items:
119+
- shim
120+
path: ./out/artifacts-2
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Differs from hierarchical-config-amd64-azl4 in its use of grub2-efi-aa64 (not grub2-efi-x64)
2+
storage:
3+
disks:
4+
- partitionTableType: gpt
5+
partitions:
6+
- id: esp
7+
type: esp
8+
size: 100M
9+
10+
- id: boot
11+
size: 100M
12+
13+
- id: rootfs
14+
size: 2G
15+
16+
bootType: efi
17+
18+
filesystems:
19+
- deviceId: esp
20+
type: fat32
21+
mountPoint:
22+
path: /boot/efi
23+
options: umask=0077
24+
25+
- deviceId: boot
26+
type: ext4
27+
mountPoint:
28+
path: /boot
29+
30+
- deviceId: rootfs
31+
type: ext4
32+
mountPoint:
33+
path: /
34+
35+
previewFeatures:
36+
- output-artifacts
37+
- base-configs
38+
- uki
39+
40+
baseConfigs:
41+
- path: hierarchical-config-base-azl4.yaml
42+
43+
os:
44+
additionalFiles:
45+
- source: files/b.txt
46+
destination: /mnt/b/b.txt
47+
48+
additionalDirs:
49+
- source: dirs/b
50+
destination: /
51+
52+
groups:
53+
- name: test-group
54+
55+
users:
56+
- name: test-user
57+
hostname: test-hostname
58+
bootloader:
59+
resetType: hard-reset
60+
61+
uki:
62+
mode: create
63+
64+
packages:
65+
remove:
66+
- grub2-efi-aa64
67+
install:
68+
- systemd-boot-unsigned
69+
- openssh-server
70+
- selinux-policy
71+
- selinux-policy-targeted
72+
73+
services:
74+
enable:
75+
- sshd
76+
disable:
77+
- console-getty
78+
79+
modules:
80+
- name: vfio
81+
loadMode: disable
82+
83+
selinux:
84+
mode: disabled
85+
86+
overlays:
87+
- mountPoint: /etc
88+
lowerDirs:
89+
- /etc
90+
upperDir: /var/overlays/etc/upper
91+
workDir: /var/overlays/etc/work
92+
93+
kernelCommandLine:
94+
extraCommandLine:
95+
- console=tty0
96+
- console=ttyS0
97+
98+
scripts:
99+
postCustomization:
100+
- content: |
101+
set -eux
102+
echo "pelican" >> "/animals.txt"
103+
104+
finalizeCustomization:
105+
- content: |
106+
set -eux
107+
echo "bandicoot" >> "/animals.txt"
108+
109+
input:
110+
image:
111+
path: testimages/empty.vhdx
112+
113+
output:
114+
image:
115+
path: ./out/output-image-2.vhdx
116+
format: vhdx
117+
artifacts:
118+
items:
119+
- shim
120+
path: ./out/artifacts-2

0 commit comments

Comments
 (0)