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(st *state.State) (jujucharmstore.Client, error) { csURL, err := url.Parse(s.Server.URL) c.Assert(err, jc.ErrorIsNil) return jujucharmstore.NewCachingClient(state.MacaroonCache{st}, csURL) }) s.charms = make(map[string]*state.Charm) }
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(st *state.State) (charmstore.Client, error) { csURL, err := url.Parse(srv.URL) c.Assert(err, jc.ErrorIsNil) return charmstore.NewCachingClient(state.MacaroonCache{st}, csURL) }) 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()) }
func (s *charmVersionSuite) TestJujuMetadataHeaderIsSent(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(st *state.State) (charmstore.Client, error) { csURL, err := url.Parse(srv.URL) c.Assert(err, jc.ErrorIsNil) return charmstore.NewCachingClient(state.MacaroonCache{st}, csURL) }) 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) cloud, err := s.State.Cloud(env.Cloud()) c.Assert(err, jc.ErrorIsNil) expected_header := []string{ "environment_uuid=" + env.UUID(), "cloud=" + env.Cloud(), "cloud_region=" + env.CloudRegion(), "provider=" + cloud.Type, "controller_version=" + version.Current.String(), } for i, expected := range expected_header { c.Assert(header[charmrepo.JujuMetadataHTTPHeader][i], gc.Equals, expected) } }
// 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(st *state.State) (charmstore.Client, error) { return charmstore.NewCachingClient(state.MacaroonCache{st}, nil) } 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 }
func newCharmStoreClient(st *state.State) (charmstore.Client, error) { return charmstore.NewCachingClient(state.MacaroonCache{st}, nil) }