Merge lp:~niedbalski/golxc/fix-1329049 into lp:golxc

Proposed by Jorge Niedbalski
Status: Merged
Merged at revision: 10
Proposed branch: lp:~niedbalski/golxc/fix-1329049
Merge into: lp:golxc
Diff against target: 74 lines (+32/-2)
3 files modified
golxc.go (+14/-1)
golxc_test.go (+17/-0)
network.go (+1/-1)
To merge this branch: bzr merge lp:~niedbalski/golxc/fix-1329049
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Frank Mueller Pending
Review via email: mp+225584@code.launchpad.net

Description of the change

- Added function getDefaultLXCContainerDir , first executes lxc-config lxc.lxcpath if this fails, then DefaultLXCDir is used.
 - Required fix to LP:#1329049

To post a comment you must log in.
lp:~niedbalski/golxc/fix-1329049 updated
11. By Jorge Niedbalski

Small typo fix on method comment

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

Can we please have a test?

You should be able to mock out the lxc-config executable.

review: Needs Fixing
lp:~niedbalski/golxc/fix-1329049 updated
12. By Jorge Niedbalski

Added UtilsSuite, implemented TestGetDefaultLXCContainerDir test for validate changes.

Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

Hey @thumper,

Added tests to validate this changes.

lp:~niedbalski/golxc/fix-1329049 updated
13. By Jorge Niedbalski

- Minor formatting issues.

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

Added comments inline, let's see how they look.

lp:~niedbalski/golxc/fix-1329049 updated
14. By Jorge Niedbalski

- Fixes according to @thumper comments.

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

LGTM, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'golxc.go'
--- golxc.go 2014-03-11 00:59:30 +0000
+++ golxc.go 2014-07-04 02:01:18 +0000
@@ -134,7 +134,7 @@
134134
135const DefaultLXCDir = "/var/lib/lxc"135const DefaultLXCDir = "/var/lib/lxc"
136136
137var ContainerDir = DefaultLXCDir137var ContainerDir = GetDefaultLXCContainerDir()
138138
139type container struct {139type container struct {
140 name string140 name string
@@ -200,6 +200,7 @@
200 "-n", c.name,200 "-n", c.name,
201 "-t", template,201 "-t", template,
202 }202 }
203
203 if configFile != "" {204 if configFile != "" {
204 args = append(args, "-f", configFile)205 args = append(args, "-f", configFile)
205 }206 }
@@ -499,3 +500,15 @@
499 }500 }
500 return set501 return set
501}502}
503
504// GetDefaultLXCContainerDir returns the current lxc.lxcpath value otherwise
505// the const DefaultLXCDir is returned.
506func GetDefaultLXCContainerDir() string {
507 result, err := run("lxc-config", "lxc.lxcpath")
508
509 if err != nil {
510 return DefaultLXCDir
511 }
512
513 return strings.Replace(result, "\n", "", 1)
514}
502515
=== modified file 'golxc_test.go'
--- golxc_test.go 2014-05-28 12:05:04 +0000
+++ golxc_test.go 2014-07-04 02:01:18 +0000
@@ -420,3 +420,20 @@
420 "--", "template-1", "template-2")420 "--", "template-1", "template-2")
421 c.Assert(clone.Name(), Equals, "name")421 c.Assert(clone.Name(), Equals, "name")
422}422}
423
424type UtilsSuite struct {
425 testing.IsolationSuite
426}
427
428var _ = Suite(&UtilsSuite{})
429
430func (s *UtilsSuite) TestGetDefaultLXCContainerDirDefaultValue(c *C) {
431 testing.PatchExecutable(c, s, "lxc-config", "#!/bin/sh\nexit -1\n")
432 c.Assert(golxc.GetDefaultLXCContainerDir(), Equals, golxc.DefaultLXCDir)
433}
434
435func (s *UtilsSuite) TestGetDefaultLXCContainerDir(c *C) {
436 const path = "/var/lib/non-standard-lxc"
437 testing.PatchExecutable(c, s, "lxc-config", "#!/bin/sh\necho '"+path+"'\n")
438 c.Assert(golxc.GetDefaultLXCContainerDir(), Equals, path)
439}
423440
=== modified file 'network.go'
--- network.go 2013-06-14 00:29:08 +0000
+++ network.go 2014-07-04 02:01:18 +0000
@@ -53,7 +53,7 @@
53 return status == "running", nil53 return status == "running", nil
54}54}
5555
56// NetworkAttributes returns the lxc network attributes: 56// NetworkAttributes returns the lxc network attributes:
57// starting IP address and bridge name.57// starting IP address and bridge name.
58func NetworkAttributes() (addr, bridge string, err error) {58func NetworkAttributes() (addr, bridge string, err error) {
59 config, err := ReadConf()59 config, err := ReadConf()

Subscribers

People subscribed via source and target branches