Exemple #1
0
func (s *S) TestFixContainer(c *check.C) {
	cleanup, server, p := startDocker("9999")
	defer cleanup()
	coll := p.Collection()
	defer coll.Close()
	cont := container.Container{
		ID:       "9930c24f1c4x",
		AppName:  "makea",
		Type:     "python",
		Status:   provision.StatusStarted.String(),
		IP:       "127.0.0.4",
		HostPort: "9025",
		HostAddr: "127.0.0.1",
	}
	err := coll.Insert(cont)
	c.Assert(err, check.IsNil)
	defer coll.RemoveAll(bson.M{"appname": cont.AppName})
	err = s.storage.Apps().Insert(&app.App{Name: cont.AppName})
	c.Assert(err, check.IsNil)
	appInstance := provisiontest.NewFakeApp(cont.AppName, cont.Type, 0)
	defer p.Destroy(appInstance)
	p.Provision(appInstance)
	var storage cluster.MapStorage
	storage.StoreContainer(cont.ID, server.URL)
	p.cluster, err = cluster.New(nil, &storage,
		cluster.Node{Address: server.URL},
	)
	c.Assert(err, check.IsNil)
	info, err := cont.NetworkInfo(p)
	c.Assert(err, check.IsNil)
	err = p.fixContainer(&cont, info)
	c.Assert(err, check.IsNil)
	conta, err := p.GetContainer("9930c24f1c4x")
	c.Assert(err, check.IsNil)
	c.Assert(conta.IP, check.Equals, "127.0.0.9")
	c.Assert(conta.HostPort, check.Equals, "9999")
}
Exemple #2
0
func (p *dockerProvisioner) checkContainer(container *container.Container) error {
	if container.Available() {
		info, err := container.NetworkInfo(p)
		if err != nil {
			return err
		}
		if info.HTTPHostPort != container.HostPort || info.IP != container.IP {
			err = p.fixContainer(container, info)
			if err != nil {
				log.Errorf("error on fix container hostport for [container %s]", container.ID)
				return err
			}
		}
	}
	return nil
}