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
data/path_helper.rb ADDED
@@ -0,0 +1,21 @@
1
+ # heavily influenced by https://github.com/puppetlabs/hiera/blob/master/spec/spec_helper.rb
2
+
3
+ # this gets us Rouster, still need to figure out how to find vagrant
4
+ $LOAD_PATH << File.join([File.dirname(__FILE__), 'lib'])
5
+
6
+ require 'rubygems'
7
+
8
+ # debugging help
9
+ begin
10
+ require 'debugger'
11
+ rescue LoadError
12
+ end
13
+
14
+ class Object
15
+ def my_methods
16
+ # Cookbook implementation
17
+ # my_super = self.class.superclass
18
+ # my_super ? methods - my_super.methods : methods
19
+ (methods - Object.methods).sort
20
+ end
21
+ end
data/rouster.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ ## heavily modified/copy-paste-replaced from vagrant.gemspec
2
+
3
+ require './path_helper'
4
+ require 'rouster'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'rouster'
8
+ s.version = Rouster::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.author = 'Conor Horan-Kates'
11
+ s.email = 'conor.code@gmail.com'
12
+ s.homepage = 'http://github.com/chorankates/rouster'
13
+ s.summary = 'Rouster is an abstraction layer for Vagrant'
14
+ s.description = 'Rouster allows you to programmatically control and interact with your existing Vagrant virtual machines'
15
+ s.license = 'BSD 3-Clause'
16
+
17
+ s.required_rubygems_version = '>= 1.3.6'
18
+ s.rubyforge_project = 'Rouster'
19
+
20
+ s.add_dependency 'json'
21
+ s.add_dependency 'log4r', '~> 1.1.9'
22
+ s.add_dependency 'net-scp'
23
+ s.add_dependency 'net-ssh'
24
+ s.add_dependency 'rake'
25
+
26
+ s.add_development_dependency 'test-unit', '~> 2.0'
27
+ s.add_development_dependency 'reek'
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ end
data/test/basic.rb ADDED
@@ -0,0 +1,10 @@
1
+ require sprintf('%s/../%s', File.dirname(File.expand_path(__FILE__)), 'path_helper')
2
+
3
+ require 'rouster'
4
+ require 'rouster/puppet'
5
+ require 'rouster/testing'
6
+ require 'rouster/tests'
7
+
8
+ p = Rouster.new(:name => 'app', :verbosity => 0)
9
+
10
+ p 'DBGZ' if nil?
@@ -0,0 +1,99 @@
1
+ require sprintf('%s/../../../path_helper', File.dirname(File.expand_path(__FILE__)))
2
+
3
+ require 'rouster'
4
+ require 'rouster/deltas'
5
+ require 'test/unit'
6
+
7
+ class TestDeltasGetCrontab < Test::Unit::TestCase
8
+
9
+ def setup
10
+ assert_nothing_raised do
11
+ @app = Rouster.new(:name => 'app')
12
+ end
13
+
14
+ @app.up()
15
+
16
+ ## setup some cronjobs so we have something to look at - and yes, this is hacktastic
17
+ ['root', 'puppet'].each do | user|
18
+ tmp = sprintf('/tmp/rouster.tmp.crontab.%s.%s.%s', user, Time.now.to_i, $$)
19
+ @app.run("echo '0 0 * * * echo #{user}' > #{tmp}")
20
+ #@app.run("crontab -u #{user} -f #{tmp}") # rhel
21
+ @app.run("crontab -u #{user} #{tmp}") # centos
22
+ end
23
+
24
+ end
25
+
26
+ def test_happy_path
27
+
28
+ res = nil
29
+
30
+ assert_nothing_raised do
31
+ res = @app.get_crontab()
32
+ end
33
+
34
+ assert_equal(Hash, res.class)
35
+ assert_equal(res, @app.deltas[:crontab]['root'])
36
+ assert_not_nil(@app.deltas[:crontab]['root'])
37
+
38
+ end
39
+
40
+ def test_happy_path_specified_user
41
+
42
+ res = nil
43
+
44
+ assert_nothing_raised do
45
+ res = @app.get_crontab('puppet')
46
+ end
47
+
48
+ assert_equal(Hash, res.class)
49
+ assert_equal(res, @app.deltas[:crontab]['puppet'])
50
+ assert_not_nil(@app.deltas[:crontab]['puppet'])
51
+
52
+ end
53
+
54
+ def test_happy_path_specified_star
55
+
56
+ res = nil
57
+
58
+ assert_nothing_raised do
59
+ res = @app.get_crontab('*')
60
+ end
61
+
62
+ assert_equal(Hash, res.class)
63
+ assert_equal(res, @app.deltas[:crontab])
64
+ assert_not_nil(@app.deltas[:crontab]['root'])
65
+ assert_not_nil(@app.deltas[:crontab]['puppet'])
66
+
67
+ end
68
+
69
+ def test_unhappy_path_non_existent_user
70
+
71
+ res = nil
72
+
73
+ assert_nothing_raised do
74
+ res = @app.get_crontab('fizzybang')
75
+ end
76
+
77
+ assert_equal(Hash, res.class)
78
+ assert_equal(0, res.keys.size)
79
+
80
+ end
81
+
82
+ def test_happy_path_no_cache
83
+
84
+ res = nil
85
+
86
+ assert_nothing_raised do
87
+ res = @app.get_crontab('root', false)
88
+ end
89
+
90
+ assert_equal(Hash, res.class)
91
+ assert_nil(@app.deltas[:crontab])
92
+
93
+ end
94
+
95
+ def teardown
96
+ @app = nil
97
+ end
98
+
99
+ end
@@ -0,0 +1,48 @@
1
+ require sprintf('%s/../../../path_helper', File.dirname(File.expand_path(__FILE__)))
2
+
3
+ require 'rouster'
4
+ require 'rouster/deltas'
5
+ require 'test/unit'
6
+
7
+ class TestDeltasGetGroups < Test::Unit::TestCase
8
+
9
+ def setup
10
+ assert_nothing_raised do
11
+ @app = Rouster.new(:name => 'app')
12
+ end
13
+
14
+ @app.up()
15
+ end
16
+
17
+ def test_happy_path
18
+ res = nil
19
+
20
+ assert_nothing_raised do
21
+ res = @app.get_groups()
22
+ end
23
+
24
+ assert_equal(Hash, res.class)
25
+ assert_not_nil(@app.deltas[:groups])
26
+
27
+ res.each_key do |k|
28
+ assert_not_nil(res[k][:users])
29
+ assert_equal(res[k][:users].class, Array)
30
+ assert_not_nil(res[k][:gid])
31
+ end
32
+
33
+ ## only working on *nix right now, check some specific accounts
34
+ expected = %w[root vagrant]
35
+
36
+ expected.each do |e|
37
+ assert_not_nil(res[e])
38
+ end
39
+
40
+ end
41
+
42
+ # TODO add some non-caching tests
43
+
44
+ def teardown
45
+ @app = nil
46
+ end
47
+
48
+ end
@@ -0,0 +1,71 @@
1
+ require sprintf('%s/../../../path_helper', File.dirname(File.expand_path(__FILE__)))
2
+
3
+ require 'rouster'
4
+ require 'rouster/deltas'
5
+ require 'test/unit'
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
+ class TestDeltasGetPackages < Test::Unit::TestCase
10
+
11
+ def setup
12
+ assert_nothing_raised do
13
+ @app = Rouster.new(:name => 'app')
14
+ end
15
+
16
+ @app.up()
17
+ end
18
+
19
+ def test_happy_path
20
+ res = nil
21
+
22
+ assert_equal(false, @app.deltas.has_key?(:packages))
23
+
24
+ assert_nothing_raised do
25
+ res = @app.get_packages()
26
+ end
27
+
28
+ assert_equal(Hash, res.class)
29
+ assert_not_nil(@app.deltas[:packages])
30
+
31
+ res.each_key do |k|
32
+ assert_not_nil(res[k])
33
+ assert_match(/^\d+/, res[k]) # start with a number
34
+ end
35
+
36
+ end
37
+
38
+ def test_caching_negative
39
+ res = nil
40
+
41
+ assert_equal(false, @app.deltas.has_key?(:packages))
42
+
43
+ assert_nothing_raised do
44
+ res = @app.get_packages(false)
45
+ end
46
+
47
+ assert_equal(Hash, res.class)
48
+ assert_equal(false, @app.deltas.has_key?(:packages))
49
+ end
50
+
51
+ def test_without_deep_inspection
52
+ res = nil
53
+
54
+ assert_nothing_raised do
55
+ res = @app.get_packages(true, false)
56
+ end
57
+
58
+ res.each_key do |k|
59
+ assert_not_nil(res[k])
60
+
61
+ #assert_match(/\d*\..*/, res[k]) # testing the regular expression used in deltas.rb itself
62
+ assert_match(/\?/, res[k])
63
+ end
64
+
65
+ end
66
+
67
+ def teardown
68
+ @app = nil
69
+ end
70
+
71
+ end
@@ -0,0 +1,119 @@
1
+ require sprintf('%s/../../../path_helper', File.dirname(File.expand_path(__FILE__)))
2
+
3
+ require 'rouster'
4
+ require 'rouster/deltas'
5
+ require 'test/unit'
6
+
7
+ class TestDeltasGetPorts < Test::Unit::TestCase
8
+
9
+ def setup
10
+ assert_nothing_raised do
11
+ @app = Rouster.new(:name => 'app')
12
+ end
13
+
14
+ @app.up()
15
+ end
16
+
17
+ def test_happy_path
18
+ res = nil
19
+
20
+ assert_nil(@app.deltas[:ports])
21
+
22
+ assert_nothing_raised do
23
+ res = @app.get_ports()
24
+ end
25
+
26
+ assert_equal(Hash, res.class)
27
+
28
+ res.each_key do |proto|
29
+ assert_not_nil(res[proto])
30
+
31
+ res[proto].each_key do |port|
32
+ assert_not_nil(res[proto][port])
33
+ end
34
+
35
+ end
36
+
37
+ assert_nil(@app.deltas[:ports])
38
+
39
+ end
40
+
41
+ def test_happy_path_caching
42
+
43
+ assert_nil(@app.deltas[:ports])
44
+
45
+ assert_nothing_raised do
46
+ @app.get_ports(true)
47
+ end
48
+
49
+ assert_equal(Hash, @app.deltas[:ports].class)
50
+
51
+ end
52
+
53
+ # TODO this probably isn't the right placefor this test..
54
+ def test_functional_tests
55
+
56
+ # TODO this is still wrong, since the data structure may change further
57
+ stock = {
58
+ "udp"=>
59
+ {"123"=>
60
+ {:address=>
61
+ {"fe80::a00:27ff:fe30:a00b"=>"you_might_not_get_it",
62
+ "::1"=>"you_might_not_get_it",
63
+ "0.0.0.0"=>"you_might_not_get_it",
64
+ "fe80::a00:27ff:fe42:f532"=>"you_might_not_get_it",
65
+ "127.0.0.1"=>"you_might_not_get_it",
66
+ "::"=>"you_might_not_get_it",
67
+ "10.0.2.15"=>"you_might_not_get_it",
68
+ "10.0.1.104"=>"you_might_not_get_it",
69
+ "192.168.1.161"=>"you_might_not_get_it"
70
+ }
71
+ },
72
+ "68"=>
73
+ {:address=>
74
+ {"0.0.0.0"=>"you_might_not_get_it"}
75
+ },
76
+ "111"=>
77
+ {:address=>
78
+ {"0.0.0.0"=>"you_might_not_get_it", "::"=>"you_might_not_get_it"}
79
+ },
80
+ "840"=>
81
+ {:address=>
82
+ {"0.0.0.0"=>"you_might_not_get_it", "::"=>"you_might_not_get_it"}
83
+ },
84
+ "161"=>
85
+ {:address=>
86
+ {"0.0.0.0"=>"you_might_not_get_it"}
87
+ }
88
+ },
89
+ "tcp"=>
90
+ {"111"=>{:address=>{"0.0.0.0"=>"LISTEN", "::"=>"LISTEN"}},
91
+ "199"=>{:address=>{"127.0.0.1"=>"LISTEN"}},
92
+ "25"=>{:address=>{"127.0.0.1"=>"LISTEN"}},
93
+ "22"=>{:address=>{"0.0.0.0"=>"LISTEN", "::"=>"LISTEN"}}
94
+ }
95
+ }
96
+
97
+ @app.deltas[:ports] = stock
98
+
99
+ assert_equal(true, @app.is_port_open?(1234, 'tcp', true))
100
+ assert_equal(true, @app.is_port_active?(22, 'tcp', true))
101
+
102
+ assert_equal(true, @app.is_port_open?(303, 'udp', true))
103
+ assert_equal(true, @app.is_port_active?(123, 'udp', true))
104
+
105
+ # expected to return false
106
+ assert_equal(false, @app.is_port_open?(22, 'tcp', true))
107
+ assert_equal(false, @app.is_port_active?(1234, 'tcp', true))
108
+
109
+ # caching/argument default validation -- can't currently do this, don't know what ports will be open on others systems
110
+ #assert_equal(true, @app.is_port_active?(22))
111
+ #assert_equal(true, @app.is_port_open?(1234))
112
+
113
+ end
114
+
115
+ def teardown
116
+ @app = nil
117
+ end
118
+
119
+ end
@@ -0,0 +1,43 @@
1
+ require sprintf('%s/../../../path_helper', File.dirname(File.expand_path(__FILE__)))
2
+
3
+ require 'rouster'
4
+ require 'rouster/deltas'
5
+ require 'test/unit'
6
+
7
+ class TestDeltasGetServices < Test::Unit::TestCase
8
+
9
+ def setup
10
+ assert_nothing_raised do
11
+ @app = Rouster.new(:name => 'app')
12
+ end
13
+
14
+ @app.up()
15
+
16
+ # eventually this should be standardized (and symbolized?)
17
+ @allowed_states = %w(exists operational running stopped)
18
+ end
19
+
20
+ def test_happy_path
21
+ res = nil
22
+
23
+ assert_nothing_raised do
24
+ res = @app.get_services()
25
+ end
26
+
27
+ assert_equal(Hash, res.class)
28
+ assert_not_nil(@app.deltas[:services])
29
+
30
+ res.each_key do |k|
31
+ assert_not_nil(res[k])
32
+ #assert(@allowed_states.member?(res[k]))
33
+ end
34
+
35
+ end
36
+
37
+ # TODO add some caching tests
38
+
39
+ def teardown
40
+ @app = nil
41
+ end
42
+
43
+ end