1
0
mirror of https://github.com/rancher/os.git synced 2025-09-22 19:10:13 +00:00

Merge pull request #547 from imikushin/tests

Revive integration tests
This commit is contained in:
Darren Shepherd
2015-09-04 10:49:12 -07:00
20 changed files with 86 additions and 85 deletions

View File

@@ -8,5 +8,8 @@ tmp
state
build
dist
assets
Godeps/_workspace/pkg
tests/integration/.venv*
tests/integration/.tox
*/*/*/*.pyc
*/*/*/__pycache__

View File

@@ -7,5 +7,8 @@ gopath
tmp
state
build
assets
Godeps/_workspace/pkg
tests/integration/.venv*
tests/integration/.tox
*/*/*/*.pyc
*/*/*/__pycache__

2
.gitignore vendored
View File

@@ -10,3 +10,5 @@
/tests/integration/MANIFEST
/tests/integration/.venv*
/tests/integration/.tox
*.pyc
__pychache__

View File

@@ -2,7 +2,8 @@ FROM debian:jessie
RUN apt-get update && \
apt-get -y dist-upgrade && \
apt-get -y install locales sudo vim less curl wget git rsync build-essential syslinux isolinux xorriso \
libblkid-dev libmount-dev libselinux1-dev
libblkid-dev libmount-dev libselinux1-dev genisoimage qemu-kvm python-pip
RUN ln -s /usr/bin/genisoimage /usr/bin/mkisofs
RUN locale-gen en_US.UTF-8
RUN curl -sSL https://get.docker.com/ | sh
@@ -11,6 +12,8 @@ RUN curl -sSL https://get.docker.com/ | sh
#ENV LC_ALL en_US.UTF-8
#ENV TERM linux
RUN pip install tox
ENV GOLANG_VERSION 1.4.2
RUN curl -sSL https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz | tar -v -C /usr/src -xz
RUN cd /usr/src/go/src && ./make.bash --no-clean 2>&1

View File

@@ -60,5 +60,7 @@ build-all: \
$(DIST)/artifacts/rancheros.iso \
$(DIST)/artifacts/iso-checksums.txt
integration-tests:
cd tests/integration && tox
.PHONY: build-all installer version bin/rancheros
.PHONY: build-all installer version bin/rancheros integration-tests

Binary file not shown.

View File

@@ -9,4 +9,4 @@ fi
docker build -t ros-build-base -f Dockerfile.build-base .
docker build -t ros-build -f Dockerfile.build .
./scripts/docker-run.sh make -f Makefile.docker build-all
./scripts/docker-run.sh make -f Makefile.docker build-all integration-tests

View File

@@ -8,6 +8,9 @@ if [ -n "$BIND_DIR" ]; then
fi
DOCKER_ARGS="-t -v $BIND_DIR:/go/src/github.com/rancherio/os"
fi
if [ -c /dev/kvm ] || [ "${PRIVILEGED}" == "1" ]; then
DOCKER_ARGS="${DOCKER_ARGS} --privileged"
fi
docker rm -fv ros-build >/dev/null 2>&1 || true
exec docker run -i -v /var/run/docker.sock:/var/run/docker.sock $DOCKER_ARGS --name=ros-build ros-build "$@"

View File

@@ -22,7 +22,7 @@ HD_GZ=${BASE}/assets/empty-hd.img.gz
INITRD_TMP=${BUILD}/$(${sha1sum} ${INITRD} | awk '{print $1}')
INITRD_CURRENT=${BUILD}/initrd-current
INITRD_TEST=${BUILD}/initrd.test
USER_DATA=cloud-init/openstack/latest/user_data
USER_DATA=${BUILD}/cloud-config/openstack/latest/user_data
# PREREQ: brew install coreutils
path() {
@@ -45,6 +45,11 @@ while [ "$#" -gt 0 ]; do
exit 1
fi
;;
--xhyve)
if [ "$UNAME" == "Darwin" ] && [ -x $(which xhyve) ]; then
XHYVE=1
fi
;;
*)
break
;;
@@ -77,14 +82,15 @@ ln -sf ${INITRD_TMP} ${INITRD_CURRENT}
mkdir -p ${INITRD_TMP}/usr/{bin,share/ros}
cp bin/rancheros ${INITRD_TMP}/usr/bin/ros
cp -f os-config.yml ${INITRD_TMP}/usr/share/ros
cd ${INITRD_TMP}
pushd ${INITRD_TMP}
find . | cpio -H newc -o > ${INITRD_TEST}
popd
if [ ! -e ${HD} ]; then
mkdir -p $(dirname ${HD})
if [ "$UNAME" == "Darwin" ]; then qemu-img create -f raw -o size=10G ${HD}
elif [ "$UNAME" == "Linux" ]; then gzip -dc ${HD_GZ} > ${HD};
if [ "$XHYVE" == "1" ]; then qemu-img create -f raw -o size=10G ${HD}
else qemu-img create -f qcow2 -o size=10G ${HD}
fi
fi
@@ -103,18 +109,18 @@ else
done
fi
KERNEL_ARGS="rancher.password=rancher rancher.modules=[9p,9pnet_virtio] console=ttyS0 ${QEMU_APPEND}"
KERNEL_ARGS="quiet rancher.password=rancher console=ttyS0 ${QEMU_APPEND}"
KERNEL_ARGS="${KERNEL_ARGS} rancher.state.formatzero=true rancher.state.autoformat=[/dev/sda,/dev/vda]"
if [ "$UNAME" == "Darwin" ] && [ -x $(which xhyve) ]; then
CLOUD_CONFIG_ISO="${BUILD}/cloud-config.iso"
rm -rf ${CLOUD_CONFIG_ISO}
CLOUD_CONFIG_ISO="$(pwd)/cloud-config.iso"
rm -rf ${CLOUD_CONFIG_ISO}
mkisofs -R -V config-2 -o "${CLOUD_CONFIG_ISO}" "$BUILD/cloud-config"
# PREREQ: brew install cdrtools
mkisofs -R -V config-2 -o "${CLOUD_CONFIG_ISO}" "$(pwd)/cloud-init"
if [ "$XHYVE" == "1" ]; then
echo PWD=`pwd`
exec sudo xhyve -A -H -P -u \
exec sudo -n xhyve -A -H -P -u \
-m 4G \
-s 0:0,hostbridge -s 31,lpc \
-l com1,stdio \
@@ -122,9 +128,12 @@ if [ "$UNAME" == "Darwin" ] && [ -x $(which xhyve) ]; then
-s 3,ahci-cd,${CLOUD_CONFIG_ISO} \
-s 4,virtio-blk,${HD} \
-U a01fb25c-3a19-4759-a47a-2e353e51807d \
-f kexec,${KERNEL},${INITRD_TEST},"earlyprintk=serial elevator=noop rancher.state.formatzero=true rancher.state.autoformat=[/dev/sda,/dev/vda] ${KERNEL_ARGS}"
-f kexec,${KERNEL},${INITRD_TEST},"earlyprintk=serial elevator=noop ${KERNEL_ARGS}"
elif [ "$UNAME" == "Linux" ] && [ -x $(which qemu-system-x86_64) ]; then
elif [ -x $(which qemu-system-x86_64) ]; then
if [ -c /dev/kvm ] && [ -r /dev/kvm ] && [ -w /dev/kvm ]; then
KVM_ENABLE="-machine accel=kvm -cpu host"
fi
exec qemu-system-x86_64 -serial stdio \
-kernel ${KERNEL} \
-initrd ${INITRD_TEST} \
@@ -132,14 +141,12 @@ elif [ "$UNAME" == "Linux" ] && [ -x $(which qemu-system-x86_64) ]; then
-net nic,vlan=0,model=virtio \
-net user,vlan=0,hostfwd=tcp::2222-:22,hostname=rancher-dev \
-drive if=virtio,file=${HD} \
-machine accel=kvm \
-cpu host \
${KVM_ENABLE} \
-smp 4 \
-fsdev local,id=conf,security_model=none,readonly,path=$(pwd)/cloud-init \
-device virtio-9p-pci,fsdev=conf,mount_tag=config-2 \
-cdrom ${CLOUD_CONFIG_ISO} \
-append "${KERNEL_ARGS}" \
-serial mon:telnet:localhost:4444,server,nowait \
-nographic \
-display none \
${QEMU_ARGS} "${@}"
else
exit 42

View File

@@ -7,10 +7,24 @@ chmod 0600 ./assets/rancher.key
UNAME=$(uname)
if [ "$UNAME" == "Darwin" ]; then
while [ "$#" -gt 0 ]; do
case $1 in
--xhyve)
shift 1
if [ "$UNAME" == "Darwin" ] && [ -x $(which xhyve) ]; then
XHYVE=1
fi
;;
*)
break
;;
esac
done
if [ "$XHYVE" == "1" ]; then
HOST=192.168.64.2 # consult `/var/db/dhcpd_leases` or delete it
exec ssh -F ./assets/scripts_ssh_config -i ./assets/rancher.key rancher@${HOST} "$@"
elif [ "$UNAME" == "Linux" ]; then
else
exec ssh -p 2222 -F ./assets/scripts_ssh_config -i ./assets/rancher.key rancher@localhost "$@"
fi

View File

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

View File

@@ -1,6 +0,0 @@
def func(x):
return x + 1
def test_answer():
assert func(3) == 4

View File

@@ -1,3 +0,0 @@
flake8==2.4.0
pytest==2.7.0
tox==1.9.2

View File

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

View File

@@ -1,12 +0,0 @@
[tox]
envlist=flake8, py27
[testenv]
deps=-rrequirements.txt
changedir={toxinidir}
commands=py.test --durations=20 {posargs}
[testenv:flake8]
deps=-rrequirements.txt
changedir={toxinidir}
commands=flake8 rancheros

View File

@@ -1,10 +1,11 @@
import os
import pytest
import subprocess
@pytest.fixture(scope="session", autouse=True)
def chdir_to_project_root():
os.chdir('../..')
print('\nChdir to project root dir')
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

@@ -10,7 +10,7 @@ def qemu(request):
def rancheros_version():
with open('./scripts/version') as f:
for ln in iter(f.readline, ''):
for ln in f:
(k, _, v) = ln.partition('=')
if k == 'VERSION' and v.strip() != '':
return v.strip()
@@ -19,13 +19,14 @@ def rancheros_version():
@pytest.mark.timeout(30)
def test_system_boot(qemu):
with qemu.stdout as f:
for ln in iter(f.readline, ''):
ros_booted_substr = str.find(ln, 'RancherOS {v} started'.format(v=rancheros_version()))
print(str.strip(ln))
if ros_booted_substr > -1:
assert True
return
version = rancheros_version()
print('parsed version: ' + version)
for ln in u.iter_lines(qemu.stdout):
ros_booted_substr = str.find(ln, 'RancherOS {v} started'.format(v=version))
print(str.strip(ln))
if ros_booted_substr > -1:
assert True
return
assert False
@@ -38,8 +39,8 @@ def test_run_system_container(qemu):
'./scripts/ssh sudo system-docker run --rm busybox /bin/true', shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
with ssh, ssh.stdout as f:
for ln in iter(f.readline, ''):
print(str.strip(ln))
for ln in u.iter_lines(ssh.stdout):
print(str.strip(ln))
ssh.wait()
assert ssh.returncode == 0

View File

@@ -3,6 +3,10 @@ import subprocess
import time
def iter_lines(s):
return iter(s.readline, '')
def run_qemu(request, run_args=[]):
subprocess.check_call('rm -f ./state/empty-hd.img', shell=True)
print('\nrm ./state/*')

View File

@@ -1,10 +1,2 @@
PyYAML.Yandex==3.11.1
flake8==2.4.0
mccabe==0.3
pep8==1.6.2
py==1.4.27
pyflakes==0.8.1
pytest==2.7.0
pytest-timeout==0.4
tox==1.9.2
virtualenv==12.1.1
PyYAML==3.11
pytest==2.7.2

View File

@@ -1,14 +1,13 @@
[tox]
envlist=flake8, py34
envlist=flake8, py27
skipsdist=True
[testenv]
deps=-rrequirements.txt
changedir={toxinidir}
commands=py.test --durations=20 {posargs}
commands=py.test -s --durations=20 rancherostest {posargs}
[testenv:flake8]
deps=-rrequirements.txt
changedir={toxinidir}
deps=flake8
commands=flake8 rancherostest
[flake8]