rouster 0.42 → 0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ class TestFacter < Test::Unit::TestCase
8
8
 
9
9
  def setup
10
10
  assert_nothing_raised do
11
- @app = Rouster.new(:name => 'app')
11
+ @app = Rouster.new(:name => 'app', :cache_timeout => 10)
12
12
  end
13
13
 
14
14
  @app.up()
@@ -38,6 +38,46 @@ class TestFacter < Test::Unit::TestCase
38
38
  assert_equal(nil, @app.facts)
39
39
  end
40
40
 
41
+ def test_caching
42
+ # NOTE: this only works if (time_to_run_facter < cache_timeout)
43
+
44
+ assert_nothing_raised do
45
+ @app.facter(true)
46
+ end
47
+
48
+ first_cached_time = @app.cache[:facter]
49
+
50
+ assert_nothing_raised do
51
+ @app.facter(true)
52
+ end
53
+
54
+ second_cached_time = @app.cache[:facter]
55
+
56
+ assert_equal(first_cached_time, second_cached_time)
57
+
58
+ end
59
+
60
+ def test_cache_invalidation
61
+
62
+ assert_nothing_raised do
63
+ @app.facter(true)
64
+ end
65
+
66
+ first_cached_time = @app.cache[:facter]
67
+
68
+ sleep (@app.cache_timeout + 1)
69
+
70
+ assert_nothing_raised do
71
+ @app.facter(true)
72
+ end
73
+
74
+ second_cached_time = @app.cache[:facter]
75
+
76
+ assert_not_equal(first_cached_time, second_cached_time)
77
+ assert(second_cached_time > first_cached_time)
78
+
79
+ end
80
+
41
81
  def test_custom_facts
42
82
 
43
83
  facts = nil
@@ -74,8 +74,12 @@ class TestCaching < Test::Unit::TestCase
74
74
  end
75
75
 
76
76
  def test_ssh_caching
77
+
78
+ skip('see comments in rouster.rb line ~84')
79
+
77
80
  timeout = 100
78
- app = Rouster.new(:name => 'app', :cache_timeout => timeout)
81
+ app = Rouster.new(:name => 'app', :sshtunnel => true, :cache_timeout => timeout)
82
+ app.up()
79
83
 
80
84
  assert_equal(app.cache_timeout, timeout)
81
85
 
@@ -56,6 +56,31 @@ class TestDirs < Test::Unit::TestCase
56
56
 
57
57
  end
58
58
 
59
+ def test_case_sensitvity
60
+ dirs_to_create = ['Fizz', 'foo', 'baz']
61
+ dirs_expected_sensitive = ['foo']
62
+ dirs_expected_insensitive = ['Fizz', 'foo']
63
+
64
+ dirs_to_create.each do |dir|
65
+ @app.run(sprintf('mkdir -p %s/%s', @dir, dir))
66
+ end
67
+
68
+ dirs_actual_sensitive = @app.dirs(@dir, 'f*', false)
69
+
70
+ dirs_actual_sensitive.each do |dir|
71
+ dir = dir.gsub(/#{@dir}/, '')
72
+ assert(dirs_expected_sensitive.member?(dir))
73
+ end
74
+
75
+ dirs_actual_insensitive = @app.dirs(@dir, 'f*', true)
76
+
77
+ dirs_actual_insensitive.each do |dir|
78
+ dir = dir.gsub(/#{@dir}/, '')
79
+ assert(dirs_expected_insensitive.member?(dir))
80
+ end
81
+
82
+ end
83
+
59
84
  def teardown
60
85
  @app.run(sprintf('rm -rf %s', @dir))
61
86
  end
@@ -45,7 +45,8 @@ class TestGet < Test::Unit::TestCase
45
45
  def test_remote_path_dne
46
46
 
47
47
  assert_raise Rouster::FileTransferError do
48
- @app.get(@kb_dne_location, @kg_local_location)
48
+ res = @app.get(@kb_dne_location, @kg_local_location)
49
+ assert_equal(false, res)
49
50
  end
50
51
 
51
52
  assert_equal(false, File.file?(@kg_local_location), 'known bad remote file path DNE')
@@ -54,7 +55,7 @@ class TestGet < Test::Unit::TestCase
54
55
  def test_with_suspended_machine
55
56
  @app.suspend()
56
57
 
57
- #assert_raise Rouster::SSHConnectionError do <-- why was this ever used?
58
+ #assert_raise Rouster::SSHConnectionError do <-- this is what we want when the connection is bad, as opposed to permission/disk space issues
58
59
  assert_raise Rouster::FileTransferError do
59
60
  @app.get(@kg_remote_location, @kg_local_location)
60
61
  end
@@ -63,10 +64,13 @@ class TestGet < Test::Unit::TestCase
63
64
  end
64
65
 
65
66
  def teardown
66
- # TODO we should suspend instead if any test failed for triage
67
- #@app.destroy()
68
- #@ppm.destroy()
69
-
70
67
  File.delete(@kg_local_location) if File.file?(@kg_local_location).true?
71
68
  end
69
+
70
+ def self.shutdown
71
+ # TODO we should suspend instead if any test failed for triage
72
+ #@app.suspend()
73
+ #@ppm.suspend()
74
+ end
75
+
72
76
  end
@@ -23,7 +23,7 @@ class TestNew < Test::Unit::TestCase
23
23
 
24
24
  def test_2_good_openssh_tunnel
25
25
  @app = Rouster.new(:name => 'app', :sshtunnel => true)
26
-
26
+ 7
27
27
  # TODO how do we properly test this? we really need the rspec should_call mechanism...
28
28
 
29
29
  assert_equal(true, @app.is_available_via_ssh?)
@@ -33,23 +33,24 @@ class TestNew < Test::Unit::TestCase
33
33
 
34
34
  assert_nothing_raised do
35
35
  @app = Rouster.new(
36
- :name => 'app',
37
- :passthrough => true,
38
- :sudo => false,
39
- :verbosity => 4,
40
- #:vagrantfile => traverse_up(Dir.pwd, 'Vagrantfile'), # this is what happens anyway..
41
- :sshkey => ENV['VAGRANT_HOME'].nil? ? sprintf('%s/.vagrant.d/insecure_private_key', ENV['HOME']) : sprintf('%s/insecure_private_key', ENV['VAGRANT_HOME']),
36
+ :name => 'app',
37
+ :passthrough => false,
38
+ :sudo => false,
39
+ :verbosity => 4,
40
+ #:vagrantfile => traverse_up(Dir.pwd, 'Vagrantfile'), # this is what happens anyway..
41
+ :sshkey => ENV['VAGRANT_HOME'].nil? ? sprintf('%s/.vagrant.d/insecure_private_key', ENV['HOME']) : sprintf('%s/insecure_private_key', ENV['VAGRANT_HOME']),
42
+ :cache_timeout => 10,
42
43
  )
43
44
 
44
-
45
45
  end
46
46
 
47
47
  assert_equal('app', @app.name)
48
- assert_equal(true, @app.is_passthrough?())
48
+ assert_equal(false, @app.is_passthrough?())
49
49
  assert_equal(false, @app.uses_sudo?())
50
50
  assert_equal(4, @app.verbosity) # is this going to be strinigified?
51
51
  assert_equal(true, File.file?(@app.vagrantfile))
52
52
  assert_equal(true, File.file?(@app.sshkey))
53
+ assert_equal(10, @app.cache_timeout)
53
54
  end
54
55
 
55
56
  def test_4_bad_name_instantiation
@@ -49,35 +49,33 @@ class TestPut < Test::Unit::TestCase
49
49
 
50
50
  end
51
51
 
52
- =begin
53
- TODO fix tests failing for unknown/incorrect reasons
54
52
  def test_with_suspended_machine
55
53
  @app.is_available_via_ssh?() # make sure we have a tunnel
56
54
  @app.suspend()
57
55
 
58
- assert_raise Net::SSH::Disconnect do
56
+ #assert_raise Rouster::SSHConnectionError
57
+ assert_raise Rouster::FileTransferError do
59
58
  @app.put(__FILE__, @kg_local_location)
60
59
  end
61
60
 
62
- assert_equal(false, @app.is_file?(@kg_local_location), 'when machine is suspended, unable to get from it')
61
+ #assert_equal(false, @app.is_file?(@kg_local_location), 'when machine is suspended, unable to get from it')
63
62
  end
64
63
 
65
64
  def test_with_suspended_machine_after_destroying_ssh_tunnel
66
- @app._vm.channel.destroy_ssh_connection() # make sure we don't have a tunnel
65
+ @app.disconnect_ssh_tunnel()
67
66
  @app.suspend()
68
67
 
69
- assert_raise Rouster::SSHConnectionError do
68
+ #assert_raise Rouster::SSHConnectionError do
69
+ assert_raise Rouster::FileTransferError do
70
70
  @app.put(__FILE__, @kg_local_location)
71
71
  end
72
72
 
73
- assert_equal(false, @app.is_file?(@kg_local_location), 'when machine is suspended, and connection is manually destroyed, unable to get from it')
73
+ #assert_equal(false, @app.is_file?(@kg_local_location), 'when machine is suspended, and connection is manually destroyed, unable to get from it')
74
74
  end
75
- =end
76
75
 
77
76
  def teardown
78
- # TODO we should suspend instead if any test failed for triage
79
77
  #@app.destroy()
80
- #@ppm.destroy()
78
+ @app.suspend()
81
79
  File.delete(@kg_location) if File.file?(@kg_location).true?
82
80
  end
83
81
  end
@@ -10,7 +10,6 @@
10
10
  assert_nothing_raised do
11
11
  @app = Rouster.new(:name => 'app', :verbosity => 4)
12
12
  end
13
-
14
13
  end
15
14
 
16
15
  def test_happy_path
@@ -31,7 +30,7 @@
31
30
  sleep 10
32
31
  end
33
32
 
34
- new_uptime = @app.facter()['uptime_seconds'].to_i
33
+ new_uptime = @app.facter(false)['uptime_seconds'].to_i
35
34
 
36
35
  assert_not_equal(original_uptime, new_uptime)
37
36
  assert(original_uptime > new_uptime)
@@ -71,8 +71,7 @@ class TestRun < Test::Unit::TestCase
71
71
  end
72
72
 
73
73
  def teardown
74
- # TODO we should suspend instead if any test failed for triage
75
- #@app.destroy()
76
- #@ppm.destroy()
74
+ @app.suspend()
75
+ @app_no_sudo.suspend()
77
76
  end
78
77
  end
@@ -0,0 +1,30 @@
1
+ require sprintf('%s/../../path_helper', File.dirname(File.expand_path(__FILE__)))
2
+
3
+ require 'rouster'
4
+ require 'rouster/puppet'
5
+ require 'rouster/testing'
6
+ require 'test/unit'
7
+
8
+ class TestValidateFileFunctional < Test::Unit::TestCase
9
+
10
+ def setup
11
+ # expose private methods
12
+ Rouster.send(:public, *Rouster.private_instance_methods)
13
+ Rouster.send(:public, *Rouster.protected_instance_methods)
14
+
15
+ @app = Rouster.new(:name => 'app')
16
+ end
17
+
18
+ def test_negative_functional_fallthrough
19
+
20
+ assert_equal(false, @app.validate_file('/foo', {}, false, true))
21
+ assert_equal(false, @app.validate_file('/fizzy', { :ensure => 'directory' }, false, true))
22
+ assert_equal(false, @app.validate_file('/bang', { :ensure => 'file' }, false, true))
23
+
24
+ end
25
+
26
+ def teardown
27
+ # noop
28
+ end
29
+
30
+ end
@@ -121,23 +121,23 @@ class TestPuppetApply < Test::Unit::TestCase
121
121
 
122
122
  # manually specified testing
123
123
  app_expected_files.each_pair do |f,e|
124
- assert_equal(true, @app.validate_file(f,e))
124
+ assert_equal(true, @app.validate_file(f,e), "file[#{f}] expectation[#{e}]")
125
125
  end
126
126
 
127
127
  app_expected_groups.each_pair do |g,e|
128
- assert_equal(true, @app.validate_group(g,e))
128
+ assert_equal(true, @app.validate_group(g,e), "group[#{g}] expectation[#{e}]")
129
129
  end
130
130
 
131
131
  app_expected_packages.each_pair do |p,e|
132
- assert_equal(true, @app.validate_package(p, e))
132
+ assert_equal(true, @app.validate_package(p, e), "package[#{p}] expectation[#{e}]")
133
133
  end
134
134
 
135
135
  app_expected_services.each_pair do |s,e|
136
- assert_equal(true, @app.validate_service(s,e))
136
+ assert_equal(true, @app.validate_service(s,e), "service[#{s}] expectation[#{e}]")
137
137
  end
138
138
 
139
139
  app_expected_users.each_pair do |u,e|
140
- assert_equal(true, @app.validate_user(u,e))
140
+ assert_equal(true, @app.validate_user(u,e), "user[#{u}] expectation[#{e}]")
141
141
  end
142
142
 
143
143
  end
@@ -9,10 +9,23 @@ require 'test/unit'
9
9
  class TestPuppetRoles < Test::Unit::TestCase
10
10
 
11
11
  def setup
12
- @ppm = Rouster.new(:name => 'ppm', :vagrantfile => '../piab/Vagrantfile')
13
- @ppm.rebuild() unless @ppm.status.eql?('running') # destroy / rebuild
14
12
 
15
- @app = Rouster.new(:name => 'app', :vagrantfile => '../piab/Vagrantfile')
13
+ piab_vagrantfile = sprintf('%s/../../../piab/Vagrantfile', File.dirname(File.expand_path(__FILE__)))
14
+
15
+ unless File.file?(piab_vagrantfile)
16
+ skip(sprintf('missing SFDC specific Vagrantfile[%s], skipping', piab_vagrantfile))
17
+ end
18
+
19
+ assert_nothing_raised do
20
+ @ppm = Rouster.new(:name => 'ppm', :vagrantfile => piab_vagrantfile)
21
+ @ppm.up()
22
+ @ppm.remove_existing_certs('ppm')
23
+ #@ppm.rebuild() unless @ppm.status.eql?('running') # destroy / rebuild
24
+ end
25
+
26
+ assert_nothing_raised do
27
+ @app = Rouster.new(:name => 'app', :vagrantfile => piab_vagrantfile)
28
+ end
16
29
 
17
30
  assert_nothing_raised do
18
31
  @ppm.run_puppet('master', { :expected_exitcode => [0,2] })
@@ -327,6 +327,30 @@ class TestParseLsString < Test::Unit::TestCase
327
327
 
328
328
  end
329
329
 
330
+ def test_suid
331
+ str = "drwxr-sr-x 2 root root 4096 Oct 7 17:09 /etc/nagios/objects\n"
332
+
333
+ skip('need to improve (read: implement) actual suid support')
334
+
335
+ expectation = {
336
+ :directory? => true,
337
+ :file? => false,
338
+ :mode => '4755', # right now, we return '0755', if we detect an 's', do we just +4000?
339
+ :name => '/etc/nagios/objects',
340
+ :owner => 'root',
341
+ :group => 'root',
342
+ :size => '4096',
343
+ :executable? => [true, true, true], # right now, we return [true,false,true]
344
+ :readable? => [true, true, true],
345
+ :writeable? => [true, false, false],
346
+ }
347
+
348
+ res = @app.exposed_parse_ls_string(str)
349
+
350
+ assert_equal(expectation, res)
351
+
352
+ end
353
+
330
354
  def teardown
331
355
  # noop
332
356
  end
@@ -48,67 +48,60 @@ class TestValidateFile < Test::Unit::TestCase
48
48
 
49
49
  def test_positive_basic
50
50
 
51
- assert(@app.validate_file('/etc/hosts', { :ensure => 'file', :mode => '0644', :file => true, :directory => false, :owner => 'root', :group => 'root' }, true))
52
- assert(@app.validate_file('/etc/hosts', { :exists => 'present' }, true ))
53
- assert(@app.validate_file('/etc/hosts', { }, true ))
54
- assert(@app.validate_file('/etc/hosts', { :mode => '0644' }, true))
55
- assert(@app.validate_file('/etc/hosts', { :permissions => '0644' }, true))
56
- assert(@app.validate_file('/etc/hosts', { :size => 166 }, true ))
57
- assert(@app.validate_file('/etc/hosts', { :size => '166' }, true ))
58
- assert(@app.validate_file('/etc/hosts', { :file => 'true' }, true))
59
- assert(@app.validate_file('/etc/hosts', { :file => true }, true))
60
- assert(@app.validate_file('/etc/hosts', { :directory => 'false' }, true))
61
- assert(@app.validate_file('/etc/hosts', { :directory => false }, true))
62
- assert(@app.validate_file('/etc/hosts', { :owner => 'root' }, true))
63
- assert(@app.validate_file('/etc/hosts', { :group => 'root' }, true))
64
-
65
- assert(@app.validate_file('/etc/fizzbang', { :ensure => 'absent' }, true))
66
- assert(@app.validate_file('/etc/fizzbang', { :ensure => false }, true ))
67
-
68
- assert(@app.validate_file('/etc', { :ensure => 'directory' }, true))
69
- assert(@app.validate_file('/etc', { :ensure => 'dir' }, true))
70
- assert(@app.validate_file('/etc', { :ensure => 'dir', :file => 'false' }, true))
71
- assert(@app.validate_file('/etc', { :ensure => 'dir', :directory => 'true' }, true))
72
- assert(@app.validate_file('/etc', { :ensure => 'dir', :file => 'false', :directory => 'true' }, true))
73
-
74
- assert(@app.validate_file('/fizzy', { :ensure => 'absent' }, true))
75
- assert(@app.validate_file('/fizzy', { :ensure => false }, true))
76
- assert(@app.validate_file('/fizzy', { :exists => 'false' }, true))
77
- assert(@app.validate_file('/fizzy', { :exists => false }, true))
78
-
79
- # TODO need to do :contains testing in a non-unit context
51
+ assert(@app.validate_file('/etc/hosts', { :ensure => 'file', :mode => '0644', :file => true, :directory => false, :owner => 'root', :group => 'root' }, false, true))
52
+ assert(@app.validate_file('/etc/hosts', { :exists => 'present' }, false, true ))
53
+ assert(@app.validate_file('/etc/hosts', { }, false, true ))
54
+ assert(@app.validate_file('/etc/hosts', { :mode => '0644' }, false, true))
55
+ assert(@app.validate_file('/etc/hosts', { :permissions => '0644' }, false, true))
56
+ assert(@app.validate_file('/etc/hosts', { :size => 166 }, false, true ))
57
+ assert(@app.validate_file('/etc/hosts', { :size => '166' }, false, true ))
58
+ assert(@app.validate_file('/etc/hosts', { :file => 'true' }, false, true))
59
+ assert(@app.validate_file('/etc/hosts', { :file => true }, false, true))
60
+ assert(@app.validate_file('/etc/hosts', { :directory => 'false' }, false, true))
61
+ assert(@app.validate_file('/etc/hosts', { :directory => false }, false, true))
62
+ assert(@app.validate_file('/etc/hosts', { :owner => 'root' }, false, true))
63
+ assert(@app.validate_file('/etc/hosts', { :group => 'root' }, false, true))
64
+
65
+ assert(@app.validate_file('/etc/fizzbang', { :ensure => 'absent' }, false, true))
66
+ assert(@app.validate_file('/etc/fizzbang', { :ensure => false }, false, true ))
67
+
68
+ assert(@app.validate_file('/etc', { :ensure => 'directory' }, false, true))
69
+ assert(@app.validate_file('/etc', { :ensure => 'dir' }, false, true))
70
+ assert(@app.validate_file('/etc', { :ensure => 'dir', :file => 'false' }, false, true))
71
+ assert(@app.validate_file('/etc', { :ensure => 'dir', :directory => 'true' }, false, true))
72
+ assert(@app.validate_file('/etc', { :ensure => 'dir', :file => 'false', :directory => 'true' }, false, true))
73
+
74
+ assert(@app.validate_file('/fizzy', { :ensure => 'absent' }, false, true))
75
+ assert(@app.validate_file('/fizzy', { :ensure => false }, false, true))
76
+ assert(@app.validate_file('/fizzy', { :exists => 'false' }, false, true))
77
+ assert(@app.validate_file('/fizzy', { :exists => false }, false, true))
80
78
 
81
79
  end
82
80
 
83
81
  def test_positive_constrained
84
82
 
85
- assert(@app.validate_file('/etc/hosts', { :mode => '0644', :constrain => 'is_virtual true' }, true))
83
+ assert(@app.validate_file('/etc/hosts', { :mode => '0644', :constrain => 'is_virtual true' }, false, true))
86
84
 
87
85
  end
88
86
 
89
87
  def test_negative_basic
90
88
 
91
- assert_equal(false, @app.validate_file('/etc/hosts', { :mode => '0777' }, true))
92
- assert_equal(false, @app.validate_file('/etc/hosts', { :permissions => '0777' }, true))
93
- assert_equal(false, @app.validate_file('/etc/hosts', { :file => 'false' }, true ))
94
- assert_equal(false, @app.validate_file('/etc/hosts', { :file => false }, true))
95
- assert_equal(false, @app.validate_file('/etc/hosts', { :directory => 'true' }, true))
96
- assert_equal(false, @app.validate_file('/etc/hosts', { :directory => true }, true))
97
- assert_equal(false, @app.validate_file('/etc/hosts', { :size => 'foo' }, true))
98
- assert_equal(false, @app.validate_file('/etc/hosts', { :size => 100 }, true))
99
- assert_equal(false, @app.validate_file('/etc/hosts', { :size => '100'}, true))
100
-
101
- # TODO figure out how to run these in a truly unit-y way, since the data is not present in faked hash, we will fall through to functional testing
102
- assert_equal(false, @app.validate_file('/foo', {}, true))
103
- assert_equal(false, @app.validate_file('/fizzy', { :ensure => 'directory' }, true))
104
- assert_equal(false, @app.validate_file('/bang', { :ensure => 'file' }, true))
89
+ assert_equal(false, @app.validate_file('/etc/hosts', { :mode => '0777' }, false, true))
90
+ assert_equal(false, @app.validate_file('/etc/hosts', { :permissions => '0777' }, false, true))
91
+ assert_equal(false, @app.validate_file('/etc/hosts', { :file => 'false' }, false, true ))
92
+ assert_equal(false, @app.validate_file('/etc/hosts', { :file => false }, false, true))
93
+ assert_equal(false, @app.validate_file('/etc/hosts', { :directory => 'true' }, false, true))
94
+ assert_equal(false, @app.validate_file('/etc/hosts', { :directory => true }, false, true))
95
+ assert_equal(false, @app.validate_file('/etc/hosts', { :size => 'foo' }, false, true))
96
+ assert_equal(false, @app.validate_file('/etc/hosts', { :size => 100 }, false, true))
97
+ assert_equal(false, @app.validate_file('/etc/hosts', { :size => '100'}, false, true))
105
98
 
106
99
  end
107
100
 
108
101
  def test_negative_constrained
109
102
 
110
- assert(@app.validate_file('/etc/hosts', { :mode => '0644', :constrain => 'is_virtual false' }, true))
111
- assert(@app.validate_file('/etc/hosts', { :mode => '0999', :constrain => 'is_virtual false' }, true))
103
+ assert(@app.validate_file('/etc/hosts', { :mode => '0644', :constrain => 'is_virtual false' }, false, true))
104
+ assert(@app.validate_file('/etc/hosts', { :mode => '0999', :constrain => 'is_virtual false' }, false, true))
112
105
 
113
106
  end
114
107