toft 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +6 -1
- data/Rakefile +93 -4
- data/features/checker.feature +2 -2
- data/features/chef.feature +23 -5
- data/features/command.feature +4 -3
- data/features/node.feature +21 -6
- data/features/step_definitions/chef.rb +11 -3
- data/features/step_definitions/command.rb +1 -3
- data/features/step_definitions/node.rb +19 -3
- data/features/support/env.rb +6 -3
- data/fixtures/chef/attributes.json +9 -0
- data/lib/toft/chef/chef_attributes.rb +2 -2
- data/lib/toft/chef/chef_runner.rb +17 -4
- data/lib/toft/node.rb +64 -20
- data/lib/toft/node_controller.rb +2 -2
- data/lib/toft/version.rb +1 -1
- data/lib/toft.rb +5 -2
- data/scripts/bin/centos/lxc-prepare-host +175 -0
- data/scripts/{ubuntu/bin → bin/share}/install-chef-ubuntu.sh +0 -0
- data/scripts/{ubuntu/bin → bin/share}/install-rvm.sh +0 -0
- data/scripts/{ubuntu/bin → bin/share}/lxc-create-centos-image +6 -5
- data/scripts/{ubuntu/bin → bin/ubuntu}/lxc-create-ubuntu-image +3 -3
- data/scripts/bin/ubuntu/lxc-prepare-host +190 -0
- data/scripts/cookbooks/lxc/recipes/default.rb +8 -14
- data/scripts/{ubuntu/lxc-templates → cookbooks/lxc/templates/default}/lxc-centos-6 +7 -3
- data/scripts/cookbooks/lxc/templates/default/{lxc-lucid-chef → lxc-lucid} +2 -2
- data/scripts/cookbooks/lxc/templates/default/{lxc-natty-chef → lxc-natty} +2 -2
- data/scripts/lxc-templates/files/rc.local +38 -0
- data/scripts/lxc-templates/lxc-centos-6 +279 -0
- data/scripts/{ubuntu/lxc-templates → lxc-templates}/lxc-lucid +3 -12
- data/scripts/{ubuntu/lxc-templates → lxc-templates}/lxc-natty +51 -61
- data/spec/fixtures/illegal_syntax.json +1 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/tuft/chef_attributes_spec.rb +6 -0
- data/spec/tuft/chef_runner_spec.rb +34 -0
- metadata +55 -21
- data/scripts/centos/bin/lxc-prepare-host +0 -39
- data/scripts/cookbooks/lxc/files/default/lxc-create-ubuntu-image +0 -75
- data/scripts/ubuntu/bin/lxc-prepare-host +0 -24
@@ -0,0 +1,279 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
echo "Creating centos-6 node..."
|
4
|
+
|
5
|
+
configure_centos()
|
6
|
+
{
|
7
|
+
rootfs=$1
|
8
|
+
hostname=$2
|
9
|
+
|
10
|
+
# disable selinux in centos
|
11
|
+
mkdir -p $rootfs/selinux
|
12
|
+
echo 0 > $rootfs/selinux/enforce
|
13
|
+
|
14
|
+
# add host root ssh access
|
15
|
+
mkdir $rootfs/root/.ssh
|
16
|
+
chmod 0600 $rootfs/root/.ssh
|
17
|
+
cat <<-EOF > $rootfs/root/.ssh/authorized_keys
|
18
|
+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCguB7XL3ARzLZYLsIMZe4UUO371m+H5C6V8MhtmSlgXtgHDo7eZhNSm5zCeoyGd32OKeLxuxCCEkXfDDF1aa2a6twcASE3pmWNdnBS7auiOH4P7g+eQ4Aw9v7DdESbIVgHF/NDiAEFFdmApYNM3oCX2FhEVNVKxkkIokUr4axYFJzmJ6Xoi5Sd8JtPC85FZVXqDucZDnHQlOcCkbSo0UOmsWQGwtu8eUHoDeUG0dB8ntb9xlBeLctdrAPhuFYCX8IfFkdcakkzv61ETPbKE6g9wdTDC/TEep7/AHGYmarziRnwKiVOL1jnE1coOJLqy8wOC3dKGmRZy9D4sTc+FRV root insecure public key
|
19
|
+
EOF
|
20
|
+
|
21
|
+
cp /usr/lib/lxc/templates/files/rc.local $rootfs/etc/rc.local
|
22
|
+
|
23
|
+
# set the hostname
|
24
|
+
cat <<EOF > $rootfs/etc/hostname
|
25
|
+
$hostname
|
26
|
+
EOF
|
27
|
+
# set minimal hosts
|
28
|
+
cat <<EOF > $rootfs/etc/hosts
|
29
|
+
127.0.0.1 localhost $hostname
|
30
|
+
EOF
|
31
|
+
|
32
|
+
cat <<EOF > $rootfs/etc/init/console.conf
|
33
|
+
# console - mingetty
|
34
|
+
#
|
35
|
+
# This service maintains a console on tty1 from the point the system is
|
36
|
+
# started until it is shut down again.
|
37
|
+
|
38
|
+
start on stopped rc RUNLEVEL=[2345]
|
39
|
+
stop on runlevel [!2345]
|
40
|
+
|
41
|
+
respawn
|
42
|
+
exec /sbin/mingetty console
|
43
|
+
EOF
|
44
|
+
|
45
|
+
cat <<EOF > $rootfs/etc/fstab
|
46
|
+
none /dev/pts devpts defaults 0 0
|
47
|
+
EOF
|
48
|
+
|
49
|
+
[ ! -f $rootfs/etc/init/kexec-disable.conf ] || mv $rootfs/etc/init/kexec-disable.conf $rootfs/etc/init/kexec-disable.conf.orig
|
50
|
+
sed -i -e 's:/sbin/start_udev:#/sbin/start_udev:' $rootfs/etc/rc.d/rc.sysinit
|
51
|
+
|
52
|
+
sed -i -e 's:\(Defaults *requiretty\):# \1:' $rootfs/etc/sudoers
|
53
|
+
|
54
|
+
# create necessary devices
|
55
|
+
rm $rootfs/dev/null
|
56
|
+
mknod -m 666 $rootfs/dev/null c 1 3
|
57
|
+
mknod -m 666 $rootfs/dev/random c 1 8
|
58
|
+
mknod -m 666 $rootfs/dev/urandom c 1 9
|
59
|
+
mkdir -m 755 $rootfs/dev/pts
|
60
|
+
mknod -m 666 $rootfs/dev/tty c 5 0
|
61
|
+
mknod -m 666 $rootfs/dev/tty0 c 4 0
|
62
|
+
mknod -m 666 $rootfs/dev/tty1 c 4 1
|
63
|
+
mknod -m 666 $rootfs/dev/tty2 c 4 2
|
64
|
+
mknod -m 666 $rootfs/dev/tty3 c 4 3
|
65
|
+
mknod -m 666 $rootfs/dev/tty4 c 4 4
|
66
|
+
mknod -m 600 $rootfs/dev/console c 5 1
|
67
|
+
mknod -m 666 $rootfs/dev/full c 1 7
|
68
|
+
mknod -m 600 $rootfs/dev/initctl p
|
69
|
+
|
70
|
+
# change root password
|
71
|
+
echo "Set root password to 'root'"
|
72
|
+
echo "root:root" | chroot $rootfs chpasswd
|
73
|
+
|
74
|
+
return 0
|
75
|
+
}
|
76
|
+
|
77
|
+
copy_centos()
|
78
|
+
{
|
79
|
+
cache=$1
|
80
|
+
arch=$2
|
81
|
+
rootfs=$3
|
82
|
+
|
83
|
+
# make a local copy of the minicentos
|
84
|
+
echo "Extracting rootfs image to $rootfs ..."
|
85
|
+
mkdir $rootfs
|
86
|
+
tar zxf $cache/centos-6-$arch.tar.gz -C $rootfs || return 1
|
87
|
+
return 0
|
88
|
+
}
|
89
|
+
|
90
|
+
install_centos()
|
91
|
+
{
|
92
|
+
cache="/var/cache/lxc"
|
93
|
+
rootfs=$1
|
94
|
+
mkdir -p /var/lock/subsys/
|
95
|
+
(
|
96
|
+
flock -n -x 200
|
97
|
+
if [ $? -ne 0 ]; then
|
98
|
+
echo "Cache repository is busy."
|
99
|
+
return 1
|
100
|
+
fi
|
101
|
+
|
102
|
+
arch=$(arch)
|
103
|
+
if [ "$arch" == "x86_64" ]; then
|
104
|
+
arch=amd64
|
105
|
+
fi
|
106
|
+
|
107
|
+
if [ "$arch" == "i686" ]; then
|
108
|
+
arch=i386
|
109
|
+
fi
|
110
|
+
|
111
|
+
echo "Checking image cache in $cache/rootfs-$arch ... "
|
112
|
+
if [ ! -e "$cache/rootfs-$arch" ]; then
|
113
|
+
if [ $? -ne 0 ]; then
|
114
|
+
echo "Failed to download 'centos base'"
|
115
|
+
return 1
|
116
|
+
fi
|
117
|
+
fi
|
118
|
+
|
119
|
+
copy_centos $cache $arch $rootfs
|
120
|
+
if [ $? -ne 0 ]; then
|
121
|
+
echo "Failed to copy rootfs"
|
122
|
+
return 1
|
123
|
+
fi
|
124
|
+
|
125
|
+
return 0
|
126
|
+
|
127
|
+
) 200>/var/lock/subsys/lxc
|
128
|
+
|
129
|
+
return $?
|
130
|
+
}
|
131
|
+
|
132
|
+
copy_configuration()
|
133
|
+
{
|
134
|
+
path=$1
|
135
|
+
rootfs=$2
|
136
|
+
name=$3
|
137
|
+
|
138
|
+
cat <<EOF >> $path/config
|
139
|
+
lxc.utsname = $name
|
140
|
+
|
141
|
+
lxc.tty = 4
|
142
|
+
lxc.pts = 1024
|
143
|
+
lxc.rootfs = $rootfs
|
144
|
+
lxc.mount = $path/fstab
|
145
|
+
|
146
|
+
lxc.cgroup.devices.deny = a
|
147
|
+
|
148
|
+
lxc.cgroup.devices.allow = b 1:0 rwm
|
149
|
+
lxc.cgroup.devices.allow = b 1:1 rwm
|
150
|
+
lxc.cgroup.devices.allow = c 1:1 rwm
|
151
|
+
lxc.cgroup.devices.allow = c 1:2 rwm
|
152
|
+
lxc.cgroup.devices.allow = c 1:4 rwm
|
153
|
+
lxc.cgroup.devices.allow = c 1:6 rwm
|
154
|
+
lxc.cgroup.devices.allow = c 1:7 rwm
|
155
|
+
lxc.cgroup.devices.allow = c 1:11 rwm
|
156
|
+
|
157
|
+
lxc.cgroup.devices.allow = c 2:* rwm
|
158
|
+
lxc.cgroup.devices.allow = c 3:* rwm
|
159
|
+
|
160
|
+
# /dev/null and zero
|
161
|
+
lxc.cgroup.devices.allow = c 1:3 rwm
|
162
|
+
lxc.cgroup.devices.allow = c 1:5 rwm
|
163
|
+
# consoles
|
164
|
+
lxc.cgroup.devices.allow = c 5:1 rwm
|
165
|
+
lxc.cgroup.devices.allow = c 5:0 rwm
|
166
|
+
lxc.cgroup.devices.allow = c 4:0 rwm
|
167
|
+
lxc.cgroup.devices.allow = c 4:1 rwm
|
168
|
+
# /dev/{,u}random
|
169
|
+
lxc.cgroup.devices.allow = c 1:9 rwm
|
170
|
+
lxc.cgroup.devices.allow = c 1:8 rwm
|
171
|
+
lxc.cgroup.devices.allow = c 136:* rwm
|
172
|
+
lxc.cgroup.devices.allow = c 5:2 rwm
|
173
|
+
# rtc
|
174
|
+
lxc.cgroup.devices.allow = c 254:0 rwm
|
175
|
+
EOF
|
176
|
+
|
177
|
+
cat <<EOF > $path/fstab
|
178
|
+
proc $rootfs/proc proc nodev,noexec,nosuid 0 0
|
179
|
+
devpts $rootfs/dev/pts devpts defaults 0 0
|
180
|
+
sysfs $rootfs/sys sysfs defaults 0 0
|
181
|
+
EOF
|
182
|
+
|
183
|
+
if [ $? -ne 0 ]; then
|
184
|
+
echo "Failed to add configuration"
|
185
|
+
return 1
|
186
|
+
fi
|
187
|
+
|
188
|
+
return 0
|
189
|
+
}
|
190
|
+
|
191
|
+
clean()
|
192
|
+
{
|
193
|
+
cache="/var/cache/lxc"
|
194
|
+
|
195
|
+
if [ ! -e $cache ]; then
|
196
|
+
exit 0
|
197
|
+
fi
|
198
|
+
|
199
|
+
# lock, so we won't purge while someone is creating a repository
|
200
|
+
(
|
201
|
+
flock -n -x 200
|
202
|
+
if [ $? != 0 ]; then
|
203
|
+
echo "Cache repository is busy."
|
204
|
+
exit 1
|
205
|
+
fi
|
206
|
+
|
207
|
+
echo -n "Purging the download cache..."
|
208
|
+
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
|
209
|
+
exit 0
|
210
|
+
|
211
|
+
) 200>/var/lock/subsys/lxc
|
212
|
+
}
|
213
|
+
|
214
|
+
usage()
|
215
|
+
{
|
216
|
+
cat <<EOF
|
217
|
+
$1 -h|--help -p|--path=<path> --clean
|
218
|
+
EOF
|
219
|
+
return 0
|
220
|
+
}
|
221
|
+
|
222
|
+
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
|
223
|
+
if [ $? -ne 0 ]; then
|
224
|
+
usage $(basename $0)
|
225
|
+
exit 1
|
226
|
+
fi
|
227
|
+
eval set -- "$options"
|
228
|
+
|
229
|
+
while true
|
230
|
+
do
|
231
|
+
case "$1" in
|
232
|
+
-h|--help) usage $0 && exit 0;;
|
233
|
+
-p|--path) path=$2; shift 2;;
|
234
|
+
-n|--name) name=$2; shift 2;;
|
235
|
+
-c|--clean) clean=$2; shift 2;;
|
236
|
+
--) shift 1; break ;;
|
237
|
+
*) break ;;
|
238
|
+
esac
|
239
|
+
done
|
240
|
+
|
241
|
+
if [ ! -z "$clean" -a -z "$path" ]; then
|
242
|
+
clean || exit 1
|
243
|
+
exit 0
|
244
|
+
fi
|
245
|
+
|
246
|
+
if [ -z "$path" ]; then
|
247
|
+
echo "'path' parameter is required"
|
248
|
+
exit 1
|
249
|
+
fi
|
250
|
+
|
251
|
+
if [ "$(id -u)" != "0" ]; then
|
252
|
+
echo "This script should be run as 'root'"
|
253
|
+
exit 1
|
254
|
+
fi
|
255
|
+
|
256
|
+
rootfs=$path/rootfs
|
257
|
+
|
258
|
+
install_centos $rootfs
|
259
|
+
if [ $? -ne 0 ]; then
|
260
|
+
echo "failed to install centos"
|
261
|
+
exit 1
|
262
|
+
fi
|
263
|
+
|
264
|
+
configure_centos $rootfs $name
|
265
|
+
if [ $? -ne 0 ]; then
|
266
|
+
echo "failed to configure centos for a container"
|
267
|
+
exit 1
|
268
|
+
fi
|
269
|
+
|
270
|
+
copy_configuration $path $rootfs $name
|
271
|
+
if [ $? -ne 0 ]; then
|
272
|
+
echo "failed write configuration file"
|
273
|
+
exit 1
|
274
|
+
fi
|
275
|
+
|
276
|
+
if [ ! -z $clean ]; then
|
277
|
+
clean || exit 1
|
278
|
+
exit 0
|
279
|
+
fi
|
@@ -18,16 +18,7 @@ configure_ubuntu()
|
|
18
18
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCguB7XL3ARzLZYLsIMZe4UUO371m+H5C6V8MhtmSlgXtgHDo7eZhNSm5zCeoyGd32OKeLxuxCCEkXfDDF1aa2a6twcASE3pmWNdnBS7auiOH4P7g+eQ4Aw9v7DdESbIVgHF/NDiAEFFdmApYNM3oCX2FhEVNVKxkkIokUr4axYFJzmJ6Xoi5Sd8JtPC85FZVXqDucZDnHQlOcCkbSo0UOmsWQGwtu8eUHoDeUG0dB8ntb9xlBeLctdrAPhuFYCX8IfFkdcakkzv61ETPbKE6g9wdTDC/TEep7/AHGYmarziRnwKiVOL1jnE1coOJLqy8wOC3dKGmRZy9D4sTc+FRV root insecure public key
|
19
19
|
EOF
|
20
20
|
|
21
|
-
|
22
|
-
rm $rootfs/etc/resolv.conf
|
23
|
-
cp /etc/resolv.conf $rootfs/etc/resolv.conf
|
24
|
-
|
25
|
-
# add default route to host
|
26
|
-
cat <<EOF > $rootfs/etc/rc.local
|
27
|
-
#!/bin/sh -e
|
28
|
-
route add default gw 192.168.20.1
|
29
|
-
exit 0
|
30
|
-
EOF
|
21
|
+
cp /usr/lib/lxc/templates/files/rc.local $rootfs/etc/rc.local
|
31
22
|
|
32
23
|
# disable selinux in ubuntu
|
33
24
|
mkdir -p $rootfs/selinux
|
@@ -149,7 +140,7 @@ copy_ubuntu()
|
|
149
140
|
|
150
141
|
install_ubuntu()
|
151
142
|
{
|
152
|
-
cache="/var/cache/lxc
|
143
|
+
cache="/var/cache/lxc"
|
153
144
|
rootfs=$1
|
154
145
|
mkdir -p /var/lock/subsys/
|
155
146
|
(
|
@@ -237,7 +228,7 @@ EOF
|
|
237
228
|
|
238
229
|
clean()
|
239
230
|
{
|
240
|
-
cache="/var/cache/lxc
|
231
|
+
cache="/var/cache/lxc"
|
241
232
|
|
242
233
|
if [ ! -e $cache ]; then
|
243
234
|
exit 0
|
@@ -16,18 +16,9 @@ configure_ubuntu()
|
|
16
16
|
chmod 0600 $rootfs/root/.ssh
|
17
17
|
cat <<-EOF > $rootfs/root/.ssh/authorized_keys
|
18
18
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCguB7XL3ARzLZYLsIMZe4UUO371m+H5C6V8MhtmSlgXtgHDo7eZhNSm5zCeoyGd32OKeLxuxCCEkXfDDF1aa2a6twcASE3pmWNdnBS7auiOH4P7g+eQ4Aw9v7DdESbIVgHF/NDiAEFFdmApYNM3oCX2FhEVNVKxkkIokUr4axYFJzmJ6Xoi5Sd8JtPC85FZVXqDucZDnHQlOcCkbSo0UOmsWQGwtu8eUHoDeUG0dB8ntb9xlBeLctdrAPhuFYCX8IfFkdcakkzv61ETPbKE6g9wdTDC/TEep7/AHGYmarziRnwKiVOL1jnE1coOJLqy8wOC3dKGmRZy9D4sTc+FRV root insecure public key
|
19
|
-
EOF
|
20
|
-
|
21
|
-
# copy host resolve
|
22
|
-
rm $rootfs/etc/resolv.conf
|
23
|
-
cp /etc/resolv.conf $rootfs/etc/resolv.conf
|
24
|
-
|
25
|
-
# add default route to host
|
26
|
-
cat <<EOF > $rootfs/etc/rc.local
|
27
|
-
#!/bin/sh -e
|
28
|
-
route add default gw 192.168.20.1
|
29
|
-
exit 0
|
30
19
|
EOF
|
20
|
+
|
21
|
+
cp /usr/lib/lxc/templates/files/rc.local $rootfs/etc/rc.local
|
31
22
|
|
32
23
|
# disable selinux in ubuntu
|
33
24
|
mkdir -p $rootfs/selinux
|
@@ -39,7 +30,7 @@ $hostname
|
|
39
30
|
EOF
|
40
31
|
# set minimal hosts
|
41
32
|
cat <<EOF > $rootfs/etc/hosts
|
42
|
-
127.0.0.1
|
33
|
+
127.0.0.1 $hostname localhost
|
43
34
|
EOF
|
44
35
|
|
45
36
|
# suppress log level output for udev
|
@@ -70,40 +61,40 @@ copy_ubuntu()
|
|
70
61
|
|
71
62
|
install_ubuntu()
|
72
63
|
{
|
73
|
-
cache="/var/cache/lxc
|
64
|
+
cache="/var/cache/lxc"
|
74
65
|
rootfs=$1
|
75
66
|
mkdir -p /var/lock/subsys/
|
76
67
|
(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
68
|
+
flock -n -x 200
|
69
|
+
if [ $? -ne 0 ]; then
|
70
|
+
echo "Cache repository is busy."
|
71
|
+
return 1
|
72
|
+
fi
|
73
|
+
|
74
|
+
arch=$(arch)
|
75
|
+
if [ "$arch" == "x86_64" ]; then
|
76
|
+
arch=amd64
|
77
|
+
fi
|
78
|
+
|
79
|
+
if [ "$arch" == "i686" ]; then
|
80
|
+
arch=i386
|
81
|
+
fi
|
82
|
+
|
83
|
+
echo "Checking image cache in $cache/rootfs-$arch ... "
|
84
|
+
if [ ! -e "$cache/rootfs-$arch" ]; then
|
85
|
+
if [ $? -ne 0 ]; then
|
86
|
+
echo "Failed to download 'ubuntu base'"
|
87
|
+
return 1
|
88
|
+
fi
|
89
|
+
fi
|
90
|
+
|
91
|
+
copy_ubuntu $cache $arch $rootfs
|
92
|
+
if [ $? -ne 0 ]; then
|
93
|
+
echo "Failed to copy rootfs"
|
94
|
+
return 1
|
95
|
+
fi
|
96
|
+
|
97
|
+
return 0
|
107
98
|
|
108
99
|
) 200>/var/lock/subsys/lxc
|
109
100
|
|
@@ -149,8 +140,8 @@ sysfs $rootfs/sys sysfs defaults 0 0
|
|
149
140
|
EOF
|
150
141
|
|
151
142
|
if [ $? -ne 0 ]; then
|
152
|
-
|
153
|
-
|
143
|
+
echo "Failed to add configuration"
|
144
|
+
return 1
|
154
145
|
fi
|
155
146
|
|
156
147
|
return 0
|
@@ -158,7 +149,7 @@ EOF
|
|
158
149
|
|
159
150
|
clean()
|
160
151
|
{
|
161
|
-
cache="/var/cache/lxc
|
152
|
+
cache="/var/cache/lxc"
|
162
153
|
|
163
154
|
if [ ! -e $cache ]; then
|
164
155
|
exit 0
|
@@ -166,16 +157,15 @@ clean()
|
|
166
157
|
|
167
158
|
# lock, so we won't purge while someone is creating a repository
|
168
159
|
(
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
160
|
+
flock -n -x 200
|
161
|
+
if [ $? != 0 ]; then
|
162
|
+
echo "Cache repository is busy."
|
163
|
+
exit 1
|
164
|
+
fi
|
165
|
+
|
166
|
+
echo -n "Purging the download cache..."
|
167
|
+
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
|
168
|
+
exit 0
|
179
169
|
) 200>/var/lock/subsys/lxc
|
180
170
|
}
|
181
171
|
|
@@ -197,11 +187,11 @@ eval set -- "$options"
|
|
197
187
|
while true
|
198
188
|
do
|
199
189
|
case "$1" in
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
190
|
+
-h|--help) usage $0 && exit 0;;
|
191
|
+
-p|--path) path=$2; shift 2;;
|
192
|
+
-n|--name) name=$2; shift 2;;
|
193
|
+
-c|--clean) clean=$2; shift 2;;
|
194
|
+
--) shift 1; break ;;
|
205
195
|
*) break ;;
|
206
196
|
esac
|
207
197
|
done
|
@@ -0,0 +1 @@
|
|
1
|
+
illegal json file
|
data/spec/spec_helper.rb
CHANGED
@@ -30,4 +30,10 @@ describe "ChefAttributes" do
|
|
30
30
|
ca = Toft::ChefAttributes.new(table)
|
31
31
|
ca.to_json.should == "{\"one\":{\"two\":{\"three\":\"some\"},\"four\":\"one\"}}"
|
32
32
|
end
|
33
|
+
|
34
|
+
it "should initialize with 0 parameter" do
|
35
|
+
ca = Toft::ChefAttributes.new
|
36
|
+
ca.add_attribute "one.four", "one"
|
37
|
+
ca.attributes["one"]["four"].should == "one"
|
38
|
+
end
|
33
39
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "ChefRunner" do
|
4
|
+
it "should throw exception if json file not exist" do
|
5
|
+
cf = Toft::Chef::ChefRunner.new "whatever"
|
6
|
+
lambda { cf.run "run list", :json => "non-exist-file" }.
|
7
|
+
should raise_error Errno::ENOENT, "No such file or directory - non-exist-file"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should throw exception if json file syntax is illegal" do
|
11
|
+
cf = Toft::Chef::ChefRunner.new "whatever"
|
12
|
+
lambda { cf.run "run list", :json => "#{PROJECT_ROOT}/spec/fixtures/illegal_syntax.json" }.
|
13
|
+
should raise_error JSON::ParserError
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should throw exception if cookbook path not set" do
|
17
|
+
cf = Toft::Chef::ChefRunner.new "whatever"
|
18
|
+
lambda { cf.run "run list" }.should raise_error ArgumentError, "Toft.cookbook_path can not be empty!"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should throw exception if cookbook not exist" do
|
22
|
+
Toft.cookbook_path = "non-exist-cookbook"
|
23
|
+
cf = Toft::Chef::ChefRunner.new "whatever"
|
24
|
+
lambda { cf.run "run list" }.should raise_error RuntimeError
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should throw exception if roles not exist" do
|
28
|
+
Toft.cookbook_path = "#{PROJECT_ROOT}/fixtures/chef/cookbookse"
|
29
|
+
Toft.role_path = "non-exist-roles"
|
30
|
+
cf = Toft::Chef::ChefRunner.new "#{PROJECT_ROOT}/tmp"
|
31
|
+
lambda { cf.run "run list" }.should raise_error RuntimeError
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Huang Liang
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
type: :development
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
35
|
+
name: fpm
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
@@ -46,9 +46,37 @@ dependencies:
|
|
46
46
|
type: :development
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: rake
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: cucumber
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: vagrant
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
52
80
|
none: false
|
53
81
|
requirements:
|
54
82
|
- - ">="
|
@@ -60,11 +88,11 @@ dependencies:
|
|
60
88
|
- 7
|
61
89
|
version: 0.8.7
|
62
90
|
type: :development
|
63
|
-
version_requirements: *
|
91
|
+
version_requirements: *id005
|
64
92
|
- !ruby/object:Gem::Dependency
|
65
93
|
name: net-ssh
|
66
94
|
prerelease: false
|
67
|
-
requirement: &
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
68
96
|
none: false
|
69
97
|
requirements:
|
70
98
|
- - ">="
|
@@ -74,7 +102,7 @@ dependencies:
|
|
74
102
|
- 0
|
75
103
|
version: "0"
|
76
104
|
type: :runtime
|
77
|
-
version_requirements: *
|
105
|
+
version_requirements: *id006
|
78
106
|
description: toft currently support testing chef, shell scripts using cucumber on lxc on ubuntu
|
79
107
|
email:
|
80
108
|
- exceedhl@gmail.com
|
@@ -97,6 +125,7 @@ files:
|
|
97
125
|
- features/step_definitions/command.rb
|
98
126
|
- features/step_definitions/node.rb
|
99
127
|
- features/support/env.rb
|
128
|
+
- fixtures/chef/attributes.json
|
100
129
|
- fixtures/chef/cookbooks/test/attributes/default.rb
|
101
130
|
- fixtures/chef/cookbooks/test/recipes/attribute.rb
|
102
131
|
- fixtures/chef/cookbooks/test/recipes/default.rb
|
@@ -109,22 +138,25 @@ files:
|
|
109
138
|
- lib/toft/node.rb
|
110
139
|
- lib/toft/node_controller.rb
|
111
140
|
- lib/toft/version.rb
|
112
|
-
- scripts/centos/
|
141
|
+
- scripts/bin/centos/lxc-prepare-host
|
142
|
+
- scripts/bin/share/install-chef-ubuntu.sh
|
143
|
+
- scripts/bin/share/install-rvm.sh
|
144
|
+
- scripts/bin/share/lxc-create-centos-image
|
145
|
+
- scripts/bin/ubuntu/lxc-create-ubuntu-image
|
146
|
+
- scripts/bin/ubuntu/lxc-prepare-host
|
113
147
|
- scripts/cookbooks/lxc/attributes/default.rb
|
114
|
-
- scripts/cookbooks/lxc/files/default/lxc-create-ubuntu-image
|
115
148
|
- scripts/cookbooks/lxc/recipes/default.rb
|
116
|
-
- scripts/cookbooks/lxc/templates/default/lxc-
|
117
|
-
- scripts/cookbooks/lxc/templates/default/lxc-
|
118
|
-
- scripts/
|
119
|
-
- scripts/
|
120
|
-
- scripts/
|
121
|
-
- scripts/
|
122
|
-
- scripts/
|
123
|
-
-
|
124
|
-
- scripts/ubuntu/lxc-templates/lxc-lucid
|
125
|
-
- scripts/ubuntu/lxc-templates/lxc-natty
|
149
|
+
- scripts/cookbooks/lxc/templates/default/lxc-centos-6
|
150
|
+
- scripts/cookbooks/lxc/templates/default/lxc-lucid
|
151
|
+
- scripts/cookbooks/lxc/templates/default/lxc-natty
|
152
|
+
- scripts/lxc-templates/files/rc.local
|
153
|
+
- scripts/lxc-templates/lxc-centos-6
|
154
|
+
- scripts/lxc-templates/lxc-lucid
|
155
|
+
- scripts/lxc-templates/lxc-natty
|
156
|
+
- spec/fixtures/illegal_syntax.json
|
126
157
|
- spec/spec_helper.rb
|
127
158
|
- spec/tuft/chef_attributes_spec.rb
|
159
|
+
- spec/tuft/chef_runner_spec.rb
|
128
160
|
homepage: https://github.com/exceedhl/toft
|
129
161
|
licenses: []
|
130
162
|
|
@@ -168,5 +200,7 @@ test_files:
|
|
168
200
|
- features/step_definitions/command.rb
|
169
201
|
- features/step_definitions/node.rb
|
170
202
|
- features/support/env.rb
|
203
|
+
- spec/fixtures/illegal_syntax.json
|
171
204
|
- spec/spec_helper.rb
|
172
205
|
- spec/tuft/chef_attributes_spec.rb
|
206
|
+
- spec/tuft/chef_runner_spec.rb
|