45
45
var sampleConfig = testing.Attrs{
48
"authorized-keys": "my-keys",
48
"authorized-keys": testing.FakeAuthKeys,
49
49
"firewall-mode": config.FwInstance,
50
50
"admin-secret": "foo",
51
51
"unknown": "my-unknown",
129
129
attrs: testing.Attrs{
130
130
"type": "my-type",
131
131
"name": "my-name",
132
"authorized-keys": "my-keys",
132
"authorized-keys": testing.FakeAuthKeys,
135
135
about: "Load authorized-keys from path",
304
304
attrs: testing.Attrs{
305
305
"type": "my-type",
306
306
"name": "my-name",
307
"authorized-keys": "my-keys",
307
"authorized-keys": testing.FakeAuthKeys,
308
308
"development": "invalid",
310
310
err: `development: expected bool, got string\("invalid"\)`,
314
314
attrs: testing.Attrs{
315
315
"type": "my-type",
316
316
"name": "my-name",
317
"authorized-keys": "my-keys",
317
"authorized-keys": testing.FakeAuthKeys,
318
318
"agent-version": "2",
320
320
err: `invalid agent version in environment configuration: "2"`,
448
448
err: `provisioner-safe-mode: expected bool, got string\("yes please"\)`,
450
about: "default image stream",
451
useDefaults: config.UseDefaults,
452
attrs: testing.Attrs{
457
about: "explicit image stream",
458
useDefaults: config.UseDefaults,
459
attrs: testing.Attrs{
462
"image-stream": "daily",
450
465
about: "Explicit state port",
451
466
useDefaults: config.UseDefaults,
452
467
attrs: testing.Attrs{
499
514
err: `syslog-port: expected number, got string\("illegal"\)`,
516
about: "Explicit bootstrap timeout",
517
useDefaults: config.UseDefaults,
518
attrs: testing.Attrs{
521
"bootstrap-timeout": 300,
524
about: "Invalid bootstrap timeout",
525
useDefaults: config.UseDefaults,
526
attrs: testing.Attrs{
529
"bootstrap-timeout": "illegal",
531
err: `bootstrap-timeout: expected number, got string\("illegal"\)`,
533
about: "Explicit bootstrap retry delay",
534
useDefaults: config.UseDefaults,
535
attrs: testing.Attrs{
538
"bootstrap-retry-delay": 5,
541
about: "Invalid bootstrap retry delay",
542
useDefaults: config.UseDefaults,
543
attrs: testing.Attrs{
546
"bootstrap-retry-delay": "illegal",
548
err: `bootstrap-retry-delay: expected number, got string\("illegal"\)`,
550
about: "Explicit bootstrap addresses delay",
551
useDefaults: config.UseDefaults,
552
attrs: testing.Attrs{
555
"bootstrap-addresses-delay": 15,
558
about: "Invalid bootstrap addresses delay",
559
useDefaults: config.UseDefaults,
560
attrs: testing.Attrs{
563
"bootstrap-addresses-delay": "illegal",
565
err: `bootstrap-addresses-delay: expected number, got string\("illegal"\)`,
501
567
about: "Invalid logging configuration",
502
568
useDefaults: config.UseDefaults,
503
569
attrs: testing.Attrs{
556
622
"firewall-mode": "instance",
626
about: "Provider type null is replaced with manual",
627
useDefaults: config.UseDefaults,
628
attrs: testing.Attrs{
560
633
authTokenConfigTest("token=value, tokensecret=value", true),
561
634
authTokenConfigTest("token=value, ", true),
646
719
attrs: testing.Attrs{
647
720
"type": "my-type",
648
721
"name": "my-name",
649
"authorized-keys": "my-keys",
722
"authorized-keys": testing.FakeAuthKeys,
652
725
about: "Unspecified certificate, specified key",
654
727
attrs: testing.Attrs{
655
728
"type": "my-type",
656
729
"name": "my-name",
657
"authorized-keys": "my-keys",
730
"authorized-keys": testing.FakeAuthKeys,
658
731
"ca-private-key": caKey,
660
733
err: "bad CA certificate/key in configuration: crypto/tls:.*",
677
750
attrs: testing.Attrs{
678
751
"type": "my-type",
679
752
"name": "my-name",
680
"authorized-keys": "my-keys",
753
"authorized-keys": testing.FakeAuthKeys,
681
754
"ca-private-key": caKey,
683
756
err: `file ".*/my-name-cert.pem" is empty`,
687
760
attrs: testing.Attrs{
688
761
"type": "my-type",
689
762
"name": "my-name",
690
"authorized-keys": "my-keys",
763
"authorized-keys": testing.FakeAuthKeys,
692
765
err: `file ".*/my-name-cert.pem" is empty`,
696
769
attrs: testing.Attrs{
697
770
"type": "my-type",
698
771
"name": "my-name",
699
"authorized-keys": "my-keys",
772
"authorized-keys": testing.FakeAuthKeys,
700
773
"ca-cert": caCert,
702
775
err: `file ".*/my-name-private-key.pem" is empty`,
716
789
attrs: testing.Attrs{
717
790
"type": "my-type",
718
791
"name": "my-name",
719
"authorized-keys": "my-keys",
792
"authorized-keys": testing.FakeAuthKeys,
722
795
err: "bad CA certificate/key in configuration: crypto/tls: .*",
747
820
c.Assert(err, gc.IsNil)
749
822
typ, _ := test.attrs["type"].(string)
823
// "null" has been deprecated in favour of "manual",
824
// and is automatically switched.
750
828
name, _ := test.attrs["name"].(string)
751
829
c.Assert(cfg.Type(), gc.Equals, typ)
752
830
c.Assert(cfg.Name(), gc.Equals, name)
840
918
c.Assert(cfg.ProvisionerSafeMode(), gc.Equals, false)
920
sshOpts := cfg.BootstrapSSHOpts()
925
config.DefaultBootstrapSSHTimeout,
929
"bootstrap-retry-delay",
931
config.DefaultBootstrapSSHRetryDelay,
935
"bootstrap-addresses-delay",
936
sshOpts.AddressesDelay,
937
config.DefaultBootstrapSSHAddressesDelay,
940
if v, ok := test.attrs["image-stream"]; ok {
941
c.Assert(cfg.ImageStream(), gc.Equals, v)
943
c.Assert(cfg.ImageStream(), gc.Equals, "released")
843
946
url, urlPresent := cfg.ImageMetadataURL()
844
947
if v, _ := test.attrs["image-metadata-url"].(string); v != "" {
973
func (test configTest) assertDuration(c *gc.C, name string, actual time.Duration, defaultInSeconds int) {
974
value, ok := test.attrs[name].(int)
975
if !ok || value == 0 {
976
c.Assert(actual, gc.Equals, time.Duration(defaultInSeconds)*time.Second)
978
c.Assert(actual, gc.Equals, time.Duration(value)*time.Second)
870
982
func (s *ConfigSuite) TestConfigAttrs(c *gc.C) {
871
983
// Normally this is handled by testing.FakeHome
872
984
s.PatchEnvironment(osenv.JujuLoggingConfigEnvKey, "")
873
985
attrs := map[string]interface{}{
874
986
"type": "my-type",
875
987
"name": "my-name",
876
"authorized-keys": "my-keys",
988
"authorized-keys": testing.FakeAuthKeys,
877
989
"firewall-mode": config.FwInstance,
878
990
"admin-secret": "foo",
879
991
"unknown": "my-unknown",
884
996
"state-port": 1234,
885
997
"api-port": 4321,
886
998
"syslog-port": 2345,
999
"bootstrap-timeout": 3600,
1000
"bootstrap-retry-delay": 30,
1001
"bootstrap-addresses-delay": 10,
887
1002
"default-series": "precise",
888
1003
"charm-store-auth": "token=auth",
900
1015
attrs["tools-url"] = ""
901
1016
// Default firewall mode is instance
902
1017
attrs["firewall-mode"] = string(config.FwInstance)
903
c.Assert(cfg.AllAttrs(), gc.DeepEquals, attrs)
904
c.Assert(cfg.UnknownAttrs(), gc.DeepEquals, map[string]interface{}{"unknown": "my-unknown"})
1018
c.Assert(cfg.AllAttrs(), jc.DeepEquals, attrs)
1019
c.Assert(cfg.UnknownAttrs(), jc.DeepEquals, map[string]interface{}{"unknown": "my-unknown"})
906
1021
newcfg, err := cfg.Apply(map[string]interface{}{
907
1022
"name": "new-name",
908
1023
"new-unknown": "my-new-unknown",
1025
c.Assert(err, gc.IsNil)
911
1027
attrs["name"] = "new-name"
912
1028
attrs["new-unknown"] = "my-new-unknown"
913
c.Assert(newcfg.AllAttrs(), gc.DeepEquals, attrs)
1029
c.Assert(newcfg.AllAttrs(), jc.DeepEquals, attrs)
916
1032
type validationTest struct {
1137
1253
c.Assert(config.AptFtpProxy(), gc.Equals, "")
1256
func (*ConfigSuite) TestProxyConfigMap(c *gc.C) {
1257
defer makeFakeHome(c).Restore()
1259
cfg := newTestConfig(c, testing.Attrs{})
1260
proxy := osenv.ProxySettings{
1262
Https: "https proxy",
1265
cfg, err := cfg.Apply(config.ProxyConfigMap(proxy))
1266
c.Assert(err, gc.IsNil)
1267
c.Assert(cfg.ProxySettings(), gc.DeepEquals, proxy)
1268
c.Assert(cfg.AptProxySettings(), gc.DeepEquals, proxy)
1271
func (*ConfigSuite) TestAptProxyConfigMap(c *gc.C) {
1272
defer makeFakeHome(c).Restore()
1274
cfg := newTestConfig(c, testing.Attrs{})
1275
proxy := osenv.ProxySettings{
1277
Https: "https proxy",
1280
cfg, err := cfg.Apply(config.AptProxyConfigMap(proxy))
1281
c.Assert(err, gc.IsNil)
1282
// The default proxy settings should still be empty.
1283
c.Assert(cfg.ProxySettings(), gc.DeepEquals, osenv.ProxySettings{})
1284
c.Assert(cfg.AptProxySettings(), gc.DeepEquals, proxy)
1140
1287
func (*ConfigSuite) TestGenerateStateServerCertAndKey(c *gc.C) {
1141
1288
// In order to test missing certs, it checks the JUJU_HOME dir, so we need
1142
1289
// a fake home.