Skip to content

Commit

Permalink
snap-failure: set symlink before calling snapd
Browse files Browse the repository at this point in the history
  • Loading branch information
valentindavid authored and Meulengracht committed Mar 13, 2024
1 parent d1cf336 commit 4bacd50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cmd/snap-failure/cmd_snapd.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ func (c *cmdSnapd) Execute(args []string) error {
}

logger.Noticef("restoring invoking snapd from: %v", snapdPath)
if prevRev != "0" {
// if prevRev was "0" it means we did *not* find a
// previous revision and we would obey the current
// symlink. So we overwrite the symlink only if
// prevRev != "0".
currentSymlink := filepath.Join(dirs.SnapMountDir, "snapd", "current")
if err := osutil.AtomicSymlink(prevRev, currentSymlink); err != nil {
return fmt.Errorf("cannot create symlink %s: %v", currentSymlink, err)
}
}
// start previous snapd
cmd := runCmd(snapdPath, nil, []string{"SNAPD_REVERT_TO_REV=" + prevRev, "SNAPD_DEBUG=1"})
if err = cmd.Run(); err != nil {
Expand Down
11 changes: 9 additions & 2 deletions cmd/snap-failure/cmd_snapd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package main_test

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -72,9 +73,15 @@ func (r *failureSuite) TestCallPrevSnapdFromSnap(c *C) {
{Revision: snap.R(123)},
})

mockScript := `
set -eu
[ -L '%[1]s/snapd/current' ]
[ "$(readlink '%[1]s/snapd/current')" = 100 ]
[ "${SNAPD_REVERT_TO_REV}" = 100 ]
`
// mock snapd command from 'previous' revision
snapdCmd := testutil.MockCommand(c, filepath.Join(dirs.SnapMountDir, "snapd", "100", "/usr/lib/snapd/snapd"),
`test "$SNAPD_REVERT_TO_REV" = "100"`)
snapdCmd := testutil.MockCommand(c, filepath.Join(dirs.SnapMountDir, "snapd", "100", "/usr/lib/snapd/snapd"), fmt.Sprintf(mockScript, dirs.SnapMountDir))
defer snapdCmd.Restore()

systemctlCmd := testutil.MockCommand(c, "systemctl", "")
Expand Down

0 comments on commit 4bacd50

Please sign in to comment.