From 6ba6ecf59b9204d36388de07b866f157a4d13957 Mon Sep 17 00:00:00 2001 From: baude Date: Fri, 2 Feb 2018 11:02:09 -0600 Subject: Migrate Create|Commit to ginkgo Migrate create and commit bats tests to the ginkgo test suite. In doing so, some structures had to be moved to pkg/podmanstructs/podmanstructs.go so we could do better verification of test results. Signed-off-by: baude Closes: #286 Approved by: rhatdan --- cmd/podman/create.go | 5 ++- cmd/podman/images.go | 13 +++--- cmd/podman/inspect.go | 105 +++---------------------------------------------- cmd/podman/run_test.go | 6 +-- 4 files changed, 18 insertions(+), 111 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/create.go b/cmd/podman/create.go index 045703074..ac6bc2969 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -17,6 +17,7 @@ import ( "github.com/opencontainers/selinux/go-selinux/label" "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod" + "github.com/projectatomic/libpod/pkg/inspect" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -381,7 +382,7 @@ func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[na // imageData pulls down the image if not stored locally and extracts the // default container runtime data out of it. imageData returns the data // to the caller. Example Data: Entrypoint, Env, WorkingDir, Labels ... -func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, string, *libpod.ImageData, error) { +func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, string, *inspect.ImageData, error) { var ( err error imageName, imageID string @@ -420,7 +421,7 @@ func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, s // Parses CLI options related to container creation into a config which can be // parsed into an OCI runtime spec -func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime, imageName string, data *libpod.ImageData) (*createConfig, error) { +func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime, imageName string, data *inspect.ImageData) (*createConfig, error) { var command []string var memoryLimit, memoryReservation, memorySwap, memoryKernel int64 var blkioWeight uint16 diff --git a/cmd/podman/images.go b/cmd/podman/images.go index 1f1174950..540a5f4f3 100644 --- a/cmd/podman/images.go +++ b/cmd/podman/images.go @@ -13,6 +13,7 @@ import ( "github.com/projectatomic/libpod/cmd/podman/formats" "github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod/common" + "github.com/projectatomic/libpod/pkg/inspect" "github.com/urfave/cli" ) @@ -273,7 +274,7 @@ func generateImagesOutput(runtime *libpod.Runtime, images []*storage.Image, opts func generateImagesFilter(params *libpod.ImageFilterParams, filterType string) libpod.ImageFilter { switch filterType { case "label": - return func(image *storage.Image, info *libpod.ImageData) bool { + return func(image *storage.Image, info *inspect.ImageData) bool { if params == nil || params.Label == "" { return true } @@ -290,21 +291,21 @@ func generateImagesFilter(params *libpod.ImageFilterParams, filterType string) l return false } case "before-image": - return func(image *storage.Image, info *libpod.ImageData) bool { + return func(image *storage.Image, info *inspect.ImageData) bool { if params == nil || params.BeforeImage.IsZero() { return true } return info.Created.Before(params.BeforeImage) } case "since-image": - return func(image *storage.Image, info *libpod.ImageData) bool { + return func(image *storage.Image, info *inspect.ImageData) bool { if params == nil || params.SinceImage.IsZero() { return true } return info.Created.After(params.SinceImage) } case "dangling": - return func(image *storage.Image, info *libpod.ImageData) bool { + return func(image *storage.Image, info *inspect.ImageData) bool { if params == nil || params.Dangling == "" { return true } @@ -317,14 +318,14 @@ func generateImagesFilter(params *libpod.ImageFilterParams, filterType string) l return false } case "reference": - return func(image *storage.Image, info *libpod.ImageData) bool { + return func(image *storage.Image, info *inspect.ImageData) bool { if params == nil || params.ReferencePattern == "" { return true } return libpod.MatchesReference(params.ImageName, params.ReferencePattern) } case "image-input": - return func(image *storage.Image, info *libpod.ImageData) bool { + return func(image *storage.Image, info *inspect.ImageData) bool { if params == nil || params.ImageInput == "" { return true } diff --git a/cmd/podman/inspect.go b/cmd/podman/inspect.go index 01de6587d..2e70eaa0a 100644 --- a/cmd/podman/inspect.go +++ b/cmd/podman/inspect.go @@ -2,12 +2,11 @@ package main import ( "encoding/json" - - "github.com/docker/go-connections/nat" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/formats" "github.com/projectatomic/libpod/libpod" + "github.com/projectatomic/libpod/pkg/inspect" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -143,7 +142,7 @@ func inspectCmd(c *cli.Context) error { return nil } -func getCtrInspectInfo(ctr *libpod.Container, ctrInspectData *libpod.ContainerInspectData) (*ContainerData, error) { +func getCtrInspectInfo(ctr *libpod.Container, ctrInspectData *inspect.ContainerInspectData) (*inspect.ContainerData, error) { config := ctr.Config() spec := config.Spec @@ -163,9 +162,9 @@ func getCtrInspectInfo(ctr *libpod.Container, ctrInspectData *libpod.ContainerIn logrus.Errorf("couldn't get some inspect information, error getting artifact %q: %v", ctr.ID(), err) } - data := &ContainerData{ + data := &inspect.ContainerData{ CtrInspectData: ctrInspectData, - HostConfig: &HostConfig{ + HostConfig: &inspect.HostConfig{ ConsoleSize: spec.Process.ConsoleSize, OomScoreAdj: spec.Process.OOMScoreAdj, CPUShares: shares, @@ -211,7 +210,7 @@ func getCtrInspectInfo(ctr *libpod.Container, ctrInspectData *libpod.ContainerIn Ulimits: createArtifact.Resources.Ulimit, SecurityOpt: createArtifact.SecurityOpts, }, - Config: &CtrConfig{ + Config: &inspect.CtrConfig{ Hostname: spec.Hostname, User: spec.Process.User, Env: spec.Process.Env, @@ -282,97 +281,3 @@ func getCgroup(spec *specs.Spec) string { } return cgroup } - -// ContainerData holds the podman inspect data for a container -type ContainerData struct { - CtrInspectData *libpod.ContainerInspectData `json:"CtrInspectData"` - HostConfig *HostConfig `json:"HostConfig"` - Config *CtrConfig `json:"Config"` -} - -// LogConfig holds the log information for a container -type LogConfig struct { - Type string `json:"Type"` // TODO - Config map[string]string `json:"Config"` //idk type, TODO -} - -// HostConfig represents the host configuration for the container -type HostConfig struct { - ContainerIDFile string `json:"ContainerIDFile"` - LogConfig *LogConfig `json:"LogConfig"` //TODO - NetworkMode string `json:"NetworkMode"` - PortBindings nat.PortMap `json:"PortBindings"` //TODO - AutoRemove bool `json:"AutoRemove"` - CapAdd []string `json:"CapAdd"` - CapDrop []string `json:"CapDrop"` - DNS []string `json:"DNS"` - DNSOptions []string `json:"DNSOptions"` - DNSSearch []string `json:"DNSSearch"` - ExtraHosts []string `json:"ExtraHosts"` - GroupAdd []uint32 `json:"GroupAdd"` - IpcMode string `json:"IpcMode"` - Cgroup string `json:"Cgroup"` - OomScoreAdj *int `json:"OomScoreAdj"` - PidMode string `json:"PidMode"` - Privileged bool `json:"Privileged"` - PublishAllPorts bool `json:"PublishAllPorts"` //TODO - ReadonlyRootfs bool `json:"ReadonlyRootfs"` - SecurityOpt []string `json:"SecurityOpt"` - UTSMode string `json:"UTSMode"` - UsernsMode string `json:"UsernsMode"` - ShmSize int64 `json:"ShmSize"` - Runtime string `json:"Runtime"` - ConsoleSize *specs.Box `json:"ConsoleSize"` - Isolation string `json:"Isolation"` //TODO - CPUShares *uint64 `json:"CPUSShares"` - Memory int64 `json:"Memory"` - NanoCPUs int `json:"NanoCPUs"` //check type, TODO - CgroupParent string `json:"CgroupParent"` - BlkioWeight *uint16 `json:"BlkioWeight"` - BlkioWeightDevice []specs.LinuxWeightDevice `json:"BlkioWeightDevice"` - BlkioDeviceReadBps []specs.LinuxThrottleDevice `json:"BlkioDeviceReadBps"` - BlkioDeviceWriteBps []specs.LinuxThrottleDevice `json:"BlkioDeviceWriteBps"` - BlkioDeviceReadIOps []specs.LinuxThrottleDevice `json:"BlkioDeviceReadIOps"` - BlkioDeviceWriteIOps []specs.LinuxThrottleDevice `json:"BlkioDeviceWriteIOps"` - CPUPeriod *uint64 `json:"CPUPeriod"` - CPUQuota *int64 `json:"CPUQuota"` - CPURealtimePeriod *uint64 `json:"CPURealtimePeriod"` - CPURealtimeRuntime *int64 `json:"CPURealtimeRuntime"` - CPUSetCPUs string `json:"CPUSetCPUs"` - CPUSetMems string `json:"CPUSetMems"` - Devices []specs.LinuxDevice `json:"Devices"` - DiskQuota int `json:"DiskQuota"` //check type, TODO - KernelMemory *int64 `json:"KernelMemory"` - MemoryReservation *int64 `json:"MemoryReservation"` - MemorySwap *int64 `json:"MemorySwap"` - MemorySwappiness *uint64 `json:"MemorySwappiness"` - OomKillDisable *bool `json:"OomKillDisable"` - PidsLimit *int64 `json:"PidsLimit"` - Ulimits []string `json:"Ulimits"` - CPUCount int `json:"CPUCount"` //check type, TODO - CPUPercent int `json:"CPUPercent"` //check type, TODO - IOMaximumIOps int `json:"IOMaximumIOps"` //check type, TODO - IOMaximumBandwidth int `json:"IOMaximumBandwidth"` //check type, TODO -} - -// CtrConfig holds information about the container configuration -type CtrConfig struct { - Hostname string `json:"Hostname"` - DomainName string `json:"Domainname"` //TODO - User specs.User `json:"User"` - AttachStdin bool `json:"AttachStdin"` //TODO - AttachStdout bool `json:"AttachStdout"` //TODO - AttachStderr bool `json:"AttachStderr"` //TODO - Tty bool `json:"Tty"` - OpenStdin bool `json:"OpenStdin"` - StdinOnce bool `json:"StdinOnce"` //TODO - Env []string `json:"Env"` - Cmd []string `json:"Cmd"` - Image string `json:"Image"` - Volumes map[string]struct{} `json:"Volumes"` - WorkingDir string `json:"WorkingDir"` - Entrypoint string `json:"Entrypoint"` - Labels map[string]string `json:"Labels"` - Annotations map[string]string `json:"Annotations"` - StopSignal uint `json:"StopSignal"` -} diff --git a/cmd/podman/run_test.go b/cmd/podman/run_test.go index b82df86db..55c535337 100644 --- a/cmd/podman/run_test.go +++ b/cmd/podman/run_test.go @@ -6,7 +6,7 @@ import ( units "github.com/docker/go-units" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" spec "github.com/opencontainers/runtime-spec/specs-go" - "github.com/projectatomic/libpod/libpod" + "github.com/projectatomic/libpod/pkg/inspect" "github.com/stretchr/testify/assert" "github.com/urfave/cli" ) @@ -22,7 +22,7 @@ var ( ) // generates a mocked ImageData structure based on alpine -func generateAlpineImageData() *libpod.ImageData { +func generateAlpineImageData() *inspect.ImageData { config := &ociv1.ImageConfig{ User: "", ExposedPorts: nil, @@ -35,7 +35,7 @@ func generateAlpineImageData() *libpod.ImageData { StopSignal: "", } - data := &libpod.ImageData{ + data := &inspect.ImageData{ ID: "e21c333399e0aeedfd70e8827c9fba3f8e9b170ef8a48a29945eb7702bf6aa5f", RepoTags: []string{"docker.io/library/alpine:latest"}, RepoDigests: []string{"docker.io/library/alpine@sha256:5cb04fce748f576d7b72a37850641de8bd725365519673c643ef2d14819b42c6"}, -- cgit v1.2.3-54-g00ecf