func NewPeerRelation(c *gc.C, st *state.State, owner names.UserTag) *PeerRelation { svc := state.AddTestingService(c, st, "riak", state.AddTestingCharm(c, st, "riak"), owner) ep, err := svc.Endpoint("ring") c.Assert(err, jc.ErrorIsNil) rel, err := st.EndpointsRelation(ep) c.Assert(err, jc.ErrorIsNil) pr := &PeerRelation{rel: rel, svc: svc} pr.u0, pr.ru0 = addRU(c, svc, rel, nil) pr.u1, pr.ru1 = addRU(c, svc, rel, nil) pr.u2, pr.ru2 = addRU(c, svc, rel, nil) pr.u3, pr.ru3 = addRU(c, svc, rel, nil) return pr }
func (s *MigrationImportSuite) TestRelations(c *gc.C) { // Need to remove owner from service. ignored := s.Owner wordpress := state.AddTestingService(c, s.State, "wordpress", state.AddTestingCharm(c, s.State, "wordpress"), ignored) state.AddTestingService(c, s.State, "mysql", state.AddTestingCharm(c, s.State, "mysql"), ignored) eps, err := s.State.InferEndpoints("mysql", "wordpress") c.Assert(err, jc.ErrorIsNil) rel, err := s.State.AddRelation(eps...) c.Assert(err, jc.ErrorIsNil) wordpress_0 := s.Factory.MakeUnit(c, &factory.UnitParams{Service: wordpress}) ru, err := rel.Unit(wordpress_0) c.Assert(err, jc.ErrorIsNil) relSettings := map[string]interface{}{ "name": "wordpress/0", } err = ru.EnterScope(relSettings) c.Assert(err, jc.ErrorIsNil) _, newSt := s.importModel(c) defer newSt.Close() newWordpress, err := newSt.Service("wordpress") c.Assert(err, jc.ErrorIsNil) c.Assert(state.RelationCount(newWordpress), gc.Equals, 1) rels, err := newWordpress.Relations() c.Assert(err, jc.ErrorIsNil) c.Assert(rels, gc.HasLen, 1) units, err := newWordpress.AllUnits() c.Assert(err, jc.ErrorIsNil) c.Assert(units, gc.HasLen, 1) ru, err = rels[0].Unit(units[0]) c.Assert(err, jc.ErrorIsNil) settings, err := ru.Settings() c.Assert(err, jc.ErrorIsNil) c.Assert(settings.Map(), gc.DeepEquals, relSettings) }
func (s *ConnSuite) AddTestingCharm(c *gc.C, name string) *state.Charm { return state.AddTestingCharm(c, s.State, name) }
func (s *MigrationExportSuite) TestRelations(c *gc.C) { wordpress := state.AddTestingService(c, s.State, "wordpress", state.AddTestingCharm(c, s.State, "wordpress")) mysql := state.AddTestingService(c, s.State, "mysql", state.AddTestingCharm(c, s.State, "mysql")) // InferEndpoints will always return provider, requirer eps, err := s.State.InferEndpoints("mysql", "wordpress") c.Assert(err, jc.ErrorIsNil) rel, err := s.State.AddRelation(eps...) msEp, wpEp := eps[0], eps[1] c.Assert(err, jc.ErrorIsNil) wordpress_0 := s.Factory.MakeUnit(c, &factory.UnitParams{Application: wordpress}) mysql_0 := s.Factory.MakeUnit(c, &factory.UnitParams{Application: mysql}) ru, err := rel.Unit(wordpress_0) c.Assert(err, jc.ErrorIsNil) wordpressSettings := map[string]interface{}{ "name": "wordpress/0", } err = ru.EnterScope(wordpressSettings) c.Assert(err, jc.ErrorIsNil) ru, err = rel.Unit(mysql_0) c.Assert(err, jc.ErrorIsNil) mysqlSettings := map[string]interface{}{ "name": "mysql/0", } err = ru.EnterScope(mysqlSettings) c.Assert(err, jc.ErrorIsNil) model, err := s.State.Export() c.Assert(err, jc.ErrorIsNil) rels := model.Relations() c.Assert(rels, gc.HasLen, 1) exRel := rels[0] c.Assert(exRel.Id(), gc.Equals, rel.Id()) c.Assert(exRel.Key(), gc.Equals, rel.String()) exEps := exRel.Endpoints() c.Assert(exEps, gc.HasLen, 2) checkEndpoint := func( exEndpoint description.Endpoint, unitName string, ep state.Endpoint, settings map[string]interface{}, ) { c.Logf("%#v", exEndpoint) c.Check(exEndpoint.ApplicationName(), gc.Equals, ep.ApplicationName) c.Check(exEndpoint.Name(), gc.Equals, ep.Name) c.Check(exEndpoint.UnitCount(), gc.Equals, 1) c.Check(exEndpoint.Settings(unitName), jc.DeepEquals, settings) c.Check(exEndpoint.Role(), gc.Equals, string(ep.Role)) c.Check(exEndpoint.Interface(), gc.Equals, ep.Interface) c.Check(exEndpoint.Optional(), gc.Equals, ep.Optional) c.Check(exEndpoint.Limit(), gc.Equals, ep.Limit) c.Check(exEndpoint.Scope(), gc.Equals, string(ep.Scope)) } checkEndpoint(exEps[0], mysql_0.Name(), msEp, mysqlSettings) checkEndpoint(exEps[1], wordpress_0.Name(), wpEp, wordpressSettings) }