Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon, interfaces, travis: workaround build ID with Go 1.9, use 1.9 for travis tests #7063

Merged
merged 3 commits into from Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -4,9 +4,9 @@ git:
jobs:
include:
- stage: quick
name: go 1.10/xenial static and unit test suites
name: go 1.9/xenial static and unit test suites
dist: xenial
go: "1.10.x"
go: "1.9.x"
before_install:
- sudo apt --quiet -o Dpkg::Progress-Fancy=false update
install:
Expand Down
10 changes: 6 additions & 4 deletions daemon/api_test.go
Expand Up @@ -1031,8 +1031,9 @@ func (s *apiSuite) TestSysInfo(c *check.C) {
// reload dirs for release info to have effect
dirs.SetRootDir(dirs.GlobalRootDir)

buildID, err := osutil.MyBuildID()
c.Assert(err, check.IsNil)
buildID := "this-is-my-build-id"
restore = MockBuildID(buildID)
defer restore()

sysInfoCmd.GET(sysInfoCmd, nil, nil).ServeHTTP(rec, nil)
c.Check(rec.Code, check.Equals, 200)
Expand Down Expand Up @@ -1101,8 +1102,9 @@ func (s *apiSuite) TestSysInfoLegacyRefresh(c *check.C) {
})
c.Assert(err, check.IsNil)

buildID, err := osutil.MyBuildID()
c.Assert(err, check.IsNil)
buildID := "this-is-my-build-id"
restore = MockBuildID(buildID)
defer restore()

sysInfoCmd.GET(sysInfoCmd, nil, nil).ServeHTTP(rec, nil)
c.Check(rec.Code, check.Equals, 200)
Expand Down
8 changes: 8 additions & 0 deletions daemon/export_test.go
Expand Up @@ -41,3 +41,11 @@ func MockMuxVars(vars func(*http.Request) map[string]string) (restore func()) {
muxVars = old
}
}

func MockBuildID(mock string) (restore func()) {
old := buildID
buildID = mock
return func() {
buildID = old
}
}
8 changes: 8 additions & 0 deletions interfaces/export_test.go
Expand Up @@ -51,3 +51,11 @@ func MockIsHomeUsingNFS(new func() (bool, error)) (restore func()) {
isHomeUsingNFS = old
}
}

func MockReadBuildID(mock func(p string) (string, error)) (restore func()) {
old := readBuildID
readBuildID = mock
return func() {
readBuildID = old
}
}
4 changes: 3 additions & 1 deletion interfaces/system_key.go
Expand Up @@ -80,6 +80,8 @@ var (
mockedSystemKey *systemKey

seccompCompilerVersionInfo = seccompCompilerVersionInfoImpl

readBuildID = osutil.ReadBuildID
)

func seccompCompilerVersionInfoImpl(path string) (string, error) {
Expand All @@ -103,7 +105,7 @@ func generateSystemKey() (*systemKey, error) {
if err != nil {
return nil, err
}
buildID, err := osutil.ReadBuildID(snapdPath)
buildID, err := readBuildID(snapdPath)
if err != nil && !os.IsNotExist(err) {
return nil, err
}
Expand Down
29 changes: 22 additions & 7 deletions interfaces/system_key_test.go
Expand Up @@ -60,9 +60,7 @@ func (s *systemKeySuite) SetUpTest(c *C) {
c.Assert(err, IsNil)

s.apparmorFeatures = filepath.Join(s.tmp, "/sys/kernel/security/apparmor/features")
id, err := osutil.MyBuildID()
c.Assert(err, IsNil)
s.buildID = id
s.buildID = "this-is-my-build-id"

s.seccompCompilerVersion = "123 2.3.3 abcdef123 -"
testutil.MockCommand(c, filepath.Join(dirs.DistroLibExecDir, "snap-seccomp"), fmt.Sprintf(`
Expand All @@ -83,6 +81,12 @@ func (s *systemKeySuite) testInterfaceWriteSystemKey(c *C, nfsHome bool) {
restore := interfaces.MockIsHomeUsingNFS(func() (bool, error) { return nfsHome, nil })
defer restore()

restore = interfaces.MockReadBuildID(func(p string) (string, error) {
c.Assert(p, Equals, filepath.Join(dirs.DistroLibExecDir, "snapd"))
return s.buildID, nil
})
defer restore()

err := interfaces.WriteSystemKey()
c.Assert(err, IsNil)

Expand All @@ -104,9 +108,6 @@ func (s *systemKeySuite) testInterfaceWriteSystemKey(c *C, nfsHome bool) {
seccompActionsStr, err := json.Marshal(release.SecCompActions())
c.Assert(err, IsNil)

buildID, err := osutil.ReadBuildID("/proc/self/exe")
c.Assert(err, IsNil)

compiler, err := seccomp_compiler.New(func(name string) (string, error) {
return filepath.Join(dirs.DistroLibExecDir, "snap-seccomp"), nil
})
Expand All @@ -117,7 +118,7 @@ func (s *systemKeySuite) testInterfaceWriteSystemKey(c *C, nfsHome bool) {

overlayRoot, err := osutil.IsRootWritableOverlay()
c.Assert(err, IsNil)
c.Check(string(systemKey), Equals, fmt.Sprintf(`{"version":1,"build-id":"%s","apparmor-features":%s,"apparmor-parser-mtime":%s,"apparmor-parser-features":%s,"nfs-home":%v,"overlay-root":%q,"seccomp-features":%s,"seccomp-compiler-version":"%s"}`, buildID, apparmorFeaturesStr, apparmorParserMtime, apparmorParserFeaturesStr, nfsHome, overlayRoot, seccompActionsStr, seccompCompilerVersion))
c.Check(string(systemKey), Equals, fmt.Sprintf(`{"version":1,"build-id":"%s","apparmor-features":%s,"apparmor-parser-mtime":%s,"apparmor-parser-features":%s,"nfs-home":%v,"overlay-root":%q,"seccomp-features":%s,"seccomp-compiler-version":"%s"}`, s.buildID, apparmorFeaturesStr, apparmorParserMtime, apparmorParserFeaturesStr, nfsHome, overlayRoot, seccompActionsStr, seccompCompilerVersion))
}

func (s *systemKeySuite) TestInterfaceWriteSystemKeyNoNFS(c *C) {
Expand All @@ -128,6 +129,20 @@ func (s *systemKeySuite) TestInterfaceWriteSystemKeyWithNFS(c *C) {
s.testInterfaceWriteSystemKey(c, true)
}

func (s *systemKeySuite) TestInterfaceWriteSystemKeyErrorOnBuildID(c *C) {
restore := interfaces.MockIsHomeUsingNFS(func() (bool, error) { return false, nil })
defer restore()

restore = interfaces.MockReadBuildID(func(p string) (string, error) {
c.Assert(p, Equals, filepath.Join(dirs.DistroLibExecDir, "snapd"))
return "", fmt.Errorf("no build ID for you")
})
defer restore()

err := interfaces.WriteSystemKey()
c.Assert(err, ErrorMatches, "no build ID for you")
}

func (s *systemKeySuite) TestInterfaceSystemKeyMismatchHappy(c *C) {
s.AddCleanup(interfaces.MockSystemKey(`
{
Expand Down