From 168d340b76f38539fef82d1d9661092458c32d42 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Wed, 9 Sep 2015 18:53:04 +0500 Subject: [PATCH] test custom kernel and docker build and boot --- scripts/ci | 2 +- scripts/docker-run.sh | 3 ++ tests/integration/assets/test_02/build.conf | 6 ++++ .../assets/test_02/test-custom-kernel.sh | 10 ++++++ .../rancherostest/test_00_system.py | 12 +------ .../rancherostest/test_02_custom_kernel.py | 35 +++++++++++++++++++ tests/integration/rancherostest/util.py | 10 ++++++ 7 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 tests/integration/assets/test_02/build.conf create mode 100755 tests/integration/assets/test_02/test-custom-kernel.sh create mode 100644 tests/integration/rancherostest/test_02_custom_kernel.py diff --git a/scripts/ci b/scripts/ci index 0a2d2382..037af254 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 integration-tests +./scripts/docker-run.sh --name ros-ci make -f Makefile.docker build-all integration-tests diff --git a/scripts/docker-run.sh b/scripts/docker-run.sh index db876631..37479f47 100755 --- a/scripts/docker-run.sh +++ b/scripts/docker-run.sh @@ -24,6 +24,9 @@ while [ "$#" -gt 0 ]; do rm $NAME DOCKER_ARGS="${DOCKER_ARGS} --rm" ;; + -t) + DOCKER_ARGS="${DOCKER_ARGS} -t" + ;; *) break ;; diff --git a/tests/integration/assets/test_02/build.conf b/tests/integration/assets/test_02/build.conf new file mode 100644 index 00000000..b8567aa6 --- /dev/null +++ b/tests/integration/assets/test_02/build.conf @@ -0,0 +1,6 @@ +IMAGE_NAME=rancher/os +VERSION=v0.4.0-test + +DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.8.2-rc1-ros/docker-1.8.2-rc1 +KERNEL_URL=https://github.com/imikushin/os-kernel/releases/download/4.2/linux-4.2.0-rancher-x86.tar.gz +DFS_IMAGE=rancher/docker:1.8.1 diff --git a/tests/integration/assets/test_02/test-custom-kernel.sh b/tests/integration/assets/test_02/test-custom-kernel.sh new file mode 100755 index 00000000..857ad992 --- /dev/null +++ b/tests/integration/assets/test_02/test-custom-kernel.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -ex + +cd $(dirname $0)/../../../.. + +cp ./tests/integration/assets/test_02/build.conf ./ + +make -f Makefile.docker minimal + +exec ./scripts/run diff --git a/tests/integration/rancherostest/test_00_system.py b/tests/integration/rancherostest/test_00_system.py index 9c5cdb70..c4f0c5ff 100644 --- a/tests/integration/rancherostest/test_00_system.py +++ b/tests/integration/rancherostest/test_00_system.py @@ -10,19 +10,9 @@ def qemu(request): return u.run_qemu(request) -def rancheros_version(): - with open('./build.conf') as f: - for v in it.ifilter(u.non_empty, - it.imap(u.parse_value('VERSION'), - it.ifilter(u.non_empty, - it.imap(u.strip_comment('#'), u.iter_lines(f))))): - return v - raise RuntimeError("Could not parse RancherOS version") - - @pytest.mark.timeout(30) def test_system_boot(qemu): - version = rancheros_version() + version = u.rancheros_version('./build.conf') print('parsed version: ' + version) def has_ros_started_substr(s): diff --git a/tests/integration/rancherostest/test_02_custom_kernel.py b/tests/integration/rancherostest/test_02_custom_kernel.py new file mode 100644 index 00000000..817064f0 --- /dev/null +++ b/tests/integration/rancherostest/test_02_custom_kernel.py @@ -0,0 +1,35 @@ +from __future__ import print_function +import itertools as it +import pytest +import subprocess +import rancherostest.util as u + + +@pytest.fixture(scope="module") +def build_and_run(request): + print('\nBuilding and running RancherOS with custom kernel') + p = subprocess.Popen(['./scripts/docker-run.sh', '--rm', + './tests/integration/assets/test_02/test-custom-kernel.sh'], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) + + def fin(): + print('\nTerminating docker-run test-custom-kernel') + p.terminate() + + request.addfinalizer(fin) + return p + + +@pytest.mark.timeout(30) +def test_system_boot(build_and_run): + version = u.rancheros_version('./tests/integration/assets/test_02/build.conf') + print('parsed version: ' + version) + + def has_ros_started_substr(s): + return str.find(s, 'RancherOS {v} started'.format(v=version)) > -1 + + for _ in it.ifilter(has_ros_started_substr, + it.imap(u.with_effect(print), u.iter_lines(build_and_run.stdout))): + assert True + return + assert False diff --git a/tests/integration/rancherostest/util.py b/tests/integration/rancherostest/util.py index 0f4e02b0..394bb359 100644 --- a/tests/integration/rancherostest/util.py +++ b/tests/integration/rancherostest/util.py @@ -33,6 +33,16 @@ def with_effect(p): return effect +def rancheros_version(build_conf): + with open(build_conf) as f: + for v in it.ifilter(non_empty, + it.imap(parse_value('VERSION'), + it.ifilter(non_empty, + it.imap(strip_comment('#'), iter_lines(f))))): + return v + raise RuntimeError("Could not parse RancherOS version") + + def run_qemu(request, run_args=[]): subprocess.check_call('rm -f ./state/empty-hd.img', shell=True) print('\nrm ./state/*')