testlab 0.7.6 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -1
- data/bin/tl +8 -4
- data/features/step_definitions/testlab_steps.rb +5 -1
- data/features/support/Labfile.local +46 -0
- data/features/support/Labfile.vagrant +58 -0
- data/features/support/env.rb +8 -0
- data/features/testlab.feature +4 -8
- data/lib/commands/container.rb +28 -240
- data/lib/commands/network.rb +27 -193
- data/lib/commands/node.rb +9 -160
- data/lib/commands/testlab.rb +72 -10
- data/lib/testlab/container/actions.rb +2 -2
- data/lib/testlab/container/io.rb +21 -12
- data/lib/testlab/container/lifecycle.rb +13 -0
- data/lib/testlab/container/ssh.rb +2 -2
- data/lib/testlab/container.rb +3 -1
- data/lib/testlab/interface.rb +2 -0
- data/lib/testlab/network/actions.rb +2 -2
- data/lib/testlab/network/lifecycle.rb +15 -0
- data/lib/testlab/network/status.rb +1 -1
- data/lib/testlab/network.rb +3 -1
- data/lib/testlab/node/lifecycle.rb +9 -0
- data/lib/testlab/node.rb +2 -0
- data/lib/testlab/user.rb +2 -0
- data/lib/testlab/utility/gli.rb +83 -0
- data/lib/testlab/utility/logger.rb +35 -30
- data/lib/testlab/utility.rb +2 -0
- data/lib/testlab/version.rb +1 -1
- data/lib/testlab.rb +111 -38
- data/spec/container_spec.rb +4 -0
- data/spec/network_spec.rb +4 -0
- metadata +9 -6
- data/features/support/Labfile +0 -85
data/lib/commands/network.rb
CHANGED
@@ -20,150 +20,7 @@
|
|
20
20
|
|
21
21
|
# NETWORKS
|
22
22
|
###########
|
23
|
-
|
24
|
-
arg_name 'Describe arguments to network here'
|
25
|
-
command :network do |c|
|
26
|
-
|
27
|
-
c.desc 'Network ID or Name'
|
28
|
-
c.arg_name 'network'
|
29
|
-
c.flag [:n, :name]
|
30
|
-
|
31
|
-
# NETWORK CREATE
|
32
|
-
#################
|
33
|
-
c.desc 'Create a network'
|
34
|
-
c.long_desc <<-EOF
|
35
|
-
Create a network. The network is created.
|
36
|
-
EOF
|
37
|
-
c.command :create do |create|
|
38
|
-
create.action do |global_options, options, args|
|
39
|
-
if options[:name].nil?
|
40
|
-
help_now!('a name is required') if options[:name].nil?
|
41
|
-
else
|
42
|
-
network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
43
|
-
network.nil? and raise TestLab::TestLabError, "We could not find the network you screateplied!"
|
44
|
-
|
45
|
-
network.create
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# NETWORK DESTROY
|
51
|
-
#################
|
52
|
-
c.desc 'Destroy a network'
|
53
|
-
c.long_desc <<-EOF
|
54
|
-
Destroy a network. The network is destroyed.
|
55
|
-
EOF
|
56
|
-
c.command :destroy do |destroy|
|
57
|
-
destroy.action do |global_options, options, args|
|
58
|
-
if options[:name].nil?
|
59
|
-
help_now!('a name is required') if options[:name].nil?
|
60
|
-
else
|
61
|
-
network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
62
|
-
network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
|
63
|
-
|
64
|
-
network.destroy
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# NETWORK UP
|
70
|
-
#############
|
71
|
-
c.desc 'Up a network'
|
72
|
-
c.long_desc <<-EOF
|
73
|
-
Up a network. The network is started and brought online.
|
74
|
-
EOF
|
75
|
-
c.command :up do |up|
|
76
|
-
up.action do |global_options, options, args|
|
77
|
-
if options[:name].nil?
|
78
|
-
help_now!('a name is required') if options[:name].nil?
|
79
|
-
else
|
80
|
-
network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
81
|
-
network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
|
82
|
-
|
83
|
-
network.up
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# NETWORK DOWN
|
89
|
-
###############
|
90
|
-
c.desc 'Down a network'
|
91
|
-
c.long_desc <<-EOF
|
92
|
-
Down a network. The network is stopped taking it offline.
|
93
|
-
EOF
|
94
|
-
c.command :down do |down|
|
95
|
-
down.action do |global_options, options, args|
|
96
|
-
if options[:name].nil?
|
97
|
-
help_now!('a name is required') if options[:name].nil?
|
98
|
-
else
|
99
|
-
network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
100
|
-
network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
|
101
|
-
|
102
|
-
network.down
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# NETWORK SETUP
|
108
|
-
################
|
109
|
-
c.desc 'Setup a network'
|
110
|
-
c.long_desc <<-EOF
|
111
|
-
Setup a network. The network is created, started and provisioned.
|
112
|
-
EOF
|
113
|
-
c.command :setup do |setup|
|
114
|
-
setup.action do |global_options, options, args|
|
115
|
-
if options[:name].nil?
|
116
|
-
help_now!('a name is required') if options[:name].nil?
|
117
|
-
else
|
118
|
-
network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
119
|
-
network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
|
120
|
-
|
121
|
-
network.setup
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# NETWORK TEARDOWN
|
127
|
-
###################
|
128
|
-
c.desc 'Teardown a network'
|
129
|
-
c.long_desc <<-EOF
|
130
|
-
Teardown a network. The network is offlined and destroyed.
|
131
|
-
EOF
|
132
|
-
c.command :teardown do |teardown|
|
133
|
-
teardown.action do |global_options, options, args|
|
134
|
-
if options[:name].nil?
|
135
|
-
help_now!('a name is required') if options[:name].nil?
|
136
|
-
else
|
137
|
-
network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
138
|
-
network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
|
139
|
-
|
140
|
-
network.teardown
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
# NETWORK BUILD
|
146
|
-
################
|
147
|
-
c.desc 'Build a network'
|
148
|
-
c.long_desc <<-EOF
|
149
|
-
Attempts to build up the network. TestLab will attempt to create, online and provision the network.
|
150
|
-
|
151
|
-
The network is taken through the following phases:
|
152
|
-
|
153
|
-
Create -> Up -> Setup
|
154
|
-
EOF
|
155
|
-
c.command :build do |build|
|
156
|
-
build.action do |global_options, options, args|
|
157
|
-
if options[:name].nil?
|
158
|
-
help_now!('a name is required') if options[:name].nil?
|
159
|
-
else
|
160
|
-
network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
161
|
-
network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
|
162
|
-
|
163
|
-
network.build
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
23
|
+
build_lab_commands(:network, TestLab::Network) do |c|
|
167
24
|
|
168
25
|
# NETWORK STATUS
|
169
26
|
#################
|
@@ -173,27 +30,13 @@ Displays the status of all networks or single/multiple networks if supplied via
|
|
173
30
|
EOF
|
174
31
|
c.command :status do |status|
|
175
32
|
status.action do |global_options, options, args|
|
176
|
-
|
177
|
-
networks = Array.new
|
178
|
-
|
179
|
-
if options[:name].nil?
|
180
|
-
# No ID supplied; show everything
|
181
|
-
networks = TestLab::Network.all
|
182
|
-
else
|
183
|
-
# ID supplied; show just those items
|
184
|
-
names = options[:name].split(',')
|
185
|
-
networks = TestLab::Network.find(names)
|
186
|
-
(networks.nil? || (networks.count == 0)) and raise TestLab::TestLabError, "We could not find any of the networks you supplied!"
|
187
|
-
end
|
188
|
-
|
189
|
-
networks = networks.delete_if{ |network| network.node.dead? }
|
33
|
+
networks = iterate_objects_by_name(options[:name], TestLab::Network).delete_if{ |network| network.node.dead? }
|
190
34
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
end
|
35
|
+
if (networks.count == 0)
|
36
|
+
@testlab.ui.stderr.puts("You either have no networks defined or dead nodes!".yellow)
|
37
|
+
else
|
38
|
+
ZTK::Report.new(:ui => @testlab.ui).list(networks, TestLab::Network::STATUS_KEYS) do |network|
|
39
|
+
OpenStruct.new(network.status)
|
197
40
|
end
|
198
41
|
end
|
199
42
|
end
|
@@ -209,15 +52,12 @@ EOF
|
|
209
52
|
route.desc 'Add routes to lab networks'
|
210
53
|
route.command :add do |add|
|
211
54
|
add.action do |global_options,options,args|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
p.on_network_setup(network)
|
219
|
-
@testlab.ui.stdout.puts("Added routes successfully!".green.bold)
|
220
|
-
@testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
|
55
|
+
iterate_objects_by_name(options[:name], TestLab::Network) do |network|
|
56
|
+
p = TestLab::Provisioner::Route.new({}, @ui)
|
57
|
+
p.on_network_setup(network)
|
58
|
+
@testlab.ui.stdout.puts("Added routes successfully!".green.bold)
|
59
|
+
@testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
|
60
|
+
end
|
221
61
|
end
|
222
62
|
end
|
223
63
|
|
@@ -226,15 +66,12 @@ EOF
|
|
226
66
|
route.desc 'Delete routes to lab networks'
|
227
67
|
route.command :del do |del|
|
228
68
|
del.action do |global_options,options,args|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
p.on_network_teardown(network)
|
236
|
-
@testlab.ui.stdout.puts("Deleted routes successfully!".red.bold)
|
237
|
-
@testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
|
69
|
+
iterate_objects_by_name(options[:name], TestLab::Network) do |network|
|
70
|
+
p = TestLab::Provisioner::Route.new({}, @ui)
|
71
|
+
p.on_network_teardown(network)
|
72
|
+
@testlab.ui.stdout.puts("Deleted routes successfully!".red.bold)
|
73
|
+
@testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
|
74
|
+
end
|
238
75
|
end
|
239
76
|
end
|
240
77
|
|
@@ -243,17 +80,14 @@ EOF
|
|
243
80
|
route.desc 'Show routes to lab networks'
|
244
81
|
route.command :show do |show|
|
245
82
|
show.action do |global_options,options,args|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
@testlab.ui.stdout.puts %x(netstat -nrf inet | grep '#{network.node.ip}').strip
|
255
|
-
when /linux/ then
|
256
|
-
@testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
|
83
|
+
iterate_objects_by_name(options[:name], TestLab::Network) do |network|
|
84
|
+
@testlab.ui.stdout.puts("TestLab routes:".green.bold)
|
85
|
+
case RUBY_PLATFORM
|
86
|
+
when /darwin/ then
|
87
|
+
@testlab.ui.stdout.puts %x(netstat -nrf inet | grep '#{network.node.ip}').strip
|
88
|
+
when /linux/ then
|
89
|
+
@testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
|
90
|
+
end
|
257
91
|
end
|
258
92
|
end
|
259
93
|
end
|
data/lib/commands/node.rb
CHANGED
@@ -20,168 +20,20 @@
|
|
20
20
|
|
21
21
|
# NODES
|
22
22
|
########
|
23
|
-
|
24
|
-
arg_name 'Describe arguments to node here'
|
25
|
-
command :node do |c|
|
26
|
-
|
27
|
-
c.desc 'Node ID or Name'
|
28
|
-
c.arg_name 'node'
|
29
|
-
c.flag [:n, :name]
|
30
|
-
|
31
|
-
# NODE CREATE
|
32
|
-
##############
|
33
|
-
c.desc 'Create a node'
|
34
|
-
c.long_desc <<-EOF
|
35
|
-
Create a node. The node is created.
|
36
|
-
EOF
|
37
|
-
c.command :create do |create|
|
38
|
-
create.action do |global_options, options, args|
|
39
|
-
if options[:name].nil?
|
40
|
-
help_now!('a name is required') if options[:name].nil?
|
41
|
-
else
|
42
|
-
node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
43
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you screateplied!"
|
44
|
-
|
45
|
-
node.create
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# NODE DESTROY
|
51
|
-
############
|
52
|
-
c.desc 'Destroy a node'
|
53
|
-
c.long_desc <<-EOF
|
54
|
-
Destroy a node. The node is stopped and destroyed.
|
55
|
-
EOF
|
56
|
-
c.command :destroy do |destroy|
|
57
|
-
destroy.action do |global_options, options, args|
|
58
|
-
if options[:name].nil?
|
59
|
-
help_now!('a name is required') if options[:name].nil?
|
60
|
-
else
|
61
|
-
node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
62
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
|
63
|
-
|
64
|
-
node.destroy
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# NODE UP
|
70
|
-
##########
|
71
|
-
c.desc 'Up a node'
|
72
|
-
c.long_desc <<-EOF
|
73
|
-
Up a node. The node is started and brought online.
|
74
|
-
EOF
|
75
|
-
c.command :up do |up|
|
76
|
-
up.action do |global_options, options, args|
|
77
|
-
if options[:name].nil?
|
78
|
-
help_now!('a name is required') if options[:name].nil?
|
79
|
-
else
|
80
|
-
node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
81
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
|
82
|
-
|
83
|
-
node.up
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# NODE DOWN
|
89
|
-
############
|
90
|
-
c.desc 'Down a node'
|
91
|
-
c.long_desc <<-EOF
|
92
|
-
Down a node. The node is stopped taking it offline.
|
93
|
-
EOF
|
94
|
-
c.command :down do |down|
|
95
|
-
down.action do |global_options, options, args|
|
96
|
-
if options[:name].nil?
|
97
|
-
help_now!('a name is required') if options[:name].nil?
|
98
|
-
else
|
99
|
-
node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
100
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
|
101
|
-
|
102
|
-
node.down
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# NODE SETUP
|
108
|
-
#############
|
109
|
-
c.desc 'Setup a node'
|
110
|
-
c.long_desc <<-EOF
|
111
|
-
Setup a node. The node is created, started and provisioned.
|
112
|
-
EOF
|
113
|
-
c.command :setup do |setup|
|
114
|
-
setup.action do |global_options, options, args|
|
115
|
-
if options[:name].nil?
|
116
|
-
help_now!('a name is required') if options[:name].nil?
|
117
|
-
else
|
118
|
-
node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
119
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
|
120
|
-
|
121
|
-
node.setup
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# NODE TEARDOWN
|
127
|
-
################
|
128
|
-
c.desc 'Teardown a node'
|
129
|
-
c.long_desc <<-EOF
|
130
|
-
Teardown a node. The node is offlined and destroyed.
|
131
|
-
EOF
|
132
|
-
c.command :teardown do |teardown|
|
133
|
-
teardown.action do |global_options, options, args|
|
134
|
-
if options[:name].nil?
|
135
|
-
help_now!('a name is required') if options[:name].nil?
|
136
|
-
else
|
137
|
-
node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
138
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
|
139
|
-
|
140
|
-
node.teardown
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
# NODE BUILD
|
146
|
-
#############
|
147
|
-
c.desc 'Build a node'
|
148
|
-
c.long_desc <<-EOF
|
149
|
-
Attempts to build up the node. TestLab will attempt to create, online and provision the node.
|
150
|
-
|
151
|
-
The node is taken through the following phases:
|
152
|
-
|
153
|
-
Create -> Up -> Setup
|
154
|
-
EOF
|
155
|
-
c.command :build do |build|
|
156
|
-
build.action do |global_options, options, args|
|
157
|
-
if options[:name].nil?
|
158
|
-
help_now!('a name is required') if options[:name].nil?
|
159
|
-
else
|
160
|
-
node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
161
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
|
162
|
-
|
163
|
-
node.build
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
23
|
+
build_lab_commands(:node, TestLab::Node) do |c|
|
167
24
|
|
168
25
|
# NODE STATUS
|
169
26
|
##############
|
170
|
-
c.desc 'Display
|
27
|
+
c.desc 'Display nodes status'
|
171
28
|
c.long_desc 'Displays the status of all nodes or a single node if supplied via the ID parameter.'
|
172
29
|
c.command :status do |status|
|
173
30
|
status.action do |global_options, options, args|
|
174
|
-
|
175
|
-
# No ID supplied; show everything
|
176
|
-
ZTK::Report.new(:ui => @testlab.ui).list(@testlab.nodes, TestLab::Node::STATUS_KEYS) do |node|
|
177
|
-
OpenStruct.new(node.status)
|
178
|
-
end
|
179
|
-
else
|
180
|
-
# ID supplied; show just that item
|
181
|
-
node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first
|
182
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
|
31
|
+
nodes = iterate_objects_by_name(options[:name], TestLab::Node)
|
183
32
|
|
184
|
-
|
33
|
+
if (nodes.count == 0)
|
34
|
+
@testlab.ui.stderr.puts("You either have no nodes defined or dead nodes!".yellow)
|
35
|
+
else
|
36
|
+
ZTK::Report.new(:ui => @testlab.ui).list(nodes, TestLab::Node::STATUS_KEYS) do |node|
|
185
37
|
OpenStruct.new(node.status)
|
186
38
|
end
|
187
39
|
end
|
@@ -190,13 +42,10 @@ EOF
|
|
190
42
|
|
191
43
|
# NODE SSH
|
192
44
|
###########
|
193
|
-
c.desc '
|
45
|
+
c.desc 'Node SSH console'
|
194
46
|
c.command :ssh do |ssh|
|
195
47
|
ssh.action do |global_options,options,args|
|
196
|
-
|
197
|
-
|
198
|
-
node = @testlab.nodes.select{ |n| n.id.to_sym == options[:name].to_sym }.first
|
199
|
-
node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
|
48
|
+
node = iterate_objects_by_name(options[:name], TestLab::Node).first
|
200
49
|
|
201
50
|
node.ssh.console
|
202
51
|
end
|
data/lib/commands/testlab.rb
CHANGED
@@ -20,7 +20,14 @@
|
|
20
20
|
|
21
21
|
# LAB CREATE
|
22
22
|
#############
|
23
|
-
desc 'Create the
|
23
|
+
desc 'Create the lab components'
|
24
|
+
long_desc <<-EOF
|
25
|
+
Attempts to create the defined lab components.
|
26
|
+
|
27
|
+
The components are created in the following order:
|
28
|
+
|
29
|
+
Nodes -> Networks -> Containers
|
30
|
+
EOF
|
24
31
|
command :create do |create|
|
25
32
|
create.action do |global_options,options,args|
|
26
33
|
@testlab.create
|
@@ -29,7 +36,14 @@ end
|
|
29
36
|
|
30
37
|
# LAB DESTROY
|
31
38
|
##############
|
32
|
-
desc 'Destroy the
|
39
|
+
desc 'Destroy the lab components'
|
40
|
+
long_desc <<-EOF
|
41
|
+
Attempts to destroy the defined lab components.
|
42
|
+
|
43
|
+
The components are destroyed in the following order:
|
44
|
+
|
45
|
+
Nodes -> Networks -> Containers
|
46
|
+
EOF
|
33
47
|
command :destroy do |destroy|
|
34
48
|
destroy.action do |global_options,options,args|
|
35
49
|
@testlab.destroy
|
@@ -38,7 +52,14 @@ end
|
|
38
52
|
|
39
53
|
# LAB ONLINE
|
40
54
|
#############
|
41
|
-
desc '
|
55
|
+
desc 'On-line the lab components'
|
56
|
+
long_desc <<-EOF
|
57
|
+
Attempts to online the defined lab components.
|
58
|
+
|
59
|
+
The components are onlined in the following order:
|
60
|
+
|
61
|
+
Nodes -> Networks -> Containers
|
62
|
+
EOF
|
42
63
|
command :up do |up|
|
43
64
|
up.action do |global_options,options,args|
|
44
65
|
@testlab.up
|
@@ -47,7 +68,14 @@ end
|
|
47
68
|
|
48
69
|
# LAB OFFLINE
|
49
70
|
##############
|
50
|
-
desc '
|
71
|
+
desc 'Off-line the lab components'
|
72
|
+
long_desc <<-EOF
|
73
|
+
Attempts to offline the defined lab components.
|
74
|
+
|
75
|
+
The components are offlined in the following order:
|
76
|
+
|
77
|
+
Containers -> Networks -> Nodes
|
78
|
+
EOF
|
51
79
|
command :down do |down|
|
52
80
|
down.action do |global_options,options,args|
|
53
81
|
@testlab.down
|
@@ -56,7 +84,14 @@ end
|
|
56
84
|
|
57
85
|
# LAB SETUP
|
58
86
|
############
|
59
|
-
desc '
|
87
|
+
desc 'Provision the lab components'
|
88
|
+
long_desc <<-EOF
|
89
|
+
Attempts to setup the defined lab components.
|
90
|
+
|
91
|
+
The components are set up in the following order:
|
92
|
+
|
93
|
+
Nodes -> Networks -> Containers
|
94
|
+
EOF
|
60
95
|
command :setup do |setup|
|
61
96
|
setup.action do |global_options,options,args|
|
62
97
|
@testlab.setup
|
@@ -65,7 +100,14 @@ end
|
|
65
100
|
|
66
101
|
# LAB TEARDOWN
|
67
102
|
###############
|
68
|
-
desc '
|
103
|
+
desc 'De-provision the lab components'
|
104
|
+
long_desc <<-EOF
|
105
|
+
Attempts to teardown the defined lab components.
|
106
|
+
|
107
|
+
The components are torndown in the following order:
|
108
|
+
|
109
|
+
Containers -> Networks -> Nodes
|
110
|
+
EOF
|
69
111
|
command :teardown do |teardown|
|
70
112
|
teardown.action do |global_options,options,args|
|
71
113
|
@testlab.teardown
|
@@ -74,15 +116,15 @@ end
|
|
74
116
|
|
75
117
|
# LAB BUILD
|
76
118
|
############
|
77
|
-
desc 'Build the
|
119
|
+
desc 'Build the lab'
|
78
120
|
long_desc <<-EOF
|
79
|
-
Attempts to build the defined
|
121
|
+
Attempts to build the defined lab. TestLab will attempt to create, online and provision the lab components.
|
80
122
|
|
81
123
|
The components are built in the following order:
|
82
124
|
|
83
125
|
Nodes -> Networks -> Containers
|
84
126
|
|
85
|
-
TestLab will then attempt to build the
|
127
|
+
TestLab will then attempt to build the components, executing the following tasks for each:
|
86
128
|
|
87
129
|
Create -> Up -> Setup
|
88
130
|
EOF
|
@@ -92,9 +134,29 @@ command :build do |build|
|
|
92
134
|
end
|
93
135
|
end
|
94
136
|
|
137
|
+
# LAB DEMOLISH
|
138
|
+
###############
|
139
|
+
desc 'Demolish the lab'
|
140
|
+
long_desc <<-EOF
|
141
|
+
Attempts to demolish the defined lab. TestLab will attempt to deprovision, offline and destroy the lab components.
|
142
|
+
|
143
|
+
The components are demolished in the following order:
|
144
|
+
|
145
|
+
Containers -> Networks -> Nodes
|
146
|
+
|
147
|
+
TestLab will then attempt to demolish the components, executing the following tasks for each:
|
148
|
+
|
149
|
+
Teardown -> Down -> Destroy
|
150
|
+
EOF
|
151
|
+
command :demolish do |demolish|
|
152
|
+
demolish.action do |global_options,options,args|
|
153
|
+
@testlab.demolish
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
95
157
|
# LAB STATUS
|
96
158
|
#############
|
97
|
-
desc 'Display
|
159
|
+
desc 'Display the lab status'
|
98
160
|
command :status do |status|
|
99
161
|
status.action do |global_options,options,args|
|
100
162
|
@testlab.ui.stdout.puts("\nNODES:".green.bold)
|
@@ -12,7 +12,7 @@ class TestLab
|
|
12
12
|
def create
|
13
13
|
@ui.logger.debug { "Container Create: #{self.id} " }
|
14
14
|
|
15
|
-
(self.node.state
|
15
|
+
(self.node.state != :running) and return false
|
16
16
|
(self.lxc.state != :not_created) and return false
|
17
17
|
|
18
18
|
please_wait(:ui => @ui, :message => format_object_action(self, 'Create', :green)) do
|
@@ -32,7 +32,7 @@ class TestLab
|
|
32
32
|
def destroy
|
33
33
|
@ui.logger.debug { "Container Destroy: #{self.id} " }
|
34
34
|
|
35
|
-
(self.node.state
|
35
|
+
(self.node.state != :running) and return false
|
36
36
|
(self.lxc.state == :not_created) and return false
|
37
37
|
|
38
38
|
please_wait(:ui => @ui, :message => format_object_action(self, 'Destroy', :red)) do
|
data/lib/testlab/container/io.rb
CHANGED
@@ -2,6 +2,7 @@ class TestLab
|
|
2
2
|
class Container
|
3
3
|
|
4
4
|
module IO
|
5
|
+
require 'tempfile'
|
5
6
|
PBZIP2_MEMORY = 256
|
6
7
|
|
7
8
|
# Export the container
|
@@ -14,8 +15,12 @@ class TestLab
|
|
14
15
|
|
15
16
|
self.down
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
export_tempfile = Tempfile.new('export')
|
19
|
+
remote_filename = File.basename(export_tempfile.path.dup)
|
20
|
+
export_tempfile.close!
|
21
|
+
|
22
|
+
remote_file = File.join("", "tmp", remote_filename)
|
23
|
+
local_file ||= File.join(Dir.pwd, File.basename(remote_file))
|
19
24
|
local_file = File.expand_path(local_file)
|
20
25
|
|
21
26
|
please_wait(:ui => @ui, :message => format_object_action(self, 'Compress', :cyan)) do
|
@@ -24,15 +29,15 @@ set -x
|
|
24
29
|
set -e
|
25
30
|
|
26
31
|
du -sh #{self.lxc.container_root}
|
27
|
-
find #{self.lxc.container_root} -print0 -depth | cpio -o0 | pbzip2 -#{compression} -vfczm#{PBZIP2_MEMORY} > #{
|
28
|
-
chown ${SUDO_USER}:${SUDO_USER} #{
|
29
|
-
ls -lah #{
|
32
|
+
find #{self.lxc.container_root} -print0 -depth | cpio -o0 | pbzip2 -#{compression} -vfczm#{PBZIP2_MEMORY} > #{remote_file}
|
33
|
+
chown ${SUDO_USER}:${SUDO_USER} #{remote_file}
|
34
|
+
ls -lah #{remote_file}
|
30
35
|
EOF
|
31
36
|
end
|
32
37
|
|
33
38
|
please_wait(:ui => @ui, :message => format_object_action(self, 'Export', :cyan)) do
|
34
39
|
File.exists?(local_file) and FileUtils.rm_f(local_file)
|
35
|
-
self.node.ssh.download(
|
40
|
+
self.node.ssh.download(remote_file, local_file)
|
36
41
|
end
|
37
42
|
|
38
43
|
puts("Your shipping container is now exported and available at '#{local_file}'!")
|
@@ -49,12 +54,16 @@ EOF
|
|
49
54
|
self.down
|
50
55
|
self.destroy
|
51
56
|
|
52
|
-
|
53
|
-
|
57
|
+
import_tempfile = Tempfile.new('import')
|
58
|
+
remote_filename = File.basename(import_tempfile.path.dup)
|
59
|
+
import_tempfile.close!
|
60
|
+
|
61
|
+
remote_file = File.join("", "tmp", remote_filename)
|
62
|
+
local_file = File.expand_path(local_file)
|
54
63
|
|
55
64
|
please_wait(:ui => @ui, :message => format_object_action(self, 'Import', :cyan)) do
|
56
|
-
self.node.ssh.exec(%(sudo rm -fv #{
|
57
|
-
self.node.ssh.upload(local_file,
|
65
|
+
self.node.ssh.exec(%(sudo rm -fv #{remote_file}), :silence => true, :ignore_exit_status => true)
|
66
|
+
self.node.ssh.upload(local_file, remote_file)
|
58
67
|
end
|
59
68
|
|
60
69
|
please_wait(:ui => @ui, :message => format_object_action(self, 'Expand', :cyan)) do
|
@@ -62,8 +71,8 @@ EOF
|
|
62
71
|
set -x
|
63
72
|
set -e
|
64
73
|
|
65
|
-
ls -lah #{
|
66
|
-
pbzip2 -vdcm#{PBZIP2_MEMORY} #{
|
74
|
+
ls -lah #{remote_file}
|
75
|
+
pbzip2 -vdcm#{PBZIP2_MEMORY} #{remote_file} | cpio -uid && rm -fv #{remote_file}
|
67
76
|
du -sh #{self.lxc.container_root}
|
68
77
|
EOF
|
69
78
|
end
|