testlab 1.6.6 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tl-knife +1 -1
- data/lib/testlab/container.rb +2 -0
- data/lib/testlab/container/configuration.rb +5 -1
- data/lib/testlab/container/support.rb +1 -1
- data/lib/testlab/providers/templates/vagrant/Vagrantfile.erb +3 -0
- data/lib/testlab/providers/vagrant.rb +6 -1
- data/lib/testlab/provisioner.rb +1 -0
- data/lib/testlab/provisioners/nfs_mount.rb +135 -0
- data/lib/testlab/provisioners/templates/raring/provision.erb +9 -1
- data/lib/testlab/version.rb +1 -1
- metadata +5 -4
data/bin/tl-knife
CHANGED
@@ -32,7 +32,7 @@ logger = ZTK::Logger.new(%(/tmp/tl-knife.log))
|
|
32
32
|
ui = ZTK::UI.new(:logger => logger) # ui interface class
|
33
33
|
l = TestLab.new(:ui => ui) # lab
|
34
34
|
l.boot # boot lab
|
35
|
-
chef_server = l.containers.
|
35
|
+
chef_server = l.containers.select{ |c| c.id == 'chef-server' }.first
|
36
36
|
|
37
37
|
verbose_flags = %w(-V -VV --verbose)
|
38
38
|
verbose = ARGV.any?{ |arg| verbose_flags.include?(arg) } || (!ENV['LOG_LEVEL'].nil? && (ENV['LOG_LEVEL'].upcase == 'DEBUG'))
|
data/lib/testlab/container.rb
CHANGED
@@ -28,6 +28,10 @@ class TestLab
|
|
28
28
|
lxc_config['lxc.arch'] = self.arch
|
29
29
|
lxc_config['lxc.utsname'] = self.fqdn
|
30
30
|
|
31
|
+
self.mounts.nil? or self.mounts.flatten.compact.each do |mount|
|
32
|
+
lxc_config['lxc.mount.entry'] = mount
|
33
|
+
end
|
34
|
+
|
31
35
|
unless self.aa_profile.nil?
|
32
36
|
lxc_config['lxc.aa_profile'] = self.aa_profile
|
33
37
|
end
|
@@ -36,7 +40,7 @@ class TestLab
|
|
36
40
|
lxc_config['lxc.cap.drop'] = [self.cap_drop].flatten.compact.map(&:downcase).join(' ')
|
37
41
|
end
|
38
42
|
|
39
|
-
lxc_config.networks
|
43
|
+
lxc_config.networks = build_lxc_network_conf(self.interfaces)
|
40
44
|
|
41
45
|
lxc_config.save
|
42
46
|
|
@@ -11,6 +11,9 @@ Vagrant.configure("2") do |config|
|
|
11
11
|
testlab.vm.box = <%= @box.inspect %>
|
12
12
|
testlab.vm.box_url = <%= @box_url.inspect %>
|
13
13
|
testlab.vm.network(:private_network, :ip => <%= @ip.inspect %>)
|
14
|
+
<% @synced_folders.nil? or @synced_folders.each do |synced_folder| -%>
|
15
|
+
testlab.vm.synced_folder *<%= synced_folder.inspect %>
|
16
|
+
<% end -%>
|
14
17
|
|
15
18
|
testlab.vm.provider :virtualbox do |vb|
|
16
19
|
vb.name = <%= @hostname.inspect %>
|
@@ -171,6 +171,10 @@ class TestLab
|
|
171
171
|
(@config[:vagrant][:resize] || (1024 * 16))
|
172
172
|
end
|
173
173
|
|
174
|
+
def synced_folders
|
175
|
+
(@config[:vagrant][:synced_folders] || nil)
|
176
|
+
end
|
177
|
+
|
174
178
|
################################################################################
|
175
179
|
|
176
180
|
def vagrant_cli(*args)
|
@@ -204,7 +208,8 @@ class TestLab
|
|
204
208
|
:memory => self.memory,
|
205
209
|
:resize => self.resize,
|
206
210
|
:box => self.box,
|
207
|
-
:box_url => self.box_url
|
211
|
+
:box_url => self.box_url,
|
212
|
+
:synced_folders => self.synced_folders
|
208
213
|
}
|
209
214
|
|
210
215
|
vagrantfile_template = File.join(TestLab::Provider.template_dir, "vagrant", "Vagrantfile.erb")
|
data/lib/testlab/provisioner.rb
CHANGED
@@ -11,6 +11,7 @@ class TestLab
|
|
11
11
|
autoload :AptCacherNG, 'testlab/provisioners/apt_cacher_ng'
|
12
12
|
autoload :Bind, 'testlab/provisioners/bind'
|
13
13
|
autoload :Chef, 'testlab/provisioners/chef'
|
14
|
+
autoload :NFSMount, 'testlab/provisioners/nfs_mount'
|
14
15
|
autoload :Raring, 'testlab/provisioners/raring'
|
15
16
|
autoload :Resolv, 'testlab/provisioners/resolv'
|
16
17
|
autoload :Route, 'testlab/provisioners/route'
|
@@ -0,0 +1,135 @@
|
|
1
|
+
class TestLab
|
2
|
+
|
3
|
+
class Provisioner
|
4
|
+
|
5
|
+
# NFSMount Provisioner Error Class
|
6
|
+
class NFSMountError < ProvisionerError; end
|
7
|
+
|
8
|
+
# NFSMount Provisioner Class
|
9
|
+
#
|
10
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
11
|
+
class NFSMount
|
12
|
+
require 'base64'
|
13
|
+
require 'digest/sha1'
|
14
|
+
|
15
|
+
include TestLab::Utility::Misc
|
16
|
+
|
17
|
+
def initialize(config={}, ui=nil)
|
18
|
+
@config = (config || Hash.new)
|
19
|
+
@ui = (ui || TestLab.ui)
|
20
|
+
@command = ZTK::Command.new(:ui => @ui, :silence => true, :ignore_exit_status => true)
|
21
|
+
|
22
|
+
@config[:nfs_mounts] ||= Array.new
|
23
|
+
|
24
|
+
@ui.logger.debug { "config(#{@config.inspect})" }
|
25
|
+
end
|
26
|
+
|
27
|
+
# NFSMount: Container Provision
|
28
|
+
def on_container_provision(container)
|
29
|
+
container.exec(%(sudo dpkg --status nfs-common || sudo apt-get -y install nfs-common))
|
30
|
+
|
31
|
+
add_nfs_mounts(container)
|
32
|
+
container_mount(container)
|
33
|
+
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
# NFSMount: Container Up
|
38
|
+
def on_container_up(container)
|
39
|
+
(container.exec(%(sudo dpkg --status nfs-common), :ignore_exit_status => true).exit_code == 0) or return false
|
40
|
+
|
41
|
+
add_nfs_mounts(container)
|
42
|
+
container_mount(container)
|
43
|
+
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_container_deprovision(container)
|
48
|
+
remove_nfs_mounts(container)
|
49
|
+
|
50
|
+
true
|
51
|
+
end
|
52
|
+
alias :on_container_down :on_container_deprovision
|
53
|
+
alias :on_container_destroy :on_container_deprovision
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def add_nfs_mounts(container)
|
58
|
+
@command.exec(<<-EOF)
|
59
|
+
set -x
|
60
|
+
#{service_check}
|
61
|
+
grep '#{def_tag(container)}' /etc/exports && exit 0
|
62
|
+
cat <<EOI | #{sudo} tee -a /etc/exports
|
63
|
+
#{def_tag(container)}
|
64
|
+
#{mount_blob(container)}
|
65
|
+
#{end_tag(container)}
|
66
|
+
EOI
|
67
|
+
#{restart_service_command}
|
68
|
+
EOF
|
69
|
+
end
|
70
|
+
|
71
|
+
def remove_nfs_mounts(container)
|
72
|
+
@command.exec(sed_exports(container))
|
73
|
+
end
|
74
|
+
|
75
|
+
def mount_blob(container)
|
76
|
+
mount_entries = Array.new
|
77
|
+
@config[:nfs_mounts].each do |nfs_mount|
|
78
|
+
mount_entries << case RUBY_PLATFORM
|
79
|
+
when /darwin/ then
|
80
|
+
%(#{nfs_mount[1]})
|
81
|
+
when /linux/ then
|
82
|
+
%(#{nfs_mount[1]} *(rw,sync,no_subtree_check))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
mount_entries.join("\n")
|
86
|
+
end
|
87
|
+
|
88
|
+
def sed_exports(container)
|
89
|
+
case RUBY_PLATFORM
|
90
|
+
when /darwin/ then
|
91
|
+
%(#{sudo} sed -i '' '/#{def_tag(container)}/,/#{end_tag(container)}/d' /etc/exports)
|
92
|
+
when /linux/ then
|
93
|
+
%(#{sudo} sed -i '/#{def_tag(container)}/,/#{end_tag(container)}/d' /etc/exports)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def container_mount(container)
|
98
|
+
@config[:nfs_mounts].each do |nfs_mount|
|
99
|
+
container.exec(%(sudo mkdir -p #{nfs_mount[2]}))
|
100
|
+
container.exec(%(sudo mount -vt nfs -o 'nfsvers=3' #{nfs_mount[0]}:#{nfs_mount[1]} #{nfs_mount[2]}), :ignore_exit_status => true)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def restart_service_command
|
105
|
+
case RUBY_PLATFORM
|
106
|
+
when /darwin/ then
|
107
|
+
%(#{sudo} nfsd restart ; sleep 10)
|
108
|
+
when /linux/ then
|
109
|
+
%(#{sudo} service nfs-kernel-server reload || #{sudo} service nfs-kernel-server restart)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def service_check
|
114
|
+
case RUBY_PLATFORM
|
115
|
+
when /darwin/ then
|
116
|
+
%(#{sudo} nfsd enable)
|
117
|
+
when /linux/ then
|
118
|
+
%((#{sudo} dpkg --status nfs-kernel-server || #{sudo} apt-get -y install nfs-kernel-server) && #{sudo} service nfs-kernel-server start)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# NFS Exports Start Definition Tag
|
123
|
+
def def_tag(container)
|
124
|
+
"#TESTLAB-NFS-EXPORTS-DEF-#{container.id.to_s.upcase}"
|
125
|
+
end
|
126
|
+
|
127
|
+
# NFS Exports End Definition Tag
|
128
|
+
def end_tag(container)
|
129
|
+
"#TESTLAB-NFS-EXPORTS-END-#{container.id.to_s.upcase}"
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
@@ -5,7 +5,7 @@ export DEBIAN_FRONTEND="noninteractive"
|
|
5
5
|
|
6
6
|
# Update APT and ensure our required packages are installed
|
7
7
|
apt-get -y update
|
8
|
-
<% %w(lxc bridge-utils debootstrap yum iptables iptables-persistent ntpdate ntp pbzip2).each do |package| -%>
|
8
|
+
<% %w(lxc apparmor bridge-utils debootstrap yum iptables iptables-persistent ntpdate ntp pbzip2).each do |package| -%>
|
9
9
|
dpkg --status <%= package %> &> /dev/null || apt-get -y install <%= package %>
|
10
10
|
<% end -%>
|
11
11
|
|
@@ -26,3 +26,11 @@ if ! iptables -t nat -v --list | grep "MASQUERADE"; then
|
|
26
26
|
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
27
27
|
iptables-save | tee /etc/iptables/rules.v4
|
28
28
|
fi
|
29
|
+
|
30
|
+
grep 'mount fstype=nfs,' /etc/apparmor.d/abstractions/lxc/container-base || cat <<EOF | tee -a /etc/apparmor.d/abstractions/lxc/container-base
|
31
|
+
mount fstype=nfs,
|
32
|
+
EOF
|
33
|
+
|
34
|
+
grep 'mount fstype=rpc_pipefs,' /etc/apparmor.d/abstractions/lxc/container-base || cat <<EOF | tee -a /etc/apparmor.d/abstractions/lxc/container-base
|
35
|
+
mount fstype=rpc_pipefs,
|
36
|
+
EOF
|
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.
|
4
|
+
version: 1.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gli
|
@@ -286,6 +286,7 @@ files:
|
|
286
286
|
- lib/testlab/provisioners/chef/omni_truck.rb
|
287
287
|
- lib/testlab/provisioners/chef/ruby_gem_client.rb
|
288
288
|
- lib/testlab/provisioners/chef/ruby_gem_server.rb
|
289
|
+
- lib/testlab/provisioners/nfs_mount.rb
|
289
290
|
- lib/testlab/provisioners/raring.rb
|
290
291
|
- lib/testlab/provisioners/resolv.rb
|
291
292
|
- lib/testlab/provisioners/route.rb
|
@@ -342,7 +343,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
342
343
|
version: '0'
|
343
344
|
segments:
|
344
345
|
- 0
|
345
|
-
hash: -
|
346
|
+
hash: -571229206992494918
|
346
347
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
347
348
|
none: false
|
348
349
|
requirements:
|
@@ -351,7 +352,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
352
|
version: '0'
|
352
353
|
segments:
|
353
354
|
- 0
|
354
|
-
hash: -
|
355
|
+
hash: -571229206992494918
|
355
356
|
requirements: []
|
356
357
|
rubyforge_project:
|
357
358
|
rubygems_version: 1.8.25
|