Exemple #1
0
// createInternalVicContainer() creates an container representation (for docker personality)
// This is called by ContainerCreate()
func createInternalVicContainer(image *metadata.ImageConfig, config *types.ContainerCreateConfig) (*viccontainer.VicContainer, error) {
	// provide basic container config via the image
	container := viccontainer.NewVicContainer()
	container.ImageID = image.ID
	container.Config = image.Config //Set defaults.  Overrides will get copied below.

	return container, nil
}
Exemple #2
0
func TestPortInformation(t *testing.T) {
	mockContainerInfo := &plmodels.ContainerInfo{}
	mockContainerConfig := &plmodels.ContainerConfig{}
	containerID := "foo"
	mockContainerConfig.ContainerID = &containerID

	mockHostConfig := &container.HostConfig{}

	portMap := nat.PortMap{}
	port, _ := nat.NewPort("tcp", "80")
	portBinding := nat.PortBinding{
		HostIP:   "127.0.0.1",
		HostPort: "8000",
	}
	portBindings := []nat.PortBinding{portBinding}
	portMap[port] = portBindings
	mockHostConfig.PortBindings = portMap

	mockContainerInfo.ContainerConfig = mockContainerConfig

	ip, _ := netlink.ParseAddr("192.168.1.1/24")
	ips := []netlink.Addr{*ip}

	co := viccontainer.NewVicContainer()
	co.HostConfig = mockHostConfig
	co.ContainerID = containerID
	co.Name = "bar"
	cache.ContainerCache().AddContainer(co)

	ports := portInformation(mockContainerInfo, ips)

	assert.NotEmpty(t, ports, "There should be bound IPs")
	assert.Equal(t, len(ports), 1, "Expected 1 port binding, found %d", len(ports))

	port, _ = nat.NewPort("tcp", "80")
	portBinding = nat.PortBinding{
		HostIP:   "127.0.0.1",
		HostPort: "00",
	}
	portMap[port] = portBindings
	ports = portInformation(mockContainerInfo, ips)
	assert.NotEmpty(t, ports, "There should be 1 bound IP")
	assert.Equal(t, len(ports), 1, "Expected 1 port binding, found %d", len(ports))

	port, _ = nat.NewPort("tcp", "800")
	portBinding = nat.PortBinding{
		HostIP:   "127.0.0.1",
		HostPort: "800",
	}
	portMap[port] = portBindings
	ports = portInformation(mockContainerInfo, ips)
	assert.Equal(t, len(ports), 2, "Expected 2 port binding, found %d", len(ports))
}
Exemple #3
0
func AddMockContainerToCache() {
	AddMockImageToCache()

	image, err := cache.ImageCache().GetImage("e732471cb81a564575aad46b9510161c5945deaf18e9be3db344333d72f0b4b2")
	if err == nil {
		vc := viccontainer.NewVicContainer()
		vc.ImageID = image.ID
		vc.Config = image.Config //Set defaults.  Overrides will get copied below.
		vc.Config.Tty = false
		vc.ContainerID = dummyContainerID

		cache.ContainerCache().AddContainer(vc)

		vc = viccontainer.NewVicContainer()
		vc.ImageID = image.ID
		vc.Config = image.Config
		vc.Config.Tty = true
		vc.ContainerID = dummyContainerID_tty

		cache.ContainerCache().AddContainer(vc)
	}
}