Skip to content

Commit

Permalink
Fix systemd artifact install to account for artifact name
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperlin authored and cpuguy83 committed Jul 8, 2024
1 parent 9099c58 commit 577b9ef
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
5 changes: 3 additions & 2 deletions frontend/rpm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ func (w *specWrapper) Files() fmt.Stringer {
if w.Spec.Artifacts.Systemd != nil {
serviceKeys := dalec.SortMapKeys(w.Spec.Artifacts.Systemd.Units)
for _, p := range serviceKeys {
serviceName := filepath.Base(p)
unitPath := filepath.Join(`%{_unitdir}/`, serviceName)
cfg := w.Spec.Artifacts.Systemd.Units[p]
a := cfg.Artifact()
unitPath := filepath.Join(`%{_unitdir}/`, a.SubPath, a.ResolveName(p))
fmt.Fprintln(b, unitPath)
}

Expand Down
51 changes: 51 additions & 0 deletions frontend/rpm/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,57 @@ fi
`
assert.Equal(t, want, got)
})

t.Run("test systemd artifact installed under a different name", func(t *testing.T) {
spec := &dalec.Spec{
Name: "test-systemd-unit",
Description: "Test systemd unit",
Website: "https://www.github.com/Azure/dalec",
Version: "0.0.1",
Revision: "1",
Vendor: "Microsoft",
License: "Apache 2.0",
Packager: "Microsoft <[email protected]>",
Sources: map[string]dalec.Source{
"src": {
Inline: &dalec.SourceInline{
Dir: &dalec.SourceInlineDir{

Files: map[string]*dalec.SourceInlineFile{
"simple.service": {
Contents: `
Phony unit
`},
},
},
},
},
},
Artifacts: dalec.Artifacts{
Systemd: &dalec.SystemdConfiguration{
Units: map[string]dalec.SystemdUnitConfig{
"src/simple.service": {
Enable: true,
Name: "phony.service",
},
},
},
},
}
w := specWrapper{Spec: spec}

assert.Equal(t, w.Install().String(), `%install
mkdir -p %{buildroot}/%{_unitdir}
cp -r src/simple.service %{buildroot}/%{_unitdir}/phony.service
`)

assert.Equal(t, w.Files().String(), `%files
%{_unitdir}/phony.service
`)
})

}

func TestTemplate_Requires(t *testing.T) {
Expand Down
29 changes: 29 additions & 0 deletions test/azlinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,35 @@ WantedBy=multi-user.target
req := newSolveRequest(withBuildTarget(testConfig.BuildTarget), withSpec(ctx, t, spec))
solveT(ctx, t, client, req)
})

// Test to ensure unit can be installed under a different name
spec.Artifacts.Systemd = &dalec.SystemdConfiguration{
Units: map[string]dalec.SystemdUnitConfig{
"src/simple.service": {
Name: "phony.service",
},
},
}

spec.Tests = []*dalec.TestSpec{
{
Name: "Check service files",
Files: map[string]dalec.FileCheckOutput{
filepath.Join(testConfig.SystemdDir.Units, "system/phony.service"): {
CheckOutput: dalec.CheckOutput{Contains: []string{"ExecStart=/usr/bin/service"}},
Permissions: 0644,
},
filepath.Join(testConfig.SystemdDir.Targets, "multi-user.target.wants/phony.service"): {
NotExist: true,
},
},
},
}

testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
req := newSolveRequest(withBuildTarget(testConfig.BuildTarget), withSpec(ctx, t, spec))
solveT(ctx, t, client, req)
})
})

t.Run("test systemd unit multiple components", func(t *testing.T) {
Expand Down

0 comments on commit 577b9ef

Please sign in to comment.