Skip to content

Commit

Permalink
version: make version.Current a version.Number
Browse files Browse the repository at this point in the history
This PR converts version.Current to a type version.Number. The values
previously captured by version.Current, namely the host's architecture
and series, are available via their respective helpers, arch.HostArch and
series.HostSeries.
  • Loading branch information
davecheney committed Oct 26, 2015
1 parent 39d0a1d commit 56bf73e
Show file tree
Hide file tree
Showing 87 changed files with 805 additions and 466 deletions.
42 changes: 21 additions & 21 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
},
checkErr: "password not found in configuration",
}, {
about: "missing environment tag",
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
},
checkErr: "environment not found in configuration",
Expand All @@ -72,7 +72,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
Environment: names.NewEnvironTag("uuid"),
},
Expand All @@ -82,7 +82,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
Environment: testing.EnvironmentTag,
},
Expand All @@ -92,7 +92,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Expand All @@ -103,7 +103,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Expand All @@ -115,7 +115,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Expand All @@ -127,7 +127,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Expand All @@ -138,7 +138,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Expand All @@ -149,7 +149,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Expand All @@ -162,7 +162,7 @@ var agentConfigTests = []struct {
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
StateAddresses: []string{"localhost:1234"},
Expand All @@ -175,7 +175,7 @@ var agentConfigTests = []struct {
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
StateAddresses: []string{"localhost:1234"},
Expand All @@ -191,7 +191,7 @@ var agentConfigTests = []struct {
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
StateAddresses: []string{"localhost:1234"},
Expand All @@ -210,7 +210,7 @@ var agentConfigTests = []struct {
},
Tag: names.NewMachineTag("1"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
StateAddresses: []string{"localhost:1234"},
Expand All @@ -225,7 +225,7 @@ var agentConfigTests = []struct {
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewUserTag("admin"), // this is a joke, the admin user is nil.
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
},
checkErr: "entity tag must be MachineTag or UnitTag, got names.UserTag",
Expand All @@ -235,7 +235,7 @@ var agentConfigTests = []struct {
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewUnitTag("ubuntu/1"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Environment: testing.EnvironmentTag,
CACert: "ca cert",
StateAddresses: []string{"localhost:1234"},
Expand All @@ -250,7 +250,7 @@ var agentConfigTests = []struct {
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
StateAddresses: []string{"localhost:1234"},
Expand All @@ -267,7 +267,7 @@ var agentConfigTests = []struct {
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
StateAddresses: []string{"localhost:1234"},
Expand Down Expand Up @@ -506,7 +506,7 @@ var attributeParams = agent.AgentConfigParams{
DataDir: "/data/dir",
},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
StateAddresses: []string{"localhost:1234"},
Expand All @@ -525,7 +525,7 @@ func (*suite) TestAttributes(c *gc.C) {
c.Assert(conf.Tag(), gc.Equals, names.NewMachineTag("1"))
c.Assert(conf.Dir(), gc.Equals, "/data/dir/agents/machine-1")
c.Assert(conf.Nonce(), gc.Equals, "a nonce")
c.Assert(conf.UpgradedToVersion(), jc.DeepEquals, version.Current.Number)
c.Assert(conf.UpgradedToVersion(), jc.DeepEquals, version.Current)
}

func (*suite) TestStateServingInfo(c *gc.C) {
Expand Down Expand Up @@ -723,7 +723,7 @@ func (*suite) TestSetUpgradedToVersion(c *gc.C) {
conf, err := agent.NewAgentConfig(attributeParams)
c.Assert(err, jc.ErrorIsNil)

c.Assert(conf.UpgradedToVersion(), gc.Equals, version.Current.Number)
c.Assert(conf.UpgradedToVersion(), gc.Equals, version.Current)

expectVers := version.MustParse("3.4.5")
conf.SetUpgradedToVersion(expectVers)
Expand Down
10 changes: 5 additions & 5 deletions agent/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ LXC_BRIDGE="ignored"`[1:])
configParams := agent.AgentConfigParams{
Paths: agent.Paths{DataDir: dataDir},
Tag: names.NewMachineTag("0"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
StateAddresses: []string{s.mgoInst.Addr()},
CACert: testing.CACert,
Password: pwHash,
Expand Down Expand Up @@ -136,7 +136,7 @@ LXC_BRIDGE="ignored"`[1:])
filteredAddrs = append([]network.Address{}, initialAddrs...)
}
envAttrs := dummy.SampleConfig().Delete("admin-secret").Merge(testing.Attrs{
"agent-version": version.Current.Number.String(),
"agent-version": version.Current.String(),
"state-id": "1", // needed so policy can Open config
})
envCfg, err := config.New(config.NoDefaults, envAttrs)
Expand Down Expand Up @@ -222,7 +222,7 @@ func (s *bootstrapSuite) TestInitializeStateWithStateServingInfoNotAvailable(c *
configParams := agent.AgentConfigParams{
Paths: agent.Paths{DataDir: c.MkDir()},
Tag: names.NewMachineTag("0"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
StateAddresses: []string{s.mgoInst.Addr()},
CACert: testing.CACert,
Password: "fake",
Expand All @@ -247,7 +247,7 @@ func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
configParams := agent.AgentConfigParams{
Paths: agent.Paths{DataDir: dataDir},
Tag: names.NewMachineTag("0"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
StateAddresses: []string{s.mgoInst.Addr()},
CACert: testing.CACert,
Password: pwHash,
Expand All @@ -272,7 +272,7 @@ func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
Characteristics: expectHW,
}
envAttrs := dummy.SampleConfig().Delete("admin-secret").Merge(testing.Attrs{
"agent-version": version.Current.Number.String(),
"agent-version": version.Current.String(),
"state-id": "1", // needed so policy can Open config
})
envCfg, err := config.New(config.NoDefaults, envAttrs)
Expand Down
2 changes: 1 addition & 1 deletion agent/format_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = gc.Suite(&formatSuite{})
// located here for easy reuse.
var agentParams = AgentConfigParams{
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
Password: "sekrit",
CACert: "ca cert",
Expand Down
2 changes: 1 addition & 1 deletion agent/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = gc.Suite(&identitySuite{})

var attributeParams = AgentConfigParams{
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current.Number,
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
StateAddresses: []string{"localhost:1234"},
Expand Down
2 changes: 1 addition & 1 deletion api/apiclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *apiclientSuite) TestOpen(c *gc.C) {

remoteVersion, versionSet := st.ServerVersion()
c.Assert(versionSet, jc.IsTrue)
c.Assert(remoteVersion, gc.Equals, version.Current.Number)
c.Assert(remoteVersion, gc.Equals, version.Current)
}

func (s *apiclientSuite) TestOpenHonorsEnvironTag(c *gc.C) {
Expand Down
11 changes: 8 additions & 3 deletions api/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,12 @@ func (s *provisionerSuite) TestFindToolsLogicError(c *gc.C) {
}

func (s *provisionerSuite) testFindTools(c *gc.C, matchArch bool, apiError, logicError error) {
var toolsList = coretools.List{&coretools.Tools{Version: version.Current}}
current := version.Binary{
Number: version.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
var toolsList = coretools.List{&coretools.Tools{Version: current}}
var called bool
var a string
if matchArch {
Expand All @@ -819,7 +824,7 @@ func (s *provisionerSuite) testFindTools(c *gc.C, matchArch bool, apiError, logi
called = true
c.Assert(request, gc.Equals, "FindTools")
expected := params.FindToolsParams{
Number: version.Current.Number,
Number: version.Current,
Series: series.HostSeries(),
Arch: a,
MinorVersion: -1,
Expand All @@ -833,7 +838,7 @@ func (s *provisionerSuite) testFindTools(c *gc.C, matchArch bool, apiError, logi
}
return apiError
})
apiList, err := s.provisioner.FindTools(version.Current.Number, series.HostSeries(), a)
apiList, err := s.provisioner.FindTools(version.Current, series.HostSeries(), a)
c.Assert(called, jc.IsTrue)
if apiError != nil {
c.Assert(err, gc.Equals, apiError)
Expand Down
31 changes: 18 additions & 13 deletions api/upgrader/unitupgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils"
"github.com/juju/utils/arch"
"github.com/juju/utils/series"
gc "gopkg.in/check.v1"

"github.com/juju/juju/api"
Expand Down Expand Up @@ -34,6 +36,12 @@ type unitUpgraderSuite struct {

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

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

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

Expand Down Expand Up @@ -62,28 +70,27 @@ func (s *unitUpgraderSuite) addMachineServiceCharmAndUnit(c *gc.C, serviceName s
}

func (s *unitUpgraderSuite) TestSetVersionWrongUnit(c *gc.C) {
err := s.st.SetVersion("unit-wordpress-42", version.Current)
err := s.st.SetVersion("unit-wordpress-42", current)
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", version.Current)
err := s.st.SetVersion("foo-42", current)
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *unitUpgraderSuite) TestSetVersion(c *gc.C) {
cur := version.Current
agentTools, err := s.rawUnit.AgentTools()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Assert(agentTools, gc.IsNil)
err = s.st.SetVersion(s.rawUnit.Tag().String(), cur)
err = s.st.SetVersion(s.rawUnit.Tag().String(), current)
c.Assert(err, jc.ErrorIsNil)
s.rawUnit.Refresh()
agentTools, err = s.rawUnit.AgentTools()
c.Assert(err, jc.ErrorIsNil)
c.Check(agentTools.Version, gc.Equals, cur)
c.Check(agentTools.Version, gc.Equals, current)
}

func (s *unitUpgraderSuite) TestToolsWrongUnit(c *gc.C) {
Expand All @@ -101,15 +108,14 @@ func (s *unitUpgraderSuite) TestToolsNotUnit(c *gc.C) {
}

func (s *unitUpgraderSuite) TestTools(c *gc.C) {
cur := version.Current
curTools := &tools.Tools{Version: cur, URL: ""}
curTools := &tools.Tools{Version: current, URL: ""}
curTools.Version.Minor++
s.rawMachine.SetAgentVersion(cur)
s.rawMachine.SetAgentVersion(current)
// UnitUpgrader.Tools returns the *desired* set of tools, not the currently
// running set. We want to be upgraded to cur.Version
stateTools, err := s.st.Tools(s.rawUnit.Tag().String())
c.Assert(err, jc.ErrorIsNil)
c.Check(stateTools.Version.Number, gc.DeepEquals, version.Current.Number)
c.Check(stateTools.Version.Number, gc.DeepEquals, current.Number)
c.Assert(stateTools.URL, gc.NotNil)
}

Expand Down Expand Up @@ -146,15 +152,14 @@ func (s *unitUpgraderSuite) TestWatchAPIVersionNotUnit(c *gc.C) {
}

func (s *unitUpgraderSuite) TestDesiredVersion(c *gc.C) {
cur := version.Current
curTools := &tools.Tools{Version: cur, URL: ""}
curTools := &tools.Tools{Version: current, URL: ""}
curTools.Version.Minor++
s.rawMachine.SetAgentVersion(cur)
s.rawMachine.SetAgentVersion(current)
// UnitUpgrader.DesiredVersion returns the *desired* set of tools, not the
// currently running set. We want to be upgraded to cur.Version
stateVersion, err := s.st.DesiredVersion(s.rawUnit.Tag().String())
c.Assert(err, jc.ErrorIsNil)
c.Assert(stateVersion, gc.Equals, cur.Number)
c.Assert(stateVersion, gc.Equals, current.Number)
}

func (s *unitUpgraderSuite) TestDesiredVersionWrongUnit(c *gc.C) {
Expand Down
Loading

0 comments on commit 56bf73e

Please sign in to comment.