toft 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/Rakefile +9 -9
- data/features/command.feature +1 -1
- data/features/step_definitions/command.rb +11 -2
- data/features/step_definitions/node.rb +1 -1
- data/features/support/env.rb +1 -1
- data/lib/toft/node.rb +44 -17
- data/lib/toft/version.rb +1 -1
- data/scripts/bin/centos/lxc-prepare-host +3 -3
- data/scripts/bin/ubuntu/lxc-prepare-host +2 -0
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -16,16 +16,16 @@ task :package_deb do
|
|
16
16
|
src_dir = "#{PROJECT_ROOT}/scripts"
|
17
17
|
content_dir = "#{PROJECT_ROOT}/pkg/#{LXC_PACKAGE_NAME}"
|
18
18
|
mkdir_p content_dir
|
19
|
-
mkdir_p "#{content_dir}/usr/
|
19
|
+
mkdir_p "#{content_dir}/usr/bin"
|
20
20
|
mkdir_p "#{content_dir}/var/cache/lxc"
|
21
21
|
mkdir_p "#{content_dir}/usr/lib/lxc/templates"
|
22
|
-
cp_r Dir.glob("#{src_dir}/bin/share/*"), "#{content_dir}/usr/
|
23
|
-
cp_r Dir.glob("#{src_dir}/bin/ubuntu/*"), "#{content_dir}/usr/
|
22
|
+
cp_r Dir.glob("#{src_dir}/bin/share/*"), "#{content_dir}/usr/bin"
|
23
|
+
cp_r Dir.glob("#{src_dir}/bin/ubuntu/*"), "#{content_dir}/usr/bin"
|
24
24
|
cp_r Dir.glob("#{src_dir}/lxc-templates/*"), "#{content_dir}/usr/lib/lxc/templates"
|
25
25
|
|
26
26
|
post_install_script = <<-eos
|
27
27
|
#!/bin/sh -e
|
28
|
-
/usr/
|
28
|
+
/usr/bin/lxc-prepare-host
|
29
29
|
eos
|
30
30
|
File.open("#{PROJECT_ROOT}/pkg/toft-lxc-post-install.sh", 'w') { |f| f.write(post_install_script) }
|
31
31
|
|
@@ -60,17 +60,17 @@ task :package_rpm do
|
|
60
60
|
src_dir = "#{PROJECT_ROOT}/scripts"
|
61
61
|
content_dir = "#{PROJECT_ROOT}/pkg/#{LXC_PACKAGE_NAME}"
|
62
62
|
mkdir_p content_dir
|
63
|
-
mkdir_p "#{content_dir}/usr/
|
64
|
-
mkdir_p "#{content_dir}/
|
63
|
+
mkdir_p "#{content_dir}/usr/bin"
|
64
|
+
mkdir_p "#{content_dir}/var/lib/lxc"
|
65
65
|
mkdir_p "#{content_dir}/var/cache/lxc"
|
66
66
|
mkdir_p "#{content_dir}/usr/lib/lxc/templates"
|
67
|
-
cp_r Dir.glob("#{src_dir}/bin/share/*"), "#{content_dir}/usr/
|
68
|
-
cp_r Dir.glob("#{src_dir}/bin/centos/*"), "#{content_dir}/usr/
|
67
|
+
cp_r Dir.glob("#{src_dir}/bin/share/*"), "#{content_dir}/usr/bin"
|
68
|
+
cp_r Dir.glob("#{src_dir}/bin/centos/*"), "#{content_dir}/usr/bin"
|
69
69
|
cp_r Dir.glob("#{src_dir}/lxc-templates/*"), "#{content_dir}/usr/lib/lxc/templates"
|
70
70
|
|
71
71
|
post_install_script = <<-eos
|
72
72
|
#!/bin/sh -e
|
73
|
-
/usr/
|
73
|
+
/usr/bin/lxc-prepare-host
|
74
74
|
eos
|
75
75
|
File.open("#{PROJECT_ROOT}/pkg/toft-lxc-post-install.sh", 'w') { |f| f.write(post_install_script) }
|
76
76
|
|
data/features/command.feature
CHANGED
@@ -16,5 +16,5 @@ Scenario: Test rm
|
|
16
16
|
Scenario: Check ssh command result
|
17
17
|
Given I have a clean running node n1
|
18
18
|
Then the result of running ssh command "ps" on "n1" should contain "sshd"
|
19
|
-
Then the result of running ssh command "chef-solo" on "n1" should
|
19
|
+
Then the result of running ssh command "chef-solo" on "n1" should fail because of "No cookbook found"
|
20
20
|
|
@@ -15,5 +15,14 @@ Then /^Rm "([^"]*)" on "([^"]*)" should succeed$/ do |dir, node|
|
|
15
15
|
end
|
16
16
|
|
17
17
|
Then /^the result of running ssh command "([^"]*)" on "([^"]*)" should contain "([^"]*)"$/ do |cmd, node, s|
|
18
|
-
find(node).
|
19
|
-
|
18
|
+
r = find(node).run_ssh(cmd)
|
19
|
+
r.stdout.should include(s)
|
20
|
+
end
|
21
|
+
|
22
|
+
Then /^the result of running ssh command "([^"]*)" on "([^"]*)" should fail because of "([^"]*)"$/ do |cmd, node, s|
|
23
|
+
begin
|
24
|
+
r = find(node).run_ssh(cmd)
|
25
|
+
rescue CommandExecutionError => e
|
26
|
+
e.stdout.should include(s)
|
27
|
+
end
|
28
|
+
end
|
@@ -42,7 +42,7 @@ end
|
|
42
42
|
|
43
43
|
Then /^Node "([^"]*)" should have ip address same with that obtained from inside it through ssh$/ do |node|
|
44
44
|
n = find(node)
|
45
|
-
n.
|
45
|
+
n.run_ssh("ifconfig eth0 | grep 'inet addr:'").stdout.should include(n.ip)
|
46
46
|
end
|
47
47
|
|
48
48
|
When /^I add cname "([^"]*)" to "([^"]*)"$/ do |cname, node|
|
data/features/support/env.rb
CHANGED
data/lib/toft/node.rb
CHANGED
@@ -90,28 +90,36 @@ CQWv13UgQjiHgQILXSb7xdzpWK1wpDoqIEWQugRyPQDeZhPWVbB4Lg==
|
|
90
90
|
|
91
91
|
def run_ssh(command)
|
92
92
|
raise ArgumentError, "Trying to run empty command on node #{@hostname}", caller if command.blank?
|
93
|
-
|
93
|
+
stdout = ""
|
94
|
+
stderr = ""
|
94
95
|
Net::SSH.start(fqdn, "root", :key_data => [PRIVATE_KEY]) do |ssh|
|
95
|
-
ssh.
|
96
|
-
|
97
|
-
|
96
|
+
ssh.open_channel do |channel|
|
97
|
+
channel.exec(command) do |ch, success|
|
98
|
+
raise RuntimeError, "Could not execute command: [#{command}]", caller unless success
|
99
|
+
|
100
|
+
channel.on_data do |c, data|
|
101
|
+
puts data
|
102
|
+
stdout << data
|
103
|
+
yield data if block_given?
|
104
|
+
end
|
105
|
+
channel.on_extended_data do |c, type, data|
|
106
|
+
puts data
|
107
|
+
stderr << data
|
108
|
+
yield data if block_given?
|
109
|
+
end
|
110
|
+
channel.on_request("exit-status") do |c, data|
|
111
|
+
exit_code = data.read_long
|
112
|
+
raise CommandExecutionError.new "Remote command [#{command}] exited with status #{exit_code}", stdout, stderr unless exit_code.zero?
|
113
|
+
end
|
114
|
+
channel.on_request("exit-signal") do |c, data|
|
115
|
+
raise CommandExecutionError.new "Remote command [#{command}] terminated with signal", stdout, stderr
|
116
|
+
end
|
98
117
|
end
|
99
|
-
|
100
|
-
puts data
|
101
|
-
end
|
118
|
+
end.wait
|
102
119
|
end
|
103
|
-
|
104
|
-
return true
|
120
|
+
return CommandResult.new stdout, stderr
|
105
121
|
end
|
106
122
|
|
107
|
-
def get_ssh_result(cmd)
|
108
|
-
output = ""
|
109
|
-
run_ssh(cmd) do |data|
|
110
|
-
output += data
|
111
|
-
end
|
112
|
-
return output
|
113
|
-
end
|
114
|
-
|
115
123
|
def rm(dir)
|
116
124
|
raise ArgumentError, "Illegal dir path: [#{dir}]", caller if dir.blank? || dir[0] != ?/
|
117
125
|
system "rm -rf #{rootfs}#{dir}"
|
@@ -182,4 +190,23 @@ lxc.network.ipv4 = #{full_ip}
|
|
182
190
|
"#{@hostname}.#{Toft::DOMAIN}"
|
183
191
|
end
|
184
192
|
end
|
193
|
+
|
194
|
+
class CommandResult
|
195
|
+
attr_reader :stdout, :stderr
|
196
|
+
|
197
|
+
def initialize(stdout, stderr)
|
198
|
+
@stdout = stdout
|
199
|
+
@stderr = stderr
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
class CommandExecutionError < RuntimeError
|
204
|
+
attr_reader :message, :stdout, :stderr
|
205
|
+
|
206
|
+
def initialize(message, stdout, stderr)
|
207
|
+
@message = message
|
208
|
+
@stdout = stdout
|
209
|
+
@stderr = stderr
|
210
|
+
end
|
211
|
+
end
|
185
212
|
end
|
data/lib/toft/version.rb
CHANGED
@@ -19,7 +19,7 @@ if [[ ! -f /usr/bin/lxc-ls ]]; then
|
|
19
19
|
wget http://lxc.sourceforge.net/download/lxc/lxc-0.7.4.tar.gz && \
|
20
20
|
tar zxf lxc-0.7.4.tar.gz && \
|
21
21
|
cd lxc-0.7.4 && \
|
22
|
-
./configure --prefix=/usr && \
|
22
|
+
./configure --prefix=/usr --with-config-path=/var/lib/lxc && \
|
23
23
|
make && \
|
24
24
|
make install)
|
25
25
|
fi
|
@@ -38,14 +38,14 @@ BOOTPROTO=static
|
|
38
38
|
DELAY=0
|
39
39
|
TYPE=Bridge
|
40
40
|
IPADDR=$gateway_ip
|
41
|
-
NETWORK=$subnet
|
42
41
|
NETMASK=$netmask
|
43
|
-
GATEWAY=$gateway_ip
|
44
42
|
MTU=1500
|
45
43
|
IPV6INIT=no
|
46
44
|
USERCTL=no
|
47
45
|
EOF
|
48
46
|
|
47
|
+
sudo sed -i "s/#*[ ^I]*net\.ipv4\.ip_forward[ ^I]*=[ ^I]*[01]/net\.ipv4\.ip_forward = 1/" /etc/sysctl.conf
|
48
|
+
|
49
49
|
# reset iptables
|
50
50
|
cat <<EOF > /etc/sysconfig/iptables
|
51
51
|
*nat
|
@@ -36,6 +36,8 @@ post-up /usr/sbin/brctl setfd br0 0
|
|
36
36
|
EOF
|
37
37
|
fi
|
38
38
|
|
39
|
+
sudo sed -i "s/#*[ ^I]*net\.ipv4\.ip_forward[ ^I]*=[ ^I]*[01]/net\.ipv4\.ip_forward = 1/" /etc/sysctl.conf
|
40
|
+
|
39
41
|
iptables-save > /etc/firewall.conf
|
40
42
|
echo "#!/bin/sh" > /etc/network/if-up.d/iptables
|
41
43
|
echo "iptables-restore < /etc/firewall.conf" >> /etc/network/if-up.d/iptables
|
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: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
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-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|