summaryrefslogtreecommitdiff
diff options
authorFederico Gimenez <fgimenez@canonical.com>2016-02-24 10:28:10 +0100
committerFederico Gimenez <fgimenez@canonical.com>2016-02-25 09:32:19 +0100
commit71bea7a2f32c73053e3dd461557fafbdaec91e18 (patch)
treee75c31a8be1a908de470ae6385e0eb133dc03317
parent6305a9c4c41cff9420a435655a9e771533eb01ea (diff)
integration-tests: always use the built snapd when compiling binaries from branch
The commands for shutting down the system's snapd and setting up the compiled one are moved from the snapdSuite SetUpTest method to the init() function of the tests package (this way it gets executed once per boot) and it's only set up if we are generating the binaries from the current branch. The previous call to kill the process has been removed, we could keep it in the Test function after the runner.TestingT(t, output) call, but in fact it wasn't stopping the daemon forked by systemd-activate, the process being killed was the parent. This will be handled in an upcoming branch.
-rw-r--r--integration-tests/tests/base_test.go35
-rw-r--r--integration-tests/tests/snapd_test.go22
2 files changed, 34 insertions, 23 deletions
diff --git a/integration-tests/tests/base_test.go b/integration-tests/tests/base_test.go
index b69e5acd22..310082df24 100644
--- a/integration-tests/tests/base_test.go
+++ b/integration-tests/tests/base_test.go
@@ -2,7 +2,7 @@
// +build !excludeintegration
/*
- * Copyright (C) 2015 Canonical Ltd
+ * Copyright (C) 2015, 2016 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
@@ -23,17 +23,22 @@ package tests
import (
"io"
"os"
+ "os/exec"
+ "path/filepath"
"testing"
"gopkg.in/check.v1"
"github.com/ubuntu-core/snappy/integration-tests/testutils/cli"
+ "github.com/ubuntu-core/snappy/integration-tests/testutils/config"
"github.com/ubuntu-core/snappy/integration-tests/testutils/partition"
"github.com/ubuntu-core/snappy/integration-tests/testutils/report"
"github.com/ubuntu-core/snappy/integration-tests/testutils/runner"
"github.com/ubuntu-core/snappy/integration-tests/testutils/wait"
)
+var daemonCmd *exec.Cmd
+
func init() {
c := &check.C{}
// Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293
@@ -44,6 +49,13 @@ func init() {
cli.ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer")
cli.ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")
+
+ cfg, err := config.ReadConfig(config.DefaultFileName)
+ c.Assert(err, check.IsNil, check.Commentf("Error reading config: %v", err))
+
+ if cfg.FromBranch {
+ setUpSnapdFromBranch(c)
+ }
}
// Hook up gocheck into the "go test" runner.
@@ -53,3 +65,24 @@ func Test(t *testing.T) {
report.NewSubunitV2ParserReporter(&report.FileReporter{}))
runner.TestingT(t, output)
}
+
+func setUpSnapdFromBranch(c *check.C) {
+ if daemonCmd == nil {
+ trustedKey, err := filepath.Abs("integration-tests/data/trusted.acckey")
+ c.Assert(err, check.IsNil)
+
+ cli.ExecCommand(c, "sudo", "systemctl", "stop",
+ "ubuntu-snappy.snapd.service", "ubuntu-snappy.snapd.socket")
+
+ // FIXME: for now pass a test-only trusted key through an env var
+ daemonCmd = exec.Command("sudo", "env", "PATH="+os.Getenv("PATH"),
+ "SNAPPY_TRUSTED_ACCOUNT_KEY="+trustedKey,
+ "/lib/systemd/systemd-activate", "--setenv=SNAPPY_TRUSTED_ACCOUNT_KEY",
+ "-l", "/run/snapd.socket", "snapd")
+
+ err = daemonCmd.Start()
+ c.Assert(err, check.IsNil)
+
+ wait.ForCommand(c, `^$`, "sudo", "chmod", "0666", "/run/snapd.socket")
+ }
+}
diff --git a/integration-tests/tests/snapd_test.go b/integration-tests/tests/snapd_test.go
index b2e7416ed6..123f7c1fbc 100644
--- a/integration-tests/tests/snapd_test.go
+++ b/integration-tests/tests/snapd_test.go
@@ -50,34 +50,12 @@ type snapdTestSuite struct {
func (s *snapdTestSuite) SetUpTest(c *check.C) {
s.SnappySuite.SetUpTest(c)
- trustedKey, err := filepath.Abs("integration-tests/data/trusted.acckey")
- c.Assert(err, check.IsNil)
-
- cli.ExecCommand(c, "sudo", "systemctl", "stop",
- "ubuntu-snappy.snapd.service", "ubuntu-snappy.snapd.socket")
-
- // FIXME: for now pass a test-only trusted key through an env var
- s.cmd = exec.Command("sudo", "env", "PATH="+os.Getenv("PATH"),
- "SNAPPY_TRUSTED_ACCOUNT_KEY="+trustedKey,
- "/lib/systemd/systemd-activate", "--setenv=SNAPPY_TRUSTED_ACCOUNT_KEY",
- "-l", "/run/snapd.socket", "snapd")
-
- err = s.cmd.Start()
- c.Assert(err, check.IsNil)
-
- wait.ForCommand(c, `^$`, "sudo", "chmod", "0666", "/run/snapd.socket")
common.InstallSnap(c, httpClientSnap+"/edge")
}
func (s *snapdTestSuite) TearDownTest(c *check.C) {
s.SnappySuite.TearDownTest(c)
- proc := s.cmd.Process
- if proc != nil {
- proc.Kill()
- }
- cli.ExecCommand(c, "sudo", "systemctl", "start", "ubuntu-snappy.snapd.socket")
-
common.RemoveSnap(c, httpClientSnap)
}