Skip to content

Commit

Permalink
Merge pull request #390 from istalker2/e2e-go
Browse files Browse the repository at this point in the history
New e2e test suite in golang
  • Loading branch information
jellonek authored Aug 29, 2017
2 parents ea22295 + 07bba08 commit e190dab
Show file tree
Hide file tree
Showing 23 changed files with 2,226 additions and 363 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ jobs:
NONINTERACTIVE=1 \
NO_VM_CONSOLE=1 \
INJECT_LOCAL_IMAGE=1 \
VIRTLET_DEMO_RELEASE=master \
BASE_LOCATION="$PWD" \
deploy/demo.sh
- run:
name: Run e2e tests
command: |
build/portforward.sh 8080&
tests/e2e/e2e.sh
_output/virtlet-e2e-tests -test.v
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -y libvirt-bin libguestfs0 libguestfs-tools genisoimage \
openssl qemu-kvm qemu-system-x86 python-libvirt \
netbase iproute2 iptables ebtables && \
netbase iproute2 iptables ebtables vncsnapshot && \
apt-get clean

RUN mkdir -p /var/lib/virtlet/volumes /opt/cni/bin && \
Expand All @@ -26,3 +26,4 @@ COPY _output/virtlet /usr/local/bin
COPY _output/vmwrapper /
COPY _output/criproxy /
COPY _output/virtlet_log /
COPY _output/virtlet-e2e-tests /
11 changes: 6 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ all:
patch -d vendor/github.com/libvirt/libvirt-go-xml -p1 -b -i $(CURDIR)/libvirt-xml-go.patch; \
fi
mkdir -p $(builddir)/_output $(builddir)/contrib/images/libvirt/_output
go build -o $(builddir)/_output/virtlet ./cmd/virtlet
go build -o $(builddir)/_output/vmwrapper ./cmd/vmwrapper
go build -o $(builddir)/_output/criproxy ./cmd/criproxy
go build -o $(builddir)/_output/flexvolume_driver ./cmd/flexvolume_driver
go build -o $(builddir)/_output/virtlet_log ./cmd/virtlet_log
go build -i -o $(builddir)/_output/virtlet ./cmd/virtlet
go build -i -o $(builddir)/_output/vmwrapper ./cmd/vmwrapper
go build -i -o $(builddir)/_output/criproxy ./cmd/criproxy
go build -i -o $(builddir)/_output/flexvolume_driver ./cmd/flexvolume_driver
go build -i -o $(builddir)/_output/virtlet_log ./cmd/virtlet_log
go test -i -c -o $(builddir)/_output/virtlet-e2e-tests ./tests/e2e

verify-glide-installation:
@which glide || go get github.com/Masterminds/glide
Expand Down
52 changes: 50 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ import:
# version: 56fd84210219dbdfe6501fb2085adfb8e61f2bc1
- package: github.com/jonboulle/clockwork
version: bcac9884e7502bb2b474c0339d889cb981a2f27f
- package: github.com/onsi/ginkgo
- package: github.com/onsi/gomega
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ fi
docker build -t mirantis/virtlet .

VIRTLET_DEMO_RELEASE=master NONINTERACTIVE=1 NO_VM_CONSOLE=1 INJECT_LOCAL_IMAGE=1 BASE_LOCATION="${SCRIPT_DIR}" deploy/demo.sh
tests/e2e/e2e.sh
./_output/virtlet-e2e-tests -test.v
172 changes: 172 additions & 0 deletions tests/e2e/basic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
Copyright 2017 Mirantis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"encoding/json"
"fmt"
"path"
"strings"
"time"

. "github.com/onsi/gomega"

"github.com/Mirantis/virtlet/tests/e2e/framework"
. "github.com/Mirantis/virtlet/tests/e2e/ginkgo-ext"
)

var _ = Describe("Basic cirros tests", func() {
var (
vm *framework.VMInterface
vmPod *framework.PodInterface
)

BeforeAll(func() {
vm = controller.VM("cirros-vm")
vm.Create(framework.VMOptions{
Image: *cirrosLocation,
SSHKey: sshPublicKey,
VCPUCount: 1,
DiskDriver: "virtio",
Limits: map[string]string{
"memory": "128Mi",
},
}, time.Minute*5, nil)
var err error
vmPod, err = vm.Pod()
Expect(err).NotTo(HaveOccurred())
})

AfterAll(func() {
deleteVM(vm)
})

Context("VM guest OS", func() {
var ssh framework.Executor
scheduleWaitSSH(&vm, &ssh)

It("Should have default route", func() {
Expect(framework.ExecSimple(ssh, "ip r")).To(SatisfyAll(
ContainSubstring("default via"),
ContainSubstring("src "+vmPod.Pod.Status.PodIP),
))
})

It("Should have internet connectivity", func(done Done) {
defer close(done)
Expect(framework.ExecSimple(ssh, "ping -c1 8.8.8.8")).To(ContainSubstring(
"1 packets transmitted, 1 packets received, 0% packet loss"))
}, 5)

Context("With nginx server", func() {
var nginxPod *framework.PodInterface

BeforeAll(func() {
p, err := controller.RunPod("nginx", "nginx", nil, time.Minute*4, 80)
Expect(err).NotTo(HaveOccurred())
Expect(p).NotTo(BeNil())
nginxPod = p
})

AfterAll(func() {
Expect(nginxPod.Delete()).To(Succeed())
})

It("Should be able to access another k8s endpoint", func(done Done) {
defer close(done)
cmd := fmt.Sprintf("curl -s --connect-timeout 5 http://nginx.%s.svc.cluster.local", controller.Namespace())
Eventually(func() (string, error) {
return framework.ExecSimple(ssh, cmd)
}, 60).Should(ContainSubstring("Thank you for using nginx."))
}, 60*5)
})

It("Should have hostname equal to the pod name", func() {
Expect(framework.ExecSimple(ssh, "hostname")).To(Equal(vmPod.Pod.Name))
})

It("Should have CPU count that was specified for the pod", func() {
checkCPUCount(vm, ssh, 1)
})
})

Context("Virtlet logs", func() {
var (
filename string
sandboxID string
nodeExecutor framework.Executor
)

BeforeAll(func() {
virtletPod, err := vm.VirtletPod()
Expect(err).NotTo(HaveOccurred())
nodeExecutor, err = virtletPod.DinDNodeExecutor()
Expect(err).NotTo(HaveOccurred())

domain, err := vm.Domain()
Expect(err).NotTo(HaveOccurred())
var logPath string
for _, serial := range domain.Devices.Serials {
if serial.Type == "file" {
logPath = serial.Source.Path
break
}
}
Expect(logPath).NotTo(BeEmpty())
var dir string
dir, filename = path.Split(logPath)
sandboxID = path.Base(dir)
})

It("Should contain login string in VM log", func() {
out := do(framework.ExecSimple(nodeExecutor, "cat",
fmt.Sprintf("/var/log/virtlet/vms/%s/%s", sandboxID, filename))).(string)
Expect(strings.Count(out,
"login as 'cirros' user. default password: 'cubswin:)'. use 'sudo' for root.",
)).To(Equal(1))
})

It("Should contain login string in pod log and each line of that log must be a valid JSON", func() {
out := do(framework.ExecSimple(nodeExecutor, "cat",
fmt.Sprintf("/var/log/pods/%s/%s", sandboxID, filename))).(string)
found := 0
for _, line := range strings.Split(out, "\n") {
var entry map[string]string
Expect(json.Unmarshal([]byte(line), &entry)).To(Succeed())
if strings.HasPrefix(entry["log"], "login as 'cirros' user. default password") {
found++
}
}
Expect(found).To(Equal(1))
})
})

It("Should provide VNC interface", func(done Done) {
defer close(done)
pod, err := vm.VirtletPod()
Expect(err).NotTo(HaveOccurred())

virtletPodExecutor, err := pod.Container("virtlet")
Expect(err).NotTo(HaveOccurred())

display, err := vm.VirshCommand("vncdisplay", "<domain>")
Expect(err).NotTo(HaveOccurred())

By(fmt.Sprintf("Taking VNC display snapshot from %s", display))
do(framework.ExecSimple(virtletPodExecutor, "vncsnapshot", "-allowblank", display, "/vm.jpg"))
}, 60)
})
Loading

0 comments on commit e190dab

Please sign in to comment.