testlab 1.18.1 → 1.19.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTBiNzQ4NzUwY2JlYWVjMTE0NzcwNmMwYzM0OTQ3ZTY2OTQwZDIzOQ==
4
+ NjQ3NDM1Njk2ZWQwMjJmMDU0MWMyODcxNTk1OWVlYTExODFlZmQ0Yw==
5
5
  data.tar.gz: !binary |-
6
- M2RhODk4NGFjYjViYjE2NzEwMTE2Nzg2OGI0NTMyMGY0NGIzMWFhMA==
6
+ N2NlZjBhNTdkYTVmYjMxODg5NmQzZTJmNzFiZDAyNGQ1YjMxODBmMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDBmN2Q5OGQ3OGY4MTgxNGM1MDFmNzY4MzU1MjMwNWFmMzFmYzM4NjM1NTdj
10
- OTFlZTYyNTUxMmQ0YTA4ZTM3NWJjMDI2YmMyZWE1MzYxYzZhYjgyMzgwOGJk
11
- MTVjOTUwNTgyOGJkOTM4ODk0NTgwYmQ4MDgyNDY1NDc5MGMyODI=
9
+ ZWEyOGQyNzM4NDQ1ZGU1MmVjYTBlMzUyZTU5ZTA4MzgyMzc2NTM4NDBmZmI2
10
+ YWZmZDM1YmE1Mjc1MjQyMWUxNmVhNzI2M2I0NTRlYTgwNTNjMTRjOGQ3MGI3
11
+ ODcyM2Y0NWI1NWQ0NjRiNzliMWIwY2Y4ZGJhMDkyNTY4MzAwMzM=
12
12
  data.tar.gz: !binary |-
13
- OTRiNTBjN2UxMzQzMjAyZGJmNThjN2VkM2I1ZDEzYmZlOTUzMjRhNjdjMjNl
14
- NzdkYzIxNTYxMmYzNzkxNTQ3MTcwMGI1MDlmNDI5ZWU5ZTJmMGEyZjFlNDk4
15
- ZjIyZmNiM2Y0NThiYmU4M2UxMmUzZGI5ZTE4ZGY1MTQ2OTM0NTE=
13
+ M2UxMThlZTIwOGZkODE2YjNkNjMwYzEwNWRjMjdkNTNjMDZiZTNmODk2ZDdk
14
+ MDkxMmMzODRjNWMzOTUzZWY1MjQ4ZDM3ZjE5OTVlMmYzNmM2M2Q3YTdhZTcy
15
+ ZmUxODNhYzUzOGE1NTc5ZTM5MWM0ZmQwMTE4NWU3YWYyZWRkM2I=
data/bin/tl CHANGED
@@ -74,11 +74,11 @@ require 'commands/container'
74
74
 
75
75
  # commands_from 'commands'
76
76
 
77
- desc 'Show verbose output'
77
+ desc 'Verbose output (or set VERBOSE=1 in your environment)'
78
78
  default_value false
79
79
  switch [:v, :verbose]
80
80
 
81
- desc 'Quiet mode'
81
+ desc 'Quiet output (or set QUIET=1 in your environment)'
82
82
  default_value false
83
83
  switch [:q, :quiet]
84
84
 
@@ -95,19 +95,27 @@ arg_name 'path/to/directory'
95
95
  flag [:c, :config]
96
96
 
97
97
  desc 'Path to Log file'
98
- default_value STDOUT
98
+ default_value DEFAULT_LOG_FILE
99
99
  arg_name 'path/to/log_file'
100
100
  flag [:log]
101
101
 
102
102
  pre do |global,command,options,args|
103
103
  @testlab_start_time = Time.now.utc
104
+ @verbose = ((ENV['VERBOSE'] == '1') || (global[:verbose] == true))
105
+ @quiet = ((ENV['QUIET'] == '1') || (global[:quiet] == true))
104
106
 
105
- (global[:verbose] == true) and (ENV['LOG_LEVEL'] = 'DEBUG')
107
+ (@verbose == true) and (ENV['LOG_LEVEL'] = 'DEBUG')
108
+
109
+ File.exists?(global[:log]) and FileUtils.move(global[:log], DEFAULT_LOG_BACKUP)
110
+ logger = ZTK::Logger.new(global[:log])
111
+ if ((@verbose == true) || (@quiet == false))
112
+ logger.loggers << ::Logger.new(STDOUT)
113
+ end
106
114
 
107
115
  @ui = ZTK::UI.new(
108
- :logger => ZTK::Logger.new(global[:log]),
109
- :verbose => global[:verbose],
110
- :quiet => global[:quiet]
116
+ :logger => logger,
117
+ :verbose => @verbose,
118
+ :quiet => @quiet
111
119
  )
112
120
 
113
121
  @ui.logger.debug { "global(#{global.inspect})" }
@@ -141,6 +149,8 @@ post do |global,command,options,args|
141
149
  @ui.logger.info { message }
142
150
  end
143
151
 
152
+ File.exists?(DEFAULT_DUMP_FILE) and File.delete(DEFAULT_DUMP_FILE)
153
+
144
154
  true
145
155
  end
146
156
 
@@ -159,12 +169,22 @@ on_error do |exception|
159
169
  else
160
170
  testlab_run_time = (Time.now.utc - @testlab_start_time)
161
171
 
172
+ dump_file = File.open(DEFAULT_DUMP_FILE, 'w')
173
+
174
+ if !@testlab.nil?
175
+ TestLab::Utility.log_header(@testlab).each { |line| dump_file.puts(line) }
176
+ end
177
+
178
+ dump_file.puts(exception.inspect)
162
179
  @ui.logger.fatal { exception.inspect }
180
+
163
181
  exception.backtrace.each do |line|
164
- @ui.logger.logdev.write("#{line}\n")
182
+ dump_file.puts(line)
183
+ @ui.logger << "#{line}\n"
165
184
  end
166
185
 
167
186
  message = format_message("TestLab v#{TestLab::VERSION} Aborted (%0.4f seconds)".black.bold % testlab_run_time)
187
+ dump_file.puts(ZTK::ANSI.uncolor(message))
168
188
  @ui.stderr.puts(message)
169
189
  @ui.logger.info { message }
170
190
 
@@ -46,17 +46,26 @@ def build_lab_commands(component, klass, &block)
46
46
  c.arg_name %(#{component}[,#{component},...])
47
47
  c.flag [:n, :name]
48
48
 
49
+ c.desc %(Force the actions verbatium, do not attempt to infer shortcuts; this has no effect for most operations)
50
+ c.switch [:f, :force]
51
+
49
52
  LAB_ACTION_ORDER.each do |lab_action|
50
53
  action_desc = LAB_ACTIONS[lab_action]
51
54
  c.desc(action_desc.first % "#{component}s")
52
55
  c.long_desc(ZTK::Template.string(action_desc.last, {:component => "#{component}s"}))
53
56
 
54
57
  c.command lab_action do |la|
58
+
55
59
  la.action do |global_options, options, args|
56
60
  iterate_objects_by_name(options[:name], klass) do |object|
57
- object.send(lab_action)
61
+ if %w( build recycle ).map(&:to_sym).include?(lab_action)
62
+ object.send(lab_action, options[:force])
63
+ else
64
+ object.send(lab_action)
65
+ end
58
66
  end
59
67
  end
68
+
60
69
  end
61
70
  end
62
71
 
@@ -33,7 +33,7 @@ TestLab will then attempt to build the components, executing the following tasks
33
33
  Create -> Up -> Provision
34
34
  EOF
35
35
  command :build do |build|
36
- build.action do |global_options,options,args|
36
+ build.action do |global_options, options, args|
37
37
  @testlab.build
38
38
  end
39
39
  end
@@ -53,7 +53,7 @@ TestLab will then attempt to demolish the components, executing the following ta
53
53
  Deprovision -> Down -> Destroy
54
54
  EOF
55
55
  command :demolish do |demolish|
56
- demolish.action do |global_options,options,args|
56
+ demolish.action do |global_options, options, args|
57
57
  @testlab.demolish
58
58
  end
59
59
  end
@@ -73,7 +73,7 @@ Then components are onlined in the following order:
73
73
  Nodes -> Networks -> Containers
74
74
  EOF
75
75
  command :bounce do |bounce|
76
- bounce.action do |global_options,options,args|
76
+ bounce.action do |global_options, options, args|
77
77
  @testlab.bounce
78
78
  end
79
79
  end
@@ -93,7 +93,7 @@ Then components are built in the following order:
93
93
  Nodes -> Networks -> Containers
94
94
  EOF
95
95
  command :recycle do |recycle|
96
- recycle.action do |global_options,options,args|
96
+ recycle.action do |global_options, options, args|
97
97
  @testlab.recycle
98
98
  end
99
99
  end
@@ -109,7 +109,7 @@ The components are created in the following order:
109
109
  Nodes -> Networks -> Containers
110
110
  EOF
111
111
  command :create do |create|
112
- create.action do |global_options,options,args|
112
+ create.action do |global_options, options, args|
113
113
  @testlab.create
114
114
  end
115
115
  end
@@ -125,7 +125,7 @@ The components are destroyed in the following order:
125
125
  Nodes -> Networks -> Containers
126
126
  EOF
127
127
  command :destroy do |destroy|
128
- destroy.action do |global_options,options,args|
128
+ destroy.action do |global_options, options, args|
129
129
  @testlab.destroy
130
130
  end
131
131
  end
@@ -141,7 +141,7 @@ The components are onlined in the following order:
141
141
  Nodes -> Networks -> Containers
142
142
  EOF
143
143
  command :up do |up|
144
- up.action do |global_options,options,args|
144
+ up.action do |global_options, options, rgs|
145
145
  @testlab.up
146
146
  end
147
147
  end
@@ -157,7 +157,7 @@ The components are offlined in the following order:
157
157
  Containers -> Networks -> Nodes
158
158
  EOF
159
159
  command :down do |down|
160
- down.action do |global_options,options,args|
160
+ down.action do |global_options, options, args|
161
161
  @testlab.down
162
162
  end
163
163
  end
@@ -173,7 +173,7 @@ The components are provisioned in the following order:
173
173
  Nodes -> Networks -> Containers
174
174
  EOF
175
175
  command :provision do |provision|
176
- provision.action do |global_options,options,args|
176
+ provision.action do |global_options, options, args|
177
177
  @testlab.provision
178
178
  end
179
179
  end
@@ -189,7 +189,7 @@ The components are torndown in the following order:
189
189
  Containers -> Networks -> Nodes
190
190
  EOF
191
191
  command :deprovision do |deprovision|
192
- deprovision.action do |global_options,options,args|
192
+ deprovision.action do |global_options, options, args|
193
193
  @testlab.deprovision
194
194
  end
195
195
  end
@@ -198,7 +198,7 @@ end
198
198
  #############
199
199
  desc 'Display the lab status'
200
200
  command :status do |status|
201
- status.action do |global_options,options,args|
201
+ status.action do |global_options, options, args|
202
202
  @testlab.ui.logger.level = ZTK::Logger::WARN
203
203
  @testlab.ui.stdout.puts("\nNODES:".green.bold)
204
204
  commands[:node].commands[:status].execute({}, {}, [])
@@ -211,6 +211,25 @@ command :status do |status|
211
211
  end
212
212
  end
213
213
 
214
+ # LAB BUG REPORT
215
+ #################
216
+ desc 'Generate a lab bug report'
217
+ command :bugreport do |bugreport|
218
+ bugreport.action do |global_options, options, args|
219
+ @testlab.ui.logger.level = ZTK::Logger::FATAL
220
+
221
+ report_file = File.join("", "tmp", "testlab-bug-report.#{Time.now.utc.to_i}")
222
+
223
+ content = Array.new
224
+ content << (IO.read(DEFAULT_DUMP_FILE) rescue nil)
225
+ content << ("#{'=' * 30} TestLab Log #{'=' * 30}")
226
+ content << IO.read(DEFAULT_LOG_BACKUP)
227
+
228
+ IO.write(report_file, content.flatten.compact.join("\n"))
229
+
230
+ @testlab.ui.stdout.puts("The bug report for your most recent execution of TestLab is located at #{report_file.inspect}.")
231
+ end
232
+ end
214
233
 
215
234
  # LAB DOCTOR
216
235
  #############
data/lib/testlab.rb CHANGED
@@ -7,6 +7,7 @@ require 'lxc'
7
7
  require 'active_support/inflector'
8
8
 
9
9
  require 'testlab/version'
10
+ require 'testlab/const'
10
11
  require 'testlab/monkeys'
11
12
 
12
13
  # TestLab - A framework for building lightweight virtual infrastructure using LXC
@@ -153,9 +154,6 @@ class TestLab
153
154
 
154
155
  @config_dir = (options[:config_dir] || File.join(@repo_dir, ".testlab-#{TestLab.hostname}"))
155
156
  File.exists?(@config_dir) or FileUtils.mkdir_p(@config_dir)
156
-
157
- # @log_file = (options[:log_file] || File.join(@repo_dir, "testlab-#{TestLab.hostname}.log") || STDOUT)
158
- # self.ui.logger = ZTK::Logger.new(@log_file)
159
157
  end
160
158
 
161
159
  # Boot TestLab
@@ -0,0 +1,11 @@
1
+ unless defined?(DEFAULT_DUMP_FILE)
2
+ DEFAULT_DUMP_FILE = File.join('', 'tmp', 'testlab.dump')
3
+ end
4
+
5
+ unless defined?(DEFAULT_LOG_FILE)
6
+ DEFAULT_LOG_FILE = File.join('', 'tmp', 'testlab.log')
7
+ end
8
+
9
+ unless defined?(DEFAULT_LOG_BACKUP)
10
+ DEFAULT_LOG_BACKUP = File.join('', 'tmp', 'testlab.log.bak')
11
+ end
@@ -114,7 +114,7 @@ class TestLab
114
114
  # Import the container
115
115
  #
116
116
  # @return [Boolean] True if successful.
117
- def import(local_file)
117
+ def import(local_file=nil)
118
118
  @ui.logger.debug { "Container Import: #{self.id}" }
119
119
 
120
120
  self.node.alive? or return false
@@ -141,8 +141,8 @@ class TestLab
141
141
  # Ensure we are not in ephemeral mode.
142
142
  self.persistent
143
143
 
144
- self.down
145
- self.destroy
144
+ (self.state == :running) and self.down
145
+ self.exists? and self.destroy
146
146
 
147
147
  self.create
148
148
 
@@ -4,10 +4,14 @@ class TestLab
4
4
  module Lifecycle
5
5
 
6
6
  # Build the object
7
- def build
8
- create
9
- up
10
- provision
7
+ def build(force=false)
8
+ if (force == false) and self.respond_to?(:importable?) and self.respond_to?(:import) and (self.importable? == true)
9
+ import
10
+ else
11
+ create
12
+ up
13
+ provision
14
+ end
11
15
 
12
16
  true
13
17
  end
@@ -22,9 +26,9 @@ class TestLab
22
26
  end
23
27
 
24
28
  # Recycle the object
25
- def recycle
29
+ def recycle(force=false)
26
30
  demolish
27
- build
31
+ build(force)
28
32
 
29
33
  true
30
34
  end
@@ -25,7 +25,7 @@ class TestLab
25
25
  "config_dir" => testlab.config_dir.inspect,
26
26
  "repo_dir" => testlab.repo_dir.inspect,
27
27
  "labfile_path" => testlab.labfile_path.inspect,
28
- "logdev" => testlab.ui.logger.logdev.inspect,
28
+ "logdev" => testlab.ui.logger.instance_variable_get(:@logdev).inspect,
29
29
  "version" => TestLab::VERSION.inspect,
30
30
  }
31
31
  end
@@ -26,27 +26,29 @@ class TestLab
26
26
  end
27
27
 
28
28
  def please_wait(options={}, &block)
29
- ui = options[:ui]
30
- message = options[:message]
31
- mark = (options[:mark] || "Completed in %0.4f seconds!")
29
+ ui = options[:ui]
30
+ message = options[:message]
31
+ mark = (options[:mark] || "Completed in %0.4f seconds!")
32
32
 
33
33
  !block_given? and raise MiscError, "You must supply a block!"
34
34
  ui.nil? and raise MiscError, "You must supply a ZTK::UI object!"
35
35
  message.nil? and raise MiscError, "You must supply a message!"
36
36
 
37
- if (ui.logger.logdev == STDOUT)
38
- mark = format_message("#{message} / #{mark.black.bold}")
39
- message = format_message(message)
40
- else
41
- message = format_message(message)
42
- length = message.uncolor.length
43
- max = (length >= 60 ? (length+1) : (60 - length))
44
- mark = ((' ' * max) + "# #{mark}".black.bold)
37
+ use_spinner = true
38
+ msg = format_message("#{message} ")
39
+ length = msg.uncolor.length
40
+ max = (length >= 60 ? (length+1) : (60 - length))
41
+ mrk = ((' ' * max) + "# #{mark}\n".bold)
42
+
43
+ if (ui.logger.respond_to?(:loggers) && ui.logger.loggers.is_a?(Array))
44
+ if ui.logger.loggers.count > 1
45
+ use_spinner = false
46
+ mrk = format_message("#{message} / #{mark.bold}\n")
47
+ msg = format_message("#{message}\n")
48
+ end
45
49
  end
46
- use_spinner = ((ui.logger.logdev == STDOUT) ? false : true)
47
50
 
48
- ZTK::Benchmark.bench(:ui => ui, :message => message, :mark => mark, :use_spinner => use_spinner) do
49
- (ui.logger.logdev == STDOUT) and STDOUT.puts
51
+ ZTK::Benchmark.bench(:ui => ui, :message => msg, :mark => mrk, :use_spinner => use_spinner) do
50
52
  yield
51
53
  end
52
54
  end
@@ -1,6 +1,6 @@
1
1
  class TestLab
2
2
  unless const_defined?(:VERSION)
3
3
  # TestLab Gem Version
4
- VERSION = "1.18.1"
4
+ VERSION = "1.19.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.1
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Patten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-01 00:00:00.000000000 Z
11
+ date: 2014-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -271,6 +271,7 @@ files:
271
271
  - lib/commands/support.rb
272
272
  - lib/commands/testlab.rb
273
273
  - lib/testlab.rb
274
+ - lib/testlab/const.rb
274
275
  - lib/testlab/container.rb
275
276
  - lib/testlab/container/actions.rb
276
277
  - lib/testlab/container/class_methods.rb
@@ -388,7 +389,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
388
389
  version: '0'
389
390
  requirements: []
390
391
  rubyforge_project:
391
- rubygems_version: 2.2.1
392
+ rubygems_version: 2.1.11
392
393
  signing_key:
393
394
  specification_version: 4
394
395
  summary: A toolkit for building virtual computer labs