testlab 1.0.0 → 1.0.1
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/lib/testlab/container/lxc.rb +1 -7
- data/lib/testlab/node/lxc.rb +12 -0
- data/lib/testlab/provisioners/apt.rb +7 -2
- data/lib/testlab/provisioners/apt_cacher_ng.rb +41 -13
- data/lib/testlab/provisioners/bind.rb +11 -1
- data/lib/testlab/provisioners/raring.rb +8 -2
- data/lib/testlab/provisioners/route.rb +2 -0
- data/lib/testlab/provisioners/templates/apt_cacher_ng/deprovision.erb +6 -0
- data/lib/testlab/provisioners/templates/apt_cacher_ng/provision.erb +12 -0
- data/lib/testlab/provisioners/templates/raring/{bootstrap.erb → provision.erb} +2 -2
- data/lib/testlab/version.rb +1 -1
- metadata +7 -6
- data/lib/testlab/provisioners/templates/apt_cacher_ng/bootstrap.erb +0 -8
- /data/lib/testlab/provisioners/templates/apt/{bootstrap.erb → provision.erb} +0 -0
@@ -8,15 +8,9 @@ class TestLab
|
|
8
8
|
# Renders the supplied content into a file on the container and proceeds
|
9
9
|
# to execute it on the container as root.
|
10
10
|
#
|
11
|
-
# On rare occasion it appears that the container will wipe '/tmp' after
|
12
|
-
# the bootstrap script is seeded but before it is executed via lxc-attach.
|
13
|
-
# This results in a 'No such file or directory' bash error when attempting
|
14
|
-
# to execute the script. We allow 5 retries to seed the bootstrap script
|
15
|
-
# after which time the exception will be thrown and execution halted.
|
16
|
-
#
|
17
11
|
# @param [String] content The content to render on the container and
|
18
12
|
# execute. This is generally a bash script of some sort for example.
|
19
|
-
# @return [String] The output of
|
13
|
+
# @return [String] The output of respective SSH/LXC bootstrap.
|
20
14
|
def bootstrap(content, options={})
|
21
15
|
if self.lxc_clone.exists?
|
22
16
|
self.ssh.bootstrap(content, options)
|
data/lib/testlab/node/lxc.rb
CHANGED
@@ -4,6 +4,18 @@ class TestLab
|
|
4
4
|
module LXC
|
5
5
|
require 'lxc'
|
6
6
|
|
7
|
+
# Node Bootstrap
|
8
|
+
#
|
9
|
+
# Renders the supplied content into a file on the node and proceeds
|
10
|
+
# to execute it on the node as root.
|
11
|
+
#
|
12
|
+
# @param [String] content The content to render on the node and
|
13
|
+
# execute. This is generally a bash script of some sort for example.
|
14
|
+
# @return [String] The output of SSH bootstrap.
|
15
|
+
def bootstrap(content, options={})
|
16
|
+
self.ssh.bootstrap(content, options)
|
17
|
+
end
|
18
|
+
|
7
19
|
# Returns the LXC object for this Node
|
8
20
|
#
|
9
21
|
# This object is used to control containers on the node via it's provider
|
@@ -29,8 +29,13 @@ class TestLab
|
|
29
29
|
def on_container_provision(container)
|
30
30
|
@ui.logger.debug { "APT Provisioner: Container #{container.id}" }
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
container.bootstrap(ZTK::Template.render(provision_template, @config))
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def provision_template
|
38
|
+
File.join(TestLab::Provisioner.template_dir, 'apt', 'provision.erb')
|
34
39
|
end
|
35
40
|
|
36
41
|
end
|
@@ -18,9 +18,6 @@ class TestLab
|
|
18
18
|
@config[:apt][:cacher_ng] ||= Hash.new
|
19
19
|
@config[:apt][:cacher_ng][:exclude_hosts] ||= Array.new
|
20
20
|
|
21
|
-
@apt_conf_d_proxy_file_template = File.join(TestLab::Provisioner.template_dir, "apt_cacher_ng", "00proxy.erb")
|
22
|
-
@apt_cacher_ng_security_conf_template = File.join(TestLab::Provisioner.template_dir, "apt_cacher_ng", "security.conf.erb")
|
23
|
-
|
24
21
|
@ui.logger.debug { "config(#{@config.inspect})" }
|
25
22
|
end
|
26
23
|
|
@@ -31,8 +28,7 @@ class TestLab
|
|
31
28
|
def on_node_provision(node)
|
32
29
|
@ui.logger.debug { "APT-CacherNG Provisioner: Node #{node.id}" }
|
33
30
|
|
34
|
-
|
35
|
-
node.ssh.bootstrap(ZTK::Template.render(bootstrap_template, @config))
|
31
|
+
node.bootstrap(ZTK::Template.render(provision_template, @config))
|
36
32
|
|
37
33
|
context = {
|
38
34
|
:apt => {
|
@@ -43,14 +39,12 @@ class TestLab
|
|
43
39
|
}
|
44
40
|
}
|
45
41
|
|
46
|
-
apt_conf_d_proxy_file = %(/etc/apt/apt.conf.d/00proxy)
|
47
42
|
node.ssh.file(:target => apt_conf_d_proxy_file, :chown => "root:root", :chmod => "0644") do |file|
|
48
|
-
file.puts(ZTK::Template.render(
|
43
|
+
file.puts(ZTK::Template.render(apt_conf_d_proxy_file_template, context))
|
49
44
|
end
|
50
45
|
|
51
|
-
apt_cacher_ng_security_conf_file = %(/etc/apt-cacher-ng/security.conf)
|
52
46
|
node.ssh.file(:target => apt_cacher_ng_security_conf_file, :chown => "root:root", :chmod => "0644") do |file|
|
53
|
-
file.puts(ZTK::Template.render(
|
47
|
+
file.puts(ZTK::Template.render(apt_cacher_ng_security_conf_template, context))
|
54
48
|
end
|
55
49
|
|
56
50
|
node.ssh.exec(%(sudo service apt-cacher-ng restart))
|
@@ -58,6 +52,16 @@ class TestLab
|
|
58
52
|
true
|
59
53
|
end
|
60
54
|
|
55
|
+
# APT-CacherNG: Node Deprovision
|
56
|
+
#
|
57
|
+
# @param [TestLab::Node] node The node which we want to deprovision.
|
58
|
+
# @return [Boolean] True if successful.
|
59
|
+
def on_node_deprovision(node)
|
60
|
+
node.bootstrap(ZTK::Template.render(deprovision_template, @config))
|
61
|
+
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
61
65
|
# APT-CacherNG: Container Provision
|
62
66
|
#
|
63
67
|
# @param [TestLab::Container] container The container which we want to
|
@@ -68,17 +72,41 @@ class TestLab
|
|
68
72
|
|
69
73
|
# Ensure the container APT calls use apt-cacher-ng on the node
|
70
74
|
gateway_ip = container.primary_interface.network.ip
|
71
|
-
apt_conf_d_proxy_file = %(/etc/apt/apt.conf.d/00proxy)
|
72
75
|
|
73
76
|
@config[:apt][:cacher_ng] = { :proxy_url => "http://#{gateway_ip}:3142" }.merge(@config[:apt][:cacher_ng])
|
74
77
|
|
75
78
|
container.ssh.file(:target => apt_conf_d_proxy_file, :chown => "root:root", :chmod => "0644") do |file|
|
76
|
-
file.puts(ZTK::Template.render(
|
79
|
+
file.puts(ZTK::Template.render(apt_conf_d_proxy_file_template, @config))
|
77
80
|
end
|
78
81
|
|
79
82
|
# Fix the APT sources since LXC mudges them when using apt-cacher-ng
|
80
|
-
|
81
|
-
|
83
|
+
container.ssh.exec(%(sudo sed -i 's/127.0.0.1:3142\\///g' /etc/apt/sources.list))
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def apt_conf_d_proxy_file
|
89
|
+
%(/etc/apt/apt.conf.d/00proxy)
|
90
|
+
end
|
91
|
+
|
92
|
+
def apt_cacher_ng_security_conf_file
|
93
|
+
%(/etc/apt-cacher-ng/security.conf)
|
94
|
+
end
|
95
|
+
|
96
|
+
def apt_conf_d_proxy_file_template
|
97
|
+
File.join(TestLab::Provisioner.template_dir, "apt_cacher_ng", "00proxy.erb")
|
98
|
+
end
|
99
|
+
|
100
|
+
def apt_cacher_ng_security_conf_template
|
101
|
+
File.join(TestLab::Provisioner.template_dir, "apt_cacher_ng", "security.conf.erb")
|
102
|
+
end
|
103
|
+
|
104
|
+
def provision_template
|
105
|
+
File.join(TestLab::Provisioner.template_dir, 'apt_cacher_ng', 'provision.erb')
|
106
|
+
end
|
107
|
+
|
108
|
+
def deprovision_template
|
109
|
+
File.join(TestLab::Provisioner.template_dir, 'apt_cacher_ng', 'deprovision.erb')
|
82
110
|
end
|
83
111
|
|
84
112
|
end
|
@@ -32,6 +32,16 @@ class TestLab
|
|
32
32
|
true
|
33
33
|
end
|
34
34
|
|
35
|
+
# Bind: Node Deprovision
|
36
|
+
#
|
37
|
+
# @param [TestLab::Node] node The node which we want to deprovision.
|
38
|
+
# @return [Boolean] True if successful.
|
39
|
+
def on_node_deprovision(node)
|
40
|
+
node.ssh.exec(%(DEBIAN_FRONTEND="noninteractive" sudo apt-get -y purge bind9))
|
41
|
+
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
35
45
|
# Bind: Network Up
|
36
46
|
#
|
37
47
|
# @param [TestLab::Network] network The network that is being onlined.
|
@@ -120,7 +130,7 @@ class TestLab
|
|
120
130
|
end
|
121
131
|
|
122
132
|
def bind_install(ssh)
|
123
|
-
ssh.exec(%(sudo apt-get -y install bind9))
|
133
|
+
ssh.exec(%(DEBIAN_FRONTEND="noninteractive" sudo apt-get -y install bind9))
|
124
134
|
ssh.exec(%(sudo rm -fv /etc/bind/{*.arpa,*.zone,*.conf*}))
|
125
135
|
end
|
126
136
|
|
@@ -27,8 +27,14 @@ class TestLab
|
|
27
27
|
def on_node_provision(node)
|
28
28
|
@ui.logger.debug { "Ubuntu Raring Provisioner: Node #{node.id}" }
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
node.bootstrap(ZTK::Template.render(provision_template, @config))
|
31
|
+
end
|
32
|
+
alias :on_node_up :on_node_provision
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def provision_template
|
37
|
+
File.join(TestLab::Provisioner.template_dir, 'raring', 'provision.erb')
|
32
38
|
end
|
33
39
|
|
34
40
|
end
|
@@ -25,6 +25,7 @@ class TestLab
|
|
25
25
|
|
26
26
|
true
|
27
27
|
end
|
28
|
+
alias :on_network_up :on_network_provision
|
28
29
|
|
29
30
|
# Route: Network Deprovision
|
30
31
|
def on_network_deprovision(network)
|
@@ -32,6 +33,7 @@ class TestLab
|
|
32
33
|
|
33
34
|
true
|
34
35
|
end
|
36
|
+
alias :on_network_down :on_network_deprovision
|
35
37
|
|
36
38
|
def manage_route(action, network)
|
37
39
|
command = ZTK::Command.new(:ui => @ui, :silence => true, :ignore_exit_status => true)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
set -x
|
2
|
+
set -e
|
3
|
+
|
4
|
+
[[ -f /.testlab-apt-cacher-ng-provision ]] && exit 0
|
5
|
+
|
6
|
+
export DEBIAN_FRONTEND="noninteractive"
|
7
|
+
|
8
|
+
apt-get -y install apt-cacher-ng
|
9
|
+
service apt-cacher-ng restart || service apt-cacher-ng start
|
10
|
+
grep "^MIRROR" /etc/default/lxc || (echo 'MIRROR="http://127.0.0.1:3142/archive.ubuntu.com/ubuntu"' | tee -a /etc/default/lxc)
|
11
|
+
|
12
|
+
touch /.testlab-apt-cacher-ng-provision
|
@@ -18,7 +18,7 @@ service lxc-net stop || (service lxc-net start ; service lxc-net stop)
|
|
18
18
|
service ntp restart || service ntp start
|
19
19
|
|
20
20
|
# Enable ipv4 forwarding
|
21
|
-
sysctl net.ipv4.ip_forward | grep "net.ipv4.ip_forward = 1" || sysctl -w net.ipv4.ip_forward=1
|
21
|
+
(sysctl net.ipv4.ip_forward | grep "net.ipv4.ip_forward = 1") || sysctl -w net.ipv4.ip_forward=1
|
22
22
|
|
23
23
|
# Install an iptable NAT rule
|
24
|
-
iptables -t nat --list -v | grep "MASQUERADE all -- any eth0 anywhere anywhere" || iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
24
|
+
(iptables -t nat --list -v | grep "MASQUERADE all -- any eth0 anywhere anywhere") || iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
data/lib/testlab/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testlab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -284,9 +284,10 @@ files:
|
|
284
284
|
- lib/testlab/provisioners/resolv.rb
|
285
285
|
- lib/testlab/provisioners/route.rb
|
286
286
|
- lib/testlab/provisioners/shell.rb
|
287
|
-
- lib/testlab/provisioners/templates/apt/
|
287
|
+
- lib/testlab/provisioners/templates/apt/provision.erb
|
288
288
|
- lib/testlab/provisioners/templates/apt_cacher_ng/00proxy.erb
|
289
|
-
- lib/testlab/provisioners/templates/apt_cacher_ng/
|
289
|
+
- lib/testlab/provisioners/templates/apt_cacher_ng/deprovision.erb
|
290
|
+
- lib/testlab/provisioners/templates/apt_cacher_ng/provision.erb
|
290
291
|
- lib/testlab/provisioners/templates/apt_cacher_ng/security.conf.erb
|
291
292
|
- lib/testlab/provisioners/templates/bind/bind-db.erb
|
292
293
|
- lib/testlab/provisioners/templates/bind/bind-zone.erb
|
@@ -295,7 +296,7 @@ files:
|
|
295
296
|
- lib/testlab/provisioners/templates/chef/omni_truck.erb
|
296
297
|
- lib/testlab/provisioners/templates/chef/ruby_gem_client.erb
|
297
298
|
- lib/testlab/provisioners/templates/chef/ruby_gem_server.erb
|
298
|
-
- lib/testlab/provisioners/templates/raring/
|
299
|
+
- lib/testlab/provisioners/templates/raring/provision.erb
|
299
300
|
- lib/testlab/provisioners/templates/resolv/resolv.conf.erb
|
300
301
|
- lib/testlab/user.rb
|
301
302
|
- lib/testlab/user/lifecycle.rb
|
@@ -332,7 +333,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
332
333
|
version: '0'
|
333
334
|
segments:
|
334
335
|
- 0
|
335
|
-
hash:
|
336
|
+
hash: 2056415191929520166
|
336
337
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
337
338
|
none: false
|
338
339
|
requirements:
|
@@ -341,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
341
342
|
version: '0'
|
342
343
|
segments:
|
343
344
|
- 0
|
344
|
-
hash:
|
345
|
+
hash: 2056415191929520166
|
345
346
|
requirements: []
|
346
347
|
rubyforge_project:
|
347
348
|
rubygems_version: 1.8.25
|
@@ -1,8 +0,0 @@
|
|
1
|
-
set -x
|
2
|
-
set -e
|
3
|
-
|
4
|
-
export DEBIAN_FRONTEND="noninteractive"
|
5
|
-
|
6
|
-
apt-get -y install apt-cacher-ng
|
7
|
-
service apt-cacher-ng restart || service apt-cacher-ng start
|
8
|
-
grep "^MIRROR" /etc/default/lxc || echo 'MIRROR="http://127.0.0.1:3142/archive.ubuntu.com/ubuntu"' | tee -a /etc/default/lxc
|
File without changes
|