OLD | NEW |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package state | 4 package state |
5 | 5 |
6 import ( | 6 import ( |
7 "errors" | 7 "errors" |
8 "fmt" | 8 "fmt" |
9 "labix.org/v2/mgo" | 9 "labix.org/v2/mgo" |
10 . "launchpad.net/gocheck" | 10 . "launchpad.net/gocheck" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 c.Assert(err, IsNil) | 78 c.Assert(err, IsNil) |
79 err = wordpress.SetConstraints(constraints.MustParse("mem=100M")) | 79 err = wordpress.SetConstraints(constraints.MustParse("mem=100M")) |
80 c.Assert(err, IsNil) | 80 c.Assert(err, IsNil) |
81 setServiceConfigAttr(c, wordpress, "blog-title", "boring") | 81 setServiceConfigAttr(c, wordpress, "blog-title", "boring") |
82 add(¶ms.ServiceInfo{ | 82 add(¶ms.ServiceInfo{ |
83 Name: "wordpress", | 83 Name: "wordpress", |
84 Exposed: true, | 84 Exposed: true, |
85 CharmURL: serviceCharmURL(wordpress).String(), | 85 CharmURL: serviceCharmURL(wordpress).String(), |
86 Life: params.Life(Alive.String()), | 86 Life: params.Life(Alive.String()), |
87 Constraints: constraints.MustParse("mem=100M"), | 87 Constraints: constraints.MustParse("mem=100M"), |
88 » » Config: map[string]interface{}{"blog-title": "boring"}, | 88 » » Config: charm.Settings{"blog-title": "boring"}, |
89 }) | 89 }) |
90 pairs := map[string]string{"x": "12", "y": "99"} | 90 pairs := map[string]string{"x": "12", "y": "99"} |
91 err = wordpress.SetAnnotations(pairs) | 91 err = wordpress.SetAnnotations(pairs) |
92 c.Assert(err, IsNil) | 92 c.Assert(err, IsNil) |
93 add(¶ms.AnnotationInfo{ | 93 add(¶ms.AnnotationInfo{ |
94 Tag: "service-wordpress", | 94 Tag: "service-wordpress", |
95 Annotations: pairs, | 95 Annotations: pairs, |
96 }) | 96 }) |
97 | 97 |
98 logging, err := s.State.AddService("logging", AddTestingCharm(c, s.State
, "logging")) | 98 logging, err := s.State.AddService("logging", AddTestingCharm(c, s.State
, "logging")) |
99 c.Assert(err, IsNil) | 99 c.Assert(err, IsNil) |
100 add(¶ms.ServiceInfo{ | 100 add(¶ms.ServiceInfo{ |
101 Name: "logging", | 101 Name: "logging", |
102 CharmURL: serviceCharmURL(logging).String(), | 102 CharmURL: serviceCharmURL(logging).String(), |
103 Life: params.Life(Alive.String()), | 103 Life: params.Life(Alive.String()), |
104 » » Config: map[string]interface{}{}, | 104 » » Config: charm.Settings{}, |
105 }) | 105 }) |
106 | 106 |
107 eps, err := s.State.InferEndpoints([]string{"logging", "wordpress"}) | 107 eps, err := s.State.InferEndpoints([]string{"logging", "wordpress"}) |
108 c.Assert(err, IsNil) | 108 c.Assert(err, IsNil) |
109 rel, err := s.State.AddRelation(eps...) | 109 rel, err := s.State.AddRelation(eps...) |
110 c.Assert(err, IsNil) | 110 c.Assert(err, IsNil) |
111 add(¶ms.RelationInfo{ | 111 add(¶ms.RelationInfo{ |
112 Key: "logging:logging-directory wordpress:logging-dir", | 112 Key: "logging:logging-directory wordpress:logging-dir", |
113 Endpoints: []params.Endpoint{ | 113 Endpoints: []params.Endpoint{ |
114 {ServiceName: "logging", Relation: charm.Relation{Name:
"logging-directory", Role: "requirer", Interface: "logging", Optional: false, Li
mit: 1, Scope: "container"}}, | 114 {ServiceName: "logging", Relation: charm.Relation{Name:
"logging-directory", Role: "requirer", Interface: "logging", Optional: false, Li
mit: 1, Scope: "container"}}, |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 change: watcher.Change{ | 404 change: watcher.Change{ |
405 C: "services", | 405 C: "services", |
406 Id: "wordpress", | 406 Id: "wordpress", |
407 }, | 407 }, |
408 expectContents: []params.EntityInfo{ | 408 expectContents: []params.EntityInfo{ |
409 ¶ms.ServiceInfo{ | 409 ¶ms.ServiceInfo{ |
410 Name: "wordpress", | 410 Name: "wordpress", |
411 Exposed: true, | 411 Exposed: true, |
412 CharmURL: "local:series/series-wordpress-3", | 412 CharmURL: "local:series/series-wordpress-3", |
413 Life: params.Life(Alive.String()), | 413 Life: params.Life(Alive.String()), |
414 » » » » Config: map[string]interface{}{}, | 414 » » » » Config: charm.Settings{}, |
415 }, | 415 }, |
416 }, | 416 }, |
417 }, { | 417 }, { |
418 about: "service is updated if it's in backing and in multiwatche
r.Store", | 418 about: "service is updated if it's in backing and in multiwatche
r.Store", |
419 add: []params.EntityInfo{¶ms.ServiceInfo{ | 419 add: []params.EntityInfo{¶ms.ServiceInfo{ |
420 Name: "wordpress", | 420 Name: "wordpress", |
421 Exposed: true, | 421 Exposed: true, |
422 CharmURL: "local:series/series-wordpress-3", | 422 CharmURL: "local:series/series-wordpress-3", |
423 Constraints: constraints.MustParse("mem=99M"), | 423 Constraints: constraints.MustParse("mem=99M"), |
424 » » » Config: map[string]interface{}{"blog-title": "borin
g"}, | 424 » » » Config: charm.Settings{"blog-title": "boring"}, |
425 }}, | 425 }}, |
426 setUp: func(c *C, st *State) { | 426 setUp: func(c *C, st *State) { |
427 svc, err := st.AddService("wordpress", AddTestingCharm(c
, st, "wordpress")) | 427 svc, err := st.AddService("wordpress", AddTestingCharm(c
, st, "wordpress")) |
428 c.Assert(err, IsNil) | 428 c.Assert(err, IsNil) |
429 setServiceConfigAttr(c, svc, "blog-title", "boring") | 429 setServiceConfigAttr(c, svc, "blog-title", "boring") |
430 }, | 430 }, |
431 change: watcher.Change{ | 431 change: watcher.Change{ |
432 C: "services", | 432 C: "services", |
433 Id: "wordpress", | 433 Id: "wordpress", |
434 }, | 434 }, |
435 expectContents: []params.EntityInfo{ | 435 expectContents: []params.EntityInfo{ |
436 ¶ms.ServiceInfo{ | 436 ¶ms.ServiceInfo{ |
437 Name: "wordpress", | 437 Name: "wordpress", |
438 CharmURL: "local:series/series-wordpress-3", | 438 CharmURL: "local:series/series-wordpress-3", |
439 Life: params.Life(Alive.String()), | 439 Life: params.Life(Alive.String()), |
440 Constraints: constraints.MustParse("mem=99M"), | 440 Constraints: constraints.MustParse("mem=99M"), |
441 » » » » Config: map[string]interface{}{"blog-title"
: "boring"}, | 441 » » » » Config: charm.Settings{"blog-title": "borin
g"}, |
442 }, | 442 }, |
443 }, | 443 }, |
444 }, { | 444 }, { |
445 about: "service re-reads config when charm URL changes", | 445 about: "service re-reads config when charm URL changes", |
446 add: []params.EntityInfo{¶ms.ServiceInfo{ | 446 add: []params.EntityInfo{¶ms.ServiceInfo{ |
447 Name: "wordpress", | 447 Name: "wordpress", |
448 // Note: CharmURL has a different revision number from | 448 // Note: CharmURL has a different revision number from |
449 // the wordpress revision in the testing repo. | 449 // the wordpress revision in the testing repo. |
450 CharmURL: "local:series/series-wordpress-2", | 450 CharmURL: "local:series/series-wordpress-2", |
451 » » » Config: map[string]interface{}{"foo": "bar"}, | 451 » » » Config: charm.Settings{"foo": "bar"}, |
452 }}, | 452 }}, |
453 setUp: func(c *C, st *State) { | 453 setUp: func(c *C, st *State) { |
454 svc, err := st.AddService("wordpress", AddTestingCharm(c
, st, "wordpress")) | 454 svc, err := st.AddService("wordpress", AddTestingCharm(c
, st, "wordpress")) |
455 c.Assert(err, IsNil) | 455 c.Assert(err, IsNil) |
456 » » » cfg, err := svc.Config() | 456 » » » setServiceConfigAttr(c, svc, "blog-title", "boring") |
457 » » » c.Assert(err, IsNil) | |
458 » » » cfg.Set("blog-title", "boring") | |
459 » » » _, err = cfg.Write() | |
460 » » » c.Assert(err, IsNil) | |
461 }, | 457 }, |
462 change: watcher.Change{ | 458 change: watcher.Change{ |
463 C: "services", | 459 C: "services", |
464 Id: "wordpress", | 460 Id: "wordpress", |
465 }, | 461 }, |
466 expectContents: []params.EntityInfo{ | 462 expectContents: []params.EntityInfo{ |
467 ¶ms.ServiceInfo{ | 463 ¶ms.ServiceInfo{ |
468 Name: "wordpress", | 464 Name: "wordpress", |
469 CharmURL: "local:series/series-wordpress-3", | 465 CharmURL: "local:series/series-wordpress-3", |
470 Life: params.Life(Alive.String()), | 466 Life: params.Life(Alive.String()), |
471 » » » » Config: map[string]interface{}{"blog-title": "
boring"}, | 467 » » » » Config: charm.Settings{"blog-title": "boring"}
, |
472 }, | 468 }, |
473 }, | 469 }, |
474 }, | 470 }, |
475 // Relation changes | 471 // Relation changes |
476 { | 472 { |
477 about: "no relation in state, no service in store -> do nothing"
, | 473 about: "no relation in state, no service in store -> do nothing"
, |
478 setUp: func(c *C, st *State) {}, | 474 setUp: func(c *C, st *State) {}, |
479 change: watcher.Change{ | 475 change: watcher.Change{ |
480 C: "relations", | 476 C: "relations", |
481 Id: "logging:logging-directory wordpress:logging-dir", | 477 Id: "logging:logging-directory wordpress:logging-dir", |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 }, | 747 }, |
752 expectContents: []params.EntityInfo{¶ms.ServiceInfo{ | 748 expectContents: []params.EntityInfo{¶ms.ServiceInfo{ |
753 Name: "wordpress", | 749 Name: "wordpress", |
754 CharmURL: "local:series/series-wordpress-3", | 750 CharmURL: "local:series/series-wordpress-3", |
755 }}, | 751 }}, |
756 }, { | 752 }, { |
757 about: "service config is changed if service exists in the store
with the same URL", | 753 about: "service config is changed if service exists in the store
with the same URL", |
758 add: []params.EntityInfo{¶ms.ServiceInfo{ | 754 add: []params.EntityInfo{¶ms.ServiceInfo{ |
759 Name: "wordpress", | 755 Name: "wordpress", |
760 CharmURL: "local:series/series-wordpress-3", | 756 CharmURL: "local:series/series-wordpress-3", |
761 » » » Config: map[string]interface{}{"foo": "bar"}, | 757 » » » Config: charm.Settings{"foo": "bar"}, |
762 }}, | 758 }}, |
763 setUp: func(c *C, st *State) { | 759 setUp: func(c *C, st *State) { |
764 svc, err := st.AddService("wordpress", AddTestingCharm(c
, st, "wordpress")) | 760 svc, err := st.AddService("wordpress", AddTestingCharm(c
, st, "wordpress")) |
765 c.Assert(err, IsNil) | 761 c.Assert(err, IsNil) |
766 setServiceConfigAttr(c, svc, "blog-title", "foo") | 762 setServiceConfigAttr(c, svc, "blog-title", "foo") |
767 }, | 763 }, |
768 change: watcher.Change{ | 764 change: watcher.Change{ |
769 C: "settings", | 765 C: "settings", |
770 Id: "s#wordpress#local:series/series-wordpress-3", | 766 Id: "s#wordpress#local:series/series-wordpress-3", |
771 }, | 767 }, |
772 expectContents: []params.EntityInfo{ | 768 expectContents: []params.EntityInfo{ |
773 ¶ms.ServiceInfo{ | 769 ¶ms.ServiceInfo{ |
774 Name: "wordpress", | 770 Name: "wordpress", |
775 CharmURL: "local:series/series-wordpress-3", | 771 CharmURL: "local:series/series-wordpress-3", |
776 » » » » Config: map[string]interface{}{"blog-title": "
foo"}, | 772 » » » » Config: charm.Settings{"blog-title": "foo"}, |
777 }, | 773 }, |
778 }, | 774 }, |
779 }, { | 775 }, { |
780 about: "service config is unchanged if service exists in the sto
re with a different URL", | 776 about: "service config is unchanged if service exists in the sto
re with a different URL", |
781 add: []params.EntityInfo{¶ms.ServiceInfo{ | 777 add: []params.EntityInfo{¶ms.ServiceInfo{ |
782 Name: "wordpress", | 778 Name: "wordpress", |
783 CharmURL: "local:series/series-wordpress-2", // Note dif
ferent revno. | 779 CharmURL: "local:series/series-wordpress-2", // Note dif
ferent revno. |
784 » » » Config: map[string]interface{}{"foo": "bar"}, | 780 » » » Config: charm.Settings{"foo": "bar"}, |
785 }}, | 781 }}, |
786 setUp: func(c *C, st *State) { | 782 setUp: func(c *C, st *State) { |
787 svc, err := st.AddService("wordpress", AddTestingCharm(c
, st, "wordpress")) | 783 svc, err := st.AddService("wordpress", AddTestingCharm(c
, st, "wordpress")) |
788 c.Assert(err, IsNil) | 784 c.Assert(err, IsNil) |
789 setServiceConfigAttr(c, svc, "blog-title", "foo") | 785 setServiceConfigAttr(c, svc, "blog-title", "foo") |
790 }, | 786 }, |
791 change: watcher.Change{ | 787 change: watcher.Change{ |
792 C: "settings", | 788 C: "settings", |
793 Id: "s#wordpress#local:series/series-wordpress-3", | 789 Id: "s#wordpress#local:series/series-wordpress-3", |
794 }, | 790 }, |
795 expectContents: []params.EntityInfo{ | 791 expectContents: []params.EntityInfo{ |
796 ¶ms.ServiceInfo{ | 792 ¶ms.ServiceInfo{ |
797 Name: "wordpress", | 793 Name: "wordpress", |
798 CharmURL: "local:series/series-wordpress-2", | 794 CharmURL: "local:series/series-wordpress-2", |
799 » » » » Config: map[string]interface{}{"foo": "bar"}, | 795 » » » » Config: charm.Settings{"foo": "bar"}, |
800 }, | 796 }, |
801 }, | 797 }, |
802 }, { | 798 }, { |
803 about: "non-service config change is ignored", | 799 about: "non-service config change is ignored", |
804 setUp: func(*C, *State) {}, | 800 setUp: func(*C, *State) {}, |
805 change: watcher.Change{ | 801 change: watcher.Change{ |
806 C: "settings", | 802 C: "settings", |
807 Id: "m#0", | 803 Id: "m#0", |
808 }, | 804 }, |
809 }, { | 805 }, { |
810 about: "service config change with no charm url is ignored", | 806 about: "service config change with no charm url is ignored", |
811 setUp: func(*C, *State) {}, | 807 setUp: func(*C, *State) {}, |
812 change: watcher.Change{ | 808 change: watcher.Change{ |
813 C: "settings", | 809 C: "settings", |
814 Id: "s#foo", | 810 Id: "s#foo", |
815 }, | 811 }, |
816 }, | 812 }, |
817 } | 813 } |
818 | 814 |
819 func setServiceConfigAttr(c *C, svc *Service, attr string, val interface{}) { | 815 func setServiceConfigAttr(c *C, svc *Service, attr string, val interface{}) { |
820 » cfg, err := svc.Config() | 816 » err := svc.UpdateConfigSettings(charm.Settings{attr: val}) |
821 » c.Assert(err, IsNil) | |
822 » cfg.Set("blog-title", val) | |
823 » _, err = cfg.Write() | |
824 c.Assert(err, IsNil) | 817 c.Assert(err, IsNil) |
825 } | 818 } |
826 | 819 |
827 func (s *storeManagerStateSuite) TestChanged(c *C) { | 820 func (s *storeManagerStateSuite) TestChanged(c *C) { |
828 collections := map[string]*mgo.Collection{ | 821 collections := map[string]*mgo.Collection{ |
829 "machines": s.State.machines, | 822 "machines": s.State.machines, |
830 "units": s.State.units, | 823 "units": s.State.units, |
831 "services": s.State.services, | 824 "services": s.State.services, |
832 "relations": s.State.relations, | 825 "relations": s.State.relations, |
833 "annotations": s.State.annotations, | 826 "annotations": s.State.annotations, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 panic(fmt.Errorf("%v mentioned twice in delta set", id)) | 984 panic(fmt.Errorf("%v mentioned twice in delta set", id)) |
992 } | 985 } |
993 if d.Removed { | 986 if d.Removed { |
994 m[id] = nil | 987 m[id] = nil |
995 } else { | 988 } else { |
996 m[id] = d.Entity | 989 m[id] = d.Entity |
997 } | 990 } |
998 } | 991 } |
999 return m | 992 return m |
1000 } | 993 } |
OLD | NEW |