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

Proposed by Jorge Niedbalski on 2014-07-03
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 2014-07-03 Approve on 2014-07-04
Frank Mueller 2014-07-03 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 on 2014-07-03
11. By Jorge Niedbalski on 2014-07-03

Small typo fix on method comment

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 on 2014-07-04
12. By Jorge Niedbalski on 2014-07-04

Added UtilsSuite, implemented TestGetDefaultLXCContainerDir test for validate changes.

Jorge Niedbalski (niedbalski) wrote :

Hey @thumper,

Added tests to validate this changes.

lp:~niedbalski/golxc/fix-1329049 updated on 2014-07-04
13. By Jorge Niedbalski on 2014-07-04

- Minor formatting issues.

Tim Penhey (thumper) wrote :

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

lp:~niedbalski/golxc/fix-1329049 updated on 2014-07-04
14. By Jorge Niedbalski on 2014-07-04

- Fixes according to @thumper comments.

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
1=== modified file 'golxc.go'
2--- golxc.go 2014-03-11 00:59:30 +0000
3+++ golxc.go 2014-07-04 02:01:18 +0000
4@@ -134,7 +134,7 @@
5
6 const DefaultLXCDir = "/var/lib/lxc"
7
8-var ContainerDir = DefaultLXCDir
9+var ContainerDir = GetDefaultLXCContainerDir()
10
11 type container struct {
12 name string
13@@ -200,6 +200,7 @@
14 "-n", c.name,
15 "-t", template,
16 }
17+
18 if configFile != "" {
19 args = append(args, "-f", configFile)
20 }
21@@ -499,3 +500,15 @@
22 }
23 return set
24 }
25+
26+// GetDefaultLXCContainerDir returns the current lxc.lxcpath value otherwise
27+// the const DefaultLXCDir is returned.
28+func GetDefaultLXCContainerDir() string {
29+ result, err := run("lxc-config", "lxc.lxcpath")
30+
31+ if err != nil {
32+ return DefaultLXCDir
33+ }
34+
35+ return strings.Replace(result, "\n", "", 1)
36+}
37
38=== modified file 'golxc_test.go'
39--- golxc_test.go 2014-05-28 12:05:04 +0000
40+++ golxc_test.go 2014-07-04 02:01:18 +0000
41@@ -420,3 +420,20 @@
42 "--", "template-1", "template-2")
43 c.Assert(clone.Name(), Equals, "name")
44 }
45+
46+type UtilsSuite struct {
47+ testing.IsolationSuite
48+}
49+
50+var _ = Suite(&UtilsSuite{})
51+
52+func (s *UtilsSuite) TestGetDefaultLXCContainerDirDefaultValue(c *C) {
53+ testing.PatchExecutable(c, s, "lxc-config", "#!/bin/sh\nexit -1\n")
54+ c.Assert(golxc.GetDefaultLXCContainerDir(), Equals, golxc.DefaultLXCDir)
55+}
56+
57+func (s *UtilsSuite) TestGetDefaultLXCContainerDir(c *C) {
58+ const path = "/var/lib/non-standard-lxc"
59+ testing.PatchExecutable(c, s, "lxc-config", "#!/bin/sh\necho '"+path+"'\n")
60+ c.Assert(golxc.GetDefaultLXCContainerDir(), Equals, path)
61+}
62
63=== modified file 'network.go'
64--- network.go 2013-06-14 00:29:08 +0000
65+++ network.go 2014-07-04 02:01:18 +0000
66@@ -53,7 +53,7 @@
67 return status == "running", nil
68 }
69
70-// NetworkAttributes returns the lxc network attributes:
71+// NetworkAttributes returns the lxc network attributes:
72 // starting IP address and bridge name.
73 func NetworkAttributes() (addr, bridge string, err error) {
74 config, err := ReadConf()

Subscribers

People subscribed via source and target branches