simp-cli 1.0.12

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 (150) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE +27 -0
  3. data/README.md +48 -0
  4. data/Rakefile +142 -0
  5. data/bin/simp +5 -0
  6. data/lib/simp/cli.rb +88 -0
  7. data/lib/simp/cli/commands/bootstrap.rb +275 -0
  8. data/lib/simp/cli/commands/check.rb +163 -0
  9. data/lib/simp/cli/commands/cleancerts.rb +114 -0
  10. data/lib/simp/cli/commands/config.rb +235 -0
  11. data/lib/simp/cli/commands/doc.rb +14 -0
  12. data/lib/simp/cli/commands/passgen.rb +128 -0
  13. data/lib/simp/cli/commands/puppeteval.rb +82 -0
  14. data/lib/simp/cli/commands/runpuppet.rb +95 -0
  15. data/lib/simp/cli/config/item.rb +456 -0
  16. data/lib/simp/cli/config/item/add_ldap_to_hiera.rb +43 -0
  17. data/lib/simp/cli/config/item/answers_yaml_file_writer.rb +58 -0
  18. data/lib/simp/cli/config/item/certificates.rb +39 -0
  19. data/lib/simp/cli/config/item/client_nets.rb +65 -0
  20. data/lib/simp/cli/config/item/common_runlevel_default.rb +32 -0
  21. data/lib/simp/cli/config/item/dns_search.rb +48 -0
  22. data/lib/simp/cli/config/item/dns_servers.rb +57 -0
  23. data/lib/simp/cli/config/item/failover_log_servers.rb +27 -0
  24. data/lib/simp/cli/config/item/gateway.rb +32 -0
  25. data/lib/simp/cli/config/item/grub_password.rb +51 -0
  26. data/lib/simp/cli/config/item/hostname.rb +24 -0
  27. data/lib/simp/cli/config/item/hostname_conf.rb +48 -0
  28. data/lib/simp/cli/config/item/ipaddress.rb +46 -0
  29. data/lib/simp/cli/config/item/is_master_yum_server.rb +23 -0
  30. data/lib/simp/cli/config/item/ldap_base_dn.rb +38 -0
  31. data/lib/simp/cli/config/item/ldap_bind_dn.rb +34 -0
  32. data/lib/simp/cli/config/item/ldap_bind_hash.rb +28 -0
  33. data/lib/simp/cli/config/item/ldap_bind_pw.rb +24 -0
  34. data/lib/simp/cli/config/item/ldap_master.rb +33 -0
  35. data/lib/simp/cli/config/item/ldap_root_dn.rb +42 -0
  36. data/lib/simp/cli/config/item/ldap_root_hash.rb +35 -0
  37. data/lib/simp/cli/config/item/ldap_sync_dn.rb +24 -0
  38. data/lib/simp/cli/config/item/ldap_sync_hash.rb +28 -0
  39. data/lib/simp/cli/config/item/ldap_sync_pw.rb +26 -0
  40. data/lib/simp/cli/config/item/ldap_uri.rb +43 -0
  41. data/lib/simp/cli/config/item/log_servers.rb +27 -0
  42. data/lib/simp/cli/config/item/netmask.rb +39 -0
  43. data/lib/simp/cli/config/item/network_conf.rb +63 -0
  44. data/lib/simp/cli/config/item/network_dhcp.rb +27 -0
  45. data/lib/simp/cli/config/item/network_interface.rb +41 -0
  46. data/lib/simp/cli/config/item/network_setup_nic.rb +28 -0
  47. data/lib/simp/cli/config/item/ntp_servers.rb +69 -0
  48. data/lib/simp/cli/config/item/puppet_autosign.rb +66 -0
  49. data/lib/simp/cli/config/item/puppet_ca.rb +31 -0
  50. data/lib/simp/cli/config/item/puppet_ca_port.rb +28 -0
  51. data/lib/simp/cli/config/item/puppet_conf.rb +98 -0
  52. data/lib/simp/cli/config/item/puppet_fileserver.rb +104 -0
  53. data/lib/simp/cli/config/item/puppet_hosts_entry.rb +44 -0
  54. data/lib/simp/cli/config/item/puppet_server.rb +30 -0
  55. data/lib/simp/cli/config/item/puppet_server_ip.rb +25 -0
  56. data/lib/simp/cli/config/item/puppetdb_port.rb +25 -0
  57. data/lib/simp/cli/config/item/puppetdb_server.rb +26 -0
  58. data/lib/simp/cli/config/item/remove_ldap_from_hiera.rb +47 -0
  59. data/lib/simp/cli/config/item/rename_fqdn_yaml.rb +40 -0
  60. data/lib/simp/cli/config/item/rsync_base.rb +37 -0
  61. data/lib/simp/cli/config/item/rsync_server.rb +44 -0
  62. data/lib/simp/cli/config/item/rsync_timeout.rb +26 -0
  63. data/lib/simp/cli/config/item/set_grub_password.rb +19 -0
  64. data/lib/simp/cli/config/item/simp_yum_servers.rb +30 -0
  65. data/lib/simp/cli/config/item/use_auditd.rb +19 -0
  66. data/lib/simp/cli/config/item/use_fips.rb +46 -0
  67. data/lib/simp/cli/config/item/use_iptables.rb +22 -0
  68. data/lib/simp/cli/config/item/use_ldap.rb +19 -0
  69. data/lib/simp/cli/config/item/use_selinux.rb +32 -0
  70. data/lib/simp/cli/config/item/yum_repositories.rb +75 -0
  71. data/lib/simp/cli/config/item_list_factory.rb +236 -0
  72. data/lib/simp/cli/config/questionnaire.rb +86 -0
  73. data/lib/simp/cli/config/utils.rb +128 -0
  74. data/lib/simp/cli/lib/utils.rb +114 -0
  75. data/lib/simp/simp.rb +77 -0
  76. data/spec/lib/simp/cli/commands/config_spec.rb +42 -0
  77. data/spec/lib/simp/cli/config/item/add_ldap_to_hiera_spec.rb +58 -0
  78. data/spec/lib/simp/cli/config/item/answers_yaml_file_writer_spec.rb +86 -0
  79. data/spec/lib/simp/cli/config/item/certificates_spec.rb +50 -0
  80. data/spec/lib/simp/cli/config/item/client_nets_spec.rb +66 -0
  81. data/spec/lib/simp/cli/config/item/common_runlevel_default_spec.rb +27 -0
  82. data/spec/lib/simp/cli/config/item/dns_search_spec.rb +74 -0
  83. data/spec/lib/simp/cli/config/item/dns_servers_spec.rb +76 -0
  84. data/spec/lib/simp/cli/config/item/failover_log_servers_spec.rb +49 -0
  85. data/spec/lib/simp/cli/config/item/files/FakeCA/cacertkey +1 -0
  86. data/spec/lib/simp/cli/config/item/files/FakeCA/gencerts_nopass.sh +10 -0
  87. data/spec/lib/simp/cli/config/item/files/autosign.conf.new +11 -0
  88. data/spec/lib/simp/cli/config/item/files/autosign.conf.used +15 -0
  89. data/spec/lib/simp/cli/config/item/files/fileserver.conf +41 -0
  90. data/spec/lib/simp/cli/config/item/files/hosts +2 -0
  91. data/spec/lib/simp/cli/config/item/files/hosts.old_puppet_entry +3 -0
  92. data/spec/lib/simp/cli/config/item/files/puppet.conf +25 -0
  93. data/spec/lib/simp/cli/config/item/files/puppet.your.domain.yaml +21 -0
  94. data/spec/lib/simp/cli/config/item/files/resolv.conf__multiple +10 -0
  95. data/spec/lib/simp/cli/config/item/files/resolv.conf__single +4 -0
  96. data/spec/lib/simp/cli/config/item/files/rsyncd.conf +225 -0
  97. data/spec/lib/simp/cli/config/item/gateway_spec.rb +23 -0
  98. data/spec/lib/simp/cli/config/item/grub_password_spec.rb +24 -0
  99. data/spec/lib/simp/cli/config/item/hostname_conf_spec.rb +27 -0
  100. data/spec/lib/simp/cli/config/item/hostname_spec.rb +22 -0
  101. data/spec/lib/simp/cli/config/item/ipaddress_spec.rb +40 -0
  102. data/spec/lib/simp/cli/config/item/is_master_yum_server_spec.rb +29 -0
  103. data/spec/lib/simp/cli/config/item/ldap_base_dn_spec.rb +23 -0
  104. data/spec/lib/simp/cli/config/item/ldap_bind_dn_spec.rb +23 -0
  105. data/spec/lib/simp/cli/config/item/ldap_bind_hash_spec.rb +23 -0
  106. data/spec/lib/simp/cli/config/item/ldap_bind_pw_spec.rb +21 -0
  107. data/spec/lib/simp/cli/config/item/ldap_master_spec.rb +37 -0
  108. data/spec/lib/simp/cli/config/item/ldap_root_dn_spec.rb +23 -0
  109. data/spec/lib/simp/cli/config/item/ldap_root_hash_spec.rb +23 -0
  110. data/spec/lib/simp/cli/config/item/ldap_sync_dn_spec.rb +22 -0
  111. data/spec/lib/simp/cli/config/item/ldap_sync_hash_spec.rb +23 -0
  112. data/spec/lib/simp/cli/config/item/ldap_sync_pw_spec.rb +21 -0
  113. data/spec/lib/simp/cli/config/item/ldap_uri_spec.rb +32 -0
  114. data/spec/lib/simp/cli/config/item/log_servers_spec.rb +49 -0
  115. data/spec/lib/simp/cli/config/item/netmask_spec.rb +28 -0
  116. data/spec/lib/simp/cli/config/item/network_conf_spec.rb +63 -0
  117. data/spec/lib/simp/cli/config/item/network_dhcp_spec.rb +11 -0
  118. data/spec/lib/simp/cli/config/item/network_interface_spec.rb +26 -0
  119. data/spec/lib/simp/cli/config/item/network_setup_nic_spec.rb +29 -0
  120. data/spec/lib/simp/cli/config/item/ntp_servers_spec.rb +43 -0
  121. data/spec/lib/simp/cli/config/item/puppet_autosign_spec.rb +55 -0
  122. data/spec/lib/simp/cli/config/item/puppet_ca_port_spec.rb +23 -0
  123. data/spec/lib/simp/cli/config/item/puppet_ca_spec.rb +22 -0
  124. data/spec/lib/simp/cli/config/item/puppet_conf_spec.rb +110 -0
  125. data/spec/lib/simp/cli/config/item/puppet_fileserver_spec.rb +53 -0
  126. data/spec/lib/simp/cli/config/item/puppet_hosts_entry_spec.rb +85 -0
  127. data/spec/lib/simp/cli/config/item/puppet_server_ip_spec.rb +24 -0
  128. data/spec/lib/simp/cli/config/item/puppet_server_spec.rb +22 -0
  129. data/spec/lib/simp/cli/config/item/puppetdb_port_spec.rb +25 -0
  130. data/spec/lib/simp/cli/config/item/puppetdb_server_spec.rb +25 -0
  131. data/spec/lib/simp/cli/config/item/remove_ldap_from_hiera_spec.rb +58 -0
  132. data/spec/lib/simp/cli/config/item/rename_fqdn_yaml_spec.rb +63 -0
  133. data/spec/lib/simp/cli/config/item/rsync_base_spec.rb +28 -0
  134. data/spec/lib/simp/cli/config/item/rsync_server_spec.rb +41 -0
  135. data/spec/lib/simp/cli/config/item/rsync_timeout_spec.rb +21 -0
  136. data/spec/lib/simp/cli/config/item/set_grub_password_spec.rb +29 -0
  137. data/spec/lib/simp/cli/config/item/simp_yum_servers_spec.rb +41 -0
  138. data/spec/lib/simp/cli/config/item/spec_helper.rb +22 -0
  139. data/spec/lib/simp/cli/config/item/use_auditd_spec.rb +29 -0
  140. data/spec/lib/simp/cli/config/item/use_fips_spec.rb +29 -0
  141. data/spec/lib/simp/cli/config/item/use_iptables_spec.rb +29 -0
  142. data/spec/lib/simp/cli/config/item/use_ldap_spec.rb +29 -0
  143. data/spec/lib/simp/cli/config/item/use_selinux_spec.rb +24 -0
  144. data/spec/lib/simp/cli/config/item/yum_repositories_spec.rb +94 -0
  145. data/spec/lib/simp/cli/config/item_spec.rb +106 -0
  146. data/spec/lib/simp/cli/config/spec_helper.rb +1 -0
  147. data/spec/lib/simp/cli/config/utils_spec.rb +131 -0
  148. data/spec/lib/simp/cli/spec_helper.rb +1 -0
  149. data/spec/spec_helper.rb +91 -0
  150. metadata +391 -0
@@ -0,0 +1,85 @@
1
+ require 'simp/cli/config/item/puppet_hosts_entry'
2
+ require 'simp/cli/config/item/puppet_server'
3
+ require 'simp/cli/config/item/puppet_server_ip'
4
+ require 'rspec/its'
5
+ require_relative( 'spec_helper' )
6
+
7
+ describe Simp::Cli::Config::Item::PuppetHostsEntry do
8
+ before :all do
9
+ @ci = Simp::Cli::Config::Item::PuppetHostsEntry.new
10
+ @ci.silent = true # turn off command line summary on stdout
11
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
12
+ @tmp_dir = File.expand_path( 'tmp', File.dirname( __FILE__ ) )
13
+ end
14
+
15
+ describe "#apply" do
16
+ before :context do
17
+ @tmp_file = File.join( @tmp_dir, 'test__hosts' )
18
+ @file = File.join( @files_dir,'hosts')
19
+ @ci.file = @tmp_file
20
+
21
+ item = Simp::Cli::Config::Item::PuppetServerIP.new
22
+ item.value = '1.2.3.4'
23
+ @ci.config_items[item.key] = item
24
+
25
+ item = Simp::Cli::Config::Item::PuppetServer.new
26
+ item.value = 'puppet.domain.tld'
27
+ @ci.config_items[item.key] = item
28
+ end
29
+
30
+ context "with a fresh hosts file" do
31
+ before :context do
32
+ FileUtils.mkdir_p @tmp_dir
33
+ FileUtils.copy_file @file, @tmp_file
34
+
35
+ @result = @ci.apply
36
+ end
37
+
38
+ it "configures hosts with the correct values" do
39
+ lines = File.readlines( @tmp_file ).join( "\n" )
40
+ expect( lines ).to match(%r{\bpuppet.domain.tld\b})
41
+ end
42
+
43
+ it "reports success" do
44
+ expect( @result ).to eq true
45
+ end
46
+
47
+ after :context do
48
+ FileUtils.rm @tmp_file
49
+ end
50
+ end
51
+
52
+
53
+ context "with an existing hosts file" do
54
+ before :context do
55
+ FileUtils.mkdir_p @tmp_dir
56
+ FileUtils.copy_file @file, @tmp_file
57
+
58
+ @result = @ci.apply
59
+ end
60
+
61
+ it "configures hosts with the correct values" do
62
+ lines = File.readlines( @tmp_file ).join( "\n" )
63
+ expect( lines ).to match(%r{\bpuppet.domain.tld\b})
64
+ end
65
+
66
+ it "replaces puppet host/aliases with the correct values" do
67
+ lines = File.readlines( @tmp_file ).each do |line|
68
+ expect( line ).to_not match(%r{\bpuppet.example.com\b})
69
+ end
70
+ end
71
+
72
+ it "reports success" do
73
+ expect( @result ).to eq true
74
+ end
75
+
76
+ after :context do
77
+ FileUtils.rm @tmp_file
78
+ end
79
+ end
80
+ end
81
+
82
+ it_behaves_like "an Item that doesn't output YAML"
83
+ it_behaves_like "a child of Simp::Cli::Config::Item"
84
+ end
85
+
@@ -0,0 +1,24 @@
1
+ require 'simp/cli/config/item/puppet_server_ip'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::PuppetServerIP do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::PuppetServerIP.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates IPv4 IPs" do
12
+ expect( @ci.validate '192.168.1.1' ).to eq true
13
+ end
14
+
15
+ it "doesn't validate bad IPs" do
16
+ expect( @ci.validate 'x.x.x.x' ).to eq false
17
+ expect( @ci.validate '999.999.999.999' ).to eq false
18
+ expect( @ci.validate '192.168.1.1/24' ).to eq false
19
+ expect( @ci.validate nil ).to eq false
20
+ expect( @ci.validate false ).to eq false
21
+ end
22
+ end
23
+ it_behaves_like "a child of Simp::Cli::Config::Item"
24
+ end
@@ -0,0 +1,22 @@
1
+ require 'simp/cli/config/item/puppet_server'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::PuppetServer do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::PuppetServer.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates fqdns" do
12
+ expect( @ci.validate 'puppet' ).to eq true
13
+ expect( @ci.validate 'puppet.change.me' ).to eq true
14
+ end
15
+
16
+ it "doesn't validate bad fqdns" do
17
+ expect( @ci.validate 'puppet-' ).to eq false
18
+ end
19
+ end
20
+
21
+ it_behaves_like "a child of Simp::Cli::Config::Item"
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'simp/cli/config/item/puppetdb_port'
2
+ require_relative( 'spec_helper' )
3
+
4
+ describe Simp::Cli::Config::Item::PuppetDBPort do
5
+ before :each do
6
+ @ci = Simp::Cli::Config::Item::PuppetDBPort.new
7
+ @ci.silent = true
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates proper port number" do
12
+ expect( @ci.validate '8139' ).to eq true
13
+ end
14
+
15
+ it "doesn't validate nonsense" do
16
+ expect( @ci.validate '0' ).to eq false
17
+ expect( @ci.validate '-1' ).to eq false
18
+ expect( @ci.validate '999999999' ).to eq false
19
+ expect( @ci.validate 'fred' ).to eq false
20
+ expect( @ci.validate '' ).to eq false
21
+ end
22
+ end
23
+
24
+ it_behaves_like "a child of Simp::Cli::Config::Item"
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'simp/cli/config/item/puppetdb_server'
2
+ require_relative( 'spec_helper' )
3
+
4
+ describe Simp::Cli::Config::Item::PuppetDBServer do
5
+ before :each do
6
+ @ci = Simp::Cli::Config::Item::PuppetDBServer.new
7
+ @ci.silent = true
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates puppet fqdn" do
12
+ expect( @ci.validate 'puppet.change.me' ).to eq true
13
+ end
14
+
15
+ it "validates hiera" do
16
+ expect( @ci.validate "%{hiera('puppet::server')}" ).to eq true
17
+ end
18
+
19
+ it "doesn't validate empty string" do
20
+ expect( @ci.validate '' ).to eq false
21
+ end
22
+ end
23
+
24
+ it_behaves_like "a child of Simp::Cli::Config::Item"
25
+ end
@@ -0,0 +1,58 @@
1
+ require 'simp/cli/config/item/remove_ldap_from_hiera'
2
+ require 'simp/cli/config/item/hostname'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::RemoveLdapFromHiera do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::RemoveLdapFromHiera.new
8
+ @ci.silent = true
9
+ end
10
+
11
+ describe "#strip_line?" do
12
+ it 'decides to strip ::ldap and openldap:: classes' do
13
+ expect(@ci.strip_line?(' - simp::ldap_server')).to be true
14
+ expect(@ci.strip_line?(%q{ - 'simp::ldap_server'})).to be true
15
+ expect(@ci.strip_line?(' - openldap')).to be true
16
+ expect(@ci.strip_line?(' - openldap::server')).to be true
17
+ end
18
+
19
+ it 'rejects false positives' do
20
+ expect(@ci.strip_line?( '# - simp::ldap_server')).to be false
21
+ expect(@ci.strip_line?(' - randomldap::foo')).to be false
22
+ end
23
+ end
24
+
25
+ describe "#apply" do
26
+ context "with a valid fqdn" do
27
+ before :each do
28
+ @fqdn = 'hostname.domain.tld'
29
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
30
+ @tmp_dir = File.expand_path( 'tmp', File.dirname( __FILE__ ) )
31
+ @file = File.join( @files_dir,'puppet.your.domain.yaml')
32
+ @tmp_file = File.join( @tmp_dir, "#{@fqdn}.yaml" )
33
+ @ci.dir = @tmp_dir
34
+
35
+ item = Simp::Cli::Config::Item::Hostname.new
36
+ item.value = @fqdn
37
+ @ci.config_items[item.key] = item
38
+ @new_file = File.join( @tmp_dir, "#{@fqdn}.yaml" )
39
+
40
+ [@tmp_file, @new_file].each do |file|
41
+ FileUtils.rm file if File.exists? file
42
+ end
43
+
44
+ FileUtils.mkdir_p @tmp_dir
45
+ FileUtils.copy_file @file, @tmp_file
46
+
47
+ @result = @ci.apply
48
+ end
49
+
50
+ it "file won't have any lines containing ldap" do
51
+ expect( File.open(@tmp_file).readlines.join("\n") ).not_to match(/ldap/)
52
+ end
53
+ end
54
+ end
55
+
56
+ it_behaves_like "an Item that doesn't output YAML"
57
+ it_behaves_like 'a child of Simp::Cli::Config::Item'
58
+ end
@@ -0,0 +1,63 @@
1
+ require 'simp/cli/config/item/rename_fqdn_yaml'
2
+ require 'simp/cli/config/item/hostname'
3
+ require 'rspec/its'
4
+ require_relative( 'spec_helper' )
5
+
6
+ describe Simp::Cli::Config::Item::RenameFqdnYaml do
7
+ before :all do
8
+ @ci = Simp::Cli::Config::Item::RenameFqdnYaml.new
9
+ @ci.silent = true # turn off command line summary on stdout
10
+ end
11
+
12
+ context "when ensuring the hosts entry" do
13
+ before :context do
14
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
15
+ @tmp_dir = File.expand_path( 'tmp', File.dirname( __FILE__ ) )
16
+ @file = File.join( @files_dir,'puppet.your.domain.yaml')
17
+ @tmp_file = File.join( @tmp_dir, 'temp__puppet.your.domain.yaml' )
18
+ @ci.file = @tmp_file
19
+
20
+ @fqdn = 'hostname.domain.tld'
21
+ item = Simp::Cli::Config::Item::Hostname.new
22
+ item.value = @fqdn
23
+ @ci.config_items[item.key] = item
24
+ @new_file = File.join( @tmp_dir, "#{@fqdn}.yaml" )
25
+ end
26
+
27
+
28
+ context "when moving the yaml file" do
29
+ before :context do
30
+ [@tmp_file, @new_file].each do |file|
31
+ FileUtils.rm file if File.exists? file
32
+ end
33
+
34
+ FileUtils.mkdir_p @tmp_dir
35
+ FileUtils.copy_file @file, @tmp_file
36
+
37
+ @result = @ci.apply
38
+ end
39
+
40
+ it "places a file in the correct location" do
41
+ expect( File ).to exist( @new_file )
42
+ end
43
+
44
+ it "doesn't leave a file in the old location" do
45
+ expect( File ).not_to exist( @tmp_file )
46
+ end
47
+
48
+ it "reports success" do
49
+ expect( @result ).to eq true
50
+ end
51
+
52
+ after :context do
53
+ [@tmp_file, @new_file].each do |file|
54
+ FileUtils.rm file if File.exists? file
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ it_behaves_like "an Item that doesn't output YAML"
61
+ it_behaves_like "a child of Simp::Cli::Config::Item"
62
+ end
63
+
@@ -0,0 +1,28 @@
1
+ require 'simp/cli/config/item/rsync_base'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::RsyncBase do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::RsyncBase.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates a good rsync base path" do
12
+ expect( @ci.validate "/var/simp/rsync/%{::operatingsystem}/%{::lsbmajdistrelease}" ).to eq true
13
+ expect( @ci.validate "/srv/simp/rsync/%{::operatingsystem}/%{::lsbmajdistrelease}" ).to eq true
14
+ end
15
+
16
+ it "doesn't validate bad rsync base paths" do
17
+ expect( @ci.validate '..' ).to eq false
18
+ end
19
+ end
20
+
21
+ describe "#recommended_value" do
22
+ it "recommends a /srv or /var/simp path" do
23
+ expect( @ci.recommended_value ).to match %r{^(/var/simp/rsync|/srv/simp/rsync|/srv/rsync)}
24
+ end
25
+ end
26
+
27
+ it_behaves_like "a child of Simp::Cli::Config::Item"
28
+ end
@@ -0,0 +1,41 @@
1
+ require 'simp/cli/config/item/rsync_server'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::RsyncServer do
6
+ before :each do
7
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
8
+ @ci = Simp::Cli::Config::Item::RsyncServer.new
9
+ @ci.silent = true
10
+ end
11
+
12
+ describe "#validate" do
13
+ it "validates a good rsync server" do
14
+ expect( @ci.validate 'puppet.simp.dev' ).to eq true
15
+ expect( @ci.validate '127.0.0.1' ).to eq true
16
+ end
17
+
18
+ it "doesn't validate nonsense" do
19
+ expect( @ci.validate '..' ).to eq false
20
+ end
21
+ end
22
+
23
+ describe "os_value" do
24
+ it "reads address from rsyncd.conf file" do
25
+ @ci.file = File.join( @files_dir, 'rsyncd.conf' )
26
+ expect( @ci.os_value ).to eq '127.0.0.1'
27
+ end
28
+
29
+ it "returns nil if file does not contain address" do
30
+ @ci.file = '/dev/null'
31
+ expect( @ci.os_value ).to be_falsey
32
+ end
33
+
34
+ it "returns nil if file is not readable" do
35
+ @ci.file = '/proc/nonsense/blahblahblah/.........'
36
+ expect( @ci.os_value ).to be_falsey
37
+ end
38
+ end
39
+
40
+ it_behaves_like "a child of Simp::Cli::Config::Item"
41
+ end
@@ -0,0 +1,21 @@
1
+ require 'simp/cli/config/item/rsync_timeout'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::RsyncTimeout do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::RsyncTimeout.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates a good rsync timeout" do
12
+ expect( @ci.validate "1" ).to eq true
13
+ end
14
+
15
+ it "doesn't validate a bad rsync timeout" do
16
+ expect( @ci.validate '-1' ).to eq false
17
+ end
18
+ end
19
+
20
+ it_behaves_like "a child of Simp::Cli::Config::Item"
21
+ end
@@ -0,0 +1,29 @@
1
+ require 'simp/cli/config/item/set_grub_password'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::SetGrubPassword do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::SetGrubPassword.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates yes/no" do
12
+ expect( @ci.validate 'yes' ).to eq true
13
+ expect( @ci.validate 'y' ).to eq true
14
+ expect( @ci.validate 'Y' ).to eq true
15
+ expect( @ci.validate 'no' ).to eq true
16
+ expect( @ci.validate 'n' ).to eq true
17
+ expect( @ci.validate 'NO' ).to eq true
18
+ expect( @ci.validate true ).to eq true
19
+ expect( @ci.validate false ).to eq true
20
+ end
21
+
22
+ it "doesn't validate other things" do
23
+ expect( @ci.validate 'ydd' ).to eq false
24
+ expect( @ci.validate 'gsdg' ).to eq false
25
+ end
26
+ end
27
+
28
+ it_behaves_like "a child of Simp::Cli::Config::Item"
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'simp/cli/config/item/simp_yum_servers'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::SimpYumServers do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::SimpYumServers.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates array with good hosts" do
12
+ expect( @ci.validate ['yum'] ).to eq true
13
+ expect( @ci.validate ['yum-server'] ).to eq true
14
+ expect( @ci.validate ['yum.yummityyum.org'] ).to eq true
15
+ expect( @ci.validate ['192.168.1.1'] ).to eq true
16
+ expect( @ci.validate ['192.168.1.1'] ).to eq true
17
+ expect( @ci.validate ["%{hiera('puppet::server')}"] ).to eq true
18
+ expect( @ci.validate ["%{::domain}"] ).to eq true
19
+
20
+ # yum_servers is allowed to be empty
21
+ expect( @ci.validate nil ).to eq true
22
+ expect( @ci.validate ' ' ).to eq true
23
+ expect( @ci.validate '' ).to eq true
24
+ expect( @ci.validate [] ).to eq true
25
+ end
26
+
27
+ it "doesn't validate array with bad hosts" do
28
+ expect( @ci.validate 0 ).to eq false
29
+ expect( @ci.validate false ).to eq false
30
+ expect( @ci.validate [nil] ).to eq false
31
+ expect( @ci.validate ['yum-'] ).to eq false
32
+ expect( @ci.validate ['-yum'] ).to eq false
33
+ expect( @ci.validate ['yum.yummityyum.org.'] ).to eq false
34
+ expect( @ci.validate ['.yum.yummityyum.org'] ).to eq false
35
+ expect( @ci.validate ["%[hiera('puppet::server')]"] ).to eq false
36
+ end
37
+ end
38
+
39
+ it_behaves_like "a child of Simp::Cli::Config::Item"
40
+ end
41
+