Merge lp:~wallyworld/golxc/support-cmd-env into lp:golxc

Proposed by Ian Booth on 2014-11-20
Status: Merged
Approved by: Ian Booth on 2014-11-21
Approved revision: 15
Merged at revision: 13
Proposed branch: lp:~wallyworld/golxc/support-cmd-env
Merge into: lp:golxc
Diff against target: 812 lines (+203/-160)
4 files modified
golxc.go (+18/-15)
golxc_test.go (+181/-141)
network.go (+3/-3)
package_test.go (+1/-1)
To merge this branch: bzr merge lp:~wallyworld/golxc/support-cmd-env
Reviewer Review Type Date Requested Status
Andrew Wilkins (community) 2014-11-20 Approve on 2014-11-21
Review via email: mp+242438@code.launchpad.net

Commit message

Add support for passing environment variables to the container Create command. This can potentially be added to other commands too, but for now is just needed for Create().

Also, the gocheck import was out of date, so was updated.

Description of the change

Add support for passing environment variables to the container Create command. This can potentially be added to other commands too, but for now is just needed for Create().

Also, the gocheck import was out of date, so was updated.

To post a comment you must log in.
Andrew Wilkins (axwalk) wrote :

LGTM with comments addressed.

review: Approve
Ian Booth (wallyworld) :
lp:~wallyworld/golxc/support-cmd-env updated on 2014-11-21
14. By Ian Booth on 2014-11-21

Enahnce test

15. By Ian Booth on 2014-11-21

Improve comment

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'golxc.go'
2--- golxc.go 2014-07-30 01:57:14 +0000
3+++ golxc.go 2014-11-21 03:15:57 +0000
4@@ -70,7 +70,9 @@
5 Name() string
6
7 // Create creates a new container based on the given template.
8- Create(configFile, template string, extraArgs []string, templateArgs []string) error
9+ // envArgs, if not nil, are assigned to the environment of the process, otherwise the
10+ // environment of the current process is used.
11+ Create(configFile, template string, extraArgs []string, templateArgs []string, envArgs []string) error
12
13 // Start runs the container as a daemon.
14 Start(configFile, consoleFile string) error
15@@ -157,7 +159,7 @@
16
17 // List returns all the existing containers on the system.
18 func (factory *containerFactory) List() ([]Container, error) {
19- out, err := run("lxc-ls", "-1")
20+ out, err := run("lxc-ls", nil, "-1")
21 if err != nil {
22 return nil, err
23 }
24@@ -192,7 +194,7 @@
25 }
26
27 // Create creates a new container based on the given template.
28-func (c *container) Create(configFile, template string, extraArgs []string, templateArgs []string) error {
29+func (c *container) Create(configFile, template string, extraArgs []string, templateArgs []string, envArgs []string) error {
30 if c.IsConstructed() {
31 return fmt.Errorf("container %q is already created", c.Name())
32 }
33@@ -212,7 +214,7 @@
34 args = append(args, "--")
35 args = append(args, templateArgs...)
36 }
37- _, err := run("lxc-create", args...)
38+ _, err := run("lxc-create", envArgs, args...)
39 if err != nil {
40 return err
41 }
42@@ -238,11 +240,11 @@
43 if consoleFile != "" {
44 startArgs = append(args, "--console-log", consoleFile)
45 }
46- _, err := run("lxc-start", startArgs...)
47+ _, err := run("lxc-start", nil, startArgs...)
48 // We may need to fallback to the older --console arg name.
49 if err != nil && consoleFile != "" {
50 startArgs = append(args, "--console", consoleFile)
51- _, err = run("lxc-start", startArgs...)
52+ _, err = run("lxc-start", nil, startArgs...)
53 }
54 if err != nil {
55 return err
56@@ -271,7 +273,7 @@
57 if c.logFile != "" {
58 args = append(args, "--logfile", c.logFile, "--logpriority", string(c.logLevel))
59 }
60- _, err := run("lxc-stop", args...)
61+ _, err := run("lxc-stop", nil, args...)
62 if err != nil {
63 return err
64 }
65@@ -306,7 +308,7 @@
66 args = append(args, "--")
67 args = append(args, templateArgs...)
68 }
69- _, err := run("lxc-clone", args...)
70+ _, err := run("lxc-clone", nil, args...)
71 if err != nil {
72 return nil, err
73 }
74@@ -327,7 +329,7 @@
75 if c.logFile != "" {
76 args = append(args, "--logfile", c.logFile, "--logpriority", string(c.logLevel))
77 }
78- _, err := run("lxc-freeze", args...)
79+ _, err := run("lxc-freeze", nil, args...)
80 if err != nil {
81 return err
82 }
83@@ -348,7 +350,7 @@
84 if c.logFile != "" {
85 args = append(args, "--logfile", c.logFile, "--logpriority", string(c.logLevel))
86 }
87- _, err := run("lxc-unfreeze", args...)
88+ _, err := run("lxc-unfreeze", nil, args...)
89 if err != nil {
90 return err
91 }
92@@ -363,7 +365,7 @@
93 if err := c.Stop(); err != nil {
94 return err
95 }
96- _, err := run("lxc-destroy", "-n", c.name)
97+ _, err := run("lxc-destroy", nil, "-n", c.name)
98 if err != nil {
99 return err
100 }
101@@ -380,7 +382,7 @@
102 stateStrs[i] = string(state)
103 }
104 waitStates := strings.Join(stateStrs, "|")
105- _, err := run("lxc-wait", "--name", c.name, "--state", waitStates)
106+ _, err := run("lxc-wait", nil, "--name", c.name, "--state", waitStates)
107 if err != nil {
108 return err
109 }
110@@ -389,7 +391,7 @@
111
112 // Info returns the status and the process id of the container.
113 func (c *container) Info() (State, int, error) {
114- out, err := run("lxc-info", "--name", c.name)
115+ out, err := run("lxc-info", nil, "--name", c.name)
116 if err != nil {
117 return StateUnknown, -1, err
118 }
119@@ -441,10 +443,11 @@
120 }
121
122 // run executes the passed command and returns the out.
123-func run(name string, args ...string) (string, error) {
124+func run(name string, env []string, args ...string) (string, error) {
125 logger := loggo.GetLogger(fmt.Sprintf("golxc.run.%s", name))
126 logger.Tracef("run: %s %v", name, args)
127 cmd := exec.Command(name, args...)
128+ cmd.Env = env
129 // LXC tools do not use stdout and stderr in a predictable
130 // way; based on experimentation, the most convenient
131 // solution is to combine them and leave the client to
132@@ -510,7 +513,7 @@
133 // GetDefaultLXCContainerDir returns the current lxc.lxcpath value otherwise
134 // the const DefaultLXCDir is returned.
135 func GetDefaultLXCContainerDir() string {
136- result, err := run("lxc-config", "lxc.lxcpath")
137+ result, err := run("lxc-config", nil, "lxc.lxcpath")
138
139 if err != nil {
140 return DefaultLXCDir
141
142=== modified file 'golxc_test.go'
143--- golxc_test.go 2014-07-30 01:57:14 +0000
144+++ golxc_test.go 2014-11-21 03:15:57 +0000
145@@ -11,7 +11,7 @@
146
147 "github.com/juju/testing"
148 jc "github.com/juju/testing/checkers"
149- . "launchpad.net/gocheck"
150+ gc "gopkg.in/check.v1"
151
152 "launchpad.net/golxc"
153 )
154@@ -52,154 +52,154 @@
155
156 type ConfigSuite struct{}
157
158-var _ = Suite(&ConfigSuite{})
159+var _ = gc.Suite(&ConfigSuite{})
160
161-func (s *ConfigSuite) TestReadConf(c *C) {
162+func (s *ConfigSuite) TestReadConf(c *gc.C) {
163 // Test reading the configuration.
164 cf := filepath.Join(c.MkDir(), "lxc-test")
165- c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), IsNil)
166+ c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), gc.IsNil)
167
168 defer golxc.SetConfPath(golxc.SetConfPath(cf))
169
170 conf, err := golxc.ReadConf()
171- c.Assert(err, IsNil)
172- c.Assert(conf, DeepEquals, lxcconf)
173+ c.Assert(err, gc.IsNil)
174+ c.Assert(conf, gc.DeepEquals, lxcconf)
175 }
176
177-func (s *ConfigSuite) TestReadNotExistingDefaultEnvironment(c *C) {
178+func (s *ConfigSuite) TestReadNotExistingDefaultEnvironment(c *gc.C) {
179 // Test reading a not existing environment.
180 defer golxc.SetConfPath(golxc.SetConfPath(filepath.Join(c.MkDir(), "foo")))
181
182 _, err := golxc.ReadConf()
183- c.Assert(err, ErrorMatches, "open .*: no such file or directory")
184+ c.Assert(err, gc.ErrorMatches, "open .*: no such file or directory")
185 }
186
187-func (s *ConfigSuite) TestNetworkAttributes(c *C) {
188+func (s *ConfigSuite) TestNetworkAttributes(c *gc.C) {
189 // Test reading the network attribute form an environment.
190 cf := filepath.Join(c.MkDir(), "lxc-test")
191- c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), IsNil)
192+ c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), gc.IsNil)
193
194 defer golxc.SetConfPath(golxc.SetConfPath(cf))
195
196 addr, bridge, err := golxc.NetworkAttributes()
197- c.Assert(err, IsNil)
198- c.Assert(addr, Equals, "10.0.9.1")
199- c.Assert(bridge, Equals, "lxcbr9")
200+ c.Assert(err, gc.IsNil)
201+ c.Assert(addr, gc.Equals, "10.0.9.1")
202+ c.Assert(bridge, gc.Equals, "lxcbr9")
203 }
204
205 type NetworkSuite struct{}
206
207-var _ = Suite(&NetworkSuite{})
208+var _ = gc.Suite(&NetworkSuite{})
209
210-func (s *NetworkSuite) SetUpSuite(c *C) {
211+func (s *NetworkSuite) SetUpSuite(c *gc.C) {
212 u, err := user.Current()
213- c.Assert(err, IsNil)
214+ c.Assert(err, gc.IsNil)
215 if u.Uid != "0" {
216 // Has to be run as root!
217 c.Skip("tests must run as root")
218 }
219 }
220
221-func (s *NetworkSuite) TestStartStopNetwork(c *C) {
222+func (s *NetworkSuite) TestStartStopNetwork(c *gc.C) {
223 // Test starting and stoping of the LXC network.
224 initialRunning, err := golxc.IsNetworkRunning()
225- c.Assert(err, IsNil)
226+ c.Assert(err, gc.IsNil)
227 defer func() {
228 if initialRunning {
229- c.Assert(golxc.StartNetwork(), IsNil)
230+ c.Assert(golxc.StartNetwork(), gc.IsNil)
231 }
232 }()
233- c.Assert(golxc.StartNetwork(), IsNil)
234+ c.Assert(golxc.StartNetwork(), gc.IsNil)
235 running, err := golxc.IsNetworkRunning()
236- c.Assert(err, IsNil)
237- c.Assert(running, Equals, true)
238- c.Assert(golxc.StopNetwork(), IsNil)
239+ c.Assert(err, gc.IsNil)
240+ c.Assert(running, gc.Equals, true)
241+ c.Assert(golxc.StopNetwork(), gc.IsNil)
242 running, err = golxc.IsNetworkRunning()
243- c.Assert(err, IsNil)
244- c.Assert(running, Equals, false)
245+ c.Assert(err, gc.IsNil)
246+ c.Assert(running, gc.Equals, false)
247 }
248
249-func (s *NetworkSuite) TestNotExistingNetworkAttributes(c *C) {
250+func (s *NetworkSuite) TestNotExistingNetworkAttributes(c *gc.C) {
251 // Test reading of network attributes from a not existing environment.
252 defer golxc.SetConfPath(golxc.SetConfPath(filepath.Join(c.MkDir(), "foo")))
253
254 _, _, err := golxc.NetworkAttributes()
255- c.Assert(err, ErrorMatches, "open .*: no such file or directory")
256+ c.Assert(err, gc.ErrorMatches, "open .*: no such file or directory")
257 }
258
259 type LXCSuite struct {
260 factory golxc.ContainerFactory
261 }
262
263-var _ = Suite(&LXCSuite{golxc.Factory()})
264+var _ = gc.Suite(&LXCSuite{golxc.Factory()})
265
266-func (s *LXCSuite) SetUpSuite(c *C) {
267+func (s *LXCSuite) SetUpSuite(c *gc.C) {
268 u, err := user.Current()
269- c.Assert(err, IsNil)
270+ c.Assert(err, gc.IsNil)
271 if u.Uid != "0" {
272 // Has to be run as root!
273 c.Skip("tests must run as root")
274 }
275 }
276
277-func (s *LXCSuite) createContainer(c *C) golxc.Container {
278+func (s *LXCSuite) createContainer(c *gc.C) golxc.Container {
279 container := s.factory.New("golxc")
280- c.Assert(container.IsConstructed(), Equals, false)
281- err := container.Create("", "ubuntu", nil, nil)
282- c.Assert(err, IsNil)
283- c.Assert(container.IsConstructed(), Equals, true)
284+ c.Assert(container.IsConstructed(), gc.Equals, false)
285+ err := container.Create("", "ubuntu", nil, nil, nil)
286+ c.Assert(err, gc.IsNil)
287+ c.Assert(container.IsConstructed(), gc.Equals, true)
288 return container
289 }
290
291-func (s *LXCSuite) TestCreateDestroy(c *C) {
292+func (s *LXCSuite) TestCreateDestroy(c *gc.C) {
293 // Test clean creation and destroying of a container.
294 lc := s.factory.New("golxc")
295- c.Assert(lc.IsConstructed(), Equals, false)
296+ c.Assert(lc.IsConstructed(), gc.Equals, false)
297 home := golxc.ContainerHome(lc)
298 _, err := os.Stat(home)
299- c.Assert(err, ErrorMatches, "stat .*: no such file or directory")
300- err = lc.Create("", "ubuntu", nil, nil)
301- c.Assert(err, IsNil)
302- c.Assert(lc.IsConstructed(), Equals, true)
303+ c.Assert(err, gc.ErrorMatches, "stat .*: no such file or directory")
304+ err = lc.Create("", "ubuntu", nil, nil, nil)
305+ c.Assert(err, gc.IsNil)
306+ c.Assert(lc.IsConstructed(), gc.Equals, true)
307 defer func() {
308 err = lc.Destroy()
309- c.Assert(err, IsNil)
310+ c.Assert(err, gc.IsNil)
311 _, err = os.Stat(home)
312- c.Assert(err, ErrorMatches, "stat .*: no such file or directory")
313+ c.Assert(err, gc.ErrorMatches, "stat .*: no such file or directory")
314 }()
315 fi, err := os.Stat(golxc.ContainerHome(lc))
316- c.Assert(err, IsNil)
317- c.Assert(fi.IsDir(), Equals, true)
318+ c.Assert(err, gc.IsNil)
319+ c.Assert(fi.IsDir(), gc.Equals, true)
320 }
321
322-func (s *LXCSuite) TestCreateTwice(c *C) {
323+func (s *LXCSuite) TestCreateTwice(c *gc.C) {
324 // Test that a container cannot be created twice.
325 lc1 := s.createContainer(c)
326- c.Assert(lc1.IsConstructed(), Equals, true)
327+ c.Assert(lc1.IsConstructed(), gc.Equals, true)
328 defer func() {
329- c.Assert(lc1.Destroy(), IsNil)
330+ c.Assert(lc1.Destroy(), gc.IsNil)
331 }()
332 lc2 := s.factory.New("golxc")
333- err := lc2.Create("", "ubuntu", nil, nil)
334- c.Assert(err, ErrorMatches, "container .* is already created")
335+ err := lc2.Create("", "ubuntu", nil, nil, nil)
336+ c.Assert(err, gc.ErrorMatches, "container .* is already created")
337 }
338
339-func (s *LXCSuite) TestCreateIllegalTemplate(c *C) {
340+func (s *LXCSuite) TestCreateIllegalTemplate(c *gc.C) {
341 // Test that a container creation fails correctly in
342 // case of an illegal template.
343 lc := s.factory.New("golxc")
344- c.Assert(lc.IsConstructed(), Equals, false)
345- err := lc.Create("", "name-of-a-not-existing-template-for-golxc", nil, nil)
346- c.Assert(err, ErrorMatches, `error executing "lxc-create": .*bad template.*`)
347- c.Assert(lc.IsConstructed(), Equals, false)
348+ c.Assert(lc.IsConstructed(), gc.Equals, false)
349+ err := lc.Create("", "name-of-a-not-existing-template-for-golxc", nil, nil, nil)
350+ c.Assert(err, gc.ErrorMatches, `error executing "lxc-create": .*bad template.*`)
351+ c.Assert(lc.IsConstructed(), gc.Equals, false)
352 }
353
354-func (s *LXCSuite) TestDestroyNotCreated(c *C) {
355+func (s *LXCSuite) TestDestroyNotCreated(c *gc.C) {
356 // Test that a non-existing container can't be destroyed.
357 lc := s.factory.New("golxc")
358- c.Assert(lc.IsConstructed(), Equals, false)
359+ c.Assert(lc.IsConstructed(), gc.Equals, false)
360 err := lc.Destroy()
361- c.Assert(err, ErrorMatches, "container .* is not yet created")
362+ c.Assert(err, gc.ErrorMatches, "container .* is not yet created")
363 }
364
365 func contains(lcs []golxc.Container, lc golxc.Container) bool {
366@@ -211,148 +211,148 @@
367 return false
368 }
369
370-func (s *LXCSuite) TestList(c *C) {
371+func (s *LXCSuite) TestList(c *gc.C) {
372 // Test the listing of created containers.
373 lcs, err := s.factory.List()
374 oldLen := len(lcs)
375- c.Assert(err, IsNil)
376- c.Assert(oldLen >= 0, Equals, true)
377+ c.Assert(err, gc.IsNil)
378+ c.Assert(oldLen >= 0, gc.Equals, true)
379 lc := s.createContainer(c)
380 defer func() {
381- c.Assert(lc.Destroy(), IsNil)
382+ c.Assert(lc.Destroy(), gc.IsNil)
383 }()
384 lcs, _ = s.factory.List()
385 newLen := len(lcs)
386- c.Assert(newLen == oldLen+1, Equals, true)
387- c.Assert(contains(lcs, lc), Equals, true)
388+ c.Assert(newLen == oldLen+1, gc.Equals, true)
389+ c.Assert(contains(lcs, lc), gc.Equals, true)
390 }
391
392-func (s *LXCSuite) TestClone(c *C) {
393+func (s *LXCSuite) TestClone(c *gc.C) {
394 // Test the cloning of an existing container.
395 lc1 := s.createContainer(c)
396 defer func() {
397- c.Assert(lc1.Destroy(), IsNil)
398+ c.Assert(lc1.Destroy(), gc.IsNil)
399 }()
400 lcs, _ := s.factory.List()
401 oldLen := len(lcs)
402 lc2, err := lc1.Clone("golxcclone", nil, nil)
403- c.Assert(err, IsNil)
404- c.Assert(lc2.IsConstructed(), Equals, true)
405+ c.Assert(err, gc.IsNil)
406+ c.Assert(lc2.IsConstructed(), gc.Equals, true)
407 defer func() {
408- c.Assert(lc2.Destroy(), IsNil)
409+ c.Assert(lc2.Destroy(), gc.IsNil)
410 }()
411 lcs, _ = s.factory.List()
412 newLen := len(lcs)
413- c.Assert(newLen == oldLen+1, Equals, true)
414- c.Assert(contains(lcs, lc1), Equals, true)
415- c.Assert(contains(lcs, lc2), Equals, true)
416+ c.Assert(newLen == oldLen+1, gc.Equals, true)
417+ c.Assert(contains(lcs, lc1), gc.Equals, true)
418+ c.Assert(contains(lcs, lc2), gc.Equals, true)
419 }
420
421-func (s *LXCSuite) TestCloneNotCreated(c *C) {
422+func (s *LXCSuite) TestCloneNotCreated(c *gc.C) {
423 // Test the cloning of a non-existing container.
424 lc := s.factory.New("golxc")
425- c.Assert(lc.IsConstructed(), Equals, false)
426+ c.Assert(lc.IsConstructed(), gc.Equals, false)
427 _, err := lc.Clone("golxcclone", nil, nil)
428- c.Assert(err, ErrorMatches, "container .* is not yet created")
429+ c.Assert(err, gc.ErrorMatches, "container .* is not yet created")
430 }
431
432-func (s *LXCSuite) TestStartStop(c *C) {
433+func (s *LXCSuite) TestStartStop(c *gc.C) {
434 // Test starting and stopping a container.
435 lc := s.createContainer(c)
436 defer func() {
437- c.Assert(lc.Destroy(), IsNil)
438+ c.Assert(lc.Destroy(), gc.IsNil)
439 }()
440- c.Assert(lc.Start("", ""), IsNil)
441- c.Assert(lc.IsRunning(), Equals, true)
442- c.Assert(lc.Stop(), IsNil)
443- c.Assert(lc.IsRunning(), Equals, false)
444+ c.Assert(lc.Start("", ""), gc.IsNil)
445+ c.Assert(lc.IsRunning(), gc.Equals, true)
446+ c.Assert(lc.Stop(), gc.IsNil)
447+ c.Assert(lc.IsRunning(), gc.Equals, false)
448 }
449
450-func (s *LXCSuite) TestStartNotCreated(c *C) {
451+func (s *LXCSuite) TestStartNotCreated(c *gc.C) {
452 // Test that a non-existing container can't be started.
453 lc := s.factory.New("golxc")
454- c.Assert(lc.IsConstructed(), Equals, false)
455- c.Assert(lc.Start("", ""), ErrorMatches, "container .* is not yet created")
456+ c.Assert(lc.IsConstructed(), gc.Equals, false)
457+ c.Assert(lc.Start("", ""), gc.ErrorMatches, "container .* is not yet created")
458 }
459
460-func (s *LXCSuite) TestStopNotRunning(c *C) {
461+func (s *LXCSuite) TestStopNotRunning(c *gc.C) {
462 // Test that a not running container can't be stopped.
463 lc := s.createContainer(c)
464 defer func() {
465- c.Assert(lc.Destroy(), IsNil)
466+ c.Assert(lc.Destroy(), gc.IsNil)
467 }()
468- c.Assert(lc.Stop(), IsNil)
469+ c.Assert(lc.Stop(), gc.IsNil)
470 }
471
472-func (s *LXCSuite) TestWait(c *C) {
473+func (s *LXCSuite) TestWait(c *gc.C) {
474 // Test waiting for one of a number of states of a container.
475 // ATTN: Using a not reached state blocks the test until timeout!
476 lc := s.factory.New("golxc")
477- c.Assert(lc.IsConstructed(), Equals, false)
478- c.Assert(lc.Wait(), ErrorMatches, "no states specified")
479- c.Assert(lc.Wait(golxc.StateStopped), IsNil)
480- c.Assert(lc.Wait(golxc.StateStopped, golxc.StateRunning), IsNil)
481- c.Assert(lc.Create("", "ubuntu", nil, nil), IsNil)
482+ c.Assert(lc.IsConstructed(), gc.Equals, false)
483+ c.Assert(lc.Wait(), gc.ErrorMatches, "no states specified")
484+ c.Assert(lc.Wait(golxc.StateStopped), gc.IsNil)
485+ c.Assert(lc.Wait(golxc.StateStopped, golxc.StateRunning), gc.IsNil)
486+ c.Assert(lc.Create("", "ubuntu", nil, nil, nil), gc.IsNil)
487 defer func() {
488- c.Assert(lc.Destroy(), IsNil)
489+ c.Assert(lc.Destroy(), gc.IsNil)
490 }()
491 go func() {
492- c.Assert(lc.Start("", ""), IsNil)
493+ c.Assert(lc.Start("", ""), gc.IsNil)
494 }()
495- c.Assert(lc.Wait(golxc.StateRunning), IsNil)
496+ c.Assert(lc.Wait(golxc.StateRunning), gc.IsNil)
497 }
498
499-func (s *LXCSuite) TestFreezeUnfreeze(c *C) {
500+func (s *LXCSuite) TestFreezeUnfreeze(c *gc.C) {
501 // Test the freezing and unfreezing of a started container.
502 lc := s.createContainer(c)
503 defer func() {
504- c.Assert(lc.Destroy(), IsNil)
505+ c.Assert(lc.Destroy(), gc.IsNil)
506 }()
507- c.Assert(lc.Start("", ""), IsNil)
508+ c.Assert(lc.Start("", ""), gc.IsNil)
509 defer func() {
510- c.Assert(lc.Stop(), IsNil)
511+ c.Assert(lc.Stop(), gc.IsNil)
512 }()
513- c.Assert(lc.IsRunning(), Equals, true)
514- c.Assert(lc.Freeze(), IsNil)
515- c.Assert(lc.IsRunning(), Equals, false)
516- c.Assert(lc.Unfreeze(), IsNil)
517- c.Assert(lc.IsRunning(), Equals, true)
518+ c.Assert(lc.IsRunning(), gc.Equals, true)
519+ c.Assert(lc.Freeze(), gc.IsNil)
520+ c.Assert(lc.IsRunning(), gc.Equals, false)
521+ c.Assert(lc.Unfreeze(), gc.IsNil)
522+ c.Assert(lc.IsRunning(), gc.Equals, true)
523 }
524
525-func (s *LXCSuite) TestFreezeNotStarted(c *C) {
526+func (s *LXCSuite) TestFreezeNotStarted(c *gc.C) {
527 // Test that a not running container can't be frozen.
528 lc := s.createContainer(c)
529 defer func() {
530- c.Assert(lc.Destroy(), IsNil)
531+ c.Assert(lc.Destroy(), gc.IsNil)
532 }()
533- c.Assert(lc.Freeze(), ErrorMatches, "container .* is not running")
534+ c.Assert(lc.Freeze(), gc.ErrorMatches, "container .* is not running")
535 }
536
537-func (s *LXCSuite) TestFreezeNotCreated(c *C) {
538+func (s *LXCSuite) TestFreezeNotCreated(c *gc.C) {
539 // Test that a non-existing container can't be frozen.
540 lc := s.factory.New("golxc")
541- c.Assert(lc.IsConstructed(), Equals, false)
542- c.Assert(lc.Freeze(), ErrorMatches, "container .* is not yet created")
543+ c.Assert(lc.IsConstructed(), gc.Equals, false)
544+ c.Assert(lc.Freeze(), gc.ErrorMatches, "container .* is not yet created")
545 }
546
547-func (s *LXCSuite) TestUnfreezeNotCreated(c *C) {
548+func (s *LXCSuite) TestUnfreezeNotCreated(c *gc.C) {
549 // Test that a non-existing container can't be unfrozen.
550 lc := s.factory.New("golxc")
551- c.Assert(lc.IsConstructed(), Equals, false)
552- c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not yet created")
553+ c.Assert(lc.IsConstructed(), gc.Equals, false)
554+ c.Assert(lc.Unfreeze(), gc.ErrorMatches, "container .* is not yet created")
555 }
556
557-func (s *LXCSuite) TestUnfreezeNotFrozen(c *C) {
558+func (s *LXCSuite) TestUnfreezeNotFrozen(c *gc.C) {
559 // Test that a running container can't be unfrozen.
560 lc := s.createContainer(c)
561 defer func() {
562- c.Assert(lc.Destroy(), IsNil)
563+ c.Assert(lc.Destroy(), gc.IsNil)
564 }()
565- c.Assert(lc.Start("", ""), IsNil)
566+ c.Assert(lc.Start("", ""), gc.IsNil)
567 defer func() {
568- c.Assert(lc.Stop(), IsNil)
569+ c.Assert(lc.Stop(), gc.IsNil)
570 }()
571- c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen")
572+ c.Assert(lc.Unfreeze(), gc.ErrorMatches, "container .* is not frozen")
573 }
574
575 type commandArgs struct {
576@@ -360,20 +360,20 @@
577 originalPath string
578 }
579
580-var _ = Suite(&commandArgs{})
581+var _ = gc.Suite(&commandArgs{})
582
583-func (s *commandArgs) SetUpSuite(c *C) {
584+func (s *commandArgs) SetUpSuite(c *gc.C) {
585 // lxc-create requires the PATH to be set.
586 s.originalPath = os.Getenv("PATH")
587 s.IsolationSuite.SetUpSuite(c)
588 }
589
590-func (s *commandArgs) setupLxcStart(c *C) {
591+func (s *commandArgs) setupLxcStart(c *gc.C) {
592 dir := c.MkDir()
593 // Make the rootfs for the "test" container so it thinks it is created.
594 rootfs := filepath.Join(dir, "test", "rootfs")
595 err := os.MkdirAll(rootfs, 0755)
596- c.Assert(err, IsNil)
597+ c.Assert(err, gc.IsNil)
598 c.Assert(rootfs, jc.IsDirectory)
599
600 s.PatchValue(&golxc.ContainerDir, dir)
601@@ -384,12 +384,12 @@
602 testing.PatchExecutable(c, s, "lxc-info", "#!/bin/sh\necho '"+info+"'\n")
603 }
604
605-func (s *commandArgs) TestStartArgs(c *C) {
606+func (s *commandArgs) TestStartArgs(c *gc.C) {
607 s.setupLxcStart(c)
608 factory := golxc.Factory()
609 container := factory.New("test")
610 err := container.Start("config-file", "console-log")
611- c.Assert(err, IsNil)
612+ c.Assert(err, gc.IsNil)
613 testing.AssertEchoArgs(
614 c, "lxc-start",
615 "--daemon",
616@@ -398,12 +398,12 @@
617 "--console-log", "console-log")
618 }
619
620-func (s *commandArgs) TestStartArgsNoConsoleLog(c *C) {
621+func (s *commandArgs) TestStartArgsNoConsoleLog(c *gc.C) {
622 s.setupLxcStart(c)
623 factory := golxc.Factory()
624 container := factory.New("test")
625 err := container.Start("config-file", "")
626- c.Assert(err, IsNil)
627+ c.Assert(err, gc.IsNil)
628 testing.AssertEchoArgs(
629 c, "lxc-start",
630 "--daemon",
631@@ -411,12 +411,12 @@
632 "--rcfile", "config-file")
633 }
634
635-func (s *commandArgs) TestStartArgsFallback(c *C) {
636+func (s *commandArgs) TestStartArgsFallback(c *gc.C) {
637 dir := c.MkDir()
638 // Make the rootfs for the "test" container so it thinks it is created.
639 rootfs := filepath.Join(dir, "test", "rootfs")
640 err := os.MkdirAll(rootfs, 0755)
641- c.Assert(err, IsNil)
642+ c.Assert(err, gc.IsNil)
643 c.Assert(rootfs, jc.IsDirectory)
644
645 s.PatchValue(&golxc.ContainerDir, dir)
646@@ -442,7 +442,7 @@
647 factory := golxc.Factory()
648 container := factory.New("test")
649 err = container.Start("config-file", "console-log")
650- c.Assert(err, IsNil)
651+ c.Assert(err, gc.IsNil)
652 testing.AssertEchoArgs(
653 c, "lxc-start",
654 "--daemon",
655@@ -451,7 +451,7 @@
656 "--console", "console-log")
657 }
658
659-func (s *commandArgs) TestCreateArgs(c *C) {
660+func (s *commandArgs) TestCreateArgs(c *gc.C) {
661 s.PatchValue(&golxc.ContainerDir, c.MkDir())
662 s.PatchEnvironment("PATH", s.originalPath)
663 testing.PatchExecutableAsEchoArgs(c, s, "lxc-create")
664@@ -462,8 +462,9 @@
665 "config-file", "template",
666 []string{"extra-1", "extra-2"},
667 []string{"template-1", "template-2"},
668+ nil,
669 )
670- c.Assert(err, IsNil)
671+ c.Assert(err, gc.IsNil)
672 testing.AssertEchoArgs(
673 c, "lxc-create",
674 "-n", "test",
675@@ -473,7 +474,46 @@
676 "--", "template-1", "template-2")
677 }
678
679-func (s *commandArgs) TestCloneArgs(c *C) {
680+func (s *commandArgs) TestCreateWithEnv(c *gc.C) {
681+ s.PatchValue(&golxc.ContainerDir, c.MkDir())
682+ s.PatchEnvironment("PATH", s.originalPath)
683+
684+ EchoEnvHello := `#!/bin/bash
685+name=` + "`basename $0`" + `
686+argfile="$name.out"
687+rm -f $argfile
688+printf "%s" $name | tee -a $argfile
689+printf " \"%s\"" "$HELLO" | tee -a $argfile
690+if [ -n "$FOO" ]; then
691+ printf " \"%s\"" "$FOO" | tee -a $argfile
692+fi
693+printf "\n" | tee -a $argfile
694+`
695+
696+ testing.PatchExecutable(
697+ c, s, "lxc-create", EchoEnvHello)
698+ s.AddCleanup(func(*gc.C) {
699+ os.Remove("lxc-create.out")
700+ })
701+
702+ // Add an environment variable to the calling process
703+ // to show that these don't get passed through.
704+ s.PatchEnvironment("FOO", "BAR")
705+ // Only the explicitly set env variables are propagated.
706+ envArgs := []string{"HELLO=WORLD!"}
707+ factory := golxc.Factory()
708+ container := factory.New("test")
709+ err := container.Create(
710+ "config-file", "template",
711+ []string{"extra-1", "extra-2"},
712+ []string{"template-1", "template-2"},
713+ envArgs,
714+ )
715+ c.Assert(err, gc.IsNil)
716+ testing.AssertEchoArgs(c, "lxc-create", "WORLD!")
717+}
718+
719+func (s *commandArgs) TestCloneArgs(c *gc.C) {
720 dir := c.MkDir()
721 s.PatchValue(&golxc.ContainerDir, dir)
722 s.PatchEnvironment("PATH", s.originalPath)
723@@ -486,7 +526,7 @@
724 // Make the rootfs for the "test" container so it thinks it is created.
725 rootfs := filepath.Join(dir, "test", "rootfs")
726 err := os.MkdirAll(rootfs, 0755)
727- c.Assert(err, IsNil)
728+ c.Assert(err, gc.IsNil)
729 c.Assert(rootfs, jc.IsDirectory)
730 c.Assert(container.IsConstructed(), jc.IsTrue)
731 clone, err := container.Clone(
732@@ -494,29 +534,29 @@
733 []string{"extra-1", "extra-2"},
734 []string{"template-1", "template-2"},
735 )
736- c.Assert(err, IsNil)
737+ c.Assert(err, gc.IsNil)
738 testing.AssertEchoArgs(
739 c, "lxc-clone",
740 "-o", "test",
741 "-n", "name",
742 "extra-1", "extra-2",
743 "--", "template-1", "template-2")
744- c.Assert(clone.Name(), Equals, "name")
745+ c.Assert(clone.Name(), gc.Equals, "name")
746 }
747
748 type UtilsSuite struct {
749 testing.IsolationSuite
750 }
751
752-var _ = Suite(&UtilsSuite{})
753+var _ = gc.Suite(&UtilsSuite{})
754
755-func (s *UtilsSuite) TestGetDefaultLXCContainerDirDefaultValue(c *C) {
756+func (s *UtilsSuite) TestGetDefaultLXCContainerDirDefaultValue(c *gc.C) {
757 testing.PatchExecutable(c, s, "lxc-config", "#!/bin/sh\nexit -1\n")
758- c.Assert(golxc.GetDefaultLXCContainerDir(), Equals, golxc.DefaultLXCDir)
759+ c.Assert(golxc.GetDefaultLXCContainerDir(), gc.Equals, golxc.DefaultLXCDir)
760 }
761
762-func (s *UtilsSuite) TestGetDefaultLXCContainerDir(c *C) {
763+func (s *UtilsSuite) TestGetDefaultLXCContainerDir(c *gc.C) {
764 const path = "/var/lib/non-standard-lxc"
765 testing.PatchExecutable(c, s, "lxc-config", "#!/bin/sh\necho '"+path+"'\n")
766- c.Assert(golxc.GetDefaultLXCContainerDir(), Equals, path)
767+ c.Assert(golxc.GetDefaultLXCContainerDir(), gc.Equals, path)
768 }
769
770=== modified file 'network.go'
771--- network.go 2014-07-03 21:37:49 +0000
772+++ network.go 2014-11-21 03:15:57 +0000
773@@ -20,7 +20,7 @@
774 return err
775 }
776 if goal != "start" {
777- _, err := run("start", "lxc-net")
778+ _, err := run("start", nil, "lxc-net")
779 if err != nil {
780 return err
781 }
782@@ -35,7 +35,7 @@
783 return err
784 }
785 if goal != "stop" {
786- _, err := run("stop", "lxc-net")
787+ _, err := run("stop", nil, "lxc-net")
788 if err != nil {
789 return err
790 }
791@@ -73,7 +73,7 @@
792
793 // networkStatus returns the status of the lxc network subsystem.
794 func networkStatus() (goal, status string, err error) {
795- output, err := run("status", "lxc-net")
796+ output, err := run("status", nil, "lxc-net")
797 if err != nil {
798 return "", "", err
799 }
800
801=== modified file 'package_test.go'
802--- package_test.go 2014-03-11 00:34:54 +0000
803+++ package_test.go 2014-11-21 03:15:57 +0000
804@@ -6,7 +6,7 @@
805 import (
806 "testing"
807
808- gc "launchpad.net/gocheck"
809+ gc "gopkg.in/check.v1"
810 )
811
812 func Test(t *testing.T) {

Subscribers

People subscribed via source and target branches

to all changes: