Skip to content

Commit

Permalink
Don't use MustHostSeries and MustOSFromSeries to avoid panic on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoyt committed Nov 19, 2020
1 parent 5bd6bb4 commit 3bf1a33
Show file tree
Hide file tree
Showing 95 changed files with 403 additions and 702 deletions.
11 changes: 5 additions & 6 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/os/series"
"github.com/juju/utils"
"github.com/juju/utils/shell"
"github.com/juju/version"
Expand All @@ -43,11 +42,11 @@ const (

// These are base values used for the corresponding defaults.
var (
logDir = paths.MustSucceed(paths.LogDir(series.MustHostSeries()))
dataDir = paths.MustSucceed(paths.DataDir(series.MustHostSeries()))
transientDataDir = paths.MustSucceed(paths.TransientDataDir(series.MustHostSeries()))
confDir = paths.MustSucceed(paths.ConfDir(series.MustHostSeries()))
metricsSpoolDir = paths.MustSucceed(paths.MetricsSpoolDir(series.MustHostSeries()))
logDir = paths.LogDir(paths.CurrentOS())
dataDir = paths.DataDir(paths.CurrentOS())
transientDataDir = paths.TransientDataDir(paths.CurrentOS())
confDir = paths.ConfDir(paths.CurrentOS())
metricsSpoolDir = paths.MetricsSpoolDir(paths.CurrentOS())
)

// Agent exposes the agent's configuration to other components. This
Expand Down
3 changes: 1 addition & 2 deletions agent/agentbootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"

"github.com/juju/names/v4"
"github.com/juju/os/series"
gitjujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils"
Expand Down Expand Up @@ -280,7 +279,7 @@ LXC_BRIDGE="ignored"`[1:])
c.Assert(err, jc.ErrorIsNil)
c.Assert(m.Id(), gc.Equals, "0")
c.Assert(m.Jobs(), gc.DeepEquals, []state.MachineJob{state.JobManageModel})
c.Assert(m.Series(), gc.Equals, series.MustHostSeries())
c.Assert(m.Series(), gc.Equals, testing.HostSeries(c))
c.Assert(m.CheckProvisioned(agent.BootstrapNonce), jc.IsTrue)
c.Assert(m.Addresses(), jc.DeepEquals, filteredAddrs)
gotBootstrapConstraints, err := m.Constraints()
Expand Down
11 changes: 2 additions & 9 deletions agent/tools/symlinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ import (
"path/filepath"
"time"

"github.com/juju/os/series"
"github.com/juju/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils"
"github.com/juju/utils/arch"
"github.com/juju/utils/symlink"
"github.com/juju/version"
gc "gopkg.in/check.v1"

"github.com/juju/juju/agent/tools"
"github.com/juju/juju/juju/names"
jujuversion "github.com/juju/juju/version"
)

type SymlinksSuite struct {
Expand All @@ -30,11 +27,7 @@ var _ = gc.Suite(&SymlinksSuite{})

func (s *SymlinksSuite) SetUpTest(c *gc.C) {
s.dataDir = c.MkDir()
s.toolsDir = tools.SharedToolsDir(s.dataDir, version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.MustHostSeries(),
})
s.toolsDir = tools.SharedToolsDir(s.dataDir, testing.CurrentVersion(c))
err := os.MkdirAll(s.toolsDir, 0755)
c.Assert(err, jc.ErrorIsNil)
c.Logf("created %s", s.toolsDir)
Expand Down
3 changes: 1 addition & 2 deletions api/certpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import (
"path/filepath"

"github.com/juju/errors"
"github.com/juju/os/series"
"github.com/juju/utils/cert"

"github.com/juju/juju/core/paths"
)

var certDir = filepath.FromSlash(paths.MustSucceed(paths.CertDir(series.MustHostSeries())))
var certDir = filepath.FromSlash(paths.CertDir(paths.CurrentOS()))

// CreateCertPool creates a new x509.CertPool and adds in the caCert passed
// in. All certs from the cert directory (/etc/juju/cert.d on ubuntu) are
Expand Down
12 changes: 3 additions & 9 deletions api/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import (
"github.com/golang/mock/gomock"
"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/juju/os/series"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils"
"github.com/juju/utils/arch"
"github.com/juju/version"
gc "gopkg.in/check.v1"

"github.com/juju/juju/api"
Expand Down Expand Up @@ -786,11 +784,7 @@ func (s *provisionerSuite) TestFindToolsLogicError(c *gc.C) {
}

func (s *provisionerSuite) testFindTools(c *gc.C, matchArch bool, apiError, logicError error) {
current := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.MustHostSeries(),
}
current := coretesting.CurrentVersion(c)
var toolsList = coretools.List{&coretools.Tools{Version: current}}
var called bool
var a string
Expand All @@ -805,7 +799,7 @@ func (s *provisionerSuite) testFindTools(c *gc.C, matchArch bool, apiError, logi
c.Assert(request, gc.Equals, "FindTools")
expected := params.FindToolsParams{
Number: jujuversion.Current,
Series: series.MustHostSeries(),
Series: current.Series,
Arch: a,
MinorVersion: -1,
MajorVersion: -1,
Expand All @@ -818,7 +812,7 @@ func (s *provisionerSuite) testFindTools(c *gc.C, matchArch bool, apiError, logi
}
return apiError
})
apiList, err := s.provisioner.FindTools(jujuversion.Current, series.MustHostSeries(), a)
apiList, err := s.provisioner.FindTools(jujuversion.Current, current.Series, a)
c.Assert(called, jc.IsTrue)
if apiError != nil {
c.Assert(err, gc.Equals, apiError)
Expand Down
17 changes: 6 additions & 11 deletions api/upgrader/unitupgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ package upgrader_test

import (
"github.com/juju/errors"
"github.com/juju/os/series"
"github.com/juju/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils"
"github.com/juju/utils/arch"
"github.com/juju/version"
gc "gopkg.in/check.v1"

Expand All @@ -19,7 +18,6 @@ import (
jujutesting "github.com/juju/juju/juju/testing"
"github.com/juju/juju/state"
"github.com/juju/juju/tools"
jujuversion "github.com/juju/juju/version"
)

type unitUpgraderSuite struct {
Expand All @@ -37,12 +35,6 @@ type unitUpgraderSuite struct {

var _ = gc.Suite(&unitUpgraderSuite{})

var current = version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.MustHostSeries(),
}

func (s *unitUpgraderSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)

Expand Down Expand Up @@ -73,18 +65,19 @@ func (s *unitUpgraderSuite) addMachineApplicationCharmAndUnit(c *gc.C, appName s
}

func (s *unitUpgraderSuite) TestSetVersionWrongUnit(c *gc.C) {
err := s.st.SetVersion("unit-wordpress-42", current)
err := s.st.SetVersion("unit-wordpress-42", testing.CurrentVersion(c))
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *unitUpgraderSuite) TestSetVersionNotUnit(c *gc.C) {
err := s.st.SetVersion("foo-42", current)
err := s.st.SetVersion("foo-42", testing.CurrentVersion(c))
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *unitUpgraderSuite) TestSetVersion(c *gc.C) {
current := testing.CurrentVersion(c)
agentTools, err := s.rawUnit.AgentTools()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Assert(agentTools, gc.IsNil)
Expand All @@ -111,6 +104,7 @@ func (s *unitUpgraderSuite) TestToolsNotUnit(c *gc.C) {
}

func (s *unitUpgraderSuite) TestTools(c *gc.C) {
current := testing.CurrentVersion(c)
curTools := &tools.Tools{Version: current, URL: ""}
curTools.Version.Minor++
s.rawMachine.SetAgentVersion(current)
Expand Down Expand Up @@ -157,6 +151,7 @@ func (s *unitUpgraderSuite) TestWatchAPIVersionNotUnit(c *gc.C) {
}

func (s *unitUpgraderSuite) TestDesiredVersion(c *gc.C) {
current := testing.CurrentVersion(c)
curTools := &tools.Tools{Version: current, URL: ""}
curTools.Version.Minor++
s.rawMachine.SetAgentVersion(current)
Expand Down
7 changes: 5 additions & 2 deletions api/upgrader/upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ func (s *machineUpgraderSuite) TestNew(c *gc.C) {
}

func (s *machineUpgraderSuite) TestSetVersionWrongMachine(c *gc.C) {
err := s.st.SetVersion("machine-42", current)
err := s.st.SetVersion("machine-42", coretesting.CurrentVersion(c))
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *machineUpgraderSuite) TestSetVersionNotMachine(c *gc.C) {
err := s.st.SetVersion("foo-42", current)
err := s.st.SetVersion("foo-42", coretesting.CurrentVersion(c))
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *machineUpgraderSuite) TestSetVersion(c *gc.C) {
current := coretesting.CurrentVersion(c)
agentTools, err := s.rawMachine.AgentTools()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Assert(agentTools, gc.IsNil)
Expand All @@ -90,6 +91,7 @@ func (s *machineUpgraderSuite) TestToolsNotMachine(c *gc.C) {
}

func (s *machineUpgraderSuite) TestTools(c *gc.C) {
current := coretesting.CurrentVersion(c)
curTools := &tools.Tools{Version: current, URL: ""}
curTools.Version.Minor++
s.rawMachine.SetAgentVersion(current)
Expand Down Expand Up @@ -133,6 +135,7 @@ func (s *machineUpgraderSuite) TestWatchAPIVersion(c *gc.C) {
}

func (s *machineUpgraderSuite) TestDesiredVersion(c *gc.C) {
current := coretesting.CurrentVersion(c)
curTools := &tools.Tools{Version: current, URL: ""}
curTools.Version.Minor++
s.rawMachine.SetAgentVersion(current)
Expand Down
23 changes: 11 additions & 12 deletions apiserver/common/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/juju/juju/state"
"github.com/juju/juju/state/binarystorage"
"github.com/juju/juju/state/stateenvirons"
coretesting "github.com/juju/juju/testing"
coretools "github.com/juju/juju/tools"
jujuversion "github.com/juju/juju/version"
)
Expand All @@ -34,12 +35,6 @@ type toolsSuite struct {

var _ = gc.Suite(&toolsSuite{})

var current = version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.MustHostSeries(),
}

func (s *toolsSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
var err error
Expand All @@ -63,6 +58,7 @@ func (s *toolsSuite) TestTools(c *gc.C) {
)
c.Assert(tg, gc.NotNil)

current := coretesting.CurrentVersion(c)
err := s.machine0.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)

Expand Down Expand Up @@ -113,6 +109,7 @@ func (s *toolsSuite) TestSetTools(c *gc.C) {
ts := common.NewToolsSetter(s.State, getCanWrite)
c.Assert(ts, gc.NotNil)

current := coretesting.CurrentVersion(c)
err := s.machine0.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)

Expand Down Expand Up @@ -154,7 +151,7 @@ func (s *toolsSuite) TestToolsSetError(c *gc.C) {
AgentTools: []params.EntityVersion{{
Tag: "machine-42",
Tools: &params.Version{
Version: current,
Version: coretesting.CurrentVersion(c),
},
}},
}
Expand Down Expand Up @@ -250,7 +247,7 @@ func (s *toolsSuite) TestFindToolsExactInStorage(c *gc.C) {
}

s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
s.PatchValue(&series.MustHostSeries, func() string { return "trusty" })
s.PatchValue(&series.HostSeries, func() (string, error) { return "trusty", nil })
s.PatchValue(&jujuversion.Current, version.MustParseBinary("1.22-beta1-trusty-amd64").Number)
s.testFindToolsExact(c, mockToolsStorage, true, true)
s.PatchValue(&jujuversion.Current, version.MustParseBinary("1.22.0-trusty-amd64").Number)
Expand All @@ -267,10 +264,11 @@ func (s *toolsSuite) TestFindToolsExactNotInStorage(c *gc.C) {

func (s *toolsSuite) testFindToolsExact(c *gc.C, t common.ToolsStorageGetter, inStorage bool, develVersion bool) {
var called bool
current := coretesting.CurrentVersion(c)
s.PatchValue(common.EnvtoolsFindTools, func(e environs.BootstrapEnviron, major, minor int, stream []string, filter coretools.Filter) (list coretools.List, err error) {
called = true
c.Assert(filter.Number, gc.Equals, jujuversion.Current)
c.Assert(filter.Series, gc.Equals, series.MustHostSeries())
c.Assert(filter.Series, gc.Equals, current.Series)
c.Assert(filter.Arch, gc.Equals, arch.HostArch())
if develVersion {
c.Assert(stream, gc.DeepEquals, []string{"devel", "proposed", "released"})
Expand All @@ -287,7 +285,7 @@ func (s *toolsSuite) testFindToolsExact(c *gc.C, t common.ToolsStorageGetter, in
Number: jujuversion.Current,
MajorVersion: -1,
MinorVersion: -1,
Series: series.MustHostSeries(),
Series: current.Series,
Arch: arch.HostArch(),
})
c.Assert(err, jc.ErrorIsNil)
Expand Down Expand Up @@ -326,13 +324,13 @@ func (s *toolsSuite) TestFindToolsToolsStorageError(c *gc.C) {

func (s *toolsSuite) TestToolsURLGetterNoAPIHostPorts(c *gc.C) {
g := common.NewToolsURLGetter("my-uuid", mockAPIHostPortsGetter{})
_, err := g.ToolsURLs(current)
_, err := g.ToolsURLs(coretesting.CurrentVersion(c))
c.Assert(err, gc.ErrorMatches, "no suitable API server address to pick from")
}

func (s *toolsSuite) TestToolsURLGetterAPIHostPortsError(c *gc.C) {
g := common.NewToolsURLGetter("my-uuid", mockAPIHostPortsGetter{err: errors.New("oh noes")})
_, err := g.ToolsURLs(current)
_, err := g.ToolsURLs(coretesting.CurrentVersion(c))
c.Assert(err, gc.ErrorMatches, "oh noes")
}

Expand All @@ -342,6 +340,7 @@ func (s *toolsSuite) TestToolsURLGetter(c *gc.C) {
network.NewSpaceHostPorts(1234, "0.1.2.3"),
},
})
current := coretesting.CurrentVersion(c)
urls, err := g.ToolsURLs(current)
c.Assert(err, jc.ErrorIsNil)
c.Check(urls, jc.DeepEquals, []string{
Expand Down
Loading

0 comments on commit 3bf1a33

Please sign in to comment.