Merge lp:~axwalk/juju-core/upgrade-syslog-port into lp:~go-bot/juju-core/trunk

Proposed by Andrew Wilkins
Status: Merged
Approved by: Ian Booth
Approved revision: no longer in the source branch.
Merged at revision: 2373
Proposed branch: lp:~axwalk/juju-core/upgrade-syslog-port
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 415 lines (+175/-10)
10 files modified
cmd/jujud/machine.go (+19/-3)
cmd/jujud/upgrade_test.go (+32/-0)
testing/testbase/cmd.go (+1/-0)
upgrades/export_test.go (+1/-0)
upgrades/rsyslogport.go (+23/-0)
upgrades/rsyslogport_test.go (+51/-0)
upgrades/steps118.go (+5/-0)
upgrades/steps118_test.go (+1/-0)
upgrades/upgrade.go (+17/-4)
upgrades/upgrade_test.go (+25/-3)
To merge this branch: bzr merge lp:~axwalk/juju-core/upgrade-syslog-port
Reviewer Review Type Date Requested Status
Ian Booth Approve
Review via email: mp+208724@code.launchpad.net

Commit message

upgrades: change syslog-port on upgrade

We upgrade syslog-port to 6514, to work
around a problem with older versions of
rsyslog to do with privileged ports.

There are some incidental changes here:
 - fixed AllMachines handling in upgrades
 - provide *state.State to state server
   upgrade context

https://codereview.appspot.com/69890043/

Description of the change

upgrades: change syslog-port on upgrade

We upgrade syslog-port to 6514, to work
around a problem with older versions of
rsyslog to do with privileged ports.

There are some incidental changes here:
 - fixed AllMachines handling in upgrades
 - provide *state.State to state server
   upgrade context

https://codereview.appspot.com/69890043/

To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote :
Download full text (8.3 KiB)

Reviewers: mp+208724_code.launchpad.net,

Message:
Please take a look.

Description:
upgrades: change syslog-port on upgrade

We upgrade syslog-port to 6514, to work
around a problem with older versions of
rsyslog to do with privileged ports.

There are some incidental changes here:
  - fixed AllMachines handling in upgrades
  - provide *state.State to state server
    upgrade context

https://code.launchpad.net/~axwalk/juju-core/upgrade-syslog-port/+merge/208724

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/69890043/

Affected files (+88, -10 lines):
   A [revision details]
   M cmd/jujud/machine.go
   A upgrades/rsyslogport.go
   M upgrades/steps118.go
   M upgrades/steps118_test.go
   M upgrades/upgrade.go
   M upgrades/upgrade_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: upgrades/rsyslogport.go
=== added file 'upgrades/rsyslogport.go'
--- upgrades/rsyslogport.go 1970-01-01 00:00:00 +0000
+++ upgrades/rsyslogport.go 2014-02-28 04:19:59 +0000
@@ -0,0 +1,20 @@
+// Copyright 2014 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package upgrades
+
+import (
+ "launchpad.net/juju-core/environs/config"
+)
+
+func updateRsyslogPort(context Context) error {
+ st := context.State()
+ old, err := st.EnvironConfig()
+ if err != nil {
+ return err
+ }
+ cfg, err := old.Apply(map[string]interface{}{
+ "syslog-port": config.DefaultSyslogPort,
+ })
+ return st.SetEnvironConfig(cfg, old)
+}

Index: upgrades/steps118.go
=== modified file 'upgrades/steps118.go'
--- upgrades/steps118.go 2014-02-27 08:28:24 +0000
+++ upgrades/steps118.go 2014-02-28 04:19:59 +0000
@@ -17,6 +17,11 @@
     run: ensureSystemSSHKey,
    },
    &upgradeStep{
+ description: "update rsyslog port",
+ targets: []Target{StateServer},
+ run: updateRsyslogPort,
+ },
+ &upgradeStep{
     description: "install rsyslog-gnutls",
     targets: []Target{AllMachines},
     run: installRsyslogGnutls,

Index: upgrades/steps118_test.go
=== modified file 'upgrades/steps118_test.go'
--- upgrades/steps118_test.go 2014-02-27 08:28:24 +0000
+++ upgrades/steps118_test.go 2014-02-28 04:19:59 +0000
@@ -19,6 +19,7 @@
  var expectedSteps = []string{
   "make $DATADIR/locks owned by ubuntu:ubuntu",
   "generate system ssh key",
+ "update rsyslog port",
   "install rsyslog-gnutls",
  }

Index: upgrades/upgrade.go
=== modified file 'upgrades/upgrade.go'
--- upgrades/upgrade.go 2014-02-26 04:21:25 +0000
+++ upgrades/upgrade.go 2014-02-28 04:19:59 +0000
@@ -9,6 +9,7 @@
   "github.com/loggo/loggo"

   "launchpad.net/juju-core/agent"
+ "launchpad.net/juju-core/state"
   "launchpad.net/juju-core/state/api"
   "launchpad.net/juju-core/version"
  )
@@ -78,7 +79,12 @@
   // APIState returns an API connection to state.
   APIState() *api.State

- // AgentConfig returns the agent config for the...

Read more...

Revision history for this message
Ian Booth (wallyworld) wrote :

Looks great but there are missing tests for the rsyslogport upgrade
function as well as for machine agent upgrade in
cmd/jujud/upgrade_test.go

https://codereview.appspot.com/69890043/diff/1/upgrades/rsyslogport.go
File upgrades/rsyslogport.go (right):

https://codereview.appspot.com/69890043/diff/1/upgrades/rsyslogport.go#newcode18
upgrades/rsyslogport.go:18: })
we're missing an error check

https://codereview.appspot.com/69890043/

Revision history for this message
Andrew Wilkins (axwalk) wrote :

Please take a look.

https://codereview.appspot.com/69890043/diff/1/upgrades/rsyslogport.go
File upgrades/rsyslogport.go (right):

https://codereview.appspot.com/69890043/diff/1/upgrades/rsyslogport.go#newcode18
upgrades/rsyslogport.go:18: })
On 2014/02/28 04:43:51, wallyworld wrote:
> we're missing an error check

Done.

https://codereview.appspot.com/69890043/

Revision history for this message
Ian Booth (wallyworld) wrote :
Revision history for this message
Ian Booth (wallyworld) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/jujud/machine.go'
2--- cmd/jujud/machine.go 2014-02-27 14:16:26 +0000
3+++ cmd/jujud/machine.go 2014-02-28 05:45:22 +0000
4@@ -68,6 +68,8 @@
5 MachineId string
6 runner worker.Runner
7 upgradeComplete chan struct{}
8+ stateOpened chan struct{}
9+ st *state.State
10 }
11
12 // Info returns usage information for the command.
13@@ -93,6 +95,7 @@
14 }
15 a.runner = newRunner(isFatal, moreImportant)
16 a.upgradeComplete = make(chan struct{})
17+ a.stateOpened = make(chan struct{})
18 return nil
19 }
20
21@@ -310,6 +313,8 @@
22 if err != nil {
23 return nil, err
24 }
25+ a.st = st
26+ close(a.stateOpened)
27 reportOpenedState(st)
28 m := entity.(*state.Machine)
29
30@@ -413,7 +418,18 @@
31 return nil
32 default:
33 }
34- err := a.runUpgrades(apiState, jobs)
35+ // If the machine agent is a state server, wait until state is opened.
36+ var st *state.State
37+ for _, job := range jobs {
38+ if job == params.JobManageEnviron {
39+ select {
40+ case <-a.stateOpened:
41+ }
42+ st = a.st
43+ break
44+ }
45+ }
46+ err := a.runUpgrades(st, apiState, jobs)
47 if err != nil {
48 return err
49 }
50@@ -425,7 +441,7 @@
51 }
52
53 // runUpgrades runs the upgrade operations for each job type and updates the updatedToVersion on success.
54-func (a *MachineAgent) runUpgrades(st *api.State, jobs []params.MachineJob) error {
55+func (a *MachineAgent) runUpgrades(st *state.State, apiState *api.State, jobs []params.MachineJob) error {
56 agentConfig := a.Conf.config
57 from := version.Current
58 from.Number = agentConfig.UpgradedToVersion()
59@@ -433,7 +449,7 @@
60 logger.Infof("Upgrade to %v already completed.", version.Current)
61 return nil
62 }
63- context := upgrades.NewContext(agentConfig, st)
64+ context := upgrades.NewContext(agentConfig, apiState, st)
65 for _, job := range jobs {
66 var target upgrades.Target
67 switch job {
68
69=== modified file 'cmd/jujud/upgrade_test.go'
70--- cmd/jujud/upgrade_test.go 2014-02-26 05:45:36 +0000
71+++ cmd/jujud/upgrade_test.go 2014-02-28 05:45:22 +0000
72@@ -5,20 +5,24 @@
73
74 import (
75 "os"
76+ "os/exec"
77 "path/filepath"
78
79 gc "launchpad.net/gocheck"
80
81 "launchpad.net/juju-core/agent"
82+ "launchpad.net/juju-core/environs/config"
83 "launchpad.net/juju-core/state"
84 coretesting "launchpad.net/juju-core/testing"
85 jc "launchpad.net/juju-core/testing/checkers"
86+ "launchpad.net/juju-core/utils"
87 "launchpad.net/juju-core/version"
88 )
89
90 type UpgradeSuite struct {
91 commonMachineSuite
92
93+ aptCmds []*exec.Cmd
94 machine *state.Machine
95 upgradeToVersion version.Binary
96 }
97@@ -30,6 +34,15 @@
98 func (s *UpgradeSuite) SetUpTest(c *gc.C) {
99 s.commonMachineSuite.SetUpTest(c)
100
101+ // Capture all apt commands.
102+ s.aptCmds = nil
103+ aptCmds := s.HookCommandOutput(&utils.AptCommandOutput, nil, nil)
104+ go func() {
105+ for cmd := range aptCmds {
106+ s.aptCmds = append(s.aptCmds, cmd)
107+ }
108+ }()
109+
110 // As Juju versions increase, update the version to which we are upgrading.
111 s.upgradeToVersion = version.Current
112 s.upgradeToVersion.Number.Minor++
113@@ -84,17 +97,36 @@
114 return filepath.Join(s.DataDir(), "system-identity")
115 }
116
117+func (s *UpgradeSuite) assertCommonUpgrades(c *gc.C) {
118+ // rsyslog-gnutls should have been installed.
119+ c.Assert(s.aptCmds, gc.HasLen, 1)
120+ args := s.aptCmds[0].Args
121+ c.Assert(len(args), jc.GreaterThan, 1)
122+ c.Assert(args[0], gc.Equals, "apt-get")
123+ c.Assert(args[len(args)-1], gc.Equals, "rsyslog-gnutls")
124+}
125+
126 func (s *UpgradeSuite) assertStateServerUpgrades(c *gc.C) {
127+ s.assertCommonUpgrades(c)
128 // System SSH key
129 c.Assert(s.keyFile(), jc.IsNonEmptyFile)
130+ // Syslog port should have been updated
131+ cfg, err := s.State.EnvironConfig()
132+ c.Assert(err, gc.IsNil)
133+ c.Assert(cfg.SyslogPort(), gc.Equals, config.DefaultSyslogPort)
134 }
135
136 func (s *UpgradeSuite) assertHostUpgrades(c *gc.C) {
137+ s.assertCommonUpgrades(c)
138 // Lock directory
139 lockdir := filepath.Join(s.DataDir(), "locks")
140 c.Assert(lockdir, jc.IsDirectory)
141 // SSH key file should not be generated for hosts.
142 _, err := os.Stat(s.keyFile())
143 c.Assert(err, jc.Satisfies, os.IsNotExist)
144+ // Syslog port should not have been updated
145+ cfg, err := s.State.EnvironConfig()
146+ c.Assert(err, gc.IsNil)
147+ c.Assert(cfg.SyslogPort(), gc.Not(gc.Equals), config.DefaultSyslogPort)
148 // Add other checks as needed...
149 }
150
151=== modified file 'testing/testbase/cmd.go'
152--- testing/testbase/cmd.go 2013-11-15 06:36:39 +0000
153+++ testing/testbase/cmd.go 2014-02-28 05:45:22 +0000
154@@ -17,6 +17,7 @@
155 cmdChan := make(chan *exec.Cmd, 1)
156 origCommandOutput := *outputFunc
157 cleanup := func() {
158+ close(cmdChan)
159 *outputFunc = origCommandOutput
160 }
161 *outputFunc = func(cmd *exec.Cmd) ([]byte, error) {
162
163=== modified file 'upgrades/export_test.go'
164--- upgrades/export_test.go 2014-02-27 03:06:54 +0000
165+++ upgrades/export_test.go 2014-02-28 05:45:22 +0000
166@@ -11,4 +11,5 @@
167 StepsFor118 = stepsFor118
168 EnsureLockDirExistsAndUbuntuWritable = ensureLockDirExistsAndUbuntuWritable
169 EnsureSystemSSHKey = ensureSystemSSHKey
170+ UpdateRsyslogPort = updateRsyslogPort
171 )
172
173=== added file 'upgrades/rsyslogport.go'
174--- upgrades/rsyslogport.go 1970-01-01 00:00:00 +0000
175+++ upgrades/rsyslogport.go 2014-02-28 05:45:22 +0000
176@@ -0,0 +1,23 @@
177+// Copyright 2014 Canonical Ltd.
178+// Licensed under the AGPLv3, see LICENCE file for details.
179+
180+package upgrades
181+
182+import (
183+ "launchpad.net/juju-core/environs/config"
184+)
185+
186+func updateRsyslogPort(context Context) error {
187+ st := context.State()
188+ old, err := st.EnvironConfig()
189+ if err != nil {
190+ return err
191+ }
192+ cfg, err := old.Apply(map[string]interface{}{
193+ "syslog-port": config.DefaultSyslogPort,
194+ })
195+ if err != nil {
196+ return err
197+ }
198+ return st.SetEnvironConfig(cfg, old)
199+}
200
201=== added file 'upgrades/rsyslogport_test.go'
202--- upgrades/rsyslogport_test.go 1970-01-01 00:00:00 +0000
203+++ upgrades/rsyslogport_test.go 2014-02-28 05:45:22 +0000
204@@ -0,0 +1,51 @@
205+// Copyright 2014 Canonical Ltd.
206+// Licensed under the AGPLv3, see LICENCE file for details.
207+
208+package upgrades_test
209+
210+import (
211+ gc "launchpad.net/gocheck"
212+
213+ "launchpad.net/juju-core/environs/config"
214+ jujutesting "launchpad.net/juju-core/juju/testing"
215+ "launchpad.net/juju-core/state"
216+ "launchpad.net/juju-core/upgrades"
217+)
218+
219+type rsyslogPortSuite struct {
220+ jujutesting.JujuConnSuite
221+ ctx upgrades.Context
222+}
223+
224+var _ = gc.Suite(&rsyslogPortSuite{})
225+
226+func (s *rsyslogPortSuite) SetUpTest(c *gc.C) {
227+ s.JujuConnSuite.SetUpTest(c)
228+ apiState, _ := s.OpenAPIAsNewMachine(c, state.JobManageEnviron)
229+ s.ctx = &mockContext{
230+ agentConfig: &mockAgentConfig{dataDir: s.DataDir()},
231+ apiState: apiState,
232+ state: s.State,
233+ }
234+ cfg, err := s.State.EnvironConfig()
235+ c.Assert(err, gc.IsNil)
236+ c.Assert(cfg.SyslogPort(), gc.Not(gc.Equals), config.DefaultSyslogPort)
237+}
238+
239+func (s *rsyslogPortSuite) TestSyslogPortChanged(c *gc.C) {
240+ err := upgrades.UpdateRsyslogPort(s.ctx)
241+ c.Assert(err, gc.IsNil)
242+ cfg, err := s.State.EnvironConfig()
243+ c.Assert(err, gc.IsNil)
244+ c.Assert(cfg.SyslogPort(), gc.Equals, config.DefaultSyslogPort)
245+}
246+
247+func (s *rsyslogPortSuite) TestIdempotent(c *gc.C) {
248+ err := upgrades.UpdateRsyslogPort(s.ctx)
249+ c.Assert(err, gc.IsNil)
250+ err = upgrades.UpdateRsyslogPort(s.ctx)
251+ c.Assert(err, gc.IsNil)
252+ cfg, err := s.State.EnvironConfig()
253+ c.Assert(err, gc.IsNil)
254+ c.Assert(cfg.SyslogPort(), gc.Equals, config.DefaultSyslogPort)
255+}
256
257=== modified file 'upgrades/steps118.go'
258--- upgrades/steps118.go 2014-02-27 08:28:24 +0000
259+++ upgrades/steps118.go 2014-02-28 05:45:22 +0000
260@@ -17,6 +17,11 @@
261 run: ensureSystemSSHKey,
262 },
263 &upgradeStep{
264+ description: "update rsyslog port",
265+ targets: []Target{StateServer},
266+ run: updateRsyslogPort,
267+ },
268+ &upgradeStep{
269 description: "install rsyslog-gnutls",
270 targets: []Target{AllMachines},
271 run: installRsyslogGnutls,
272
273=== modified file 'upgrades/steps118_test.go'
274--- upgrades/steps118_test.go 2014-02-27 08:28:24 +0000
275+++ upgrades/steps118_test.go 2014-02-28 05:45:22 +0000
276@@ -19,6 +19,7 @@
277 var expectedSteps = []string{
278 "make $DATADIR/locks owned by ubuntu:ubuntu",
279 "generate system ssh key",
280+ "update rsyslog port",
281 "install rsyslog-gnutls",
282 }
283
284
285=== modified file 'upgrades/upgrade.go'
286--- upgrades/upgrade.go 2014-02-26 04:21:25 +0000
287+++ upgrades/upgrade.go 2014-02-28 05:45:22 +0000
288@@ -9,6 +9,7 @@
289 "github.com/loggo/loggo"
290
291 "launchpad.net/juju-core/agent"
292+ "launchpad.net/juju-core/state"
293 "launchpad.net/juju-core/state/api"
294 "launchpad.net/juju-core/version"
295 )
296@@ -78,7 +79,12 @@
297 // APIState returns an API connection to state.
298 APIState() *api.State
299
300- // AgentConfig returns the agent config for the machine that is being upgraded.
301+ // State returns a connection to state. This will be non-nil
302+ // only in the context of a state server.
303+ State() *state.State
304+
305+ // AgentConfig returns the agent config for the machine that is being
306+ // upgraded.
307 AgentConfig() agent.Config
308 }
309
310@@ -87,12 +93,18 @@
311 // Work in progress........
312 // Exactly what a context needs is to be determined as the
313 // implementation evolves.
314- st *api.State
315+ api *api.State
316+ st *state.State
317 agentConfig agent.Config
318 }
319
320 // APIState is defined on the Context interface.
321 func (c *upgradeContext) APIState() *api.State {
322+ return c.api
323+}
324+
325+// State is defined on the Context interface.
326+func (c *upgradeContext) State() *state.State {
327 return c.st
328 }
329
330@@ -102,8 +114,9 @@
331 }
332
333 // NewContext returns a new upgrade context.
334-func NewContext(agentConfig agent.Config, st *api.State) Context {
335+func NewContext(agentConfig agent.Config, api *api.State, st *state.State) Context {
336 return &upgradeContext{
337+ api: api,
338 st: st,
339 agentConfig: agentConfig,
340 }
341@@ -146,7 +159,7 @@
342 // validTarget returns true if target is in step.Targets().
343 func validTarget(target Target, step Step) bool {
344 for _, opTarget := range step.Targets() {
345- if target == AllMachines || target == opTarget {
346+ if opTarget == AllMachines || target == opTarget {
347 return true
348 }
349 }
350
351=== modified file 'upgrades/upgrade_test.go'
352--- upgrades/upgrade_test.go 2014-02-20 01:09:59 +0000
353+++ upgrades/upgrade_test.go 2014-02-28 05:45:22 +0000
354@@ -11,6 +11,7 @@
355 gc "launchpad.net/gocheck"
356
357 "launchpad.net/juju-core/agent"
358+ "launchpad.net/juju-core/state"
359 "launchpad.net/juju-core/state/api"
360 coretesting "launchpad.net/juju-core/testing"
361 jc "launchpad.net/juju-core/testing/checkers"
362@@ -78,12 +79,17 @@
363 messages []string
364 agentConfig *mockAgentConfig
365 apiState *api.State
366+ state *state.State
367 }
368
369 func (c *mockContext) APIState() *api.State {
370 return c.apiState
371 }
372
373+func (c *mockContext) State() *state.State {
374+ return c.state
375+}
376+
377 func (c *mockContext) AgentConfig() agent.Config {
378 return c.agentConfig
379 }
380@@ -160,6 +166,14 @@
381 &mockUpgradeStep{"step 2 - 1.18.0", targets(upgrades.StateServer)},
382 },
383 },
384+ &mockUpgradeOperation{
385+ targetVersion: version.MustParse("1.20.0"),
386+ steps: []upgrades.Step{
387+ &mockUpgradeStep{"step 1 - 1.20.0", targets(upgrades.AllMachines)},
388+ &mockUpgradeStep{"step 2 - 1.20.0", targets(upgrades.HostMachine)},
389+ &mockUpgradeStep{"step 3 - 1.20.0", targets(upgrades.StateServer)},
390+ },
391+ },
392 }
393 return steps
394 }
395@@ -200,9 +214,17 @@
396 },
397 {
398 about: "allMachines matches everything",
399- fromVersion: "1.17.1",
400- target: upgrades.AllMachines,
401- expectedSteps: []string{"step 1 - 1.18.0", "step 2 - 1.18.0"},
402+ fromVersion: "1.18.1",
403+ toVersion: "1.20.0",
404+ target: upgrades.HostMachine,
405+ expectedSteps: []string{"step 1 - 1.20.0", "step 2 - 1.20.0"},
406+ },
407+ {
408+ about: "allMachines matches everything",
409+ fromVersion: "1.18.1",
410+ toVersion: "1.20.0",
411+ target: upgrades.StateServer,
412+ expectedSteps: []string{"step 1 - 1.20.0", "step 3 - 1.20.0"},
413 },
414 {
415 about: "error aborts, subsequent steps not run",

Subscribers

People subscribed via source and target branches

to status/vote changes: