1
0
mirror of https://github.com/rancher/os.git synced 2025-08-30 21:26:09 +00:00

Merge pull request #1122 from joshwget/refactor-integration-tests

Refactor integration tests
This commit is contained in:
Darren Shepherd 2016-07-20 20:28:22 -07:00 committed by GitHub
commit c1cd100dae
75 changed files with 545 additions and 938 deletions

View File

@ -145,6 +145,8 @@ RUN curl -fL ${!DOCKER_URL} > ${DOWNLOADS}/docker.tgz
# Install Trash
RUN go get github.com/rancher/trash
RUN go get gopkg.in/check.v1
# Install dapper
RUN curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m | sed 's/arm.*/arm/'` > /usr/bin/dapper && \
chmod +x /usr/bin/dapper

View File

@ -1,5 +1,5 @@
#!/bin/bash
# help: Run Python based integration tests
# help: Run integration tests
set -e
if [ "$INTEGRATION_TESTS" = 0 ]; then
@ -8,10 +8,10 @@ fi
source $(dirname $0)/version
cd $(dirname $0)/../tests/integration
cd $(dirname $0)/../tests
if [ ! -e ../../dist/artifacts/initrd ]; then
../../scripts/dev
if [ ! -e ../dist/artifacts/initrd ]; then
../scripts/dev
fi
tox "$@"
go test -timeout 20m

View File

@ -6,7 +6,7 @@ cd $(dirname $0)/..
echo Running tests
PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin)' | sed -e 's!^!./!' -e 's!$!/...!')"
PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin|tests)' | sed -e 's!^!./!' -e 's!$!/...!')"
if [ "$ARCH" = "amd64" ]; then
RACE="-race"

View File

@ -16,4 +16,4 @@ rancher:
docker:
args: [daemon, --log-opt, max-file=2, --log-opt, max-size=25m, -s, overlay, -G, docker, -H, 'unix:///var/run/docker.sock', --userland-proxy=false]
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF

View File

@ -99,4 +99,4 @@ rancher:
-----END RSA PRIVATE KEY-----
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF

View File

@ -0,0 +1,5 @@
#cloud-config
rancher:
console: debian
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF

View File

@ -0,0 +1,5 @@
#cloud-config
rancher:
console: debian
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF

View File

@ -0,0 +1,18 @@
#cloud-config
rancher:
environment:
A: A
BB: BB
BC: BC
services:
env:
image: busybox
command: env
labels:
io.rancher.os.scope: system
io.rancher.os.before: console
environment:
- A
- B*
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF

View File

@ -0,0 +1,3 @@
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF

View File

@ -0,0 +1,4 @@
#cloud-config
hostname: rancher-test
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF

View File

@ -0,0 +1,11 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestCloudConfigHostname(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_13/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, "hostname | grep rancher-test")
s.CheckCall(c, "cat /etc/hosts | grep rancher-test")
}

View File

@ -0,0 +1,10 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestCloudConfigMounts(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_16/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, "cat /home/rancher/test | grep test")
}

137
tests/common_test.go Normal file
View File

@ -0,0 +1,137 @@
package integration
import (
"fmt"
"os"
"os/exec"
"runtime"
"testing"
"time"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
func init() {
Suite(&QemuSuite{
runCommand: "../scripts/run",
sshCommand: "../scripts/ssh",
})
}
var (
BusyboxImage = map[string]string{
"amd64": "busybox",
"arm": "armhf/busybox",
"arm64": "aarch64/busybox",
}[runtime.GOARCH]
NginxImage = map[string]string{
"amd64": "nginx",
"arm": "armhfbuild/nginx",
"arm64": "armhfbuild/nginx",
}[runtime.GOARCH]
DockerUrl = "https://experimental.docker.com/builds/Linux/x86_64/docker-1.10.0-dev"
Version = os.Getenv("VERSION")
Suffix = os.Getenv("SUFFIX")
)
type QemuSuite struct {
runCommand string
sshCommand string
qemuCmd *exec.Cmd
}
func (s *QemuSuite) TearDownTest(c *C) {
c.Assert(s.qemuCmd.Process.Kill(), IsNil)
time.Sleep(time.Millisecond * 1000)
}
func (s *QemuSuite) RunQemu(additionalArgs ...string) error {
runArgs := []string{
"--qemu",
"--no-rebuild",
"--no-rm-usr",
"--fresh",
}
runArgs = append(runArgs, additionalArgs...)
s.qemuCmd = exec.Command(s.runCommand, runArgs...)
s.qemuCmd.Stdout = os.Stdout
s.qemuCmd.Stderr = os.Stderr
if err := s.qemuCmd.Start(); err != nil {
return err
}
return s.WaitForSSH()
}
func (s *QemuSuite) RestartQemu(additionalArgs ...string) error {
s.qemuCmd.Process.Kill()
time.Sleep(time.Millisecond * 1000)
runArgs := []string{
"--qemu",
"--no-rebuild",
"--no-rm-usr",
}
runArgs = append(runArgs, additionalArgs...)
s.qemuCmd = exec.Command(s.runCommand, runArgs...)
s.qemuCmd.Stdout = os.Stdout
s.qemuCmd.Stderr = os.Stderr
if err := s.qemuCmd.Start(); err != nil {
return err
}
return s.WaitForSSH()
}
func (s *QemuSuite) WaitForSSH() error {
sshArgs := []string{
"--qemu",
"docker",
"version",
">/dev/null",
"2>&1",
}
var err error
for i := 0; i < 300; i++ {
cmd := exec.Command(s.sshCommand, sshArgs...)
if err = cmd.Run(); err == nil {
return nil
}
time.Sleep(500 * time.Millisecond)
}
return fmt.Errorf("Failed to connect to SSH: %v", err)
}
func (s *QemuSuite) MakeCall(additionalArgs ...string) error {
sshArgs := []string{
"--qemu",
}
sshArgs = append(sshArgs, additionalArgs...)
cmd := exec.Command(s.sshCommand, sshArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func (s *QemuSuite) CheckCall(c *C, additionalArgs ...string) {
c.Assert(s.MakeCall(additionalArgs...), IsNil)
}
func (s *QemuSuite) Reboot() {
s.MakeCall("sudo reboot")
time.Sleep(3000 * time.Millisecond)
}
func (s *QemuSuite) LoadInstallerImage(c *C) {
cmd := exec.Command("sh", "-c", fmt.Sprintf("docker save rancher/os:%s%s | ../scripts/ssh --qemu sudo system-docker load", Version, Suffix))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
c.Assert(cmd.Run(), IsNil)
}

View File

@ -0,0 +1,14 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestCustomDockerInPersistentConsole(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_05/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, "curl", "-Lfo", "./docker", DockerUrl)
s.CheckCall(c, "chmod", "+x", "/home/rancher/docker")
s.CheckCall(c, "sudo", "ln", "-sf", "/home/rancher/docker", "/usr/bin/docker")
s.CheckCall(c, "sudo", "system-docker", "restart", "docker")
s.CheckCall(c, "sudo", "system-docker", "version")
}

View File

@ -0,0 +1,11 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestDhcpHostname(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_12/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, "hostname | grep rancher-dev")
s.CheckCall(c, "cat /etc/hosts | grep rancher-dev")
}

View File

@ -0,0 +1,20 @@
package integration
import (
"fmt"
. "gopkg.in/check.v1"
)
func (s *QemuSuite) TestRebootWithContainerRunning(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_03/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, fmt.Sprintf(`
set -e -x
docker run -d --restart=always %s`, NginxImage))
s.Reboot()
s.CheckCall(c, "docker ps -f status=running | grep nginx")
}

12
tests/environment_test.go Normal file
View File

@ -0,0 +1,12 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestEnvironment(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_11/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, "sudo system-docker inspect env | grep A=A")
s.CheckCall(c, "sudo system-docker inspect env | grep BB=BB")
s.CheckCall(c, "sudo system-docker inspect env | grep BC=BC")
}

32
tests/http_proxy_test.go Normal file
View File

@ -0,0 +1,32 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestHttpProxy(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_17/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, `
set -x -e
sudo system-docker exec docker env | grep HTTP_PROXY=invalid
sudo system-docker exec docker env | grep HTTPS_PROXY=invalid
sudo system-docker exec docker env | grep NO_PROXY=invalid
if docker pull busybox; then
exit 1
else
exit 0
fi`)
s.RestartQemu("--cloud-config", "./tests/assets/test_17/cloud-config.yml")
s.CheckCall(c, `
set -x -e
if sudo system-docker pull busybox; then
exit 1
else
exit 0
fi`)
}

18
tests/install_test.go Normal file
View File

@ -0,0 +1,18 @@
package integration
import (
"fmt"
. "gopkg.in/check.v1"
)
func (s *QemuSuite) TestInstall(c *C) {
err := s.RunQemu("--no-format")
c.Assert(err, IsNil)
s.LoadInstallerImage(c)
s.CheckCall(c, fmt.Sprintf(`
sudo mkfs.ext4 /dev/vda
sudo ros install -f --no-reboot -d /dev/vda -i rancher/os:%s%s`, Version, Suffix))
}

View File

@ -1 +0,0 @@
RancherOS Integration Tests

View File

@ -1,27 +0,0 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA1JbFgC+UX9ForPwO5O05asdH2UutFcwmaz2WGz/8JC/eY79F
8wsfG3da2R3sm25RzwzaTQ9wS7+Kj2OQ8UcnsReLHhrs3CSP6TrxlBo0KJ3XjD4A
0xRKOcPd/YEnXk2XH180NMAFYc8A24B+Mz3zM23aKPAIrvY5CpY18PCBY7tIIfre
oipBmQiIyk/aO882tbxn5KHYb4tld1cz3TTtvIGsWWkTbZgWFKFZxskep1zdUNwi
WlboeaOhjwjqq4RzW2DhWSgaQ4h28T4VacR0A9vvMlEhkxu1lu+RX2Xj42ucvHdH
PzuS9+2WMeAGQHdyoEGAwU9lwhCRkDWsDW36bQIDAQABAoIBAE9NGslxdji0BgcZ
U3kEIPn68otVVnCeIeq5I4hwut7I2H1++VnrWSRGxqXdKsjkQzIoSjqauroW7loE
uym18FF4RdXqF1cbcG+BJGKpz7EjCCfxbR9QH0wjC2koR4Y/DVOPkQroYlmU/W3k
Ja95uYICxXGl8KdLhAW1+NMy9CE+KmEc0j+7hkpTrmK1yfv4zT/jc2VjcF7jEV7s
sBN2OT6LwFixfJd4SWU8V50DWrzU64qhwKGCQtmCZX3Ym9vRd6KUoWd8jnwuN+KV
RttuqFCSrLw86TaUfgqnlF8lt2Dno2NAz5eyP/yq6m8SQ7pK5nVz1CXPXp24M5DW
9mWWa0UCgYEA65YecXBRTkgIvFo8yJj8DmmKQKVfe1OI6qKIVXzY2Dmzd+NE+WKJ
h1AKajZBKEHMILnPEtEMB226A0Sl1VsTY+dhDSsk34sgsP7zpbFI3S2ZzJMEkwoh
thQ9ihegzt+gn/hiHwaanYjuwELx0h+nIIinSph7aBA66yeisfPU/LsCgYEA5wKD
VIHdE3dDSpCDhuZefZpRQvTsP13XGoYU7IL0cFrTKL00CVzCAEEG2QPzJGro1KM5
+IRUf68G0C9z9MY+fPRY6/BLEKiV+S+sfPhlbxLg9IxJSO952advEpJWYYZHnh/d
SuXfglSLjWra3VgLh6aho9/jQ7+7enrEru3JRvcCgYEAuo3484mmyN+gE0893PfQ
ebU3prOOJcHjpTIp1dB0gt1GcgSFpRpTn9RROwRVmoRoGe4pvVPPO763U0k0LPzf
IPij0OK+Y0rwC1kJJcd61LL8nJQ7Rhj60w26IbVOQSOzNZpiUQFQxLkfnx4kEmnA
VbIBD8Ap0SExFvAfFN3qZmsCgYA8c53meW1e8LC9TH/+xz4m5EEromhIVMg7eqbz
FXneBQaI/KonYQyrgFjIZY41E30GWAiNjiOGnkjMJf7UKSSlElRKucELBPLqGJ2s
vlvc6zXPCP8MhQ5/9J7OX1kXgEoxiOkh9nG8617xjOrlTWsG/oYCGk6gpgXrkUDy
/erUFQKBgQDY8h3pTIC3ZvFcy0+UpvVMceLWfaP9+/8dTpAr0HClNOjQC0Fuq6cV
nazAREnDB62y4keGV5xcZdHQ9bZBR4dq4h1oFQUq7RJr5fsgaxN13JPJht2xf/ra
hK3WKZN5oa/hrRu5m+z9rOwR4T7B863cBs/b1YNj3eKUIakHJEv5xw==
-----END RSA PRIVATE KEY-----

View File

@ -1,5 +0,0 @@
#cloud-config
rancher:
console: debian
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt

View File

@ -1,5 +0,0 @@
#cloud-config
rancher:
console: debian
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt

View File

@ -1,18 +0,0 @@
#cloud-config
rancher:
environment:
A: A
BB: BB
BC: BC
services:
env:
image: busybox
command: env
labels:
io.rancher.os.scope: system
io.rancher.os.before: console
environment:
- A
- B*
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt

View File

@ -1,3 +0,0 @@
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt

View File

@ -1,4 +0,0 @@
#cloud-config
hostname: rancher-test
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt

View File

@ -1,2 +0,0 @@
PyYAML==3.11
pytest==2.7.2

View File

@ -1,13 +0,0 @@
import subprocess
import os
import pytest
import rostest
@pytest.fixture(scope="session", autouse=True)
def chdir_to_project_root():
os.chdir(os.path.join(os.path.dirname(rostest.__file__), '../../..'))
print('\nChdir to project root dir: ' + subprocess.check_output('pwd'))
os.chmod('./tests/integration/assets/test.key', 0o600)
print('Also, `chmod 600 tests/integration/assets/test.key` to make ssh happy')

View File

@ -1,49 +0,0 @@
from __future__ import print_function
import subprocess
import pytest
import rostest.util as u
@pytest.fixture(scope="module")
def qemu(request):
return u.run_qemu(request)
@pytest.mark.timeout(30)
def test_system_boot(qemu):
u.flush_out(qemu.stdout)
busybox = {'amd64': 'busybox', 'arm': 'armhf/busybox', 'arm64': 'aarch64/busybox'}
@pytest.mark.timeout(60)
def test_run_system_container(qemu):
u.wait_for_ssh(qemu)
ssh = subprocess.Popen(
'./scripts/ssh --qemu sudo system-docker run --rm ' + busybox[u.arch] + ' /bin/true',
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
for ln in u.iter_lines(ssh.stdout):
print(ln)
ssh.wait()
assert ssh.returncode == 0
@pytest.mark.timeout(60)
def test_ros_dev(qemu):
u.wait_for_ssh(qemu)
ssh = subprocess.Popen(
'./scripts/ssh --qemu sudo ros dev',
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
for ln in u.iter_lines(ssh.stdout):
print(ln)
ssh.wait()
assert ssh.returncode == 0

View File

@ -1,103 +0,0 @@
import string
import pytest
import rostest.util as u
from rostest.util import SSH
import yaml
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
cloud_config_path = './tests/integration/assets/test_01/cloud-config.yml'
net_args = {'amd64': ['-net', 'nic,vlan=1,model=virtio,macaddr=52:54:00:12:34:59',
'-net', 'user,vlan=1,net=10.10.2.0/24'],
'arm64': ['-netdev', 'user,id=net1,net=10.10.2.0/24',
'-device', 'virtio-net-device,netdev=net1,mac=52:54:00:12:34:59']}
net_args['arm'] = net_args['arm64']
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--cloud-config', cloud_config_path] + net_args[u.arch])
u.flush_out(q.stdout)
return q
@pytest.fixture(scope="module")
def cloud_config():
return yaml.load(open(cloud_config_path))
@pytest.mark.timeout(40)
def test_ssh_authorized_keys(qemu):
u.wait_for_ssh(qemu, ssh_command)
assert True
@pytest.mark.timeout(40)
def test_rancher_environment(qemu, cloud_config):
v = SSH(qemu, ssh_command).check_output('''
sudo ros env printenv FLANNEL_NETWORK
'''.strip())
assert v.strip() == cloud_config['rancher']['environment']['FLANNEL_NETWORK']
@pytest.mark.timeout(40)
def test_docker_args(qemu, cloud_config):
v = SSH(qemu, ssh_command).check_output('''
ps -ef | grep docker
'''.strip())
expected = string.join(cloud_config['rancher']['docker']['args'])
assert v.find(expected) != -1
@pytest.mark.timeout(40)
def test_dhcpcd(qemu, cloud_config):
v = SSH(qemu, ssh_command).check_output('''
ps -ef | grep dhcpcd
'''.strip())
assert v.find('dhcpcd -M') != -1
@pytest.mark.timeout(40)
def test_services_include(qemu, cloud_config):
u.wait_for_ssh(qemu, ssh_command, ['docker inspect kernel-headers >/dev/null 2>&1'])
@pytest.mark.timeout(40)
def test_docker_tls_args(qemu, cloud_config):
SSH(qemu, ssh_command).check_call('''
set -e -x
sudo ros tls gen --server -H localhost
sudo ros tls gen
sudo ros c set rancher.docker.tls true
sudo system-docker restart docker
sleep 5
docker --tlsverify version
'''.strip())
@pytest.mark.timeout(40)
def test_rancher_network(qemu, cloud_config):
v = SSH(qemu, ssh_command).check_output('''
ip route get to 10.10.2.120
'''.strip())
assert v.split(' ')[5] + '/24' == \
cloud_config['rancher']['network']['interfaces']['mac=52:54:00:12:34:59']['address']
def test_docker_pid_one(qemu):
SSH(qemu, ssh_command).check_call('''
set -e -x
for i in $(pidof docker); do
if [ $i = 1 ]; then
found=true
fi
done
[ "$found" = "true" ]
'''.strip())

View File

@ -1,22 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
cloud_config_path = './tests/integration/assets/test_02/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
@pytest.mark.timeout(40)
def test_docker_tls_args(qemu):
SSH(qemu, ssh_command).check_call('''
set -e -x
sudo ros tls gen
docker --tlsverify version
'''.strip())

View File

@ -1,38 +0,0 @@
import time
import pytest
import rostest.util as u
from rostest.util import SSH
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
cloud_config_path = './tests/integration/assets/test_03/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
nginx = {'amd64': 'nginx', 'arm': 'armhfbuild/nginx', 'arm64': 'armhfbuild/nginx'}
@pytest.mark.timeout(40)
def test_reboot_with_container_running(qemu):
try:
SSH(qemu, ssh_command).check_call('''
set -ex
docker run -d --restart=always %(image)s
sudo reboot
'''.strip() % {'image': nginx[u.arch]})
except:
pass
time.sleep(3)
v = SSH(qemu, ssh_command).check_output('''
docker ps -f status=running
'''.strip())
assert v.find('nginx') != -1

View File

@ -1,34 +0,0 @@
import subprocess
import pytest
import rostest.util as u
from rostest.util import SSH
ssh_command = ['./scripts/ssh', '--qemu']
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--no-format'])
u.flush_out(q.stdout)
return q
@pytest.mark.timeout(40)
def test_ros_install_on_formatted_disk(qemu):
u.wait_for_ssh(qemu, ssh_command)
subprocess.check_call(
['sh', '-c', 'docker save rancher/os:%s%s | ./scripts/ssh sudo system-docker load' % (u.version, u.suffix)],
stderr=subprocess.STDOUT, universal_newlines=True)
SSH(qemu, ssh_command).check_call('''
set -e -x
sudo mkfs.ext4 /dev/vda
sudo ros install -f --no-reboot -d /dev/vda -i rancher/os:%s%s
'''.strip() % (u.version, u.suffix))
subprocess.call(ssh_command + ['sudo', 'reboot'],
stderr=subprocess.STDOUT, universal_newlines=True)
u.wait_for_ssh(qemu, ssh_command)

View File

@ -1,39 +0,0 @@
import subprocess
import pytest
import rostest.util as u
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
cloud_config_path = './tests/integration/assets/test_05/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
docker_url = {'amd64': 'https://experimental.docker.com/builds/Linux/x86_64/docker-1.10.0-dev',
'arm': 'https://github.com/rancher/docker/releases/download/v1.10.3-arm/docker-1.10.3_arm',
'arm64': 'https://github.com/rancher/docker/releases/download/v1.10.3-arm/docker-1.10.3_arm64'}
@pytest.mark.timeout(40)
def test_system_docker_survives_custom_docker_install(qemu):
u.wait_for_ssh(qemu, ssh_command)
subprocess.check_call(ssh_command + ['curl', '-Lfo', './docker', docker_url[u.arch]],
stderr=subprocess.STDOUT, universal_newlines=True)
subprocess.check_call(ssh_command + ['chmod', '+x', '/home/rancher/docker'],
stderr=subprocess.STDOUT, universal_newlines=True)
subprocess.check_call(ssh_command + ['sudo', 'ln', '-sf', '/home/rancher/docker', '/usr/bin/docker'],
stderr=subprocess.STDOUT, universal_newlines=True)
subprocess.check_call(ssh_command + ['sudo', 'system-docker', 'restart', 'docker'],
stderr=subprocess.STDOUT, universal_newlines=True)
subprocess.check_call(ssh_command + ['sudo', 'system-docker', 'version'],
stderr=subprocess.STDOUT, universal_newlines=True)
u.wait_for_ssh(qemu, ssh_command)

View File

@ -1,19 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--append', 'rancher.state.directory=ros_subdir'])
u.flush_out(q.stdout)
return q
def test_system_docker_survives_custom_docker_install(qemu):
SSH(qemu).check_call('''
set -x -e
mkdir x
sudo mount $(sudo ros dev LABEL=RANCHER_STATE) x
[ -d x/ros_subdir/home/rancher ]
'''.strip())

View File

@ -1,50 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
pytestmark = pytest.mark.skipif(u.arch != 'amd64', reason='amd64 network setup impossible to replicate for arm64')
cloud_config_path = './tests/integration/assets/test_09/cloud-config.yml'
net_args_arch = {'amd64': ['-net', 'nic,vlan=0,model=virtio'],
'arm64': ['-device', 'virtio-net-device']}
net_args_arch['arm'] = net_args_arch['arm64']
net_args = net_args_arch[u.arch]
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request,
run_args=['--cloud-config', cloud_config_path] +
net_args + net_args + net_args + net_args + net_args + net_args + net_args)
u.flush_out(q.stdout)
return q
def test_network_interfaces_conf(qemu):
SSH(qemu).check_call('''cat > test-merge << "SCRIPT"
set -x -e
ip link show dev br0
ip link show dev br0.100 | grep br0.100@br0
ip link show dev eth1.100 | grep 'master br0'
ip link show dev eth6 | grep 'master bond0'
ip link show dev eth7 | grep 'master bond0'
[ "$(</sys/class/net/bond0/bonding/mode)" = "active-backup 1" ]
SCRIPT
sudo bash test-merge
'''.strip())
def test_network_dns_conf(qemu):
SSH(qemu).check_call('''cat > test-merge << "SCRIPT"
set -x -e
cat /etc/resolv.conf | grep "search mydomain.com example.com"
cat /etc/resolv.conf | grep "nameserver 208.67.222.123"
cat /etc/resolv.conf | grep "nameserver 208.67.220.123"
SCRIPT
sudo bash test-merge
'''.strip())

View File

@ -1,62 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
pytestmark = pytest.mark.skipif(u.arch != 'amd64', reason='amd64 network setup impossible to replicate for arm64')
cloud_config_path = './tests/integration/assets/test_10/cloud-config.yml'
net_args_arch = {'amd64': ['-net', 'nic,vlan=0,model=virtio'],
'arm64': ['-device', 'virtio-net-device']}
net_args_arch['arm'] = net_args_arch['arm64']
net_args = net_args_arch[u.arch]
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request,
run_args=['--cloud-config', cloud_config_path] +
net_args + net_args + net_args + net_args + net_args + net_args + net_args)
u.flush_out(q.stdout)
return q
def test_network_interfaces_conf(qemu):
SSH(qemu).check_call('''cat > test-merge << "SCRIPT"
set -x -e
ip link show dev br0
ip link show dev br0.100 | grep br0.100@br0
ip link show dev eth1.100 | grep 'master br0'
SCRIPT
sudo bash test-merge
'''.strip())
def test_network_dns_conf(qemu):
SSH(qemu).check_call('''cat > test-merge << "SCRIPT"
set -x -e
cat /etc/resolv.conf | grep "search mydomain.com example.com"
cat /etc/resolv.conf | grep "nameserver 208.67.222.123"
cat /etc/resolv.conf | grep "nameserver 208.67.220.123"
SCRIPT
sudo bash test-merge
'''.strip())
def test_network_dns_ros_set(qemu):
SSH(qemu).check_call('''
set -x -e
sudo ros config set rancher.network.dns.search '[a,b]'
if [ "$(sudo ros config get rancher.network.dns.search)" == "- a
- b
" ]; then
sudo ros config get rancher.network.dns.search
exit 1
fi
'''.strip())

View File

@ -1,24 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
cloud_config_path = {'amd64': './tests/integration/assets/test_11/cloud-config.yml',
'arm': './tests/integration/assets/test_11/cloud-config_arm.yml',
'arm64': './tests/integration/assets/test_11/cloud-config_arm64.yml'}
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--cloud-config', cloud_config_path[u.arch]])
u.flush_out(q.stdout)
return q
@pytest.mark.timeout(40)
def test_rancher_environment_in_system_service(qemu):
SSH(qemu, ssh_command).check_call('''
sudo system-docker logs env | grep A=A
sudo system-docker logs env | grep BB=BB
sudo system-docker logs env | grep BC=BC
''')

View File

@ -1,21 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
cloud_config_path = './tests/integration/assets/test_12/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
@pytest.mark.timeout(40)
def test_dhcp_hostname(qemu):
SSH(qemu, ssh_command).check_call('''
hostname | grep rancher-dev
cat /etc/hosts | grep rancher-dev
''')

View File

@ -1,21 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
cloud_config_path = './tests/integration/assets/test_13/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, ['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
@pytest.mark.timeout(40)
def test_cloud_config_hostname(qemu):
SSH(qemu, ssh_command).check_call('''
hostname | grep rancher-test
cat /etc/hosts | grep rancher-test
''')

View File

@ -1,21 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request)
u.flush_out(q.stdout)
return q
def test_shared_mount(qemu):
SSH(qemu).check_call('''
set -x -e
sudo mkdir /mnt/shared
sudo touch /test
sudo system-docker run --privileged -v /mnt:/mnt:shared -v /test:/test {busybox_image} mount --bind / /mnt/shared
ls /mnt/shared | grep test
'''.format(busybox_image=u.busybox_image))

View File

@ -1,17 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
cloud_config_path = './tests/integration/assets/test_16/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
def test_cloud_config_mounts(qemu):
SSH(qemu).check_call('cat /home/rancher/test | grep test')

View File

@ -1,45 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
cloud_config_path = './tests/integration/assets/test_17/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
def test_docker_http_proxy(qemu):
SSH(qemu).check_call('''
set -x -e
sudo system-docker exec docker env | grep HTTP_PROXY=invalid
sudo system-docker exec docker env | grep HTTPS_PROXY=invalid
sudo system-docker exec docker env | grep NO_PROXY=invalid
if docker pull busybox; then
exit 1
else
exit 0
fi
''')
def test_system_docker_http_proxy(qemu):
try:
SSH(qemu).check_call('sudo reboot')
except:
pass
SSH(qemu).check_call('''
set -x -e
if sudo system-docker pull busybox; then
exit 1
else
exit 0
fi
''')

View File

@ -1,26 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
pytestmark = pytest.mark.skipif(u.arch != 'amd64', reason='amd64 network setup impossible to replicate for arm64')
cloud_config_path = './tests/integration/assets/test_18/cloud-config.yml'
net_args_arch = {'amd64': ['-net', 'nic,vlan=1,model=virtio'],
'arm64': ['-device', 'virtio-net-device']}
net_args_arch['arm'] = net_args_arch['arm64']
net_args = net_args_arch[u.arch]
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request,
run_args=['--cloud-config', cloud_config_path] +
net_args + net_args + net_args)
u.flush_out(q.stdout)
return q
def test_network_resources_loaded(qemu):
SSH(qemu).check_call("apt-get --version")
SSH(qemu).check_call("sudo system-docker images | grep tianon/true")

View File

@ -1,18 +0,0 @@
import time
import pytest
import rostest.util as u
from rostest.util import SSH
cloud_config_path = './tests/integration/assets/test_19/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
def test_lenient_service_parsing(qemu):
time.sleep(5)
SSH(qemu).check_call("sudo system-docker ps -a | grep test-parsing")

View File

@ -1,17 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
cloud_config_path = './tests/integration/assets/test_20/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
def test_sysctl(qemu):
SSH(qemu).check_call("sudo cat /proc/sys/kernel/domainname | grep test")
SSH(qemu).check_call("sudo cat /proc/sys/dev/cdrom/debug | grep 1")

View File

@ -1,19 +0,0 @@
import pytest
import rostest.util as u
from rostest.util import SSH
cloud_config_path = './tests/integration/assets/test_21/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--second-drive', '--cloud-config',
cloud_config_path])
u.flush_out(q.stdout)
return q
def test_swap(qemu):
SSH(qemu).check_call("sudo mkswap /dev/vdb")
SSH(qemu).check_call("sudo cloud-init -execute")
SSH(qemu).check_call("cat /proc/swaps | grep /dev/vdb")

View File

@ -1,116 +0,0 @@
from __future__ import print_function
import itertools as it
import os
import subprocess
import time
import pytest
ros_test = 'ros-test'
arch = os.environ.get('ARCH', 'amd64')
version = os.environ.get('VERSION')
suffix = os.environ.get('SUFFIX')
if version is None or version == '' or suffix is None:
raise RuntimeError("Could not get VERSION or SUFFIX from environment")
busybox_image = {'amd64': 'busybox',
'arm': 'armhf/busybox',
'arm64': 'aarch64/busybox'}[arch]
def iter_lines(s):
return it.imap(str.rstrip, iter(s.readline, ''))
def strip_comment(prefix):
return lambda s: s.partition(prefix)[0].strip()
def non_empty(s):
return s != ''
def parse_value(var):
def get_value(s):
(k, _, v) = s.partition('=')
(k, v) = (k.strip(), v.strip())
if k == var:
return v
return ''
return get_value
def with_effect(p):
def effect(s):
p(s)
return s
return effect
def run_qemu(request, run_args=[]):
print('\nStarting QEMU')
p = subprocess.Popen(['./scripts/run', '--qemu', '--no-rebuild', '--no-rm-usr', '--fresh'] + run_args,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
assert p.returncode is None
def fin():
print('\nTerminating QEMU')
p.terminate()
p.wait()
request.addfinalizer(fin)
return p
def has_substr(token):
return lambda s: str.find(s, token) > -1
def flush_out(stdout, substr='RancherOS '):
for _ in it.ifilter(has_substr(substr),
it.imap(with_effect(print), iter_lines(stdout))):
return
@pytest.mark.timeout(10)
def wait_for_ssh(qemu, ssh_command=['./scripts/ssh', '--qemu'], command=['docker version >/dev/null 2>&1']):
i = 0
assert qemu.returncode is None
print('\nWaiting for ssh and docker... ' + str(i))
while subprocess.call(ssh_command + command) != 0:
i += 1
print('\nWaiting for ssh and docker... ' + str(i))
time.sleep(1)
if i > 150:
raise AssertionError('Failed to connect to SSH')
assert qemu.returncode is None
class SSH:
def __init__(self, qemu, ssh_command=['./scripts/ssh', '--qemu']):
self._qemu = qemu
self._ssh_command = ssh_command
self._waited = False
def wait(self):
if not self._waited:
wait_for_ssh(self._qemu, ssh_command=self._ssh_command)
self._waited = True
def check_call(self, *args, **kw):
self.wait()
kw['stderr'] = subprocess.STDOUT
kw['universal_newlines'] = True
return subprocess.check_call(self._ssh_command + list(args), **kw)
def check_output(self, *args, **kw):
self.wait()
kw['stderr'] = subprocess.STDOUT
kw['universal_newlines'] = True
return subprocess.check_output(self._ssh_command + list(args), **kw)

View File

@ -1,11 +0,0 @@
from distutils.core import setup
setup(
name='RancherOSIntegrationTests',
version='0.1',
packages=[
'rostest'
],
license='ASL 2.0',
long_description=open('README.txt').read(),
)

View File

@ -1,15 +0,0 @@
[tox]
envlist=flake8, py27
skipsdist=True
[testenv]
deps=-rrequirements.txt
passenv=HOST_ARCH ARCH VERSION SUFFIX
commands=py.test -s --durations=20 rostest {posargs}
[testenv:flake8]
deps=flake8
commands=flake8 rostest
[flake8]
max-line-length = 120

View File

@ -0,0 +1,12 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestLenientServiceParsing(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_19/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, `
sleep 5
sudo system-docker ps -a | grep test-parsing`)
}

35
tests/misc_test.go Normal file
View File

@ -0,0 +1,35 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestMisc(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_01/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, "sudo ros env printenv FLANNEL_NETWORK | grep '10.244.0.0/16'")
s.CheckCall(c, "ps -ef | grep 'daemon --log-opt max-file=2 --log-opt max-size=25m -s overlay -G docker -H unix:///var/run/docker.sock --userland-proxy=false'")
s.CheckCall(c, "ps -ef | grep 'dhcpcd -M'")
s.CheckCall(c, `
set -e -x
sudo ros tls gen --server -H localhost
sudo ros tls gen
sudo ros c set rancher.docker.tls true
sudo system-docker restart docker
sleep 5
docker --tlsverify version`)
s.CheckCall(c, `
set -e -x
for i in $(pidof docker); do
if [ $i = 1 ]; then
found=true
fi
done
[ "$found" = "true" ]`)
s.CheckCall(c, `
sleep 5
docker inspect kernel-headers`)
}

View File

@ -0,0 +1,35 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestNetworkFromUrl(c *C) {
netArgs := []string{"-net", "nic,vlan=0,model=virtio"}
args := []string{"--cloud-config", "./tests/assets/test_10/cloud-config.yml"}
for i := 0; i < 7; i++ {
args = append(args, netArgs...)
}
err := s.RunQemu(args...)
c.Assert(err, IsNil)
s.CheckCall(c, `
cat > test-merge << "SCRIPT"
set -x -e
ip link show dev br0
ip link show dev br0.100 | grep br0.100@br0
ip link show dev eth1.100 | grep 'master br0'
SCRIPT
sudo bash test-merge`)
s.CheckCall(c, `
cat > test-merge << "SCRIPT"
set -x -e
cat /etc/resolv.conf | grep "search mydomain.com example.com"
cat /etc/resolv.conf | grep "nameserver 208.67.222.123"
cat /etc/resolv.conf | grep "nameserver 208.67.220.123"
SCRIPT
sudo bash test-merge`)
}

View File

@ -0,0 +1,11 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestNetworkOnBoot(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_18/cloud-config.yml", "-net", "nic,vlan=1,model=virtio")
c.Assert(err, IsNil)
s.CheckCall(c, "apt-get --version")
s.CheckCall(c, "sudo system-docker images | grep tianon/true")
}

38
tests/network_test.go Normal file
View File

@ -0,0 +1,38 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestNetwork(c *C) {
netArgs := []string{"-net", "nic,vlan=0,model=virtio"}
args := []string{"--cloud-config", "./tests/assets/test_09/cloud-config.yml"}
for i := 0; i < 7; i++ {
args = append(args, netArgs...)
}
err := s.RunQemu(args...)
c.Assert(err, IsNil)
s.CheckCall(c, `
cat > test-merge << "SCRIPT"
set -x -e
ip link show dev br0
ip link show dev br0.100 | grep br0.100@br0
ip link show dev eth1.100 | grep 'master br0'
ip link show dev eth6 | grep 'master bond0'
ip link show dev eth7 | grep 'master bond0'
[ "$(</sys/class/net/bond0/bonding/mode)" = "active-backup 1" ]
SCRIPT
sudo bash test-merge`)
s.CheckCall(c, `
cat > test-merge << "SCRIPT"
set -x -e
cat /etc/resolv.conf | grep "search mydomain.com example.com"
cat /etc/resolv.conf | grep "nameserver 208.67.222.123"
cat /etc/resolv.conf | grep "nameserver 208.67.220.123"
SCRIPT
sudo bash test-merge`)
}

View File

@ -1,19 +1,12 @@
import time
import pytest
import rostest.util as u
from rostest.util import SSH
package integration
import . "gopkg.in/check.v1"
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--append', 'rancher.state.dev=x'])
u.flush_out(q.stdout)
return q
func (s *QemuSuite) TestOem(c *C) {
err := s.RunQemu("--append", "rancher.state.dev=x")
c.Assert(err, IsNil)
def test_oem(qemu):
try:
SSH(qemu).check_call('''
s.CheckCall(c, `
set -x
set -e
sudo mkfs.ext4 -L RANCHER_OEM /dev/vda
@ -25,15 +18,11 @@ rancher:
url: 'foo'
EOF
sudo cp /tmp/oem-config.yml /mnt
sudo umount /mnt
sudo reboot
'''.strip())
except:
pass
sudo umount /mnt`)
time.sleep(3)
s.Reboot()
SSH(qemu).check_call('''
s.CheckCall(c, `
set -x
if [ ! -e /usr/share/ros/oem/oem-config.yml ]; then
echo Failed to find /usr/share/ros/oem/oem-config.yml
@ -44,5 +33,5 @@ FOO="$(sudo ros config get rancher.upgrade.url)"
if [ "$FOO" != "foo" ]; then
echo rancher.upgrade.url is not foo
exit 1
fi
'''.strip())
fi`)
}

View File

@ -1,19 +1,12 @@
import pytest
import rostest.util as u
from rostest.util import SSH
package integration
cloud_config_path = './tests/integration/assets/test_14/cloud-config.yml'
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestRosConfig(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_14/cloud-config.yml")
c.Assert(err, IsNil)
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path])
u.flush_out(q.stdout)
return q
def test_ros_config_string(qemu):
SSH(qemu).check_call('''
s.CheckCall(c, `
set -x -e
if [ "$(sudo ros config get hostname)" == "hostname3
@ -27,12 +20,9 @@ if [ "$(sudo ros config get hostname)" == "rancher-test
" ]; then
sudo ros config get hostname
exit 1
fi
'''.strip())
fi`)
def test_ros_config_bool(qemu):
SSH(qemu).check_call('''
s.CheckCall(c, `
set -x -e
if [ "$(sudo ros config get rancher.log)" == "true
@ -59,12 +49,9 @@ if [ "$(sudo ros config get rancher.debug)" == "true
" ]; then
sudo ros config get rancher.debug
exit 1
fi
'''.strip())
fi`)
def test_ros_config_slice(qemu):
SSH(qemu).check_call('''
s.CheckCall(c, `
set -x -e
sudo ros config set rancher.network.dns.search '[a,b]'
@ -81,12 +68,9 @@ if [ "$(sudo ros config get rancher.network.dns.search)" == "[]
" ]; then
sudo ros config get rancher.network.dns.search
exit 1
fi
'''.strip())
fi`)
def test_ros_export(qemu):
SSH(qemu).check_call('''
s.CheckCall(c, `
set -x -e
if sudo ros config export | grep "PRIVATE KEY"; then
@ -99,5 +83,5 @@ sudo ros config export --full | grep "udev"
sudo ros config export --private --full | grep "ntp"
sudo ros config export --full | grep "labels"
sudo ros config export --private --full | grep "PRIVATE KEY"
'''.strip())
sudo ros config export --private --full | grep "PRIVATE KEY"`)
}

View File

@ -0,0 +1,20 @@
package integration
import (
"fmt"
. "gopkg.in/check.v1"
)
func (s *QemuSuite) TestSharedMount(c *C) {
err := s.RunQemu()
c.Assert(err, IsNil)
s.CheckCall(c, fmt.Sprintf(`
set -x -e
sudo mkdir /mnt/shared
sudo touch /test
sudo system-docker run --privileged -v /mnt:/mnt:shared -v /test:/test %s mount --bind / /mnt/shared
ls /mnt/shared | grep test`, BusyboxImage))
}

View File

@ -1,17 +1,13 @@
import pytest
import rostest.util as u
from rostest.util import SSH
package integration
import . "gopkg.in/check.v1"
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request)
u.flush_out(q.stdout)
return q
func (s *QemuSuite) TestSshKeyMerge(c *C) {
err := s.RunQemu()
c.Assert(err, IsNil)
def test_ssh_key_merging(qemu):
SSH(qemu).check_call('''cat > test-merge << "SCRIPT"
s.CheckCall(c, `
cat > test-merge << "SCRIPT"
set -x -e
rm /var/lib/rancher/conf/cloud-config.yml
@ -39,5 +35,5 @@ ros config get ssh_authorized_keys > got
diff got expected
SCRIPT
sudo bash test-merge
'''.strip())
sudo bash test-merge`)
}

14
tests/subdir_test.go Normal file
View File

@ -0,0 +1,14 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestSubdir(c *C) {
err := s.RunQemu("--append", "rancher.state.directory=ros_subdir")
c.Assert(err, IsNil)
s.CheckCall(c, `
set -x -e
mkdir x
sudo mount $(sudo ros dev LABEL=RANCHER_STATE) x
[ -d x/ros_subdir/home/rancher ]`)
}

12
tests/swap_test.go Normal file
View File

@ -0,0 +1,12 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestSwap(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_21/cloud-config.yml", "--second-drive")
c.Assert(err, IsNil)
s.CheckCall(c, "sudo mkswap /dev/vdb")
s.CheckCall(c, "sudo cloud-init -execute")
s.CheckCall(c, "cat /proc/swaps | grep /dev/vdb")
}

11
tests/sysctl_test.go Normal file
View File

@ -0,0 +1,11 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestSysctl(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_20/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, "sudo cat /proc/sys/kernel/domainname | grep test")
s.CheckCall(c, "sudo cat /proc/sys/dev/cdrom/debug | grep 1")
}

13
tests/tls_test.go Normal file
View File

@ -0,0 +1,13 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestTls(c *C) {
err := s.RunQemu("--cloud-config", "./tests/assets/test_02/cloud-config.yml")
c.Assert(err, IsNil)
s.CheckCall(c, `
set -e -x
sudo ros tls gen
docker --tlsverify version`)
}