Create a gist now

Instantly share code, notes, and snippets.

@smoser /README.md
Last active May 24, 2017

What would you like to do?
Centos cloud-init tools

centos tools for cloud-init

What is here right now is just centos-setup.

The goal is to put stuff here to help work with centos on cloud-init.

General info

centos-setup should be run on CentOS 6 or CentOS 7. Its intent is simply to install packages necessary for testing or building cloud-init.

It takes an argument of one or more sets of packages to install. The test targets utilize packages installed via pip as rpm/yum may not have packages available for test dependencies.

The package sets are:

  • test-distro: Install dependencies need to run nosetests and use the OS provided system packages (an environment like a distro-installed cloud-init would likely run in).

  • test-tox: install all necessary dependencies to run tox. This will test cloud-init using the system python executable but python packages at levels specified in tox.ini.

  • build: install rpm dependencies needed for ./packages/bdrpm

  • run: install rpm dependencies needed for cloud-init runtime.

Test

To run tests, assuming you are in a CentOS environment and have centos-setup.

./centos-setup test-distro  # or test-tox
git clone git://git.launchpad.net/cloud-init
cd cloud-init
nosetests tests/unittests

Note you could also use test-tox above and then run tox.

RPM Build

./centos-setup build
git clone git://git.launchpad.net/cloud-init
cd cloud-init
./packages/brpm

Usage via LXD

LXD is not necessary at all, but if you have a 16.04 host and want to easily be able to develop/test cloud-init in CentOS it is useful.

lxd setup

from a fresh 16.04+ instance, setting up lxd is fairly easy enough. mostly just consists of:

$ apt-get update -qy && apt-get --assume-yes -q install lxc2
$ lxd init
<answer some questions... mostly hit enter many times>

Getting centos environment for cloud-init

Then create a centos container, push centos-setup inside and use it as described above.

name=cent6
src=images:centos/6/amd64   # or images:centos/7/amd64

lxc launch $src $name
lxc push centos-setup "$name/root/centos-setup"
lxc exec "$name" /bin/bash

% ./centos-setup test-distro
% git clone ...
#!/bin/sh
set -f
pips_test_tox="
setuptools
tox
virtualenv
"
# for running test against distro packages. Only have what
# we need for the tests themselves.
pips_test_distro="
contextlib2
httpretty
mock
nose
pep8
unittest2
"
# for all things
packages_base="
git
python-pip
file
"
packages_distro="
pyserial
python-argparse
python-cheetah
python-configobj
python-jinja2
python-jsonpatch
python-oauthlib
python-prettytable
python-requests
python-six
PyYAML
"
packages_build="
python-devel
rpm-build
tar
$packages_distro
"
error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
if [ $# -eq 0 ]; then
error "Must give target: test-distro test-tox build run"
exit 1
fi
packages="${packages_base}"
pips=""
for target in "$@"; do
case "$target" in
test-distro)
pips="${pips} ${pips_test_distro}"
packages="${packages} ${packages_distro}";;
test-tox)
pips="${pips} ${pips_test_tox}";;
build)
packages="${packages} ${packages_build}";;
run)
packages="${packages} ${packages_distro}";;
esac
done
pips=$(for p in $pips; do echo $p; done | sort -u)
packages=$(for p in $packages; do echo $p; done | sort -u)
error "target=$*"
error "packages:" $packages
error "pips: " $pips
if [ -n "$packages" ]; then
if ! out=$(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
fi
if [ -n "$pips" ]; then
pip install --upgrade $pips ||
fail "failed: pip install" $pips
fi

with centos7, I need to also install 'rpm-build' and 'python-devel'

Owner

smoser commented May 24, 2017

hm.. 'packages-build' should install python-devel, rpm-build, and tar. so you can then run ./packages/bdrpm . I've tested that here just now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment