Merge pull request #5374 from baude/create

add default network for apiv2 create
This commit is contained in:
OpenShift Merge Robot
2020-03-07 14:16:43 +01:00
committed by GitHub
14 changed files with 329 additions and 190 deletions

View File

@ -138,6 +138,7 @@ func before(cmd *cobra.Command, args []string) error {
logrus.Info("running as rootless") logrus.Info("running as rootless")
} }
setUMask() setUMask()
return profileOn(cmd) return profileOn(cmd)
} }

View File

@ -18,7 +18,7 @@ exithandler() {
echo "$(basename $0) exit status: $RET" echo "$(basename $0) exit status: $RET"
[[ "$RET" -eq "0" ]] && date +%s >> "$SETUP_MARKER_FILEPATH" [[ "$RET" -eq "0" ]] && date +%s >> "$SETUP_MARKER_FILEPATH"
show_env_vars show_env_vars
[ "$RET" -eq "0" ]] || warn "Non-zero exit caused by error ABOVE env. var. display." [[ "$RET" -eq "0" ]] || warn "Non-zero exit caused by error ABOVE env. var. display."
} }
trap exithandler EXIT trap exithandler EXIT

View File

@ -10,6 +10,7 @@ import (
"github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/events" "github.com/containers/libpod/libpod/events"
"github.com/containers/libpod/pkg/cgroups"
"github.com/containers/libpod/pkg/rootless" "github.com/containers/libpod/pkg/rootless"
"github.com/containers/storage/pkg/stringid" "github.com/containers/storage/pkg/stringid"
spec "github.com/opencontainers/runtime-spec/specs-go" spec "github.com/opencontainers/runtime-spec/specs-go"
@ -438,9 +439,16 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool,
if err := c.ociRuntime.KillContainer(c, 9, false); err != nil { if err := c.ociRuntime.KillContainer(c, 9, false); err != nil {
return err return err
} }
if err := c.unpause(); err != nil { isV2, err := cgroups.IsCgroup2UnifiedMode()
if err != nil {
return err return err
} }
// cgroups v1 and v2 handle signals on paused processes differently
if !isV2 {
if err := c.unpause(); err != nil {
return err
}
}
// Need to update container state to make sure we know it's stopped // Need to update container state to make sure we know it's stopped
if err := c.waitForExitFileAndSync(); err != nil { if err := c.waitForExitFileAndSync(); err != nil {
return err return err

View File

@ -72,7 +72,6 @@ func UnpauseContainer(w http.ResponseWriter, r *http.Request) {
return return
} }
// the api does not error if the Container is already paused, so just into it
if err := con.Unpause(); err != nil { if err := con.Unpause(); err != nil {
utils.InternalServerError(w, err) utils.InternalServerError(w, err)
return return

View File

@ -968,6 +968,50 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// 500: // 500:
// $ref: '#/responses/InternalError' // $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name:.*}/tag"), s.APIHandler(handlers.TagImage)).Methods(http.MethodPost) r.Handle(VersionedPath("/libpod/images/{name:.*}/tag"), s.APIHandler(handlers.TagImage)).Methods(http.MethodPost)
// swagger:operation POST /commit libpod libpodCommitContainer
// ---
// tags:
// - containers
// summary: Commit
// description: Create a new image from a container
// parameters:
// - in: query
// name: container
// type: string
// description: the name or ID of a container
// - in: query
// name: repo
// type: string
// description: the repository name for the created image
// - in: query
// name: tag
// type: string
// description: tag name for the created image
// - in: query
// name: comment
// type: string
// description: commit message
// - in: query
// name: author
// type: string
// description: author of the image
// - in: query
// name: pause
// type: boolean
// description: pause the container before committing it
// - in: query
// name: changes
// type: string
// description: instructions to apply while committing in Dockerfile format
// produces:
// - application/json
// responses:
// 201:
// description: no error
// 404:
// $ref: '#/responses/NoSuchImage'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/commit"), s.APIHandler(generic.CommitContainer)).Methods(http.MethodPost)
return nil return nil
} }

View File

@ -11,7 +11,7 @@ import (
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
) )
func CreateWithSpec(ctx context.Context, s specgen.SpecGenerator) (utils.ContainerCreateResponse, error) { func CreateWithSpec(ctx context.Context, s *specgen.SpecGenerator) (utils.ContainerCreateResponse, error) {
var ccr utils.ContainerCreateResponse var ccr utils.ContainerCreateResponse
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {

View File

@ -1,6 +1,7 @@
package test_bindings package test_bindings
import ( import (
"context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -8,6 +9,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
. "github.com/containers/libpod/pkg/bindings"
"github.com/containers/libpod/pkg/bindings/containers"
"github.com/containers/libpod/pkg/specgen"
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
"github.com/onsi/gomega/gexec" "github.com/onsi/gomega/gexec"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -55,6 +59,16 @@ type bindingTest struct {
tempDirPath string tempDirPath string
runRoot string runRoot string
crioRoot string crioRoot string
conn context.Context
}
func (b *bindingTest) NewConnection() error {
connText, err := NewConnection(context.Background(), b.sock)
if err != nil {
return err
}
b.conn = connText
return nil
} }
func (b *bindingTest) runPodman(command []string) *gexec.Session { func (b *bindingTest) runPodman(command []string) *gexec.Session {
@ -173,17 +187,27 @@ func (b *bindingTest) restoreImageFromCache(i testImage) {
// Run a container within or without a pod // Run a container within or without a pod
// and add or append the alpine image to it // and add or append the alpine image to it
func (b *bindingTest) RunTopContainer(containerName *string, insidePod *bool, podName *string) { func (b *bindingTest) RunTopContainer(containerName *string, insidePod *bool, podName *string) (string, error) {
cmd := []string{"run", "-dt"} s := specgen.NewSpecGenerator(alpine.name)
if insidePod != nil && podName != nil { s.Terminal = false
pName := *podName s.Command = []string{"top"}
cmd = append(cmd, "--pod", pName) if containerName != nil {
} else if containerName != nil { s.Name = *containerName
cName := *containerName
cmd = append(cmd, "--name", cName)
} }
cmd = append(cmd, alpine.name, "top") if insidePod != nil && podName != nil {
b.runPodman(cmd).Wait(45) s.Pod = *podName
}
ctr, err := containers.CreateWithSpec(b.conn, s)
if err != nil {
return "", nil
}
err = containers.Start(b.conn, ctr.ID, nil)
if err != nil {
return "", err
}
waiting := "running"
_, err = containers.Wait(b.conn, ctr.ID, &waiting)
return ctr.ID, err
} }
// This method creates a pod with the given pod name. // This method creates a pod with the given pod name.

View File

@ -1,7 +1,6 @@
package test_bindings package test_bindings
import ( import (
"context"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@ -18,7 +17,6 @@ var _ = Describe("Podman containers ", func() {
var ( var (
bt *bindingTest bt *bindingTest
s *gexec.Session s *gexec.Session
connText context.Context
err error err error
falseFlag bool = false falseFlag bool = false
trueFlag bool = true trueFlag bool = true
@ -29,18 +27,18 @@ var _ = Describe("Podman containers ", func() {
bt.RestoreImagesFromCache() bt.RestoreImagesFromCache()
s = bt.startAPIService() s = bt.startAPIService()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
connText, err = bindings.NewConnection(context.Background(), bt.sock) err := bt.NewConnection()
Expect(err).To(BeNil()) Expect(err).To(BeNil())
}) })
AfterEach(func() { AfterEach(func() {
s.Kill() s.Kill()
bt.cleanup() //bt.cleanup()
}) })
It("podman pause a bogus container", func() { It("podman pause a bogus container", func() {
// Pausing bogus container should return 404 // Pausing bogus container should return 404
err = containers.Pause(connText, "foobar") err = containers.Pause(bt.conn, "foobar")
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
@ -48,7 +46,7 @@ var _ = Describe("Podman containers ", func() {
It("podman unpause a bogus container", func() { It("podman unpause a bogus container", func() {
// Unpausing bogus container should return 404 // Unpausing bogus container should return 404
err = containers.Unpause(connText, "foobar") err = containers.Unpause(bt.conn, "foobar")
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
@ -57,12 +55,13 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a running container by name", func() { It("podman pause a running container by name", func() {
// Pausing by name should work // Pausing by name should work
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) _, err := bt.RunTopContainer(&name, &falseFlag, nil)
err := containers.Pause(connText, name) Expect(err).To(BeNil())
err = containers.Pause(bt.conn, name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Ensure container is paused // Ensure container is paused
data, err := containers.Inspect(connText, name, nil) data, err := containers.Inspect(bt.conn, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(data.State.Status).To(Equal("paused")) Expect(data.State.Status).To(Equal("paused"))
}) })
@ -70,54 +69,60 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a running container by id", func() { It("podman pause a running container by id", func() {
// Pausing by id should work // Pausing by id should work
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) cid, err := bt.RunTopContainer(&name, &falseFlag, nil)
data, err := containers.Inspect(connText, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, data.ID) err = containers.Pause(bt.conn, cid)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Ensure container is paused // Ensure container is paused
data, err = containers.Inspect(connText, data.ID, nil) data, err := containers.Inspect(bt.conn, cid, nil)
Expect(err).To(BeNil())
Expect(data.State.Status).To(Equal("paused")) Expect(data.State.Status).To(Equal("paused"))
}) })
It("podman unpause a running container by name", func() { It("podman unpause a running container by name", func() {
// Unpausing by name should work // Unpausing by name should work
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) _, err := bt.RunTopContainer(&name, &falseFlag, nil)
err := containers.Pause(connText, name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Unpause(connText, name) err = containers.Pause(bt.conn, name)
Expect(err).To(BeNil())
err = containers.Unpause(bt.conn, name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Ensure container is unpaused // Ensure container is unpaused
data, err := containers.Inspect(connText, name, nil) data, err := containers.Inspect(bt.conn, name, nil)
Expect(err).To(BeNil())
Expect(data.State.Status).To(Equal("running")) Expect(data.State.Status).To(Equal("running"))
}) })
It("podman unpause a running container by ID", func() { It("podman unpause a running container by ID", func() {
// Unpausing by ID should work // Unpausing by ID should work
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) _, err := bt.RunTopContainer(&name, &falseFlag, nil)
// Pause by name
err := containers.Pause(connText, name)
data, err := containers.Inspect(connText, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Unpause(connText, data.ID) // Pause by name
err = containers.Pause(bt.conn, name)
//paused := "paused"
//_, err = containers.Wait(bt.conn, cid, &paused)
//Expect(err).To(BeNil())
err = containers.Unpause(bt.conn, name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Ensure container is unpaused // Ensure container is unpaused
data, err = containers.Inspect(connText, name, nil) data, err := containers.Inspect(bt.conn, name, nil)
Expect(err).To(BeNil())
Expect(data.State.Status).To(Equal("running")) Expect(data.State.Status).To(Equal("running"))
}) })
It("podman pause a paused container by name", func() { It("podman pause a paused container by name", func() {
// Pausing a paused container by name should fail // Pausing a paused container by name should fail
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) _, err := bt.RunTopContainer(&name, &falseFlag, nil)
err := containers.Pause(connText, name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, name) err = containers.Pause(bt.conn, name)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, name)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -126,12 +131,11 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a paused container by id", func() { It("podman pause a paused container by id", func() {
// Pausing a paused container by id should fail // Pausing a paused container by id should fail
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) cid, err := bt.RunTopContainer(&name, &falseFlag, nil)
data, err := containers.Inspect(connText, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, data.ID) err = containers.Pause(bt.conn, cid)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, data.ID) err = containers.Pause(bt.conn, cid)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -140,10 +144,11 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a stopped container by name", func() { It("podman pause a stopped container by name", func() {
// Pausing a stopped container by name should fail // Pausing a stopped container by name should fail
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) _, err := bt.RunTopContainer(&name, &falseFlag, nil)
err := containers.Stop(connText, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, name) err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, name)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -152,11 +157,11 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a stopped container by id", func() { It("podman pause a stopped container by id", func() {
// Pausing a stopped container by id should fail // Pausing a stopped container by id should fail
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) cid, err := bt.RunTopContainer(&name, &falseFlag, nil)
data, err := containers.Inspect(connText, name, nil)
err = containers.Stop(connText, data.ID, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, data.ID) err = containers.Stop(bt.conn, cid, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, cid)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -165,12 +170,11 @@ var _ = Describe("Podman containers ", func() {
It("podman remove a paused container by id without force", func() { It("podman remove a paused container by id without force", func() {
// Removing a paused container without force should fail // Removing a paused container without force should fail
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) cid, err := bt.RunTopContainer(&name, &falseFlag, nil)
data, err := containers.Inspect(connText, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, data.ID) err = containers.Pause(bt.conn, cid)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Remove(connText, data.ID, &falseFlag, &falseFlag) err = containers.Remove(bt.conn, cid, &falseFlag, &falseFlag)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -187,22 +191,22 @@ var _ = Describe("Podman containers ", func() {
// Removing a paused container with force should work // Removing a paused container with force should work
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) cid, err := bt.RunTopContainer(&name, &falseFlag, nil)
data, err := containers.Inspect(connText, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, data.ID) err = containers.Pause(bt.conn, cid)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Remove(connText, data.ID, &trueFlag, &falseFlag) err = containers.Remove(bt.conn, cid, &trueFlag, &falseFlag)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
}) })
It("podman stop a paused container by name", func() { It("podman stop a paused container by name", func() {
// Stopping a paused container by name should fail // Stopping a paused container by name should fail
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) _, err := bt.RunTopContainer(&name, &falseFlag, nil)
err := containers.Pause(connText, name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Stop(connText, name, nil) err = containers.Pause(bt.conn, name)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -211,12 +215,11 @@ var _ = Describe("Podman containers ", func() {
It("podman stop a paused container by id", func() { It("podman stop a paused container by id", func() {
// Stopping a paused container by id should fail // Stopping a paused container by id should fail
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) cid, err := bt.RunTopContainer(&name, &falseFlag, nil)
data, err := containers.Inspect(connText, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Pause(connText, data.ID) err = containers.Pause(bt.conn, cid)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Stop(connText, data.ID, nil) err = containers.Stop(bt.conn, cid, nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -225,12 +228,13 @@ var _ = Describe("Podman containers ", func() {
It("podman stop a running container by name", func() { It("podman stop a running container by name", func() {
// Stopping a running container by name should work // Stopping a running container by name should work
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) _, err := bt.RunTopContainer(&name, &falseFlag, nil)
err := containers.Stop(connText, name, nil) Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Ensure container is stopped // Ensure container is stopped
data, err := containers.Inspect(connText, name, nil) data, err := containers.Inspect(bt.conn, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(isStopped(data.State.Status)).To(BeTrue()) Expect(isStopped(data.State.Status)).To(BeTrue())
}) })
@ -238,14 +242,13 @@ var _ = Describe("Podman containers ", func() {
It("podman stop a running container by ID", func() { It("podman stop a running container by ID", func() {
// Stopping a running container by ID should work // Stopping a running container by ID should work
var name = "top" var name = "top"
bt.RunTopContainer(&name, &falseFlag, nil) cid, err := bt.RunTopContainer(&name, &falseFlag, nil)
data, err := containers.Inspect(connText, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = containers.Stop(connText, data.ID, nil) err = containers.Stop(bt.conn, cid, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Ensure container is stopped // Ensure container is stopped
data, err = containers.Inspect(connText, name, nil) data, err := containers.Inspect(bt.conn, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(isStopped(data.State.Status)).To(BeTrue()) Expect(isStopped(data.State.Status)).To(BeTrue())
}) })
@ -255,19 +258,20 @@ var _ = Describe("Podman containers ", func() {
name = "top" name = "top"
exitCode int32 = -1 exitCode int32 = -1
) )
_, err := containers.Wait(connText, "foobar", nil) _, err := containers.Wait(bt.conn, "foobar", nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
errChan := make(chan error) errChan := make(chan error)
bt.RunTopContainer(&name, nil, nil) _, err = bt.RunTopContainer(&name, nil, nil)
Expect(err).To(BeNil())
go func() { go func() {
exitCode, err = containers.Wait(connText, name, nil) exitCode, err = containers.Wait(bt.conn, name, nil)
errChan <- err errChan <- err
close(errChan) close(errChan)
}() }()
err = containers.Stop(connText, name, nil) err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
wait := <-errChan wait := <-errChan
Expect(wait).To(BeNil()) Expect(wait).To(BeNil())
@ -282,13 +286,14 @@ var _ = Describe("Podman containers ", func() {
unpause = "running" unpause = "running"
) )
errChan := make(chan error) errChan := make(chan error)
bt.RunTopContainer(&name, nil, nil) _, err := bt.RunTopContainer(&name, nil, nil)
Expect(err).To(BeNil())
go func() { go func() {
exitCode, err = containers.Wait(connText, name, &pause) exitCode, err = containers.Wait(bt.conn, name, &pause)
errChan <- err errChan <- err
close(errChan) close(errChan)
}() }()
err := containers.Pause(connText, name) err = containers.Pause(bt.conn, name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
wait := <-errChan wait := <-errChan
Expect(wait).To(BeNil()) Expect(wait).To(BeNil())
@ -296,11 +301,11 @@ var _ = Describe("Podman containers ", func() {
errChan = make(chan error) errChan = make(chan error)
go func() { go func() {
exitCode, err = containers.Wait(connText, name, &unpause) exitCode, err = containers.Wait(bt.conn, name, &unpause)
errChan <- err errChan <- err
close(errChan) close(errChan)
}() }()
err = containers.Unpause(connText, name) err = containers.Unpause(bt.conn, name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
unPausewait := <-errChan unPausewait := <-errChan
Expect(unPausewait).To(BeNil()) Expect(unPausewait).To(BeNil())

View File

@ -0,0 +1,50 @@
package test_bindings
import (
"time"
"github.com/containers/libpod/pkg/bindings/containers"
"github.com/containers/libpod/pkg/specgen"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("Create containers ", func() {
var (
bt *bindingTest
s *gexec.Session
)
BeforeEach(func() {
bt = newBindingTest()
bt.RestoreImagesFromCache()
s = bt.startAPIService()
time.Sleep(1 * time.Second)
err := bt.NewConnection()
Expect(err).To(BeNil())
})
AfterEach(func() {
s.Kill()
bt.cleanup()
})
It("create a container running top", func() {
s := specgen.NewSpecGenerator(alpine.name)
s.Command = []string{"top"}
s.Terminal = true
s.Name = "top"
ctr, err := containers.CreateWithSpec(bt.conn, s)
Expect(err).To(BeNil())
data, err := containers.Inspect(bt.conn, ctr.ID, nil)
Expect(err).To(BeNil())
Expect(data.Name).To(Equal("top"))
err = containers.Start(bt.conn, ctr.ID, nil)
Expect(err).To(BeNil())
data, err = containers.Inspect(bt.conn, ctr.ID, nil)
Expect(err).To(BeNil())
Expect(data.State.Status).To(Equal("running"))
})
})

View File

@ -1,7 +1,6 @@
package test_bindings package test_bindings
import ( import (
"context"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -22,7 +21,6 @@ var _ = Describe("Podman images", func() {
//podmanTest *PodmanTestIntegration //podmanTest *PodmanTestIntegration
bt *bindingTest bt *bindingTest
s *gexec.Session s *gexec.Session
connText context.Context
err error err error
falseFlag bool = false falseFlag bool = false
trueFlag bool = true trueFlag bool = true
@ -40,7 +38,7 @@ var _ = Describe("Podman images", func() {
bt.RestoreImagesFromCache() bt.RestoreImagesFromCache()
s = bt.startAPIService() s = bt.startAPIService()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
connText, err = bindings.NewConnection(context.Background(), bt.sock) err := bt.NewConnection()
Expect(err).To(BeNil()) Expect(err).To(BeNil())
}) })
@ -53,32 +51,32 @@ var _ = Describe("Podman images", func() {
}) })
It("inspect image", func() { It("inspect image", func() {
// Inspect invalid image be 404 // Inspect invalid image be 404
_, err = images.GetImage(connText, "foobar5000", nil) _, err = images.GetImage(bt.conn, "foobar5000", nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Inspect by short name // Inspect by short name
data, err := images.GetImage(connText, alpine.shortName, nil) data, err := images.GetImage(bt.conn, alpine.shortName, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Inspect with full ID // Inspect with full ID
_, err = images.GetImage(connText, data.ID, nil) _, err = images.GetImage(bt.conn, data.ID, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Inspect with partial ID // Inspect with partial ID
_, err = images.GetImage(connText, data.ID[0:12], nil) _, err = images.GetImage(bt.conn, data.ID[0:12], nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Inspect by long name // Inspect by long name
_, err = images.GetImage(connText, alpine.name, nil) _, err = images.GetImage(bt.conn, alpine.name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// TODO it looks like the images API alwaays returns size regardless // TODO it looks like the images API alwaays returns size regardless
// of bool or not. What should we do ? // of bool or not. What should we do ?
//Expect(data.Size).To(BeZero()) //Expect(data.Size).To(BeZero())
// Enabling the size parameter should result in size being populated // Enabling the size parameter should result in size being populated
data, err = images.GetImage(connText, alpine.name, &trueFlag) data, err = images.GetImage(bt.conn, alpine.name, &trueFlag)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(data.Size).To(BeNumerically(">", 0)) Expect(data.Size).To(BeNumerically(">", 0))
}) })
@ -86,49 +84,50 @@ var _ = Describe("Podman images", func() {
// Test to validate the remove image api // Test to validate the remove image api
It("remove image", func() { It("remove image", func() {
// Remove invalid image should be a 404 // Remove invalid image should be a 404
_, err = images.Remove(connText, "foobar5000", &falseFlag) _, err = images.Remove(bt.conn, "foobar5000", &falseFlag)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Remove an image by name, validate image is removed and error is nil // Remove an image by name, validate image is removed and error is nil
inspectData, err := images.GetImage(connText, busybox.shortName, nil) inspectData, err := images.GetImage(bt.conn, busybox.shortName, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, err := images.Remove(connText, busybox.shortName, nil) response, err := images.Remove(bt.conn, busybox.shortName, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(inspectData.ID).To(Equal(response[0]["Deleted"])) Expect(inspectData.ID).To(Equal(response[0]["Deleted"]))
inspectData, err = images.GetImage(connText, busybox.shortName, nil) inspectData, err = images.GetImage(bt.conn, busybox.shortName, nil)
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Start a container with alpine image // Start a container with alpine image
var top string = "top" var top string = "top"
bt.RunTopContainer(&top, &falseFlag, nil) _, err = bt.RunTopContainer(&top, &falseFlag, nil)
Expect(err).To(BeNil())
// we should now have a container called "top" running // we should now have a container called "top" running
containerResponse, err := containers.Inspect(connText, "top", &falseFlag) containerResponse, err := containers.Inspect(bt.conn, "top", &falseFlag)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(containerResponse.Name).To(Equal("top")) Expect(containerResponse.Name).To(Equal("top"))
// try to remove the image "alpine". This should fail since we are not force // try to remove the image "alpine". This should fail since we are not force
// deleting hence image cannot be deleted until the container is deleted. // deleting hence image cannot be deleted until the container is deleted.
response, err = images.Remove(connText, alpine.shortName, &falseFlag) response, err = images.Remove(bt.conn, alpine.shortName, &falseFlag)
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
// Removing the image "alpine" where force = true // Removing the image "alpine" where force = true
response, err = images.Remove(connText, alpine.shortName, &trueFlag) response, err = images.Remove(bt.conn, alpine.shortName, &trueFlag)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Checking if both the images are gone as well as the container is deleted // Checking if both the images are gone as well as the container is deleted
inspectData, err = images.GetImage(connText, busybox.shortName, nil) inspectData, err = images.GetImage(bt.conn, busybox.shortName, nil)
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
inspectData, err = images.GetImage(connText, alpine.shortName, nil) inspectData, err = images.GetImage(bt.conn, alpine.shortName, nil)
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
_, err = containers.Inspect(connText, "top", &falseFlag) _, err = containers.Inspect(bt.conn, "top", &falseFlag)
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
}) })
@ -136,17 +135,17 @@ var _ = Describe("Podman images", func() {
// Tests to validate the image tag command. // Tests to validate the image tag command.
It("tag image", func() { It("tag image", func() {
// Validates if invalid image name is given a bad response is encountered. // Validates if invalid image name is given a bad response is encountered.
err = images.Tag(connText, "dummy", "demo", alpine.shortName) err = images.Tag(bt.conn, "dummy", "demo", alpine.shortName)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Validates if the image is tagged sucessfully. // Validates if the image is tagged sucessfully.
err = images.Tag(connText, alpine.shortName, "demo", alpine.shortName) err = images.Tag(bt.conn, alpine.shortName, "demo", alpine.shortName)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
//Validates if name updates when the image is retagged. //Validates if name updates when the image is retagged.
_, err := images.GetImage(connText, "alpine:demo", nil) _, err := images.GetImage(bt.conn, "alpine:demo", nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
}) })
@ -154,7 +153,7 @@ var _ = Describe("Podman images", func() {
// Test to validate the List images command. // Test to validate the List images command.
It("List image", func() { It("List image", func() {
// Array to hold the list of images returned // Array to hold the list of images returned
imageSummary, err := images.List(connText, nil, nil) imageSummary, err := images.List(bt.conn, nil, nil)
// There Should be no errors in the response. // There Should be no errors in the response.
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Since in the begin context two images are created the // Since in the begin context two images are created the
@ -164,7 +163,7 @@ var _ = Describe("Podman images", func() {
// Adding one more image. There Should be no errors in the response. // Adding one more image. There Should be no errors in the response.
// And the count should be three now. // And the count should be three now.
bt.Pull("busybox:glibc") bt.Pull("busybox:glibc")
imageSummary, err = images.List(connText, nil, nil) imageSummary, err = images.List(bt.conn, nil, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(imageSummary)).To(Equal(3)) Expect(len(imageSummary)).To(Equal(3))
@ -179,13 +178,13 @@ var _ = Describe("Podman images", func() {
// List images with a filter // List images with a filter
filters := make(map[string][]string) filters := make(map[string][]string)
filters["reference"] = []string{alpine.name} filters["reference"] = []string{alpine.name}
filteredImages, err := images.List(connText, &falseFlag, filters) filteredImages, err := images.List(bt.conn, &falseFlag, filters)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(filteredImages)).To(BeNumerically("==", 1)) Expect(len(filteredImages)).To(BeNumerically("==", 1))
// List images with a bad filter // List images with a bad filter
filters["name"] = []string{alpine.name} filters["name"] = []string{alpine.name}
_, err = images.List(connText, &falseFlag, filters) _, err = images.List(bt.conn, &falseFlag, filters)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -193,64 +192,64 @@ var _ = Describe("Podman images", func() {
It("Image Exists", func() { It("Image Exists", func() {
// exists on bogus image should be false, with no error // exists on bogus image should be false, with no error
exists, err := images.Exists(connText, "foobar") exists, err := images.Exists(bt.conn, "foobar")
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeFalse()) Expect(exists).To(BeFalse())
// exists with shortname should be true // exists with shortname should be true
exists, err = images.Exists(connText, alpine.shortName) exists, err = images.Exists(bt.conn, alpine.shortName)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeTrue()) Expect(exists).To(BeTrue())
// exists with fqname should be true // exists with fqname should be true
exists, err = images.Exists(connText, alpine.name) exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeTrue()) Expect(exists).To(BeTrue())
}) })
It("Load|Import Image", func() { It("Load|Import Image", func() {
// load an image // load an image
_, err := images.Remove(connText, alpine.name, nil) _, err := images.Remove(bt.conn, alpine.name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
exists, err := images.Exists(connText, alpine.name) exists, err := images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeFalse()) Expect(exists).To(BeFalse())
f, err := os.Open(filepath.Join(ImageCacheDir, alpine.tarballName)) f, err := os.Open(filepath.Join(ImageCacheDir, alpine.tarballName))
defer f.Close() defer f.Close()
Expect(err).To(BeNil()) Expect(err).To(BeNil())
names, err := images.Load(connText, f, nil) names, err := images.Load(bt.conn, f, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(names).To(Equal(alpine.name)) Expect(names).To(Equal(alpine.name))
exists, err = images.Exists(connText, alpine.name) exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeTrue()) Expect(exists).To(BeTrue())
// load with a repo name // load with a repo name
f, err = os.Open(filepath.Join(ImageCacheDir, alpine.tarballName)) f, err = os.Open(filepath.Join(ImageCacheDir, alpine.tarballName))
Expect(err).To(BeNil()) Expect(err).To(BeNil())
_, err = images.Remove(connText, alpine.name, nil) _, err = images.Remove(bt.conn, alpine.name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
exists, err = images.Exists(connText, alpine.name) exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeFalse()) Expect(exists).To(BeFalse())
newName := "quay.io/newname:fizzle" newName := "quay.io/newname:fizzle"
names, err = images.Load(connText, f, &newName) names, err = images.Load(bt.conn, f, &newName)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(names).To(Equal(alpine.name)) Expect(names).To(Equal(alpine.name))
exists, err = images.Exists(connText, newName) exists, err = images.Exists(bt.conn, newName)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeTrue()) Expect(exists).To(BeTrue())
// load with a bad repo name should trigger a 500 // load with a bad repo name should trigger a 500
f, err = os.Open(filepath.Join(ImageCacheDir, alpine.tarballName)) f, err = os.Open(filepath.Join(ImageCacheDir, alpine.tarballName))
Expect(err).To(BeNil()) Expect(err).To(BeNil())
_, err = images.Remove(connText, alpine.name, nil) _, err = images.Remove(bt.conn, alpine.name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
exists, err = images.Exists(connText, alpine.name) exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeFalse()) Expect(exists).To(BeFalse())
badName := "quay.io/newName:fizzle" badName := "quay.io/newName:fizzle"
_, err = images.Load(connText, f, &badName) _, err = images.Load(bt.conn, f, &badName)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -262,7 +261,7 @@ var _ = Describe("Podman images", func() {
w, err := os.Create(filepath.Join(bt.tempDirPath, alpine.tarballName)) w, err := os.Create(filepath.Join(bt.tempDirPath, alpine.tarballName))
defer w.Close() defer w.Close()
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = images.Export(connText, alpine.name, w, nil, nil) err = images.Export(bt.conn, alpine.name, w, nil, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
_, err = os.Stat(exportPath) _, err = os.Stat(exportPath)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
@ -272,9 +271,9 @@ var _ = Describe("Podman images", func() {
It("Import Image", func() { It("Import Image", func() {
// load an image // load an image
_, err = images.Remove(connText, alpine.name, nil) _, err = images.Remove(bt.conn, alpine.name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
exists, err := images.Exists(connText, alpine.name) exists, err := images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeFalse()) Expect(exists).To(BeFalse())
f, err := os.Open(filepath.Join(ImageCacheDir, alpine.tarballName)) f, err := os.Open(filepath.Join(ImageCacheDir, alpine.tarballName))
@ -282,27 +281,27 @@ var _ = Describe("Podman images", func() {
Expect(err).To(BeNil()) Expect(err).To(BeNil())
changes := []string{"CMD /bin/foobar"} changes := []string{"CMD /bin/foobar"}
testMessage := "test_import" testMessage := "test_import"
_, err = images.Import(connText, changes, &testMessage, &alpine.name, nil, f) _, err = images.Import(bt.conn, changes, &testMessage, &alpine.name, nil, f)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
exists, err = images.Exists(connText, alpine.name) exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(exists).To(BeTrue()) Expect(exists).To(BeTrue())
data, err := images.GetImage(connText, alpine.name, nil) data, err := images.GetImage(bt.conn, alpine.name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(data.Comment).To(Equal(testMessage)) Expect(data.Comment).To(Equal(testMessage))
}) })
It("History Image", func() { It("History Image", func() {
// a bogus name should return a 404 // a bogus name should return a 404
_, err := images.History(connText, "foobar") _, err := images.History(bt.conn, "foobar")
Expect(err).To(Not(BeNil())) Expect(err).To(Not(BeNil()))
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
var foundID bool var foundID bool
data, err := images.GetImage(connText, alpine.name, nil) data, err := images.GetImage(bt.conn, alpine.name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
history, err := images.History(connText, alpine.name) history, err := images.History(bt.conn, alpine.name)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
for _, i := range history { for _, i := range history {
if i.ID == data.ID { if i.ID == data.ID {
@ -314,7 +313,7 @@ var _ = Describe("Podman images", func() {
}) })
It("Search for an image", func() { It("Search for an image", func() {
imgs, err := images.Search(connText, "alpine", nil, nil) imgs, err := images.Search(bt.conn, "alpine", nil, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(imgs)).To(BeNumerically(">", 1)) Expect(len(imgs)).To(BeNumerically(">", 1))
var foundAlpine bool var foundAlpine bool
@ -328,21 +327,21 @@ var _ = Describe("Podman images", func() {
// Search for alpine with a limit of 10 // Search for alpine with a limit of 10
ten := 10 ten := 10
imgs, err = images.Search(connText, "docker.io/alpine", &ten, nil) imgs, err = images.Search(bt.conn, "docker.io/alpine", &ten, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(imgs)).To(BeNumerically("<=", 10)) Expect(len(imgs)).To(BeNumerically("<=", 10))
// Search for alpine with stars greater than 100 // Search for alpine with stars greater than 100
filters := make(map[string][]string) filters := make(map[string][]string)
filters["stars"] = []string{"100"} filters["stars"] = []string{"100"}
imgs, err = images.Search(connText, "docker.io/alpine", nil, filters) imgs, err = images.Search(bt.conn, "docker.io/alpine", nil, filters)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
for _, i := range imgs { for _, i := range imgs {
Expect(i.Stars).To(BeNumerically(">=", 100)) Expect(i.Stars).To(BeNumerically(">=", 100))
} }
// Search with a fqdn // Search with a fqdn
imgs, err = images.Search(connText, "quay.io/libpod/alpine_nginx", nil, nil) imgs, err = images.Search(bt.conn, "quay.io/libpod/alpine_nginx", nil, nil)
Expect(len(imgs)).To(BeNumerically(">=", 1)) Expect(len(imgs)).To(BeNumerically(">=", 1))
}) })

View File

@ -1,7 +1,6 @@
package test_bindings package test_bindings
import ( import (
"context"
"net/http" "net/http"
"time" "time"
@ -17,7 +16,6 @@ var _ = Describe("Podman pods", func() {
var ( var (
bt *bindingTest bt *bindingTest
s *gexec.Session s *gexec.Session
connText context.Context
newpod string newpod string
err error err error
trueFlag bool = true trueFlag bool = true
@ -30,7 +28,7 @@ var _ = Describe("Podman pods", func() {
bt.Podcreate(&newpod) bt.Podcreate(&newpod)
s = bt.startAPIService() s = bt.startAPIService()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
connText, err = bindings.NewConnection(context.Background(), bt.sock) err := bt.NewConnection()
Expect(err).To(BeNil()) Expect(err).To(BeNil())
}) })
@ -41,13 +39,13 @@ var _ = Describe("Podman pods", func() {
It("inspect pod", func() { It("inspect pod", func() {
//Inspect an invalid pod name //Inspect an invalid pod name
_, err := pods.Inspect(connText, "dummyname") _, err := pods.Inspect(bt.conn, "dummyname")
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
//Inspect an valid pod name //Inspect an valid pod name
response, err := pods.Inspect(connText, newpod) response, err := pods.Inspect(bt.conn, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(response.Config.Name).To(Equal(newpod)) Expect(response.Config.Name).To(Equal(newpod))
}) })
@ -55,12 +53,13 @@ var _ = Describe("Podman pods", func() {
// Test validates the list all api returns // Test validates the list all api returns
It("list pod", func() { It("list pod", func() {
//List all the pods in the current instance //List all the pods in the current instance
podSummary, err := pods.List(connText, nil) podSummary, err := pods.List(bt.conn, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(podSummary)).To(Equal(1)) Expect(len(podSummary)).To(Equal(1))
// Adding an alpine container to the existing pod // Adding an alpine container to the existing pod
bt.RunTopContainer(nil, &trueFlag, &newpod) _, err = bt.RunTopContainer(nil, &trueFlag, &newpod)
podSummary, err = pods.List(connText, nil) Expect(err).To(BeNil())
podSummary, err = pods.List(bt.conn, nil)
// Verify no errors. // Verify no errors.
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Verify number of containers in the pod. // Verify number of containers in the pod.
@ -69,7 +68,7 @@ var _ = Describe("Podman pods", func() {
// Add multiple pods and verify them by name and size. // Add multiple pods and verify them by name and size.
var newpod2 string = "newpod2" var newpod2 string = "newpod2"
bt.Podcreate(&newpod2) bt.Podcreate(&newpod2)
podSummary, err = pods.List(connText, nil) podSummary, err = pods.List(bt.conn, nil)
Expect(len(podSummary)).To(Equal(2)) Expect(len(podSummary)).To(Equal(2))
var names []string var names []string
for _, i := range podSummary { for _, i := range podSummary {
@ -83,19 +82,19 @@ var _ = Describe("Podman pods", func() {
// Validate list pod with filters // Validate list pod with filters
//filters := make(map[string][]string) //filters := make(map[string][]string)
//filters["name"] = []string{newpod} //filters["name"] = []string{newpod}
//filteredPods, err := pods.List(connText, filters) //filteredPods, err := pods.List(bt.conn, filters)
//Expect(err).To(BeNil()) //Expect(err).To(BeNil())
//Expect(len(filteredPods)).To(BeNumerically("==", 1)) //Expect(len(filteredPods)).To(BeNumerically("==", 1))
}) })
// The test validates if the exists responds // The test validates if the exists responds
It("exists pod", func() { It("exists pod", func() {
response, err := pods.Exists(connText, "dummyName") response, err := pods.Exists(bt.conn, "dummyName")
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(response).To(BeFalse()) Expect(response).To(BeFalse())
// Should exit with no error and response should be true // Should exit with no error and response should be true
response, err = pods.Exists(connText, "newpod") response, err = pods.Exists(bt.conn, "newpod")
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(response).To(BeTrue()) Expect(response).To(BeTrue())
}) })
@ -103,23 +102,24 @@ var _ = Describe("Podman pods", func() {
// This test validates if All running containers within // This test validates if All running containers within
// each specified pod are paused and unpaused // each specified pod are paused and unpaused
It("pause upause pod", func() { It("pause upause pod", func() {
// TODO fix this
Skip("Pod behavior is jacked right now.")
// Pause invalid container // Pause invalid container
err := pods.Pause(connText, "dummyName") err := pods.Pause(bt.conn, "dummyName")
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Adding an alpine container to the existing pod // Adding an alpine container to the existing pod
bt.RunTopContainer(nil, &trueFlag, &newpod) _, err = bt.RunTopContainer(nil, &trueFlag, &newpod)
response, err := pods.Inspect(connText, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Binding needs to be modified to inspect the pod state. // Binding needs to be modified to inspect the pod state.
// Since we dont have a pod state we inspect the states of the containers within the pod. // Since we dont have a pod state we inspect the states of the containers within the pod.
// Pause a valid container // Pause a valid container
err = pods.Pause(connText, newpod) err = pods.Pause(bt.conn, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, err = pods.Inspect(connText, newpod) response, err := pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStatePaused)) Expect(response.State.Status).To(Equal(define.PodStatePaused))
for _, i := range response.Containers { for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)). Expect(define.StringToContainerStatus(i.State)).
@ -127,9 +127,9 @@ var _ = Describe("Podman pods", func() {
} }
// Unpause a valid container // Unpause a valid container
err = pods.Unpause(connText, newpod) err = pods.Unpause(bt.conn, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, err = pods.Inspect(connText, newpod) response, err = pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStateRunning)) Expect(response.State.Status).To(Equal(define.PodStateRunning))
for _, i := range response.Containers { for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)). Expect(define.StringToContainerStatus(i.State)).
@ -139,28 +139,28 @@ var _ = Describe("Podman pods", func() {
It("start stop restart pod", func() { It("start stop restart pod", func() {
// Start an invalid pod // Start an invalid pod
err = pods.Start(connText, "dummyName") err = pods.Start(bt.conn, "dummyName")
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Stop an invalid pod // Stop an invalid pod
err = pods.Stop(connText, "dummyName", nil) err = pods.Stop(bt.conn, "dummyName", nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Restart an invalid pod // Restart an invalid pod
err = pods.Restart(connText, "dummyName") err = pods.Restart(bt.conn, "dummyName")
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Start a valid pod and inspect status of each container // Start a valid pod and inspect status of each container
err = pods.Start(connText, newpod) err = pods.Start(bt.conn, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, err := pods.Inspect(connText, newpod) response, err := pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStateRunning)) Expect(response.State.Status).To(Equal(define.PodStateRunning))
for _, i := range response.Containers { for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)). Expect(define.StringToContainerStatus(i.State)).
@ -168,13 +168,13 @@ var _ = Describe("Podman pods", func() {
} }
// Start an already running pod // Start an already running pod
err = pods.Start(connText, newpod) err = pods.Start(bt.conn, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Stop the running pods // Stop the running pods
err = pods.Stop(connText, newpod, nil) err = pods.Stop(bt.conn, newpod, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, _ = pods.Inspect(connText, newpod) response, _ = pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStateExited)) Expect(response.State.Status).To(Equal(define.PodStateExited))
for _, i := range response.Containers { for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)). Expect(define.StringToContainerStatus(i.State)).
@ -182,12 +182,12 @@ var _ = Describe("Podman pods", func() {
} }
// Stop an already stopped pod // Stop an already stopped pod
err = pods.Stop(connText, newpod, nil) err = pods.Stop(bt.conn, newpod, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = pods.Restart(connText, newpod) err = pods.Restart(bt.conn, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, _ = pods.Inspect(connText, newpod) response, _ = pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStateRunning)) Expect(response.State.Status).To(Equal(define.PodStateRunning))
for _, i := range response.Containers { for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)). Expect(define.StringToContainerStatus(i.State)).
@ -201,52 +201,52 @@ var _ = Describe("Podman pods", func() {
var newpod2 string = "newpod2" var newpod2 string = "newpod2"
bt.Podcreate(&newpod2) bt.Podcreate(&newpod2)
// No pods pruned since no pod in exited state // No pods pruned since no pod in exited state
err = pods.Prune(connText) err = pods.Prune(bt.conn)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
podSummary, err := pods.List(connText, nil) podSummary, err := pods.List(bt.conn, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(podSummary)).To(Equal(2)) Expect(len(podSummary)).To(Equal(2))
// Prune only one pod which is in exited state. // Prune only one pod which is in exited state.
// Start then stop a pod. // Start then stop a pod.
// pod moves to exited state one pod should be pruned now. // pod moves to exited state one pod should be pruned now.
err = pods.Start(connText, newpod) err = pods.Start(bt.conn, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = pods.Stop(connText, newpod, nil) err = pods.Stop(bt.conn, newpod, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, err := pods.Inspect(connText, newpod) response, err := pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStateExited)) Expect(response.State.Status).To(Equal(define.PodStateExited))
err = pods.Prune(connText) err = pods.Prune(bt.conn)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
podSummary, err = pods.List(connText, nil) podSummary, err = pods.List(bt.conn, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(podSummary)).To(Equal(1)) Expect(len(podSummary)).To(Equal(1))
// Test prune all pods in exited state. // Test prune all pods in exited state.
bt.Podcreate(&newpod) bt.Podcreate(&newpod)
err = pods.Start(connText, newpod) err = pods.Start(bt.conn, newpod)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = pods.Start(connText, newpod2) err = pods.Start(bt.conn, newpod2)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = pods.Stop(connText, newpod, nil) err = pods.Stop(bt.conn, newpod, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, err = pods.Inspect(connText, newpod) response, err = pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStateExited)) Expect(response.State.Status).To(Equal(define.PodStateExited))
for _, i := range response.Containers { for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)). Expect(define.StringToContainerStatus(i.State)).
To(Equal(define.ContainerStateStopped)) To(Equal(define.ContainerStateStopped))
} }
err = pods.Stop(connText, newpod2, nil) err = pods.Stop(bt.conn, newpod2, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
response, err = pods.Inspect(connText, newpod2) response, err = pods.Inspect(bt.conn, newpod2)
Expect(response.State.Status).To(Equal(define.PodStateExited)) Expect(response.State.Status).To(Equal(define.PodStateExited))
for _, i := range response.Containers { for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)). Expect(define.StringToContainerStatus(i.State)).
To(Equal(define.ContainerStateStopped)) To(Equal(define.ContainerStateStopped))
} }
err = pods.Prune(connText) err = pods.Prune(bt.conn)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
podSummary, err = pods.List(connText, nil) podSummary, err = pods.List(bt.conn, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(podSummary)).To(Equal(0)) Expect(len(podSummary)).To(Equal(0))
}) })

View File

@ -13,7 +13,6 @@ import (
// MakeContainer creates a container based on the SpecGenerator // MakeContainer creates a container based on the SpecGenerator
func (s *SpecGenerator) MakeContainer(rt *libpod.Runtime) (*libpod.Container, error) { func (s *SpecGenerator) MakeContainer(rt *libpod.Runtime) (*libpod.Container, error) {
var pod *libpod.Pod
if err := s.validate(rt); err != nil { if err := s.validate(rt); err != nil {
return nil, errors.Wrap(err, "invalid config provided") return nil, errors.Wrap(err, "invalid config provided")
} }
@ -22,7 +21,7 @@ func (s *SpecGenerator) MakeContainer(rt *libpod.Runtime) (*libpod.Container, er
return nil, err return nil, err
} }
options, err := s.createContainerOptions(rt, pod) options, err := s.createContainerOptions(rt)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -46,7 +45,7 @@ func (s *SpecGenerator) MakeContainer(rt *libpod.Runtime) (*libpod.Container, er
return rt.NewContainer(context.Background(), runtimeSpec, options...) return rt.NewContainer(context.Background(), runtimeSpec, options...)
} }
func (s *SpecGenerator) createContainerOptions(rt *libpod.Runtime, pod *libpod.Pod) ([]libpod.CtrCreateOption, error) { func (s *SpecGenerator) createContainerOptions(rt *libpod.Runtime) ([]libpod.CtrCreateOption, error) {
var options []libpod.CtrCreateOption var options []libpod.CtrCreateOption
var err error var err error
@ -61,6 +60,10 @@ func (s *SpecGenerator) createContainerOptions(rt *libpod.Runtime, pod *libpod.P
options = append(options, libpod.WithName(s.Name)) options = append(options, libpod.WithName(s.Name))
} }
if s.Pod != "" { if s.Pod != "" {
pod, err := rt.LookupPod(s.Pod)
if err != nil {
return nil, err
}
logrus.Debugf("adding container to pod %s", s.Pod) logrus.Debugf("adding container to pod %s", s.Pod)
options = append(options, rt.WithPod(pod)) options = append(options, rt.WithPod(pod))
} }
@ -116,7 +119,6 @@ func (s *SpecGenerator) createContainerOptions(rt *libpod.Runtime, pod *libpod.P
} }
options = append(options, namespaceOptions...) options = append(options, namespaceOptions...)
// TODO NetworkNS still needs to be done!
if len(s.ConmonPidFile) > 0 { if len(s.ConmonPidFile) > 0 {
options = append(options, libpod.WithConmonPidFile(s.ConmonPidFile)) options = append(options, libpod.WithConmonPidFile(s.ConmonPidFile))
} }

View File

@ -70,9 +70,7 @@ func (n *Namespace) IsPrivate() bool {
return n.NSMode == Private return n.NSMode == Private
} }
// validate perform simple validation on the namespace to make sure it is not func validateNetNS(n *Namespace) error {
// invalid from the get-go
func (n *Namespace) validate() error {
if n == nil { if n == nil {
return nil return nil
} }
@ -82,6 +80,15 @@ func (n *Namespace) validate() error {
default: default:
return errors.Errorf("invalid network %q", n.NSMode) return errors.Errorf("invalid network %q", n.NSMode)
} }
return nil
}
// validate perform simple validation on the namespace to make sure it is not
// invalid from the get-go
func (n *Namespace) validate() error {
if n == nil {
return nil
}
// Path and From Container MUST have a string value set // Path and From Container MUST have a string value set
if n.NSMode == Path || n.NSMode == FromContainer { if n.NSMode == Path || n.NSMode == FromContainer {
if len(n.Value) < 1 { if len(n.Value) < 1 {

View File

@ -138,7 +138,7 @@ func (s *SpecGenerator) validate(rt *libpod.Runtime) error {
if err := s.IpcNS.validate(); err != nil { if err := s.IpcNS.validate(); err != nil {
return err return err
} }
if err := s.NetNS.validate(); err != nil { if err := validateNetNS(&s.NetNS); err != nil {
return err return err
} }
if err := s.PidNS.validate(); err != nil { if err := s.PidNS.validate(); err != nil {