cucumber-chef 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.document +5 -0
  2. data/.gitignore +45 -0
  3. data/Gemfile +21 -0
  4. data/LICENSE +201 -0
  5. data/README.md +83 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/bin/cucumber-chef +162 -0
  9. data/cookbooks/cucumber-chef/README.rdoc +8 -0
  10. data/cookbooks/cucumber-chef/files/default/add-git-identity +2 -0
  11. data/cookbooks/cucumber-chef/files/default/controller-first-boot +1 -0
  12. data/cookbooks/cucumber-chef/files/default/cucumber-net +5 -0
  13. data/cookbooks/cucumber-chef/files/default/cucumber-private-key +27 -0
  14. data/cookbooks/cucumber-chef/files/default/cucumber-run_list +1 -0
  15. data/cookbooks/cucumber-chef/files/default/git-private-key +27 -0
  16. data/cookbooks/cucumber-chef/files/default/install-chef +1 -0
  17. data/cookbooks/cucumber-chef/files/default/lxc-controller-network-config +5 -0
  18. data/cookbooks/cucumber-chef/files/default/lxc-lucid-chef +377 -0
  19. data/cookbooks/cucumber-chef/files/default/permissive-ssh-config +3 -0
  20. data/cookbooks/cucumber-chef/metadata.rb +6 -0
  21. data/cookbooks/cucumber-chef/recipes/controller.rb +50 -0
  22. data/cookbooks/cucumber-chef/recipes/lxc.rb +35 -0
  23. data/cookbooks/cucumber-chef/recipes/test_lab.rb +23 -0
  24. data/cookbooks/cucumber-chef/recipes/testrunner.rb +46 -0
  25. data/cookbooks/cucumber-chef/roles/controller.rb +7 -0
  26. data/cookbooks/cucumber-chef/roles/test_lab_test.rb +9 -0
  27. data/cookbooks/cucumber-chef/templates/default/controller-client.erb +5 -0
  28. data/cookbooks/cucumber-chef/templates/default/lxc-lucid-chef +385 -0
  29. data/cucumber-chef.gemspec +118 -0
  30. data/features/installing.feature +10 -0
  31. data/features/steps/installing_steps.rb +34 -0
  32. data/features/steps/setup_steps.rb +32 -0
  33. data/features/steps/upload_steps.rb +11 -0
  34. data/features/steps/usage_steps.rb +62 -0
  35. data/features/support/env.rb +25 -0
  36. data/features/support/filetools.rb +9 -0
  37. data/features/support/silent_system.rb +4 -0
  38. data/features/usage.feature +26 -0
  39. data/lib/cucumber-chef.rb +1 -0
  40. data/lib/cucumber/chef.rb +195 -0
  41. data/lib/cucumber/chef/handy.rb +87 -0
  42. data/lib/cucumber/chef/templates/controller.erb +35 -0
  43. data/lib/cucumber/chef/templates/env.rb +16 -0
  44. data/lib/cucumber/chef/templates/example_feature.erb +11 -0
  45. data/lib/cucumber/chef/templates/example_step.erb +19 -0
  46. data/lib/cucumber/chef/templates/readme.erb +28 -0
  47. data/lib/cucumber/chef/templates/ubuntu10.04-gems.erb +43 -0
  48. data/lib/cucumber/chef/version.rb +5 -0
  49. data/lib/cucumber/ec2_server_create.rb +99 -0
  50. data/spec/unit/cucumber_chef_spec.rb +270 -0
  51. metadata +213 -0
@@ -0,0 +1,8 @@
1
+ = DESCRIPTION:
2
+
3
+ = REQUIREMENTS:
4
+
5
+ = ATTRIBUTES:
6
+
7
+ = USAGE:
8
+
@@ -0,0 +1,2 @@
1
+ eval $(ssh-agent) > /dev/null 2>&1
2
+ ssh-add /root/.ssh/git-key.rsa > /dev/null 2>&1
@@ -0,0 +1 @@
1
+ { "run_list": [ "recipe[cucumber-chef::testrunner]" ] }
@@ -0,0 +1,5 @@
1
+ lxc.network.type = veth
2
+ lxc.network.flags = up
3
+ lxc.network.link = br0
4
+ lxc.network.name = eth0
5
+ lxc.network.ipv4 = 192.168.3.2/24
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEpAIBAAKCAQEAzj2O8BxvLn1Q7vUTiyFdtle9SeataEF//+651mXTV8WdKuXG
3
+ RgvIKZPu+ZnTsqnDoR+pwMRFf95hDPHScpdYj2WVY1cN2e6xEKEsz3xcKdhaTuAO
4
+ Bd47J9wu6Nmgr1aZ/2/AWTrLEOMxUVVp/bzeSFzfHR2bctfKCKzMUCLGZLEGn0Yv
5
+ 5Qbk56V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C7FIG9bHbN3vvIZl4Ztnu+aAAa0EhX2dfQKpe33v/JkbbzLF
26
+ ua9FnGX910pMFqlPxEkdYywhBuh2j7xydqOjTOD4d2ZeaLxw6q68nUo=
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1 @@
1
+ /usr/bin/apt-get update && /usr/bin/apt-get --assume-yes --allow-unauthenticated install ruby1.9.1p180 && /usr/local/bin/gem install chef --no-ri --no-rdoc
@@ -0,0 +1,5 @@
1
+ lxc.network.type = veth
2
+ lxc.network.flags = up
3
+ lxc.network.link = br0
4
+ lxc.network.name = eth0
5
+ lxc.network.ipv4 = 192.168.20.10/24
@@ -0,0 +1,377 @@
1
+
2
+ #!/bin/bash
3
+
4
+ configure_ubuntu()
5
+ {
6
+ rootfs=$1
7
+ hostname=$2
8
+
9
+ # disable selinux in ubuntu
10
+ mkdir -p $rootfs/selinux
11
+ echo 0 > $rootfs/selinux/enforce
12
+
13
+ # set the hostname
14
+ cat <<EOF > $rootfs/etc/hostname
15
+ $hostname
16
+ EOF
17
+ # set minimal hosts
18
+ cat <<EOF > $rootfs/etc/hosts
19
+ 127.0.0.1 localhost $hostname
20
+ EOF
21
+
22
+ # provide the lxc service
23
+ cat <<EOF > $rootfs/etc/init/lxc.conf
24
+ # fake some events needed for correct startup other services
25
+
26
+ description "Container Upstart"
27
+
28
+ start on startup
29
+
30
+ script
31
+ rm -rf /var/run/*.pid
32
+ rm -rf /var/run/network/*
33
+ /sbin/initctl emit stopped JOB=udevtrigger --no-wait
34
+ /sbin/initctl emit started JOB=udev --no-wait
35
+ end script
36
+ EOF
37
+
38
+ # fix buggus runlevel with sshd
39
+ cat <<EOF > $rootfs/etc/init/ssh.conf
40
+ # ssh - OpenBSD Secure Shell server
41
+ #
42
+ # The OpenSSH server provides secure shell access to the system.
43
+
44
+ description "OpenSSH server"
45
+
46
+ start on filesystem
47
+ stop on runlevel [!2345]
48
+
49
+ expect fork
50
+ respawn
51
+ respawn limit 10 5
52
+ umask 022
53
+ # replaces SSHD_OOM_ADJUST in /etc/default/ssh
54
+ oom never
55
+
56
+ pre-start script
57
+ test -x /usr/sbin/sshd || { stop; exit 0; }
58
+ test -e /etc/ssh/sshd_not_to_be_run && { stop; exit 0; }
59
+ test -c /dev/null || { stop; exit 0; }
60
+
61
+ mkdir -p -m0755 /var/run/sshd
62
+ end script
63
+
64
+ # if you used to set SSHD_OPTS in /etc/default/ssh, you can change the
65
+ # 'exec' line here instead
66
+ exec /usr/sbin/sshd
67
+ EOF
68
+
69
+ cat <<EOF > $rootfs/etc/init/console.conf
70
+ # console - getty
71
+ #
72
+ # This service maintains a console on tty1 from the point the system is
73
+ # started until it is shut down again.
74
+
75
+ start on stopped rc RUNLEVEL=[2345]
76
+ stop on runlevel [!2345]
77
+
78
+ respawn
79
+ exec /sbin/getty -8 38400 /dev/console
80
+ EOF
81
+
82
+ cat <<EOF > $rootfs/lib/init/fstab
83
+ # /lib/init/fstab: lxc system fstab
84
+ none /spu spufs gid=spu,optional 0 0
85
+ none /tmp none defaults 0 0
86
+ none /var/lock tmpfs nodev,noexec,nosuid,showthrough 0 0
87
+ none /lib/init/rw tmpfs mode=0755,nosuid,optional 0 0
88
+ EOF
89
+
90
+
91
+
92
+ # reconfigure some services
93
+ if [ -z "$LANG" ]; then
94
+ chroot $rootfs locale-gen en_US.UTF-8
95
+ chroot $rootfs update-locale LANG=en_US.UTF-8
96
+ else
97
+ chroot $rootfs locale-gen $LANG
98
+ chroot $rootfs update-locale LANG=$LANG
99
+ fi
100
+
101
+ # remove pointless services in a container
102
+ chroot $rootfs /usr/sbin/update-rc.d -f ondemand remove
103
+
104
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls u*.conf); do mv $f $f.orig; done'
105
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls tty[2-9].conf); do mv $f $f.orig; done'
106
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls plymouth*.conf); do mv $f $f.orig; done'
107
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls hwclock*.conf); do mv $f $f.orig; done'
108
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls module*.conf); do mv $f $f.orig; done'
109
+
110
+ echo "Please change root-password !"
111
+ echo "root:root" | chroot $rootfs chpasswd
112
+
113
+ return 0
114
+ }
115
+
116
+ configure_image()
117
+ {
118
+ image=$cache/rootfs-$arch
119
+ mkdir $image/root/.ssh
120
+ chmod 0600 /root/.ssh
121
+
122
+ cat <<EOF > $image/etc/rc.local
123
+ #!/bin/sh -e
124
+ ip route add default via 192.168.20.1
125
+ exit 0
126
+ EOF
127
+
128
+ cat <<EOF > $image/root/.ssh/authorized_keys
129
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzj2O8BxvLn1Q7vUTiyFdtle9SeataEF//+651mXTV8WdKuXGRgvIKZPu+ZnTsqnDoR+pwMRFf95hDPHScpdYj2WVY1cN2e6xEKEsz3xcKdhaTuAOBd47J9wu6Nmgr1aZ/2/AWTrLEOMxUVVp/bzeSFzfHR2bctfKCKzMUCLGZLEGn0Yv5Qbk56Vr9A5jUJcKgCodWOpTcPlf+kKzxejgt/wHRZTRrJIOyx5Zhddim10/sZZ8ct9+WgBwhIL2fUHrsAb1wjxKpQCOYoxHuRSFnv4zrFzblI737TmQIHkkb9g08z3qIJLLiLKgGNXP2wclA37ctGfqwfJWj9FA9nI9iQ== root@cucumber
130
+ EOF
131
+
132
+ mkdir $image/etc/chef
133
+
134
+ cat <<EOF > $image/tmp/validation.pem
135
+ <%= IO.read(Chef::Config[:validation_key]) %>
136
+ EOF
137
+ awk NF $image/tmp/validation.pem > $image/etc/chef/validation.pem
138
+ rm $image/tmp/validation.pem
139
+
140
+ cat <<EOF > $image/etc/apt/sources.list.d/atalanta.list
141
+ deb http://packages.atalanta-systems.com lucid main
142
+ EOF
143
+
144
+ rm $image/etc/resolv.conf
145
+ cp /etc/resolv.conf $image/etc/resolv.conf
146
+ cp /etc/lxc/install-chef.sh $image/tmp/install-chef.sh
147
+ chroot $image /bin/sh -c "/usr/bin/apt-get update && /usr/bin/apt-get --assume-yes --allow-unauthenticated install strace ruby1.9.1p180"
148
+ mkdir -p $image/$HOME
149
+ chroot $image /bin/sh -c "strace /usr/local/bin/gem install chef --no-ri --no-rdoc 2>&1" 2>&1 >> /tmp/data
150
+ return $?
151
+ }
152
+
153
+ download_ubuntu()
154
+ {
155
+ packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,wget,gpgv,gnupg
156
+
157
+ cache=$1
158
+ arch=$2
159
+
160
+ # check the mini ubuntu was not already downloaded
161
+ mkdir -p "$cache/partial-$arch"
162
+ if [ $? -ne 0 ]; then
163
+ echo "Failed to create '$cache/partial-$arch' directory"
164
+ return 1
165
+ fi
166
+
167
+ # download a mini ubuntu into a cache
168
+ echo "Downloading ubuntu minimal ..."
169
+ debootstrap --verbose --variant=minbase --components=main,universe --arch=$arch --include=$packages lucid $cache/partial-$arch
170
+ if [ $? -ne 0 ]; then
171
+ echo "Failed to download the rootfs, aborting."
172
+ return 1
173
+ fi
174
+
175
+ mv "$1/partial-$arch" "$1/rootfs-$arch"
176
+ echo "Download complete."
177
+
178
+ return 0
179
+ }
180
+
181
+ copy_ubuntu()
182
+ {
183
+ cache=$1
184
+ arch=$2
185
+ rootfs=$3
186
+
187
+ # make a local copy of the miniubuntu
188
+ echo -n "Copying rootfs to $rootfs ..."
189
+ cp -a $cache/rootfs-$arch $rootfs || return 1
190
+ return 0
191
+ }
192
+
193
+ install_ubuntu()
194
+ {
195
+ cache="/var/cache/lxc/ubuntu"
196
+ rootfs=$1
197
+ mkdir -p /var/lock/subsys/
198
+ (
199
+ flock -n -x 200
200
+ if [ $? -ne 0 ]; then
201
+ echo "Cache repository is busy."
202
+ return 1
203
+ fi
204
+
205
+ arch=$(arch)
206
+ if [ "$arch" == "x86_64" ]; then
207
+ arch=amd64
208
+ fi
209
+
210
+ if [ "$arch" == "i686" ]; then
211
+ arch=i386
212
+ fi
213
+
214
+ echo "Checking cache download in $cache/rootfs-$arch ... "
215
+ if [ ! -e "$cache/rootfs-$arch" ]; then
216
+ download_ubuntu $cache $arch
217
+ if [ $? -ne 0 ]; then
218
+ echo "Failed to download 'ubuntu base'"
219
+ return 1
220
+ fi
221
+ fi
222
+ configure_image
223
+ echo "Copy $cache/rootfs-$arch to $rootfs ... "
224
+ copy_ubuntu $cache $arch $rootfs
225
+ if [ $? -ne 0 ]; then
226
+ echo "Failed to copy rootfs"
227
+ return 1
228
+ fi
229
+
230
+ return 0
231
+
232
+ ) 200>/var/lock/subsys/lxc
233
+
234
+ return $?
235
+ }
236
+
237
+ copy_configuration()
238
+ {
239
+ path=$1
240
+ rootfs=$2
241
+ name=$3
242
+
243
+ cat <<EOF >> $path/config
244
+ lxc.utsname = $name
245
+
246
+ lxc.tty = 4
247
+ lxc.pts = 1024
248
+ lxc.rootfs = $rootfs
249
+ lxc.mount = $path/fstab
250
+
251
+ lxc.cgroup.devices.deny = a
252
+ # /dev/null and zero
253
+ lxc.cgroup.devices.allow = c 1:3 rwm
254
+ lxc.cgroup.devices.allow = c 1:5 rwm
255
+ # consoles
256
+ lxc.cgroup.devices.allow = c 5:1 rwm
257
+ lxc.cgroup.devices.allow = c 5:0 rwm
258
+ lxc.cgroup.devices.allow = c 4:0 rwm
259
+ lxc.cgroup.devices.allow = c 4:1 rwm
260
+ # /dev/{,u}random
261
+ lxc.cgroup.devices.allow = c 1:9 rwm
262
+ lxc.cgroup.devices.allow = c 1:8 rwm
263
+ lxc.cgroup.devices.allow = c 136:* rwm
264
+ lxc.cgroup.devices.allow = c 5:2 rwm
265
+ # rtc
266
+ lxc.cgroup.devices.allow = c 254:0 rwm
267
+ EOF
268
+
269
+ cat <<EOF > $path/fstab
270
+ proc $rootfs/proc proc nodev,noexec,nosuid 0 0
271
+ devpts $rootfs/dev/pts devpts defaults 0 0
272
+ sysfs $rootfs/sys sysfs defaults 0 0
273
+ EOF
274
+
275
+ if [ $? -ne 0 ]; then
276
+ echo "Failed to add configuration"
277
+ return 1
278
+ fi
279
+
280
+ return 0
281
+ }
282
+
283
+ clean()
284
+ {
285
+ cache="/var/cache/lxc/ubuntu"
286
+
287
+ if [ ! -e $cache ]; then
288
+ exit 0
289
+ fi
290
+
291
+ # lock, so we won't purge while someone is creating a repository
292
+ (
293
+ flock -n -x 200
294
+ if [ $? != 0 ]; then
295
+ echo "Cache repository is busy."
296
+ exit 1
297
+ fi
298
+
299
+ echo -n "Purging the download cache..."
300
+ rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
301
+ exit 0
302
+
303
+ ) 200>/var/lock/subsys/lxc
304
+ }
305
+
306
+ usage()
307
+ {
308
+ cat <<EOF
309
+ $1 -h|--help -p|--path=<path> --clean
310
+ EOF
311
+ return 0
312
+ }
313
+
314
+ options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
315
+ if [ $? -ne 0 ]; then
316
+ usage $(basename $0)
317
+ exit 1
318
+ fi
319
+ eval set -- "$options"
320
+
321
+ while true
322
+ do
323
+ case "$1" in
324
+ -h|--help) usage $0 && exit 0;;
325
+ -p|--path) path=$2; shift 2;;
326
+ -n|--name) name=$2; shift 2;;
327
+ -c|--clean) clean=$2; shift 2;;
328
+ --) shift 1; break ;;
329
+ *) break ;;
330
+ esac
331
+ done
332
+
333
+ if [ ! -z "$clean" -a -z "$path" ]; then
334
+ clean || exit 1
335
+ exit 0
336
+ fi
337
+
338
+ type debootstrap
339
+ if [ $? -ne 0 ]; then
340
+ echo "'debootstrap' command is missing"
341
+ exit 1
342
+ fi
343
+
344
+ if [ -z "$path" ]; then
345
+ echo "'path' parameter is required"
346
+ exit 1
347
+ fi
348
+
349
+ if [ "$(id -u)" != "0" ]; then
350
+ echo "This script should be run as 'root'"
351
+ exit 1
352
+ fi
353
+
354
+ rootfs=$path/rootfs
355
+
356
+ install_ubuntu $rootfs
357
+ if [ $? -ne 0 ]; then
358
+ echo "failed to install ubuntu"
359
+ exit 1
360
+ fi
361
+
362
+ configure_ubuntu $rootfs $name
363
+ if [ $? -ne 0 ]; then
364
+ echo "failed to configure ubuntu for a container"
365
+ exit 1
366
+ fi
367
+
368
+ copy_configuration $path $rootfs $name
369
+ if [ $? -ne 0 ]; then
370
+ echo "failed write configuration file"
371
+ exit 1
372
+ fi
373
+
374
+ if [ ! -z $clean ]; then
375
+ clean || exit 1
376
+ exit 0
377
+ fi