Merge lp:~cox-katherine-e/golxc/support-lxc-start-v0.8-and-greater into lp:golxc

Proposed by Katherine Cox-Buday on 2014-07-28
Status: Merged
Approved by: Ian Booth on 2014-07-28
Approved revision: 13
Merged at revision: 11
Proposed branch: lp:~cox-katherine-e/golxc/support-lxc-start-v0.8-and-greater
Merge into: lp:golxc
Diff against target: 94 lines (+50/-1)
3 files modified
export_test.go (+2/-0)
golxc.go (+31/-1)
golxc_test.go (+17/-0)
To merge this branch: bzr merge lp:~cox-katherine-e/golxc/support-lxc-start-v0.8-and-greater
Reviewer Review Type Date Requested Status
Ian Booth 2014-07-28 Approve on 2014-07-28
Review via email: mp+228582@code.launchpad.net

Commit message

Added support for >= v0.8 of lxc-start.

Description of the change

In versions of lxc-start >= v0.8, the -c flag was migrated to -L. These changes add backwards-compatible support for specifying a log-file.

To post a comment you must log in.

In versions of lxc-start >= v0.8, the -c flag was migrated to -L. These changes add backwards-compatible support for specifying a log-file.

Ian Booth (wallyworld) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'export_test.go'
2--- export_test.go 2013-06-14 03:27:43 +0000
3+++ export_test.go 2014-07-28 22:25:21 +0000
4@@ -15,3 +15,5 @@
5 confPath = cp
6 return orig
7 }
8+
9+var GenerateConsoleFileArguments func(string) (string, error) = generateConsoleFileArgument
10
11=== modified file 'golxc.go'
12--- golxc.go 2014-07-04 01:23:39 +0000
13+++ golxc.go 2014-07-28 22:25:21 +0000
14@@ -12,6 +12,7 @@
15 "os"
16 "os/exec"
17 "path"
18+ "regexp"
19 "strconv"
20 "strings"
21
22@@ -232,7 +233,16 @@
23 args = append(args, "-f", configFile)
24 }
25 if consoleFile != "" {
26- args = append(args, "-c", consoleFile)
27+ version, err := lxcStartVersion()
28+ if err != nil {
29+ return fmt.Errorf("cannot determine the lxc-start version: %v", err)
30+ }
31+
32+ consoleFlag, err := generateConsoleFileArgument(version)
33+ if err != nil {
34+ return fmt.Errorf("cannot determine the flag for specifying a console-output log file: %v", err)
35+ }
36+ args = append(args, consoleFlag, consoleFile)
37 }
38 if c.logFile != "" {
39 args = append(args, "-o", c.logFile, "-l", string(c.logLevel))
40@@ -434,6 +444,26 @@
41 return path.Join(c.containerHome(), "rootfs")
42 }
43
44+func generateConsoleFileArgument(lxcVersion string) (flag string, err error) {
45+ // Version <= 0.7 specified a console file via the -c flag. Newer
46+ // versions utilize the -L flag.
47+ if matched, err := regexp.MatchString(`^0\.[0-8]`, lxcVersion); err == nil {
48+ if matched {
49+ flag = "-c"
50+ } else {
51+ flag = "-L"
52+ }
53+ }
54+
55+ return flag, err
56+}
57+
58+// Returns the lxc-start version
59+func lxcStartVersion() (string, error) {
60+ version, err := exec.Command("lxc-start", "--version").Output()
61+ return string(version), err
62+}
63+
64 // run executes the passed command and returns the out.
65 func run(name string, args ...string) (string, error) {
66 logger := loggo.GetLogger(fmt.Sprintf("golxc.run.%s", name))
67
68=== modified file 'golxc_test.go'
69--- golxc_test.go 2014-07-04 02:00:24 +0000
70+++ golxc_test.go 2014-07-28 22:25:21 +0000
71@@ -368,6 +368,23 @@
72 s.IsolationSuite.SetUpSuite(c)
73 }
74
75+// Test that our function which parses versions and returns the proper
76+// console flag is working as intended.
77+func (s *commandArgs) TestGenerateCorrectConsoleFileFlag(c *C) {
78+
79+ assertGood := func(desiredFlag string) func(string, error) {
80+ return func(flag string, err error) {
81+ c.Assert(err, IsNil)
82+ c.Assert(flag, Equals, desiredFlag)
83+ }
84+ }
85+
86+ assertGood("-c")(golxc.GenerateConsoleFileArguments("0.8"))
87+ assertGood("-L")(golxc.GenerateConsoleFileArguments("0.9"))
88+ assertGood("-L")(golxc.GenerateConsoleFileArguments("1.8"))
89+ assertGood("-L")(golxc.GenerateConsoleFileArguments("1.0.4"))
90+}
91+
92 func (s *commandArgs) TestCreateArgs(c *C) {
93 s.PatchValue(&golxc.ContainerDir, c.MkDir())
94 s.PatchEnvironment("PATH", s.originalPath)

Subscribers

People subscribed via source and target branches