Merge lp:~waigani/juju-core/lxc-autorestart-setting into lp:~go-bot/juju-core/trunk

Proposed by Jesse Meek
Status: Work in progress
Proposed branch: lp:~waigani/juju-core/lxc-autorestart-setting
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~waigani/juju-core/managers-should-warn-for-any-unknown-options
Diff against target: 148 lines (+60/-5)
4 files modified
container/lxc/lxc.go (+15/-2)
container/lxc/lxc_test.go (+39/-3)
provider/local/config.go (+5/-0)
provider/local/environ.go (+1/-0)
To merge this branch: bzr merge lp:~waigani/juju-core/lxc-autorestart-setting
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+210117@code.launchpad.net

Description of the change

LXC AutoRestart Setting

lxc.containerManager gains “autorestart bool”,
and sets that from container.ManagerConfig, if
not in container.ManagerConfig, then manager
default is true.

https://codereview.appspot.com/73390043/

To post a comment you must log in.
Revision history for this message
Jesse Meek (waigani) wrote :

Reviewers: mp+210117_code.launchpad.net,

Message:
Please take a look.

Description:
LXC AutoRestart Setting

lxc.containerManager gains "autorestart bool",
and sets that from container.ManagerConfig, if
not in container.ManagerConfig, then manager
default is true.

https://code.launchpad.net/~waigani/juju-core/lxc-autorestart-setting/+merge/210117

Requires:
https://code.launchpad.net/~waigani/juju-core/managers-should-warn-for-any-unknown-options/+merge/210114

(do not edit description out of merge proposal)

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

Affected files (+26, -3 lines):
   A [revision details]
   M container/lxc/lxc.go
   M container/lxc/lxc_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: container/lxc/lxc.go
=== modified file 'container/lxc/lxc.go'
--- container/lxc/lxc.go 2014-03-10 02:51:31 +0000
+++ container/lxc/lxc.go 2014-03-10 03:33:38 +0000
@@ -42,8 +42,9 @@
  }

  type containerManager struct {
- name string
- logdir string
+ name string
+ logdir string
+ autorestart bool
  }

  // containerManager implements container.Manager.
@@ -63,11 +64,21 @@
   if logDir == "" {
    logDir = agent.DefaultLogDir
   }
+ autoRestart := false
+ if conf["autoRestart"] == "" || conf["autoRestart"] == "true" {
+ autoRestart = true
+ }
+ delete(conf, "autoRestart")
+
   for k, v := range conf {
    logger.Warningf(`Found unused config option with key: "%v" and
value: "%v"`, k, v)
   }

- return &containerManager{name: name, logdir: logDir}, nil
+ return &containerManager{name: name, logdir: logDir, autorestart:
autoRestart}, nil
+}
+
+func (manager *containerManager) AutoRestart() bool {
+ return manager.autorestart
  }

  func (manager *containerManager) StartContainer(

Index: container/lxc/lxc_test.go
=== modified file 'container/lxc/lxc_test.go'
--- container/lxc/lxc_test.go 2014-03-10 02:51:31 +0000
+++ container/lxc/lxc_test.go 2014-03-10 03:33:38 +0000
@@ -58,6 +58,16 @@
   c.Assert(c.GetTestLog(), gc.Matches, `^.*WARNING juju.container.lxc Found
unused config option with key: "shazam" and value: "Captain Marvel"\n*`)
  }

+func (*LxcSuite) TestAutoRestartDefaultTrue(c *gc.C) {
+ _, err := lxc.NewContainerManager(container.ManagerConfig{
+ container.ConfigName: "startMeUp",
+ })
+ c.Assert(err, gc.IsNil)
+
+ // How do we test autorestart ?
+ // c.Assert(manager.somehowGetAutoRestart(?), gc.Equals, true)
+}
+
  func (s *LxcSuite) TestStartContainer(c *gc.C) {
   manager := s.makeManager(c, "test")
   instance := containertesting.StartContainer(c, manager, "1/lxc/0")

Revision history for this message
Tim Penhey (thumper) wrote :

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go
File container/lxc/lxc.go (right):

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go#newcode47
container/lxc/lxc.go:47: autorestart bool
normally camel case: "autoRestart"

yes logdir is wrong

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go#newcode80
container/lxc/lxc.go:80: func (manager *containerManager) AutoRestart()
bool {
this doesn't need to be exported

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc_test.go
File container/lxc/lxc_test.go (right):

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc_test.go#newcode67
container/lxc/lxc_test.go:67: // How do we test autorestart ?
I have a branch that we probably want to land first, as I have tests for
this.

https://codereview.appspot.com/73390043/

Revision history for this message
Horacio Durán (hduran-8) wrote :

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go
File container/lxc/lxc.go (right):

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go#newcode70
container/lxc/lxc.go:70: }
Wouldn't this whole block be equivalent to:

autoRestart := conf["autoRestart"] == "" || conf["autoRestart"] ==
"true"

it seems a bit odd to me to do if true then true if false then false,
but it is just an opinion.

https://codereview.appspot.com/73390043/

2400. By Jesse Meek

cosmetic change to if statement syntax

2401. By Jesse Meek

merged trunk

Revision history for this message
Jesse Meek (waigani) wrote :

Please take a look.

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go
File container/lxc/lxc.go (right):

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go#newcode47
container/lxc/lxc.go:47: autorestart bool
On 2014/03/10 03:56:48, thumper wrote:
> normally camel case: "autoRestart"

> yes logdir is wrong

Done.

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go#newcode70
container/lxc/lxc.go:70: }
On 2014/03/17 17:42:23, hduran wrote:
> Wouldn't this whole block be equivalent to:

> autoRestart := conf["autoRestart"] == "" || conf["autoRestart"] ==
"true"

> it seems a bit odd to me to do if true then true if false then false,
but it is
> just an opinion.

Done. Much better. I didn't know you could do that in go, but now I
think about it - of course you can.

https://codereview.appspot.com/73390043/diff/1/container/lxc/lxc.go#newcode80
container/lxc/lxc.go:80: func (manager *containerManager) AutoRestart()
bool {
On 2014/03/10 03:56:48, thumper wrote:
> this doesn't need to be exported

Done. It was a leftover from debugging.

https://codereview.appspot.com/73390043/

2402. By Jesse Meek

added tests

2403. By Jesse Meek

merged trunk

Revision history for this message
Jesse Meek (waigani) wrote :
Revision history for this message
Tim Penhey (thumper) wrote :

I think we should hold off on the local provider changes until suspend
and resume are done.

https://codereview.appspot.com/73390043/diff/40001/container/lxc/lxc.go
File container/lxc/lxc.go (right):

https://codereview.appspot.com/73390043/diff/40001/container/lxc/lxc.go#newcode93
container/lxc/lxc.go:93: autoRestart := conf["auto-restart"] == "" ||
conf["auto-restart"] == "true"
autoRestart, err := strconv.ParseBool(conf.PopValue("auto-restart"))
if err != nil {
   // An empty string is an error.
   autoRestart = true
}

https://codereview.appspot.com/73390043/diff/40001/container/lxc/lxc.go#newcode97
container/lxc/lxc.go:97: logger.Warningf(`Found unused config option
with key: "%v" and value: "%v"`, k, v)
Please delete this. It is now handled by the

   conf.WarnAboutUnused()

below.

https://codereview.appspot.com/73390043/diff/40001/container/lxc/lxc_test.go
File container/lxc/lxc_test.go (right):

https://codereview.appspot.com/73390043/diff/40001/container/lxc/lxc_test.go#newcode346
container/lxc/lxc_test.go:346: s.autoRestartFalse = true
Don't set here and reset at the end, as an assert stops the end from
happening. Instead use PatchValue...

   s.PatchValue(&s.autoRestartFalse, true)

https://codereview.appspot.com/73390043/diff/40001/container/lxc/lxc_test.go#newcode355
container/lxc/lxc_test.go:355: s.autoRestartFalse = true
ditto.

https://codereview.appspot.com/73390043/diff/40001/provider/local/config.go
File provider/local/config.go (right):

https://codereview.appspot.com/73390043/diff/40001/provider/local/config.go#newcode121
provider/local/config.go:121: value, _ :=
c.attrs["lxc-auto-restart"].(bool)
I think we want a general auto-restart, not just an lxc- one. We can do
the same for kvm. Which leads me to point out that you need to fix kvm.

Although I don't think we should add the ability to set it in the local
provider until suspend and resume are done.

https://codereview.appspot.com/73390043/

Revision history for this message
William Reade (fwereade) wrote :

re thumper's comment, setting WIP

Unmerged revisions

2403. By Jesse Meek

merged trunk

2402. By Jesse Meek

added tests

2401. By Jesse Meek

merged trunk

2400. By Jesse Meek

cosmetic change to if statement syntax

2399. By Jesse Meek

LXC AutoRestart Setting

lxc.containerManager gains “autorestart bool”,
and sets that from container.ManagerConfig, if
not in container.ManagerConfig, then manager
default is true.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'container/lxc/lxc.go'
2--- container/lxc/lxc.go 2014-03-17 22:21:59 +0000
3+++ container/lxc/lxc.go 2014-03-18 17:52:53 +0000
4@@ -68,6 +68,7 @@
5 type containerManager struct {
6 name string
7 logdir string
8+ autoRestart bool
9 createWithClone bool
10 useAUFS bool
11 backingFilesystem string
12@@ -88,6 +89,14 @@
13 if logDir == "" {
14 logDir = agent.DefaultLogDir
15 }
16+
17+ autoRestart := conf["auto-restart"] == "" || conf["auto-restart"] == "true"
18+ delete(conf, "auto-restart")
19+
20+ for k, v := range conf {
21+ logger.Warningf(`Found unused config option with key: "%v" and value: "%v"`, k, v)
22+ }
23+
24 // Explicitly ignore the error result from ParseBool.
25 // If it fails to parse, the value is false, and this suits
26 // us fine.
27@@ -101,11 +110,13 @@
28 // call it 'unknown'.
29 backingFS = "unknown"
30 }
31+
32 logger.Tracef("backing filesystem: %q", backingFS)
33 conf.WarnAboutUnused()
34 return &containerManager{
35 name: name,
36 logdir: logDir,
37+ autoRestart: autoRestart,
38 createWithClone: useClone,
39 useAUFS: useAUFS,
40 backingFilesystem: backingFS,
41@@ -198,8 +209,10 @@
42 }
43 logger.Tracef("lxc container created")
44 }
45- if err := autostartContainer(name); err != nil {
46- return nil, nil, err
47+ if manager.autoRestart {
48+ if err := autostartContainer(name); err != nil {
49+ return nil, nil, err
50+ }
51 }
52 if err := mountHostLogDir(name, manager.logdir); err != nil {
53 return nil, nil, err
54
55=== modified file 'container/lxc/lxc_test.go'
56--- container/lxc/lxc_test.go 2014-03-17 01:08:31 +0000
57+++ container/lxc/lxc_test.go 2014-03-18 17:52:53 +0000
58@@ -36,9 +36,10 @@
59 type LxcSuite struct {
60 lxctesting.TestSuite
61
62- events chan mock.Event
63- useClone bool
64- useAUFS bool
65+ events chan mock.Event
66+ useClone bool
67+ useAUFS bool
68+ autoRestartFalse bool
69 }
70
71 var _ = gc.Suite(&LxcSuite{})
72@@ -99,6 +100,10 @@
73 if s.useAUFS {
74 params["use-aufs"] = "true"
75 }
76+ if s.autoRestartFalse {
77+ params["auto-restart"] = "false"
78+ }
79+
80 manager, err := lxc.NewContainerManager(params)
81 c.Assert(err, gc.IsNil)
82 return manager
83@@ -337,6 +342,37 @@
84 instancetest.MatchInstances(c, result, bar1, bar2)
85 }
86
87+func (s *LxcSuite) TestStartContainerNoAutostart(c *gc.C) {
88+ s.autoRestartFalse = true
89+ manager := s.makeManager(c, "test")
90+ instance := containertesting.StartContainer(c, manager, "1/lxc/0")
91+ autostartLink := lxc.RestartSymlink(string(instance.Id()))
92+ c.Assert(autostartLink, jc.SymlinkDoesNotExist)
93+ s.autoRestartFalse = false
94+}
95+
96+func (s *LxcSuite) TestStartContainerNoAutostartNoRestartDir(c *gc.C) {
97+ s.autoRestartFalse = true
98+ err := os.Remove(s.RestartDir)
99+ c.Assert(err, gc.IsNil)
100+
101+ manager := s.makeManager(c, "test")
102+ instance := containertesting.StartContainer(c, manager, "1/lxc/0")
103+ name := string(instance.Id())
104+ autostartLink := lxc.RestartSymlink(name)
105+ config, err := ioutil.ReadFile(lxc.ContainerConfigFilename(name))
106+ c.Assert(err, gc.IsNil)
107+ expected := `
108+lxc.network.type = veth
109+lxc.network.link = nic42
110+lxc.network.flags = up
111+lxc.mount.entry=/var/log/juju var/log/juju none defaults,bind 0 0
112+`
113+ c.Assert(string(config), gc.Equals, expected)
114+ c.Assert(autostartLink, jc.DoesNotExist)
115+ s.autoRestartFalse = false
116+}
117+
118 func (s *LxcSuite) TestStartContainerAutostarts(c *gc.C) {
119 manager := s.makeManager(c, "test")
120 instance := containertesting.StartContainer(c, manager, "1/lxc/0")
121
122=== modified file 'provider/local/config.go'
123--- provider/local/config.go 2014-03-18 03:51:15 +0000
124+++ provider/local/config.go 2014-03-18 17:52:53 +0000
125@@ -117,6 +117,11 @@
126 return value
127 }
128
129+func (c *environConfig) lxcAutoRestart() bool {
130+ value, _ := c.attrs["lxc-auto-restart"].(bool)
131+ return value
132+}
133+
134 func (c *environConfig) createDirs() error {
135 for _, dirname := range []string{
136 c.storageDir(),
137
138=== modified file 'provider/local/environ.go'
139--- provider/local/environ.go 2014-03-18 03:51:15 +0000
140+++ provider/local/environ.go 2014-03-18 17:52:53 +0000
141@@ -220,6 +220,7 @@
142 if containerType == instance.LXC {
143 managerConfig["use-clone"] = strconv.FormatBool(env.config.lxcClone())
144 managerConfig["use-aufs"] = strconv.FormatBool(env.config.lxcCloneAUFS())
145+ managerConfig["auto-restart"] = strconv.FormatBool(env.config.lxcAutoRestart())
146 }
147 env.containerManager, err = factory.NewContainerManager(
148 containerType, managerConfig)

Subscribers

People subscribed via source and target branches

to status/vote changes: