testlab 1.8.2 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,26 @@ class TestLab
10
10
  READ_SIZE = ((64 * 1024) - 1)
11
11
  TRANSFER_MESSAGE = "transferring '%s' at %0.2fMB/s -- %0.2fMB of %0.2fMB -- %d%% (%01d:%02dT-%01d:%02d) \r"
12
12
 
13
+ def transfer_message(filename, current_size, total_size, elapsed)
14
+ total_size_mb = (total_size.to_f / (1024 * 1024).to_f)
15
+ current_size_mb = (current_size.to_f / (1024 * 1024).to_f)
16
+
17
+ speed = (current_size.to_f / elapsed.to_f)
18
+ speed = total_size.to_f if (speed == 0.0)
19
+ speed_mb = speed.to_f / (1024 * 1024).to_f
20
+
21
+ minutes = elapsed.div(60)
22
+ seconds = elapsed.modulo(60)
23
+
24
+ estimated = ((total_size.to_f - current_size.to_f) / speed.to_f)
25
+ est_minutes = estimated.div(60)
26
+ est_seconds = estimated.modulo(60)
27
+
28
+ percentage_done = ((current_size * 100) / total_size)
29
+
30
+ @ui.stdout.print(format_message(TRANSFER_MESSAGE.yellow % [File.basename(filename), speed_mb, current_size_mb, total_size_mb, percentage_done, minutes, seconds, est_minutes, est_seconds]))
31
+ end
32
+
13
33
  def progress_callback(action, args)
14
34
  @total_size ||= 0
15
35
 
@@ -18,28 +38,13 @@ class TestLab
18
38
  @start_time = Time.now
19
39
  if (@total_size == 0)
20
40
  @total_size = args[0].size
21
- @total_size_mb = (@total_size.to_f / (1024 * 1024).to_f)
22
41
  end
23
42
 
24
43
  when :get, :put then
25
- elapsed = (Time.now - @start_time)
26
-
44
+ elapsed = (Time.now - @start_time)
27
45
  current_size = (args[1] + args[2].length)
28
- current_size_mb = (current_size.to_f / (1024 * 1024).to_f)
29
46
 
30
- speed = (current_size.to_f / elapsed.to_f)
31
- speed_mb = speed / (1024 * 1024).to_f
32
-
33
- minutes = elapsed.div(60)
34
- seconds = elapsed.modulo(60)
35
-
36
- estimated = ((@total_size.to_f - current_size).to_f / speed)
37
- est_minutes = estimated.div(60)
38
- est_seconds = estimated.modulo(60)
39
-
40
- percentage_done = ((current_size * 100) / @total_size)
41
-
42
- @ui.stdout.print(format_message(TRANSFER_MESSAGE.yellow % [File.basename(args[0].local), speed_mb, current_size_mb, @total_size_mb, percentage_done, minutes, seconds, est_minutes, est_seconds]))
47
+ transfer_message(args[0].local, current_size, @total_size, elapsed)
43
48
 
44
49
  when :finish
45
50
  @ui.stdout.puts
@@ -93,7 +98,6 @@ EOF
93
98
  File.exists?(local_file) and FileUtils.rm_f(local_file)
94
99
 
95
100
  @total_size = self.node.ssh.sftp.stat!(remote_file).size
96
- @total_size_mb = (@total_size.to_f / (1024 * 1024).to_f)
97
101
 
98
102
  self.node.download(remote_file, local_file, :on_progress => method(:progress_callback), :read_size => READ_SIZE)
99
103
 
@@ -238,34 +242,16 @@ EOF
238
242
  tempfile.binmode
239
243
 
240
244
  current_size = 0
241
- progress = 0
242
- total_size = response['content-length'].to_i
243
- total_size_mb = total_size.to_f / (1024 * 1024).to_f
245
+ total_size = response['content-length'].to_i
246
+ start_time = Time.now
244
247
 
245
- start_time = Time.now
246
248
  response.read_body do |chunk|
247
249
  tempfile << chunk
248
250
 
251
+ elapsed = (Time.now - start_time)
249
252
  current_size += chunk.size
250
- current_size_mb = current_size.to_f / (1024 * 1024).to_f
251
-
252
- new_progress = (current_size * 100) / total_size
253
- unless new_progress == progress
254
- elapsed = (Time.now - start_time)
255
-
256
- speed = (current_size.to_f / elapsed.to_f)
257
- speed_mb = speed / (1024 * 1024).to_f
258
-
259
- minutes = elapsed.div(60)
260
- seconds = elapsed.modulo(60)
261
-
262
- estimated = ((total_size.to_f - current_size).to_f / speed)
263
- est_minutes = estimated.div(60)
264
- est_seconds = estimated.modulo(60)
265
253
 
266
- @ui.stdout.print(format_message(TRANSFER_MESSAGE.yellow % [File.basename(local_file), speed_mb, current_size_mb, total_size_mb, new_progress, minutes, seconds, est_minutes, est_seconds]))
267
- end
268
- progress = new_progress
254
+ transfer_message(local_file, current_size, total_size, elapsed)
269
255
  end
270
256
  @ui.stdout.puts
271
257
 
@@ -56,6 +56,8 @@ class TestLab
56
56
  :mode => self.mode,
57
57
  :fqdn => self.fqdn,
58
58
  :state => self.state,
59
+ :memory_usage => "#{self.memory_usage}M",
60
+ :cpu_time => "#{self.cpu_usage}s",
59
61
  :distro => self.distro,
60
62
  :release => self.release,
61
63
  :interfaces => interfaces,
@@ -65,6 +67,24 @@ class TestLab
65
67
  }
66
68
  end
67
69
 
70
+ # Container Memory Usage
71
+ def memory_usage
72
+ if self.node.dead?
73
+ 0
74
+ else
75
+ self.lxc.memory_usage / (1024 * 1024)
76
+ end
77
+ end
78
+
79
+ # Container CPU Time
80
+ def cpu_usage
81
+ if self.node.dead?
82
+ 0
83
+ else
84
+ self.lxc.cpu_usage
85
+ end
86
+ end
87
+
68
88
  # Container State
69
89
  #
70
90
  # What state the container is in.
@@ -72,7 +72,7 @@ class TestLab
72
72
  # An array of symbols of the various keys in our status hash.
73
73
  #
74
74
  # @see TestLab::Container::Status
75
- STATUS_KEYS = %w(id node_id mode fqdn state distro release interfaces provisioners inherited).map(&:to_sym)
75
+ STATUS_KEYS = %w(id node_id cpu_time memory_usage mode fqdn state distro release interfaces provisioners inherited).map(&:to_sym)
76
76
 
77
77
  # Sub-Modules
78
78
  autoload :Actions, 'testlab/container/actions'
@@ -1,6 +1,6 @@
1
1
  class TestLab
2
2
  unless const_defined?(:VERSION)
3
3
  # TestLab Gem Version
4
- VERSION = "1.8.2"
4
+ VERSION = "1.8.3"
5
5
  end
6
6
  end
@@ -56,6 +56,8 @@ describe TestLab::Container do
56
56
  subject.node.stub(:dead?) { false }
57
57
  subject.node.stub(:state) { :running }
58
58
  subject.lxc.stub(:state) { :not_created }
59
+ subject.lxc.stub(:memory_usage) { 0 }
60
+ subject.lxc.stub(:cpu_usage) { 0 }
59
61
  subject.lxc_clone.stub(:exists?) { false }
60
62
 
61
63
  subject.status.should be_kind_of(Hash)
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.8.2
4
+ version: 1.8.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -344,7 +344,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
344
  version: '0'
345
345
  segments:
346
346
  - 0
347
- hash: -2021953625576057715
347
+ hash: 2852140378552631871
348
348
  required_rubygems_version: !ruby/object:Gem::Requirement
349
349
  none: false
350
350
  requirements:
@@ -353,7 +353,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
353
  version: '0'
354
354
  segments:
355
355
  - 0
356
- hash: -2021953625576057715
356
+ hash: 2852140378552631871
357
357
  requirements: []
358
358
  rubyforge_project:
359
359
  rubygems_version: 1.8.25