Example #1
0
func load() error {
	var confPath string
	if len(os.Args) == 2 {
		if _, err := os.Stat(os.Args[1]); err == nil {
			confPath = os.Args[1]
		}
	}
	if confPath == "" {
		return fmt.Errorf("usage: %s <config path>", filepath.Base(os.Args[0]))
	}
	conf, err := charmstore.ReadConfig(confPath)
	if err != nil {
		return err
	}
	if conf.MongoURL == "" {
		return fmt.Errorf("missing mongo-url in config file")
	}
	s, err := charmstore.Open(conf.MongoURL)
	if err != nil {
		return err
	}
	defer s.Close()
	err = charmstore.PublishCharmsDistro(s, lpad.Production)
	if _, ok := err.(charmstore.PublishBranchErrors); ok {
		// Ignore branch errors since they're commonplace here.
		// They're logged, though.
		return nil
	}
	return err
}
Example #2
0
func (c *DeleteCharmCommand) Run(ctx *cmd.Context) error {
	// Read config
	err := c.ConfigCommand.ReadConfig(ctx)
	if err != nil {
		return err
	}

	// Parse the charm URL
	charmUrl, err := charm.ParseURL(c.Url)
	if err != nil {
		return err
	}

	// Open the charm store storage
	s, err := charmstore.Open(c.Config.MongoURL)
	if err != nil {
		return err
	}
	defer s.Close()

	// Delete the charm by URL
	_, err = s.DeleteCharm(charmUrl)
	if err != nil {
		return err
	}
	fmt.Fprintln(ctx.Stdout, "Charm", charmUrl, "deleted.")
	return nil
}
Example #3
0
func serve() error {
	var confPath string
	if len(os.Args) == 2 {
		if _, err := os.Stat(os.Args[1]); err == nil {
			confPath = os.Args[1]
		}
	}
	if confPath == "" {
		return fmt.Errorf("usage: %s <config path>", filepath.Base(os.Args[0]))
	}
	conf, err := charmstore.ReadConfig(confPath)
	if err != nil {
		return err
	}
	if conf.MongoURL == "" || conf.APIAddr == "" {
		return fmt.Errorf("missing mongo-url or api-addr in config file")
	}
	s, err := charmstore.Open(conf.MongoURL)
	if err != nil {
		return err
	}
	defer s.Close()
	server, err := charmstore.NewServer(s)
	if err != nil {
		return err
	}
	return http.ListenAndServe(conf.APIAddr, server)
}
Example #4
0
func (s *StoreSuite) SetUpTest(c *gc.C) {
	s.FakeHomeSuite.SetUpTest(c)
	s.MgoSuite.SetUpTest(c)
	s.HTTPSuite.SetUpTest(c)
	var err error
	s.store, err = charmstore.Open(gitjujutesting.MgoServer.Addr())
	c.Assert(err, gc.IsNil)
}
Example #5
0
func (s *DeleteCharmSuite) TestRun(c *gc.C) {
	// Derive config file from test mongo port
	confDir := c.MkDir()
	f, err := os.Create(path.Join(confDir, "charmd.conf"))
	c.Assert(err, gc.IsNil)
	configPath := f.Name()
	{
		defer f.Close()
		fmt.Fprintf(f, "mongo-url: %s\n", gitjujutesting.MgoServer.Addr())
	}
	// Delete charm that does not exist, not found error.
	config := &DeleteCharmCommand{}
	out, err := testing.RunCommand(c, config, "--config", configPath, "--url", "cs:unreleased/foo")
	fmt.Println(out)
	c.Assert(err, gc.NotNil)
	// Publish that charm now
	url := charm.MustParseURL("cs:unreleased/foo")
	{
		s, err := charmstore.Open(gitjujutesting.MgoServer.Addr())
		defer s.Close()
		c.Assert(err, gc.IsNil)
		pub, err := s.CharmPublisher([]*charm.URL{url}, "such-digest-much-unique")
		c.Assert(err, gc.IsNil)
		err = pub.Publish(charmtesting.Charms.ClonedDir(c.MkDir(), "dummy"))
		c.Assert(err, gc.IsNil)
	}
	// Delete charm, should now succeed
	_, err = testing.RunCommand(c, config, "--config", configPath, "--url", "cs:unreleased/foo")
	c.Assert(err, gc.IsNil)
	c.Assert(config.Config, gc.NotNil)
	// Confirm that the charm is gone
	{
		s, err := charmstore.Open(gitjujutesting.MgoServer.Addr())
		defer s.Close()
		c.Assert(err, gc.IsNil)
		_, err = s.CharmInfo(url)
		c.Assert(err, gc.NotNil)
	}
}
Example #6
0
func (s *deleteCharmSuite) TestRunFound(c *gc.C) {
	configPath := s.createConfigFile(c)

	// Publish that charm.
	url := charm.MustParseURL("cs:unreleased/foo")
	store, err := charmstore.Open(gitjujutesting.MgoServer.Addr())
	c.Assert(err, gc.IsNil)
	defer store.Close()
	pub, err := store.CharmPublisher([]*charm.URL{url}, "such-digest-much-unique")
	c.Assert(err, gc.IsNil)
	err = pub.Publish(charmtesting.Charms.ClonedDir(c.MkDir(), "dummy"))
	c.Assert(err, gc.IsNil)

	// The charm is successfully deleted.
	config := &DeleteCharmCommand{}
	_, err = cmdtesting.RunCommand(c, config, "--config", configPath, "--url", "cs:unreleased/foo")
	c.Assert(err, gc.IsNil)
	c.Assert(config.Config, gc.NotNil)

	// Confirm that the charm is gone
	_, err = store.CharmInfo(url)
	c.Assert(err, gc.Equals, charmstore.ErrNotFound)
}
Example #7
0
func (s *StoreSuite) TestListCounters(c *gc.C) {
	if *noTestMongoJs {
		c.Skip("MongoDB javascript not available")
	}

	incs := [][]string{
		{"c", "b", "a"}, // Assign internal id c < id b < id a, to make sorting slightly trickier.
		{"a"},
		{"a", "c"},
		{"a", "b"},
		{"a", "b", "c"},
		{"a", "b", "c"},
		{"a", "b", "e"},
		{"a", "b", "d"},
		{"a", "f", "g"},
		{"a", "f", "h"},
		{"a", "i"},
		{"a", "i", "j"},
		{"k", "l"},
	}
	for _, key := range incs {
		err := s.store.IncCounter(key)
		c.Assert(err, gc.IsNil)
	}

	tests := []struct {
		prefix []string
		result []charmstore.Counter
	}{
		{
			[]string{"a"},
			[]charmstore.Counter{
				{Key: []string{"a", "b"}, Prefix: true, Count: 4},
				{Key: []string{"a", "f"}, Prefix: true, Count: 2},
				{Key: []string{"a", "b"}, Prefix: false, Count: 1},
				{Key: []string{"a", "c"}, Prefix: false, Count: 1},
				{Key: []string{"a", "i"}, Prefix: false, Count: 1},
				{Key: []string{"a", "i"}, Prefix: true, Count: 1},
			},
		}, {
			[]string{"a", "b"},
			[]charmstore.Counter{
				{Key: []string{"a", "b", "c"}, Prefix: false, Count: 2},
				{Key: []string{"a", "b", "d"}, Prefix: false, Count: 1},
				{Key: []string{"a", "b", "e"}, Prefix: false, Count: 1},
			},
		}, {
			[]string{"z"},
			[]charmstore.Counter(nil),
		},
	}

	// Use a different store to exercise cache filling.
	st, err := charmstore.Open(gitjujutesting.MgoServer.Addr())
	c.Assert(err, gc.IsNil)
	defer st.Close()

	for i := range tests {
		req := &charmstore.CounterRequest{Key: tests[i].prefix, Prefix: true, List: true}
		result, err := st.Counters(req)
		c.Assert(err, gc.IsNil)
		c.Assert(result, gc.DeepEquals, tests[i].result)
	}
}