Merge pull request #43 from runcom/int-tests

add tests skeleton
This commit is contained in:
Mrunal Patel 2016-09-23 15:44:02 -07:00 committed by GitHub
commit f115a4ab24
585 changed files with 2209 additions and 350 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
/ocic /ocic
conmon/conmon conmon/conmon
conmon/conmon.o conmon/conmon.o
vendor/src/github.com/kubernetes-incubator/ocid

View file

@ -5,6 +5,9 @@ go:
sudo: required sudo: required
services:
- docker
before_script: before_script:
- export PATH=$HOME/gopath/bin:$PATH - export PATH=$HOME/gopath/bin:$PATH
@ -12,11 +15,10 @@ before_install:
- make install.tools - make install.tools
- go get -u github.com/alecthomas/gometalinter - go get -u github.com/alecthomas/gometalinter
- gometalinter --install --update - gometalinter --install --update
- go get -t -d ./...
install: true install: true
script: script:
- make .gitvalidation - make .gitvalidation
- make lint - make lint
- make - make integration

51
Dockerfile Normal file
View file

@ -0,0 +1,51 @@
FROM golang:1.7.1
# libseccomp in jessie is not _quite_ new enough -- need backports version
RUN echo 'deb http://httpredir.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/backports.list
RUN apt-get update && apt-get install -y \
build-essential \
curl \
gawk \
iptables \
pkg-config \
libaio-dev \
libcap-dev \
libprotobuf-dev \
libprotobuf-c0-dev \
libseccomp2/jessie-backports \
libseccomp-dev/jessie-backports \
protobuf-c-compiler \
protobuf-compiler \
python-minimal \
libglib2.0-dev \
--no-install-recommends
# install bats
RUN cd /tmp \
&& git clone https://github.com/sstephenson/bats.git \
&& cd bats \
&& git reset --hard 03608115df2071fff4eaaff1605768c275e5f81f \
&& ./install.sh /usr/local
# install criu
ENV CRIU_VERSION 1.7
RUN mkdir -p /usr/src/criu \
&& curl -sSL https://github.com/xemul/criu/archive/v${CRIU_VERSION}.tar.gz | tar -v -C /usr/src/criu/ -xz --strip-components=1 \
&& cd /usr/src/criu \
&& make install-criu
# Install runc
ENV RUNC_COMMIT cc29e3dded8e27ba8f65738f40d251c885030a28
RUN set -x \
&& export GOPATH="$(mktemp -d)" \
&& git clone https://github.com/opencontainers/runc.git "$GOPATH/src/github.com/opencontainers/runc" \
&& cd "$GOPATH/src/github.com/opencontainers/runc" \
&& git checkout -q "$RUNC_COMMIT" \
&& make static BUILDTAGS="seccomp selinux" \
&& cp runc /usr/local/bin/runc \
&& rm -rf "$GOPATH"
WORKDIR /go/src/github.com/kubernetes-incubator/ocid
ADD . /go/src/github.com/kubernetes-incubator/ocid

View file

@ -1,4 +1,13 @@
EPOCH_TEST_COMMIT ?= 7fc874e05e74faa81e7c423b6514fc5c474c6b34 EPOCH_TEST_COMMIT ?= 7fc874e05e74faa81e7c423b6514fc5c474c6b34
PROJECT := github.com/kubernetes-incubator/ocid
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
OCID_IMAGE := ocid_dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
OCID_LINK := ${CURDIR}/vendor/src/github.com/kubernetes-incubator/ocid
OCID_LINK_DIR := ${CURDIR}/vendor/src/github.com/kubernetes-incubator
OCID_INSTANCE := ocid_dev
SYSTEM_GOPATH := ${GOPATH}
export GOPATH := ${CURDIR}/vendor
default: help default: help
@ -6,27 +15,49 @@ help:
@echo "Usage: make <target>" @echo "Usage: make <target>"
@echo @echo
@echo " * 'binaries' - Build ocid, conmon and ocic" @echo " * 'binaries' - Build ocid, conmon and ocic"
@echo " * 'integration' - Execute integration tests"
@echo " * 'clean' - Clean artifacts" @echo " * 'clean' - Clean artifacts"
@echo " * 'lint' - Execute the source code linter" @echo " * 'lint' - Execute the source code linter"
lint: lint: ${OCID_LINK}
@echo "checking lint" @echo "checking lint"
@./.tool/lint @./.tool/lint
${OCID_LINK}:
mkdir -p ${OCID_LINK_DIR}
ln -sfn ${CURDIR} ${OCID_LINK}
conmon: conmon:
make -C $@ make -C $@
ocid: ocid: ${OCID_LINK}
go build -o ocid ./cmd/server/ go build -o ocid ./cmd/server/
ocic: ocic: ${OCID_LINK}
go build -o ocic ./cmd/client/ go build -o ocic ./cmd/client/
clean: clean:
rm -f ocic ocid rm -f ocic ocid
rm -f ${OCID_LINK}
rm -f conmon/conmon.o conmon/conmon rm -f conmon/conmon.o conmon/conmon
binaries: ocid ocic conmon ocidimage:
docker build -t ${OCID_IMAGE} .
dbuild: ocidimage
docker run --name=${OCID_INSTANCE} --privileged ${OCID_IMAGE} make binaries
docker cp ${OCID_INSTANCE}:/go/src/github.com/kubernetes-incubator/ocid/ocid .
docker cp ${OCID_INSTANCE}:/go/src/github.com/kubernetes-incubator/ocid/ocic .
docker cp ${OCID_INSTANCE}:/go/src/github.com/kubernetes-incubator/ocid/conmon/conmon ./conmon/conmon
docker rm ${OCID_INSTANCE}
integration: ocidimage
docker run -t --privileged --rm -v ${CURDIR}:/go/src/${PROJECT} ${OCID_IMAGE} make localintegration
localintegration: binaries
./test/test_runner.sh
binaries: ${OCID_LINK} ocid ocic conmon
.PHONY: .gitvalidation .PHONY: .gitvalidation
# When this is running in travis, it will only check the travis commit range # When this is running in travis, it will only check the travis commit range
@ -40,20 +71,14 @@ endif
.PHONY: install.tools .PHONY: install.tools
install.tools: .install.gitvalidation .install.glide .install.glide-vc .install.gometalinter install.tools: .install.gitvalidation .install.gometalinter
.install.gitvalidation: .install.gitvalidation:
go get github.com/vbatts/git-validation GOPATH=${SYSTEM_GOPATH} go get github.com/vbatts/git-validation
.install.glide:
go get github.com/Masterminds/glide
.install.glide-vc:
go get github.com/sgotti/glide-vc
.install.gometalinter: .install.gometalinter:
go get github.com/alecthomas/gometalinter GOPATH=${SYSTEM_GOPATH} go get github.com/alecthomas/gometalinter
gometalinter --install GOPATH=${SYSTEM_GOPATH} gometalinter --install
.PHONY: \ .PHONY: \
binaries \ binaries \

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"path/filepath"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/ocid/server" "github.com/kubernetes-incubator/ocid/server"
@ -12,6 +13,10 @@ import (
"k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
) )
const (
ocidRoot = "/var/lib/ocid"
)
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "ocid" app.Name = "ocid"
@ -19,14 +24,19 @@ func main() {
app.Version = "0.0.1" app.Version = "0.0.1"
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{
Name: "root",
Value: ocidRoot,
Usage: "ocid root dir",
},
cli.StringFlag{ cli.StringFlag{
Name: "sandboxdir", Name: "sandboxdir",
Value: "/var/lib/ocid/sandboxes", Value: filepath.Join(ocidRoot, "sandboxes"),
Usage: "ocid pod sandbox dir", Usage: "ocid pod sandbox dir",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "containerdir", Name: "containerdir",
Value: "/var/lib/ocid/containers", Value: filepath.Join(ocidRoot, "containers"),
Usage: "ocid container dir", Usage: "ocid container dir",
}, },
cli.StringFlag{ cli.StringFlag{
@ -94,7 +104,7 @@ func main() {
containerDir := c.String("containerdir") containerDir := c.String("containerdir")
sandboxDir := c.String("sandboxdir") sandboxDir := c.String("sandboxdir")
service, err := server.New(c.String("runtime"), sandboxDir, containerDir) service, err := server.New(c.String("runtime"), c.String("root"), sandboxDir, containerDir)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View file

@ -64,7 +64,7 @@ int main(int argc, char *argv[])
{ {
int ret; int ret;
int opt; int opt;
bool terminal = FALSE; bool terminal = false;
const char *cid = NULL; const char *cid = NULL;
const char *runtime_path = NULL; const char *runtime_path = NULL;
char cmd[CMD_SIZE]; char cmd[CMD_SIZE];
@ -88,7 +88,7 @@ int main(int argc, char *argv[])
while ((opt = getopt(argc, argv, "tc:r:")) != -1) { while ((opt = getopt(argc, argv, "tc:r:")) != -1) {
switch (opt) { switch (opt) {
case 't': case 't':
terminal = TRUE; terminal = true;
break; break;
case 'c': case 'c':
cid = optarg; cid = optarg;
@ -230,7 +230,8 @@ int main(int argc, char *argv[])
/* Copy data back and forth between STDIN and master fd */ /* Copy data back and forth between STDIN and master fd */
while (true) { while (true) {
int ready = epoll_wait(epfd, evlist, MAX_EVENTS, -1); int ready = epoll_wait(epfd, evlist, MAX_EVENTS, -1);
for (int i = 0; i < ready; i++) { int i = 0;
for (i = 0; i < ready; i++) {
if (evlist[i].events & EPOLLIN) { if (evlist[i].events & EPOLLIN) {
if (evlist[i].data.fd == STDIN_FILENO) { if (evlist[i].data.fd == STDIN_FILENO) {
num_read = num_read =

View file

@ -76,5 +76,3 @@ clone git github.com/gogo/protobuf 43a2e0b1c32252bfbbdf81f7faa7a88fb3fa4028
clone git github.com/gorilla/context v1.1 clone git github.com/gorilla/context v1.1
clean clean
mv vendor/src/* vendor/

View file

@ -89,6 +89,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR
// creates a spec Generator with the default spec. // creates a spec Generator with the default spec.
g := generate.New() g := generate.New()
podInfraRootfs := filepath.Join(s.root, "graph/vfs/pause")
// setup defaults for the pod sandbox // setup defaults for the pod sandbox
g.SetRootPath(filepath.Join(podInfraRootfs, "rootfs")) g.SetRootPath(filepath.Join(podInfraRootfs, "rootfs"))
g.SetRootReadonly(true) g.SetRootReadonly(true)

View file

@ -24,6 +24,7 @@ const (
// Server implements the RuntimeService and ImageService // Server implements the RuntimeService and ImageService
type Server struct { type Server struct {
root string
runtime *oci.Runtime runtime *oci.Runtime
sandboxDir string sandboxDir string
stateLock sync.Mutex stateLock sync.Mutex
@ -102,7 +103,7 @@ func (s *Server) reservePodName(id, name string) (string, error) {
} }
// New creates a new Server with options provided // New creates a new Server with options provided
func New(runtimePath, sandboxDir, containerDir string) (*Server, error) { func New(runtimePath, root, sandboxDir, containerDir string) (*Server, error) {
// TODO: This will go away later when we have wrapper process or systemd acting as // TODO: This will go away later when we have wrapper process or systemd acting as
// subreaper. // subreaper.
if err := utils.SetSubreaper(1); err != nil { if err := utils.SetSubreaper(1); err != nil {
@ -130,6 +131,7 @@ func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
return nil, err return nil, err
} }
s := &Server{ s := &Server{
root: root,
runtime: r, runtime: r,
netPlugin: netPlugin, netPlugin: netPlugin,
sandboxDir: sandboxDir, sandboxDir: sandboxDir,

85
test/helpers.bash Normal file
View file

@ -0,0 +1,85 @@
#!/bin/bash
# Root directory of integration tests.
INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")")
# Test data path.
TESTDATA="${INTEGRATION_ROOT}/../testdata"
# Root directory of the repository.
OCID_ROOT=${OCID_ROOT:-$(cd "$INTEGRATION_ROOT/../.."; pwd -P)}
# Path of the ocid binary.
OCID_BINARY=${OCID_BINARY:-${OCID_ROOT}/ocid/ocid}
# Path of the ocic binary.
OCIC_BINARY=${OCIC_BINARY:-${OCID_ROOT}/ocid/ocic}
# Path of the conmon binary.
CONMON_BINARY=${CONMON_BINARY:-${OCID_ROOT}/ocid/conmon/conmon}
# Path of the runc binary.
RUNC_PATH=$(command -v runc || true)
RUNC_BINARY=${RUNC_PATH:-/usr/local/sbin/runc}
TESTDIR=$(mktemp -d)
OCID_SOCKET="$TESTDIR/ocid.sock"
cp "$CONMON_BINARY" "$TESTDIR/conmon"
PATH=$PATH:$TESTDIR
# Run ocid using the binary specified by $OCID_BINARY.
# This must ONLY be run on engines created with `start_ocid`.
function ocid() {
"$OCID_BINARY" "$@"
}
# Run ocic using the binary specified by $OCID_BINARY.
function ocic() {
"$OCIC_BINARY" --socket "$OCID_SOCKET" "$@"
}
# Communicate with Docker on the host machine.
# Should rarely use this.
function docker_host() {
command docker "$@"
}
# Retry a command $1 times until it succeeds. Wait $2 seconds between retries.
function retry() {
local attempts=$1
shift
local delay=$1
shift
local i
for ((i=0; i < attempts; i++)); do
run "$@"
if [[ "$status" -eq 0 ]] ; then
return 0
fi
sleep $delay
done
echo "Command \"$@\" failed $attempts times. Output: $output"
false
}
# Waits until the given ocid becomes reachable.
function wait_until_reachable() {
retry 15 1 ocic runtimeversion
}
# Start ocid.
function start_ocid() {
"$OCID_BINARY" --debug --socket "$TESTDIR/ocid.sock" --runtime "$RUNC_BINARY" --root "$TESTDIR/ocid" & OCID_PID=$!
wait_until_reachable
}
# Stop ocid.
function stop_ocid() {
kill "$OCID_PID"
}
function cleanup_test() {
rm -rf "$TESTDIR"
# TODO(runcom): runc list and kill/delete everything!
}

14
test/runtimeversion.bats Normal file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env bats
load helpers
function teardown() {
stop_ocid
cleanup_test
}
@test "ocic runtimeversion" {
start_ocid
ocic runtimeversion
[ "$status" -eq 0 ]
}

18
test/test_runner.sh Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
# Load the helpers.
. helpers.bash
function execute() {
>&2 echo "++ $@"
eval "$@"
}
# Tests to run. Defaults to all.
TESTS=${@:-.}
# Run the tests.
execute time bats --tap $TESTS

View file

@ -1,7 +0,0 @@
// +build !experimental
package graphdriver
func lookupPlugin(name, home string, opts []string) (Driver, error) {
return nil, ErrNotSupported
}

View file

@ -1,27 +0,0 @@
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -199,3 +199,4 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.

View file

@ -31,3 +31,5 @@
### Docker Image ### Docker Image
- Use Alpine Linux as base image - Use Alpine Linux as base image

View file

@ -199,3 +199,4 @@ Apache License
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.

View file

@ -60,10 +60,10 @@ For information on upcoming functionality, please see [ROADMAP.md](ROADMAP.md).
By default, Docker users pull images from Docker's public registry instance. By default, Docker users pull images from Docker's public registry instance.
[Installing Docker](https://docs.docker.com/engine/installation/) gives users this [Installing Docker](https://docs.docker.com/engine/installation/) gives users this
ability. Users can also push images to a repository on Docker's public registry, ability. Users can also push images to a repository on Docker's public registry,
if they have a [Docker Hub](https://hub.docker.com/) account. if they have a [Docker Hub](https://hub.docker.com/) account.
For some users and even companies, this default behavior is sufficient. For For some users and even companies, this default behavior is sufficient. For
others, it is not. others, it is not.
For example, users with their own software products may want to maintain a For example, users with their own software products may want to maintain a
registry for private, company images. Also, you may wish to deploy your own registry for private, company images. Also, you may wish to deploy your own

View file

@ -27,7 +27,7 @@ considerations made in respect of the future of the project.
Components of the Distribution Project are managed via github [milestones](https://github.com/docker/distribution/milestones). Upcoming Components of the Distribution Project are managed via github [milestones](https://github.com/docker/distribution/milestones). Upcoming
features and bugfixes for a component will be added to the relevant milestone. If a feature or features and bugfixes for a component will be added to the relevant milestone. If a feature or
bugfix is not part of a milestone, it is currently unscheduled for bugfix is not part of a milestone, it is currently unscheduled for
implementation. implementation.
* [Registry](#registry) * [Registry](#registry)
* [Distribution Package](#distribution-package) * [Distribution Package](#distribution-package)
@ -40,7 +40,7 @@ The new Docker registry is the main portion of the distribution repository.
Registry 2.0 is the first release of the next-generation registry. This was Registry 2.0 is the first release of the next-generation registry. This was
primarily focused on implementing the [new registry primarily focused on implementing the [new registry
API](https://github.com/docker/distribution/blob/master/docs/spec/api.md), API](https://github.com/docker/distribution/blob/master/docs/spec/api.md),
with a focus on security and performance. with a focus on security and performance.
Following from the Distribution project goals above, we have a set of goals Following from the Distribution project goals above, we have a set of goals
for registry v2 that we would like to follow in the design. New features for registry v2 that we would like to follow in the design. New features
@ -105,9 +105,9 @@ landing in the registry.
##### Proxying to other Registries ##### Proxying to other Registries
A _pull-through caching_ mode exists for the registry, but is restricted from A _pull-through caching_ mode exists for the registry, but is restricted from
within the docker client to only mirror the official Docker Hub. This functionality within the docker client to only mirror the official Docker Hub. This functionality
can be expanded when image provenance has been specified and implemented in the can be expanded when image provenance has been specified and implemented in the
distribution project. distribution project.
##### Metadata storage ##### Metadata storage
@ -247,13 +247,13 @@ Please see the following issues for more detail:
- https://github.com/docker/distribution/issues/461 - https://github.com/docker/distribution/issues/461
- https://github.com/docker/distribution/issues/462 - https://github.com/docker/distribution/issues/462
### Distribution Package ### Distribution Package
At its core, the Distribution Project is a set of Go packages that make up At its core, the Distribution Project is a set of Go packages that make up
Distribution Components. At this time, most of these packages make up the Distribution Components. At this time, most of these packages make up the
Registry implementation. Registry implementation.
The package itself is considered unstable. If you're using it, please take care to vendor the dependent version. The package itself is considered unstable. If you're using it, please take care to vendor the dependent version.
For feature additions, please see the Registry section. In the future, we may break out a For feature additions, please see the Registry section. In the future, we may break out a
separate Roadmap for distribution-specific features that apply to more than separate Roadmap for distribution-specific features that apply to more than
@ -264,3 +264,4 @@ just the registry.
### Project Planning ### Project Planning
An [Open-Source Planning Process](https://github.com/docker/distribution/wiki/Open-Source-Planning-Process) is used to define the Roadmap. [Project Pages](https://github.com/docker/distribution/wiki) define the goals for each Milestone and identify current progress. An [Open-Source Planning Process](https://github.com/docker/distribution/wiki/Open-Source-Planning-Process) is used to define the Roadmap. [Project Pages](https://github.com/docker/distribution/wiki) define the goals for each Milestone and identify current progress.

Some files were not shown because too many files have changed in this diff Show more