testlab 0.6.6 → 0.6.7

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.
data/bin/tl CHANGED
@@ -18,12 +18,16 @@
18
18
  # limitations under the License.
19
19
  #
20
20
  ################################################################################
21
+ require 'socket'
22
+
21
23
  require 'gli'
22
24
  require 'testlab'
23
25
 
24
26
  include GLI::App
25
27
  include TestLab::Utility::Misc
26
28
 
29
+ HOSTNAME = Socket.gethostname.split('.').first.strip
30
+
27
31
  version TestLab::VERSION
28
32
 
29
33
  program_desc %(TestLab - A toolkit for building virtual computer labs)
@@ -41,11 +45,9 @@ switch [:v, :verbose]
41
45
  pre do |global,command,options,args|
42
46
  global[:v].nil? or (global[:v] == true) and ENV['LOG_LEVEL'] = 'DEBUG'
43
47
 
44
- log_file = File.join(Dir.pwd, "testlab.log")
48
+ log_file = File.join(Dir.pwd, "testlab-#{HOSTNAME}.log")
45
49
  @logger = ZTK::Logger.new(log_file)
46
50
 
47
- TestLab::Utility.log_header.each { |line| @logger.info { line } }
48
-
49
51
  @logger.debug { "global(#{global.inspect})" }
50
52
  @logger.debug { "options(#{options.inspect})" }
51
53
  @logger.debug { "args(#{args.inspect})" }
@@ -53,6 +55,8 @@ pre do |global,command,options,args|
53
55
  @ui = ZTK::UI.new(:logger => @logger)
54
56
  @testlab = TestLab.new(:ui => @ui)
55
57
 
58
+ TestLab::Utility.log_header(@testlab).each { |line| @logger.info { line } }
59
+
56
60
  message = format_message("TestLab v#{TestLab::VERSION} Loaded".black.bold)
57
61
  @testlab.ui.stdout.puts(message)
58
62
 
@@ -187,7 +187,8 @@ EOF
187
187
  network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
188
188
  network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
189
189
 
190
- network.manage_route(:add)
190
+ p = TestLab::Provisioner::Route.new({}, @ui)
191
+ p.on_network_setup(network)
191
192
  @testlab.ui.stdout.puts("Added routes successfully!".green.bold)
192
193
  @testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
193
194
  end
@@ -203,7 +204,8 @@ EOF
203
204
  network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first
204
205
  network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
205
206
 
206
- network.manage_route(:del)
207
+ p = TestLab::Provisioner::Route.new({}, @ui)
208
+ p.on_network_teardown(network)
207
209
  @testlab.ui.stdout.puts("Deleted routes successfully!".red.bold)
208
210
  @testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
209
211
  end
@@ -16,16 +16,17 @@ class TestLab
16
16
  sc_file = File.join("/", "tmp", "#{self.id}.sc")
17
17
  local_file = File.join(Dir.pwd, File.basename(sc_file))
18
18
 
19
- please_wait(:ui => @ui, :message => format_object_action(self, 'Compress', :blue)) do
20
- script = <<-EOF
19
+ please_wait(:ui => @ui, :message => format_object_action(self, 'Compress', :cyan)) do
20
+ self.node.ssh.bootstrap(<<-EOF)
21
21
  set -x
22
+ set -e
22
23
  find #{self.lxc.container_root} -print0 -depth | cpio -o0 | pbzip2 -#{compression} -vfcz > #{sc_file}
23
24
  chown ${SUDO_USER}:${SUDO_USER} #{sc_file}
24
25
  EOF
25
- self.node.ssh.bootstrap(script)
26
26
  end
27
27
 
28
- please_wait(:ui => @ui, :message => format_object_action(self, 'Export', :blue)) do
28
+ please_wait(:ui => @ui, :message => format_object_action(self, 'Export', :cyan)) do
29
+ File.exists?(local_file) and FileUtils.rm_f(local_file)
29
30
  self.node.ssh.download(sc_file, local_file)
30
31
  end
31
32
 
@@ -45,17 +46,17 @@ EOF
45
46
 
46
47
  sc_file = File.join("/", "tmp", "#{self.id}.sc")
47
48
 
48
- please_wait(:ui => @ui, :message => format_object_action(self, 'Import', :blue)) do
49
+ please_wait(:ui => @ui, :message => format_object_action(self, 'Import', :cyan)) do
49
50
  self.node.ssh.exec(%(sudo rm -fv #{sc_file}), :silence => true, :ignore_exit_status => true)
50
51
  self.node.ssh.upload(local_file, sc_file)
51
52
  end
52
53
 
53
- please_wait(:ui => @ui, :message => format_object_action(self, 'Expand', :blue)) do
54
- script = <<-EOF
54
+ please_wait(:ui => @ui, :message => format_object_action(self, 'Expand', :cyan)) do
55
+ self.node.ssh.bootstrap(<<-EOF)
55
56
  set -x
57
+ set -e
56
58
  pbzip2 -vdc #{sc_file} | cpio -uid && rm -fv #{sc_file}
57
59
  EOF
58
- self.node.ssh.bootstrap(script)
59
60
  end
60
61
 
61
62
  puts("Your shipping container is now imported and available for use!")
@@ -13,6 +13,31 @@ class TestLab
13
13
  self.node.container_ssh(self, options)
14
14
  end
15
15
 
16
+ # Returns text suitable for use in an SSH configuration file
17
+ #
18
+ # @return [String] SSH configuration text blob.
19
+ def ssh_config
20
+ identities = [self.users.map(&:identity), self.node.identity].flatten.compact.uniq
21
+
22
+ output = <<-EOF
23
+ #{ZTK::Template.do_not_edit_notice(:message => %(TestLab "#{self.fqdn}" SSH Configuration))}
24
+ Host #{self.id}
25
+ HostName #{self.ip}
26
+ Port 22
27
+ UserKnownHostsFile /dev/null
28
+ StrictHostKeyChecking no
29
+ PasswordAuthentication no
30
+ ForwardAgent no
31
+ IdentitiesOnly yes
32
+ EOF
33
+
34
+ identities.each do |identity|
35
+ output += " IdentityFile #{identity}\n"
36
+ end
37
+
38
+ output
39
+ end
40
+
16
41
  end
17
42
 
18
43
  end
@@ -12,7 +12,7 @@ class TestLab
12
12
  self.provisioners.each do |provisioner|
13
13
  @ui.logger.info { ">>>>> NETWORK PROVISIONER SETUP: #{provisioner} <<<<<" }
14
14
  p = provisioner.new(self.config, @ui)
15
- p.respond_to?(:on_node_teardown) and p.on_node_teardown(self)
15
+ p.respond_to?(:on_network_setup) and p.on_network_setup(self)
16
16
  end
17
17
 
18
18
  end
@@ -29,7 +29,7 @@ class TestLab
29
29
  self.provisioners.each do |provisioner|
30
30
  @ui.logger.info { ">>>>> NETWORK PROVISIONER TEARDOWN: #{provisioner} <<<<<" }
31
31
  p = provisioner.new(self.config, @ui)
32
- p.respond_to?(:on_node_teardown) and p.on_node_teardown(self)
32
+ p.respond_to?(:on_network_teardown) and p.on_network_teardown(self)
33
33
  end
34
34
 
35
35
  end
@@ -33,7 +33,7 @@ class TestLab
33
33
 
34
34
  c.user = (options[:user] || container.primary_user.id)
35
35
  c.password = (options[:passwd] || container.primary_user.password)
36
- c.keys = (options[:keys] || container.primary_user.identity || @provider.identity)
36
+ c.keys = (options[:keys] || [container.primary_user.identity, @provider.identity])
37
37
  end
38
38
  end
39
39
  @container_ssh[name]
@@ -8,6 +8,7 @@ class TestLab
8
8
  #
9
9
  # @author Zachary Patten <zachary AT jovelabs DOT com>
10
10
  module Logger
11
+ require 'socket'
11
12
  require 'active_support/version'
12
13
 
13
14
  def log_key_value(key, value, max_key_length)
@@ -18,10 +19,13 @@ class TestLab
18
19
  (char * max_key_length)
19
20
  end
20
21
 
21
- def log_details
22
+ def log_details(testlab)
22
23
  @command = ZTK::Command.new(:silence => true, :ignore_exit_status => true)
23
24
  {
25
+ "hostname" => Socket.gethostname.inspect,
24
26
  "program" => $0.to_s.inspect,
27
+ "config_dir" => testlab.config_dir.inspect,
28
+ "logdev" => testlab.ui.logger.logdev.inspect,
25
29
  "vagrant_version" => @command.exec(%(/usr/bin/env vagrant --version)).output.strip.inspect,
26
30
  "virtualbox_version" => @command.exec(%(/usr/bin/env vboxmanage --version)).output.strip.inspect
27
31
  }
@@ -48,10 +52,10 @@ class TestLab
48
52
  }
49
53
  end
50
54
 
51
- def log_header
55
+ def log_header(testlab)
52
56
  log_lines = Array.new
53
57
 
54
- details_hash = log_details
58
+ details_hash = log_details(testlab)
55
59
  ruby_hash = log_ruby
56
60
  dependencies_hash = log_dependencies
57
61
 
@@ -1,6 +1,6 @@
1
1
  class TestLab
2
2
  unless const_defined?(:VERSION)
3
3
  # TestLab Gem Version
4
- VERSION = "0.6.6"
4
+ VERSION = "0.6.7"
5
5
  end
6
6
  end
data/lib/testlab.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'socket'
2
+
1
3
  require 'ztk'
2
4
  require 'active_support/inflector'
3
5
 
@@ -101,7 +103,7 @@ class TestLab
101
103
  def initialize(options={})
102
104
  self.ui = (options[:ui] || ZTK::UI.new)
103
105
 
104
- labfile = (options[:labfile] || 'Labfile')
106
+ labfile = (options[:labfile] || File.join(Dir.pwd, 'Labfile'))
105
107
  labfile_path = ZTK::Locator.find(labfile)
106
108
  @labfile = TestLab::Labfile.load(labfile_path)
107
109
  @labfile.config.merge!(:testlab => self)
@@ -295,7 +297,8 @@ class TestLab
295
297
  #
296
298
  # @return [String] The path to the TestLab configuration directory.
297
299
  def config_dir
298
- directory = File.join(self.config[:repo], '.testlab')
300
+ @hostname ||= Socket.gethostname.split('.').first.strip
301
+ directory = File.join(self.config[:repo], ".testlab-#{@hostname}")
299
302
  File.expand_path(directory, File.dirname(__FILE__))
300
303
  end
301
304
 
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.6
4
+ version: 0.6.7
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: -2743048303371547587
303
+ hash: 1748419604064060777
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: -2743048303371547587
312
+ hash: 1748419604064060777
313
313
  requirements: []
314
314
  rubyforge_project:
315
315
  rubygems_version: 1.8.25