← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~powersj/cloud-init:create-centos-tests into cloud-init:master

 

i use 'newscript' to create scripts once they start needing options.
make sure you use it with '--spaces'

http://smoser.brickies.net/git/?p=tildabin.git;a=blob;f=newscript;h=494d31a8f8fa0c83d7c8b03d3d63deb641709b99;hb=HEAD

Diff comments:

> diff --git a/tools/test-centos-run.sh b/tools/test-centos-run.sh
> new file mode 100755
> index 0000000..13cde62
> --- /dev/null
> +++ b/tools/test-centos-run.sh
> @@ -0,0 +1,47 @@
> +#!/bin/bash

i generally hate 'set -e'. i'd much prefer sane error messages when something fails.

> +# This file is part of cloud-init. See LICENSE file for license information.
> +set -ux
> +
> +version=${1:-7}    
> +name="cloud-init-centos-$version"

probably should take a 'name' (you can default to one if you want).
without taking a name (or letting lxc pick one and reading it back) it means a given system can only run one of these things at a time.

> +src="images:centos/$version"
> +tarball='cloud-init.tar.gz'
> +user='centos'
> +
> +error() { echo "$@" 1>&2; }
> +fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
> +info() { echo "$@"; }
> +
> +# Create tarball of current directory, with git info
> +cd "$(git rev-parse --show-toplevel)" ||

the 'git rev-parse' can fail, and then the 'cd' pass as it got nothing on stdout.

top_d=$(git rev-parse --show-toplevel) || fail "failed to get top level"
cd "$top_d" || fail "failed to cd to git top dir"

> +    fail "failed: changing to top level directory"
> +tar_folder=${PWD##*/}
> +cd ..
> +tar -czvf "$tarball" "$tar_folder" || 
> +    fail "failed: creating tarball"
> +cd "$tar_folder/tools" ||
> +    fail "failed: changing directory"
> +
> +lxc stop "$name" && lxc delete "$name"
> +lxc launch "$src" "$name"
> +
> +# need to wait for networking
> +sleep 10
> +
> +lxc exec "$name" -- useradd "$user"
> +lxc exec "$name" -- /bin/sh <test-centos-setup.sh ||
> +    fail "failed: setting up container"
> +lxc file push "../../$tarball" "$name"/home/"$user"/
> +lxc exec "$name" -- chown "$user:$user" $tarball
> +lxc exec "$name" -- su "$user" -c "cd /home/$user; tar xvfz /home/$user/$tarball" ||
> +    fail "failed: extracting tarball"
> +
> +lxc exec "$name" -- su "$user" -c "cd /home/$user/$tar_folder; nosetests tests/unittests"
> +exit_1=$?
> +lxc exec "$name" -- su "$user" -c "cd /home/$user/$tar_folder; ./packages/brpm -v"
> +exit_2=0
> +
> +lxc stop "$name"
> +lxc delete "$name"
> +
> +! (( exit_1 || exit_2 ))
> diff --git a/tools/test-centos-setup.sh b/tools/test-centos-setup.sh
> new file mode 100755
> index 0000000..d8d16e7
> --- /dev/null
> +++ b/tools/test-centos-setup.sh
> @@ -0,0 +1,51 @@
> +#!/bin/sh
> +# This file is part of cloud-init. See LICENSE file for license information.
> +set -fux
> +export LANG=C
> +

the only thing i dont really like here is that we've duplicated these dependencies and another placeto update them.

> +packages="
> +    git
> +    tar
> +    python-pip
> +    file
> +    e2fsprogs
> +    pyserial
> +    python-argparse
> +    python-cheetah
> +    python-configobj
> +    python-devel
> +    python-jinja2
> +    python-jsonpatch
> +    python-oauthlib
> +    python-prettytable
> +    python-requests
> +    python-six
> +    PyYAML
> +    rpm-build
> +"
> +
> +pips="
> +    contextlib2
> +    httpretty
> +    mock
> +    nose
> +    pep8
> +    unittest2
> +"
> +
> +error() { echo "$@" 1>&2; }
> +fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
> +info() { echo "$@"; }
> +
> +pips=$(for p in $pips; do echo "$p"; done | sort -u)
> +packages=$(for p in $packages; do echo "$p"; done | sort -u)
> +
> +if ! rpm -q epel-release >/dev/null; then
> +    yum install --assumeyes epel-release ||
> +        fail "failed: yum install epel-release"
> +fi
> +yum install --assumeyes $packages ||
> +        fail "failed: yum install" "$packages"
> +
> +pip install --upgrade $pips ||
> +    fail "failed: pip install $pips"


-- 
https://code.launchpad.net/~powersj/cloud-init/+git/cloud-init/+merge/324982
Your team cloud-init commiters is requested to review the proposed merge of ~powersj/cloud-init:create-centos-tests into cloud-init:master.


References