Merge lp:~nijaba/charm-tools/peer-scp into lp:~charmers/charm-tools/trunk

Proposed by Nick Barcet
Status: Merged
Approved by: Clint Byrum
Approved revision: 109
Merged at revision: 96
Proposed branch: lp:~nijaba/charm-tools/peer-scp
Merge into: lp:~charmers/charm-tools/trunk
Diff against target: 539 lines (+177/-47)
5 files modified
helpers/sh/net.sh (+1/-0)
helpers/sh/peer.sh (+172/-0)
tests/helpers/helpers.sh (+1/-0)
tests/helpers/test_net.sh (+3/-0)
tests/helpers/test_peer.sh (+0/-47)
To merge this branch: bzr merge lp:~nijaba/charm-tools/peer-scp
Reviewer Review Type Date Requested Status
Clint Byrum (community) Approve
Nick Barcet (community) Needs Resubmitting
Review via email: mp+86136@code.launchpad.net

Description of the change

Add ch_peer_copy function

To post a comment you must log in.
lp:~nijaba/charm-tools/peer-scp updated
102. By Nick Barcet

better result handling

103. By Nick Barcet

handle sudo for auto-tests (trying)

Revision history for this message
Nick Barcet (nijaba) wrote :

Trying to build this branch in a ppa, it seems that I have a problem with the test_peer.sh script. My current test script for ch_peer_copy requires to be executed as root so that I can start a second sshd server.

Is there a way to run a sshd server without being root (not only startiang, but able to do authentications)? I first tried to do this for a bit, but gave up.

Or is it possible to have sudo in dh_auto_test?
This is what I tried in the current branch but the build environment returned "tests/helpers/helpers.sh: 21: sudo: not found" see: https://launchpadlibrarian.net/87786598/buildlog_ubuntu-oneiric-i386.charm-tools_0.3%2B92-0~103~oneiric1_FAILEDTOBUILD.txt.gz

Mentoring welcome :)

review: Needs Information
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

Excerpts from Nick Barcet's message of Sun Dec 18 11:48:24 UTC 2011:
> Review: Needs Information
>
> Trying to build this branch in a ppa, it seems that I have a problem with the test_peer.sh script. My current test script for ch_peer_copy requires to be executed as root so that I can start a second sshd server.
>
> Is there a way to run a sshd server without being root (not only startiang, but able to do authentications)? I first tried to do this for a bit, but gave up.
>
> Or is it possible to have sudo in dh_auto_test?
> This is what I tried in the current branch but the build environment returned "tests/helpers/helpers.sh: 21: sudo: not found" see: https://launchpadlibrarian.net/87786598/buildlog_ubuntu-oneiric-i386.charm-tools_0.3%2B92-0~103~oneiric1_FAILEDTOBUILD.txt.gz
>
> Mentoring welcome :)

an alternative to openssh for testing might be using twisted's ssh server impl.
it requres a little setup, but you can setup arbitrary users/server keys.

Some examples here.

http://twistedmatrix.com/documents/current/conch/examples/

hth,
kapil

Revision history for this message
Nick Barcet (nijaba) wrote :

On 12/19/2011 03:20 PM, Kapil Thangavelu wrote:
> an alternative to openssh for testing might be using twisted's ssh server impl.
> it requres a little setup, but you can setup arbitrary users/server keys.
>
> Some examples here.
>
> http://twistedmatrix.com/documents/current/conch/examples/

The problem is that after a summary search, I can't find an example
implementation that support scp nor rsync, and for just a text of a
basic charm helper, writing one seems like an overkill. Thanks for the
pointer anyway.

Nick

lp:~nijaba/charm-tools/peer-scp updated
104. By Nick Barcet

adding test-sudo_peer.sh

105. By Nick Barcet

finally able to run sshd as a normal user, thanks to Spamaps

Revision history for this message
Nick Barcet (nijaba) wrote :

ok, this time test_peer.sh work without being root! Thanks Clint!

lp:~nijaba/charm-tools/peer-scp updated
106. By Nick Barcet

this test is uneeded now

Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Nick, thats great, it runs as non-root now, :)

And so commences the review.

[0] This is my bug, but you've exposed it. :) The way I've done the trap in helpers/test_net.sh is a bit unfair to other tests, and should be corrected. We should manage the EXIT trap a little more carefully then. At the bottom of each test_* script that has a trap, we need to call the registered exit trap and clear it, as the way this runs right now, the simple http server that test_net runs, keeps running after the tests run, because your new trap overrides the old one.

So, it should look something like this at the bottom of tests/helpers/test_net.sh

trap - EXIT
cleanup_temp

And at the bottom of test_peer.sh

trap - EXIT
cleanup_peer

[1] ssh-keygen can hang *forever* on stock EC2 instances. They have very poor entropy. Perhaps we should recommend haveged with charm-helpers-sh, which helps keep entropy up on instances (though i believe the entropy is of "moderate" quality). Otherwise another option is to make use of the SSH host key since the instance boot process already takes great pains to make that generation fast.

[2] I think we should consider adding a flag to make this key exchange permanent, and by default remove the key from authorized_keys after the copy. I'm not sure I really like having all nodes in a service be able to login as root to all other nodes in the service. For now, its ok, but maybe open this as a bug in charm-tools so we remember to consider it.

[3] in the tests, use 'output' not 'echo' so we get uniform output.

[4] Why the 'CHARM_HELPER_VERSION' in net.sh ?

I'd say the only blocker to merging is [0] so we don't leave a stale background python process hanging around for each test run. The rest are just nit picks, not real problems that make things bad.

review: Needs Fixing
lp:~nijaba/charm-tools/peer-scp updated
107. By Nick Barcet

Deregistering traps at end of tests

108. By Nick Barcet

changing test result to output function

109. By Nick Barcet

removing useless versioning

Revision history for this message
Nick Barcet (nijaba) wrote :

[0] fixed

[1] ok to recommend haveged, but since the packaging is not part of that branch, it will be another merge request

[2] I disagree. In the branch I am working on I am reusing this to allow for subsequent sync/copies within config-changed hooks, which I would not be able to do without having the keys in place since I am not in a 2 way channel anymore.

[3] fixed

[4] removed, did not make sense in the end

review: Needs Resubmitting
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Ok, LGTM

To follow up with [2] from above, I'd like the default to be "safer" meaning only when juju says "its ok to copy stuff" will these keys work. Another option would be to always copy as a non-root user. I agree with you that there will be times that this does not work, but I'd like users to have to choose less security. Users almost never choose more, until they're already burned.

Approved, please push this into lp:charm-tools, newbie charmer! :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'helpers/sh/net.sh'
2--- helpers/sh/net.sh 2011-12-18 21:54:05 +0000
3+++ helpers/sh/net.sh 2011-12-21 19:02:23 +0000
4@@ -181,3 +181,4 @@
5 echo $CHECK_IP
6 return 0
7 }
8+
9
10=== modified file 'helpers/sh/peer.sh'
11--- helpers/sh/peer.sh 2011-12-16 11:36:30 +0000
12+++ helpers/sh/peer.sh 2011-12-21 19:02:23 +0000
13@@ -83,3 +83,175 @@
14 {
15 echo "`ch_unit_id $JUJU_UNIT_NAME`"
16 }
17+
18+
19+##
20+# ch_peer_copy [-r|--rsync][-p <port>][-o "<opt>"] sourcepath1 destpath1 [... sourcepathN destpathN]
21+# ch_peer_scp [-r][-p <port>][-o "<opt>"] sourcepath1 destpath1 [... sourcepathN destpathN]
22+# ch_peer_rsync [-p <port>] sourcepath1 destpath1 [... sourcepathN destpathN]
23+#
24+# distribute a list of file to all slave of the peer relation
25+#
26+# param
27+# -r recursive scp copy (scp only, always on with rsync)
28+# -p <port> destination port to connect to
29+# -o "<opt>" any pathttrough options to the copy util
30+# --rsync use rsync instead of scp
31+# sourcepath path from which to copy (do not specify host, it will always
32+# be coming from the leader of the peer relation)
33+# destpath path to which to copy (do not specify host, it will always
34+# be the slaves of the peer relation)
35+#
36+# returns
37+# 1 when copy is complete on the slave side
38+# FALSE if an error was encountered
39+#
40+# This executes in multiple passes between the leader and each peer
41+#
42+# LEADER SLAVE
43+# <------------------- set scp-hostname
44+# set scp-ssh-key ----------------->
45+# save shh-keys
46+# <------------------- set scp-ssh-key-saved
47+# do file copy
48+# set scp-copy-done --------------->
49+#
50+# This function is idempotent and should be called for each JOINED or
51+# CHANGED event for slave or leader in the peer relation exactly the same way
52+
53+alias ch_peer_scp=ch_peer_copy
54+alias ch_peer_rsync='ch_peer_copy --rsync'
55+ch_peer_copy() {
56+ local USAGE="ERROR in $*
57+USAGE: ch_peer_scp [-r][-p <port>][-o \"<opt>\"] sourcepath1 destpath1 [... sourcepathN destpathN]
58+USAGE: ch_peer_rsync [-p <port>][-o \"<opt>\"] sourcepath1 destpath1 [... sourcepathN destpathN]"
59+ local ssh_key_p="$HOME/.ssh"
60+ local result=0
61+
62+ if [ $# -eq 0 ]; then
63+ juju-log "$USAGE"
64+ juju-log "ch_peer_copy: please provide at least one argument (path)"
65+ exit 1
66+ fi
67+
68+ ## LEADER ##
69+
70+ if ch_peer_i_am_leader ; then
71+ juju-log "ch_peer_copy: This is our leader"
72+
73+ local remote=`relation-get scp-hostname`
74+ local ssh_key_saved=`relation-get scp-ssh-key-saved`
75+ if [ -z $remote ]; then
76+ juju-log "ch_peer_copy: We do not have a remote hostname yet"
77+ remote=0
78+ fi
79+
80+ local scp_options="-o StrictHostKeyChecking=no -B"
81+ local rsync_options=""
82+ local paths=""
83+ local copy_command="scp"
84+
85+ while [ "$#" -gt 0 ];
86+ do
87+ case "$1" in
88+ "-r") # scp recure
89+ scp_options="$scp_options -r"
90+ shift
91+ ;;
92+ "-p") # port number
93+ shift
94+ scp_options="$scp_options -P $1"
95+ rsync_options="$rsync_options -e 'ssh -p $1 -o StrictHostKeyChecking=no'"
96+ shift
97+ ;;
98+ "-o") # passthrough option
99+ shift
100+ scp_options="$scp_options $1"
101+ rsync_options="$rsync_options $1"
102+ shift
103+ ;;
104+ "--rsync") # rsync secure (-e ssh)
105+ copy_command="rsync"
106+ shift
107+ ;;
108+ "$0")
109+ shift
110+ ;;
111+ *) # should be a pair of file
112+ if [ -e "`echo "$1" | sed 's/\*$//'`" ]; then
113+ local sourcep="$1"
114+ shift
115+ paths="$paths $sourcep $USER@$remote:$1"
116+ juju-log "ch_peer_copy: paths found: $sourcep -> $1"
117+ else
118+ juju-log "ch_peer_copy: unknown option, skipping: $1"
119+ fi
120+ shift
121+ ;;
122+ esac
123+ done
124+ if [ ! -n "$paths" ]; then
125+ juju-log "$USAGE"
126+ juju-log "ch_peer_copy: please provide at least one path"
127+ exit 1
128+ fi
129+
130+ if [ -n $remote ]; then
131+ # We know where to send file to
132+
133+ case $ssh_key_saved in
134+ 1) # ssh keys have been save, let's copy
135+ if [ x"$copy_command" = x"rsync" ]; then
136+ scp_options=$rsync_options
137+ fi
138+ juju-log "ch_peer_copy: $copy_command $scp_options $paths"
139+ eval "$copy_command $scp_options $paths"
140+ relation-set scp-copy-done=1
141+ ;;
142+
143+ *) # we need to first distribute our ssh key files
144+ juju-log "ch_peer_copy: distributing ssh key"
145+ if [ ! -f "$ssh_key_p/id_rsa" ]; then
146+ ssh-keygen -q -N '' -t rsa -b 2048 -f $ssh_key_p/id_rsa
147+ fi
148+ relation-set scp-ssh-key="`cat $ssh_key_p/id_rsa.pub`"
149+ ;;
150+
151+ esac
152+ fi
153+
154+ ## REMOTE ##
155+
156+ else # Not the leader
157+ juju-log "ch_peer_copy: This is a slave"
158+
159+ local scp_copy_done=`relation-get scp-copy-done`
160+ local scp_ssh_key="`relation-get scp-ssh-key`"
161+
162+ if [ -n "$scp_copy_done" ] && [ $scp_copy_done = 1 ]; then
163+ juju-log "ch_peer_copy: copy done, thanks"
164+ result=1
165+ else
166+ if [ -n "$scp_ssh_key" ]; then
167+ juju-log "ssh key dir: $ssh_key_p"
168+ mkdir -p $ssh_key_p
169+ chmod 700 $ssh_key_p
170+ if ! grep -q -F "$scp_ssh_key" $ssh_key_p/authorized_keys ; then
171+ juju-log "ch_peer_copy: saving ssh key $scp_ssh_key"
172+ echo "$scp_ssh_key" >> $ssh_key_p/authorized_keys
173+ relation-set scp-ssh-key-saved=1
174+ else
175+ juju-log "ch_peer_copy: ssh keys already saved, thanks"
176+ relation-set scp-ssh-key-saved=1
177+ fi
178+ chmod 600 "$ssh_key_p/authorized_keys"
179+ else
180+ juju-log "ch_peer_copy: ssh_keys not set yet, later"
181+ relation-set scp-hostname=`unit-get private-address`
182+ fi
183+ fi
184+ fi
185+ juju-log "ch_peer_copy: returning: $result"
186+ echo $result
187+}
188+
189
190=== modified file 'tests/helpers/helpers.sh'
191--- tests/helpers/helpers.sh 2011-12-16 21:03:04 +0000
192+++ tests/helpers/helpers.sh 2011-12-21 19:02:23 +0000
193@@ -15,3 +15,4 @@
194 for i in $test_home/test_*.sh ; do
195 . $i
196 done
197+
198
199=== modified file 'tests/helpers/test_net.sh'
200--- tests/helpers/test_net.sh 2011-12-18 22:05:29 +0000
201+++ tests/helpers/test_net.sh 2011-12-21 19:02:23 +0000
202@@ -150,3 +150,6 @@
203 cmp $f $temp_srv_dir/testdata.txt
204 rm $f
205 echo PASS
206+
207+trap - EXIT
208+cleanup_temp
209
210=== added file 'tests/helpers/test_peer.sh'
211--- tests/helpers/test_peer.sh 1970-01-01 00:00:00 +0000
212+++ tests/helpers/test_peer.sh 2011-12-21 19:02:23 +0000
213@@ -0,0 +1,274 @@
214+#!/bin/sh
215+if [ -z "$test_home" ] ; then
216+ test_home=`dirname $0`
217+ test_home=`readlink -f $test_home`
218+fi
219+
220+[ "$LIB_SOURCED" = "1" ] || . $test_home/lib.sh
221+
222+set -ue
223+
224+#mock relation-list
225+alias relation-list=mock_relation_list
226+mock_relation_list()
227+{
228+ [ -z $CH_MASTER ] && let CH_MASTER=1
229+
230+ case $CH_MASTER in
231+ 1)
232+ echo "TEST/2
233+TEST/3
234+TEST/4"
235+ ;;
236+ 0)
237+ echo "TEST/1
238+TEST/3
239+TEST/4"
240+ ;;
241+ esac
242+
243+}
244+
245+#Save juju-log for debugging
246+CH_TEMPLOG="/tmp/tmp-juju-log"
247+echo "" > $CH_TEMPLOG
248+output "creating test-log in $CH_TEMPLOG"
249+alias juju-log=mock_juju_log
250+mock_juju_log()
251+{
252+ echo "$1" >> $CH_TEMPLOG
253+}
254+
255+#mock unit-get
256+alias unit-get=mock_unit_get
257+mock_unit_get()
258+{
259+ case $1 in
260+ "private-address")
261+ echo "127.0.0.1"
262+ ;;
263+ *)
264+ echo "UNDEFINED"
265+ ;;
266+ esac
267+}
268+
269+#mock relation-set/get
270+alias relation-set=mock_relation_set
271+alias relation-get=mock_relation_get
272+CH_scp_hostname=""
273+CH_scp_ssh_key_saved=""
274+CH_scp_ssh_key=""
275+CH_scp_copy_done=""
276+mock_relation_set()
277+{
278+ juju-log "mock_relation_set: $1"
279+ CH_varname=`echo $1 | cut -d= -f1`
280+ CH_value=`echo $1 | sed 's/^[^=]*=//'`
281+ case $CH_varname in
282+ "scp-hostname")
283+ CH_scp_hostname=$CH_value
284+ ;;
285+ "scp-ssh-key-saved")
286+ CH_scp_ssh_key_saved=$CH_value
287+ ;;
288+ "scp-ssh-key")
289+ CH_scp_ssh_key="$CH_value"
290+ ;;
291+ "scp-copy-done")
292+ CH_scp_copy_done=$CH_value
293+ ;;
294+ *)
295+ juju-log "mock_relation_set: unknow var $CH_varname"
296+ ;;
297+ esac
298+}
299+mock_relation_get()
300+{
301+ case $1 in
302+ "scp-hostname")
303+ echo $CH_scp_hostname
304+ juju-log "mock_relation_get: $1 = $CH_scp_hostname"
305+ ;;
306+ "scp-ssh-key-saved")
307+ echo $CH_scp_ssh_key_saved
308+ juju-log "mock_relation_get: $1 = $CH_scp_ssh_key_saved"
309+ ;;
310+ "scp-ssh-key")
311+ echo "$CH_scp_ssh_key"
312+ juju-log "mock_relation_get: $1 = $CH_scp_ssh_key"
313+ ;;
314+ "scp-copy-done")
315+ echo $CH_scp_copy_done
316+ juju-log "mock_relation_get: $1 = $CH_scp_copy_done"
317+ ;;
318+ *)
319+ juju-log "mock_relation_get: unknow var $1"
320+ ;;
321+ esac
322+}
323+
324+
325+
326+# mock sshd server
327+CH_TEMPDIR="/tmp/`mktemp -d "/tmp/juju-helpers-tmp.XXXXXXX"`"
328+mkdir -p $CH_TEMPDIR/sourcedir/
329+mkdir -p $CH_TEMPDIR/destdir/
330+mkdir -p $CH_TEMPDIR/$HOME/
331+[ ! `which pwgen` ] && apt-get -y install pwgen
332+pwgen > $CH_TEMPDIR/sourcedir/testfile0
333+pwgen > $CH_TEMPDIR/sourcedir/testfile1
334+pwgen > $CH_TEMPDIR/sourcedir/testfile
335+CH_portnum=28822
336+ssh-keygen -t rsa -b 1024 -N "" -h -f $CH_TEMPDIR/my_host_key > /dev/null 2>&1
337+/usr/sbin/sshd -o PidFile=$CH_TEMPDIR/sshd.pid -o HostKey=$CH_TEMPDIR/my_host_key -p $CH_portnum > /dev/null 2>&1
338+cleanup_peer()
339+{
340+ echo "Cleaning up..."
341+ kill -9 `cat $CH_TEMPDIR/sshd.pid`
342+ rm -rf $CH_TEMPDIR
343+ unalias juju-log
344+ unalias relation-set
345+ unalias relation-get
346+ unalias unit-get
347+ unalias relation-list
348+}
349+trap cleanup_peer EXIT
350+
351+. $HELPERS_HOME/peer.sh
352+
353+start_test ch_unit_id...
354+JUJU_UNIT_NAME="TEST/1"
355+[ ! `ch_unit_id $JUJU_UNIT_NAME` -eq 1 ] && return 1
356+CH_bad="badarg"
357+ch_unit_id $CH_bad > /dev/null || return 1
358+output PASS
359+
360+start_test ch_my_unit_id...
361+[ ! `ch_my_unit_id` -eq 1 ] && return 1
362+output PASS
363+
364+start_test ch_peer_i_am_leader...
365+JUJU_REMOTE_UNIT="TEST/3"
366+JUJU_UNIT_NAME="TEST/2"
367+CH_MASTER=1
368+ch_peer_i_am_leader && return 1 || :
369+JUJU_UNIT_NAME="TEST/1"
370+ch_peer_i_am_leader || return 1 && :
371+output PASS
372+
373+start_test ch_peer_leader...
374+[ "`ch_peer_leader`" = "TEST/1" ] || return 1
375+[ `ch_peer_leader --id` -eq 1 ] || return 1
376+JUJU_UNIT_NAME="TEST/3"
377+[ "`ch_peer_leader`" = "TEST/2" ] || return 1
378+[ `ch_peer_leader --id` -eq 2 ] || return 1
379+output PASS
380+
381+start_test "ch_peer_scp -r..."
382+#save authorized keys and known_hosts before modifications
383+touch $HOME/.ssh/authorized_keys
384+cp $HOME/.ssh/authorized_keys $HOME/.ssh/authorized_keys_saved
385+touch $HOME/.ssh/known_hosts
386+cp $HOME/.ssh/known_hosts $HOME/.ssh/known_hosts_saved
387+for i in 1 2 3
388+do
389+ #slave relation joined
390+ JUJU_UNIT_NAME="TEST/2"
391+ JUJU_REMOTE_UNIT="TEST/1"
392+ CH_MASTER=0
393+ ch_peer_scp -r -p $CH_portnum -o "-q" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" > $CH_TEMPDIR/result 2> /dev/null
394+ [ `cat $CH_TEMPDIR/result` = 1 ] && break
395+ #master relation joined
396+ JUJU_UNIT_NAME="TEST/1"
397+ JUJU_REMOTE_UNIT="TEST/2"
398+ CH_MASTER=1
399+ ch_peer_scp -r -p $CH_portnum -o "-q" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" > $CH_TEMPDIR/result 2> /dev/null
400+ [ `cat $CH_TEMPDIR/result` = 1 ] && break
401+done
402+[ ! -e $CH_TEMPDIR/destdir/ ] && output "dir not copied" && exit 1
403+[ ! -e $CH_TEMPDIR/destdir/testfile0 ] && output "file1 not copied" && exit 1
404+[ ! -e $CH_TEMPDIR/destdir/testfile1 ] && output "file2 not copied" && exit 1
405+CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile0 | cut -d" " -f1`
406+CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile0 | cut -d" " -f1`
407+[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1
408+rm -rf $CH_TEMPDIR/destdir/*
409+#restore authorized_keys & known_hosts
410+mv $HOME/.ssh/authorized_keys_saved $HOME/.ssh/authorized_keys
411+mv $HOME/.ssh/known_hosts_saved $HOME/.ssh/known_hosts
412+output PASS
413+
414+start_test "ch_peer_rsync..."
415+CH_scp_hostname=""
416+CH_scp_ssh_key_saved=""
417+CH_scp_ssh_key=""
418+CH_scp_copy_done=""
419+#save authorized keys and known_hosts before modifications
420+touch $HOME/.ssh/authorized_keys
421+cp $HOME/.ssh/authorized_keys $HOME/.ssh/authorized_keys_saved
422+touch $HOME/.ssh/known_hosts
423+cp $HOME/.ssh/known_hosts $HOME/.ssh/known_hosts_saved
424+for i in 1 2 3
425+do
426+ #slave relation joined
427+ JUJU_UNIT_NAME="TEST/2"
428+ JUJU_REMOTE_UNIT="TEST/1"
429+ CH_MASTER=0
430+ ch_peer_rsync -p $CH_portnum -o "-azq" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" > $CH_TEMPDIR/result 2> /dev/null
431+ [ `cat $CH_TEMPDIR/result` = 1 ] && break
432+ #master relation joined
433+ JUJU_UNIT_NAME="TEST/1"
434+ JUJU_REMOTE_UNIT="TEST/2"
435+ CH_MASTER=1
436+ ch_peer_rsync -p $CH_portnum -o "-azq" "$CH_TEMPDIR/sourcedir/*" "$CH_TEMPDIR/destdir/" > $CH_TEMPDIR/result 2> /dev/null
437+ [ `cat $CH_TEMPDIR/result` = 1 ] && break
438+done
439+[ ! -e $CH_TEMPDIR/destdir/ ] && output"dir not copied" && exit 1
440+[ ! -e $CH_TEMPDIR/destdir/testfile0 ] && output "file1 not copied" && exit 1
441+[ ! -e $CH_TEMPDIR/destdir/testfile1 ] && output "file2 not copied" && exit 1
442+CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile0 | cut -d" " -f1`
443+CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile0 | cut -d" " -f1`
444+[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1
445+rm -rf $CH_TEMPDIR/destdir/*
446+#restore authorized_keys & known_hosts
447+mv $HOME/.ssh/authorized_keys_saved $HOME/.ssh/authorized_keys
448+mv $HOME/.ssh/known_hosts_saved $HOME/.ssh/known_hosts
449+output PASS
450+
451+start_test "ch_peer_scp..."
452+CH_scp_hostname=""
453+CH_scp_ssh_key_saved=""
454+CH_scp_ssh_key=""
455+CH_scp_copy_done=""
456+#save authorized keys and known_hosts before modifications
457+touch $HOME/.ssh/authorized_keys
458+cp $HOME/.ssh/authorized_keys $HOME/.ssh/authorized_keys_saved
459+touch $HOME/.ssh/known_hosts
460+cp $HOME/.ssh/known_hosts $HOME/.ssh/known_hosts_saved
461+for i in 1 2 3
462+do
463+ #slave relation joined
464+ JUJU_UNIT_NAME="TEST/2"
465+ JUJU_REMOTE_UNIT="TEST/1"
466+ CH_MASTER=0
467+ ch_peer_scp -p $CH_portnum -o "-q" $CH_TEMPDIR/sourcedir/testfile $CH_TEMPDIR/destdir/ > $CH_TEMPDIR/result 2> /dev/null
468+ [ `cat $CH_TEMPDIR/result` = 1 ] && break
469+ #master relation joined
470+ JUJU_UNIT_NAME="TEST/1"
471+ JUJU_REMOTE_UNIT="TEST/2"
472+ CH_MASTER=1
473+ ch_peer_scp -p $CH_portnum -o "-q" $CH_TEMPDIR/sourcedir/testfile $CH_TEMPDIR/destdir/ > $CH_TEMPDIR/result 2> /dev/null
474+ [ `cat $CH_TEMPDIR/result` = 1 ] && break
475+done
476+[ ! -e $CH_TEMPDIR/destdir/testfile ] && output"file not copied" && exit 1
477+CH_t1=`md5sum $CH_TEMPDIR/sourcedir/testfile | cut -d" " -f1`
478+CH_t2=`md5sum $CH_TEMPDIR/destdir/testfile | cut -d" " -f1`
479+[ ! "$CH_t1" = "$CH_t2" ] && output "md5sum differ" && exit 1
480+rm -rf $CH_TEMPDIR/destdir/*
481+#restore authorized_keys & known_hosts
482+mv $HOME/.ssh/authorized_keys_saved $HOME/.ssh/authorized_keys
483+mv $HOME/.ssh/known_hosts_saved $HOME/.ssh/known_hosts
484+output PASS
485+
486+trap - EXIT
487+cleanup_peer
488
489=== removed file 'tests/helpers/test_peer.sh'
490--- tests/helpers/test_peer.sh 2011-12-16 21:03:04 +0000
491+++ tests/helpers/test_peer.sh 1970-01-01 00:00:00 +0000
492@@ -1,47 +0,0 @@
493-#!/bin/sh
494-if [ -z "$test_home" ] ; then
495- test_home=`dirname $0`
496- test_home=`readlink -f $test_home`
497-fi
498-
499-[ "$LIB_SOURCED" = "1" ] || . $test_home/lib.sh
500-
501-set -ue
502-
503-#mock relation-list
504-alias relation-list=relation_list
505-relation_list()
506-{
507- echo "TEST/2
508-TEST/3
509-TEST/4"
510-}
511-
512-. $HELPERS_HOME/peer.sh
513-
514-start_test ch_unit_id...
515-JUJU_UNIT_NAME="TEST/1"
516-[ ! `ch_unit_id $JUJU_UNIT_NAME` -eq 1 ] && return 1
517-CH_bad="badarg"
518-ch_unit_id $CH_bad > /dev/null || return 1
519-echo PASS
520-
521-start_test ch_my_unit_id...
522-[ ! `ch_my_unit_id` -eq 1 ] && return 1
523-echo PASS
524-
525-start_test ch_peer_i_am_leader...
526-JUJU_REMOTE_UNIT="TEST/3"
527-JUJU_UNIT_NAME="TEST/2"
528-ch_peer_i_am_leader && return 1 || :
529-JUJU_UNIT_NAME="TEST/1"
530-ch_peer_i_am_leader || return 1 && :
531-echo PASS
532-
533-start_test ch_peer_leader...
534-[ "`ch_peer_leader`" = "TEST/1" ] || return 1
535-[ `ch_peer_leader --id` -eq 1 ] || return 1
536-JUJU_UNIT_NAME="TEST/3"
537-[ "`ch_peer_leader`" = "TEST/2" ] || return 1
538-[ `ch_peer_leader --id` -eq 2 ] || return 1
539-echo PASS

Subscribers

People subscribed via source and target branches