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