diff -Nru charm-tools-0.3+92/debian/changelog charm-tools-0.3+121/debian/changelog --- charm-tools-0.3+92/debian/changelog 2011-12-13 20:55:42.000000000 +0000 +++ charm-tools-0.3+121/debian/changelog 2012-01-19 20:53:04.000000000 +0000 @@ -1,3 +1,10 @@ +charm-tools (0.3+121-0ubuntu1) precise; urgency=low + + * New upstream release. + * Build-Depend on pwgen, openssh, and rsync for tests. + + -- Clint Byrum Thu, 19 Jan 2012 12:52:59 -0800 + charm-tools (0.3+92-0ubuntu1) precise; urgency=low * New upstream release. diff -Nru charm-tools-0.3+92/debian/control charm-tools-0.3+121/debian/control --- charm-tools-0.3+92/debian/control 2011-12-13 20:55:07.000000000 +0000 +++ charm-tools-0.3+121/debian/control 2012-01-16 08:23:22.000000000 +0000 @@ -2,7 +2,7 @@ Section: net Priority: optional Maintainer: Clint Byrum -Build-Depends: debhelper (>= 7.0.50~), wget, python +Build-Depends: debhelper (>= 7.0.50~), wget, python, pwgen, openssh-server, openssh-client, rsync Standards-Version: 3.9.2 Homepage: https://launchpad.net/charm-tools diff -Nru charm-tools-0.3+92/helpers/sh/apparmor.sh charm-tools-0.3+121/helpers/sh/apparmor.sh --- charm-tools-0.3+92/helpers/sh/apparmor.sh 1970-01-01 00:00:00.000000000 +0000 +++ charm-tools-0.3+121/helpers/sh/apparmor.sh 2012-01-19 20:32:05.000000000 +0000 @@ -0,0 +1,30 @@ +#!/bin/sh + +## +# Copyright 2011 Canonical, Ltd. All Rights Reserved +# +# This file is part of Charm Helpers. +# +# Charm Helpers is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Charm Helpers is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Charm Helpers. If not, see . +## + +ch_apparmor_load() { + local ddir=${CH_APPARMOR_DESTDIR:-""} + [ -n "$CHARM_DIR" ] || return 1 + [ -d "$CHARM_DIR" ] || return 1 + [ -d "$CHARM_DIR/apparmor/profiles.d" ] || return 0 + cp -f $CHARM_DIR/apparmor/profiles.d/* $ddir/etc/apparmor.d || return 1 + service apparmor reload || return 0 + return 0 +} diff -Nru charm-tools-0.3+92/helpers/sh/net.sh charm-tools-0.3+121/helpers/sh/net.sh --- charm-tools-0.3+92/helpers/sh/net.sh 2011-12-13 20:50:05.000000000 +0000 +++ charm-tools-0.3+121/helpers/sh/net.sh 2012-01-19 20:32:05.000000000 +0000 @@ -22,7 +22,7 @@ ## # Globally overridable settings. Make sure to set them before sourcing # this file. -CH_WGET_ARGS=${CH_WGET_ARGS:-"-q"} +CH_WGET_ARGS=${CH_WGET_ARGS:-"-q --content-disposition"} ## # Get File @@ -37,7 +37,7 @@ { local FILE=${1:-""} local HASH=${2:-""} - local DOWNLOAD_DIR=${CH_DOWNLOAD_DIR:-"`mktemp -d /tmp/ch-downloads.XXXXXX`"} + local CH_DOWNLOAD_DIR=${CH_DOWNLOAD_DIR:-"`mktemp -d /tmp/ch-downloads.XXXXXX`"} if [ `ch_is_url "$FILE"` ]; then wget $CH_WGET_ARGS --directory-prefix="$CH_DOWNLOAD_DIR/" "$FILE" @@ -181,3 +181,4 @@ echo $CHECK_IP return 0 } + diff -Nru charm-tools-0.3+92/helpers/sh/peer.sh charm-tools-0.3+121/helpers/sh/peer.sh --- charm-tools-0.3+92/helpers/sh/peer.sh 1970-01-01 00:00:00.000000000 +0000 +++ charm-tools-0.3+121/helpers/sh/peer.sh 2012-01-19 20:32:05.000000000 +0000 @@ -0,0 +1,562 @@ +#!/bin/sh + +#Copyright: Copyright 2011, Canonical Ltd., All Rights Reserved. +#License: GPL-3 +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# . +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# . +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +echo WARNING: peer functions are untested, and may provide unreliable +echo services. Their use is experimental. + +## +# ch_peer_i_am_leader +# Returns 1 if the current unit is the leader +# +# no params +# +# return 0|1 +ch_peer_i_am_leader() +{ + local REMOTE_UNIT_ID=`ch_unit_id $JUJU_REMOTE_UNIT` + local LOCAL_UNIT_ID=`ch_my_unit_id` + local FIRST_UNIT_ID=`relation-list | cut -d/ -f2 | sort -n | head -n 1` + if [ -z $FIRST_UNIT_ID ] ; then + #no one else in the list, we are obviously the leader + return 0 + fi + if [ $REMOTE_UNIT_ID -lt $FIRST_UNIT_ID ] ; then + #remote must be departing, lets not worry about it + if [ $LOCAL_UNIT_ID -lt $FIRST_UNIT_ID ]; then + return 0 + else + return 1 + fi + else + if [ $LOCAL_UNIT_ID -lt $REMOTE_UNIT_ID ] && [ $LOCAL_UNIT_ID -lt $FIRST_UNIT_ID ]; then + return 0 + else + return 1 + fi + fi +} + +## +# ch_peer_leader [--id] +# +# Return the name [or id] of the leader unit +# +# Option --id will have the function return the unit id instead +# +# Returns leader-unit-name[or ID] +ch_peer_leader() +{ + if ch_peer_i_am_leader; then + # this is the leader, return our own unit name + local leader_id=`ch_unit_id $JUJU_UNIT_NAME` + local leader_name=$JUJU_UNIT_NAME + else + # this is a slave the leader is the head of the list + local leader_id=`relation-list | cut -d/ -f2 | sort -n | head -n 1` + local leader_name=`relation-list | grep "/$leader_id$"` + fi + if [ $# -gt 0 ] && [ "$1" = "--id" ]; then + echo $leader_id + else + echo $leader_name + fi +} + +## +# ch_unit_id +# Returns the unit id +# +# Param is the name of the unit +# +# returns | FALSE +ch_unit_id() +{ + echo "${1##*/}" +} + +## +# ch_my_unit_id +# Returns the unit id of the current unit +# +# param none +# +# returns | FALSE +ch_my_unit_id() +{ + echo "`ch_unit_id $JUJU_UNIT_NAME`" +} + + +## +# ch_peer_copy [-r|--rsync][-p ][-o ""] sourcepath1 destpath1 [... sourcepathN destpathN] +# ch_peer_scp [-r][-p ][-o ""] sourcepath1 destpath1 [... sourcepathN destpathN] +# ch_peer_rsync [-p ] sourcepath1 destpath1 [... sourcepathN destpathN] +# +# distribute a list of file to all slave of the peer relation +# +# param +# -r recursive scp copy (scp only, always on with rsync) +# -p destination port to connect to +# -o "" any pathttrough options to the copy util +# --rsync use rsync instead of scp +# sourcepath path from which to copy (do not specify host, it will always +# be coming from the leader of the peer relation) +# destpath path to which to copy (do not specify host, it will always +# be the slaves of the peer relation) +# +# returns +# 0 when the file is copied +# 1 when there was an error +# 100 when the file is not copied +# 101 files were sent from the leader +# +# This executes in multiple passes between the leader and each peer +# +# LEADER SLAVE +# <------------------- set scp-hostname +# set scp-ssh-key -----------------> +# save shh-keys +# <------------------- set scp-ssh-key-saved +# do file copy +# set scp-copy-done ---------------> +# +# This function is idempotent and should be called for each JOINED or +# CHANGED event for slave or leader in the peer relation exactly the same way + +alias ch_peer_scp=ch_peer_copy +alias ch_peer_rsync='ch_peer_copy --rsync' +ch_peer_copy() { + local USAGE="ERROR in $* +USAGE: ch_peer_scp [-r][-p ][-o \"\"] sourcepath1 destpath1 [... sourcepathN destpathN] +USAGE: ch_peer_rsync [-p ][-o \"\"] sourcepath1 destpath1 [... sourcepathN destpathN]" + # $USER may not be set + USER=${USER:-`whoami`} + # $HOME may not be set + if [ -z "${HOME:-}" ] ; then + if [ "$USER" = "root" ] ; then + HOME="/$USER" + else + HOME="/home/$USER" + fi + fi + if ! echo "$HOME" | grep -q "$USER" ; then + if [ "$USER" = "root" ] ; then + HOME="/$USER" + else + HOME="/home/$USER" + fi + fi + local ssh_key_p="$HOME/.ssh" + local result=100 + + if [ $# -eq 0 ]; then + juju-log -l ERROR "$USAGE" + juju-log -l ERROR "ch_peer_copy: please provide at least one argument (path)" + return 1 + fi + + local scp_options="-o StrictHostKeyChecking=no -B" + local rsync_options="" + local paths="" + local copy_command="scp" + + while [ "$#" -gt 0 ]; + do + case "$1" in + "-r") # scp recure + scp_options="$scp_options -r" + shift + ;; + "-p") # port number + shift + scp_options="$scp_options -P $1" + rsync_options="$rsync_options -e 'ssh -p $1 -o StrictHostKeyChecking=no'" + shift + ;; + "-o") # passthrough option + shift + scp_options="$scp_options $1" + rsync_options="$rsync_options $1" + + shift + ;; + "--rsync") # rsync secure (-e ssh) + copy_command="rsync" + shift + ;; + "$0") + shift + ;; + *) # should be a pair of file + local sourcep="$1" + shift + paths="$paths $sourcep $USER@X0X0X0X0:$1" + juju-log -l DEBUG "ch_peer_copy: paths found: $sourcep -> $1" + shift + ;; + esac + done + if [ -z "$paths" ]; then + juju-log -l ERROR "$USAGE" + juju-log -l ERROR "ch_peer_copy: please provide at least one path" + exit 1 + fi + if [ x"$copy_command" = x"rsync" ]; then + scp_options=$rsync_options + fi + + local list="" + list=`relation-list` + # if we are not in a relation, do ch_peer_copy_new + if [ -z "${list:-}" ] ; then + _ch_peer_copy_new "$copy_command $scp_options" "$paths" + result=$? + juju-log -l DEBUG "ch_peer_copy: returning $result" + return $result + fi + + ## LEADER ## + + if ch_peer_i_am_leader ; then + juju-log -l INFO "ch_peer_copy: This is our leader" + + local remote=`relation-get scp-hostname` + local ssh_key_saved=`relation-get scp-ssh-key-saved` + if [ -z $remote ] || [ "$remote" = "0" ] ; then + juju-log -l DEBUG "ch_peer_copy: We do not have a remote hostname yet" + relation-set scp-copy-done=0 + remote=0 + fi + + if [ -n $remote ]; then + # We know where to send file to + + case $ssh_key_saved in + 1) # ssh keys have been saved, let's copy + paths=`echo "$paths" | sed "s/X0X0X0X0/$remote/g"` + local p1="" + #we do not want globbing in the loop as it would mess with the number of passes and we work on pairs + local globstate=`set -o | grep "noglob" | grep -q off && echo "+f" || echo "-f"` + set -f + for path in $paths ; do + if [ "$p1" != "" ] ; then + juju-log -l INFO "ch_peer_copy: $copy_command $scp_options $p1 $path" + #globbing is wanted here to handle + set +f + eval "$copy_command $scp_options $p1 $path" + set -f + p1="" + else + p1=$path + fi + done + set $globstate + relation-set scp-copy-done=1 + #save host and paths for later use + _ch_peer_copy_save "$copy_command" "$scp_options" "$remote" "$paths" "$JUJU_REMOTE_UNIT" + juju-log -l DEBUG "ch_peer_copy: save done" + result=101 + ;; + + *) # we need to first distribute our ssh key files + juju-log -l DEBUG "ch_peer_copy: distributing ssh key" + if [ ! -f "$ssh_key_p/id_rsa" ]; then + ssh-keygen -q -N '' -t rsa -b 2048 -f $ssh_key_p/id_rsa + fi + relation-set scp-ssh-key="`cat $ssh_key_p/id_rsa.pub`" + ;; + + esac + fi + + ## REMOTE ## + + else # Not the leader + juju-log -l INFO "ch_peer_copy: This is a slave" + + local scp_copy_done=`relation-get scp-copy-done` + local scp_ssh_key="`relation-get scp-ssh-key`" + relation-set scp-hostname=`unit-get private-address` + + if [ -n "$scp_copy_done" ] && [ $scp_copy_done = 1 ]; then + juju-log -l DEBUG "ch_peer_copy: copy done, thanks" + result=0 + else + if [ -n "$scp_ssh_key" ]; then + juju-log "ssh key dir: $ssh_key_p" + mkdir -p $ssh_key_p + chmod 700 $ssh_key_p + if ! grep -q -F "$scp_ssh_key" $ssh_key_p/authorized_keys ; then + if [ "$USER" = "root" ] ; then + # if we are root, need to ensure we can login + if ! grep -q "^PermitRootLogin yes" /etc/ssh/sshd_config ; then + juju-log -l ERROR "PermitRootLogin is not set to yes and you are root. Please use another user or call 'ch_sshd_set_root_login 1' first" + return 1 + fi + fi + juju-log -l DEBUG "ch_peer_copy: saving ssh key $scp_ssh_key" + echo "$scp_ssh_key" >> $ssh_key_p/authorized_keys + relation-set scp-ssh-key-saved=1 + else + juju-log -l DEBUG "ch_peer_copy: ssh keys already saved, thanks" + relation-set scp-ssh-key-saved=1 + fi + chmod 600 "$ssh_key_p/authorized_keys" + else + juju-log -l DEBUG "ch_peer_copy: ssh_keys not set yet, later" + relation-set scp-ssh-key-saved=0 #we can't count on this being initialized correctly + fi + fi + fi + + juju-log "ch_peer_copy: returning: $result" + return $result +} + +## +# ch_sshd_set_root_login [0|1] +# +# modify /etc/ssh/sshd_config to set PermitRootLogin and reload ssh server +# +# param +# 0 disable +# 1 enable (default) +# +# returns nothing + +ch_sshd_set_root_login() { + local on=${1:-1} + if [ $on = 1 ] ; then + if ! grep -q "^PermitRootLogin yes" /etc/ssh/sshd_config ; then + sed -i 's/PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config + service ssh reload + fi + else + if ! grep -q "^PermitRootLogin no" /etc/ssh/sshd_config ; then + sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config + service ssh reload + fi + fi + return 0 +} + +_ch_peer_copy_set_paths() { + juju-log -l DEBUG "_ch_peer_copy_set_paths" + local unitname="" + unitname=`echo $JUJU_UNIT_NAME | sed 's/\//-/g'` + CH_PEER_COPY_P="/var/lib/juju/$unitname" + if [ ! `mkdir -p $CH_PEER_COPY_P 2>/dev/null` ] ; then + if [ ! -e $CH_PEER_COPY_P ]; then + CH_PEER_COPY_P="${HOME:-/root}/ch_test/$unitname" + mkdir -p $CH_PEER_COPY_P + fi + fi + CH_PEER_COPY_HOST_F="$CH_PEER_COPY_P/ch_peer_copy_hosts" + CH_PEER_COPY_PATHS_F="$CH_PEER_COPY_P/ch_peer_copy_paths" +} + +# Save copy commands and host for later replay +_ch_peer_copy_save() { + # $1 copy_command + # $2 options + # $3 remote host + # $4 paths + # $5 remote unit name + + juju-log -l DEBUG "_ch_peer_copy_save: $*" + + _ch_peer_copy_set_paths + + #save paths + local suffix=`echo "$1%$2" | base64 -w 0 ` + local paths=`echo "$4" | base64 -w 0` + local do_save=1 + + juju-log -l DEBUG "_ch_peer_copy_save: $* in ${CH_PEER_COPY_PATHS_F}-$suffix" + + if [ -e "${CH_PEER_COPY_PATHS_F}-$suffix" ]; then + if grep -q -F "$paths" "${CH_PEER_COPY_PATHS_F}-$suffix" ; then + do_save=0 + fi + fi + if [ $do_save = 1 ] ; then + juju-log -l DEBUG "_ch_peer_copy_save: saving $paths in ${CH_PEER_COPY_PATHS_F}-$suffix" + echo "$paths" >> ${CH_PEER_COPY_PATHS_F}-$suffix + juju-log -l DEBUG "_ch_peer_copy_save: paths: saved" + fi + do_save=1 + + + #save hosts + if [ -e "${CH_PEER_COPY_HOST_F}" ]; then + if grep -q -F "$3" "${CH_PEER_COPY_HOST_F}" ; then + do_save=0 + fi + fi + [ $do_save = 1 ] && echo "$5 $3" >> $CH_PEER_COPY_HOST_F + juju-log -l DEBUG "_ch_peer_copy_save: host: $5 $3" +} + +# do a new copy when not called within a relation +# returns +# 1 when there was an error +# 100 when the file is not copied +# 101 when the file is sent from server + +_ch_peer_copy_new() { + # $1 "$copy_command $scp_options" + # $2 "$paths" + + _ch_peer_copy_set_paths + local result=100 + local hosts="" + local paths="" + + if [ -e "$CH_PEER_COPY_HOST_F" ] ; then + hosts=`cat $CH_PEER_COPY_HOST_F | cut -d" " -f2` + + for h in $hosts ; + do + paths=`echo "$2" | sed "s/X0X0X0X0/$h/"` + local p1="" + #we do not want globbing in the loop as it would mess with the number of passes and we work on pairs + local globstate=`set -o | grep "noglob" | grep -q off && echo "+f" || echo "-f"` + set -f + for path in $paths ; do + if [ "$p1" != "" ] ; then + juju-log -l INFO "_ch_peer_copy_new: $1 $p1 $path" + set +f + eval "$1 $p1 $path" + set -f + p1="" + else + p1=$path + fi + done + set $globstate + result=101 + done + else + juju-log -l DEBUG "ch_peer_copy_new: no host cache yet" + fi + juju-log -l DEBUG "_ch_peer_copy_new: returning $result" + return $result +} + +## +# ch_peer_copy_replay +# +# do a replay of all previous cached copies +# would typically be used within a config changed to resync +# files that might have been modified to all peers in the relation +# +# param none +# +# returns +# 0 when the file is copied +# 1 when there was an error +# 100 when the file is not copied + +ch_peer_copy_replay() { + _ch_peer_copy_set_paths + local result=100 + local hosts="" + local copies="" + local h="" + local c="" + local commandopt="" + local list_paths="" + local encp="" + local mpath="" + + if [ ! -e "$CH_PEER_COPY_HOST_F" ] ; then + juju-log -l DEBUG "ch_peer_copy_replay: no host cache yet" + result=1 + fi + + if [ $result = 100 ]; then + hosts=`cat $CH_PEER_COPY_HOST_F` + copies=`ls ${CH_PEER_COPY_PATHS_F}-* | xargs -n1 basename` + + if [ -z "$copies" ] ; then + juju-log -l DEBUG "ch_peer_copy_replay: no command cache yet" + result=1 + fi + fi + + if [ $result = 100 ]; then + for h in $hosts ; + do + + for c in $copies ; + do + commandopt=`echo $c | cut -d- -f2 | base64 -d | sed 's/%/ /'` + list_paths=`cat $CH_PEER_COPY_P/$c` + + for encp in $list_paths ; + do + mpath=`echo $encp | base64 -d` + local p1="" + #we do not want globbing in the loop as it would mess with the number of passes and we work on pairs + local globstate=`set -o | grep "noglob" | grep -q off && echo "+f" || echo "-f"` + set -f + for path in $mpath ; do + if [ "$p1" != "" ] ; then + juju-log -l INFO "ch_peer_copy_replay: $commandopt $p1 $path" + set +f + eval "$commandopt $p1 $path" + set -f + p1="" + else + p1=$path + fi + done + set $globstate + result=0 + done + + done + + done + fi + return $result +} + +## +# ch_peer_copy_cleanup +# +# Removes a parting remote unit fron the host cache +# Should be called for each peer-relation-departed +# +# param +# name of the remote unit +# +# returns nothing + +ch_peer_copy_cleanup() { + juju-log -l DEBUG "ch_peer_copy_cleanup: $1" + _ch_peer_copy_set_paths + if [ ! -e "$CH_PEER_COPY_HOST_F" ] ; then + juju-log -l DEBUG "ch_peer_copy_cleanup: no host cache yet" + return + fi + local unitname="" + unitname=`echo $1 | sed -e 's/\(\.\|\/\|\*\|\[\|\]\)/\\&/g'` + sed -i "/^$unitname.*$/d" $CH_PEER_COPY_HOST_F + return 0 +} + diff -Nru charm-tools-0.3+92/Makefile charm-tools-0.3+121/Makefile --- charm-tools-0.3+92/Makefile 2011-12-13 20:50:05.000000000 +0000 +++ charm-tools-0.3+121/Makefile 2012-01-19 20:32:05.000000000 +0000 @@ -9,7 +9,7 @@ all: -install: check +install: $(INSTALL) -d $(mandir) $(INSTALL) -t $(mandir) charm.1 $(INSTALL) -d $(datadir) @@ -22,6 +22,6 @@ cp -rf helpers/* $(helperdir) check: - tests/helpers/helpers.sh || sh -x tests/helpers/helpers.sh + tests/helpers/helpers.sh || sh -x tests/helpers/helpers.sh timeout @echo Test shell helpers with bash - bash tests/helpers/helpers.sh || bash -x tests/helpers/helpers.sh + bash tests/helpers/helpers.sh || bash -x tests/helpers/helpers.sh timeout diff -Nru charm-tools-0.3+92/scripts/get charm-tools-0.3+121/scripts/get --- charm-tools-0.3+92/scripts/get 2011-12-13 20:50:05.000000000 +0000 +++ charm-tools-0.3+121/scripts/get 2012-01-19 20:32:05.000000000 +0000 @@ -10,7 +10,7 @@ home=`dirname $0` -CHARM_BRANCH=`$home/search $1 | grep ^lp:charm/$1` +CHARM_BRANCH=`$home/search $1 | grep ^lp:charms/$1` if [ -z "$CHARM_BRANCH" ] ; then echo "$1 does not exist in official charm store." >&2 diff -Nru charm-tools-0.3+92/scripts/list charm-tools-0.3+121/scripts/list --- charm-tools-0.3+92/scripts/list 2011-12-13 20:50:05.000000000 +0000 +++ charm-tools-0.3+121/scripts/list 2012-01-19 20:32:05.000000000 +0000 @@ -1,5 +1,19 @@ -#!/bin/bash +#!/usr/bin/env python -CHARM_URL="https://code.launchpad.net/charm" +from launchpadlib.launchpad import Launchpad -curl -s "${CHARM_URL}" | grep 'lp:'| grep 'href=' | sed -e s#\\##g | awk -F'>' '{ print $2 }' | awk -F'<' '{ print $1 }' +lp = Launchpad.login_anonymously('charm-tools', 'production', version='devel') +charm = lp.distributions['charms'] +current_series = str(charm.current_series).split('/').pop() +branches = charm.getBranchTips() + +for branch in branches: + try: + branch_series = str(branch[2][0]).split('/')[0] + charm_name = str(branch[0]).split('/')[3] + except IndexError: + branch_series = '' + if branch_series == current_series: + print "lp:charms/%s" % charm_name + else: + print "lp:%s" % branch[0] diff -Nru charm-tools-0.3+92/scripts/promulgate charm-tools-0.3+121/scripts/promulgate --- charm-tools-0.3+92/scripts/promulgate 2011-12-13 20:50:05.000000000 +0000 +++ charm-tools-0.3+121/scripts/promulgate 2012-01-19 20:32:05.000000000 +0000 @@ -34,7 +34,7 @@ import logging -DISTRIBUTION = 'charm' +DISTRIBUTION = 'charms' REVIEW_TEAM_NAME = 'charmers' OFFICIAL_BRANCH_POCKET = 'Release' OFFICAL_BRANCH_STATUS = 'Mature' diff -Nru charm-tools-0.3+92/scripts/search charm-tools-0.3+121/scripts/search --- charm-tools-0.3+92/scripts/search 2011-12-13 20:50:05.000000000 +0000 +++ charm-tools-0.3+121/scripts/search 2012-01-19 20:32:05.000000000 +0000 @@ -2,6 +2,4 @@ [ -z "${1}" ] && echo "Search parameter required" && exit 1 -CHARM_URL="https://code.launchpad.net/charm" - -curl -s "${CHARM_URL}" | grep 'lp:'| grep 'href=' | sed -e s#\\##g | awk -F'>' '{ print $2 }' | awk -F'<' '{ print $1 }' | grep "${1}" +charm list | grep "${1}" diff -Nru charm-tools-0.3+92/scripts/update charm-tools-0.3+121/scripts/update --- charm-tools-0.3+92/scripts/update 2011-12-13 20:50:05.000000000 +0000 +++ charm-tools-0.3+121/scripts/update 2012-01-19 20:32:05.000000000 +0000 @@ -1,21 +1,40 @@ #!/bin/sh home=`dirname $0` charm_home=$1 +opt=$2 if [ -z "$charm_home" ] ; then - echo "usage: update charm_directory" >&2 + echo "usage: update charm_directory [ --fix ]" >&2 exit 1 fi -echo Pulling charm list from launchpad +echo Pulling charm list from launchpad >&2 newfile=`mktemp $charm_home/.mrconfig.XXXXXXXX` cp /dev/null $newfile -for s in `$home/list | awk -F\/ '/^lp:charm\// { print $2 }'` ; do +for s in `$home/list | awk -F\/ '/^lp:charms\// { print $2 }'` ; do cat >> $newfile </dev/null)` + [ -n "$location" ] || continue + if echo $location | grep -q '/charm/' ; then + new=`echo $location | sed -e 's,/charm/,/charms/,'` + if [ "$opt" = "--fix" ] ; then + echo UPDATING: $i, ${x}_location >&2 + (cd $i && bzr config ${x}_location=$new) || echo FAILED >&2 + else + echo WARNING: $i\'s ${x}_location must be redirected to lp:charms, or re-run update with --fix >&2 + echo cd $i '&&' bzr config ${x}_location=$new + fi + fi + done +done + +echo updating $charm_home/.mrconfig >&2 mv -f $newfile $charm_home/.mrconfig diff -Nru charm-tools-0.3+92/tests/helpers/disabled_test_peer.sh charm-tools-0.3+121/tests/helpers/disabled_test_peer.sh --- charm-tools-0.3+92/tests/helpers/disabled_test_peer.sh 1970-01-01 00:00:00.000000000 +0000 +++ charm-tools-0.3+121/tests/helpers/disabled_test_peer.sh 2012-01-19 20:32:05.000000000 +0000 @@ -0,0 +1,472 @@ +#!/bin/sh + +# debug=1 full +# debug=2 client only +debug=0 + +if [ -z "$test_home" ] ; then + test_home=`dirname $0` + test_home=`readlink -f $test_home` +fi + +[ "$LIB_SOURCED" = "1" ] || . $test_home/lib.sh + +set -ue + +JUJU_UNIT_NAME="EMPTY" + +#mock relation-list +alias relation-list=mock_relation_list +mock_relation_list() +{ + [ -z $CH_MASTER ] && let CH_MASTER=1 + + case $CH_MASTER in + 4) + echo "TEST/3 +TEST/2 +TEST/4" + ;; + 3) + echo "TEST/4 +TEST/3 +TEST/1" + ;; + 2) + echo "TEST/3 +TEST/4" + ;; + 1) + echo "TEST/2 +TEST/3 +TEST/4" + ;; + 0) + echo "TEST/1 +TEST/3 +TEST/4" + ;; + -1) + echo "" + ;; + esac + +} + +#Save juju-log for debugging +CH_TEMPLOG="/tmp/$USER-tmp-juju-log" +echo "" > $CH_TEMPLOG +output "creating test-log in $CH_TEMPLOG" +alias juju-log=mock_juju_log +mock_juju_log() +{ + echo "$*" >> $CH_TEMPLOG +} + +#mock unit-get +alias unit-get=mock_unit_get +mock_unit_get() +{ + case $1 in + "private-address") + echo "localhost" + ;; + *) + echo "UNDEFINED" + ;; + esac +} + +#mock relation-set/get +alias relation-set=mock_relation_set +alias relation-get=mock_relation_get +CH_scp_hostname="" +CH_scp_ssh_key_saved="" +CH_scp_ssh_key="" +CH_scp_copy_done="" +mock_relation_set() +{ + juju-log "mock_relation_set: $1" + CH_varname=`echo $1 | cut -d= -f1` + CH_value=`echo $1 | sed 's/^[^=]*=//'` + case $CH_varname in + "scp-hostname") + CH_scp_hostname=$CH_value + ;; + "scp-ssh-key-saved") + CH_scp_ssh_key_saved=$CH_value + ;; + "scp-ssh-key") + CH_scp_ssh_key="$CH_value" + ;; + "scp-copy-done") + CH_scp_copy_done=$CH_value + ;; + *) + juju-log "mock_relation_set: unknow var $CH_varname" + ;; + esac +} +mock_relation_get() +{ + case $1 in + "scp-hostname") + echo $CH_scp_hostname + juju-log "mock_relation_get: $1 = $CH_scp_hostname" + ;; + "scp-ssh-key-saved") + echo $CH_scp_ssh_key_saved + juju-log "mock_relation_get: $1 = $CH_scp_ssh_key_saved" + ;; + "scp-ssh-key") + echo "$CH_scp_ssh_key" + juju-log "mock_relation_get: $1 = $CH_scp_ssh_key" + ;; + "scp-copy-done") + echo $CH_scp_copy_done + juju-log "mock_relation_get: $1 = $CH_scp_copy_done" + ;; + *) + juju-log "mock_relation_get: unknow var $1" + ;; + esac +} + +CH_TEMPDIR="" + +created_ssh_home=0 + +cleanup_peer() +{ + [ $debug = 1 ] && output "====== sshd server log ======" && cat /tmp/juju-sshd-log ; rm -f /tmp/juju-sshd-log + [ $debug -gt 1 ] && output "===== juju debug log ======" && cat $CH_TEMPLOG + output "Cleaning up..." + unalias juju-log + unalias relation-set + unalias relation-get + unalias unit-get + unalias relation-list + [ -n "$CH_TEMPDIR" ] || return 0 + [ ! -f $CH_TEMPDIR/sshd.pid ] || kill -9 `cat $CH_TEMPDIR/sshd.pid` + rm -rf $CH_TEMPDIR + if [ $created_ssh_home = 1 ] ; then + backup_dir=`mktemp -d /tmp/backup-charm-helper.ssh.XXXXXXXX` + output "Backing up created $HOME/.ssh to $backup_dir/dot-ssh" + mv $HOME/.ssh $backup_dir/dot-ssh + fi + if [ -e $HOME/ch_test ] ; then + rm -rf $HOME/ch_test + fi +} +trap cleanup_peer EXIT +if [ $debug -gt 0 ] ; then echo "user: $USER, home: $HOME"; fi +if [ ! -d $HOME ] ; then + mkdir -p $HOME + chown $USER:$USER $HOME + chmod 700 $HOME +fi +if [ ! -d $HOME/.ssh ] ; then + mkdir -p $HOME/.ssh + chmod 700 $HOME/.ssh + created_ssh_home=1 +else + output "ch_peer_scp can be destructive to \$HOME/.ssh, move it out of the way or" + output "run these tests in a clean chroot or with a test user. Skipping." + exit 0 +fi +if [ x"$USER" = x"root" ] ; then + if ! touch /root/.ssh/known_hosts ; then + USER=`basename $HOME` + echo "forcing user to: $USER" + fi +fi +touch $HOME/.ssh/authorized_keys +touch $HOME/.ssh/known_hosts +chmod 600 $HOME/.ssh/authorized_keys + +# mock sshd server +CH_TEMPDIR=`mktemp -d "/tmp/juju-helpers-tmp.XXXXXXX"` +mkdir -p $CH_TEMPDIR/sourcedir/ +mkdir -p $CH_TEMPDIR/destdir/ +mkdir -p $CH_TEMPDIR/$HOME/ +if ! [ -d /var/run/sshd ] ; then + if ! mkdir -p /var/run/sshd ; then + mkdir -p $HOME/var/run/sshd/ + fi +fi +# Protect user's normal home dir +head -c 16384 /dev/urandom > $CH_TEMPDIR/sourcedir/testfile0 +head -c 32385 /dev/urandom > $CH_TEMPDIR/sourcedir/testfile1 +head -c 19998 /dev/urandom > $CH_TEMPDIR/sourcedir/testfile +CH_portnum=28822 +# lucid's ssh-keygen does not accept -h, so we check for maverick or +# later to add -h +ssh_version=`dpkg -l 'openssh-client'|awk '/^ii/ { print $3 }'` +if dpkg --compare-versions $ssh_version lt 1:5.5p1-4ubuntu4 ; then + opts="" +else + opts="-h" +fi +ssh-keygen -t rsa -b 1024 -N "" $opts -f $CH_TEMPDIR/my_host_key > /dev/null 2>&1 +if [ $debug = 1 ] ; then + /usr/sbin/sshd -e -o PidFile=$CH_TEMPDIR/sshd.pid -o UsePrivilegeSeparation=no -o StrictModes=no -d -h $CH_TEMPDIR/my_host_key -p $CH_portnum 2> /tmp/juju-sshd-log & + CH_scpopt="-v" + listening=1 +else + /usr/sbin/sshd -e -o PidFile=$CH_TEMPDIR/sshd.pid -o UsePrivilegeSeparation=no -o StrictModes=no -h $CH_TEMPDIR/my_host_key -p $CH_portnum + # wait for server + output "waiting for sshd to be available" + listening=0 + ch_tmp_result=`mktemp` + for i in 1 2 3 4 5 ; do + sleep 1 + + ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -p $CH_portnum bozo@localhost 2> $ch_tmp_result || + if grep -q -F "Permission denied" $ch_tmp_result ; then + output Attempt $i succeeded. + listening=1 + break + fi + output Attempt $i failed.. + done + rm -f $ch_tmp_result + if [ $listening = 0 ] ; then + exit 1 + fi + if [ $debug -gt 0 ]; then CH_scpopt="-v" ; else CH_scpopt="-q"; fi; +fi + +. $HELPERS_HOME/peer.sh + +start_test ch_unit_id... +JUJU_UNIT_NAME="TEST/1" +[ ! `ch_unit_id $JUJU_UNIT_NAME` -eq 1 ] && return 1 +CH_bad="badarg" +ch_unit_id $CH_bad > /dev/null || return 1 +echo PASS + +start_test ch_my_unit_id... +[ ! `ch_my_unit_id` -eq 1 ] && return 1 +echo PASS + +start_test ch_peer_i_am_leader... +JUJU_REMOTE_UNIT="TEST/3" +JUJU_UNIT_NAME="TEST/2" +CH_MASTER=1 +ch_peer_i_am_leader && return 1 || : +JUJU_UNIT_NAME="TEST/1" +ch_peer_i_am_leader || return 1 && : +echo PASS + +start_test "ch_peer_i_am_leader (unordered list 1)..." +JUJU_REMOTE_UNIT="TEST/3" +JUJU_UNIT_NAME="TEST/2" +CH_MASTER=3 +ch_peer_i_am_leader && return 1 || : +echo PASS + +start_test "ch_peer_i_am_leader (unordered list 2)..." +JUJU_UNIT_NAME="TEST/1" +CH_MASTER=4 +ch_peer_i_am_leader || return 1 && : +echo PASS + +start_test "ch_peer_i_am_leader (unordered list 3)..." +JUJU_UNIT_NAME="TEST/2" +CH_MASTER=3 +ch_peer_i_am_leader && return 1 || : +echo PASS + +start_test "ch_peer_i_am_leader (unordered list 4)..." +JUJU_UNIT_NAME="TEST/3" +ch_peer_i_am_leader && return 1 && : +echo PASS + +start_test "ch_peer_i_am_leader (empty list)..." +JUJU_REMOTE_UNIT="TEST/3" +JUJU_UNIT_NAME="TEST/1" +CH_MASTER=-1 +ch_peer_i_am_leader || return 1 && : +echo PASS + +start_test "ch_peer_i_am_leader (departed leader)..." +JUJU_REMOTE_UNIT="TEST/1" +JUJU_UNIT_NAME="TEST/4" +CH_MASTER=2 +ch_peer_i_am_leader && return 1 || : +JUJU_UNIT_NAME="TEST/2" +ch_peer_i_am_leader || return 1 && : +echo PASS + +start_test ch_peer_leader... +JUJU_REMOTE_UNIT="TEST/3" +JUJU_UNIT_NAME="TEST/1" +CH_MASTER=1 +[ "`ch_peer_leader`" = "TEST/1" ] || return 1 +[ `ch_peer_leader --id` -eq 1 ] || return 1 +JUJU_UNIT_NAME="TEST/2" +[ "`ch_peer_leader`" = "TEST/2" ] || return 1 +[ `ch_peer_leader --id` -eq 2 ] || return 1 +echo PASS + +start_test "ch_peer_scp -r..." +for i in 1 2 3 +do + #slave relation joined + JUJU_UNIT_NAME="TEST/2" + JUJU_REMOTE_UNIT="TEST/1" + CH_MASTER=0 + if ch_peer_scp -r -p $CH_portnum -o "$CH_scpopt" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" ; then break ; fi + #master relation joined + JUJU_UNIT_NAME="TEST/1" + JUJU_REMOTE_UNIT="TEST/2" + CH_MASTER=1 + if ch_peer_scp -r -p $CH_portnum -o "$CH_scpopt" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" ; then break ; fi +done +[ ! -e $CH_TEMPDIR/destdir/ ] && output "dir not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile0 ] && output "file1 not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile1 ] && output "file2 not copied" && exit 1 +CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile0 | cut -d" " -f1` +CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile0 | cut -d" " -f1` +[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1 +rm -rf $CH_TEMPDIR/destdir/* +echo PASS + +start_test "ch_peer_rsync..." +CH_scp_hostname="" +CH_scp_ssh_key_saved="" +CH_scp_ssh_key="" +CH_scp_copy_done="" +for i in 1 2 3 +do + #slave relation joined + JUJU_UNIT_NAME="TEST/2" + JUJU_REMOTE_UNIT="TEST/1" + CH_MASTER=0 + if ch_peer_rsync -p $CH_portnum -o "-azq" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" ; then break ; fi + #master relation joined + JUJU_UNIT_NAME="TEST/1" + JUJU_REMOTE_UNIT="TEST/2" + CH_MASTER=1 + if ch_peer_rsync -p $CH_portnum -o "-azq" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" ; then break ; fi +done +[ ! -e $CH_TEMPDIR/destdir/ ] && output"dir not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile0 ] && output "file1 not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile1 ] && output "file2 not copied" && exit 1 +CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile0 | cut -d" " -f1` +CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile0 | cut -d" " -f1` +[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1 +rm -rf $CH_TEMPDIR/destdir/* +echo PASS + +start_test "ch_peer_scp..." +CH_scp_hostname="" +CH_scp_ssh_key_saved="" +CH_scp_ssh_key="" +CH_scp_copy_done="" +for i in 1 2 3 +do + #slave relation joined + JUJU_UNIT_NAME="TEST/2" + JUJU_REMOTE_UNIT="TEST/1" + CH_MASTER=0 + if ch_peer_scp -p $CH_portnum -o "-q" "$CH_TEMPDIR/sourcedir/testfile" "$CH_TEMPDIR/destdir/" "$CH_TEMPDIR/sourcedir/testfile1" "$CH_TEMPDIR/destdir/" ; then break ; fi + #master relation joined + JUJU_UNIT_NAME="TEST/1" + JUJU_REMOTE_UNIT="TEST/2" + CH_MASTER=1 + if ch_peer_scp -p $CH_portnum -o "-q" "$CH_TEMPDIR/sourcedir/testfile" "$CH_TEMPDIR/destdir/" "$CH_TEMPDIR/sourcedir/testfile1" "$CH_TEMPDIR/destdir/" ; then break ; fi +done +[ ! -e $CH_TEMPDIR/destdir/testfile ] && output "file1 not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile1 ] && output "file2 not copied" && exit 1 +CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile | cut -d" " -f1` +CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile | cut -d" " -f1` +[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1 +rm -rf $CH_TEMPDIR/destdir/* +echo PASS + +start_test "ch_peer_copy_replay..." +CH_scp_hostname="" +CH_scp_ssh_key_saved="" +CH_scp_ssh_key="" +CH_scp_copy_done="" +#We are not in a relation, we are on master +JUJU_UNIT_NAME="TEST/1" +JUJU_REMOTE_UNIT="" +CH_MASTER=-1 +if ! ch_peer_copy_replay ; then + output "should not have returned not copied (1)" + exit 1 +fi +#We are not in a relation, we are on slave +JUJU_UNIT_NAME="TEST/2" +JUJU_REMOTE_UNIT="" +CH_MASTER=-1 +if ch_peer_copy_replay ; then + output "should not have returned copied (0)" + exit 1 +fi +[ ! -e $CH_TEMPDIR/destdir/testfile ] && output "file not copied" && exit 1 +CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile | cut -d" " -f1` +CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile | cut -d" " -f1` +[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/ ] && output "dir not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile0 ] && output "file1 not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile1 ] && output "file2 not copied" && exit 1 +CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile0 | cut -d" " -f1` +CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile0 | cut -d" " -f1` +[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1 +rm -rf $CH_TEMPDIR/destdir/* +echo PASS + +start_test "ch_peer_rsync (out of relation)..." +CH_scp_hostname="" +CH_scp_ssh_key_saved="" +CH_scp_ssh_key="" +CH_scp_copy_done="" +#We are not in a relation, we are on master +JUJU_UNIT_NAME="TEST/1" +JUJU_REMOTE_UNIT="" +CH_MASTER=-1 +ch_peer_rsync -p $CH_portnum -o "-azq" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" && chres=0 || chres=$? +if [ $chres -ne 101 ] ; then + output "should not have returned not copied (received $chres, 101 expected)" + exit 1 +fi +#We are not in a relation, we are on slave +JUJU_UNIT_NAME="TEST/2" +JUJU_REMOTE_UNIT="" +CH_MASTER=-1 +ch_peer_rsync -p $CH_portnum -o "-azq" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" && chres=0 || chres=$? +if [ $chres -ne 100 ] ; then + output "should not have returned copied (received $chres, 100 expected)" + exit 1 +fi +[ ! -e $CH_TEMPDIR/destdir/ ] && output "dir not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile0 ] && output "file1 not copied" && exit 1 +[ ! -e $CH_TEMPDIR/destdir/testfile1 ] && output "file2 not copied" && exit 1 +CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile0 | cut -d" " -f1` +CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile0 | cut -d" " -f1` +[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1 +rm -rf $CH_TEMPDIR/destdir/* +#restore authorized_keys & known_hosts +echo PASS + +start_test "ch_peer_copy_cleanup..." +# as a leader +JUJU_UNIT_NAME="TEST/1" +JUJU_REMOTE_UNIT="TEST/2" +CH_MASTER=-1 +ch_peer_copy_cleanup "$JUJU_REMOTE_UNIT" +unitname=`echo $JUJU_UNIT_NAME | sed 's/\//-/g'` +[ `grep -F "$JUJU_REMOTE_UNIT" $HOME/ch_test/$unitname` ] && output "not cleaned up" && exit 1 +# as a slave +JUJU_UNIT_NAME="TEST/2" +JUJU_REMOTE_UNIT="TEST/1" +CH_MASTER=-1 +ch_peer_copy_cleanup "$JUJU_REMOTE_UNIT" +#nothing to check here other than if we did not choke on cleaning up something that does not exist +echo PASS + +trap - EXIT +cleanup_peer diff -Nru charm-tools-0.3+92/tests/helpers/helpers.sh charm-tools-0.3+121/tests/helpers/helpers.sh --- charm-tools-0.3+92/tests/helpers/helpers.sh 2011-12-13 20:50:05.000000000 +0000 +++ charm-tools-0.3+121/tests/helpers/helpers.sh 2012-01-19 20:32:05.000000000 +0000 @@ -10,152 +10,9 @@ exec $test_home/run_with_timeout.py $0 timeout fi -HELPERS_SOURCE=${HELPERS_SOURCE:-"$test_home/../../helpers/sh/net.sh"} -MOCK_NET=${MOCK_NET:-"true"} +[ "${LIB_SOURCED:-''}" = "1" ] || . $test_home/lib.sh -mock_host () { - if echo $* | grep -q "[_#]" ; then return 1 ; fi - echo nothost.local has address 127.0.0.1 - echo nothost.local has address 127.0.1.1 -} - -mock_dig () { - if echo $* | grep -q "[_#]" ; then return 1 ; fi - echo 127.0.0.1 - echo 127.0.1.1 -} - -output () { - echo `date`: $* -} - -start_output () { - echo -n `date`: $* -} - -start_test () { - echo -n `date`: Testing $* -} - -if [ "$MOCK_NET" = "true" ] ; then - alias host=mock_host - alias dig=mock_dig -fi - -# Uncomment this to get more info on why wget failed -#CH_WGET_ARGS="--verbose" - -. $HELPERS_SOURCE - -start_test ch_type_hash... -# Test return codes -ch_type_hash "not a hash" > /dev/null && return 1 || : -ch_type_hash '062b92a381b6ee8f87917f8dc19ff1bb' > /dev/null -ch_type_hash '188c481c99311aba88ffeadde1d59fcca3d64d10' > /dev/null -ch_type_hash '07a9a2188113d45f23e4abe3e8b540931d1f3892634399688bab4bde08132b4b' > /dev/null -# Test types -[ "`ch_type_hash '062b92a381b6ee8f87917f8dc19ff1bb'`" = "md5" ] -[ "`ch_type_hash '188c481c99311aba88ffeadde1d59fcca3d64d10'`" = "sha1" ] -[ "`ch_type_hash '07a9a2188113d45f23e4abe3e8b540931d1f3892634399688bab4bde08132b4b'`" = "sha256" ] -echo PASS - -start_test ch_is_url... -ch_is_url "not a url" && return 1 || : -ch_is_url "http://www.w3c.org/" > /dev/null -ch_is_url "ftp://ftp.kernel.org/" > /dev/null -ch_is_url "https://launchpad.net" > /dev/null -[ "`ch_is_url 'https://launchpad.net'`" = "true" ] -echo PASS - -start_test Testing ch_is_ip... -ch_is_ip 'just.a.hostname.com' && return 1 || : -ch_is_ip '256.2.3.4' && return 1 || : -ch_is_ip '1.2.3.4' > /dev/null -ch_is_ip '192.168.3.4' > /dev/null -ch_is_ip '3.1.1.1' > /dev/null -[ "`ch_is_ip '192.168.3.4'`" = "true" ] -echo PASS - -start_test Testing ch_get_ip... -testhostname=launchpad.net -myip=`host -t A $testhostname|head -n 1|cut -d' ' -f4` -ch_get_ip _invalid#hostname > /dev/null && return 1 || : -ch_get_ip $testhostname > /dev/null -[ "`ch_get_ip $testhostname`" = "$myip" ] -echo PASS - -save_pwd=$PWD -temp_srv_dir="" -temp_dl_dir="" -temp_dirs="" -cleanup_temp () { - if [ -n "$temp_dirs" ] ; then - # Trying to be safe, only one level of files should be there - if [ -f "$temp_srv_dir/webserver.pid" ] ; then - webserver_pid=`cat $temp_srv_dir/webserver.pid` - if [ -n "$webserver_pid" ] ; then - start_output Shutting down webserver... - kill $webserver_pid || echo -n webserver already dead?... - wait - echo DONE - fi - fi - if [ -n "$temp_srv_dir" ] && [ -s $temp_srv_dir/server.log ] ; then - output Printing server log - cat $temp_srv_dir/server.log - fi - local dir="" - for dir in $temp_dirs ; do - rm -f $dir/* - rmdir $dir - done - fi - cd $save_pwd -} - -trap cleanup_temp EXIT - -temp_srv_dir=`mktemp -d /tmp/charm-helper-srv.XXXXXX` -temp_dl_dir=`mktemp -d /tmp/charm-helper-dl.XXXXXX` -temp_dirs="$temp_srv_dir $temp_dl_dir" -test_url=http://127.0.0.1:8999 -cd $temp_srv_dir -output Starting SimpleHTTPServer in $PWD on port 8999 to test fetching files. -sh $test_home/run_webserver.sh 8999 > $temp_srv_dir/server.log 2>&1 & -output Looping wget until webserver responds... -listening=0 -for i in 1 2 3 4 5 ; do - sleep 1 - if wget -q $test_url/ ; then - output Attempt $i succeeded. - listening=1 - break - fi - output Attempt $i failed.. +for i in $test_home/test_*.sh ; do + . $i done -if [ $listening -eq 0 ] ; then - output fetching from test webserver Failed $i times, aborting. - exit 1 -fi -output Creating temp data file -cat > testdata.txt < testdata.txt.gz -gzip_hash=`sha256sum testdata.txt.gz|cut -d' ' -f1` -cd $temp_dl_dir -CH_DOWNLOAD_DIR=$temp_dl_dir -start_test ch_get_file... -ch_get_file '_bad_#args/foo' && return 1 || : -ch_get_file $test_url/testdata.txt > /dev/null -f=`ch_get_file $test_url/testdata.txt` -cmp $f $temp_srv_dir/testdata.txt -ch_get_file $test_url/testdata.txt $text_hash > /dev/null -ch_get_file $test_url/testdata.txt.gz > /dev/null -f=`ch_get_file $test_url/testdata.txt.gz` -cmp $f $temp_srv_dir/testdata.txt.gz -ch_get_file $test_url/testdata.txt.gz $gzip_hash > /dev/null -echo PASS diff -Nru charm-tools-0.3+92/tests/helpers/lib.sh charm-tools-0.3+121/tests/helpers/lib.sh --- charm-tools-0.3+92/tests/helpers/lib.sh 1970-01-01 00:00:00.000000000 +0000 +++ charm-tools-0.3+121/tests/helpers/lib.sh 2012-01-19 20:32:05.000000000 +0000 @@ -0,0 +1,15 @@ +output () { + echo `date`: $* +} + +start_output () { + echo -n `date`: $* +} + +start_test () { + echo -n `date`: Testing $* +} + +HELPERS_HOME=${HELPERS_HOME:-"$test_home/../../helpers/sh"} + +LIB_SOURCED=1 diff -Nru charm-tools-0.3+92/tests/helpers/test_apparmor.sh charm-tools-0.3+121/tests/helpers/test_apparmor.sh --- charm-tools-0.3+92/tests/helpers/test_apparmor.sh 1970-01-01 00:00:00.000000000 +0000 +++ charm-tools-0.3+121/tests/helpers/test_apparmor.sh 2012-01-19 20:32:05.000000000 +0000 @@ -0,0 +1,58 @@ +#!/bin/sh + +if [ -z "$test_home" ] ; then + test_home=`dirname $0` + test_home=`readlink -f $test_home` +fi + +[ "$LIB_SOURCED" = "1" ] || . $test_home/lib.sh + +set -ue + +mock_service() { + echo $* >> $SERVICE_LOG +} +alias service=mock_service + +. $HELPERS_HOME/apparmor.sh + +CHARM_DIR="" +SERVICE_LOG="" +CH_APPARMOR_DESTDIR="" + +cleanup_apparmor() { + if [ -n "$CHARM_DIR" ] && [ -d "$CHARM_DIR" ] ; then + rm -rf $CHARM_DIR + fi + if [ -n "$CH_APPARMOR_DESTDIR" ] && [ -d "$CH_APPARMOR_DESTDIR" ] ; then + rm -rf $CH_APPARMOR_DESTDIR + fi + if [ -n "$SERVICE_LOG" ] && [ -f "$SERVICE_LOG" ] ; then + rm -rf $SERVICE_LOG + fi +} + +trap cleanup_apparmor EXIT + +CHARM_DIR=`mktemp -d /tmp/ch_charm_dir.XXXXXX` +CH_APPARMOR_DESTDIR=`mktemp -d /tmp/ch_apparmor_root.XXXXXX` +SERVICE_LOG=`mktemp /tmp/service_log.XXXXXX` + +mkdir -p $CHARM_DIR/apparmor/profiles.d +mkdir -p $CH_APPARMOR_DESTDIR/etc/apparmor.d +cat > $CHARM_DIR/apparmor/profiles.d/usr.bin.foo < +} +EOF + +start_test ch_apparmor_load... +ch_apparmor_load +[ -f $CH_APPARMOR_DESTDIR/etc/apparmor.d/usr.bin.foo ] +cmp $CH_APPARMOR_DESTDIR/etc/apparmor.d/usr.bin.foo $CHARM_DIR/apparmor/profiles.d/usr.bin.foo +grep -q "apparmor reload" $SERVICE_LOG +cp /dev/null $SERVICE_LOG +echo PASS + +trap - EXIT +cleanup_apparmor diff -Nru charm-tools-0.3+92/tests/helpers/test_net.sh charm-tools-0.3+121/tests/helpers/test_net.sh --- charm-tools-0.3+92/tests/helpers/test_net.sh 1970-01-01 00:00:00.000000000 +0000 +++ charm-tools-0.3+121/tests/helpers/test_net.sh 2012-01-19 20:32:05.000000000 +0000 @@ -0,0 +1,155 @@ +#!/bin/sh + +if [ -z "$test_home" ] ; then + test_home=`dirname $0` + test_home=`readlink -f $test_home` +fi + +[ "$LIB_SOURCED" = "1" ] || . $test_home/lib.sh + +set -ue + +MOCK_NET=${MOCK_NET:-"true"} + +mock_host () { + if echo $* | grep -q "[_#]" ; then return 1 ; fi + echo nothost.local has address 127.0.0.1 + echo nothost.local has address 127.0.1.1 +} + +mock_dig () { + if echo $* | grep -q "[_#]" ; then return 1 ; fi + echo 127.0.0.1 + echo 127.0.1.1 +} + +if [ "$MOCK_NET" = "true" ] ; then + alias host=mock_host + alias dig=mock_dig +fi + +# Uncomment this to get more info on why wget failed +#CH_WGET_ARGS="--verbose" + +. $HELPERS_HOME/net.sh + +start_test ch_type_hash... +# Test return codes +ch_type_hash "not a hash" > /dev/null && return 1 || : +ch_type_hash '062b92a381b6ee8f87917f8dc19ff1bb' > /dev/null +ch_type_hash '188c481c99311aba88ffeadde1d59fcca3d64d10' > /dev/null +ch_type_hash '07a9a2188113d45f23e4abe3e8b540931d1f3892634399688bab4bde08132b4b' > /dev/null +# Test types +[ "`ch_type_hash '062b92a381b6ee8f87917f8dc19ff1bb'`" = "md5" ] +[ "`ch_type_hash '188c481c99311aba88ffeadde1d59fcca3d64d10'`" = "sha1" ] +[ "`ch_type_hash '07a9a2188113d45f23e4abe3e8b540931d1f3892634399688bab4bde08132b4b'`" = "sha256" ] +echo PASS + +start_test ch_is_url... +ch_is_url "not a url" && return 1 || : +ch_is_url "http://www.w3c.org/" > /dev/null +ch_is_url "ftp://ftp.kernel.org/" > /dev/null +ch_is_url "https://launchpad.net" > /dev/null +[ "`ch_is_url 'https://launchpad.net'`" = "true" ] +echo PASS + +start_test Testing ch_is_ip... +ch_is_ip 'just.a.hostname.com' && return 1 || : +ch_is_ip '256.2.3.4' && return 1 || : +ch_is_ip '1.2.3.4' > /dev/null +ch_is_ip '192.168.3.4' > /dev/null +ch_is_ip '3.1.1.1' > /dev/null +[ "`ch_is_ip '192.168.3.4'`" = "true" ] +echo PASS + +start_test Testing ch_get_ip... +testhostname=launchpad.net +myip=`host -t A $testhostname|head -n 1|cut -d' ' -f4` +ch_get_ip _invalid#hostname > /dev/null && return 1 || : +ch_get_ip $testhostname > /dev/null +[ "`ch_get_ip $testhostname`" = "$myip" ] +echo PASS + +save_pwd=$PWD +temp_srv_dir="" +temp_dl_dir="" +temp_dirs="" +cleanup_temp () { + if [ -n "$temp_dirs" ] ; then + # Trying to be safe, only one level of files should be there + if [ -f "$temp_srv_dir/webserver.pid" ] ; then + webserver_pid=`cat $temp_srv_dir/webserver.pid` + if [ -n "$webserver_pid" ] ; then + start_output Shutting down webserver... + kill $webserver_pid || echo -n webserver already dead?... + wait + echo DONE + fi + fi + if [ -n "$temp_srv_dir" ] && [ -s $temp_srv_dir/server.log ] ; then + output Printing server log + cat $temp_srv_dir/server.log + fi + local dir="" + for dir in $temp_dirs ; do + rm -f $dir/* + rmdir $dir + done + fi + cd $save_pwd +} + +trap cleanup_temp EXIT + +temp_srv_dir=`mktemp -d /tmp/charm-helper-srv.XXXXXX` +temp_dl_dir=`mktemp -d /tmp/charm-helper-dl.XXXXXX` +temp_dirs="$temp_srv_dir $temp_dl_dir" +test_url=http://127.0.0.1:8999 +cd $temp_srv_dir +output Starting SimpleHTTPServer in $PWD on port 8999 to test fetching files. +sh $test_home/run_webserver.sh 8999 > $temp_srv_dir/server.log 2>&1 & +output Looping wget until webserver responds... +listening=0 +for i in 1 2 3 4 5 ; do + sleep 1 + if wget -q $test_url/ ; then + output Attempt $i succeeded. + listening=1 + break + fi + output Attempt $i failed.. +done +if [ $listening -eq 0 ] ; then + output fetching from test webserver Failed $i times, aborting. + exit 1 +fi +output Creating temp data file +cat > testdata.txt < testdata.txt.gz +gzip_hash=`sha256sum testdata.txt.gz|cut -d' ' -f1` + +cd $temp_dl_dir +CH_DOWNLOAD_DIR=$temp_dl_dir +start_test ch_get_file... +ch_get_file '_bad_#args/foo' && return 1 || : +ch_get_file $test_url/testdata.txt > /dev/null +f=`ch_get_file $test_url/testdata.txt` +cmp $f $temp_srv_dir/testdata.txt +ch_get_file $test_url/testdata.txt $text_hash > /dev/null +ch_get_file $test_url/testdata.txt.gz > /dev/null +f=`ch_get_file $test_url/testdata.txt.gz` +cmp $f $temp_srv_dir/testdata.txt.gz +ch_get_file $test_url/testdata.txt.gz $gzip_hash > /dev/null +#test with CH_DOWLOAD_DIR unset +unset CH_DOWNLOAD_DIR +f=`ch_get_file $test_url/testdata.txt` +cmp $f $temp_srv_dir/testdata.txt +rm $f +echo PASS + +trap - EXIT +cleanup_temp