Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(783)

Delta Between Two Patch Sets: golxc_test.go

Issue 6853075: golxc: added configuration reading (Closed)
Left Patch Set: golxc: added configuration reading Created 11 years, 4 months ago
Right Patch Set: golxc: added configuration reading Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « export_test.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package golxc_test 1 package golxc_test
2 2
3 import ( 3 import (
4 "io/ioutil" 4 "io/ioutil"
5 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
6 "launchpad.net/golxc"
7 "os" 6 "os"
8 "os/user" 7 "os/user"
8 "path/filepath"
9 "testing" 9 "testing"
10
11 "launchpad.net/golxc"
10 ) 12 )
11 13
12 func Test(t *testing.T) { TestingT(t) } 14 func Test(t *testing.T) { TestingT(t) }
13 15
14 type EnvironSuite struct{} 16 type ConfigSuite struct{}
15 17
16 var _ = Suite(&EnvironSuite{}) 18 var _ = Suite(&ConfigSuite{})
17 19
18 var lxcfile = `# MIRROR to be used by ubuntu template at container creation: 20 var lxcfile = `# MIRROR to be used by ubuntu template at container creation:
19 # Leaving it undefined is fine 21 # Leaving it undefined is fine
20 #MIRROR="http://archive.ubuntu.com/ubuntu" 22 #MIRROR="http://archive.ubuntu.com/ubuntu"
21 # or· 23 # or·
22 #MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu" 24 #MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu"
23 25
24 # LXC_AUTO - whether or not to start containers symlinked under 26 # LXC_AUTO - whether or not to start containers symlinked under
25 # /etc/lxc/auto 27 # /etc/lxc/auto
26 LXC_AUTO="true" 28 LXC_AUTO="true"
27 29
28 # Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your 30 # Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your
29 # containers. Set to "false" if you'll use virbr0 or another existing 31 # containers. Set to "false" if you'll use virbr0 or another existing
30 # bridge, or mavlan to your host's NIC. 32 # bridge, or mavlan to your host's NIC.
31 USE_LXC_BRIDGE="true" 33 USE_LXC_BRIDGE="true"
32 34
33 # LXC_BRIDGE and LXC_ADDR are changed against original for 35 # LXC_BRIDGE and LXC_ADDR are changed against original for
34 # testing purposes. 36 # testing purposes.
37 # LXC_BRIDGE="lxcbr1"
35 LXC_BRIDGE="lxcbr9" 38 LXC_BRIDGE="lxcbr9"
39 # LXC_ADDR="10.0.1.1"
36 LXC_ADDR="10.0.9.1" 40 LXC_ADDR="10.0.9.1"
37 LXC_NETMASK="255.255.255.0" 41 LXC_NETMASK="255.255.255.0"
38 LXC_NETWORK="10.0.9.0/24" 42 LXC_NETWORK="10.0.9.0/24"
39 LXC_DHCP_RANGE="10.0.9.2,10.0.9.254" 43 LXC_DHCP_RANGE="10.0.9.2,10.0.9.254"
40 LXC_DHCP_MAX="253" 44 LXC_DHCP_MAX="253"
45 # And for testing LXC_BRIDGE="lxcbr99" and LXC_ADDR="10.0.99.1".
41 46
42 LXC_SHUTDOWN_TIMEOUT=120` 47 LXC_SHUTDOWN_TIMEOUT=120`
43 48
44 func (s *EnvironSuite) TestReadDefaultEnviron(c *C) { 49 var lxcconf = map[string]string{
45 » // Test reading the environment. 50 » "address": "10.0.9.1",
46 » os.Setenv("LXC_BRIDGE", "") 51 » "bridge": "lxcbr9",
47 » os.Setenv("LXC_ADDR", "") 52 }
48 » os.Setenv("MIRROR", "") 53
49 54 func (s *ConfigSuite) TestReadConf(c *C) {
50 » f, err := ioutil.TempFile("/tmp", "lxc-test") 55 » // Test reading the configuration.
51 » c.Assert(err, IsNil) 56 » cf := filepath.Join(c.MkDir(), "lxc-test")
52 » defer func() { 57 » c.Assert(ioutil.WriteFile(cf, []byte(lxcfile), 0555), IsNil)
53 » » c.Assert(os.Remove(f.Name()), IsNil) 58
54 » }() 59 » defer golxc.SetConfPath(golxc.SetConfPath(cf))
55 » _, err = f.WriteString(lxcfile) 60
56 » c.Assert(err, IsNil) 61 » conf, err := golxc.ReadConf()
57 » c.Assert(f.Close(), IsNil) 62 » c.Assert(err, IsNil)
58 63 » c.Assert(conf, DeepEquals, lxcconf)
59 » orig := golxc.SetLXCDefaultFile(f.Name()) 64 }
60 » defer golxc.SetLXCDefaultFile(orig) 65
61 66 func (s *ConfigSuite) TestReadNotExistingDefaultEnviron(c *C) {
62 » env, err := golxc.ReadDefaultEnviron()
63 » c.Assert(err, IsNil)
64 » c.Assert(env["LXC_BRIDGE"], Equals, "lxcbr9")
65 » c.Assert(env["LXC_ADDR"], Equals, "10.0.9.1")
66 » c.Assert(env["MIRROR"], Equals, "")
67 }
68
69 func (s *EnvironSuite) TestReadNotExistingDefaultEnviron(c *C) {
70 // Test reading a not existing environment. 67 // Test reading a not existing environment.
71 » orig := golxc.SetLXCDefaultFile("/tmp/not-existing-exc-test") 68 » defer golxc.SetConfPath(golxc.SetConfPath(filepath.Join(c.MkDir(), "foo" )))
72 » defer golxc.SetLXCDefaultFile(orig) 69
73 70 » _, err := golxc.ReadConf()
74 » _, err := golxc.ReadDefaultEnviron() 71 » c.Assert(err, ErrorMatches, "open .*: no such file or directory")
75 » c.Assert(err, ErrorMatches, "error executing .*: Can't open /tmp/not-exi sting-exc-test")
76 } 72 }
77 73
78 type LXCSuite struct{} 74 type LXCSuite struct{}
79 75
80 var _ = Suite(&LXCSuite{}) 76 var _ = Suite(&LXCSuite{})
81 77
82 func (s *LXCSuite) SetUpSuite(c *C) { 78 func (s *LXCSuite) SetUpSuite(c *C) {
83 u, err := user.Current() 79 u, err := user.Current()
84 c.Assert(err, IsNil) 80 c.Assert(err, IsNil)
85 if u.Uid != "0" { 81 if u.Uid != "0" {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 c.Assert(lc.Create("ubuntu"), IsNil) 299 c.Assert(lc.Create("ubuntu"), IsNil)
304 defer func() { 300 defer func() {
305 c.Assert(lc.Destroy(), IsNil) 301 c.Assert(lc.Destroy(), IsNil)
306 }() 302 }()
307 c.Assert(lc.Start("", ""), IsNil) 303 c.Assert(lc.Start("", ""), IsNil)
308 defer func() { 304 defer func() {
309 c.Assert(lc.Stop(), IsNil) 305 c.Assert(lc.Stop(), IsNil)
310 }() 306 }()
311 c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen") 307 c.Assert(lc.Unfreeze(), ErrorMatches, "container .* is not frozen")
312 } 308 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b