rouster 0.5

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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/LICENSE +9 -0
  4. data/README.md +175 -0
  5. data/Rakefile +65 -0
  6. data/Vagrantfile +23 -0
  7. data/examples/bootstrap.rb +113 -0
  8. data/examples/demo.rb +71 -0
  9. data/examples/error.rb +30 -0
  10. data/lib/rouster.rb +737 -0
  11. data/lib/rouster/deltas.rb +481 -0
  12. data/lib/rouster/puppet.rb +398 -0
  13. data/lib/rouster/testing.rb +743 -0
  14. data/lib/rouster/tests.rb +596 -0
  15. data/path_helper.rb +21 -0
  16. data/rouster.gemspec +30 -0
  17. data/test/basic.rb +10 -0
  18. data/test/functional/deltas/test_get_crontab.rb +99 -0
  19. data/test/functional/deltas/test_get_groups.rb +48 -0
  20. data/test/functional/deltas/test_get_packages.rb +71 -0
  21. data/test/functional/deltas/test_get_ports.rb +119 -0
  22. data/test/functional/deltas/test_get_services.rb +43 -0
  23. data/test/functional/deltas/test_get_users.rb +45 -0
  24. data/test/functional/puppet/test_facter.rb +59 -0
  25. data/test/functional/test_caching.rb +124 -0
  26. data/test/functional/test_destroy.rb +51 -0
  27. data/test/functional/test_dirs.rb +88 -0
  28. data/test/functional/test_files.rb +64 -0
  29. data/test/functional/test_get.rb +76 -0
  30. data/test/functional/test_inspect.rb +31 -0
  31. data/test/functional/test_is_dir.rb +118 -0
  32. data/test/functional/test_is_file.rb +119 -0
  33. data/test/functional/test_new.rb +92 -0
  34. data/test/functional/test_put.rb +81 -0
  35. data/test/functional/test_rebuild.rb +49 -0
  36. data/test/functional/test_restart.rb +44 -0
  37. data/test/functional/test_run.rb +77 -0
  38. data/test/functional/test_status.rb +38 -0
  39. data/test/functional/test_suspend.rb +31 -0
  40. data/test/functional/test_up.rb +27 -0
  41. data/test/functional/test_validate_file.rb +30 -0
  42. data/test/puppet/manifests/default.pp +9 -0
  43. data/test/puppet/manifests/hiera.yaml +12 -0
  44. data/test/puppet/manifests/hieradata/common.json +3 -0
  45. data/test/puppet/manifests/hieradata/vagrant.json +3 -0
  46. data/test/puppet/manifests/manifest.pp +78 -0
  47. data/test/puppet/modules/role/manifests/ui.pp +5 -0
  48. data/test/puppet/test_apply.rb +149 -0
  49. data/test/puppet/test_roles.rb +186 -0
  50. data/test/tunnel_vs_scp.rb +41 -0
  51. data/test/unit/puppet/test_get_puppet_star.rb +68 -0
  52. data/test/unit/test_generate_unique_mac.rb +43 -0
  53. data/test/unit/test_new.rb +31 -0
  54. data/test/unit/test_parse_ls_string.rb +334 -0
  55. data/test/unit/test_traverse_up.rb +43 -0
  56. data/test/unit/testing/test_meets_constraint.rb +55 -0
  57. data/test/unit/testing/test_validate_file.rb +112 -0
  58. data/test/unit/testing/test_validate_group.rb +72 -0
  59. data/test/unit/testing/test_validate_package.rb +69 -0
  60. data/test/unit/testing/test_validate_port.rb +98 -0
  61. data/test/unit/testing/test_validate_service.rb +73 -0
  62. data/test/unit/testing/test_validate_user.rb +92 -0
  63. metadata +203 -0
@@ -0,0 +1,43 @@
1
+ require sprintf('%s/../../path_helper', File.dirname(File.expand_path(__FILE__)))
2
+
3
+ require 'rouster'
4
+ require 'test/unit'
5
+
6
+ class TestTraverseUp < Test::Unit::TestCase
7
+
8
+ def setup
9
+ assert_nothing_raised do
10
+ @app = Rouster.new(:name => 'app', :unittest => true)
11
+ end
12
+
13
+ def @app.exposed_traverse_up(*args)
14
+ traverse_up(*args)
15
+ end
16
+
17
+ end
18
+
19
+ def test_happy_path
20
+ res = @app.exposed_traverse_up(Dir.pwd, 'Vagrantfile')
21
+
22
+ assert_equal(true, File.file?(res))
23
+
24
+ end
25
+
26
+ def test_file_not_specified
27
+ assert_raises Rouster::InternalError do
28
+ @app.exposed_traverse_up(Dir.pwd)
29
+ end
30
+
31
+ end
32
+
33
+ def test_failed_to_find
34
+ res = @app.exposed_traverse_up('/tmp', 'this-file-dne')
35
+
36
+ assert_nil(res)
37
+ end
38
+
39
+ def teardown
40
+ # noop
41
+ end
42
+
43
+ end
@@ -0,0 +1,55 @@
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 TestMeetsConstraint < 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
+ fake_facts = { 'is_virtual' => 'true', 'timezone' => 'PDT', 'uptime_days' => 42 }
16
+
17
+ @app = Rouster.new(:name => 'app', :unittest => true)
18
+ @app.facts = fake_facts
19
+ end
20
+
21
+ def test_positive
22
+
23
+ assert(@app.meets_constraint?('is_virtual', 'true'))
24
+ assert(@app.meets_constraint?('timezone', 'PDT'))
25
+ assert(@app.meets_constraint?('uptime_days', 42))
26
+ assert(@app.meets_constraint?('uptime_days', '42'))
27
+
28
+ end
29
+
30
+ def test_negative
31
+
32
+ assert_equal(false, @app.meets_constraint?('is_virtual', false))
33
+ assert_equal(false, @app.meets_constraint?('timezone', 'MST'))
34
+ assert_equal(false, @app.meets_constraint?('uptime_days', 27))
35
+ assert_equal(false, @app.meets_constraint?('uptime_days', '27'))
36
+
37
+ end
38
+
39
+ def test_specified_comparator
40
+
41
+ assert(@app.meets_constraint?('is_virtual', '!= false'))
42
+ assert(@app.meets_constraint?('uptime_days', '> 10'))
43
+ assert(@app.meets_constraint?('uptime_days', '>= 42'))
44
+ assert(@app.meets_constraint?('uptime_days', '< 100'))
45
+ assert(@app.meets_constraint?('uptime_days', '<= 100'))
46
+ assert(@app.meets_constraint?('uptime_days', '== 42'))
47
+ assert(@app.meets_constraint?('uptime_days', '!= false'))
48
+
49
+ end
50
+
51
+ def teardown
52
+ # noop
53
+ end
54
+
55
+ end
@@ -0,0 +1,112 @@
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 TestValidateFile < 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
+ fake_facts = { 'is_virtual' => 'true', 'timezone' => 'PDT', 'uptime_days' => 42 }
16
+
17
+ fake_files = {
18
+ '/etc/hosts' => {
19
+ :mode => '0644',
20
+ :name => '/etc/hosts',
21
+ :owner => 'root',
22
+ :group => 'root',
23
+ :size => '166',
24
+ :directory? => false,
25
+ :file? => true,
26
+ :executable? => [false, false, false],
27
+ :writeable? => [true, false, false],
28
+ :readable? => [true, true, true]
29
+ },
30
+ '/etc' => {
31
+ :mode => '0755',
32
+ :name => '/etc/',
33
+ :owner => 'root',
34
+ :group => 'root',
35
+ :size => '4096',
36
+ :directory? => true,
37
+ :file? => false,
38
+ :executable? => [true, true, true],
39
+ :writeable? => [true, false, false],
40
+ :readable? => [true, true, true]
41
+ }
42
+ }
43
+
44
+ @app = Rouster.new(:name => 'app', :unittest => true)
45
+ @app.deltas[:files] = fake_files
46
+ @app.facts = fake_facts
47
+ end
48
+
49
+ def test_positive_basic
50
+
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))
78
+
79
+ end
80
+
81
+ def test_positive_constrained
82
+
83
+ assert(@app.validate_file('/etc/hosts', { :mode => '0644', :constrain => 'is_virtual true' }, false, true))
84
+
85
+ end
86
+
87
+ def test_negative_basic
88
+
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))
98
+
99
+ end
100
+
101
+ def test_negative_constrained
102
+
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))
105
+
106
+ end
107
+
108
+ def teardown
109
+ # noop
110
+ end
111
+
112
+ end
@@ -0,0 +1,72 @@
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 TestValidateGroup < 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
+ fake_facts = { 'is_virtual' => 'true', 'timezone' => 'PDT', 'uptime_days' => 42 }
16
+
17
+ fake_groups = {
18
+ 'root' => {
19
+ :gid => 0,
20
+ :users => ['root', 'conor']
21
+ },
22
+ 'foo' => {
23
+ :gid => '10',
24
+ :users => ['foo']
25
+ }
26
+ }
27
+
28
+ @app = Rouster.new(:name => 'app', :unittest => true)
29
+ @app.deltas[:groups] = fake_groups
30
+ @app.facts = fake_facts
31
+ end
32
+
33
+ def test_positive_basic
34
+
35
+ assert(@app.validate_group('root', { :gid => 0, :users => ['root', 'conor'] } ))
36
+ assert(@app.validate_group('root', { :gid => '0', :ensure => 'present' } ))
37
+ assert(@app.validate_group('root', { :exists => true } ))
38
+ assert(@app.validate_group('root', { :user => 'conor' } ))
39
+ assert(@app.validate_group('root', { :users => ['conor']} ))
40
+
41
+ assert(@app.validate_group('toor', { :exists => false } ))
42
+ assert(@app.validate_group('toor', { :ensure => 'absent' } ))
43
+
44
+ end
45
+
46
+ def test_positive_constrained
47
+
48
+ assert(@app.validate_group('root', { :gid => 0 , :constrain => 'is_virtual true'} ))
49
+
50
+ end
51
+
52
+ def test_negative_basic
53
+
54
+ assert_equal(false, @app.validate_group('root', { :gid => 10 } ))
55
+ assert_equal(false, @app.validate_group('root', { :ensure => 'absent'} ))
56
+ assert_equal(false, @app.validate_group('root', { :gid => 0, :users => ['root', 'toor'] } ))
57
+ assert_equal(false, @app.validate_group('root', { :gid => 0, :users => 'toor' }))
58
+
59
+ end
60
+
61
+ def test_negative_constrained
62
+
63
+ assert(@app.validate_group('root', { :gid => 10, :constrain => 'is_virtual false' } ))
64
+ assert(@app.validate_group('root', { :gid => 99, :constrain => 'is_virtual false' } ))
65
+
66
+ end
67
+
68
+ def teardown
69
+ # noop
70
+ end
71
+
72
+ end
@@ -0,0 +1,69 @@
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 TestValidatePackage < 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
+ fake_facts = { 'is_virtual' => 'true', 'timezone' => 'PDT', 'uptime_days' => 42 }
16
+
17
+ fake_packages = {
18
+ 'abrt' => '2.0.8-15.el6.centos.x86_64',
19
+ 'usermode' => '1.102-3',
20
+ }
21
+
22
+ @app = Rouster.new(:name => 'app', :unittest => true)
23
+ @app.deltas[:packages] = fake_packages
24
+ @app.facts = fake_facts
25
+ end
26
+
27
+ def test_positive_basic
28
+
29
+ assert(@app.validate_package('abrt', { :ensure => true, :version => '2.0.8-15.el6.centos.x86_64' } ))
30
+ assert(@app.validate_package('abrt', { :ensure => 'present' } ))
31
+ assert(@app.validate_package('abrt', { :exists => true } ))
32
+ assert(@app.validate_package('abrt', { :version => '> 1.0'} ))
33
+
34
+ assert(@app.validate_package('usermode', { :version => '1.102-3' } ))
35
+ assert(@app.validate_package('usermode', { :version => '> 0.5' } )) # specifying 1 here fails because 1.102-3.to_i is 1
36
+ assert(@app.validate_package('usermode', { :version => '!= false' } ))
37
+ assert(@app.validate_package('usermode', { :version => '< 5.0' } ))
38
+
39
+ assert(@app.validate_package('hds', { :exists => false } ))
40
+ assert(@app.validate_package('hds', { :ensure => 'absent'}))
41
+
42
+ end
43
+
44
+ def test_positive_constrained
45
+
46
+ assert(@app.validate_package('abrt', { :ensure => true, :constrain => 'is_virtual true' } ))
47
+
48
+ end
49
+
50
+ def test_negative_basic
51
+
52
+ assert_equal(false, @app.validate_package('abrt', { :version => 'foo.bar'} ))
53
+ assert_equal(false, @app.validate_package('abrt', { :ensure => 'absent' } ))
54
+ assert_equal(false, @app.validate_package('abrt', { :exists => false } ))
55
+
56
+ end
57
+
58
+ def test_negative_constrained
59
+
60
+ assert(@app.validate_package('abrt', { :ensure => false, :constrain => 'is_virtual false' }))
61
+ assert(@app.validate_package('abrt', { :ensure => true, :constrain => 'is_virtual false' }))
62
+
63
+ end
64
+
65
+ def teardown
66
+ # noop
67
+ end
68
+
69
+ end
@@ -0,0 +1,98 @@
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 TestValidatePort < 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
+ fake_facts = { 'is_virtual' => 'true', 'timezone' => 'PDT', 'uptime_days' => 42 }
16
+
17
+ fake_ports = {
18
+ 'tcp' => {
19
+ '22' => {
20
+ :address => {
21
+ '0.0.0.0' => 'LISTEN',
22
+ '::' => 'LISTEN'
23
+ }
24
+ },
25
+ '25' => {
26
+ :address => {
27
+ '127.0.0.1' => 'LISTEN',
28
+ '::1' => 'LISTEN'
29
+ }
30
+ },
31
+ },
32
+ 'udp' => {
33
+ '161' => {
34
+ :address => {
35
+ '0.0.0.0' => 'you_might_not_get_it'
36
+ }
37
+ },
38
+ }
39
+ }
40
+
41
+ @app = Rouster.new(:name => 'app', :unittest => true)
42
+ @app.deltas[:ports] = fake_ports
43
+ @app.facts = fake_facts
44
+ end
45
+
46
+ def test_positive_basic
47
+
48
+ assert(@app.validate_port(22, { :state => 'active', :protocol => 'tcp', :address => '0.0.0.0' } ))
49
+ assert(@app.validate_port(22, { :ensure => true } ))
50
+ assert(@app.validate_port(22, { :proto => 'tcp' } ))
51
+ assert(@app.validate_port(22, { :address => '0.0.0.0' } ))
52
+
53
+ assert(@app.validate_port('22', { :ensure => true } ))
54
+
55
+ assert(@app.validate_port(161, { :state => 'absent' } ))
56
+ assert(@app.validate_port(161, { :protocol => 'udp', :address => '0.0.0.0' } ))
57
+ assert(@app.validate_port(161, { :proto => 'udp', :state => 'this_will_always_return_true' } ))
58
+
59
+ assert(@app.validate_port(1234, { :exists => false } ))
60
+ assert(@app.validate_port(1234, { :exists => 'false' } ))
61
+ assert(@app.validate_port(1234, { :ensure => false } ))
62
+ assert(@app.validate_port(1234, { :ensure => 'absent' } ))
63
+ assert(@app.validate_port(1234, { :state => 'open' } ))
64
+
65
+ end
66
+
67
+ def test_positive_constrained
68
+
69
+ assert(@app.validate_port(22, { :state => 'connected', :constrain => 'is_virtual true' } ))
70
+
71
+ end
72
+
73
+ def test_negative_basic
74
+
75
+ assert_equal(false, @app.validate_port(22, { :ensure => true, :address => '127.0.0.1' } ))
76
+
77
+ assert_equal(false, @app.validate_port(22, { :ensure => true, :proto => 'udp' } ))
78
+ assert_equal(false, @app.validate_port(22, { :ensure => true, :protocol => 'udp' } ))
79
+
80
+ assert_equal(false, @app.validate_port(22, { :ensure => 'absent' } ))
81
+ assert_equal(false, @app.validate_port(22, { :ensure => false } ))
82
+ assert_equal(false, @app.validate_port(22, { :exists => 'absent' } ))
83
+ assert_equal(false, @app.validate_port(22, { :exists => false } ))
84
+
85
+ end
86
+
87
+ def test_negative_constrained
88
+
89
+ assert(@app.validate_port(22, { :ensure => false, :constrain => 'is_virtual false' } ))
90
+ assert(@app.validate_port(22, { :ensure => true, :constrain => 'is_virtual false' } ))
91
+
92
+ end
93
+
94
+ def teardown
95
+ # noop
96
+ end
97
+
98
+ end