LEFT | RIGHT |
(no file at all) | |
1 package juju_test | 1 package juju_test |
2 | 2 |
3 import ( | 3 import ( |
4 "io/ioutil" | 4 "io/ioutil" |
5 . "launchpad.net/gocheck" | 5 . "launchpad.net/gocheck" |
6 "launchpad.net/juju-core/charm" | 6 "launchpad.net/juju-core/charm" |
7 "launchpad.net/juju-core/environs" | 7 "launchpad.net/juju-core/environs" |
8 "launchpad.net/juju-core/environs/dummy" | 8 "launchpad.net/juju-core/environs/dummy" |
9 "launchpad.net/juju-core/juju" | 9 "launchpad.net/juju-core/juju" |
10 "launchpad.net/juju-core/state" | 10 "launchpad.net/juju-core/state" |
(...skipping 20 matching lines...) Expand all Loading... |
31 } | 31 } |
32 | 32 |
33 func (*NewConnSuite) TestNewConnWithoutAdminSecret(c *C) { | 33 func (*NewConnSuite) TestNewConnWithoutAdminSecret(c *C) { |
34 attrs := map[string]interface{}{ | 34 attrs := map[string]interface{}{ |
35 "name": "erewhemos", | 35 "name": "erewhemos", |
36 "type": "dummy", | 36 "type": "dummy", |
37 "state-server": true, | 37 "state-server": true, |
38 "authorized-keys": "i-am-a-key", | 38 "authorized-keys": "i-am-a-key", |
39 "secret": "pork", | 39 "secret": "pork", |
40 "admin-secret": "really", | 40 "admin-secret": "really", |
| 41 "ca-cert": coretesting.CACertPEM, |
| 42 "ca-private-key": "", |
41 } | 43 } |
42 env, err := environs.NewFromAttrs(attrs) | 44 env, err := environs.NewFromAttrs(attrs) |
43 c.Assert(err, IsNil) | 45 c.Assert(err, IsNil) |
44 err = juju.Bootstrap(env, false, []byte(coretesting.CACertPEM+coretestin
g.CAKeyPEM)) | 46 err = juju.Bootstrap(env, false, []byte(coretesting.CACertPEM+coretestin
g.CAKeyPEM)) |
45 c.Assert(err, IsNil) | 47 c.Assert(err, IsNil) |
46 | 48 |
47 delete(attrs, "admin-secret") | 49 delete(attrs, "admin-secret") |
48 env1, err := environs.NewFromAttrs(attrs) | 50 env1, err := environs.NewFromAttrs(attrs) |
49 c.Assert(err, IsNil) | 51 c.Assert(err, IsNil) |
50 conn, err := juju.NewConn(env1) | 52 conn, err := juju.NewConn(env1) |
51 c.Check(conn, IsNil) | 53 c.Check(conn, IsNil) |
52 c.Assert(err, ErrorMatches, "cannot connect without admin-secret") | 54 c.Assert(err, ErrorMatches, "cannot connect without admin-secret") |
53 } | 55 } |
54 | 56 |
55 func (*NewConnSuite) TestNewConnFromName(c *C) { | 57 func (*NewConnSuite) TestNewConnFromName(c *C) { |
56 home := c.MkDir() | 58 home := c.MkDir() |
57 defer os.Setenv("HOME", os.Getenv("HOME")) | 59 defer os.Setenv("HOME", os.Getenv("HOME")) |
58 os.Setenv("HOME", home) | 60 os.Setenv("HOME", home) |
59 conn, err := juju.NewConnFromName("") | 61 conn, err := juju.NewConnFromName("") |
60 c.Assert(conn, IsNil) | 62 c.Assert(conn, IsNil) |
61 c.Assert(err, ErrorMatches, ".*: no such file or directory") | 63 c.Assert(err, ErrorMatches, ".*: no such file or directory") |
62 | 64 |
63 if err := os.Mkdir(filepath.Join(home, ".juju"), 0755); err != nil { | 65 if err := os.Mkdir(filepath.Join(home, ".juju"), 0755); err != nil { |
64 » » c.Log("Could not create directory structure") | 66 » » c.Fatal("Could not create directory structure") |
65 » » c.Fail() | |
66 } | 67 } |
67 envs := filepath.Join(home, ".juju", "environments.yaml") | 68 envs := filepath.Join(home, ".juju", "environments.yaml") |
68 err = ioutil.WriteFile(envs, []byte(` | 69 err = ioutil.WriteFile(envs, []byte(` |
69 default: | 70 default: |
70 erewhemos | 71 erewhemos |
71 environments: | 72 environments: |
72 erewhemos: | 73 erewhemos: |
73 type: dummy | 74 type: dummy |
74 state-server: true | 75 state-server: true |
75 authorized-keys: i-am-a-key | 76 authorized-keys: i-am-a-key |
76 admin-secret: conn-from-name-secret | 77 admin-secret: conn-from-name-secret |
77 `), 0644) | 78 `), 0644) |
78 » if err != nil { | 79 |
79 » » c.Log("Could not create environments.yaml") | 80 » err = ioutil.WriteFile(filepath.Join(home, ".juju", "erewhemos-cert.pem"
), []byte(coretesting.CACertPEM), 0600) |
80 » » c.Fail() | 81 » c.Assert(err, IsNil) |
81 » } | |
82 | 82 |
83 // Just run through a few operations on the dummy provider and verify th
at | 83 // Just run through a few operations on the dummy provider and verify th
at |
84 // they behave as expected. | 84 // they behave as expected. |
85 conn, err = juju.NewConnFromName("") | 85 conn, err = juju.NewConnFromName("") |
86 c.Assert(err, ErrorMatches, "dummy environment not bootstrapped") | 86 c.Assert(err, ErrorMatches, "dummy environment not bootstrapped") |
87 | 87 |
88 environ, err := environs.NewFromName("") | 88 environ, err := environs.NewFromName("") |
89 c.Assert(err, IsNil) | 89 c.Assert(err, IsNil) |
90 err = juju.Bootstrap(environ, false, []byte(coretesting.CACertPEM+corete
sting.CAKeyPEM)) | 90 err = juju.Bootstrap(environ, false, []byte(coretesting.CACertPEM+corete
sting.CAKeyPEM)) |
91 c.Assert(err, IsNil) | 91 c.Assert(err, IsNil) |
(...skipping 17 matching lines...) Expand all Loading... |
109 } | 109 } |
110 | 110 |
111 func (cs *NewConnSuite) TestConnStateSecretsSideEffect(c *C) { | 111 func (cs *NewConnSuite) TestConnStateSecretsSideEffect(c *C) { |
112 attrs := map[string]interface{}{ | 112 attrs := map[string]interface{}{ |
113 "name": "erewhemos", | 113 "name": "erewhemos", |
114 "type": "dummy", | 114 "type": "dummy", |
115 "state-server": true, | 115 "state-server": true, |
116 "authorized-keys": "i-am-a-key", | 116 "authorized-keys": "i-am-a-key", |
117 "secret": "pork", | 117 "secret": "pork", |
118 "admin-secret": "side-effect secret", | 118 "admin-secret": "side-effect secret", |
| 119 "ca-cert": coretesting.CACertPEM, |
119 } | 120 } |
120 env, err := environs.NewFromAttrs(attrs) | 121 env, err := environs.NewFromAttrs(attrs) |
121 c.Assert(err, IsNil) | 122 c.Assert(err, IsNil) |
122 err = juju.Bootstrap(env, false, []byte(coretesting.CACertPEM+coretestin
g.CAKeyPEM)) | 123 err = juju.Bootstrap(env, false, []byte(coretesting.CACertPEM+coretestin
g.CAKeyPEM)) |
123 c.Assert(err, IsNil) | 124 c.Assert(err, IsNil) |
124 info, err := env.StateInfo() | 125 info, err := env.StateInfo() |
125 c.Assert(err, IsNil) | 126 c.Assert(err, IsNil) |
126 info.Password = trivial.PasswordHash("side-effect secret") | 127 info.Password = trivial.PasswordHash("side-effect secret") |
127 st, err := state.Open(info) | 128 st, err := state.Open(info) |
128 c.Assert(err, IsNil) | 129 c.Assert(err, IsNil) |
(...skipping 18 matching lines...) Expand all Loading... |
147 } | 148 } |
148 | 149 |
149 func (cs *NewConnSuite) TestConnStateDoesNotUpdateExistingSecrets(c *C) { | 150 func (cs *NewConnSuite) TestConnStateDoesNotUpdateExistingSecrets(c *C) { |
150 attrs := map[string]interface{}{ | 151 attrs := map[string]interface{}{ |
151 "name": "erewhemos", | 152 "name": "erewhemos", |
152 "type": "dummy", | 153 "type": "dummy", |
153 "state-server": true, | 154 "state-server": true, |
154 "authorized-keys": "i-am-a-key", | 155 "authorized-keys": "i-am-a-key", |
155 "secret": "pork", | 156 "secret": "pork", |
156 "admin-secret": "some secret", | 157 "admin-secret": "some secret", |
| 158 "ca-cert": coretesting.CACertPEM, |
157 } | 159 } |
158 env, err := environs.NewFromAttrs(attrs) | 160 env, err := environs.NewFromAttrs(attrs) |
159 c.Assert(err, IsNil) | 161 c.Assert(err, IsNil) |
160 err = juju.Bootstrap(env, false, []byte(coretesting.CACertPEM+coretestin
g.CAKeyPEM)) | 162 err = juju.Bootstrap(env, false, []byte(coretesting.CACertPEM+coretestin
g.CAKeyPEM)) |
161 c.Assert(err, IsNil) | 163 c.Assert(err, IsNil) |
162 | 164 |
163 // Make a new Conn, which will push the secrets. | 165 // Make a new Conn, which will push the secrets. |
164 conn, err := juju.NewConn(env) | 166 conn, err := juju.NewConn(env) |
165 c.Assert(err, IsNil) | 167 c.Assert(err, IsNil) |
166 defer conn.Close() | 168 defer conn.Close() |
(...skipping 17 matching lines...) Expand all Loading... |
184 } | 186 } |
185 | 187 |
186 func (cs *NewConnSuite) TestConnWithPassword(c *C) { | 188 func (cs *NewConnSuite) TestConnWithPassword(c *C) { |
187 env, err := environs.NewFromAttrs(map[string]interface{}{ | 189 env, err := environs.NewFromAttrs(map[string]interface{}{ |
188 "name": "erewhemos", | 190 "name": "erewhemos", |
189 "type": "dummy", | 191 "type": "dummy", |
190 "state-server": true, | 192 "state-server": true, |
191 "authorized-keys": "i-am-a-key", | 193 "authorized-keys": "i-am-a-key", |
192 "secret": "squirrel", | 194 "secret": "squirrel", |
193 "admin-secret": "nutkin", | 195 "admin-secret": "nutkin", |
| 196 "ca-cert": coretesting.CACertPEM, |
194 }) | 197 }) |
195 c.Assert(err, IsNil) | 198 c.Assert(err, IsNil) |
196 err = juju.Bootstrap(env, false, []byte(coretesting.CACertPEM+coretestin
g.CAKeyPEM)) | 199 err = juju.Bootstrap(env, false, []byte(coretesting.CACertPEM+coretestin
g.CAKeyPEM)) |
197 c.Assert(err, IsNil) | 200 c.Assert(err, IsNil) |
198 | 201 |
199 // Check that Bootstrap has correctly used a hash | 202 // Check that Bootstrap has correctly used a hash |
200 // of the admin password. | 203 // of the admin password. |
201 info, err := env.StateInfo() | 204 info, err := env.StateInfo() |
202 c.Assert(err, IsNil) | 205 c.Assert(err, IsNil) |
203 info.Password = trivial.PasswordHash("nutkin") | 206 info.Password = trivial.PasswordHash("nutkin") |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 242 |
240 func (s *ConnSuite) SetUpTest(c *C) { | 243 func (s *ConnSuite) SetUpTest(c *C) { |
241 s.LoggingSuite.SetUpTest(c) | 244 s.LoggingSuite.SetUpTest(c) |
242 s.MgoSuite.SetUpTest(c) | 245 s.MgoSuite.SetUpTest(c) |
243 attrs := map[string]interface{}{ | 246 attrs := map[string]interface{}{ |
244 "name": "erewhemos", | 247 "name": "erewhemos", |
245 "type": "dummy", | 248 "type": "dummy", |
246 "state-server": true, | 249 "state-server": true, |
247 "authorized-keys": "i-am-a-key", | 250 "authorized-keys": "i-am-a-key", |
248 "admin-secret": "deploy-test-secret", | 251 "admin-secret": "deploy-test-secret", |
| 252 "ca-cert": coretesting.CACertPEM, |
249 } | 253 } |
250 environ, err := environs.NewFromAttrs(attrs) | 254 environ, err := environs.NewFromAttrs(attrs) |
251 c.Assert(err, IsNil) | 255 c.Assert(err, IsNil) |
252 err = juju.Bootstrap(environ, false, []byte(coretesting.CACertPEM+corete
sting.CAKeyPEM)) | 256 err = juju.Bootstrap(environ, false, []byte(coretesting.CACertPEM+corete
sting.CAKeyPEM)) |
253 c.Assert(err, IsNil) | 257 c.Assert(err, IsNil) |
254 s.conn, err = juju.NewConn(environ) | 258 s.conn, err = juju.NewConn(environ) |
255 c.Assert(err, IsNil) | 259 c.Assert(err, IsNil) |
256 s.repo = &charm.LocalRepository{Path: c.MkDir()} | 260 s.repo = &charm.LocalRepository{Path: c.MkDir()} |
257 } | 261 } |
258 | 262 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 c.Assert(u.Resolved(), Equals, state.ResolvedNoHooks) | 464 c.Assert(u.Resolved(), Equals, state.ResolvedNoHooks) |
461 | 465 |
462 err = u.ClearResolved() | 466 err = u.ClearResolved() |
463 c.Assert(err, IsNil) | 467 c.Assert(err, IsNil) |
464 err = s.conn.Resolved(u, true) | 468 err = s.conn.Resolved(u, true) |
465 c.Assert(err, IsNil) | 469 c.Assert(err, IsNil) |
466 err = s.conn.Resolved(u, false) | 470 err = s.conn.Resolved(u, false) |
467 c.Assert(err, ErrorMatches, `cannot set resolved mode for unit "testriak
/0": already resolved`) | 471 c.Assert(err, ErrorMatches, `cannot set resolved mode for unit "testriak
/0": already resolved`) |
468 c.Assert(u.Resolved(), Equals, state.ResolvedRetryHooks) | 472 c.Assert(u.Resolved(), Equals, state.ResolvedRetryHooks) |
469 } | 473 } |
LEFT | RIGHT |