cucumber-chef 1.0.3 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -35
- data/.rspec +1 -0
- data/.rvmrc.template +2 -0
- data/.travis.yml +22 -0
- data/Gemfile +2 -15
- data/LICENSE +202 -201
- data/NOTICE +9 -0
- data/README.md +696 -92
- data/Rakefile +39 -25
- data/TODO.md +28 -0
- data/bin/cc-knife +32 -0
- data/bin/cucumber-chef +409 -79
- data/chef_repo/cookbooks/cucumber-chef/LICENSE +202 -0
- data/chef_repo/cookbooks/cucumber-chef/README.md +69 -0
- data/chef_repo/cookbooks/cucumber-chef/attributes/default.rb +27 -0
- data/chef_repo/cookbooks/cucumber-chef/metadata.rb +13 -0
- data/chef_repo/cookbooks/cucumber-chef/recipes/default.rb +23 -0
- data/chef_repo/cookbooks/cucumber-chef/recipes/lxc.rb +315 -0
- data/chef_repo/cookbooks/cucumber-chef/recipes/test_lab.rb +146 -0
- data/chef_repo/cookbooks/cucumber-chef/templates/default/db-168-192.erb +15 -0
- data/chef_repo/cookbooks/cucumber-chef/templates/default/db-test-lab.erb +15 -0
- data/chef_repo/cookbooks/cucumber-chef/templates/default/dhcpd-conf.erb +44 -0
- data/chef_repo/cookbooks/cucumber-chef/templates/default/gemrc.erb +10 -0
- data/{cookbooks/cucumber-chef/files/default/cucumber-net → chef_repo/cookbooks/cucumber-chef/templates/default/lxc-initializer-config.erb} +1 -1
- data/chef_repo/cookbooks/cucumber-chef/templates/default/lxc-install-chef.erb +3 -0
- data/chef_repo/cookbooks/cucumber-chef/templates/default/motd.erb +10 -0
- data/chef_repo/cookbooks/cucumber-chef/templates/default/named-conf-local.erb +25 -0
- data/{cookbooks/cucumber-chef/files/default/permissive-ssh-config → chef_repo/cookbooks/cucumber-chef/templates/default/ssh-config.erb} +3 -1
- data/chef_repo/roles/test_lab.rb +24 -0
- data/cucumber-chef.gemspec +50 -123
- data/examples/README.md +7 -0
- data/examples/users_add.feature +51 -0
- data/examples/users_auto_remove.feature +50 -0
- data/features/support/env.rb +3 -2
- data/lib/cucumber/chef/bootstrap.rb +94 -0
- data/lib/cucumber/chef/command.rb +78 -0
- data/lib/cucumber/chef/config.rb +143 -93
- data/lib/cucumber/chef/helpers/chef_client.rb +87 -0
- data/lib/cucumber/chef/helpers/chef_server.rb +90 -0
- data/lib/cucumber/chef/helpers/command.rb +57 -0
- data/lib/cucumber/chef/helpers/container.rb +154 -0
- data/lib/cucumber/chef/helpers/minitest.rb +35 -0
- data/lib/cucumber/chef/helpers/server.rb +81 -0
- data/lib/cucumber/chef/helpers/test_lab.rb +46 -0
- data/lib/cucumber/chef/helpers/utility.rb +73 -0
- data/lib/cucumber/chef/helpers.rb +56 -0
- data/lib/cucumber/chef/logger.rb +90 -0
- data/lib/cucumber/chef/provisioner.rb +275 -69
- data/lib/cucumber/chef/ssh.rb +190 -0
- data/lib/cucumber/chef/steps/chef_steps.rb +32 -0
- data/lib/cucumber/chef/steps/minitest_steps.rb +29 -0
- data/lib/cucumber/chef/steps/provision_steps.rb +60 -0
- data/lib/cucumber/chef/steps/ssh_steps.rb +95 -0
- data/lib/cucumber/chef/steps.rb +27 -0
- data/lib/cucumber/chef/tcp_socket.rb +83 -0
- data/lib/cucumber/chef/template.rb +57 -0
- data/lib/cucumber/chef/templates/bootstrap/ubuntu-precise-test-lab.erb +99 -0
- data/lib/cucumber/chef/templates/cucumber/env.rb +56 -0
- data/lib/cucumber/chef/templates/cucumber/example_feature.erb +49 -0
- data/lib/cucumber/chef/templates/cucumber/example_steps.erb +11 -0
- data/lib/cucumber/chef/templates/cucumber/readme-data_bags.erb +1 -0
- data/lib/cucumber/chef/templates/cucumber/readme-keys.erb +1 -0
- data/lib/cucumber/chef/templates/cucumber/readme-roles.erb +1 -0
- data/lib/cucumber/chef/templates/cucumber/readme.erb +18 -0
- data/lib/cucumber/chef/templates/cucumber-chef/config-rb.erb +33 -0
- data/lib/cucumber/chef/templates/cucumber-chef/cucumber-yml.erb +2 -0
- data/lib/cucumber/chef/templates/cucumber-chef/knife-rb.erb +18 -0
- data/lib/cucumber/chef/test_lab.rb +308 -52
- data/lib/cucumber/chef/test_runner.rb +86 -15
- data/lib/cucumber/chef/utility.rb +128 -0
- data/lib/cucumber/chef/version.rb +30 -1
- data/lib/cucumber/chef.rb +53 -20
- data/lib/cucumber-chef.rb +24 -1
- data/spec/cucumber/chef/config_spec.rb +144 -78
- data/spec/cucumber/chef/provisioner_spec.rb +60 -16
- data/spec/cucumber/chef/test_lab_spec.rb +62 -19
- data/spec/spec_helper.rb +30 -26
- data/todo.org +17 -0
- metadata +267 -163
- data/.document +0 -5
- data/VERSION +0 -1
- data/cookbooks/cucumber-chef/README.rdoc +0 -8
- data/cookbooks/cucumber-chef/files/default/add-git-identity +0 -2
- data/cookbooks/cucumber-chef/files/default/controller-first-boot +0 -1
- data/cookbooks/cucumber-chef/files/default/cucumber-private-key +0 -27
- data/cookbooks/cucumber-chef/files/default/cucumber-run_list +0 -1
- data/cookbooks/cucumber-chef/files/default/git-private-key +0 -27
- data/cookbooks/cucumber-chef/files/default/install-chef +0 -1
- data/cookbooks/cucumber-chef/files/default/lxc-controller-network-config +0 -5
- data/cookbooks/cucumber-chef/files/default/lxc-lucid-chef +0 -378
- data/cookbooks/cucumber-chef/metadata.rb +0 -6
- data/cookbooks/cucumber-chef/recipes/controller.rb +0 -51
- data/cookbooks/cucumber-chef/recipes/lxc.rb +0 -35
- data/cookbooks/cucumber-chef/recipes/test_lab.rb +0 -23
- data/cookbooks/cucumber-chef/recipes/testrunner.rb +0 -46
- data/cookbooks/cucumber-chef/roles/controller.rb +0 -7
- data/cookbooks/cucumber-chef/roles/test_lab_test.rb +0 -9
- data/cookbooks/cucumber-chef/templates/default/controller-client.erb +0 -5
- data/cookbooks/cucumber-chef/templates/default/lxc-lucid-chef +0 -385
- data/lib/cucumber/chef/handy.rb +0 -90
- data/lib/cucumber/chef/templates/controller.erb +0 -35
- data/lib/cucumber/chef/templates/env.rb +0 -16
- data/lib/cucumber/chef/templates/example_feature.erb +0 -11
- data/lib/cucumber/chef/templates/example_step.erb +0 -19
- data/lib/cucumber/chef/templates/readme.erb +0 -14
- data/lib/cucumber/chef/templates/ubuntu10.04-gems.erb +0 -43
- data/lib/cucumber/ec2_server_create.rb +0 -99
- data/website/website.html +0 -385
@@ -1,385 +0,0 @@
|
|
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/chef/client.rb
|
141
|
-
log_level :info
|
142
|
-
log_location STDOUT
|
143
|
-
chef_server_url "<%= Chef::Config[:chef_server_url] %>"
|
144
|
-
validation_client_name "<%= Chef::Config[:validation_client_name] %>"
|
145
|
-
EOF
|
146
|
-
|
147
|
-
|
148
|
-
cat <<EOF > $image/etc/apt/sources.list.d/atalanta.list
|
149
|
-
deb http://packages.atalanta-systems.com lucid main
|
150
|
-
EOF
|
151
|
-
|
152
|
-
rm $image/etc/resolv.conf
|
153
|
-
cp /etc/resolv.conf $image/etc/resolv.conf
|
154
|
-
cp /etc/lxc/install-chef.sh $image/tmp/install-chef.sh
|
155
|
-
chroot $image /bin/sh -c "/usr/bin/apt-get update && /usr/bin/apt-get --assume-yes --allow-unauthenticated install strace ruby1.9.1p180"
|
156
|
-
mkdir -p $image/$HOME
|
157
|
-
chroot $image /bin/sh -c "/usr/local/bin/gem install chef --no-ri --no-rdoc 2>&1" 2>&1 >> /tmp/data
|
158
|
-
return $?
|
159
|
-
}
|
160
|
-
|
161
|
-
download_ubuntu()
|
162
|
-
{
|
163
|
-
packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,wget,gpgv,gnupg
|
164
|
-
|
165
|
-
cache=$1
|
166
|
-
arch=$2
|
167
|
-
|
168
|
-
# check the mini ubuntu was not already downloaded
|
169
|
-
mkdir -p "$cache/partial-$arch"
|
170
|
-
if [ $? -ne 0 ]; then
|
171
|
-
echo "Failed to create '$cache/partial-$arch' directory"
|
172
|
-
return 1
|
173
|
-
fi
|
174
|
-
|
175
|
-
# download a mini ubuntu into a cache
|
176
|
-
echo "Downloading ubuntu minimal ..."
|
177
|
-
debootstrap --verbose --variant=minbase --components=main,universe --arch=$arch --include=$packages lucid $cache/partial-$arch
|
178
|
-
if [ $? -ne 0 ]; then
|
179
|
-
echo "Failed to download the rootfs, aborting."
|
180
|
-
return 1
|
181
|
-
fi
|
182
|
-
|
183
|
-
mv "$1/partial-$arch" "$1/rootfs-$arch"
|
184
|
-
echo "Download complete."
|
185
|
-
|
186
|
-
return 0
|
187
|
-
}
|
188
|
-
|
189
|
-
copy_ubuntu()
|
190
|
-
{
|
191
|
-
cache=$1
|
192
|
-
arch=$2
|
193
|
-
rootfs=$3
|
194
|
-
|
195
|
-
# make a local copy of the miniubuntu
|
196
|
-
echo -n "Copying rootfs to $rootfs ..."
|
197
|
-
cp -a $cache/rootfs-$arch $rootfs || return 1
|
198
|
-
return 0
|
199
|
-
}
|
200
|
-
|
201
|
-
install_ubuntu()
|
202
|
-
{
|
203
|
-
cache="/var/cache/lxc/ubuntu"
|
204
|
-
rootfs=$1
|
205
|
-
mkdir -p /var/lock/subsys/
|
206
|
-
(
|
207
|
-
flock -n -x 200
|
208
|
-
if [ $? -ne 0 ]; then
|
209
|
-
echo "Cache repository is busy."
|
210
|
-
return 1
|
211
|
-
fi
|
212
|
-
|
213
|
-
arch=$(arch)
|
214
|
-
if [ "$arch" == "x86_64" ]; then
|
215
|
-
arch=amd64
|
216
|
-
fi
|
217
|
-
|
218
|
-
if [ "$arch" == "i686" ]; then
|
219
|
-
arch=i386
|
220
|
-
fi
|
221
|
-
|
222
|
-
echo "Checking cache download in $cache/rootfs-$arch ... "
|
223
|
-
if [ ! -e "$cache/rootfs-$arch" ]; then
|
224
|
-
download_ubuntu $cache $arch
|
225
|
-
if [ $? -ne 0 ]; then
|
226
|
-
echo "Failed to download 'ubuntu base'"
|
227
|
-
return 1
|
228
|
-
fi
|
229
|
-
fi
|
230
|
-
configure_image
|
231
|
-
echo "Copy $cache/rootfs-$arch to $rootfs ... "
|
232
|
-
copy_ubuntu $cache $arch $rootfs
|
233
|
-
if [ $? -ne 0 ]; then
|
234
|
-
echo "Failed to copy rootfs"
|
235
|
-
return 1
|
236
|
-
fi
|
237
|
-
|
238
|
-
return 0
|
239
|
-
|
240
|
-
) 200>/var/lock/subsys/lxc
|
241
|
-
|
242
|
-
return $?
|
243
|
-
}
|
244
|
-
|
245
|
-
copy_configuration()
|
246
|
-
{
|
247
|
-
path=$1
|
248
|
-
rootfs=$2
|
249
|
-
name=$3
|
250
|
-
|
251
|
-
cat <<EOF >> $path/config
|
252
|
-
lxc.utsname = $name
|
253
|
-
|
254
|
-
lxc.tty = 4
|
255
|
-
lxc.pts = 1024
|
256
|
-
lxc.rootfs = $rootfs
|
257
|
-
lxc.mount = $path/fstab
|
258
|
-
|
259
|
-
lxc.cgroup.devices.deny = a
|
260
|
-
# /dev/null and zero
|
261
|
-
lxc.cgroup.devices.allow = c 1:3 rwm
|
262
|
-
lxc.cgroup.devices.allow = c 1:5 rwm
|
263
|
-
# consoles
|
264
|
-
lxc.cgroup.devices.allow = c 5:1 rwm
|
265
|
-
lxc.cgroup.devices.allow = c 5:0 rwm
|
266
|
-
lxc.cgroup.devices.allow = c 4:0 rwm
|
267
|
-
lxc.cgroup.devices.allow = c 4:1 rwm
|
268
|
-
# /dev/{,u}random
|
269
|
-
lxc.cgroup.devices.allow = c 1:9 rwm
|
270
|
-
lxc.cgroup.devices.allow = c 1:8 rwm
|
271
|
-
lxc.cgroup.devices.allow = c 136:* rwm
|
272
|
-
lxc.cgroup.devices.allow = c 5:2 rwm
|
273
|
-
# rtc
|
274
|
-
lxc.cgroup.devices.allow = c 254:0 rwm
|
275
|
-
EOF
|
276
|
-
|
277
|
-
cat <<EOF > $path/fstab
|
278
|
-
proc $rootfs/proc proc nodev,noexec,nosuid 0 0
|
279
|
-
devpts $rootfs/dev/pts devpts defaults 0 0
|
280
|
-
sysfs $rootfs/sys sysfs defaults 0 0
|
281
|
-
EOF
|
282
|
-
|
283
|
-
if [ $? -ne 0 ]; then
|
284
|
-
echo "Failed to add configuration"
|
285
|
-
return 1
|
286
|
-
fi
|
287
|
-
|
288
|
-
return 0
|
289
|
-
}
|
290
|
-
|
291
|
-
clean()
|
292
|
-
{
|
293
|
-
cache="/var/cache/lxc/ubuntu"
|
294
|
-
|
295
|
-
if [ ! -e $cache ]; then
|
296
|
-
exit 0
|
297
|
-
fi
|
298
|
-
|
299
|
-
# lock, so we won't purge while someone is creating a repository
|
300
|
-
(
|
301
|
-
flock -n -x 200
|
302
|
-
if [ $? != 0 ]; then
|
303
|
-
echo "Cache repository is busy."
|
304
|
-
exit 1
|
305
|
-
fi
|
306
|
-
|
307
|
-
echo -n "Purging the download cache..."
|
308
|
-
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
|
309
|
-
exit 0
|
310
|
-
|
311
|
-
) 200>/var/lock/subsys/lxc
|
312
|
-
}
|
313
|
-
|
314
|
-
usage()
|
315
|
-
{
|
316
|
-
cat <<EOF
|
317
|
-
$1 -h|--help -p|--path=<path> --clean
|
318
|
-
EOF
|
319
|
-
return 0
|
320
|
-
}
|
321
|
-
|
322
|
-
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
|
323
|
-
if [ $? -ne 0 ]; then
|
324
|
-
usage $(basename $0)
|
325
|
-
exit 1
|
326
|
-
fi
|
327
|
-
eval set -- "$options"
|
328
|
-
|
329
|
-
while true
|
330
|
-
do
|
331
|
-
case "$1" in
|
332
|
-
-h|--help) usage $0 && exit 0;;
|
333
|
-
-p|--path) path=$2; shift 2;;
|
334
|
-
-n|--name) name=$2; shift 2;;
|
335
|
-
-c|--clean) clean=$2; shift 2;;
|
336
|
-
--) shift 1; break ;;
|
337
|
-
*) break ;;
|
338
|
-
esac
|
339
|
-
done
|
340
|
-
|
341
|
-
if [ ! -z "$clean" -a -z "$path" ]; then
|
342
|
-
clean || exit 1
|
343
|
-
exit 0
|
344
|
-
fi
|
345
|
-
|
346
|
-
type debootstrap
|
347
|
-
if [ $? -ne 0 ]; then
|
348
|
-
echo "'debootstrap' command is missing"
|
349
|
-
exit 1
|
350
|
-
fi
|
351
|
-
|
352
|
-
if [ -z "$path" ]; then
|
353
|
-
echo "'path' parameter is required"
|
354
|
-
exit 1
|
355
|
-
fi
|
356
|
-
|
357
|
-
if [ "$(id -u)" != "0" ]; then
|
358
|
-
echo "This script should be run as 'root'"
|
359
|
-
exit 1
|
360
|
-
fi
|
361
|
-
|
362
|
-
rootfs=$path/rootfs
|
363
|
-
|
364
|
-
install_ubuntu $rootfs
|
365
|
-
if [ $? -ne 0 ]; then
|
366
|
-
echo "failed to install ubuntu"
|
367
|
-
exit 1
|
368
|
-
fi
|
369
|
-
|
370
|
-
configure_ubuntu $rootfs $name
|
371
|
-
if [ $? -ne 0 ]; then
|
372
|
-
echo "failed to configure ubuntu for a container"
|
373
|
-
exit 1
|
374
|
-
fi
|
375
|
-
|
376
|
-
copy_configuration $path $rootfs $name
|
377
|
-
if [ $? -ne 0 ]; then
|
378
|
-
echo "failed write configuration file"
|
379
|
-
exit 1
|
380
|
-
fi
|
381
|
-
|
382
|
-
if [ ! -z $clean ]; then
|
383
|
-
clean || exit 1
|
384
|
-
exit 0
|
385
|
-
fi
|
data/lib/cucumber/chef/handy.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
module Cucumber
|
2
|
-
module Chef
|
3
|
-
module Handy
|
4
|
-
def create_server(server, ip)
|
5
|
-
create_network_config(server, ip)
|
6
|
-
create_container(server)
|
7
|
-
end
|
8
|
-
|
9
|
-
def create_network_config(name, ip)
|
10
|
-
network_config = File.join("/etc/lxc", name)
|
11
|
-
File.open(network_config, 'w') do |f|
|
12
|
-
f.puts "lxc.network.type = veth"
|
13
|
-
f.puts "lxc.network.flags = up"
|
14
|
-
f.puts "lxc.network.link = br0"
|
15
|
-
f.puts "lxc.network.name = eth0"
|
16
|
-
f.puts "lxc.network.ipv4 = #{ip}/24"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def create_container(name)
|
21
|
-
unless File.exists?("/var/lib/lxc/#{name}")
|
22
|
-
%x[lxc-create -n #{name} -f /etc/lxc/#{name} -t lucid-chef > /dev/null 2>&1 ]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def set_run_list(name, run_list)
|
27
|
-
rl = Hash.new
|
28
|
-
a = Array.new
|
29
|
-
a << run_list
|
30
|
-
rl['run_list'] = a
|
31
|
-
first_boot = File.join('/var/lib/lxc', name, 'rootfs/etc/chef/first-boot.json')
|
32
|
-
File.open(first_boot, 'w') do |f|
|
33
|
-
f.puts rl.to_json
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def run_chef_first_time(name)
|
38
|
-
%x[chroot /var/lib/lxc/#{name}/rootfs /bin/bash -c 'chef-client -j /etc/chef/first-boot.json > /dev/null 2>&1']
|
39
|
-
end
|
40
|
-
|
41
|
-
def run_chef(name)
|
42
|
-
container_path = "/var/lib/lxc/#{name}/rootfs"
|
43
|
-
%x[chroot #{container_path} /bin/bash -c 'chef-client > /dev/null 2>&1']
|
44
|
-
end
|
45
|
-
|
46
|
-
def databag_item_from_file(file)
|
47
|
-
::Chef::JSONCompat.from_json(File.read(file))
|
48
|
-
end
|
49
|
-
|
50
|
-
def upload_databag_item(databag, item)
|
51
|
-
::Chef::Config.from_file("/etc/chef/client.rb")
|
52
|
-
databag_item = ::Chef::DataBagItem.new
|
53
|
-
databag_item.data_bag(databag)
|
54
|
-
databag_item.raw_data = item
|
55
|
-
databag_item.save
|
56
|
-
end
|
57
|
-
|
58
|
-
def create_client_rb(orgname)
|
59
|
-
client_rb = File.join('/var/lib/lxc', name, 'rootfs/etc/chef/client.rb')
|
60
|
-
File.open(client_rb, 'w') do |f|
|
61
|
-
f.puts "log_level :info"
|
62
|
-
f.puts "log_location STDOUT"
|
63
|
-
f.puts "chef_server_url 'https://api.opscode.com/organizations/#{orgname}'"
|
64
|
-
f.puts "validation_client_name '#{orgname}-validator'"
|
65
|
-
f.puts "node_name 'cucumber-chef-#{name}'"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def start_container(name)
|
70
|
-
status = %x[lxc-info -n #{name} 2>&1]
|
71
|
-
if status.include?("STOPPED")
|
72
|
-
%x[lxc-start -d -n #{name}]
|
73
|
-
sleep 5
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def stop_container(name)
|
78
|
-
status = %x[lxc-info -n #{name} 2>&1]
|
79
|
-
if status.include?("RUNNING")
|
80
|
-
%x[lxc-destroy -d -n #{name}]
|
81
|
-
sleep 5
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def run_remote_command(remote_server, command)
|
86
|
-
%x[ssh workstation.testlab 'ssh #{remote_server} #{command}']
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
bash -c '
|
2
|
-
(
|
3
|
-
cat <<EOP
|
4
|
-
lxc.network.type = veth
|
5
|
-
lxc.network.flags = up
|
6
|
-
lxc.network.link = br0
|
7
|
-
lxc.network.name = eth0
|
8
|
-
lxc.network.ipv4 = 192.168.10.10/24
|
9
|
-
EOP
|
10
|
-
) > /etc/lxc/controller
|
11
|
-
|
12
|
-
lxc-create -n controller -f /etc/lxc/controller -t lucid-chef
|
13
|
-
|
14
|
-
(
|
15
|
-
cat <<EOP
|
16
|
-
|
17
|
-
log_level :info
|
18
|
-
log_location STDOUT
|
19
|
-
chef_server_url "<%= @config[:chef_server_url] %>"
|
20
|
-
validation_client_name "<%= @config[:validation_client_name] %>"
|
21
|
-
<% if @config[:chef_node_name] == nil %>
|
22
|
-
# Using default node name"
|
23
|
-
<% else %>
|
24
|
-
node_name "<%= @config[:chef_node_name] %>"
|
25
|
-
<% end %>
|
26
|
-
EOP
|
27
|
-
) > /var/lib/lxc/controller/rootfs/etc/chef/client.rb
|
28
|
-
|
29
|
-
cat <<EOP
|
30
|
-
{ "run_list": [ "recipe[cucumber-chef::controller]" ] }
|
31
|
-
EOP
|
32
|
-
) > /var/lib/lxc/controller/rootfs/etc/chef/first-boot.json
|
33
|
-
|
34
|
-
chroot /var/lib/lxc/controller/rootfs /bin/bash -c "chef-client -j /etc/chef/first-boot.json > /dev/null 2>&1"
|
35
|
-
lxc-start -d -n controller && sleep 5 && lxc-start -d -n controller'
|
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rspec/expectations'
|
4
|
-
require 'chef'
|
5
|
-
require 'cucumber/chef'
|
6
|
-
require 'cucumber/nagios/steps'
|
7
|
-
require 'cucumber/chef/handy'
|
8
|
-
|
9
|
-
class CustomWorld
|
10
|
-
include Cucumber::Chef
|
11
|
-
include Cucumber::Chef::Handy
|
12
|
-
end
|
13
|
-
|
14
|
-
World do
|
15
|
-
CustomWorld.new
|
16
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
Feature: Example feature for <%= @project %>
|
2
|
-
So that I can be learn how to use cucumber-chef
|
3
|
-
As an infrastructure developer
|
4
|
-
I can run an example feature that doesn't do much
|
5
|
-
|
6
|
-
Scenario: Example scenario for <%= @project %>
|
7
|
-
Given I have a remote server
|
8
|
-
And I apply the <%= @project %> role/recipe
|
9
|
-
And run Chef
|
10
|
-
When I connect to the remote server from the test server
|
11
|
-
Then the <% @project %> server behaves as it should
|
@@ -1,19 +0,0 @@
|
|
1
|
-
Given /^I have a remote server$/ do
|
2
|
-
pending # express the regexp above with the code you wish you had
|
3
|
-
end
|
4
|
-
|
5
|
-
Given /^I apply the <%= @project %> role\/recipe$/ do
|
6
|
-
pending # express the regexp above with the code you wish you had
|
7
|
-
end
|
8
|
-
|
9
|
-
Given /^run Chef$/ do
|
10
|
-
pending # express the regexp above with the code you wish you had
|
11
|
-
end
|
12
|
-
|
13
|
-
When /^I connect to the remote server from the test server$/ do
|
14
|
-
pending # express the regexp above with the code you wish you had
|
15
|
-
end
|
16
|
-
|
17
|
-
Then /^the <%= @project %> server behaves as it should$/ do
|
18
|
-
pending # express the regexp above with the code you wish you had
|
19
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
Welcome to the <%= @project %> suite of cucumber-chef tests
|
2
|
-
|
3
|
-
Your general workflow will be to write cucumber features that describe the intended behaviour of '<%= @project %>'. You will then write failing tests by writing steps to test the behaviour, expressing them as cucumer scenarios.
|
4
|
-
|
5
|
-
You will then want to create a '<%= @project %>' cookbook, and write recipes that make your tests pass. Upload your cookbook to the Opscode Platform, and then run the tests with:
|
6
|
-
|
7
|
-
Then run your tests with:
|
8
|
-
|
9
|
-
cucumber-chef test <%= @project %>
|
10
|
-
|
11
|
-
For an example feature, take a look at ./<%= @project %>/features/example.feature
|
12
|
-
|
13
|
-
For an example step definition, look at ./<%= @project %>/features/example.feature
|
14
|
-
|
@@ -1,43 +0,0 @@
|
|
1
|
-
bash -c '
|
2
|
-
if [ ! -f /usr/bin/chef-client ]; then
|
3
|
-
apt-get update
|
4
|
-
apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
|
5
|
-
cd /tmp
|
6
|
-
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
|
7
|
-
tar zxf rubygems-1.3.7.tgz
|
8
|
-
cd rubygems-1.3.7
|
9
|
-
ruby setup.rb --no-format-executable
|
10
|
-
fi
|
11
|
-
gem install ohai chef --no-rdoc --no-ri --verbose <%= '--prerelease' if @config[:prerelease] %>
|
12
|
-
|
13
|
-
mkdir -p /etc/chef
|
14
|
-
|
15
|
-
(
|
16
|
-
cat <<'EOP'
|
17
|
-
<%= IO.read(@config[:validation_key]) %>
|
18
|
-
EOP
|
19
|
-
) > /tmp/validation.pem
|
20
|
-
awk NF /tmp/validation.pem > /etc/chef/validation.pem
|
21
|
-
rm /tmp/validation.pem
|
22
|
-
|
23
|
-
(
|
24
|
-
cat <<'EOP'
|
25
|
-
log_level :info
|
26
|
-
log_location STDOUT
|
27
|
-
chef_server_url "<%= @config[:chef_server_url] %>"
|
28
|
-
validation_client_name "<%= @config[:validation_client_name] %>"
|
29
|
-
<% if @config[:chef_node_name] == nil %>
|
30
|
-
# Using default node name"
|
31
|
-
<% else %>
|
32
|
-
node_name "<%= @config[:chef_node_name] %>"
|
33
|
-
<% end %>
|
34
|
-
EOP
|
35
|
-
) > /etc/chef/client.rb
|
36
|
-
|
37
|
-
(
|
38
|
-
cat <<'EOP'
|
39
|
-
<%= { "run_list" => @run_list }.to_json %>
|
40
|
-
EOP
|
41
|
-
) > /etc/chef/first-boot.json
|
42
|
-
|
43
|
-
/usr/bin/chef-client -j /etc/chef/first-boot.json'
|