31
29
func validAttrs() coretesting.Attrs {
32
30
return coretesting.FakeConfig().Merge(coretesting.Attrs{
35
"sdc-key-id": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff",
36
"sdc-url": "test://test.api.joyentcloud.com",
38
"manta-key-id": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff",
39
"manta-url": "test://test.manta.joyent.com",
40
"private-key-path": "~/.ssh/provider_id_rsa",
41
"algorithm": "rsa-sha256",
42
"control-dir": "juju-test",
33
"sdc-key-id": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff",
34
"sdc-url": "test://test.api.joyentcloud.com",
35
"private-key": testPrivateKey,
36
"algorithm": "rsa-sha256",
57
51
s.AddSuiteCleanup(func(*gc.C) { restoreSdcAccount() })
58
52
restoreSdcKeyId := testing.PatchEnvironment(jp.SdcKeyId, "ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00")
59
53
s.AddSuiteCleanup(func(*gc.C) { restoreSdcKeyId() })
60
restoreMantaUser := testing.PatchEnvironment(jp.MantaUser, "tester")
61
s.AddSuiteCleanup(func(*gc.C) { restoreMantaUser() })
62
restoreMantaKeyId := testing.PatchEnvironment(jp.MantaKeyId, "ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00")
63
s.AddSuiteCleanup(func(*gc.C) { restoreMantaKeyId() })
64
54
s.privateKeyData = generatePrivateKey(c)
65
55
jp.RegisterMachinesEndpoint()
66
56
s.AddSuiteCleanup(func(*gc.C) { jp.UnregisterMachinesEndpoint() })
150
139
insert: coretesting.Attrs{"sdc-url": "test://test.api.joyentcloud.com"},
151
140
expect: coretesting.Attrs{"sdc-url": "test://test.api.joyentcloud.com"},
153
info: "manta-user is required",
154
remove: []string{"manta-user"},
155
err: ".* cannot get manta-user value from model variable .*",
157
info: "manta-user cannot be empty",
158
insert: coretesting.Attrs{"manta-user": ""},
159
err: ".* cannot get manta-user value from model variable .*",
161
info: "can get manta-user from model variable",
162
insert: coretesting.Attrs{"manta-user": ""},
163
expect: coretesting.Attrs{"manta-user": "tester"},
164
envVars: map[string]string{
165
"MANTA_USER": "tester",
168
info: "can get manta-user from model variable, missing from config",
169
remove: []string{"manta-user"},
170
expect: coretesting.Attrs{"manta-user": "tester"},
171
envVars: map[string]string{
172
"MANTA_USER": "tester",
175
info: "manta-key-id is required",
176
remove: []string{"manta-key-id"},
177
err: ".* cannot get manta-key-id value from model variable .*",
179
info: "manta-key-id cannot be empty",
180
insert: coretesting.Attrs{"manta-key-id": ""},
181
err: ".* cannot get manta-key-id value from model variable .*",
183
info: "can get manta-key-id from env variable",
184
insert: coretesting.Attrs{"manta-key-id": ""},
185
expect: coretesting.Attrs{"manta-key-id": "key"},
186
envVars: map[string]string{
187
"MANTA_KEY_ID": "key",
190
info: "can get manta-key-id from model variable, missing from config",
191
remove: []string{"manta-key-id"},
192
expect: coretesting.Attrs{"manta-key-id": "key"},
193
envVars: map[string]string{
194
"MANTA_KEY_ID": "key",
197
info: "manta-url is inserted if missing",
198
expect: coretesting.Attrs{"manta-url": "test://test.manta.joyent.com"},
200
info: "manta-url cannot be empty",
201
insert: coretesting.Attrs{"manta-url": ""},
202
err: ".* cannot get manta-url value from model variable .*",
204
info: "manta-url is untouched if present",
205
insert: coretesting.Attrs{"manta-url": "test://test.manta.joyent.com"},
206
expect: coretesting.Attrs{"manta-url": "test://test.manta.joyent.com"},
208
info: "can get private-key-path from env variable",
209
insert: coretesting.Attrs{"private-key-path": ""},
210
expect: coretesting.Attrs{"private-key-path": "some-file"},
211
envVars: map[string]string{
212
"MANTA_PRIVATE_KEY_FILE": "some-file",
215
info: "can get private-key-path from model variable, missing from config",
216
remove: []string{"private-key-path"},
217
expect: coretesting.Attrs{"private-key-path": "some-file"},
218
envVars: map[string]string{
219
"MANTA_PRIVATE_KEY_FILE": "some-file",
222
142
info: "algorithm is inserted if missing",
223
143
expect: coretesting.Attrs{"algorithm": "rsa-sha256"},
288
204
insert: coretesting.Attrs{"sdc-url": "test://test.api.joyentcloud.com"},
289
205
expect: coretesting.Attrs{"sdc-url": "test://test.api.joyentcloud.com"},
291
info: "can change manta-user",
292
insert: coretesting.Attrs{"manta-user": "manta_user"},
293
expect: coretesting.Attrs{"manta-user": "manta_user"},
295
info: "can change manta-key-id",
296
insert: coretesting.Attrs{"manta-key-id": "ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00"},
297
expect: coretesting.Attrs{"manta-key-id": "ff:ee:dd:cc:bb:aa:99:88:77:66:55:44:33:22:11:00"},
299
info: "can change manta-url",
300
insert: coretesting.Attrs{"manta-url": "test://test.manta.joyent.com"},
301
expect: coretesting.Attrs{"manta-url": "test://test.manta.joyent.com"},
303
207
info: "can insert unknown field",
304
208
insert: coretesting.Attrs{"unknown": "ignoti"},
305
209
expect: coretesting.Attrs{"unknown": "ignoti"},
308
212
func (s *ConfigSuite) TestValidateChange(c *gc.C) {
309
213
attrs := validAttrs()
310
attrs["private-key"] = s.privateKeyData
311
214
baseConfig := newConfig(c, attrs)
312
215
for i, test := range changeConfigTests {
313
216
c.Logf("test %d: %s", i, test.info)
314
217
attrs := validAttrs().Merge(test.insert).Delete(test.remove...)
315
attrs["private-key"] = s.privateKeyData
316
218
testConfig := newConfig(c, attrs)
317
219
validatedConfig, err := jp.Provider.Validate(testConfig, baseConfig)
318
220
if test.err == "" {
358
func validPrepareAttrs() coretesting.Attrs {
359
return validAttrs().Delete("private-key")
362
260
// TODO(wallyworld) - add tests for cloud endpoint passed in via bootstrap args
363
var prepareConfigTests = []struct {
261
var bootstrapConfigTests = []struct {
365
263
insert coretesting.Attrs
367
265
expect coretesting.Attrs
370
info: "All value provided, nothig to do",
371
expect: validPrepareAttrs(),
373
info: "private key is loaded from key file",
374
insert: coretesting.Attrs{"private-key-path": fmt.Sprintf("~/.ssh/%s", testKeyFileName)},
375
expect: coretesting.Attrs{"private-key": testPrivateKey},
377
info: "bad private-key-path errors, not panics",
378
insert: coretesting.Attrs{"private-key-path": "~/.ssh/no-such-file"},
379
err: "invalid Joyent provider config: open .*: " + utils.NoSuchFileErrRegexp,
268
info: "All value provided, nothing to do",
269
expect: validAttrs(),
382
func (s *ConfigSuite) TestPrepareForBootstrap(c *gc.C) {
383
ctx := envtesting.BootstrapContext(c)
384
for i, test := range prepareConfigTests {
272
func (s *ConfigSuite) TestBootstrapConfig(c *gc.C) {
273
for i, test := range bootstrapConfigTests {
385
274
c.Logf("test %d: %s", i, test.info)
386
attrs := validPrepareAttrs().Merge(test.insert).Delete(test.remove...)
275
attrs := validAttrs().Merge(test.insert).Delete(test.remove...)
387
276
credentialAttrs := make(map[string]string, len(attrs))
388
for k, v := range attrs.Delete("type", "control-dir") {
277
for k, v := range attrs.Delete("type") {
389
278
credentialAttrs[k] = fmt.Sprintf("%v", v)
391
280
testConfig := newConfig(c, attrs)
392
preparedConfig, err := jp.Provider.PrepareForBootstrap(ctx, environs.PrepareForBootstrapParams{
281
preparedConfig, err := jp.Provider.BootstrapConfig(environs.BootstrapConfigParams{
393
282
Config: testConfig,
394
283
Credentials: cloud.NewCredential(
395
284
cloud.UserPassAuthType,