rouster 0.7 → 0.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -3
  3. data/README.md +7 -241
  4. data/Rakefile +18 -55
  5. data/Vagrantfile +8 -26
  6. data/lib/rouster.rb +183 -404
  7. data/lib/rouster/deltas.rb +118 -577
  8. data/lib/rouster/puppet.rb +34 -209
  9. data/lib/rouster/testing.rb +59 -366
  10. data/lib/rouster/tests.rb +19 -70
  11. data/path_helper.rb +7 -5
  12. data/rouster.gemspec +1 -3
  13. data/test/basic.rb +1 -4
  14. data/test/functional/deltas/test_get_groups.rb +2 -74
  15. data/test/functional/deltas/test_get_packages.rb +4 -86
  16. data/test/functional/deltas/test_get_ports.rb +1 -26
  17. data/test/functional/deltas/test_get_services.rb +4 -43
  18. data/test/functional/deltas/test_get_users.rb +2 -35
  19. data/test/functional/puppet/test_facter.rb +1 -41
  20. data/test/functional/puppet/test_get_puppet_star.rb +68 -0
  21. data/test/functional/test_caching.rb +1 -5
  22. data/test/functional/test_dirs.rb +0 -25
  23. data/test/functional/test_get.rb +6 -10
  24. data/test/functional/test_inspect.rb +1 -1
  25. data/test/functional/test_is_file.rb +1 -17
  26. data/test/functional/test_new.rb +22 -233
  27. data/test/functional/test_put.rb +11 -9
  28. data/test/functional/test_restart.rb +4 -1
  29. data/test/functional/test_run.rb +3 -2
  30. data/test/puppet/test_apply.rb +11 -13
  31. data/test/puppet/test_roles.rb +173 -0
  32. data/test/unit/test_new.rb +0 -88
  33. data/test/unit/test_parse_ls_string.rb +0 -67
  34. data/test/unit/testing/test_validate_file.rb +47 -39
  35. data/test/unit/testing/test_validate_package.rb +10 -36
  36. metadata +6 -46
  37. data/.reek +0 -63
  38. data/.travis.yml +0 -11
  39. data/Gemfile +0 -17
  40. data/Gemfile.lock +0 -102
  41. data/LICENSE +0 -9
  42. data/examples/aws.rb +0 -85
  43. data/examples/openstack.rb +0 -61
  44. data/examples/passthrough.rb +0 -71
  45. data/lib/rouster/vagrant.rb +0 -311
  46. data/plugins/aws.rb +0 -347
  47. data/plugins/openstack.rb +0 -136
  48. data/test/functional/deltas/test_get_crontab.rb +0 -161
  49. data/test/functional/deltas/test_get_os.rb +0 -68
  50. data/test/functional/test_is_in_file.rb +0 -40
  51. data/test/functional/test_passthroughs.rb +0 -94
  52. data/test/functional/test_validate_file.rb +0 -131
  53. data/test/unit/puppet/resources/puppet_run_with_failed_exec +0 -59
  54. data/test/unit/puppet/resources/puppet_run_with_successful_exec +0 -61
  55. data/test/unit/puppet/test_get_puppet_star.rb +0 -91
  56. data/test/unit/puppet/test_puppet_parsing.rb +0 -44
  57. data/test/unit/testing/resources/osx-launchd +0 -285
  58. data/test/unit/testing/resources/rhel-systemd +0 -46
  59. data/test/unit/testing/resources/rhel-systemv +0 -41
  60. data/test/unit/testing/resources/rhel-upstart +0 -20
  61. data/test/unit/testing/test_get_services.rb +0 -178
  62. data/test/unit/testing/test_validate_cron.rb +0 -78
  63. data/test/unit/testing/test_validate_port.rb +0 -103
data/lib/rouster/tests.rb CHANGED
@@ -30,11 +30,6 @@ class Rouster
30
30
  return self.deltas[:files][dir]
31
31
  end
32
32
 
33
- if self.unittest and cache
34
- # preventing a functional test fallthrough
35
- return nil
36
- end
37
-
38
33
  begin
39
34
  raw = self.run(sprintf('ls -ld %s', dir))
40
35
  rescue Rouster::RemoteExecutionError
@@ -44,7 +39,7 @@ class Rouster
44
39
  if raw.match(/No such file or directory/)
45
40
  res = nil
46
41
  elsif raw.match(/Permission denied/)
47
- @logger.info(sprintf('dir(%s) output[%s], try with sudo', dir, raw)) unless self.uses_sudo?
42
+ @log.info(sprintf('dir(%s) output[%s], try with sudo', dir, raw)) unless self.uses_sudo?
48
43
  res = nil
49
44
  else
50
45
  res = parse_ls_string(raw)
@@ -67,11 +62,12 @@ class Rouster
67
62
  # * <dir> - path to directory to act on, full path or relative to ~vagrant/
68
63
  # * [wildcard] - glob of directories to match, defaults to '*'
69
64
  # * [recursive] - boolean controlling whether or not to look in directories recursively, defaults to false
70
- def dirs(dir, wildcard='*', insensitive=true, recursive=false)
65
+ def dirs(dir, wildcard='*', recursive=false)
71
66
  # TODO use a numerical, not boolean value for 'recursive' -- and rename to 'depth' ?
67
+ # TODO should we be running -iname ?
72
68
  raise InternalError.new(sprintf('invalid dir specified[%s]', dir)) unless self.is_dir?(dir)
73
69
 
74
- raw = self.run(sprintf("find %s %s -type d %s '%s'", dir, recursive ? '' : '-maxdepth 1', insensitive ? '-iname' : '-name', wildcard))
70
+ raw = self.run(sprintf("find %s %s -type d -name '%s'", dir, recursive ? '' : '-maxdepth 1', wildcard))
75
71
  res = Array.new
76
72
 
77
73
  raw.split("\n").each do |line|
@@ -108,11 +104,6 @@ class Rouster
108
104
  return self.deltas[:files][file]
109
105
  end
110
106
 
111
- if self.unittest and cache
112
- # preventing a functional test fallthrough
113
- return nil
114
- end
115
-
116
107
  begin
117
108
  raw = self.run(sprintf('ls -l %s', file))
118
109
  rescue Rouster::RemoteExecutionError
@@ -120,7 +111,7 @@ class Rouster
120
111
  end
121
112
 
122
113
  if raw.match(/No such file or directory/)
123
- @logger.info(sprintf('is_file?(%s) output[%s], try with sudo', file, raw)) unless self.uses_sudo?
114
+ @log.info(sprintf('is_file?(%s) output[%s], try with sudo', file, raw)) unless self.uses_sudo?
124
115
  res = nil
125
116
  elsif raw.match(/Permission denied/)
126
117
  res = nil
@@ -144,11 +135,11 @@ class Rouster
144
135
  # * <dir> - directory to look in, full path or relative to ~vagrant/
145
136
  # * [wildcard] - glob of files to match, defaults to '*'
146
137
  # * [recursive] - boolean controlling whether or not to look in directories recursively, defaults to false
147
- def files(dir, wildcard='*', insensitive=true, recursive=false)
138
+ def files(dir, wildcard='*', recursive=false)
148
139
  # TODO use a numerical, not boolean value for 'recursive'
149
140
  raise InternalError.new(sprintf('invalid dir specified[%s]', dir)) unless self.is_dir?(dir)
150
141
 
151
- raw = self.run(sprintf("find %s %s -type f %s '%s'", dir, recursive ? '' : '-maxdepth 1', insensitive ? '-iname' : '-name', wildcard))
142
+ raw = self.run(sprintf("find %s %s -type f -name '%s'", dir, recursive ? '' : '-maxdepth 1', wildcard))
152
143
  res = Array.new
153
144
 
154
145
  raw.split("\n").each do |line|
@@ -166,13 +157,7 @@ class Rouster
166
157
  # parameters
167
158
  # * <dir> - path of directory to validate
168
159
  def is_dir?(dir)
169
- res = nil
170
- begin
171
- res = self.dir(dir)
172
- rescue => e
173
- return false
174
- end
175
-
160
+ res = self.dir(dir)
176
161
  res.class.eql?(Hash) ? res[:directory?] : false
177
162
  end
178
163
 
@@ -226,14 +211,7 @@ class Rouster
226
211
  # parameters
227
212
  # * <file> - path of filename to validate
228
213
  def is_file?(file)
229
- res = nil
230
-
231
- begin
232
- res = self.file(file)
233
- rescue => e
234
- return false
235
- end
236
-
214
+ res = self.file(file)
237
215
  res.class.eql?(Hash) ? res[:file?] : false
238
216
  end
239
217
 
@@ -257,19 +235,18 @@ class Rouster
257
235
  # parameters
258
236
  # * <file> - path of filename to examine
259
237
  # * <regex> - regular expression/string to be passed to grep
260
- # * <flags> - flags to include in grep command
261
238
  # * [scp] - downloads file to host machine before grepping (functionality not implemented, was planned when a new SSH connection was required for each run() command, not sure it is necessary any longer)
262
- def is_in_file?(file, regex, flags='', scp=false)
239
+ def is_in_file?(file, regex, scp=false)
263
240
 
264
241
  res = nil
265
242
 
266
243
  if scp
267
244
  # download the file to a temporary directory
268
- @logger.warn('is_in_file? scp option not implemented yet')
245
+ @log.warn('is_in_file? scp option not implemented yet')
269
246
  end
270
247
 
271
248
  begin
272
- command = sprintf("grep -c%s '%s' %s", flags, regex, file)
249
+ command = sprintf("grep -c '%s' %s", regex, file)
273
250
  res = self.run(command)
274
251
  rescue Rouster::RemoteExecutionError
275
252
  return false
@@ -374,14 +351,14 @@ class Rouster
374
351
  # * RedHat
375
352
  # * Ubuntu
376
353
  def is_process_running?(name)
377
- # TODO support Solaris
378
- # TODO do better validation than just grepping for a matching filename, start with removing 'grep' from output
354
+ # TODO support other flavors - this will work on RHEL and OSX
355
+ # TODO do better validation than just grepping for a matching filename
379
356
  begin
380
357
 
381
358
  os = self.os_type()
382
359
 
383
360
  case os
384
- when :rhel, :osx, :ubuntu, :debian
361
+ when :redhat, :osx, :ubuntu
385
362
  res = self.run(sprintf('ps ax | grep -c %s', name))
386
363
  else
387
364
  raise InternalError.new(sprintf('currently unable to determine running process list on OS[%s]', os))
@@ -468,25 +445,6 @@ class Rouster
468
445
  end
469
446
  end
470
447
 
471
- ##
472
- # is_symlink?
473
- #
474
- # uses file() to return boolean indicating whether parameter passed is a symlink
475
- #
476
- # parameters
477
- # * <file> - path of filename to validate
478
- def is_symlink?(file)
479
- res = nil
480
-
481
- begin
482
- res = self.file(file)
483
- rescue => e
484
- return false
485
- end
486
-
487
- res.class.eql?(Hash) ? res[:symlink?] : false
488
- end
489
-
490
448
  ##
491
449
  # is_user?
492
450
  #
@@ -584,8 +542,8 @@ class Rouster
584
542
  value += 4
585
543
  when 'w'
586
544
  value += 2
587
- when 'x', 't', 's'
588
- # is 't' / 's' really right here? copying Salesforce::Vagrant
545
+ when 'x', 't'
546
+ # is 't' really right here? copying Salesforce::Vagrant
589
547
  value += 1
590
548
  when '-'
591
549
  # noop
@@ -599,27 +557,18 @@ class Rouster
599
557
  end
600
558
 
601
559
  res[:mode] = mode
560
+ res[:name] = tokens[-1] # TODO better here: this does not support files/dirs with spaces
602
561
  res[:owner] = tokens[2]
603
562
  res[:group] = tokens[3]
604
563
  res[:size] = tokens[4]
605
564
 
606
565
  res[:directory?] = tokens[0][0].chr.eql?('d')
607
566
  res[:file?] = ! res[:directory?]
608
- res[:symlink?] = tokens[0][0].chr.eql?('l')
609
567
  res[:executable?] = [ tokens[0][3].chr.eql?('x'), tokens[0][6].chr.eql?('x'), tokens[0][9].chr.eql?('x') || tokens[0][9].chr.eql?('t') ]
610
568
  res[:writeable?] = [ tokens[0][2].chr.eql?('w'), tokens[0][5].chr.eql?('w'), tokens[0][8].chr.eql?('w') ]
611
569
  res[:readable?] = [ tokens[0][1].chr.eql?('r'), tokens[0][4].chr.eql?('r'), tokens[0][7].chr.eql?('r') ]
612
570
 
613
- # TODO better here: this does not support files/dirs with spaces
614
- if res[:symlink?]
615
- # not sure if we should only be adding this value if we're a symlink, or adding it to all results and just using nil if not a link
616
- res[:target] = tokens[-1]
617
- res[:name] = tokens[-3]
618
- else
619
- res[:name] = tokens[-1]
620
- end
621
-
622
571
  res
623
572
  end
624
573
 
625
- end
574
+ end
data/path_helper.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  # heavily influenced by https://github.com/puppetlabs/hiera/blob/master/spec/spec_helper.rb
2
2
 
3
3
  # this gets us Rouster, still need to figure out how to find vagrant
4
- $LOAD_PATH << File.join([File.dirname(__FILE__), 'lib'])
5
- $LOAD_PATH << File.join([File.dirname(__FILE__), 'plugins'])
6
- $LOAD_PATH << File.expand_path(sprintf('%s/..', File.dirname(__FILE__)))
7
- $LOAD_PATH << File.dirname(__FILE__)
4
+ $LOAD_PATH << File.join([File.dirname(__FILE__), "lib"])
8
5
 
9
6
  require 'rubygems'
10
7
 
11
- # debugging help
8
+ ## this is really optional, so don't die if we don't have it
9
+ begin
10
+ require 'ruby-debug'
11
+ rescue LoadError
12
+ end
12
13
 
14
+ # debugging help
13
15
  class Object
14
16
  def my_methods
15
17
  # Cookbook implementation
data/rouster.gemspec CHANGED
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
12
12
  s.homepage = 'http://github.com/chorankates/rouster'
13
13
  s.summary = 'Rouster is an abstraction layer for Vagrant'
14
14
  s.description = 'Rouster allows you to programmatically control and interact with your existing Vagrant virtual machines'
15
- s.license = 'BSD 3-Clause'
16
15
 
17
16
  s.required_rubygems_version = '>= 1.3.6'
18
17
  s.rubyforge_project = 'Rouster'
@@ -23,8 +22,7 @@ Gem::Specification.new do |s|
23
22
  s.add_dependency 'net-ssh'
24
23
  s.add_dependency 'rake'
25
24
 
26
- s.add_development_dependency 'test-unit', '~> 2.0'
27
- s.add_development_dependency 'reek'
25
+ s.add_development_dependency 'test-unit'
28
26
 
29
27
  s.files = `git ls-files`.split("\n")
30
28
  end
data/test/basic.rb CHANGED
@@ -5,9 +5,6 @@ require 'rouster/puppet'
5
5
  require 'rouster/testing'
6
6
  require 'rouster/tests'
7
7
 
8
- #a = Rouster.new(:name => 'app', :verbosity => 1, :vagrantfile => '../piab/Vagrantfile', :retries => 3)
9
- #p = Rouster.new(:name => 'ppm', :verbosity => 1, :vagrantfile => '../piab/Vagrantfile')
10
- #r = Rouster.new(:name => 'app', :verbosity => 1, :vagrantfile => 'Vagrantfile')
11
- l = Rouster.new(:name => 'local', :passthrough => { :type => :local }, :verbosity => 3)
8
+ p = Rouster.new(:name => 'app', :verbosity => 0)
12
9
 
13
10
  p 'DBGZ' if nil?
@@ -8,7 +8,7 @@ class TestDeltasGetGroups < Test::Unit::TestCase
8
8
 
9
9
  def setup
10
10
  assert_nothing_raised do
11
- @app = Rouster.new(:name => 'app', :cache_timeout => 10)
11
+ @app = Rouster.new(:name => 'app')
12
12
  end
13
13
 
14
14
  @app.up()
@@ -39,79 +39,7 @@ class TestDeltasGetGroups < Test::Unit::TestCase
39
39
 
40
40
  end
41
41
 
42
- def test_without_caching
43
- old_groups, new_groups = nil, nil
44
-
45
- assert_nothing_raised do
46
- old_groups = @app.get_groups(false)
47
- end
48
-
49
- assert_nil(@app.deltas[:groups])
50
-
51
- new_group = sprintf('rouster-%s', Time.now.to_i)
52
-
53
- ## create a group here
54
- if @app.os_type.eql?(:rhel)
55
- @app.run(sprintf('groupadd %s', new_group))
56
- else
57
- omit('only doing group creation on RHEL hosts')
58
- end
59
-
60
- assert_nothing_raised do
61
- new_groups = @app.get_groups(false)
62
- end
63
-
64
- assert_nil(@app.deltas[:groups])
65
- assert_not_nil(new_groups[new_group])
66
- assert_not_equal(old_groups, new_groups)
67
-
68
- end
69
-
70
- def test_deep_inspection
71
- deep, shallow = nil, nil
72
-
73
- assert_nothing_raised do
74
- deep = @app.get_groups(false, true)
75
- shallow = @app.get_groups(false, false)
76
- end
77
-
78
- assert_not_equal(deep, shallow)
79
-
80
- ## this is not really the best test
81
- deep_none, shallow_none = 0, 0
82
-
83
- deep.each_key do |group|
84
- deep_none += 1 if deep[group][:users][0].eql?('NONE')
85
- end
86
-
87
- shallow.each_key do |group|
88
- shallow_none += 1 if shallow[group][:users][0].eql?('NONE')
89
- end
90
-
91
- assert(shallow_none > deep_none)
92
- end
93
-
94
- def test_happy_path_cache_invalidation
95
- res1, res2 = nil, nil
96
-
97
- assert_nothing_raised do
98
- res1 = @app.get_groups(true, false)
99
- end
100
-
101
- first_cache_time = @app.cache[:groups]
102
-
103
- sleep (@app.cache_timeout + 1)
104
-
105
- assert_nothing_raised do
106
- res2 = @app.get_groups(true, false)
107
- end
108
-
109
- second_cache_time = @app.cache[:groups]
110
-
111
- assert_equal(res1, res2)
112
- assert_not_equal(first_cache_time, second_cache_time)
113
-
114
- end
42
+ # TODO add some non-caching tests
115
43
 
116
44
  def teardown
117
45
  @app = nil
@@ -4,13 +4,11 @@ require 'rouster'
4
4
  require 'rouster/deltas'
5
5
  require 'test/unit'
6
6
 
7
- # TODO need to figure out how to add package strings on our own for better testing (i.e. sfdc-razorpolicy-rhel-6.2-batch-1.0-17.noarch)
8
-
9
7
  class TestDeltasGetPackages < Test::Unit::TestCase
10
8
 
11
9
  def setup
12
10
  assert_nothing_raised do
13
- @app = Rouster.new(:name => 'app', :cache_timeout => 10)
11
+ @app = Rouster.new(:name => 'app')
14
12
  end
15
13
 
16
14
  @app.up()
@@ -31,16 +29,9 @@ class TestDeltasGetPackages < Test::Unit::TestCase
31
29
  res.each_key do |k|
32
30
  assert_not_nil(res[k])
33
31
 
34
- if res[k].is_a?(Array)
35
- res[k].each do |l|
36
- assert(l.has_key?(:arch))
37
- assert(l.has_key?(:version))
38
- end
39
- else
40
- assert(res[k].has_key?(:arch))
41
- assert(res[k].has_key?(:version))
42
- end
43
-
32
+ # this is not the best validation, but is not the worst either
33
+ assert_match(/^\d+\./, res[k]) # start with a number
34
+ assert_match(/\.(x86|i686|x86_64|noarch)$/, res[k]) # end with an arch type
44
35
  end
45
36
 
46
37
  end
@@ -58,79 +49,6 @@ class TestDeltasGetPackages < Test::Unit::TestCase
58
49
  assert_equal(false, @app.deltas.has_key?(:packages))
59
50
  end
60
51
 
61
- def test_without_deep_inspection
62
- res = nil
63
-
64
- assert_nothing_raised do
65
- res = @app.get_packages(true, false)
66
- end
67
-
68
- # RHEL processing doesn't do anything different in deep/not-deep calls
69
- if ! (@app.os_type.eql?(:rhel) or @app.os_type.eql?(:ubuntu))
70
- res.each_key do |k|
71
- assert_not_nil(res[k])
72
- assert_match(/\?/, res[k][:arch])
73
- end
74
- end
75
-
76
- end
77
-
78
- def test_happy_path_cache_invalidation
79
- res1, res2 = nil, nil
80
-
81
- assert_nothing_raised do
82
- res1 = @app.get_packages(true, false)
83
- end
84
-
85
- first_cache_time = @app.cache[:packages]
86
-
87
- sleep (@app.cache_timeout + 1)
88
-
89
- assert_nothing_raised do
90
- res2 = @app.get_packages(true, false)
91
- end
92
-
93
- second_cache_time = @app.cache[:packages]
94
-
95
- assert_equal(res1, res2)
96
- assert_not_equal(first_cache_time, second_cache_time)
97
- assert(second_cache_time > first_cache_time)
98
-
99
- end
100
-
101
- def test_arch_determination
102
- after, install = nil, nil
103
-
104
- if @app.os_type.eql?(:rhel)
105
- packages = [ 'glibc.x86_64', 'glibc.i686' ]
106
- install = @app.run(sprintf('yum install -y %s', packages.join(' '))) # TODO these are already in the base, but just to be safe
107
- after = @app.get_packages(false, false)
108
-
109
- assert(after.has_key?('glibc'))
110
- assert(after['glibc'].is_a?(Array))
111
- assert_equal(after['glibc'].length, 2)
112
- assert_not_equal(after['glibc'][0][:arch], after['glibc'][1][:arch])
113
- elsif @app.os_type.eql?(:ubuntu)
114
- packages = @app.get_packages(false, false)
115
-
116
- assert(packages.has_key?('xml-core'))
117
- assert(packages.has_key?('whiptail'))
118
- assert(packages['xml-core'].has_key?(:version))
119
- assert(packages['whiptail'].has_key?(:version))
120
-
121
- assert_equal(packages['xml-core'][:arch], 'all')
122
- assert_equal(packages['whiptail'][:arch], 'amd64')
123
-
124
- else
125
- # TODO should throw a flag here..
126
- assert_nothing_raised do
127
- @app.get_packages(false, true)
128
- @app.get_packages(false, false)
129
- end
130
- end
131
-
132
- end
133
-
134
52
  def teardown
135
53
  @app = nil
136
54
  end