Skip to content

Commit

Permalink
fix: correct instance error messages & xdg var e2e-tests
Browse files Browse the repository at this point in the history
Ensure that action/instanceDbusXdg e2e-tests are correctly checking
success / failure with the modified XDG env vars that are expected.

Correct an incorrect debug message from copy/paste error.

If the starter fails when starting an instance, output the starter
StdErr to the terminal StdErr - previously we were writing started
StdErr to terminal StdOut.

Fixes sylabs#3494
  • Loading branch information
dtrudg committed Feb 3, 2025
1 parent 5d15224 commit ed64559
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

- Use correct username (not user's name) when computing `singularity oci` conmon
/ singularity state dir.
- Write StdErr messages from starter to terminal StdErr when an instance fails
to start. Previously incorrectly written to terminal StdOut.
- Fix incorrect debug message in Cgroups checks.

### New Features & Functionality

Expand Down
19 changes: 15 additions & 4 deletions e2e/cgroups/cgroups.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024, Sylabs Inc. All rights reserved.
// Copyright (c) 2022-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -467,7 +467,8 @@ func (c *ctx) actionDbusXDG(t *testing.T) {
e2e.WithProfile(profile),
e2e.WithCommand("exec"),
e2e.WithArgs(tt.args...),
e2e.WithEnv(testEnv),
e2e.WithRootlessEnv(), // Apply valid rootless env vars
e2e.WithEnv(testEnv), // Override with invalid values from test
e2e.ExpectExit(tt.expectErrorCode, exitFunc...),
)
}
Expand All @@ -487,6 +488,7 @@ func (c *ctx) instanceDbusXdg(t *testing.T) {
name string
args []string
expectErrorCode int
expectErrorOut string
xdgVar string
dbusVar string
}{
Expand All @@ -506,12 +508,14 @@ func (c *ctx) instanceDbusXdg(t *testing.T) {
name: "bad xdg limits",
args: []string{"--cpus", "1", c.env.ImagePath},
expectErrorCode: 255,
expectErrorOut: "XDG_RUNTIME_DIR",
xdgVar: "/not/a/dir",
},
{
name: "bad dbus limits",
args: []string{"--cpus", "1", c.env.ImagePath},
expectErrorCode: 255,
expectErrorOut: "DBUS_SESSION_BUS_ADDRESS",
dbusVar: "/not/a/dbus/socket",
},
}
Expand All @@ -520,6 +524,11 @@ func (c *ctx) instanceDbusXdg(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
instanceName := randomName(t)

exitFunc := []e2e.SingularityCmdResultOp{}
if tt.expectErrorOut != "" {
exitFunc = []e2e.SingularityCmdResultOp{e2e.ExpectError(e2e.ContainMatch, tt.expectErrorOut)}
}

testEnv := []string{}
if tt.xdgVar != "" {
testEnv = append(testEnv, "XDG_RUNTIME_DIR="+tt.xdgVar)
Expand All @@ -535,8 +544,9 @@ func (c *ctx) instanceDbusXdg(t *testing.T) {
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("instance start"),
e2e.WithArgs(createArgs...),
e2e.WithEnv(testEnv),
e2e.ExpectExit(tt.expectErrorCode),
e2e.WithRootlessEnv(), // Apply valid rootless env vars
e2e.WithEnv(testEnv), // Override with invalid values from test
e2e.ExpectExit(tt.expectErrorCode, exitFunc...),
)

if tt.expectErrorCode == 0 {
Expand All @@ -546,6 +556,7 @@ func (c *ctx) instanceDbusXdg(t *testing.T) {
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("instance stop"),
e2e.WithArgs(instanceName),
e2e.WithRootlessEnv(),
e2e.ExpectExit(0),
)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/cgroups/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024, Sylabs Inc. All rights reserved.
// Copyright (c) 2022-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -140,7 +140,7 @@ func CanUseCgroups(systemd bool, warn bool) bool {
if warn {
sylog.Warningf("Rootless cgroups require the system to be configured for cgroups v2 in unified mode.")
} else {
sylog.Debugf("Rootless cgroups require 'systemd cgroups' to be enabled in singularity.conf")
sylog.Debugf("Rootless cgroups require the system to be configured for cgroups v2 in unified mode.")
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/runtime/launcher/native/launcher_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2024, Sylabs Inc. All rights reserved.
// Copyright (c) 2019-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -1328,7 +1328,7 @@ func (l *Launcher) starterInstance(name string, useSuid bool) error {
if end-start > 0 {
output := make([]byte, end-start)
stderr.ReadAt(output, start)
fmt.Println(string(output))
fmt.Fprintln(os.Stderr, string(output))
}
}

Expand Down

0 comments on commit ed64559

Please sign in to comment.