Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
many: fix test cases to work with different DistroLibExecDir #3222
0281474
710add9
c094911
11cfe4d
b92eae2
8f9dd95
2c626ed
88adec0
10612e6
ceb483f
2f3b287
9b771dd
97cde96
f0969ab
9e05477
94cc0e1
f78d791
a004317
69bc196
5cecbe2
8967f3a
cea541b
999789f
| @@ -98,7 +98,7 @@ func (s *SnapSuite) TestSnapRunAppIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
mvo5
Collaborator
|
||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R("x2"), | ||
| @@ -126,7 +126,7 @@ func (s *SnapSuite) TestSnapRunAppIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "snapname.app", "--arg1", "arg2"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=x2") | ||
| } | ||
| @@ -135,7 +135,7 @@ func (s *SnapSuite) TestSnapRunClassicAppIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml)+"confinement: classic\n", string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R("x2"), | ||
| @@ -163,7 +163,7 @@ func (s *SnapSuite) TestSnapRunClassicAppIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), "--classic", | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "snapname.app", "--arg1", "arg2"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=x2") | ||
| } | ||
| @@ -172,7 +172,7 @@ func (s *SnapSuite) TestSnapRunAppWithCommandIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R(42), | ||
| @@ -199,7 +199,7 @@ func (s *SnapSuite) TestSnapRunAppWithCommandIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "--command=my-command", "snapname.app", "arg1", "arg2"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42") | ||
| } | ||
| @@ -225,7 +225,7 @@ func (s *SnapSuite) TestSnapRunHookIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R(42), | ||
| @@ -252,7 +252,7 @@ func (s *SnapSuite) TestSnapRunHookIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.hook.configure", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "--hook=configure", "snapname"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42") | ||
| } | ||
| @@ -261,7 +261,7 @@ func (s *SnapSuite) TestSnapRunHookUnsetRevisionIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R(42), | ||
| @@ -288,7 +288,7 @@ func (s *SnapSuite) TestSnapRunHookUnsetRevisionIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.hook.configure", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "--hook=configure", "snapname"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42") | ||
| } | ||
| @@ -297,7 +297,7 @@ func (s *SnapSuite) TestSnapRunHookSpecificRevisionIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| // Create both revisions 41 and 42 | ||
| snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| @@ -326,7 +326,7 @@ func (s *SnapSuite) TestSnapRunHookSpecificRevisionIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.hook.configure", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "--hook=configure", "snapname"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=41") | ||
| } | ||
| @@ -398,14 +398,14 @@ func (s *SnapSuite) TestSnapRunErorsForMissingApp(c *check.C) { | ||
| func (s *SnapSuite) TestSnapRunErorrForUnavailableApp(c *check.C) { | ||
| _, err := snaprun.Parser().ParseArgs([]string{"run", "not-there"}) | ||
| - c.Assert(err, check.ErrorMatches, "cannot find current revision for snap not-there: readlink /snap/not-there/current: no such file or directory") | ||
| + c.Assert(err, check.ErrorMatches, fmt.Sprintf("cannot find current revision for snap not-there: readlink %s/not-there/current: no such file or directory", dirs.SnapMountDir)) | ||
| } | ||
| func (s *SnapSuite) TestSnapRunSaneEnvironmentHandling(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R(42), | ||
| @@ -451,8 +451,8 @@ func (s *SnapSuite) TestSnapRunIsReexeced(c *check.C) { | ||
| readlink string | ||
| expected bool | ||
| }{ | ||
| - {filepath.Join(dirs.SnapMountDir, "/usr/lib/snapd/snapd"), true}, | ||
| - {"/usr/lib/snapd/snapd", false}, | ||
| + {filepath.Join(dirs.SnapMountDir, dirs.CoreLibExecDir, "snapd"), true}, | ||
| + {fmt.Sprintf("%s/snapd", dirs.DistroLibExecDir), false}, | ||
|
|
||
| } { | ||
| osReadlinkResult = t.readlink | ||
| c.Check(snaprun.IsReexeced(), check.Equals, t.expected) | ||
| @@ -463,7 +463,7 @@ func (s *SnapSuite) TestSnapRunAppIntegrationFromCore(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(filepath.Join(dirs.SnapMountDir, "core", "current", dirs.CoreLibExecDir))() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R("x2"), | ||
| @@ -473,7 +473,7 @@ func (s *SnapSuite) TestSnapRunAppIntegrationFromCore(c *check.C) { | ||
| // pretend to be running from core | ||
| restorer := snaprun.MockOsReadlink(func(string) (string, error) { | ||
| - return filepath.Join(dirs.SnapMountDir, "/core/111//usr/bin/snap"), nil | ||
| + return filepath.Join(dirs.SnapMountDir, "core/111/usr/bin/snap"), nil | ||
| }) | ||
| defer restorer() | ||
| @@ -493,11 +493,11 @@ func (s *SnapSuite) TestSnapRunAppIntegrationFromCore(c *check.C) { | ||
| rest, err := snaprun.Parser().ParseArgs([]string{"run", "snapname.app", "--arg1", "arg2"}) | ||
| c.Assert(err, check.IsNil) | ||
| c.Assert(rest, check.DeepEquals, []string{"snapname.app", "--arg1", "arg2"}) | ||
| - c.Check(execArg0, check.Equals, filepath.Join(dirs.SnapMountDir, "/core/current", dirs.DistroLibExecDir, "snap-confine")) | ||
| + c.Check(execArg0, check.Equals, filepath.Join(dirs.SnapMountDir, "/core/current", dirs.CoreLibExecDir, "snap-confine")) | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| - filepath.Join(dirs.SnapMountDir, "/core/current", dirs.DistroLibExecDir, "snap-confine"), | ||
| + filepath.Join(dirs.SnapMountDir, "/core/current", dirs.CoreLibExecDir, "snap-confine"), | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "snapname.app", "--arg1", "arg2"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=x2") | ||
| } | ||
| @@ -507,7 +507,7 @@ func (s *SnapSuite) TestSnapRunXauthorityMigration(c *check.C) { | ||
| // below /tmp which the Xauthority migration expects. | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| u, err := user.Current() | ||
| c.Assert(err, check.IsNil) | ||
| @@ -553,7 +553,7 @@ func (s *SnapSuite) TestSnapRunXauthorityMigration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "snapname.app"}) | ||
| expectedXauthPath := filepath.Join(dirs.XdgRuntimeDirBase, u.Uid, ".Xauthority") | ||
| @@ -32,7 +32,18 @@ import ( | ||
| var ( | ||
| GlobalRootDir string | ||
| - SnapMountDir string | ||
| + SnapMountDir string | ||
| + | ||
| + // CoreSnapMountDir is the path of the snap mount dir inside | ||
| + // the snap confinement environment. Give this nature it will | ||
|
|
||
| + // not include the GlobalRootDir as prefix. | ||
| + CoreSnapMountDir string | ||
| + | ||
| + // CoreLibExecDir is similar to CoreSnapMountDir but for the | ||
| + // LibExecDir used by snapd. | ||
| + CoreLibExecDir string | ||
| + DistroLibExecDir string | ||
| + | ||
| SnapBlobDir string | ||
|
|
||
| SnapDataDir string | ||
| SnapDataHomeGlob string | ||
| @@ -72,9 +83,6 @@ var ( | ||
| ClassicDir string | ||
| - DistroLibExecDir string | ||
| - CoreLibExecDir string | ||
| - | ||
| XdgRuntimeDirBase string | ||
| XdgRuntimeDirGlob string | ||
| @@ -181,7 +189,11 @@ func SetRootDir(rootdir string) { | ||
| DistroLibExecDir = filepath.Join(rootdir, "/usr/lib/snapd") | ||
| } | ||
| - CoreLibExecDir = filepath.Join(rootdir, "/usr/lib/snapd") | ||
| + // These are directories which are static inside the core snap and | ||
| + // can never be prefixed as they will be always absolute once we | ||
| + // are in the snap confinement environment. | ||
| + CoreLibExecDir = "/usr/lib/snapd" | ||
|
|
||
| + CoreSnapMountDir = "/snap" | ||
niemeyer
Contributor
|
||
| XdgRuntimeDirBase = filepath.Join(rootdir, "/run/user") | ||
| XdgRuntimeDirGlob = filepath.Join(rootdir, XdgRuntimeDirBase, "*/") | ||
This should be done only once in this function. Right now it's being done twice, and it's also bogus because code right below will test for a path that does not exist. Proper way is likely to bring the code currently at the bottom here, and make sure snapConfine points to the proper thing upfront.