diff --git a/.dockerignore b/.dockerignore index fe5669be..4d50ab09 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,5 +8,8 @@ tmp state build dist -assets Godeps/_workspace/pkg +tests/integration/.venv* +tests/integration/.tox +*/*/*/*.pyc +*/*/*/__pycache__ diff --git a/.dockerignore.docker b/.dockerignore.docker index b36c0d26..0b3eb86d 100644 --- a/.dockerignore.docker +++ b/.dockerignore.docker @@ -7,5 +7,8 @@ gopath tmp state build -assets Godeps/_workspace/pkg +tests/integration/.venv* +tests/integration/.tox +*/*/*/*.pyc +*/*/*/__pycache__ diff --git a/.gitignore b/.gitignore index 342b3516..38ff8a7b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ /tests/integration/MANIFEST /tests/integration/.venv* /tests/integration/.tox +*.pyc +__pychache__ diff --git a/Dockerfile.build-base b/Dockerfile.build-base index 3355c155..50c7e335 100644 --- a/Dockerfile.build-base +++ b/Dockerfile.build-base @@ -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 diff --git a/Makefile.docker b/Makefile.docker index 761afc39..b0ff821a 100644 --- a/Makefile.docker +++ b/Makefile.docker @@ -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 diff --git a/assets/empty-hd.img.gz b/assets/empty-hd.img.gz deleted file mode 100644 index 7ccbceb1..00000000 Binary files a/assets/empty-hd.img.gz and /dev/null differ diff --git a/scripts/ci b/scripts/ci index fb50b2cb..0a2d2382 100755 --- a/scripts/ci +++ b/scripts/ci @@ -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 diff --git a/scripts/docker-run.sh b/scripts/docker-run.sh index c3bf3b8d..4993ab9b 100755 --- a/scripts/docker-run.sh +++ b/scripts/docker-run.sh @@ -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 "$@" diff --git a/scripts/run b/scripts/run index 62387d4a..1cb3f10e 100755 --- a/scripts/run +++ b/scripts/run @@ -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 diff --git a/scripts/ssh b/scripts/ssh index 30dc486c..6455ca72 100755 --- a/scripts/ssh +++ b/scripts/ssh @@ -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 diff --git a/tests/container/README.txt b/tests/container/README.txt deleted file mode 100644 index 76616d3c..00000000 --- a/tests/container/README.txt +++ /dev/null @@ -1 +0,0 @@ -RancherOS In-VM Integration Tests diff --git a/tests/container/rancheros/invmtest/test_sample.py b/tests/container/rancheros/invmtest/test_sample.py deleted file mode 100644 index 1030a2e3..00000000 --- a/tests/container/rancheros/invmtest/test_sample.py +++ /dev/null @@ -1,6 +0,0 @@ -def func(x): - return x + 1 - - -def test_answer(): - assert func(3) == 4 diff --git a/tests/container/requirements.txt b/tests/container/requirements.txt deleted file mode 100644 index 8d2f15f3..00000000 --- a/tests/container/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -flake8==2.4.0 -pytest==2.7.0 -tox==1.9.2 diff --git a/tests/container/setup.py b/tests/container/setup.py deleted file mode 100644 index 2d44c6cc..00000000 --- a/tests/container/setup.py +++ /dev/null @@ -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(), -) diff --git a/tests/container/tox.ini b/tests/container/tox.ini deleted file mode 100644 index 7052d0fb..00000000 --- a/tests/container/tox.ini +++ /dev/null @@ -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 diff --git a/tests/integration/rancherostest/conftest.py b/tests/integration/rancherostest/conftest.py index 6f64c247..e81b2083 100644 --- a/tests/integration/rancherostest/conftest.py +++ b/tests/integration/rancherostest/conftest.py @@ -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') diff --git a/tests/integration/rancherostest/test_00_system.py b/tests/integration/rancherostest/test_00_system.py index 920d2bfe..32ab6dea 100644 --- a/tests/integration/rancherostest/test_00_system.py +++ b/tests/integration/rancherostest/test_00_system.py @@ -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 diff --git a/tests/integration/rancherostest/util.py b/tests/integration/rancherostest/util.py index de6b4994..f17f85ee 100644 --- a/tests/integration/rancherostest/util.py +++ b/tests/integration/rancherostest/util.py @@ -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/*') diff --git a/tests/integration/requirements.txt b/tests/integration/requirements.txt index 9f903942..59cebadf 100644 --- a/tests/integration/requirements.txt +++ b/tests/integration/requirements.txt @@ -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 diff --git a/tests/integration/tox.ini b/tests/integration/tox.ini index 20c60287..28f44931 100644 --- a/tests/integration/tox.ini +++ b/tests/integration/tox.ini @@ -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]