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

Delta Between Two Patch Sets: state/state_test.go

Issue 6855054: state: add CACert to Info.
Left Patch Set: state: add RootCertPEM to Info. Created 12 years, 4 months ago
Right Patch Set: state: add CACert to Info. Created 12 years, 4 months 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 | « state/settings_test.go ('k') | state/unit_test.go » ('j') | 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 state_test 1 package state_test
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "labix.org/v2/mgo/bson" 5 "labix.org/v2/mgo/bson"
6 . "launchpad.net/gocheck" 6 . "launchpad.net/gocheck"
7 "launchpad.net/juju-core/charm" 7 "launchpad.net/juju-core/charm"
8 "launchpad.net/juju-core/environs/config" 8 "launchpad.net/juju-core/environs/config"
9 "launchpad.net/juju-core/state" 9 "launchpad.net/juju-core/state"
10 "launchpad.net/juju-core/testing" 10 "launchpad.net/juju-core/testing"
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 392
393 func (s *StateSuite) TestEnvironConfig(c *C) { 393 func (s *StateSuite) TestEnvironConfig(c *C) {
394 initial := map[string]interface{}{ 394 initial := map[string]interface{}{
395 "name": "test", 395 "name": "test",
396 "type": "test", 396 "type": "test",
397 "authorized-keys": "i-am-a-key", 397 "authorized-keys": "i-am-a-key",
398 "default-series": "precise", 398 "default-series": "precise",
399 "development": true, 399 "development": true,
400 "firewall-mode": "", 400 "firewall-mode": "",
401 "admin-secret": "", 401 "admin-secret": "",
402 "ca-cert": testing.CACert,
403 "ca-private-key": "",
402 } 404 }
403 cfg, err := config.New(initial) 405 cfg, err := config.New(initial)
404 c.Assert(err, IsNil) 406 c.Assert(err, IsNil)
405 st, err := state.Initialize(state.TestingStateInfo(), cfg) 407 st, err := state.Initialize(state.TestingStateInfo(), cfg)
406 c.Assert(err, IsNil) 408 c.Assert(err, IsNil)
407 st.Close() 409 st.Close()
408 c.Assert(err, IsNil) 410 c.Assert(err, IsNil)
409 cfg, err = s.State.EnvironConfig() 411 cfg, err = s.State.EnvironConfig()
410 c.Assert(err, IsNil) 412 c.Assert(err, IsNil)
411 current := cfg.AllAttrs() 413 current := cfg.AllAttrs()
(...skipping 11 matching lines...) Expand all
423 } 425 }
424 426
425 func (s *StateSuite) TestEnvironConfigWithAdminSecret(c *C) { 427 func (s *StateSuite) TestEnvironConfigWithAdminSecret(c *C) {
426 attrs := map[string]interface{}{ 428 attrs := map[string]interface{}{
427 "name": "test", 429 "name": "test",
428 "type": "test", 430 "type": "test",
429 "authorized-keys": "i-am-a-key", 431 "authorized-keys": "i-am-a-key",
430 "default-series": "precise", 432 "default-series": "precise",
431 "development": true, 433 "development": true,
432 "admin-secret": "foo", 434 "admin-secret": "foo",
435 "ca-cert": testing.CACert,
436 "ca-private-key": "",
433 } 437 }
434 cfg, err := config.New(attrs) 438 cfg, err := config.New(attrs)
435 c.Assert(err, IsNil) 439 c.Assert(err, IsNil)
436 _, err = state.Initialize(state.TestingStateInfo(), cfg) 440 _, err = state.Initialize(state.TestingStateInfo(), cfg)
437 c.Assert(err, ErrorMatches, "admin-secret should never be written to the state") 441 c.Assert(err, ErrorMatches, "admin-secret should never be written to the state")
438 442
439 delete(attrs, "admin-secret") 443 delete(attrs, "admin-secret")
440 cfg, err = config.New(attrs) 444 cfg, err = config.New(attrs)
441 st, err := state.Initialize(state.TestingStateInfo(), cfg) 445 st, err := state.Initialize(state.TestingStateInfo(), cfg)
442 c.Assert(err, IsNil) 446 c.Assert(err, IsNil)
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 787
784 func (s *StateSuite) TestInitialize(c *C) { 788 func (s *StateSuite) TestInitialize(c *C) {
785 m := map[string]interface{}{ 789 m := map[string]interface{}{
786 "type": "dummy", 790 "type": "dummy",
787 "name": "lisboa", 791 "name": "lisboa",
788 "authorized-keys": "i-am-a-key", 792 "authorized-keys": "i-am-a-key",
789 "default-series": "precise", 793 "default-series": "precise",
790 "development": true, 794 "development": true,
791 "firewall-mode": "", 795 "firewall-mode": "",
792 "admin-secret": "", 796 "admin-secret": "",
797 "ca-cert": testing.CACert,
798 "ca-private-key": "",
793 } 799 }
794 cfg, err := config.New(m) 800 cfg, err := config.New(m)
795 c.Assert(err, IsNil) 801 c.Assert(err, IsNil)
796 st, err := state.Initialize(state.TestingStateInfo(), cfg) 802 st, err := state.Initialize(state.TestingStateInfo(), cfg)
797 c.Assert(err, IsNil) 803 c.Assert(err, IsNil)
798 c.Assert(st, NotNil) 804 c.Assert(st, NotNil)
799 defer st.Close() 805 defer st.Close()
800 env, err := st.EnvironConfig() 806 env, err := st.EnvironConfig()
801 c.Assert(env.AllAttrs(), DeepEquals, m) 807 c.Assert(env.AllAttrs(), DeepEquals, m)
802 } 808 }
803 809
804 func (s *StateSuite) TestDoubleInitialize(c *C) { 810 func (s *StateSuite) TestDoubleInitialize(c *C) {
805 m := map[string]interface{}{ 811 m := map[string]interface{}{
806 "type": "dummy", 812 "type": "dummy",
807 "name": "lisboa", 813 "name": "lisboa",
808 "authorized-keys": "i-am-a-key", 814 "authorized-keys": "i-am-a-key",
809 "default-series": "precise", 815 "default-series": "precise",
810 "development": true, 816 "development": true,
811 "firewall-mode": "", 817 "firewall-mode": "",
812 "admin-secret": "", 818 "admin-secret": "",
819 "ca-cert": testing.CACert,
820 "ca-private-key": "",
813 } 821 }
814 cfg, err := config.New(m) 822 cfg, err := config.New(m)
815 c.Assert(err, IsNil) 823 c.Assert(err, IsNil)
816 st, err := state.Initialize(state.TestingStateInfo(), cfg) 824 st, err := state.Initialize(state.TestingStateInfo(), cfg)
817 c.Assert(err, IsNil) 825 c.Assert(err, IsNil)
818 c.Assert(st, NotNil) 826 c.Assert(st, NotNil)
819 env1, err := st.EnvironConfig() 827 env1, err := st.EnvironConfig()
820 st.Close() 828 st.Close()
821 829
822 // initialize again, there should be no error and the 830 // initialize again, there should be no error and the
823 // environ config should not change. 831 // environ config should not change.
824 m = map[string]interface{}{ 832 m = map[string]interface{}{
825 "type": "dummy", 833 "type": "dummy",
826 "name": "sydney", 834 "name": "sydney",
827 "authorized-keys": "i-am-not-an-animal", 835 "authorized-keys": "i-am-not-an-animal",
828 "default-series": "xanadu", 836 "default-series": "xanadu",
829 "development": false, 837 "development": false,
830 "firewall-mode": "", 838 "firewall-mode": "",
831 "admin-secret": "", 839 "admin-secret": "",
840 "ca-cert": testing.CACert,
841 "ca-private-key": "",
832 } 842 }
833 cfg, err = config.New(m) 843 cfg, err = config.New(m)
834 c.Assert(err, IsNil) 844 c.Assert(err, IsNil)
835 st, err = state.Initialize(state.TestingStateInfo(), cfg) 845 st, err = state.Initialize(state.TestingStateInfo(), cfg)
836 c.Assert(err, IsNil) 846 c.Assert(err, IsNil)
837 c.Assert(st, NotNil) 847 c.Assert(st, NotNil)
838 env2, err := st.EnvironConfig() 848 env2, err := st.EnvironConfig()
839 st.Close() 849 st.Close()
840 850
841 c.Assert(env1.AllAttrs(), DeepEquals, env2.AllAttrs()) 851 c.Assert(env1.AllAttrs(), DeepEquals, env2.AllAttrs())
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 assertService("foo-2foo", true) 886 assertService("foo-2foo", true)
877 } 887 }
878 888
879 type attrs map[string]interface{} 889 type attrs map[string]interface{}
880 890
881 var watchEnvironConfigTests = []attrs{ 891 var watchEnvironConfigTests = []attrs{
882 { 892 {
883 "type": "my-type", 893 "type": "my-type",
884 "name": "my-name", 894 "name": "my-name",
885 "authorized-keys": "i-am-a-key", 895 "authorized-keys": "i-am-a-key",
896 "ca-cert": testing.CACert,
897 "ca-private-key": "",
886 }, 898 },
887 { 899 {
888 // Add an attribute. 900 // Add an attribute.
889 "type": "my-type", 901 "type": "my-type",
890 "name": "my-name", 902 "name": "my-name",
891 "default-series": "my-series", 903 "default-series": "my-series",
892 "authorized-keys": "i-am-a-key", 904 "authorized-keys": "i-am-a-key",
905 "ca-cert": testing.CACert,
906 "ca-private-key": "",
893 }, 907 },
894 { 908 {
895 // Set a new attribute value. 909 // Set a new attribute value.
896 "type": "my-type", 910 "type": "my-type",
897 "name": "my-new-name", 911 "name": "my-new-name",
898 "default-series": "my-series", 912 "default-series": "my-series",
899 "authorized-keys": "i-am-a-key", 913 "authorized-keys": "i-am-a-key",
914 "ca-cert": testing.CACert,
915 "ca-private-key": "",
900 }, 916 },
901 } 917 }
902 918
903 func (s *StateSuite) TestWatchEnvironConfig(c *C) { 919 func (s *StateSuite) TestWatchEnvironConfig(c *C) {
904 watcher := s.State.WatchEnvironConfig() 920 watcher := s.State.WatchEnvironConfig()
905 defer func() { 921 defer func() {
906 c.Assert(watcher.Stop(), IsNil) 922 c.Assert(watcher.Stop(), IsNil)
907 }() 923 }()
908 for i, test := range watchEnvironConfigTests { 924 for i, test := range watchEnvironConfigTests {
909 c.Logf("test %d", i) 925 c.Logf("test %d", i)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 case <-time.After(500 * time.Millisecond): 967 case <-time.After(500 * time.Millisecond):
952 c.Fatalf("did not get change") 968 c.Fatalf("did not get change")
953 } 969 }
954 } 970 }
955 971
956 func (s *StateSuite) TestWatchEnvironConfigInvalidConfig(c *C) { 972 func (s *StateSuite) TestWatchEnvironConfigInvalidConfig(c *C) {
957 m := map[string]interface{}{ 973 m := map[string]interface{}{
958 "type": "dummy", 974 "type": "dummy",
959 "name": "lisboa", 975 "name": "lisboa",
960 "authorized-keys": "i-am-a-key", 976 "authorized-keys": "i-am-a-key",
977 "ca-cert": testing.CACert,
978 "ca-private-key": "",
961 } 979 }
962 cfg1, err := config.New(m) 980 cfg1, err := config.New(m)
963 c.Assert(err, IsNil) 981 c.Assert(err, IsNil)
964 st, err := state.Initialize(state.TestingStateInfo(), cfg1) 982 st, err := state.Initialize(state.TestingStateInfo(), cfg1)
965 c.Assert(err, IsNil) 983 c.Assert(err, IsNil)
966 st.Close() 984 st.Close()
967 985
968 // Corrupt the environment configuration. 986 // Corrupt the environment configuration.
969 settings := s.Session.DB("juju").C("settings") 987 settings := s.Session.DB("juju").C("settings")
970 err = settings.UpdateId("e", bson.D{{"$unset", bson.D{{"name", 1}}}}) 988 err = settings.UpdateId("e", bson.D{{"$unset", bson.D{{"name", 1}}}})
(...skipping 25 matching lines...) Expand all
996 case <-done: 1014 case <-done:
997 c.Fatalf("configuration returned too soon") 1015 c.Fatalf("configuration returned too soon")
998 case <-time.After(100 * time.Millisecond): 1016 case <-time.After(100 * time.Millisecond):
999 } 1017 }
1000 1018
1001 // Fix the configuration. 1019 // Fix the configuration.
1002 cfg2, err := config.New(map[string]interface{}{ 1020 cfg2, err := config.New(map[string]interface{}{
1003 "type": "dummy", 1021 "type": "dummy",
1004 "name": "lisboa", 1022 "name": "lisboa",
1005 "authorized-keys": "new-key", 1023 "authorized-keys": "new-key",
1024 "ca-cert": testing.CACert,
1025 "ca-private-key": "",
1006 }) 1026 })
1007 c.Assert(err, IsNil) 1027 c.Assert(err, IsNil)
1008 err = s.State.SetEnvironConfig(cfg2) 1028 err = s.State.SetEnvironConfig(cfg2)
1009 c.Assert(err, IsNil) 1029 c.Assert(err, IsNil)
1010 1030
1011 s.State.StartSync() 1031 s.State.StartSync()
1012 select { 1032 select {
1013 case cfg3 := <-done: 1033 case cfg3 := <-done:
1014 c.Assert(cfg3.AllAttrs(), DeepEquals, cfg2.AllAttrs()) 1034 c.Assert(cfg3.AllAttrs(), DeepEquals, cfg2.AllAttrs())
1015 case <-time.After(5 * time.Second): 1035 case <-time.After(5 * time.Second):
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 c.Assert(err, IsNil) 1181 c.Assert(err, IsNil)
1162 1182
1163 // Check that removing the password is idempotent. 1183 // Check that removing the password is idempotent.
1164 err = s.State.SetAdminPassword("") 1184 err = s.State.SetAdminPassword("")
1165 c.Assert(err, IsNil) 1185 c.Assert(err, IsNil)
1166 1186
1167 info.Password = "" 1187 info.Password = ""
1168 err = tryOpenState(info) 1188 err = tryOpenState(info)
1169 c.Assert(err, IsNil) 1189 c.Assert(err, IsNil)
1170 } 1190 }
LEFTRIGHT

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