testlab 0.6.9 → 0.6.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -7
- data/lib/testlab/container/lxc.rb +21 -9
- data/lib/testlab/provisioners/apt_cacher_ng.rb +2 -2
- data/lib/testlab/user/lifecycle.rb +18 -4
- data/lib/testlab/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -18,20 +18,25 @@ The TestLab command-line program `tl` follows in the style of git (using the GLI
|
|
18
18
|
|
19
19
|
$ tl help
|
20
20
|
NAME
|
21
|
-
tl - A
|
21
|
+
tl - TestLab - A toolkit for building virtual computer labs
|
22
22
|
|
23
23
|
SYNOPSIS
|
24
24
|
tl [global options] command [command options] [arguments...]
|
25
25
|
|
26
26
|
VERSION
|
27
|
-
0.6.
|
27
|
+
0.6.9
|
28
28
|
|
29
29
|
GLOBAL OPTIONS
|
30
|
-
--version
|
31
|
-
--
|
30
|
+
--version -
|
31
|
+
-v, --[no-]verbose - Show verbose output
|
32
|
+
-q, --[no-]quiet - Quiet mode
|
33
|
+
--help - Show this message
|
32
34
|
|
33
35
|
COMMANDS
|
34
36
|
help - Shows a list of commands or help for one command
|
37
|
+
container - Manage containers
|
38
|
+
network - Manage networks
|
39
|
+
node - Manage nodes
|
35
40
|
create - Create the test lab
|
36
41
|
destroy - Destroy the test lab
|
37
42
|
up - Online the test lab
|
@@ -40,9 +45,6 @@ The TestLab command-line program `tl` follows in the style of git (using the GLI
|
|
40
45
|
teardown - Teardown the test lab infrastructure
|
41
46
|
build - Build the test lab infrastructure
|
42
47
|
status - Display information on the status of the test lab
|
43
|
-
node - Manage nodes
|
44
|
-
network - Manage networks
|
45
|
-
container - Manage containers
|
46
48
|
|
47
49
|
You stand up your lab with the following command:
|
48
50
|
|
@@ -17,9 +17,12 @@ class TestLab
|
|
17
17
|
ZTK::RescueRetry.try(:tries => 3, :on => ContainerError) do
|
18
18
|
tempfile = Tempfile.new("bootstrap")
|
19
19
|
remote_tempfile = File.join("/tmp", File.basename(tempfile.path))
|
20
|
-
|
20
|
+
target_file = File.join(self.fs_root, remote_tempfile)
|
21
|
+
|
22
|
+
self.node.ssh.file(:target => target_file, :chmod => '0777', :chown => 'root:root') do |file|
|
21
23
|
file.puts(content)
|
22
24
|
end
|
25
|
+
|
23
26
|
output = self.lxc.attach(%(--), %(/bin/bash), remote_tempfile)
|
24
27
|
if output =~ /No such file or directory/
|
25
28
|
raise ContainerError, "We could not find the bootstrap file!"
|
@@ -105,6 +108,13 @@ class TestLab
|
|
105
108
|
self.lxc.exists?
|
106
109
|
end
|
107
110
|
|
111
|
+
# Container root filesystem path
|
112
|
+
#
|
113
|
+
# @return [String] The path to the containers root filesystem.
|
114
|
+
def fs_root
|
115
|
+
self.lxc.fs_root(self.lxc_clone.exists?)
|
116
|
+
end
|
117
|
+
|
108
118
|
# Returns arguments for lxc-create based on our distro
|
109
119
|
#
|
110
120
|
# @return [Array<String>] An array of arguments for lxc-create
|
@@ -138,9 +148,11 @@ class TestLab
|
|
138
148
|
# @return [Boolean] True if successful.
|
139
149
|
def build_lxc_config(lxc_config)
|
140
150
|
lxc_config.clear
|
151
|
+
|
141
152
|
lxc_config['lxc.utsname'] = self.fqdn
|
142
|
-
lxc_config['lxc.arch']
|
143
|
-
lxc_config.networks
|
153
|
+
lxc_config['lxc.arch'] = self.arch
|
154
|
+
lxc_config.networks = build_lxc_network_conf(self.interfaces)
|
155
|
+
|
144
156
|
lxc_config.save
|
145
157
|
|
146
158
|
true
|
@@ -158,12 +170,12 @@ class TestLab
|
|
158
170
|
|
159
171
|
interfaces.each do |interface|
|
160
172
|
networks << Hash[
|
161
|
-
'lxc.network.type'
|
162
|
-
'lxc.network.flags'
|
163
|
-
'lxc.network.link'
|
164
|
-
'lxc.network.name'
|
165
|
-
'lxc.network.hwaddr'
|
166
|
-
'lxc.network.ipv4'
|
173
|
+
'lxc.network.type' => :veth,
|
174
|
+
'lxc.network.flags' => :up,
|
175
|
+
'lxc.network.link' => interface.network.bridge,
|
176
|
+
'lxc.network.name' => interface.name,
|
177
|
+
'lxc.network.hwaddr' => interface.mac,
|
178
|
+
'lxc.network.ipv4' => "#{interface.ip}/#{interface.cidr} #{interface.netmask}"
|
167
179
|
]
|
168
180
|
if (interface.primary == true) || (interfaces.count == 1)
|
169
181
|
networks.last.merge!('lxc.network.ipv4.gateway' => :auto)
|
@@ -60,7 +60,7 @@ class TestLab
|
|
60
60
|
|
61
61
|
# Ensure the container APT calls use apt-cacher-ng on the node
|
62
62
|
gateway_ip = container.primary_interface.network.ip
|
63
|
-
apt_conf_d_proxy_file = File.join(container.
|
63
|
+
apt_conf_d_proxy_file = File.join(container.fs_root, "etc", "apt", "apt.conf.d", "00proxy")
|
64
64
|
|
65
65
|
@config[:apt][:cacher_ng] = { :proxy_url => "http://#{gateway_ip}:3142" }.merge(@config[:apt][:cacher_ng])
|
66
66
|
|
@@ -69,7 +69,7 @@ class TestLab
|
|
69
69
|
end
|
70
70
|
|
71
71
|
# Fix the APT sources since LXC mudges them when using apt-cacher-ng
|
72
|
-
apt_conf_sources_file = File.join(container.
|
72
|
+
apt_conf_sources_file = File.join(container.fs_root, "etc", "apt", "sources.list")
|
73
73
|
container.node.ssh.exec(%(sudo sed -i 's/127.0.0.1:3142\\///g' #{apt_conf_sources_file}))
|
74
74
|
end
|
75
75
|
|
@@ -13,12 +13,12 @@ class TestLab
|
|
13
13
|
node_authkeys = File.join(node_home_dir, ".ssh", "authorized_keys")
|
14
14
|
|
15
15
|
# ensure the container user exists
|
16
|
-
container_passwd_file = File.join(self.container.
|
16
|
+
container_passwd_file = File.join(self.container.fs_root, "etc", "passwd")
|
17
17
|
if self.container.node.ssh.exec(%(sudo grep "#{self.id}" #{container_passwd_file}), :ignore_exit_status => true).exit_code != 0
|
18
18
|
|
19
19
|
if !self.gid.nil?
|
20
20
|
groupadd_command = %(groupadd --gid #{self.gid} #{self.id})
|
21
|
-
self.container.node.ssh.exec(%(sudo chroot #{self.container.
|
21
|
+
self.container.node.ssh.exec(%(sudo chroot #{self.container.fs_root} /bin/bash -c '#{groupadd_command}'))
|
22
22
|
end
|
23
23
|
|
24
24
|
useradd_command = %W(useradd --create-home --shell /bin/bash --groups sudo --password #{self.password})
|
@@ -27,11 +27,11 @@ class TestLab
|
|
27
27
|
useradd_command << self.id
|
28
28
|
useradd_command = useradd_command.flatten.compact.join(' ')
|
29
29
|
|
30
|
-
self.container.node.ssh.exec(%(sudo chroot #{self.container.
|
30
|
+
self.container.node.ssh.exec(%(sudo chroot #{self.container.fs_root} /bin/bash -c '#{useradd_command}'))
|
31
31
|
end
|
32
32
|
|
33
33
|
# ensure the user user gets our node user key
|
34
|
-
user_home_dir = File.join(self.container.
|
34
|
+
user_home_dir = File.join(self.container.fs_root, ((self.id == "root") ? %(/root) : %(/home/#{self.id})))
|
35
35
|
user_authkeys = File.join(user_home_dir, ".ssh", "authorized_keys")
|
36
36
|
user_authkeys2 = File.join(user_home_dir, ".ssh", "authorized_keys2")
|
37
37
|
|
@@ -57,6 +57,20 @@ class TestLab
|
|
57
57
|
true
|
58
58
|
end
|
59
59
|
|
60
|
+
# User Home Directory
|
61
|
+
#
|
62
|
+
# Returns the path to the users home directory.
|
63
|
+
#
|
64
|
+
# @return [String] The users home directory.
|
65
|
+
def home_dir(name=nil)
|
66
|
+
username = (name || self.id)
|
67
|
+
if (username == "root")
|
68
|
+
"/root"
|
69
|
+
else
|
70
|
+
"/home/#{username}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
60
74
|
end
|
61
75
|
|
62
76
|
end
|
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: 0.6.
|
4
|
+
version: 0.6.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -300,7 +300,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
300
300
|
version: '0'
|
301
301
|
segments:
|
302
302
|
- 0
|
303
|
-
hash:
|
303
|
+
hash: 3377457757681379174
|
304
304
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
305
305
|
none: false
|
306
306
|
requirements:
|
@@ -309,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
309
309
|
version: '0'
|
310
310
|
segments:
|
311
311
|
- 0
|
312
|
-
hash:
|
312
|
+
hash: 3377457757681379174
|
313
313
|
requirements: []
|
314
314
|
rubyforge_project:
|
315
315
|
rubygems_version: 1.8.25
|