rubber 1.13.2 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/CHANGELOG +9 -0
  2. data/VERSION +1 -1
  3. data/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +9 -1
  4. data/generators/vulcanize/templates/base/config/rubber/rubber-rvm.yml +3 -0
  5. data/generators/vulcanize/templates/mysql/config/rubber/common/database.yml +1 -1
  6. data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/database.yml +1 -1
  7. data/generators/vulcanize/templates/redis/config/rubber/rubber-redis.yml +1 -1
  8. data/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +1 -1
  9. data/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/monit-sphinx.conf +2 -2
  10. data/lib/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +9 -1
  11. data/lib/generators/vulcanize/templates/base/config/rubber/rubber-rvm.yml +3 -0
  12. data/lib/generators/vulcanize/templates/mysql/config/rubber/common/database.yml +1 -1
  13. data/lib/generators/vulcanize/templates/mysql_proxy/config/rubber/common/database.yml +1 -1
  14. data/lib/generators/vulcanize/templates/redis/config/rubber/rubber-redis.yml +1 -1
  15. data/lib/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +1 -1
  16. data/lib/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/monit-sphinx.conf +2 -2
  17. data/lib/rubber/instance.rb +4 -2
  18. data/lib/rubber/recipes/rubber/deploy.rb +1 -1
  19. data/lib/rubber/recipes/rubber/instances.rb +1 -1
  20. data/lib/rubber/recipes/rubber/setup.rb +2 -20
  21. data/lib/rubber/recipes/rubber/static_ips.rb +2 -0
  22. data/lib/rubber/recipes/rubber/volumes.rb +8 -2
  23. data/lib/rubber/tasks/rubber.rb +1 -1
  24. metadata +5 -16
  25. data/test/environment_test.rb +0 -137
  26. data/test/generator_test.rb +0 -370
  27. data/test/instance_test.rb +0 -180
  28. data/test/test_helper.rb +0 -14
  29. data/test/util_test.rb +0 -19
  30. data/test/zerigo_test.rb +0 -88
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ 1.14.0 (06/02/2011)
2
+ -----
3
+
4
+ Projects using bundler will now run rake with bundle exec
5
+ Added ability to lockdown the version of rake that RVM will install (vulcanize base for the changes)
6
+ Added the image type and ID for each instance to the instance file
7
+ Fixed an issue with LVM groups keeping physical volumes in /etc/fstab
8
+ Fixed an issue using the mysql2 adapter with the stock MySQL config
9
+
1
10
  1.13.2
2
11
  -----
3
12
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.13.2
1
+ 1.14.0
@@ -37,11 +37,19 @@ namespace :rubber do
37
37
 
38
38
  bash ./scripts/install
39
39
 
40
+ # Set up the rubygems version
40
41
  sed -i 's/rubygems_version=.*/rubygems_version=#{rubber_env.rubygems_version}/' #{rubber_env.rvm_prefix}/config/db
41
42
 
43
+ # Set up the rake version
44
+ sed -i 's/rake.*/rake -v#{rubber_env.rake_version}/' #{rubber_env.rvm_prefix}/gemsets/default.gems
45
+ sed -i 's/rake.*/rake -v#{rubber_env.rake_version}/' #{rubber_env.rvm_prefix}/gemsets/global.gems
46
+
47
+ # Set up the .gemrc file
48
+ echo "--- " >> ~/.gemrc
49
+ echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
50
+
42
51
  #
43
52
  # end rvm install script
44
-
45
53
  fi
46
54
  ENDSCRIPT
47
55
  end
@@ -22,6 +22,9 @@ rvm_ruby: 1.9.2
22
22
  # know about newer RubyGems. So you may need to bump your rvm_version to get the latest RubyGems release.
23
23
  rubygems_version: 1.5.2
24
24
 
25
+ # REQUIRED: Set to version of rake you want RVM to install.
26
+ rake_version: 0.8.7
27
+
25
28
  # When rvm is installed as root, and you set the default, it symlinks ruby executables
26
29
  # into /usr/local/rvm
27
30
  ruby_prefix: /usr/local/rvm
@@ -3,7 +3,7 @@
3
3
  %>
4
4
 
5
5
  <%= RUBBER_ENV %>:
6
- adapter: mysql
6
+ adapter: <%= YAML::load(File.open("#{RUBBER_ROOT}/config/database.yml"))["production"]["adapter"] %>
7
7
  encoding: utf8
8
8
  database: <%= rubber_env.db_name %>
9
9
  username: <%= rubber_env.db_user %>
@@ -5,7 +5,7 @@
5
5
  # Sets up rails to talk to mysql-proxy load balancer running on localhost,
6
6
  # which then then balances requests between sql nodes in the cluster
7
7
  <%= RUBBER_ENV %>:
8
- adapter: mysql
8
+ adapter: <%= YAML::load(File.open("#{RUBBER_ROOT}/config/database.yml"))["production"]["adapter"] %>
9
9
  encoding: utf8
10
10
  database: <%= rubber_env.db_name %>
11
11
  username: <%= rubber_env.db_user %>
@@ -1,4 +1,4 @@
1
- redis_server_version: 2.2.1
1
+ redis_server_version: 2.2.8
2
2
 
3
3
  redis_db_dir: /mnt/redis
4
4
 
@@ -72,7 +72,7 @@ namespace :rubber do
72
72
 
73
73
  # runs the given ultrasphinx rake tasks
74
74
  def run_sphinx task
75
- rsudo "cd #{current_path} && RAILS_ENV=#{RUBBER_ENV} rake #{task}", :as => runner
75
+ rsudo "cd #{current_path} && RAILS_ENV=#{RUBBER_ENV} #{fetch(:rake, 'rake')} #{task}", :as => runner
76
76
  end
77
77
 
78
78
 
@@ -2,8 +2,8 @@
2
2
  @path = '/etc/monit/monit.d/monit-sphinx.conf'
3
3
 
4
4
  pidfile = "#{RUBBER_ROOT}/log/searchd.#{RUBBER_ENV}.pid"
5
- start_program = "cd #{RUBBER_ROOT} && rake ts:start"
6
- stop_program = "cd #{RUBBER_ROOT} && rake ts:stop"
5
+ start_program = "cd #{RUBBER_ROOT} && #{fetch(:rake, 'rake')} ts:start"
6
+ stop_program = "cd #{RUBBER_ROOT} && #{fetch(:rake, 'rake')} ts:stop"
7
7
  %>
8
8
 
9
9
  check process sphinx with pidfile <%= pidfile %>
@@ -37,11 +37,19 @@ namespace :rubber do
37
37
 
38
38
  bash ./scripts/install
39
39
 
40
+ # Set up the rubygems version
40
41
  sed -i 's/rubygems_version=.*/rubygems_version=#{rubber_env.rubygems_version}/' #{rubber_env.rvm_prefix}/config/db
41
42
 
43
+ # Set up the rake version
44
+ sed -i 's/rake.*/rake -v#{rubber_env.rake_version}/' #{rubber_env.rvm_prefix}/gemsets/default.gems
45
+ sed -i 's/rake.*/rake -v#{rubber_env.rake_version}/' #{rubber_env.rvm_prefix}/gemsets/global.gems
46
+
47
+ # Set up the .gemrc file
48
+ echo "--- " >> ~/.gemrc
49
+ echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
50
+
42
51
  #
43
52
  # end rvm install script
44
-
45
53
  fi
46
54
  ENDSCRIPT
47
55
  end
@@ -22,6 +22,9 @@ rvm_ruby: 1.9.2
22
22
  # know about newer RubyGems. So you may need to bump your rvm_version to get the latest RubyGems release.
23
23
  rubygems_version: 1.5.2
24
24
 
25
+ # REQUIRED: Set to version of rake you want RVM to install.
26
+ rake_version: 0.8.7
27
+
25
28
  # When rvm is installed as root, and you set the default, it symlinks ruby executables
26
29
  # into /usr/local/rvm
27
30
  ruby_prefix: /usr/local/rvm
@@ -3,7 +3,7 @@
3
3
  %>
4
4
 
5
5
  <%= RUBBER_ENV %>:
6
- adapter: mysql
6
+ adapter: <%= YAML::load(File.open("#{RUBBER_ROOT}/config/database.yml"))["production"]["adapter"] %>
7
7
  encoding: utf8
8
8
  database: <%= rubber_env.db_name %>
9
9
  username: <%= rubber_env.db_user %>
@@ -5,7 +5,7 @@
5
5
  # Sets up rails to talk to mysql-proxy load balancer running on localhost,
6
6
  # which then then balances requests between sql nodes in the cluster
7
7
  <%= RUBBER_ENV %>:
8
- adapter: mysql
8
+ adapter: <%= YAML::load(File.open("#{RUBBER_ROOT}/config/database.yml"))["production"]["adapter"] %>
9
9
  encoding: utf8
10
10
  database: <%= rubber_env.db_name %>
11
11
  username: <%= rubber_env.db_user %>
@@ -1,4 +1,4 @@
1
- redis_server_version: 2.2.1
1
+ redis_server_version: 2.2.8
2
2
 
3
3
  redis_db_dir: /mnt/redis
4
4
 
@@ -72,7 +72,7 @@ namespace :rubber do
72
72
 
73
73
  # runs the given ultrasphinx rake tasks
74
74
  def run_sphinx task
75
- rsudo "cd #{current_path} && RAILS_ENV=#{RUBBER_ENV} rake #{task}", :as => runner
75
+ rsudo "cd #{current_path} && RAILS_ENV=#{RUBBER_ENV} #{fetch(:rake, 'rake')} #{task}", :as => runner
76
76
  end
77
77
 
78
78
 
@@ -2,8 +2,8 @@
2
2
  @path = '/etc/monit/monit.d/monit-sphinx.conf'
3
3
 
4
4
  pidfile = "#{RUBBER_ROOT}/log/searchd.#{RUBBER_ENV}.pid"
5
- start_program = "cd #{RUBBER_ROOT} && rake ts:start"
6
- stop_program = "cd #{RUBBER_ROOT} && rake ts:stop"
5
+ start_program = "cd #{RUBBER_ROOT} && #{fetch(:rake, 'rake')} ts:start"
6
+ stop_program = "cd #{RUBBER_ROOT} && #{fetch(:rake, 'rake')} ts:stop"
7
7
  %>
8
8
 
9
9
  check process sphinx with pidfile <%= pidfile %>
@@ -114,7 +114,7 @@ module Rubber
114
114
 
115
115
  # The configuration for a single instance
116
116
  class InstanceItem
117
- attr_reader :name, :domain, :instance_id, :security_groups
117
+ attr_reader :name, :domain, :instance_id, :image_type, :image_id, :security_groups
118
118
  attr_accessor :roles, :zone
119
119
  attr_accessor :external_host, :external_ip
120
120
  attr_accessor :internal_host, :internal_ip
@@ -122,11 +122,13 @@ module Rubber
122
122
  attr_accessor :spot_instance_request_id
123
123
  attr_accessor :platform
124
124
 
125
- def initialize(name, domain, roles, instance_id, security_group_list=[])
125
+ def initialize(name, domain, roles, instance_id, image_type, image_id, security_group_list=[])
126
126
  @name = name
127
127
  @domain = domain
128
128
  @roles = roles
129
129
  @instance_id = instance_id
130
+ @image_type = image_type
131
+ @image_id = image_id
130
132
  @security_groups = security_group_list
131
133
  end
132
134
 
@@ -84,7 +84,7 @@ namespace :rubber do
84
84
  put(File.read(secret), File.join(path, base, File.basename(secret)), :mode => "+r")
85
85
  end
86
86
 
87
- rsudo "cd #{path} && #{extra_env} rake rubber:config"
87
+ rsudo "cd #{path} && #{extra_env} #{fetch(:rake, 'rake')} rubber:config"
88
88
  end
89
89
 
90
90
  end
@@ -295,7 +295,7 @@ namespace :rubber do
295
295
 
296
296
  logger.info "Instance #{instance_alias} created: #{instance_id}"
297
297
 
298
- instance_item = Rubber::Configuration::InstanceItem.new(instance_alias, env.domain, instance_roles, instance_id, security_groups)
298
+ instance_item = Rubber::Configuration::InstanceItem.new(instance_alias, env.domain, instance_roles, instance_id, ami_type, ami, security_groups)
299
299
  instance_item.spot_instance_request_id = request_id if create_spot_instance
300
300
  rubber_instances.add(instance_item)
301
301
  rubber_instances.save()
@@ -1,3 +1,5 @@
1
+ require "bundler/capistrano" if Rubber::Util.is_bundler?
2
+
1
3
  namespace :rubber do
2
4
 
3
5
  desc <<-DESC
@@ -257,26 +259,6 @@ namespace :rubber do
257
259
  gem_helper(false)
258
260
  end
259
261
 
260
- desc <<-DESC
261
- Install ruby gems defined in Gemfile
262
- DESC
263
- after "deploy:update_code", "rubber:install_bundler_gems" if Rubber::Util.is_bundler?
264
- task :install_bundler_gems do
265
- # copied from bundler/capistrano in bundler distro
266
- bundle_dir = fetch(:bundle_dir, " #{fetch(:shared_path)}/bundle")
267
- bundle_without = [*fetch(:bundle_without, [:development, :test])].compact
268
- bundle_flags = fetch(:bundle_flags, "--deployment --quiet")
269
- bundle_gemfile = fetch(:bundle_gemfile, "Gemfile")
270
- bundle_cmd = fetch(:bundle_cmd, "bundle")
271
-
272
- args = ["--gemfile #{fetch(:latest_release)}/#{bundle_gemfile}"]
273
- args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
274
- args << bundle_flags.to_s
275
- args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?
276
-
277
- rsudo "#{bundle_cmd} install #{args.join(' ')}"
278
- end
279
-
280
262
  desc <<-DESC
281
263
  Install ruby gems defined in the rails environment.rb
282
264
  DESC
@@ -134,6 +134,7 @@ namespace :rubber do
134
134
  # First half of the sync.
135
135
  new_receiver = Rubber::Configuration::InstanceItem.new(old_receiver.name,
136
136
  old_receiver.domain, old_receiver.roles, old_receiver.instance_id,
137
+ old_receiver.image_type, old_receiver.image_id,
137
138
  old_receiver.security_groups)
138
139
  new_receiver.static_ip = static_ip
139
140
  rubber_instances.add(new_receiver)
@@ -153,6 +154,7 @@ namespace :rubber do
153
154
  # Second half of the sync.
154
155
  new_donor = Rubber::Configuration::InstanceItem.new(old_donor.name,
155
156
  old_donor.domain, old_donor.roles, old_donor.instance_id,
157
+ old_donor.image_type, old_donor.image_id,
156
158
  old_donor.security_groups)
157
159
  rubber_instances.add(new_donor)
158
160
 
@@ -221,12 +221,12 @@ namespace :rubber do
221
221
 
222
222
  task :_setup_raid_volume, :hosts => ic.external_ip do
223
223
  rubber.sudo_script 'setup_raid_volume', <<-ENDSCRIPT
224
- if ! grep -q '#{raid_spec['device']}' /etc/fstab; then
224
+ if ! grep -qE '#{raid_spec['device']}|#{raid_spec['mount']}' /etc/fstab; then
225
225
  if mount | grep -q '#{raid_spec['mount']}'; then
226
226
  umount '#{raid_spec['mount']}'
227
227
  fi
228
228
  mv /etc/fstab /etc/fstab.bak
229
- cat /etc/fstab.bak | grep -v '#{raid_spec['mount']}' > /etc/fstab
229
+ cat /etc/fstab.bak | grep -vE '#{raid_spec['device']}|#{raid_spec['mount']}' > /etc/fstab
230
230
  echo '#{raid_spec['device']} #{raid_spec['mount']} #{raid_spec['filesystem']} noatime 0 0 # rubber raid volume' >> /etc/fstab
231
231
 
232
232
  # seems to help devices initialize, otherwise mdadm fails because
@@ -325,10 +325,16 @@ namespace :rubber do
325
325
  for device in #{physical_volumes.join(' ')}
326
326
  do
327
327
  if ! pvdisplay $device >> /dev/null 2>&1; then
328
+
328
329
  if grep $device /etc/mtab; then
329
330
  umount $device
330
331
  fi
331
332
 
333
+ if grep -q "$device" /etc/fstab; then
334
+ mv /etc/fstab /etc/fstab.bak
335
+ cat /etc/fstab.bak | grep -v "$device\\b" > /etc/fstab
336
+ fi
337
+
332
338
  pvcreate $device
333
339
 
334
340
  # See if the volume group already exists. If so, add the new physical volume to it.
@@ -40,7 +40,7 @@ namespace :rubber do
40
40
  end
41
41
  env = cfg.environment.bind(roles, instance_alias)
42
42
  domain = env.domain
43
- instance = Rubber::Configuration::InstanceItem.new(instance_alias, domain, role_items, 'dummyid', ['dummygroup'])
43
+ instance = Rubber::Configuration::InstanceItem.new(instance_alias, domain, role_items, 'dummyid', 'm1.small', 'ami-7000f019' ['dummygroup'])
44
44
  instance.external_host = instance.full_name
45
45
  instance.external_ip = "127.0.0.1"
46
46
  instance.internal_host = instance.full_name
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rubber
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.13.2
5
+ version: 1.14.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Conway
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-23 00:00:00 -04:00
13
+ date: 2011-06-02 00:00:00 -04:00
14
14
  default_executable: vulcanize
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -466,12 +466,6 @@ files:
466
466
  - lib/rubber/thread_safe_proxy.rb
467
467
  - lib/rubber/util.rb
468
468
  - rails/init.rb
469
- - test/environment_test.rb
470
- - test/generator_test.rb
471
- - test/instance_test.rb
472
- - test/test_helper.rb
473
- - test/util_test.rb
474
- - test/zerigo_test.rb
475
469
  has_rdoc: true
476
470
  homepage: http://github.com/wr0ngway/rubber
477
471
  licenses: []
@@ -496,14 +490,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
496
490
  requirements: []
497
491
 
498
492
  rubyforge_project: rubber
499
- rubygems_version: 1.6.1
493
+ rubygems_version: 1.3.8
500
494
  signing_key:
501
495
  specification_version: 3
502
496
  summary: A capistrano plugin for managing multi-instance deployments to the cloud (ec2)
503
- test_files:
504
- - test/environment_test.rb
505
- - test/generator_test.rb
506
- - test/instance_test.rb
507
- - test/test_helper.rb
508
- - test/util_test.rb
509
- - test/zerigo_test.rb
497
+ test_files: []
498
+
@@ -1,137 +0,0 @@
1
- require 'rubygems'
2
- gem 'test-unit'
3
-
4
- require 'test/unit'
5
- require 'tempfile'
6
- require File.expand_path(File.join(__FILE__, '..', 'test_helper'))
7
-
8
- class EnvironmentTest < Test::Unit::TestCase
9
- include Rubber::Configuration
10
-
11
- def test_known_roles
12
- env = Rubber::Configuration::Environment.new("#{File.dirname(__FILE__)}/fixtures/basic")
13
- assert_equal ['role1', 'role2'], env.known_roles, "list of know roles not correct"
14
- end
15
-
16
- def test_env
17
- env = Rubber::Configuration::Environment.new("#{File.dirname(__FILE__)}/fixtures/basic")
18
- e = env.bind()
19
- assert_equal 'val1', e['var1'], 'env not retrieving right val'
20
- assert_equal 'val2', e['var2'], 'env not retrieving right val'
21
- assert_equal 'val1', e.var1, 'env not retrieving right val for method missing'
22
- assert_equal 'val2', e.var2, 'env not retrieving right val for method missing'
23
-
24
- assert_equal 'val3', e.var3, 'env not retrieving right val for config in supplemental file'
25
-
26
- e = env.bind('role1', 'nohost')
27
- assert_equal 'val1', e['var1'], 'env not retrieving right val'
28
- assert_equal 'role1val2', e['var2'], 'env not retrieving right val'
29
- assert_equal 'val1', e.var1, 'env not retrieving right val for method missing'
30
- assert_equal 'role1val2', e.var2, 'env not retrieving right val for method missing'
31
-
32
- e = env.bind('role1', 'host1')
33
- assert_equal 'val1', e['var1'], 'env not retrieving right val'
34
- assert_equal 'host1val2', e['var2'], 'env not retrieving right val'
35
- assert_equal 'val1', e.var1, 'env not retrieving right val for method missing'
36
- assert_equal 'host1val2', e.var2, 'env not retrieving right val for method missing'
37
-
38
- e = env.bind('norole', 'host1')
39
- assert_equal 'val1', e['var1'], 'env not retrieving right val'
40
- assert_equal 'host1val2', e['var2'], 'env not retrieving right val'
41
- assert_equal 'val1', e.var1, 'env not retrieving right val for method missing'
42
- assert_equal 'host1val2', e.var2, 'env not retrieving right val for method missing'
43
- end
44
-
45
- def test_host_override
46
- env = Rubber::Configuration::Environment.new("#{File.dirname(__FILE__)}/fixtures/basic")
47
- e = env.bind('norole', 'host2')
48
- assert_equal 'host2val3', e['var3'], 'env not retrieving right val'
49
- assert_equal %w[host2val4a host2val4b], e['var4'], 'env not retrieving right val'
50
- assert_equal [{'var51a' => 'val51a', 'var52a' => 'val52a'}, {'var53' => 'val53'}, {'var54' => 'val54'}], e['var5'], 'env not retrieving right val'
51
- end
52
-
53
- def test_combine
54
- env = Rubber::Configuration::Environment
55
- assert_equal "new", env.combine("old", "new"), "Last should win for scalar combine"
56
- assert_equal 5, env.combine(1, 5), "Last should win for scalar combine"
57
- assert_equal [1, 2, 3, 4], env.combine([1, 2, 3], [3, 4]), "Arrays should be unioned when combined"
58
- assert_equal({1 => "1", 2 => "2", 3 => "3", 4 => "4"}, env.combine({1 => "1", 2 => "2"}, {3 => "3", 4 => "4"}), "Maps should be unioned when combined")
59
- assert_equal({1 => "2"}, env.combine({1 => "1"}, {1 => "2"}), "Last should win for scalars in maps when combined")
60
- assert_equal({1 => {1 => "1", 2 => "2"}}, env.combine({1 => {1 => "1"}}, {1 => {2 => "2"}}), "Maps should be unioned recursively when combined")
61
- end
62
-
63
- def test_expansion
64
- env = Rubber::Configuration::Environment.new("#{File.dirname(__FILE__)}/fixtures/expansion")
65
- e = env.bind()
66
- assert_equal 'val1', e['var1']
67
- assert_equal 'val2', e['var2']
68
- assert_equal 'val1', e['var3']
69
- assert_equal '4 is val2', e['var4']
70
- assert_equal 'val1', e['var5']
71
- assert_equal %w[lv1 lv2 val1], e['list1']
72
- expected = {'mk1' => 'mv1', 'mk2' => 'mv2', 'mk3' => 'val2'}
73
- e.map1.each do |k, v|
74
- assert_equal expected[k], v
75
- end
76
-
77
- e = env.bind('role1', 'nohost')
78
- assert_equal 'role1val1', e['var1']
79
- assert_equal 'role1val1', e['var3']
80
- assert_equal %w[lv1 lv2 role1val1 role1lv1 role1val2], e['list1']
81
-
82
- e = env.bind('role1', 'host1')
83
- assert_equal 'host1val1', e['var1']
84
- assert_equal 'host1val1', e['var3']
85
- assert_equal %w[lv1 lv2 host1val1 role1lv1 host1val2 host1lv1], e['list1'] # lists are additive
86
-
87
- e = env.bind('norole', 'host1')
88
- assert_equal 'host1val1', e['var1']
89
- assert_equal 'host1val1', e['var3']
90
- assert_equal %w[lv1 lv2 host1val1 host1lv1 host1val2], e['list1']
91
- end
92
-
93
- def test_bool_expansion
94
- env = Rubber::Configuration::Environment.new("#{File.dirname(__FILE__)}/fixtures/expansion")
95
- e = env.bind()
96
- assert_equal true, e['truevar']
97
- assert_equal false, e['falsevar']
98
- assert_equal true, e['truevar_exp']
99
- assert 'true' != e['truevar_exp']
100
- assert_equal false, e['falsevar_exp']
101
- assert 'false' != e['falsevar_exp']
102
- assert_equal 'true thing', e['faketruevar_exp']
103
- end
104
-
105
- def test_secret_env
106
- env = Rubber::Configuration::Environment.new("#{File.dirname(__FILE__)}/fixtures/basic")
107
- e = env.bind()
108
- assert_nil e['rubber_secret'], 'env should not have secret set'
109
-
110
- fixture_dir = File.expand_path("#{File.dirname(__FILE__)}/fixtures/secret")
111
- env = Rubber::Configuration::Environment.new(fixture_dir)
112
- e = env.bind()
113
- assert_equal "#{fixture_dir}/secret.yml", e['rubber_secret'], 'env should have secret set'
114
- assert_equal "secret_val", e['secret_key'], 'env should have gotten setting from secret file'
115
- end
116
-
117
- def test_nested_ref
118
- env = Rubber::Configuration::Environment.new("#{File.dirname(__FILE__)}/fixtures/nested")
119
- e = env.bind()
120
- assert_equal 'val1', e.var1, 'env not retrieving right val'
121
- assert_equal 'val3', e.var2.var3, 'env not retrieving right val'
122
- assert_equal({'var5' => 'val5'}, e.var2.var4, 'env not retrieving right val')
123
- assert_equal ['val6a', 'val6b'], e.var2.var6, 'env not retrieving right val'
124
- assert_equal 'val1', e.var2.var7, 'env not retrieving right val'
125
- assert_equal 'val3', e.var2.var8, 'env not retrieving right val'
126
- assert_equal 'val5', e.var2.var9, 'env not retrieving right val'
127
- end
128
-
129
- def test_instances_in_expansion
130
- config = Rubber::Configuration::get_configuration('test', "#{File.dirname(__FILE__)}/fixtures/instance_expansion")
131
- config.environment
132
- e = config.environment.bind()
133
- e.stubs(:rubber_instances).returns(config.instance)
134
- assert_equal "50.1.1.1", e['var1']
135
- end
136
-
137
- end
@@ -1,370 +0,0 @@
1
- require 'rubygems'
2
- gem 'test-unit'
3
-
4
- require 'test/unit'
5
- require 'tempfile'
6
- require File.expand_path(File.join(__FILE__, '..', 'test_helper'))
7
-
8
- class GeneratorTest < Test::Unit::TestCase
9
- include Rubber::Configuration
10
-
11
- def test_validate
12
- assert_raise RuntimeError do
13
- src = <<-SRC
14
- hello
15
- SRC
16
- Generator.new(nil, nil, nil).transform(src)
17
- end
18
- assert_raise RuntimeError do
19
- src = <<-SRC
20
- <%
21
- @read_cmd = 'ls'
22
- %>
23
- hello
24
- SRC
25
- Generator.new(nil, nil, nil).transform(src)
26
- end
27
- assert_raise RuntimeError do
28
- src = <<-SRC
29
- <%
30
- @write_cmd = 'cat'
31
- %>
32
- hello
33
- SRC
34
- Generator.new(nil, nil, nil).transform(src)
35
- end
36
- end
37
-
38
- def test_simple_transform
39
- out_file = Tempfile.new('testsimple')
40
- src = <<-SRC
41
- <%
42
- @path = '#{out_file.path}'
43
- %>
44
- hello
45
- SRC
46
-
47
- Generator.new(nil, nil, nil).transform(src)
48
- assert File.exists?(out_file.path), "transform did not generate an output file"
49
- assert_equal "hello", File.read(out_file.path).strip, "transformed contents are incorrect"
50
- end
51
-
52
- def test_additive_transform
53
- out_file = Tempfile.new('testadditive')
54
- open(out_file.path, 'w') { |f| f.write("howdy\n")}
55
- src = <<-SRC
56
- <%
57
- @path = '#{out_file.path}'
58
- @additive = ['#start', '#end']
59
- %>
60
- hello
61
- SRC
62
-
63
- Generator.new(nil, nil, nil).transform(src)
64
- assert File.exists?(out_file.path), "transform did not generate an output file"
65
- assert_equal "howdy\n#start \n hello\n#end", File.read(out_file.path).strip, "transformed contents are incorrect"
66
-
67
- src += "neato\n"
68
- open(out_file.path, 'a') { |f| f.write("again\n")}
69
- Generator.new(nil, nil, nil).transform(src)
70
- assert File.exists?(out_file.path), "transform did not generate an output file"
71
- assert_equal "howdy\n#start \n hello\nneato\n#end\nagain", File.read(out_file.path).strip, "transformed contents are incorrect"
72
- end
73
-
74
- def test_post_command
75
- out_file = Tempfile.new('testpost')
76
- post_file = out_file.path + '.post'
77
- src = <<-SRC
78
- <%
79
- @path = '#{out_file.path}'
80
- @post = 'touch #{post_file}'
81
- %>
82
- hello
83
- SRC
84
-
85
- Generator.new(nil, nil, nil).transform(src)
86
- assert File.exists?(out_file.path), "transform did not generate an output file"
87
- assert File.exists?(post_file), "transform did not execute post"
88
- assert_equal "hello", File.read(out_file.path).strip, "transformed contents are incorrect"
89
-
90
- FileUtils.rm_f(post_file)
91
- Generator.new(nil, nil, nil).transform(src)
92
- assert File.exists?(out_file.path), "transform did not generate an output file"
93
- assert ! File.exists?(post_file), "post should not have been executed as dest file unchanged"
94
- assert_equal "hello", File.read(out_file.path).strip, "transformed contents are incorrect"
95
-
96
- FileUtils.rm_f(post_file)
97
- gen = Generator.new(nil, nil, nil)
98
- gen.force = true
99
- gen.transform(src)
100
- assert File.exists?(out_file.path), "transform did not generate an output file"
101
- assert File.exists?(post_file), "forced transform did not execute post"
102
- assert_equal "hello", File.read(out_file.path).strip, "transformed contents are incorrect"
103
-
104
- FileUtils.rm_f(post_file)
105
- gen = Generator.new(nil, nil, nil)
106
- gen.no_post = true
107
- gen.transform(src + "there")
108
- assert File.exists?(out_file.path), "transform did not generate an output file"
109
- assert ! File.exists?(post_file), "post should not have been generated for no_post option"
110
- assert_equal "hello\nthere", File.read(out_file.path).strip, "transformed contents are incorrect"
111
- end
112
-
113
- def test_stop_on_error
114
- out_file = Tempfile.new('teststoponerr')
115
- post_file = out_file.path + '.post'
116
- src = <<-SRC
117
- <%
118
- @path = '#{out_file.path}'
119
- @post = 'badcommand; touch #{post_file}'
120
- %>
121
- hello
122
- SRC
123
-
124
- g = Generator.new(nil, nil, nil)
125
- g.transform(src)
126
- assert File.exists?(out_file.path), "transform did not generate an output file"
127
- assert File.exists?(post_file), "transform did not execute post"
128
- assert_equal "hello", File.read(out_file.path).strip, "transformed contents are incorrect"
129
-
130
- FileUtils.rm_f(post_file)
131
- g = Generator.new(nil, nil, nil)
132
- g.stop_on_error_cmd = "function error_exit { exit 99; }; trap error_exit ERR"
133
- g.transform(src)
134
- assert File.exists?(out_file.path), "transform did not generate an output file"
135
- assert ! File.exists?(post_file), "post should not have been executed as comes after error"
136
- end
137
-
138
- def test_pipe_command
139
- out_file = Tempfile.new('testpipe')
140
- src = <<-SRC
141
- <%
142
- @read_cmd = 'echo hi'
143
- @write_cmd = 'cat > #{out_file.path}'
144
- %>
145
- hello
146
- SRC
147
-
148
- Generator.new(nil, nil, nil).transform(src)
149
- assert File.exists?(out_file.path), "transform did not generate to write_cmd"
150
- assert_equal "hello", File.read(out_file.path).strip, "transformed contents are incorrect"
151
-
152
- FileUtils.rm_f(out_file.path)
153
- src = <<-SRC
154
- <%
155
- @read_cmd = 'echo hi'
156
- @write_cmd = 'cat > #{out_file.path}'
157
- @additive = ['#start', '#end']
158
- %>
159
- hello
160
- SRC
161
-
162
- Generator.new(nil, nil, nil).transform(src)
163
- assert File.exists?(out_file.path), "transform did not generate to write_cmd"
164
- assert_equal "hi\n#start \n hello\n#end", File.read(out_file.path).strip, "transformed contents are incorrect"
165
-
166
- FileUtils.rm_f(out_file.path)
167
- src = <<-SRC
168
- <%
169
- @read_cmd = 'echo "#start\nthere\n#end\nhi\n"'
170
- @write_cmd = 'cat > #{out_file.path}'
171
- @additive = ['#start', '#end']
172
- %>
173
- hello
174
- SRC
175
-
176
- Generator.new(nil, nil, nil).transform(src)
177
- assert File.exists?(out_file.path), "transform did not generate to write_cmd"
178
- assert_equal "#start \n hello\n#end\nhi", File.read(out_file.path).strip, "transformed contents are incorrect"
179
-
180
- FileUtils.rm_f(out_file.path)
181
- src = <<-SRC
182
- <%
183
- @read_cmd = 'echo hi'
184
- @write_cmd = 'badcommand'
185
- %>
186
- hello
187
- SRC
188
-
189
- assert_raises do
190
- Generator.new(nil, nil, nil).transform(src)
191
- end
192
-
193
- end
194
-
195
- def list_dir(dir)
196
- l = Dir.entries(dir)
197
- l.delete_if {|d| d =~ /(^\.+$)|\.bak$/}
198
- end
199
-
200
- def test_scoping
201
- out_dir = "#{Dir::tmpdir}/test_rubber_scoping"
202
- FileUtils.rm_rf(out_dir)
203
- assert ! File.exists?(out_dir)
204
-
205
- g = Generator.new("#{File.dirname(__FILE__)}/fixtures/basic", nil, nil, :out_dir => out_dir)
206
- g.run()
207
- assert File.directory?(out_dir), "scoped transform did not create dir"
208
- assert_equal ['bar.conf', 'foo.conf'], list_dir(out_dir), "scoped transform did not create correct files"
209
- assert_equal "common", File.read("#{out_dir}/foo.conf").strip, "transformed contents are incorrect"
210
- assert_equal "common", File.read("#{out_dir}/bar.conf").strip, "transformed contents are incorrect"
211
-
212
- FileUtils.rm_rf(out_dir)
213
- assert ! File.exists?(out_dir)
214
-
215
- g = Generator.new("#{File.dirname(__FILE__)}/fixtures/basic", ['role1'], nil, :out_dir => out_dir)
216
- g.run()
217
- assert File.directory?(out_dir), "scoped transform did not create dir"
218
- assert_equal ['bar.conf', 'foo.conf'], list_dir(out_dir), "scoped transform did not create correct files"
219
- assert_equal "role1", File.read("#{out_dir}/foo.conf").strip, "transformed contents are incorrect"
220
- assert_equal "common", File.read("#{out_dir}/bar.conf").strip, "transformed contents are incorrect"
221
-
222
- FileUtils.rm_rf(out_dir)
223
- assert ! File.exists?(out_dir)
224
-
225
- g = Generator.new("#{File.dirname(__FILE__)}/fixtures/basic", ['role2', 'role1'], nil, :out_dir => out_dir)
226
- g.run()
227
- assert File.directory?(out_dir), "scoped transform did not create dir"
228
- assert_equal ['bar.conf', 'foo.conf'], list_dir(out_dir), "scoped transform did not create correct files"
229
- assert_equal "role2", File.read("#{out_dir}/foo.conf").strip, "transformed contents are incorrect"
230
- assert_equal "common", File.read("#{out_dir}/bar.conf").strip, "transformed contents are incorrect"
231
-
232
- FileUtils.rm_rf(out_dir)
233
- assert ! File.exists?(out_dir)
234
-
235
- g = Generator.new("#{File.dirname(__FILE__)}/fixtures/basic", ['role1'], 'host1', :out_dir => out_dir)
236
- g.run()
237
- assert File.directory?(out_dir), "scoped transform did not create dir"
238
- assert_equal ['bar.conf', 'foo.conf'], list_dir(out_dir), "scoped transform did not create correct files"
239
- assert_equal "host1", File.read("#{out_dir}/foo.conf").strip, "transformed contents are incorrect"
240
- assert_equal "common", File.read("#{out_dir}/bar.conf").strip, "transformed contents are incorrect"
241
-
242
-
243
- FileUtils.rm_rf(out_dir)
244
- end
245
-
246
- def test_ordering_of_additive
247
- out_dir = "#{Dir::tmpdir}/test_rubber_ordering"
248
- FileUtils.rm_rf(out_dir)
249
- assert ! File.exists?(out_dir)
250
-
251
- g = Generator.new("#{File.dirname(__FILE__)}/fixtures/generator_order", ['role2', 'role1'], 'host1', :out_dir => out_dir)
252
- g.run()
253
- assert File.directory?(out_dir), "transform did not create dir"
254
- assert_equal ['out.conf'], list_dir(out_dir), "transform did not create correct file"
255
- result = <<DATA
256
- # common first start
257
- first
258
- # common first end
259
- # common last start
260
- last
261
- # common last end
262
- # role1 first start
263
- role1 first
264
- # role1 first end
265
- # role1 last start
266
- role1 last
267
- # role1 last end
268
- # role2 first start
269
- role2 first
270
- # role2 first end
271
- # role2 last start
272
- role2 last
273
- # role2 last end
274
- # host1 first start
275
- host1 first
276
- # host1 first end
277
- # host1 last start
278
- host1 last
279
- # host1 last end
280
- DATA
281
- assert_equal result.strip, File.read("#{out_dir}/out.conf").strip, "transformed contents are incorrect"
282
-
283
- FileUtils.rm_rf(out_dir)
284
- end
285
-
286
- def test_file_pattern
287
- out_dir = "#{Dir::tmpdir}/test_rubber_scoping"
288
- FileUtils.rm_rf(out_dir)
289
- assert ! File.exists?(out_dir)
290
-
291
- g = Generator.new("#{File.dirname(__FILE__)}/fixtures/basic", nil, nil, :out_dir => out_dir)
292
- g.file_pattern = 'foo\.conf'
293
- g.run()
294
- assert File.directory?(out_dir), "scoped transform did not create dir"
295
- assert_equal ['foo.conf'], list_dir(out_dir), "scoped transform did not create correct files"
296
- assert_equal "common", File.read("#{out_dir}/foo.conf").strip, "transformed contents are incorrect"
297
- end
298
-
299
- def test_perms
300
- user = ENV['USER']
301
- group = `groups`.split.last
302
- out_file = Tempfile.new('testperms')
303
- src = <<-SRC
304
- <%
305
- @path = '#{out_file.path}'
306
- @perms = 0777
307
- @owner = '#{user}'
308
- @group = '#{group}'
309
- %>
310
- hello
311
- SRC
312
-
313
- Generator.new(nil, nil, nil).transform(src)
314
- assert File.exists?(out_file.path), "transform did not generate an output file"
315
- assert_equal "100777", sprintf("%o", File.stat(out_file.path).mode), "transformed permissions are incorrect"
316
- assert_equal Etc.getpwnam(user).uid, File.stat(out_file.path).uid, "transformed owner is incorrect"
317
- assert_equal Etc.getgrnam(group).gid, File.stat(out_file.path).gid, "transformed group is incorrect"
318
- end
319
-
320
- def test_skip
321
- out_file = Tempfile.new('testskip')
322
- File.delete(out_file.path)
323
- src = <<-SRC
324
- <%
325
- @skip = true
326
- @path = '#{out_file.path}'
327
- %>
328
- hello
329
- SRC
330
-
331
- Generator.new(nil, nil, nil).transform(src)
332
- assert ! File.exists?(out_file.path), "transform didn't skip generation of an output file"
333
- end
334
-
335
- def test_backup
336
- out_file = Tempfile.new('testbak')
337
- assert ! File.exists?("#{out_file.path}.bak")
338
- File.open(out_file.path, 'w') {|f| f.write("howdy")}
339
-
340
- src = <<-SRC
341
- <%
342
- @path = '#{out_file.path}'
343
- %>
344
- hello <%= Time.now.to_f %>
345
- SRC
346
-
347
- Generator.new(nil, nil, nil).transform(src)
348
-
349
- assert File.exists?("#{out_file.path}.bak"), "transform didn't generate backup"
350
- assert_match /howdy/, File.read("#{out_file.path}.bak"), "transform backup has wrong contents"
351
- end
352
-
353
- def test_no_backup
354
- out_file = Tempfile.new('testnobak')
355
- assert ! File.exists?("#{out_file.path}.bak")
356
- File.open(out_file.path, 'w') {|f| f.write("howdy")}
357
- src = <<-SRC
358
- <%
359
- @path = '#{out_file.path}'
360
- @backup = false
361
- %>
362
- hello <%= Time.now.to_f %>
363
- SRC
364
-
365
- Generator.new(nil, nil, nil).transform(src)
366
-
367
- assert ! File.exists?("#{out_file.path}.bak"), "transform shouldn't generate backup"
368
- end
369
-
370
- end
@@ -1,180 +0,0 @@
1
- require 'rubygems'
2
- gem 'test-unit'
3
-
4
- require 'test/unit'
5
- require 'tempfile'
6
- require File.expand_path(File.join(__FILE__, '..', 'test_helper'))
7
-
8
- class InstanceTest < Test::Unit::TestCase
9
- include Rubber::Configuration
10
-
11
- def setup
12
- @instance = Instance.new(Tempfile.new('testforrole').path)
13
- @instance.add(@i1 = InstanceItem.new('host1', 'domain.com', [RoleItem.new('role1')], ''))
14
- @instance.add(@i2 = InstanceItem.new('host2', 'domain.com', [RoleItem.new('role1')], ''))
15
- @instance.add(@i3 = InstanceItem.new('host3', 'domain.com', [RoleItem.new('role2')], ''))
16
- @instance.add(@i4 = InstanceItem.new('host4', 'domain.com', [RoleItem.new('role2', 'primary' => true)], ''))
17
- end
18
-
19
- def test_for_role
20
- assert_equal 2, @instance.for_role('role1').size, 'not finding correct instances for role'
21
- assert_equal 2, @instance.for_role('role2').size, 'not finding correct instances for role'
22
- assert_equal 1, @instance.for_role('role2', {}).size, 'not finding correct instances for role'
23
- assert_equal @i3, @instance.for_role('role2', {}).first, 'not finding correct instances for role'
24
- assert_equal 1, @instance.for_role('role2', 'primary' => true).size, 'not finding correct instances for role'
25
- assert_equal @i4, @instance.for_role('role2', 'primary' => true).first, 'not finding correct instances for role'
26
- end
27
-
28
- def test_unfiltered
29
- ENV['FILTER'] = nil
30
- ENV['FILTER_ROLES'] = nil
31
- setup
32
- assert_equal 4, @instance.filtered().size, 'should not filter for empty FILTER(_ROLES)'
33
- end
34
-
35
-
36
- def test_filtered
37
- ENV['FILTER_ROLES'] = nil
38
- ENV['FILTER'] = 'host1'
39
- setup
40
- assert_equal [@i1], @instance.filtered(), 'should have only filtered host'
41
-
42
- ENV['FILTER'] = 'host2 , host4'
43
- setup
44
- assert_equal [@i2, @i4], @instance.filtered(), 'should have only filtered hosts'
45
-
46
- ENV['FILTER'] = '-host2'
47
- setup
48
- assert_equal [@i1, @i3, @i4], @instance.filtered(), 'should not have negated hosts'
49
-
50
- ENV['FILTER'] = 'host1,host2,-host2'
51
- setup
52
- assert_equal [@i1], @instance.filtered(), 'should not have negated hosts'
53
-
54
- ENV['FILTER'] = 'host1~host3'
55
- setup
56
- assert_equal [@i1, @i2, @i3], @instance.filtered(), 'should allow range in filter'
57
-
58
- ENV['FILTER'] = '-host1~-host3'
59
- setup
60
- assert_equal [@i4], @instance.filtered(), 'should allow negative range in filter'
61
-
62
- ENV['FILTER'] = '-host1'
63
- ENV['FILTER_ROLES'] = 'role1'
64
- setup
65
- assert_equal [@i2], @instance.filtered(), 'should not have negated roles'
66
- end
67
-
68
- def test_filtered_roles
69
- ENV['FILTER'] = nil
70
- ENV['FILTER_ROLES'] = 'role1'
71
- setup
72
- assert_equal [@i1, @i2], @instance.filtered(), 'should have only filtered roles'
73
-
74
- ENV['FILTER_ROLES'] = 'role1 , role2'
75
- setup
76
- assert_equal [@i1, @i2, @i3, @i4], @instance.filtered(), 'should have only filtered roles'
77
-
78
- ENV['FILTER_ROLES'] = '-role1'
79
- setup
80
- assert_equal [@i3, @i4], @instance.filtered(), 'should not have negated roles'
81
-
82
- ENV['FILTER_ROLES'] = 'role1~role2'
83
- setup
84
- assert_equal [@i1, @i2, @i3, @i4], @instance.filtered(), 'should allow range in filter'
85
-
86
- ENV['FILTER_ROLES'] = '-role1~-role2'
87
- setup
88
- assert_equal [], @instance.filtered(), 'should allow negative range in filter'
89
- end
90
-
91
- def test_validate_filters
92
- ENV['FILTER'] = "nohost"
93
- setup
94
- assert_raises do
95
- @instance.filtered()
96
- end
97
-
98
- ENV['FILTER'] = "-nohost"
99
- setup
100
- assert_raises do
101
- @instance.filtered()
102
- end
103
-
104
- ENV['FILTER_ROLES'] = "norole"
105
- setup
106
- assert_raises do
107
- @instance.filtered()
108
- end
109
-
110
- ENV['FILTER_ROLES'] = "-norole"
111
- setup
112
- assert_raises do
113
- @instance.filtered()
114
- end
115
- end
116
-
117
- def test_equality
118
- assert RoleItem.new('a').eql?(RoleItem.new('a'))
119
- assert RoleItem.new('a') == RoleItem.new('a')
120
- assert_equal RoleItem.new('a').hash, RoleItem.new('a').hash
121
-
122
- assert ! RoleItem.new('a').eql?(RoleItem.new('b'))
123
- assert RoleItem.new('a') != RoleItem.new('b')
124
- assert_not_equal RoleItem.new('a').hash, RoleItem.new('b').hash
125
-
126
- assert RoleItem.new('a', {'a' => 'b', 1 => true}).eql?(RoleItem.new('a', {'a' => 'b', 1 => true}))
127
- assert RoleItem.new('a', {'a' => 'b', 1 => true}) == RoleItem.new('a', {'a' => 'b', 1 => true})
128
- assert_equal RoleItem.new('a', {'a' => 'b', 1 => true}).hash, RoleItem.new('a', {'a' => 'b', 1 => true}).hash
129
-
130
- assert ! RoleItem.new('a', {'a' => 'b', 1 => true}).eql?(RoleItem.new('a', {'a' => 'b', 2 => true}))
131
- assert RoleItem.new('a', {'a' => 'b', 1 => true}) != RoleItem.new('a', {'a' => 'b', 2 => true})
132
- assert_equal RoleItem.new('a', {'a' => 'b', 1 => true}).hash, RoleItem.new('a', {'a' => 'b', 2 => true}).hash
133
- end
134
-
135
- def test_role_parse
136
- assert_equal RoleItem.new('a'), RoleItem.parse("a")
137
- assert_equal RoleItem.new('a', {'b' => 'c'}), RoleItem.parse("a:b=c")
138
- assert_equal RoleItem.new('a', {'b' => 'c', 'd' => 'e'}), RoleItem.parse("a:b=c;d=e")
139
- assert_equal RoleItem.new('a', {'b' => true, 'c' => false}), RoleItem.parse("a:b=true;c=false")
140
- end
141
-
142
- def test_role_to_s
143
- assert_equal "a", RoleItem.new('a').to_s
144
- assert_equal "a:b=c", RoleItem.new('a', {'b' => 'c'}).to_s
145
- assert_equal "a:b=c;d=e", RoleItem.new('a', {'b' => 'c', 'd' => 'e'}).to_s
146
- assert_equal "a:b=true;c=false", RoleItem.new('a', {'b' => true, 'c' => false}).to_s
147
- end
148
-
149
- def test_expand_role_dependencies
150
- deps = { RoleItem.new('a') => RoleItem.new('b'),
151
- RoleItem.new('b') => RoleItem.new('c'),
152
- RoleItem.new('c') => [RoleItem.new('d'), RoleItem.new('a')]}
153
- roles = [RoleItem.new('a'),RoleItem.new('b'),RoleItem.new('c'),RoleItem.new('d')]
154
- assert_equal roles, RoleItem.expand_role_dependencies(RoleItem.new('a'), deps).sort
155
- assert_equal roles, RoleItem.expand_role_dependencies([RoleItem.new('a'), RoleItem.new('d')], deps).sort
156
-
157
- deps = { RoleItem.new('mysql_master') => RoleItem.new('db', {'primary' => true}),
158
- RoleItem.new('mysql_slave') => RoleItem.new('db'),
159
- RoleItem.new('db', {'primary' => true}) => RoleItem.new('mysql_master'),
160
- RoleItem.new('db') => RoleItem.new('mysql_slave')
161
- }
162
- assert_equal [RoleItem.new('db', 'primary' => true), RoleItem.new('mysql_master')],
163
- RoleItem.expand_role_dependencies(RoleItem.new('mysql_master'), deps).sort
164
- assert_equal [RoleItem.new('db', 'primary' => true), RoleItem.new('mysql_master')],
165
- RoleItem.expand_role_dependencies(RoleItem.new('db', 'primary' => true), deps).sort
166
- assert_equal [RoleItem.new('db'), RoleItem.new('mysql_slave')],
167
- RoleItem.expand_role_dependencies(RoleItem.new('mysql_slave'), deps).sort
168
- assert_equal [RoleItem.new('db'), RoleItem.new('mysql_slave')],
169
- RoleItem.expand_role_dependencies(RoleItem.new('db'), deps).sort
170
-
171
- end
172
-
173
- def test_common_dependencies
174
- deps = { RoleItem.new('a') => RoleItem.new('b'),
175
- RoleItem.new('common') => [RoleItem.new('c')]}
176
- roles = [RoleItem.new('a'), RoleItem.new('b'), RoleItem.new('c')]
177
- assert_equal roles, RoleItem.expand_role_dependencies(RoleItem.new('a'), deps).sort
178
- end
179
-
180
- end
data/test/test_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- $:.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'rubber'
4
- Rubber::initialize(File.dirname(__FILE__), 'test')
5
-
6
- require 'rubygems'
7
- require 'mocha'
8
- require 'pp'
9
- require 'fakeweb'
10
- FakeWeb.allow_net_connect = false
11
-
12
- def fakeweb_fixture(name)
13
- return File.read("#{File.dirname(__FILE__)}/fixtures/fakeweb/#{name}")
14
- end
data/test/util_test.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'rubygems'
2
- gem 'test-unit'
3
-
4
- require 'test/unit'
5
- require File.expand_path(File.join(__FILE__, '..', 'test_helper'))
6
-
7
- class UtilTest < Test::Unit::TestCase
8
-
9
- def test_stringify
10
- assert_equal "", Rubber::Util::stringify(nil)
11
- assert_equal "hi", Rubber::Util::stringify("hi")
12
- assert_equal "1", Rubber::Util::stringify(1)
13
- assert_equal "3.4", Rubber::Util::stringify(3.4)
14
- assert_equal ["1", "2", "r"], Rubber::Util::stringify([1, 2, "r"])
15
- assert_equal({"1" => "2", "three" => "four"}, Rubber::Util::stringify({1 => 2, :three => "four"}))
16
- assert_equal [{"3" => "4"}], Rubber::Util::stringify([{3 => 4}])
17
- end
18
-
19
- end
data/test/zerigo_test.rb DELETED
@@ -1,88 +0,0 @@
1
- require 'rubygems'
2
- gem 'test-unit'
3
-
4
- require 'test/unit'
5
- require File.expand_path(File.join(__FILE__, '..', 'test_helper'))
6
- require 'rubber/dns'
7
- require 'rubber/dns/zerigo'
8
- require 'rexml/document'
9
-
10
- class ZerigoTest < Test::Unit::TestCase
11
-
12
- def setup
13
- env = Rubber::Configuration::Environment::BoundEnv.new({'dns_providers' => {'zerigo' => {'email' => 'foo@bar.com', 'token' => 'testtoken'}}}, nil, nil)
14
- @dns = Rubber::Dns::Zerigo.new(env)
15
- FakeWeb.register_uri(:get,
16
- "https://foo%40bar.com:testtoken@ns.zerigo.com/api/1.1/zones.xml",
17
- :body => fakeweb_fixture('zerigo/get_zones.xml'))
18
- @domain = "example1.com"
19
- @zone = ::Zerigo::DNS::Zone.find_or_create(@domain)
20
- end
21
-
22
- def test_find_records
23
- hosts_xml = fakeweb_fixture('zerigo/get_hosts.xml')
24
- FakeWeb.register_uri(:get,
25
- "https://foo%40bar.com:testtoken@ns.zerigo.com/api/1.1/hosts.xml?zone_id=1",
26
- :body => hosts_xml)
27
- records = @dns.find_host_records(:host => '*', :domain => 'example1.com')
28
- assert_equal 2, records.size
29
- assert_equal({:type=>"A", :host=>"host1", :domain=>"example1.com", :id=>1, :data=>"172.16.16.1"}, records.first)
30
-
31
- doc = REXML::Document.new(hosts_xml)
32
- doc.root.elements.delete(1)
33
- hosts_xml_single = doc.to_s
34
- FakeWeb.register_uri(:get,
35
- "https://foo%40bar.com:testtoken@ns.zerigo.com/api/1.1/hosts.xml?fqdn=example1.com&zone_id=1",
36
- :body => hosts_xml_single)
37
- records = @dns.find_host_records(:host => '', :domain => 'example1.com')
38
- assert_equal 1, records.size
39
- assert_equal '', records.first[:host]
40
-
41
- doc = REXML::Document.new(hosts_xml)
42
- doc.root.elements.delete(2)
43
- hosts_xml_single = doc.to_s
44
- FakeWeb.register_uri(:get,
45
- "https://foo%40bar.com:testtoken@ns.zerigo.com/api/1.1/hosts.xml?fqdn=host1.example1.com&zone_id=1",
46
- :body => hosts_xml_single)
47
- records = @dns.find_host_records(:host => 'host1', :domain => 'example1.com')
48
- assert_equal 1, records.size
49
- assert_equal 'host1', records.first[:host]
50
- end
51
-
52
- def test_create_record
53
- params = {:host => 'newhost', :domain => 'example1.com', :data => '1.1.1.1', :type => 'A', :ttl => '333'}
54
- dest_params = {'hostname' => 'newhost', 'data' => '1.1.1.1', 'host_type' => 'A', 'ttl' => '333', :zone_id => @zone.id}
55
-
56
- ::Zerigo::DNS::Host.expects(:create).with(dest_params)
57
-
58
- @dns.create_host_record(params)
59
- end
60
-
61
- def test_destroy_record
62
- params = {:host => 'host1', :domain => 'example1.com'}
63
-
64
- FakeWeb.register_uri(:get,
65
- "https://foo%40bar.com:testtoken@ns.zerigo.com/api/1.1/hosts.xml?fqdn=host1.example1.com&zone_id=1",
66
- :body => fakeweb_fixture('zerigo/host1.xml'))
67
- FakeWeb.register_uri(:delete,
68
- "https://foo%40bar.com:testtoken@ns.zerigo.com/api/1.1/hosts/1.xml",
69
- :body => "")
70
-
71
- @dns.destroy_host_record(params)
72
- end
73
-
74
- def test_update_record
75
- params = {:host => 'host1', :domain => 'example1.com', :data => "1.1.1.1"}
76
- new = {:host => 'host1', :domain => 'example1.com', :data => "1.1.1.2"}
77
-
78
- FakeWeb.register_uri(:get,
79
- "https://foo%40bar.com:testtoken@ns.zerigo.com/api/1.1/hosts.xml?fqdn=host1.example1.com&zone_id=1",
80
- :body => fakeweb_fixture('zerigo/host1.xml'))
81
- FakeWeb.register_uri(:post,
82
- "https://foo%40bar.com:testtoken@ns.zerigo.com/api/1.1/hosts/1.xml",
83
- :body => "")
84
-
85
- @dns.update_host_record(params, new)
86
- end
87
-
88
- end