testlab 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,10 +7,11 @@ class TestLab
7
7
  #
8
8
  # @author Zachary Patten <zachary AT jovelabs DOT com>
9
9
  class Provisioner
10
- autoload :Shell, 'testlab/provisioners/shell'
10
+ autoload :AptCacherNG, 'testlab/provisioners/apt_cacher_ng'
11
+ autoload :ChefGem, 'testlab/provisioners/chef_gem'
11
12
  autoload :OmniBus, 'testlab/provisioners/omnibus'
12
13
  autoload :OmniTruck, 'testlab/provisioners/omnitruck'
13
- autoload :AptCacherNG, 'testlab/provisioners/apt_cacher_ng'
14
+ autoload :Shell, 'testlab/provisioners/shell'
14
15
 
15
16
  class << self
16
17
 
@@ -24,11 +24,14 @@ class TestLab
24
24
  def node(node)
25
25
  @ui.logger.debug { "AptCacherNG Provisioner: Node #{node.id}" }
26
26
 
27
- node.ssh.exec(%(sudo apt-get -y install apt-cacher-ng))
28
- node.ssh.exec(%(sudo service apt-cacher-ng restart || sudo service apt-cacher-ng start))
29
- node.ssh.exec(%(echo 'Acquire::HTTP { Proxy "http://127.0.0.1:3142"; };' | sudo tee /etc/apt/apt.conf.d/00proxy))
30
- node.ssh.exec(%(sudo grep "^MIRROR" /etc/default/lxc || echo 'MIRROR="http://127.0.0.1:3142/archive.ubuntu.com/ubuntu"' | sudo tee -a /etc/default/lxc))
31
- node.ssh.exec(%(sudo service lxc restart || sudo service lxc start))
27
+ script = <<-EOF
28
+ apt-get -y install apt-cacher-ng
29
+ service apt-cacher-ng restart || service apt-cacher-ng start
30
+ echo 'Acquire::HTTP { Proxy "http://127.0.0.1:3142"; };' | tee /etc/apt/apt.conf.d/00proxy
31
+ grep "^MIRROR" /etc/default/lxc || echo 'MIRROR="http://127.0.0.1:3142/archive.ubuntu.com/ubuntu"' | tee -a /etc/default/lxc && service lxc restart || service lxc start
32
+ EOF
33
+
34
+ node.ssh.bootstrap(script)
32
35
 
33
36
  true
34
37
  end
@@ -45,16 +48,20 @@ class TestLab
45
48
  gateway_ip = container.primary_interface.network.ip
46
49
  apt_conf_d_proxy_file = File.join(container.lxc.fs_root, "etc", "apt", "apt.conf.d", "00proxy")
47
50
 
48
- container.node.ssh.exec(%(sudo mkdir -pv #{File.dirname(apt_conf_d_proxy_file)}))
51
+ script = <<-EOF
52
+ mkdir -pv #{File.dirname(apt_conf_d_proxy_file)}
53
+ echo 'Acquire::HTTP { Proxy "http://#{gateway_ip}:3142"; };' | tee #{apt_conf_d_proxy_file}
54
+ EOF
49
55
 
50
- container.node.ssh.exec(%(echo 'Acquire::HTTP { Proxy "http://#{gateway_ip}:3142"; };' | sudo tee #{apt_conf_d_proxy_file}))
51
56
  container.config[:apt_cacher_exclude_hosts].each do |host|
52
- container.node.ssh.exec(%(echo 'Acquire::HTTP::Proxy::#{host} "DIRECT";' | sudo tee -a #{apt_conf_d_proxy_file}))
57
+ script << %(echo 'Acquire::HTTP::Proxy::#{host} "DIRECT";' | tee -a #{apt_conf_d_proxy_file}\n)
53
58
  end
54
59
 
55
60
  # Fix the APT sources since LXC mudges them when using apt-cacher-ng
56
61
  apt_conf_sources_file = File.join(container.lxc.fs_root, "etc", "apt", "sources.list")
57
- container.node.ssh.exec(%(sudo sed -i 's/127.0.0.1:3142\\///g' #{apt_conf_sources_file}))
62
+ script << %(sed -i 's/127.0.0.1:3142\\///g' #{apt_conf_sources_file}\n)
63
+
64
+ container.node.ssh.bootstrap(script)
58
65
  end
59
66
 
60
67
  # AptCacherNG Provisioner Container Teardown
@@ -0,0 +1,127 @@
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
+ @config[:version] ||= "latest"
19
+ @config[:prereleases] ||= false
20
+ @config[:nightlies] ||= false
21
+
22
+ @ui.logger.debug { "config(#{@config.inspect})" }
23
+ end
24
+
25
+ # ChefGem 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 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
+ # ChefGem Provisioner Container Teardown
52
+ #
53
+ # This is a NO-OP currently.
54
+ #
55
+ # @return [Boolean] True if successful.
56
+ def 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,6 +1,6 @@
1
1
  class TestLab
2
2
  unless const_defined?(:VERSION)
3
3
  # TestLab Gem Version
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.3"
5
5
  end
6
6
  end
data/lib/testlab.rb CHANGED
@@ -169,8 +169,6 @@ class TestLab
169
169
  #
170
170
  # @return [Boolean] True if successful.
171
171
  def setup
172
- self.dead? and raise TestLabError, "You must have a running node in order to setup your infrastructure!"
173
-
174
172
  node_method_proxy(:setup)
175
173
 
176
174
  true
@@ -183,8 +181,6 @@ class TestLab
183
181
  #
184
182
  # @return [Boolean] True if successful.
185
183
  def teardown
186
- self.dead? and raise TestLabError, "You must have a running node in order to teardown your infrastructure!"
187
-
188
184
  node_method_proxy(:teardown)
189
185
 
190
186
  true
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.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -249,6 +249,7 @@ files:
249
249
  - lib/testlab/providers/vagrant.rb
250
250
  - lib/testlab/provisioner.rb
251
251
  - lib/testlab/provisioners/apt_cacher_ng.rb
252
+ - lib/testlab/provisioners/chef_gem.rb
252
253
  - lib/testlab/provisioners/omnibus.rb
253
254
  - lib/testlab/provisioners/omnitruck.rb
254
255
  - lib/testlab/provisioners/shell.rb
@@ -284,18 +285,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
284
285
  - - ! '>='
285
286
  - !ruby/object:Gem::Version
286
287
  version: '0'
287
- segments:
288
- - 0
289
- hash: 2167102659908500318
290
288
  required_rubygems_version: !ruby/object:Gem::Requirement
291
289
  none: false
292
290
  requirements:
293
291
  - - ! '>='
294
292
  - !ruby/object:Gem::Version
295
293
  version: '0'
296
- segments:
297
- - 0
298
- hash: 2167102659908500318
299
294
  requirements: []
300
295
  rubyforge_project:
301
296
  rubygems_version: 1.8.25