func (s *charmVersionSuite) TestEnvironmentUUIDUsed(c *gc.C) { s.AddMachine(c, "0", state.JobManageModel) s.SetupScenario(c) // Set up a charm store server that stores the request header. var header http.Header received := false srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // the first request is the one with the UUID. if !received { header = r.Header received = true } s.Handler.ServeHTTP(w, r) })) defer srv.Close() // Point the charm repo initializer to the testing server. s.PatchValue(&charmrevisionupdater.NewCharmStoreClient, func() charmstore.Client { var config charmstore.ClientConfig csURL, err := url.Parse(srv.URL) c.Assert(err, jc.ErrorIsNil) config.URL = csURL return charmstore.NewClient(config) }) result, err := s.charmrevisionupdater.UpdateLatestRevisions() c.Assert(err, jc.ErrorIsNil) c.Assert(result.Error, gc.IsNil) env, err := s.State.Model() c.Assert(err, jc.ErrorIsNil) c.Assert(header.Get(charmrepo.JujuMetadataHTTPHeader), gc.Equals, "environment_uuid="+env.UUID()) }
// Connect implements CharmstoreSpec. func (cs charmstoreSpec) Connect(ctx *cmd.Context) (charmstore.Client, io.Closer, error) { // Note that creating the API context in Connect is technically // wrong, as it means we'll be creating the bakery context // (and reading/writing the cookies) each time it's called. // TODO(ericsnow) Move apiContext to a field on charmstoreSpec. apiContext, err := modelcmd.NewAPIContext(ctx) if err != nil { return charmstore.Client{}, nil, errors.Trace(err) } // We use the default for URL. client := charmstore.NewClient(charmstore.ClientConfig{ BakeryClient: apiContext.BakeryClient, }) return client, apiContext, nil }
func (s *CharmSuite) SetUpTest(c *gc.C) { db := s.jcSuite.Session.DB("juju-testing") params := charmstore.ServerParams{ AuthUsername: "******", AuthPassword: "******", } handler, err := charmstore.NewServer(db, nil, "", params, charmstore.V5) c.Assert(err, jc.ErrorIsNil) s.Handler = handler s.Server = httptest.NewServer(handler) s.Client = csclient.New(csclient.Params{ URL: s.Server.URL, User: params.AuthUsername, Password: params.AuthPassword, }) urls := map[string]string{ "mysql": "quantal/mysql-23", "dummy": "quantal/dummy-24", "riak": "quantal/riak-25", "wordpress": "quantal/wordpress-26", "logging": "quantal/logging-27", } for name, url := range urls { testcharms.UploadCharm(c, s.Client, url, name) } s.jcSuite.PatchValue(&charmrepo.CacheDir, c.MkDir()) // Patch the charm repo initializer function: it is replaced with a charm // store repo pointing to the testing server. s.jcSuite.PatchValue(&charmrevisionupdater.NewCharmStoreClient, func() jujucharmstore.Client { var config jujucharmstore.ClientConfig csURL, err := url.Parse(s.Server.URL) c.Assert(err, jc.ErrorIsNil) config.URL = csURL return jujucharmstore.NewClient(config) }) s.charms = make(map[string]*state.Charm) }
// Then run through the handlers. serviceID := info.service.ServiceTag() for _, handler := range handlers { if err := handler.HandleLatest(serviceID, info.CharmInfo); err != nil { return err } } } return nil } // NewCharmStoreClient instantiates a new charm store repository. Exported so // we can change it during testing. var NewCharmStoreClient = func() charmstore.Client { return charmstore.NewClient(charmstore.ClientConfig{}) } type latestCharmInfo struct { charmstore.CharmInfo service *state.Service } // retrieveLatestCharmInfo looks up the charm store to return the charm URLs for the // latest revision of the deployed charms. func retrieveLatestCharmInfo(st *state.State) ([]latestCharmInfo, error) { // First get the uuid for the environment to use when querying the charm store. env, err := st.Model() if err != nil { return nil, err }