Skip to content

Commit

Permalink
Merge pull request #2408 from dtrudg/issue1944
Browse files Browse the repository at this point in the history
fix: Execute correct %appscript and add test for instance start --app
  • Loading branch information
dtrudg committed Nov 29, 2023
2 parents 768c77f + 596fe35 commit 07ea516
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
given the `--app <appname>` flag, and will automatically invoke the relevant
SCIF command.

### Bug Fixes

- Execute correct `%appstart` script when using `instance start` with `--app`.

## 4.0.2 \[2023-11-16\]

### Changed defaults / behaviours
Expand Down
36 changes: 34 additions & 2 deletions e2e/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,38 @@ func (c *ctx) testBasicEchoServer(t *testing.T) {
return
}
// Try to contact the instance.
echo(t, instanceStartPort)
echo(t, instanceStartPort, false)
c.stopInstance(t, instanceName)
}),
e2e.ExpectExit(0),
)
}

// Test that a basic reverse-echo server defined in an appstart script can be started,
// communicated with, and stopped.
func (c *ctx) testAppEchoServer(t *testing.T) {
const instanceName = "echoApp"

args := []string{
"--app",
"foo",
c.env.ImagePath,
instanceName,
strconv.Itoa(instanceStartPort),
}

// Start the instance.
c.env.RunSingularity(
t,
e2e.WithProfile(c.profile),
e2e.WithCommand("instance start"),
e2e.WithArgs(args...),
e2e.PostRun(func(t *testing.T) {
if t.Failed() {
return
}
// Try to contact the instance.
echo(t, instanceStartPort, true)
c.stopInstance(t, instanceName)
}),
e2e.ExpectExit(0),
Expand All @@ -77,7 +108,7 @@ func (c *ctx) testCreateManyInstances(t *testing.T) {
e2e.WithCommand("instance start"),
e2e.WithArgs(c.env.ImagePath, instanceName, strconv.Itoa(port)),
e2e.PostRun(func(t *testing.T) {
echo(t, port)
echo(t, port, false)
}),
e2e.ExpectExit(0),
)
Expand Down Expand Up @@ -403,6 +434,7 @@ func E2ETests(env e2e.TestEnv) testhelper.Tests {
function func(*testing.T)
}{
{"BasicEchoServer", c.testBasicEchoServer},
{"AppEchoServer", c.testAppEchoServer},
{"BasicOptions", c.testBasicOptions},
{"Contain", c.testContain},
{"InstanceFromURI", c.testInstanceFromURI},
Expand Down
21 changes: 15 additions & 6 deletions e2e/instance/instance_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,18 @@ func (c *ctx) expectInstance(t *testing.T, name string, nb int) {
)
}

// Sends a deterministic message to an echo server and expects the same message
// in response.
func echo(t *testing.T, port int) {
const message = "b40cbeaaea293f7e8bd40fb61f389cfca9823467\n"
// Sends a deterministic message to an echo server and expects the same, or a
// reversed, message in response.
func echo(t *testing.T, port int, reverse bool) {
const (
message = "b40cbeaaea293f7e8bd40fb61f389cfca9823467\n"
reversedMessage = "7643289acfc983f16bf04db8e7f392aeaaebc04b\n"
)

expectResponse := message
if reverse {
expectResponse = reversedMessage
}

// give it some time for responding, attempt 10 times by
// waiting 100 millisecond between each try
Expand All @@ -114,8 +122,9 @@ func echo(t *testing.T, port int) {
fmt.Fprint(sock, message)

response, responseErr := bufio.NewReader(sock).ReadString('\n')
if responseErr != nil || response != message {
t.Errorf("Bad response: err = %v, response = %v", responseErr, response)

if responseErr != nil || response != expectResponse {
t.Errorf("Bad response: err = %v, response %q != %q", responseErr, response, expectResponse)
}
break
}
Expand Down
4 changes: 3 additions & 1 deletion e2e/testdata/Singularity
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ export HELLOTHISIS

%appstart foo
echo "STARTING FOO"
exec nc -l -k -p $1 -e /bin/cat
# Echo back reverse of strings sent on port $1
exec nc -l -k -p $1 -e /bin/rev

%startscript
# Echo back strings sent on port $1
exec nc -l -k -p $1 -e /bin/cat

%runscript
Expand Down
8 changes: 7 additions & 1 deletion internal/pkg/util/fs/files/action_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ test)
sylog info "No test script found in container, exiting"
exit 0 ;;
start)
if test -x "/.singularity.d/startscript"; then
if test -n "${SINGULARITY_APPNAME:-}"; then
if test -x "/scif/apps/${SINGULARITY_APPNAME:-}/scif/startscript"; then
exec "/scif/apps/${SINGULARITY_APPNAME:-}/scif/startscript" "$@"
fi
sylog error "No startscript for contained app: ${SINGULARITY_APPNAME:-}"
exit 1
elif test -x "/.singularity.d/startscript"; then
exec "/.singularity.d/startscript" "$@"
fi
Expand Down

0 comments on commit 07ea516

Please sign in to comment.