testlab 0.6.12 → 0.6.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -248,7 +248,7 @@ EOF
248
248
  c.long_desc <<-EOF
249
249
  Recycles a container. The container is taken through a series of state changes to ensure it is pristine.
250
250
 
251
- The containers is cycled in this order:
251
+ The container is cycled in this order:
252
252
 
253
253
  Teardown -> Down -> Destroy -> Create -> Up -> Setup
254
254
  EOF
@@ -11,7 +11,7 @@ class TestLab
11
11
  c.host_name = @provider.ip
12
12
  c.port = @provider.port
13
13
  c.user = @provider.user
14
- c.keys = @provider.identity
14
+ c.keys = [@provider.identity].flatten.compact
15
15
  end
16
16
  end
17
17
  @ssh
@@ -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].flatten.compact)
37
37
  end
38
38
  end
39
39
  @container_ssh[name]
@@ -91,7 +91,7 @@ class TestLab
91
91
 
92
92
  # Inquire the state of the Vagrant-controlled VM
93
93
  def state
94
- output = self.vagrant_cli("status").output.grep(/#{self.instance_id}/).first
94
+ output = self.vagrant_cli("status").output.split("\n").select{ |line| (line =~ /#{self.instance_id}/) }.first
95
95
  result = UNKNOWN_STATE
96
96
  ALL_STATES.map{ |s| s.to_s.gsub('_', ' ') }.each do |state|
97
97
  if output =~ /#{state}/
@@ -7,16 +7,14 @@ class TestLab
7
7
  #
8
8
  # @author Zachary Patten <zachary AT jovelabs DOT com>
9
9
  class Provisioner
10
- autoload :Apt, 'testlab/provisioners/apt'
11
- autoload :AptCacherNG, 'testlab/provisioners/apt_cacher_ng'
12
- autoload :Bind, 'testlab/provisioners/bind'
13
- autoload :ChefGem, 'testlab/provisioners/chef_gem'
14
- autoload :OmniBus, 'testlab/provisioners/omnibus'
15
- autoload :OmniTruck, 'testlab/provisioners/omnitruck'
16
- autoload :Raring, 'testlab/provisioners/raring'
17
- autoload :Resolv, 'testlab/provisioners/resolv'
18
- autoload :Route, 'testlab/provisioners/route'
19
- autoload :Shell, 'testlab/provisioners/shell'
10
+ autoload :Apt, 'testlab/provisioners/apt'
11
+ autoload :AptCacherNG, 'testlab/provisioners/apt_cacher_ng'
12
+ autoload :Bind, 'testlab/provisioners/bind'
13
+ autoload :Chef, 'testlab/provisioners/chef'
14
+ autoload :Raring, 'testlab/provisioners/raring'
15
+ autoload :Resolv, 'testlab/provisioners/resolv'
16
+ autoload :Route, 'testlab/provisioners/route'
17
+ autoload :Shell, 'testlab/provisioners/shell'
20
18
 
21
19
  class << self
22
20
 
@@ -0,0 +1,104 @@
1
+ class TestLab
2
+ class Provisioner
3
+ class Chef
4
+
5
+ # OmniBus Provisioner Error Class
6
+ class OmniBusError < ChefError; end
7
+
8
+ # OmniBus Provisioner Class
9
+ #
10
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
11
+ class OmniBus
12
+
13
+ def initialize(config={}, ui=nil)
14
+ @config = (config || Hash.new)
15
+ @ui = (ui || TestLab.ui)
16
+
17
+ @chef_server = TestLab::Container.first('chef-server')
18
+
19
+ @config[:chef] ||= Hash.new
20
+ @config[:chef][:client] ||= Hash.new
21
+ @config[:chef][:client][:version] ||= %(latest)
22
+ @config[:chef][:client][:log_level] ||= :info
23
+ @config[:chef][:client][:server_url] ||= "https://#{@chef_server.ip}"
24
+ @config[:chef][:client][:attributes] ||= Hash.new
25
+
26
+ @ui.logger.debug { "config(#{@config.inspect})" }
27
+ end
28
+
29
+ # OmniBus Provisioner Container Setup
30
+ #
31
+ # Renders the defined script to a temporary file on the target container
32
+ # and proceeds to execute said script as root via *lxc-attach*.
33
+ #
34
+ # @param [TestLab::Container] container The container which we want to
35
+ # provision.
36
+ # @return [Boolean] True if successful.
37
+ def on_container_setup(container)
38
+ @config[:chef][:client][:node_name] ||= container.id
39
+
40
+ omnibus_template = File.join(TestLab::Provisioner::Chef.template_dir, 'omni_bus.erb')
41
+
42
+ config = {}.merge!({
43
+ :chef_client_cli => chef_client_cli(container),
44
+ :chef_client_rb => chef_client_rb(container),
45
+ :validation_pem => validation_pem,
46
+ :sudo_user => container.primary_user.id,
47
+ :sudo_uid => container.primary_user.uid,
48
+ :sudo_gid => container.primary_user.gid,
49
+ :home_dir => container.primary_user.home_dir
50
+ }).merge!(@config)
51
+
52
+ container.bootstrap(ZTK::Template.render(omnibus_template, config))
53
+
54
+ true
55
+ end
56
+
57
+ # OmniBus Provisioner Container Teardown
58
+ #
59
+ # @return [Boolean] True if successful.
60
+ def on_container_teardown(container)
61
+ if @chef_server.state == :running
62
+ @chef_server.ssh.exec(%(knife node delete #{container.id} --yes), :ignore_exit_status => true)
63
+ @chef_server.ssh.exec(%(knife client delete #{container.id} --yes), :ignore_exit_status => true)
64
+ end
65
+
66
+ true
67
+ end
68
+
69
+ private
70
+
71
+ def chef_client_cli(container, *args)
72
+ arguments = Array.new
73
+
74
+ arguments << %(chef-client)
75
+ arguments << [args]
76
+ arguments << %(--node-name #{container.id})
77
+ arguments << %(--environment #{@config[:chef][:client][:environment]}) if !@config[:chef][:client][:environment].nil?
78
+ arguments << %(--json-attributes /etc/chef/attributes.json)
79
+ arguments << %(--server #{@config[:chef][:client][:server_url]})
80
+ arguments << %(--once)
81
+
82
+ arguments.flatten.compact.join(' ')
83
+ end
84
+
85
+ def chef_client_rb(container)
86
+ <<-EOF
87
+ #{ZTK::Template.do_not_edit_notice(:message => "Lookout TestLab Chef-Client Configuration")}
88
+ log_level #{@config[:chef][:client][:log_level].inspect}
89
+ log_location STDOUT
90
+ chef_server_url #{@config[:chef][:client][:server_url].inspect}
91
+ validation_client_name "chef-validator"
92
+ node_name #{@config[:chef][:client][:node_name].inspect}
93
+ EOF
94
+ end
95
+
96
+ def validation_pem
97
+ @chef_server.ssh.exec(%((cat ~/.chef/validation.pem || cat ~/.chef/chef-validator.pem) 2> /dev/null)).output.strip
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,90 @@
1
+ class TestLab
2
+ class Provisioner
3
+ class Chef
4
+
5
+ # OmniTruck Provisioner Error Class
6
+ class OmniTruckError < ChefError; end
7
+
8
+ # OmniTruck Provisioner Class
9
+ #
10
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
11
+ class OmniTruck
12
+ require 'json'
13
+
14
+ def initialize(config={}, ui=nil)
15
+ @config = (config || Hash.new)
16
+ @ui = (ui || TestLab.ui)
17
+
18
+ @config[:chef] ||= Hash.new
19
+ @config[:chef][:server] ||= Hash.new
20
+ @config[:chef][:server][:version] ||= %(latest)
21
+ @config[:chef][:server][:prereleases] ||= false
22
+ @config[:chef][:server][:nightlies] ||= false
23
+ @config[:chef][:server][:server_url] ||= "https://127.0.0.1"
24
+
25
+ @ui.logger.debug { "config(#{@config.inspect})" }
26
+ end
27
+
28
+ # OmniTruck Provisioner Container Setup
29
+ #
30
+ # Renders the defined script to a temporary file on the target container
31
+ # and proceeds to execute said script as root via *lxc-attach*.
32
+ #
33
+ # @param [TestLab::Container] container The container which we want to
34
+ # provision.
35
+ # @return [Boolean] True if successful.
36
+ def on_container_setup(container)
37
+ omnitruck_template = File.join(TestLab::Provisioner::Chef.template_dir, 'omni_truck.erb')
38
+
39
+ config = {}.merge!({
40
+ :server_name => container.ip,
41
+ :chef_solo_attributes => build_omni_truck_attributes(container),
42
+ :chef_validator => '/etc/chef-server/chef-validator.pem',
43
+ :chef_webui => '/etc/chef-server/chef-webui.pem',
44
+ :chef_admin => '/etc/chef-server/admin.pem',
45
+ :local_user => ENV['USER'],
46
+ :default_password => "p@ssw01d",
47
+ :sudo_user => container.primary_user.id,
48
+ :sudo_uid => container.primary_user.uid,
49
+ :sudo_gid => container.primary_user.gid,
50
+ :home_dir => container.primary_user.home_dir
51
+ }).merge!(@config)
52
+
53
+ container.bootstrap(ZTK::Template.render(omnitruck_template, config))
54
+
55
+ true
56
+ end
57
+
58
+ private
59
+
60
+ def build_omni_truck_attributes(container)
61
+ {
62
+ "chef-server" => {
63
+ "api_fqdn" => container.ip,
64
+ "nginx" => {
65
+ "enable_non_ssl" => true,
66
+ "server_name" => container.ip,
67
+ "url" => @config[:chef][:server][:server_url]
68
+ },
69
+ "lb" => {
70
+ "fqdn" => container.ip
71
+ },
72
+ "bookshelf" => {
73
+ "vip" => container.ip
74
+ },
75
+ "chef_server_webui" => {
76
+ "enable" => true
77
+ },
78
+ "version" => @config[:chef][:server][:version],
79
+ "prereleases" => @config[:chef][:server][:prereleases],
80
+ "nightlies" => @config[:chef][:server][:nightlies]
81
+ },
82
+ "run_list" => %w(recipe[chef-server::default])
83
+ }
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,105 @@
1
+ class TestLab
2
+ class Provisioner
3
+ class Chef
4
+
5
+ # RubyGemClient Provisioner Error Class
6
+ class RubyGemClientError < ChefError; end
7
+
8
+ # RubyGemClient Provisioner Class
9
+ #
10
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
11
+ class RubyGemClient
12
+ require 'json'
13
+
14
+ def initialize(config={}, ui=nil)
15
+ @config = (config || Hash.new)
16
+ @ui = (ui || TestLab.ui)
17
+
18
+ @chef_server = TestLab::Container.first('chef-server')
19
+
20
+ @config[:chef] ||= Hash.new
21
+ @config[:chef][:client] ||= Hash.new
22
+ @config[:chef][:client][:version] ||= %(10.24.0)
23
+ @config[:chef][:client][:log_level] ||= :info
24
+ @config[:chef][:client][:server_url] ||= "https://#{@chef_server.ip}"
25
+ @config[:chef][:client][:attributes] ||= Hash.new
26
+
27
+ @ui.logger.debug { "config(#{@config.inspect})" }
28
+ end
29
+
30
+ # RubyGemClient Provisioner Container Setup
31
+ #
32
+ # Renders the defined script to a temporary file on the target container
33
+ # and proceeds to execute said script as root via *lxc-attach*.
34
+ #
35
+ # @param [TestLab::Container] container The container which we want to
36
+ # provision.
37
+ # @return [Boolean] True if successful.
38
+ def on_container_setup(container)
39
+ @config[:chef][:client][:node_name] ||= container.id
40
+
41
+ rubygem_client_template = File.join(TestLab::Provisioner::Chef.template_dir, 'ruby_gem_client.erb')
42
+
43
+ config = {}.merge!({
44
+ :chef_client_cli => chef_client_cli(container),
45
+ :chef_client_rb => chef_client_rb(container),
46
+ :validation_pem => validation_pem,
47
+ :sudo_user => container.primary_user.id,
48
+ :sudo_uid => container.primary_user.uid,
49
+ :sudo_gid => container.primary_user.gid,
50
+ :home_dir => container.primary_user.home_dir
51
+ }).merge!(@config)
52
+
53
+ container.bootstrap(ZTK::Template.render(rubygem_client_template, config))
54
+
55
+ true
56
+ end
57
+
58
+ # RubyGemClient Provisioner Container Teardown
59
+ #
60
+ # @return [Boolean] True if successful.
61
+ def on_container_teardown(container)
62
+ if @chef_server.state == :running
63
+ @chef_server.ssh.exec(%(knife node delete #{container.id} --yes), :ignore_exit_status => true)
64
+ @chef_server.ssh.exec(%(knife client delete #{container.id} --yes), :ignore_exit_status => true)
65
+ end
66
+
67
+ true
68
+ end
69
+
70
+ private
71
+
72
+ def chef_client_cli(container, *args)
73
+ arguments = Array.new
74
+
75
+ arguments << %(chef-client)
76
+ arguments << [args]
77
+ arguments << %(--node-name #{container.id})
78
+ arguments << %(--environment #{@config[:chef][:client][:environment]}) if !@config[:chef][:client][:environment].nil?
79
+ arguments << %(--json-attributes /etc/chef/attributes.json)
80
+ arguments << %(--server #{@config[:chef][:client][:server_url]})
81
+ arguments << %(--once)
82
+
83
+ arguments.flatten.compact.join(' ')
84
+ end
85
+
86
+ def chef_client_rb(container)
87
+ <<-EOF
88
+ #{ZTK::Template.do_not_edit_notice(:message => "TestLab Chef-Client Configuration")}
89
+ log_level #{@config[:chef][:client][:log_level].inspect}
90
+ log_location STDOUT
91
+ chef_server_url #{@config[:chef][:client][:server_url].inspect}
92
+ validation_client_name "chef-validator"
93
+ node_name #{@config[:chef][:client][:node_name].inspect}
94
+ EOF
95
+ end
96
+
97
+ def validation_pem
98
+ @chef_server.ssh.exec(%((cat ~/.chef/validation.pem || cat ~/.chef/chef-validator.pem) 2> /dev/null)).output.strip
99
+ end
100
+
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,74 @@
1
+ class TestLab
2
+ class Provisioner
3
+ class Chef
4
+
5
+ # RubyGemServer Provisioner Error Class
6
+ class RubyGemServerError < ChefError; end
7
+
8
+ # RubyGemServer Provisioner Class
9
+ #
10
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
11
+ class RubyGemServer
12
+ require 'json'
13
+
14
+ def initialize(config={}, ui=nil)
15
+ @config = (config || Hash.new)
16
+ @ui = (ui || TestLab.ui)
17
+
18
+ @config[:chef] ||= Hash.new
19
+ @config[:chef][:server] ||= Hash.new
20
+ @config[:chef][:server][:version] ||= %(10.24.0)
21
+ @config[:chef][:server][:server_url] ||= "https://127.0.0.1"
22
+
23
+ @ui.logger.debug { "config(#{@config.inspect})" }
24
+ end
25
+
26
+ # RubyGemServer Provisioner Container Setup
27
+ #
28
+ # Renders the defined script to a temporary file on the target container
29
+ # and proceeds to execute said script as root via *lxc-attach*.
30
+ #
31
+ # @param [TestLab::Container] container The container which we want to
32
+ # provision.
33
+ # @return [Boolean] True if successful.
34
+ def on_container_setup(container)
35
+ rubygemserver_template = File.join(TestLab::Provisioner.template_dir, 'chef', 'ruby_gem_server.erb')
36
+
37
+ config = {}.merge!({
38
+ :server_name => container.ip,
39
+ :chef_solo_attributes => build_chef_solo_attributes(container),
40
+ :chef_validator => '/etc/chef/validation.pem',
41
+ :chef_webui => '/etc/chef/webui.pem',
42
+ :chef_admin => '/etc/chef/admin.pem',
43
+ :default_password => "p@ssw01d",
44
+ :local_user => ENV['USER'],
45
+ :sudo_user => container.primary_user.id,
46
+ :sudo_uid => container.primary_user.uid,
47
+ :sudo_gid => container.primary_user.gid,
48
+ :home_dir => container.primary_user.home_dir,
49
+ :chef_gems => %w(chef chef-solr chef-expander chef-server-api chef-server-webui),
50
+ :chef_services => %w(couchdb rabbitmq-server chef-solr chef-expander chef-server chef-server-webui apache2)
51
+ }).merge!(@config)
52
+
53
+ container.bootstrap(ZTK::Template.render(rubygemserver_template, config))
54
+
55
+ true
56
+ end
57
+
58
+ private
59
+
60
+ def build_chef_solo_attributes(container)
61
+ {
62
+ "chef_server" => {
63
+ "url" => @config[:chef][:server][:server_url],
64
+ "webui_enabled" => true
65
+ },
66
+ "run_list" => %w(recipe[chef-server::rubygems-install] recipe[chef-server::apache-proxy])
67
+ }
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,28 @@
1
+ class TestLab
2
+ class Provisioner
3
+
4
+ # Chef Provisioner Error Class
5
+ class ChefError < ProvisionerError; end
6
+
7
+ # Chef Provisioner Class
8
+ #
9
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
10
+ class Chef
11
+
12
+ autoload :RubyGemClient, 'testlab/provisioners/chef/ruby_gem_client'
13
+ autoload :RubyGemServer, 'testlab/provisioners/chef/ruby_gem_server'
14
+ autoload :OmniBus, 'testlab/provisioners/chef/omni_bus'
15
+ autoload :OmniTruck, 'testlab/provisioners/chef/omni_truck'
16
+
17
+ class << self
18
+
19
+ # Returns the path to the gems provisioner templates
20
+ def template_dir
21
+ File.join(TestLab::Provisioner.template_dir, "chef")
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ #!/bin/env bash
2
+ <%= ZTK::Template.do_not_edit_notice(:message => "Chef OmniBus Bootstrap") %>
3
+ set -x
4
+ set -e
5
+
6
+ export DEBIAN_FRONTEND="noninteractive"
7
+ export SUDO_USER="<%= @sudo_user %>"
8
+ export SUDO_UID="<%= @sudo_uid %>"
9
+ export SUDO_GID="<%= @sudo_gid %>"
10
+ export HOME="<%= @home_dir %>"
11
+
12
+ export
13
+
14
+ cd /tmp
15
+ apt-get -y install wget ca-certificates || yum -y install wget ca-certificates
16
+ rm -fv /tmp/install.sh
17
+ wget -v https://www.opscode.com/chef/install.sh -O /tmp/install.sh
18
+ /bin/bash /tmp/install.sh -v <%= @chef[:client][:version] %>
19
+
20
+ mkdir -pv /etc/chef/
21
+
22
+ cat <<EOF | tee /etc/chef/attributes.json
23
+ <%= @chef[:client][:attributes].to_json %>
24
+ EOF
25
+
26
+ cat <<EOF | tee /etc/chef/validation.pem
27
+ <%= @validation_pem %>
28
+ EOF
29
+
30
+ cat <<EOF | tee /etc/chef/client.rb
31
+ <%= @chef_client_rb %>
32
+ EOF
33
+
34
+ <%= @chef_client_cli %>
35
+
36
+ touch /.omni-bus-bootstrap
@@ -0,0 +1,81 @@
1
+ #!/bin/env bash
2
+ <%= ZTK::Template.do_not_edit_notice(:message => "Chef OmniTruck Bootstrap") %>
3
+ set -x
4
+ set -e
5
+
6
+ export DEBIAN_FRONTEND="noninteractive"
7
+ export CHEF_SOLO_ROOT="/tmp/chef-solo"
8
+ export SUDO_USER="<%= @sudo_user %>"
9
+ export SUDO_UID="<%= @sudo_uid %>"
10
+ export SUDO_GID="<%= @sudo_gid %>"
11
+ export HOME="<%= @home_dir %>"
12
+ export KNIFE_CONFIG_EXP_FILE="/tmp/knife.exp"
13
+ export
14
+
15
+ mkdir -p ${CHEF_SOLO_ROOT}
16
+ cd ${CHEF_SOLO_ROOT}
17
+
18
+ apt-get -y --force-yes update
19
+ apt-get -y --force-yes install build-essential expect wget curl libgecode-dev ca-certificates
20
+
21
+ mkdir -pv /etc/chef /var/log/chef ${HOME}/.chef
22
+
23
+ cat <<EOF | tee /etc/chef/solo.rb
24
+ file_cache_path "${CHEF_SOLO_ROOT}/"
25
+ cookbook_path %w(${CHEF_SOLO_ROOT}/cookbooks/)
26
+ role_path "${CHEF_SOLO_ROOT}/roles/"
27
+ EOF
28
+
29
+ cat <<EOF | tee ${CHEF_SOLO_ROOT}/attributes.json
30
+ <%= @chef_solo_attributes.to_json %>
31
+ EOF
32
+
33
+ rm -fv ${CHEF_SOLO_ROOT}/install.sh
34
+ wget -v https://www.opscode.com/chef/install.sh -O ${CHEF_SOLO_ROOT}/install.sh
35
+ bash ${CHEF_SOLO_ROOT}/install.sh -v <%= @chef[:server][:version] %>
36
+ mkdir -pv /var/chef/cache ${CHEF_SOLO_ROOT}/cookbooks/chef-server
37
+ wget -qO- https://github.com/opscode-cookbooks/chef-server/archive/master.tar.gz | tar xvzC ${CHEF_SOLO_ROOT}/cookbooks/chef-server --strip-components=1
38
+
39
+ set +e
40
+ chef-solo --config /etc/chef/solo.rb --json-attributes ${CHEF_SOLO_ROOT}/attributes.json --logfile /var/log/chef/chef-solo.log --log_level debug
41
+ set -e
42
+
43
+ cat << EOF | tee /etc/chef-server/chef-server.rb
44
+ <%= ZTK::Template.do_not_edit_notice(:message => "OmniTruck Bootstrap") %>
45
+ server_name = "<%= @server_name %>"
46
+ #
47
+ topology "standalone"
48
+ api_fqdn server_name
49
+ nginx['url'] = "https://#{server_name}"
50
+ nginx['server_name'] = server_name
51
+ lb['fqdn'] = server_name
52
+ bookshelf['vip'] = server_name
53
+ EOF
54
+ chef-server-ctl reconfigure
55
+
56
+ echo -n "Waiting on <%= File.basename(@chef_validator) %> and <%= File.basename(@chef_webui) %> to appear..."
57
+ until [ -f <%= @chef_validator %> ] && [ -f <%= @chef_webui %> ]; do
58
+ echo -n "."
59
+ sleep 1
60
+ done
61
+ echo "done."
62
+
63
+ cp -v <%= @chef_validator %> <%= @chef_webui %> ~/.chef
64
+ [ -f /etc/chef/validation.pem ] || ln -sv <%= @chef_validator %> /etc/chef/validation.pem
65
+ [ -f /etc/chef/admin.pem ] || ln -sv <%= @chef_admin %> /etc/chef/admin.pem
66
+
67
+ cat << EOF | tee ${KNIFE_CONFIG_EXP_FILE}
68
+ #!/usr/bin/expect -f
69
+ set timeout 10
70
+ spawn knife configure --initial --server-url <%= @chef[:server][:server_url] %> --admin-client-key <%= @chef_admin %> --user <%= @sudo_user %> --repository '' --defaults --yes -VV
71
+ expect "Please enter a password for the new user:" { send "<%= @default_password %>\n" }
72
+ interact
73
+ EOF
74
+ chmod -v +x ${KNIFE_CONFIG_EXP_FILE}
75
+ [ -f <%= @home_dir %>/.chef/<%= @sudo_user %>.pem ] || ${KNIFE_CONFIG_EXP_FILE}
76
+
77
+ [ -f <%= @home_dir %>/.chef/<%= @local_user %>.pem ] || knife client create <%= @local_user %> --server-url <%= @chef[:server][:server_url] %> --user <%= @sudo_user %> --key <%= @home_dir %>/.chef/<%= @sudo_user %>.pem --admin --file <%= @home_dir %>/.chef/<%= @local_user %>.pem --editor echo --disable-editing --defaults --yes -VV
78
+
79
+ chown -Rv ${SUDO_USER}:${SUDO_USER} ${HOME}
80
+
81
+ touch /.omni-truck-bootstrap
@@ -0,0 +1,46 @@
1
+ #!/bin/env bash
2
+ <%= ZTK::Template.do_not_edit_notice(:message => "Chef OmniBus Bootstrap") %>
3
+ set -x
4
+ set -e
5
+
6
+ export DEBIAN_FRONTEND="noninteractive"
7
+ export SUDO_USER="<%= @sudo_user %>"
8
+ export SUDO_UID="<%= @sudo_uid %>"
9
+ export SUDO_GID="<%= @sudo_gid %>"
10
+ export HOME="<%= @home_dir %>"
11
+
12
+ export
13
+
14
+ cd /tmp
15
+
16
+ apt-get -y --force-yes update
17
+ apt-get -y --force-yes install ca-certificates ruby1.8 rubygems
18
+
19
+ mkdir -pv /etc/chef/
20
+
21
+ cat <<EOF | tee /tmp/Gemfile
22
+ source 'https://rubygems.org'
23
+ gem 'chef', '<%= @chef[:client][:version] %>'
24
+ gem 'moneta', '< 0.7.0'
25
+ EOF
26
+
27
+ gem install bundler --no-ri --no-rdoc
28
+ bundle install
29
+
30
+ update-alternatives --install /usr/bin/chef-client chef-client /usr/local/bin/chef-client 500
31
+
32
+ cat <<EOF | tee /etc/chef/attributes.json
33
+ <%= @chef[:client][:attributes].to_json %>
34
+ EOF
35
+
36
+ cat <<EOF | tee /etc/chef/validation.pem
37
+ <%= @validation_pem %>
38
+ EOF
39
+
40
+ cat <<EOF | tee /etc/chef/client.rb
41
+ <%= @chef_client_rb %>
42
+ EOF
43
+
44
+ <%= @chef_client_cli %>
45
+
46
+ touch /.ruby-gem-client-bootstrap
@@ -0,0 +1,79 @@
1
+ #!/bin/env bash
2
+ <%= ZTK::Template.do_not_edit_notice(:message => "Chef RubyGem Bootstrap") %>
3
+ set -x
4
+ set -e
5
+
6
+ export DEBIAN_FRONTEND="noninteractive"
7
+ export CHEF_SOLO_ROOT="/tmp/chef-solo"
8
+ export SUDO_USER="<%= @sudo_user %>"
9
+ export SUDO_UID="<%= @sudo_uid %>"
10
+ export SUDO_GID="<%= @sudo_gid %>"
11
+ export HOME="<%= @home_dir %>"
12
+ export
13
+
14
+ mkdir -pv ${CHEF_SOLO_ROOT}
15
+ cd ${CHEF_SOLO_ROOT}
16
+
17
+ apt-get -y --force-yes update
18
+ apt-get -y --force-yes install build-essential expect wget curl libgecode-dev ca-certificates ruby1.8 rubygems
19
+
20
+ mkdir -pv /etc/chef /var/log/chef ${HOME}/.chef
21
+
22
+ cat <<EOF | tee /etc/chef/solo.rb
23
+ file_cache_path "${CHEF_SOLO_ROOT}/"
24
+ cookbook_path %w(${CHEF_SOLO_ROOT}/cookbooks/)
25
+ role_path "${CHEF_SOLO_ROOT}/roles/"
26
+ EOF
27
+
28
+ cat <<EOF | tee ${CHEF_SOLO_ROOT}/attributes.json
29
+ <%= @chef_solo_attributes.to_json %>
30
+ EOF
31
+
32
+ cat <<EOF | tee ${CHEF_SOLO_ROOT}/Gemfile
33
+ source 'https://rubygems.org'
34
+ <% @chef_gems.each do |chef_gem| -%>
35
+ gem '<%= chef_gem %>', '<%= @chef[:server][:version] %>'
36
+ <% end -%>
37
+ gem 'haml', '< 4.0.0'
38
+ gem 'moneta', '< 0.7.0'
39
+ gem 'librarian-chef'
40
+ EOF
41
+
42
+ gem install bundler --no-ri --no-rdoc
43
+ bundle install
44
+
45
+ update-alternatives --install /usr/bin/chef-client chef-client /usr/local/bin/chef-client 500
46
+ update-alternatives --install /usr/bin/chef-server chef-server /usr/local/bin/chef-server 500
47
+ update-alternatives --install /usr/bin/chef-server-webui chef-server-webui /usr/local/bin/chef-server-webui 500
48
+ update-alternatives --install /usr/bin/chef-expander chef-expander /usr/local/bin/chef-expander 500
49
+ update-alternatives --install /usr/bin/chef-expanderctl chef-expanderctl /usr/local/bin/chef-expanderctl 500
50
+ update-alternatives --install /usr/bin/chef-expander-vnode chef-expander-vnode /usr/local/bin/chef-expander-vnode 500
51
+ update-alternatives --install /usr/bin/chef-solr chef-solr /usr/local/bin/chef-solr 500
52
+ update-alternatives --install /usr/bin/chef-solr-installer chef-solr-installer /usr/local/bin/chef-solr-installer 500
53
+ update-alternatives --install /usr/bin/chef-solo chef-solo /usr/local/bin/chef-solo 500
54
+ update-alternatives --install /usr/bin/knife knife /usr/local/bin/knife 500
55
+
56
+ cat <<EOF | tee ${CHEF_SOLO_ROOT}/Cheffile
57
+ site 'http://community.opscode.com/api/v1'
58
+ cookbook 'chef-server', '< 2.0.0'
59
+ cookbook 'apt', '< 2.0.0'
60
+ EOF
61
+ librarian-chef install
62
+
63
+ chef-solo --config /etc/chef/solo.rb --json-attributes ${CHEF_SOLO_ROOT}/attributes.json --logfile /var/log/chef/chef-solo.log --log_level debug
64
+
65
+ echo -n "Waiting on <%= File.basename(@chef_validator) %> and <%= File.basename(@chef_webui) %> to appear..."
66
+ until [ -f <%= @chef_validator %> ] && [ -f <%= @chef_webui %> ]; do
67
+ echo -n "."
68
+ sleep 1
69
+ done
70
+ echo "done."
71
+
72
+ cp -v <%= @chef_validator %> <%= @chef_webui %> ~/.chef
73
+
74
+ [ -f <%= @home_dir %>/.chef/<%= @sudo_user %>.pem ] || knife configure --initial --server-url <%= @chef[:server][:server_url] %> --user <%= @sudo_user %> --repository '' --defaults --yes -VV
75
+ [ -f <%= @home_dir %>/.chef/<%= @local_user %>.pem ] || knife client create <%= @local_user %> --server-url <%= @chef[:server][:server_url] %> --user <%= @sudo_user %> --key <%= @home_dir %>/.chef/<%= @sudo_user %>.pem --admin --file <%= @home_dir %>/.chef/<%= @local_user %>.pem --editor echo --disable-editing --defaults --yes -VV
76
+
77
+ chown -Rv ${SUDO_USER}:${SUDO_USER} ${HOME}
78
+
79
+ touch /.ruby-gem-server-bootstrap
data/lib/testlab/user.rb CHANGED
@@ -16,7 +16,6 @@ class TestLab
16
16
  # Associations and Attributes
17
17
  belongs_to :container, :class_name => 'TestLab::Container'
18
18
 
19
- attribute :user
20
19
  attribute :password
21
20
 
22
21
  attribute :identity
@@ -1,6 +1,6 @@
1
1
  class TestLab
2
2
  unless const_defined?(:VERSION)
3
3
  # TestLab Gem Version
4
- VERSION = "0.6.12"
4
+ VERSION = "0.6.14"
5
5
  end
6
6
  end
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.12
4
+ version: 0.6.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-22 00:00:00.000000000 Z
12
+ date: 2013-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
@@ -249,9 +249,11 @@ files:
249
249
  - lib/testlab/provisioners/apt.rb
250
250
  - lib/testlab/provisioners/apt_cacher_ng.rb
251
251
  - lib/testlab/provisioners/bind.rb
252
- - lib/testlab/provisioners/chef_gem.rb
253
- - lib/testlab/provisioners/omnibus.rb
254
- - lib/testlab/provisioners/omnitruck.rb
252
+ - lib/testlab/provisioners/chef.rb
253
+ - lib/testlab/provisioners/chef/omni_bus.rb
254
+ - lib/testlab/provisioners/chef/omni_truck.rb
255
+ - lib/testlab/provisioners/chef/ruby_gem_client.rb
256
+ - lib/testlab/provisioners/chef/ruby_gem_server.rb
255
257
  - lib/testlab/provisioners/raring.rb
256
258
  - lib/testlab/provisioners/resolv.rb
257
259
  - lib/testlab/provisioners/route.rb
@@ -262,9 +264,10 @@ files:
262
264
  - lib/testlab/provisioners/templates/bind/bind-db.erb
263
265
  - lib/testlab/provisioners/templates/bind/bind-zone.erb
264
266
  - lib/testlab/provisioners/templates/bind/bind.erb
265
- - lib/testlab/provisioners/templates/chef/omnibus.erb
266
- - lib/testlab/provisioners/templates/chef/omnitruck.erb
267
- - lib/testlab/provisioners/templates/chef/rubygem.erb
267
+ - lib/testlab/provisioners/templates/chef/omni_bus.erb
268
+ - lib/testlab/provisioners/templates/chef/omni_truck.erb
269
+ - lib/testlab/provisioners/templates/chef/ruby_gem_client.erb
270
+ - lib/testlab/provisioners/templates/chef/ruby_gem_server.erb
268
271
  - lib/testlab/provisioners/templates/raring/bootstrap.erb
269
272
  - lib/testlab/provisioners/templates/resolv/resolv.conf.erb
270
273
  - lib/testlab/user.rb
@@ -298,18 +301,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
301
  - - ! '>='
299
302
  - !ruby/object:Gem::Version
300
303
  version: '0'
301
- segments:
302
- - 0
303
- hash: -3900495778607553131
304
304
  required_rubygems_version: !ruby/object:Gem::Requirement
305
305
  none: false
306
306
  requirements:
307
307
  - - ! '>='
308
308
  - !ruby/object:Gem::Version
309
309
  version: '0'
310
- segments:
311
- - 0
312
- hash: -3900495778607553131
313
310
  requirements: []
314
311
  rubyforge_project:
315
312
  rubygems_version: 1.8.25
@@ -1,49 +0,0 @@
1
- class TestLab
2
-
3
- class Provisioner
4
-
5
- # ChefGem Provisioner Error Class
6
- class ChefGemError < ProvisionerError; end
7
-
8
- # ChefGem Provisioner Class
9
- #
10
- # @author Zachary Patten <zachary AT jovelabs DOT com>
11
- class ChefGem
12
- require 'json'
13
-
14
- def initialize(config={}, ui=nil)
15
- @config = (config || Hash.new)
16
- @ui = (ui || TestLab.ui)
17
-
18
- @ui.logger.debug { "config(#{@config.inspect})" }
19
- end
20
-
21
- # ChefGem Provisioner Container Setup
22
- #
23
- # Renders the defined script to a temporary file on the target container
24
- # and proceeds to execute said script as root via *lxc-attach*.
25
- #
26
- # @param [TestLab::Container] container The container which we want to
27
- # provision.
28
- # @return [Boolean] True if successful.
29
- def on_container_setup(container)
30
- # NOOP
31
-
32
- true
33
- end
34
-
35
- # ChefGem Provisioner Container Teardown
36
- #
37
- # This is a NO-OP currently.
38
- #
39
- # @return [Boolean] True if successful.
40
- def on_container_teardown(container)
41
- # NOOP
42
-
43
- true
44
- end
45
-
46
- end
47
-
48
- end
49
- end
@@ -1,50 +0,0 @@
1
- class TestLab
2
-
3
- class Provisioner
4
-
5
- # OmniBus Provisioner Error Class
6
- class OmniBusError < ProvisionerError; end
7
-
8
- # OmniBus Provisioner Class
9
- #
10
- # @author Zachary Patten <zachary AT jovelabs DOT com>
11
- class OmniBus
12
-
13
- def initialize(config={}, ui=nil)
14
- @config = (config || Hash.new)
15
- @ui = (ui || TestLab.ui)
16
-
17
- @config[:version] ||= %(latest)
18
- @config[:omnibus_url] ||= %(https://www.opscode.com/chef/install.sh)
19
-
20
- @ui.logger.debug { "config(#{@config.inspect})" }
21
- end
22
-
23
- # OmniBus Provisioner Container Setup
24
- #
25
- # Renders the defined script to a temporary file on the target container
26
- # and proceeds to execute said script as root via *lxc-attach*.
27
- #
28
- # @param [TestLab::Container] container The container which we want to
29
- # provision.
30
- # @return [Boolean] True if successful.
31
- def on_container_setup(container)
32
- omnibus_template = File.join(TestLab::Provisioner.template_dir, 'chef', 'omnibus.erb')
33
- container.bootstrap(ZTK::Template.render(omnibus_template, @config))
34
- end
35
-
36
- # OmniBus Provisioner Container Teardown
37
- #
38
- # This is a NO-OP currently.
39
- #
40
- # @return [Boolean] True if successful.
41
- def on_container_teardown(container)
42
- # NOOP
43
-
44
- true
45
- end
46
-
47
- end
48
-
49
- end
50
- end
@@ -1,127 +0,0 @@
1
- class TestLab
2
-
3
- class Provisioner
4
-
5
- # OmniTruck Provisioner Error Class
6
- class OmniTruckError < ProvisionerError; end
7
-
8
- # OmniTruck Provisioner Class
9
- #
10
- # @author Zachary Patten <zachary AT jovelabs DOT com>
11
- class OmniTruck
12
- require 'json'
13
-
14
- def initialize(config={}, ui=nil)
15
- @config = (config || Hash.new)
16
- @ui = (ui || TestLab.ui)
17
-
18
- @config[:version] ||= "latest"
19
- @config[:prereleases] ||= false
20
- @config[:nightlies] ||= false
21
-
22
- @ui.logger.debug { "config(#{@config.inspect})" }
23
- end
24
-
25
- # OmniTruck Provisioner Container Setup
26
- #
27
- # Renders the defined script to a temporary file on the target container
28
- # and proceeds to execute said script as root via *lxc-attach*.
29
- #
30
- # @param [TestLab::Container] container The container which we want to
31
- # provision.
32
- # @return [Boolean] True if successful.
33
- def on_container_setup(container)
34
- omnibus_template = File.join(TestLab::Provisioner.template_dir, 'chef', 'omnitruck.erb')
35
- config = {}.merge!({
36
- :server_name => container.fqdn,
37
- :chef_pre_11 => chef_pre_11?,
38
- :chef_solo_attributes => build_chef_solo_attributes(container),
39
- :chef_validator => (chef_pre_11? ? '/etc/chef/validation.pem' : '/etc/chef-server/chef-validator.pem'),
40
- :chef_webui => (chef_pre_11? ? '/etc/chef/webui.pem' : '/etc/chef-server/chef-webui.pem'),
41
- :chef_admin => (chef_pre_11? ? '/etc/chef/admin.pem' : '/etc/chef-server/admin.pem'),
42
- :default_password => "p@ssw01d",
43
- :user => ENV['USER'],
44
- :hostname_short => container.id,
45
- :hostname_full => container.fqdn,
46
- :omnibus_version => omnibus_version
47
- }).merge!(@config)
48
- container.bootstrap(ZTK::Template.render(omnibus_template, config))
49
- end
50
-
51
- # OmniTruck Provisioner Container Teardown
52
- #
53
- # This is a NO-OP currently.
54
- #
55
- # @return [Boolean] True if successful.
56
- def on_container_teardown(container)
57
- # NOOP
58
-
59
- true
60
- end
61
-
62
- private
63
-
64
- def build_chef_solo_10_attributes(container)
65
- {
66
- "chef_server" => {
67
- "url" => "https://#{container.fqdn}",
68
- "webui_enabled" => true
69
- },
70
- "run_list" => %w(recipe[chef-server::rubygems-install] recipe[chef-server::apache-proxy])
71
- }
72
- end
73
-
74
- def build_chef_solo_11_attributes(container)
75
- {
76
- "chef-server" => {
77
- "api_fqdn" => container.fqdn,
78
- "nginx" => {
79
- "enable_non_ssl" => true,
80
- "server_name" => container.fqdn,
81
- "url" => "https://#{container.fqdn}"
82
- },
83
- "lb" => {
84
- "fqdn" => container.fqdn
85
- },
86
- "bookshelf" => {
87
- "vip" => container.fqdn
88
- },
89
- "chef_server_webui" => {
90
- "enable" => true
91
- },
92
- "version" => @config[:version],
93
- "prereleases" => @config[:prereleases],
94
- "nightlies" => @config[:nightlies]
95
- },
96
- "run_list" => %w(recipe[chef-server::default])
97
- }
98
- end
99
-
100
- def build_chef_solo_attributes(container)
101
- if chef_pre_11?
102
- build_chef_solo_10_attributes(container)
103
- else
104
- build_chef_solo_11_attributes(container)
105
- end
106
- end
107
-
108
- def chef_pre_11?
109
- if (@config[:version].to_s.downcase != "latest") && (@config[:version].to_f < 11.0)
110
- true
111
- else
112
- false
113
- end
114
- end
115
-
116
- def omnibus_version
117
- if (@config[:version].to_f == 0.1)
118
- "10.12.0"
119
- else
120
- @config[:version]
121
- end
122
- end
123
-
124
- end
125
-
126
- end
127
- end
@@ -1,8 +0,0 @@
1
- set -x
2
-
3
- export DEBIAN_FRONTEND="noninteractive"
4
- cd /tmp
5
- apt-get -y install wget || yum -y install wget
6
- rm -fv /tmp/install.sh
7
- wget -v --no-check-certificate <%= @omnibus_url %> -O /tmp/install.sh
8
- /bin/bash /tmp/install.sh -v <%= @version %>
@@ -1,101 +0,0 @@
1
- #!/bin/env bash
2
- <%= ZTK::Template.do_not_edit_notice(:message => "OmniTruck Bootstrap") %>
3
- set -x
4
-
5
- export DEBIAN_FRONTEND="noninteractive"
6
- CHEF_SOLO_ROOT="/tmp/chef-solo"
7
- KNIFE_CONFIG_EXP_FILE="/tmp/knife-config.exp"
8
- export DEBIAN_FRONTEND CHEF_SOLO_ROOT KNIFE_CONFIG_EXP_FILE
9
-
10
- mkdir -p ${CHEF_SOLO_ROOT}
11
- cd ${CHEF_SOLO_ROOT}
12
-
13
- apt-get -y --force-yes update
14
- apt-get -y --force-yes install build-essential expect wget curl libgecode-dev
15
-
16
- mkdir -pv /etc/chef /var/log/chef ${HOME}/.chef
17
-
18
- cat <<EOF | tee /etc/chef/solo.rb
19
- file_cache_path "${CHEF_SOLO_ROOT}/"
20
- cookbook_path %w(${CHEF_SOLO_ROOT}/cookbooks/ ${CHEF_SOLO_ROOT}/site-cookbooks/)
21
- role_path "${CHEF_SOLO_ROOT}/roles/"
22
- EOF
23
-
24
- cat <<EOF | tee ${CHEF_SOLO_ROOT}/attributes.json
25
- <%= @chef_solo_attributes.to_json %>
26
- EOF
27
-
28
- wget -v https://www.opscode.com/chef/install.sh
29
- bash install.sh -v <%= @omnibus_version %>
30
- <% if (@chef_pre_11 == false) -%>
31
-
32
- mkdir -pv /var/chef/cache ${CHEF_SOLO_ROOT}/cookbooks/chef-server
33
- wget -qO- https://github.com/opscode-cookbooks/chef-server/archive/master.tar.gz | tar xvzC ${CHEF_SOLO_ROOT}/cookbooks/chef-server --strip-components=1
34
- <% else -%>
35
-
36
- export PATH=/opt/chef/embedded/bin:$PATH
37
-
38
- cat <<EOF | tee ${CHEF_SOLO_ROOT}/Gemfile
39
- source 'https://rubygems.org'
40
- gem 'chef', '<%= @version %>'
41
- gem 'berkshelf'
42
- gem 'moneta', '< 0.7.0'
43
- EOF
44
-
45
- cat <<EOF | tee ${CHEF_SOLO_ROOT}/Berksfile
46
- site :opscode
47
- cookbook 'chef-server'
48
- EOF
49
-
50
- gem install bundler --no-ri --no-rdoc
51
- bundle install --standalone --path vendor/bundle --binstubs
52
- bin/berks install --path ${CHEF_SOLO_ROOT}/cookbooks/
53
- <% end -%>
54
-
55
- PATH=./bin/:$PATH chef-solo --config /etc/chef/solo.rb --json-attributes ${CHEF_SOLO_ROOT}/attributes.json --logfile /var/log/chef/chef-solo.log --log_level debug
56
- <% if (@chef_pre_11 == false) -%>
57
-
58
- cat << EOF | tee /etc/chef-server/chef-server.rb
59
- <%= ZTK::Template.do_not_edit_notice(:message => "OmniTruck Bootstrap") %>
60
- server_name = "<%= @server_name %>"
61
- #
62
- topology "standalone"
63
- api_fqdn server_name
64
- nginx['url'] = "https://#{server_name}"
65
- nginx['server_name'] = server_name
66
- lb['fqdn'] = server_name
67
- bookshelf['vip'] = server_name
68
- EOF
69
- sudo chef-server-ctl reconfigure
70
- <% end -%>
71
-
72
- echo -n "Waiting on <%= File.basename(@chef_validator) %> and <%= File.basename(@chef_webui) %> to appear..."
73
- until [ -f <%= @chef_validator %> ] && [ -f <%= @chef_webui %> ]; do
74
- echo -n "."
75
- sleep 1
76
- done
77
- echo "done."
78
-
79
- cp -v <%= @chef_validator %> <%= @chef_webui %> ~/.chef
80
- <% if (@chef_pre_11 == false) -%>
81
-
82
- ln -sv <%= @chef_validator %> /etc/chef/validation.pem
83
- ln -sv <%= @chef_admin %> /etc/chef/admin.pem
84
- <% end -%>
85
-
86
- cat <<EOF | tee ${KNIFE_CONFIG_EXP_FILE}
87
- #!/usr/bin/expect -f
88
- set timeout 10
89
- <% if (@chef_pre_11 == false) -%>
90
- spawn knife configure -i --server-url https://127.0.0.1 --admin-client-key <%= @chef_admin %> -u ${SUDO_USER} -r '' --defaults --yes -VV
91
- <% else -%>
92
- spawn knife configure -i --server-url https://127.0.0.1 -u ${SUDO_USER} -r '' --defaults --yes -VV
93
- <% end -%>
94
- expect "Please enter a password for the new user:" { send "<%= @default_password %>\n" }
95
- interact
96
- EOF
97
- chmod +x ${KNIFE_CONFIG_EXP_FILE}
98
- ${KNIFE_CONFIG_EXP_FILE}
99
-
100
- knife client create <%= @user %> -a -f ${HOME}/.chef/<%= @user %>.pem --disable-editing --yes -VV
101
- chown -Rv ${SUDO_USER}:${SUDO_USER} ${HOME}
File without changes