beaker 4.38.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +36 -11
  5. data/.rubocop.yml +75 -0
  6. data/.rubocop_todo.yml +239 -0
  7. data/CHANGELOG.md +88 -33
  8. data/Gemfile +16 -4
  9. data/HISTORY.md +103 -0
  10. data/Rakefile +101 -112
  11. data/acceptance/config/acceptance-options.rb +1 -1
  12. data/acceptance/config/base/acceptance-options.rb +2 -2
  13. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  14. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  15. data/acceptance/fixtures/module/Gemfile +1 -1
  16. data/acceptance/fixtures/module/Rakefile +3 -3
  17. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +16 -23
  18. data/acceptance/fixtures/module/spec/classes/init_spec.rb +1 -2
  19. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  20. data/acceptance/lib/helpers/test_helper.rb +7 -6
  21. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  22. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  24. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +7 -8
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +9 -7
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +15 -21
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +23 -30
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +3 -3
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +21 -16
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +7 -7
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +30 -38
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +14 -18
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +8 -14
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +7 -11
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +4 -5
  40. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +8 -8
  41. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +4 -6
  42. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  43. data/acceptance/tests/base/dsl/structure_test.rb +9 -21
  44. data/acceptance/tests/base/host/file_test.rb +8 -8
  45. data/acceptance/tests/base/host/group_test.rb +2 -3
  46. data/acceptance/tests/base/host/host_test.rb +69 -66
  47. data/acceptance/tests/base/host/packages.rb +27 -30
  48. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  49. data/acceptance/tests/base/host/user_test.rb +2 -3
  50. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  51. data/acceptance/tests/base/test_suite/export.rb +6 -9
  52. data/acceptance/tests/install/from_file.rb +3 -5
  53. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  54. data/acceptance/tests/subcommands/destroy.rb +19 -21
  55. data/acceptance/tests/subcommands/exec.rb +0 -1
  56. data/acceptance/tests/subcommands/init.rb +2 -3
  57. data/acceptance/tests/subcommands/provision.rb +0 -1
  58. data/beaker.gemspec +10 -14
  59. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  60. data/docs/concepts/style_guide.md +1 -1
  61. data/docs/how_to/debug_beaker_tests.md +13 -13
  62. data/docs/how_to/hosts/eos.md +2 -12
  63. data/docs/how_to/install_puppet.md +0 -18
  64. data/docs/how_to/test_arbitrary_beaker_versions.md +2 -2
  65. data/docs/how_to/the_beaker_dsl.md +0 -2
  66. data/lib/beaker/cli.rb +63 -74
  67. data/lib/beaker/command.rb +22 -30
  68. data/lib/beaker/command_factory.rb +4 -3
  69. data/lib/beaker/dsl/assertions.rb +7 -19
  70. data/lib/beaker/dsl/helpers/hocon_helpers.rb +5 -9
  71. data/lib/beaker/dsl/helpers/host_helpers.rb +72 -133
  72. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  73. data/lib/beaker/dsl/helpers/web_helpers.rb +20 -28
  74. data/lib/beaker/dsl/helpers.rb +2 -4
  75. data/lib/beaker/dsl/outcomes.rb +17 -19
  76. data/lib/beaker/dsl/patterns.rb +1 -3
  77. data/lib/beaker/dsl/roles.rb +18 -21
  78. data/lib/beaker/dsl/structure.rb +55 -67
  79. data/lib/beaker/dsl/test_tagging.rb +7 -10
  80. data/lib/beaker/dsl/wrappers.rb +15 -16
  81. data/lib/beaker/dsl.rb +2 -3
  82. data/lib/beaker/host/aix/exec.rb +1 -1
  83. data/lib/beaker/host/aix/file.rb +0 -1
  84. data/lib/beaker/host/aix/group.rb +3 -3
  85. data/lib/beaker/host/aix/user.rb +3 -3
  86. data/lib/beaker/host/aix.rb +3 -4
  87. data/lib/beaker/host/cisco.rb +36 -48
  88. data/lib/beaker/host/eos.rb +4 -30
  89. data/lib/beaker/host/freebsd/exec.rb +1 -1
  90. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  91. data/lib/beaker/host/freebsd.rb +9 -12
  92. data/lib/beaker/host/mac/exec.rb +5 -5
  93. data/lib/beaker/host/mac/group.rb +13 -13
  94. data/lib/beaker/host/mac/pkg.rb +6 -109
  95. data/lib/beaker/host/mac/user.rb +7 -7
  96. data/lib/beaker/host/mac.rb +8 -9
  97. data/lib/beaker/host/pswindows/exec.rb +70 -74
  98. data/lib/beaker/host/pswindows/file.rb +4 -6
  99. data/lib/beaker/host/pswindows/group.rb +5 -5
  100. data/lib/beaker/host/pswindows/pkg.rb +17 -17
  101. data/lib/beaker/host/pswindows/user.rb +4 -4
  102. data/lib/beaker/host/pswindows.rb +4 -3
  103. data/lib/beaker/host/unix/exec.rb +86 -88
  104. data/lib/beaker/host/unix/file.rb +41 -47
  105. data/lib/beaker/host/unix/group.rb +3 -3
  106. data/lib/beaker/host/unix/pkg.rb +158 -421
  107. data/lib/beaker/host/unix/user.rb +4 -4
  108. data/lib/beaker/host/unix.rb +18 -20
  109. data/lib/beaker/host/windows/exec.rb +20 -20
  110. data/lib/beaker/host/windows/file.rb +5 -5
  111. data/lib/beaker/host/windows/group.rb +5 -5
  112. data/lib/beaker/host/windows/pkg.rb +6 -57
  113. data/lib/beaker/host/windows/user.rb +4 -4
  114. data/lib/beaker/host/windows.rb +13 -13
  115. data/lib/beaker/host.rb +82 -139
  116. data/lib/beaker/host_prebuilt_steps.rb +121 -233
  117. data/lib/beaker/hypervisor/noop.rb +2 -4
  118. data/lib/beaker/hypervisor.rb +46 -63
  119. data/lib/beaker/local_connection.rb +4 -6
  120. data/lib/beaker/logger.rb +71 -85
  121. data/lib/beaker/logger_junit.rb +22 -26
  122. data/lib/beaker/network_manager.rb +40 -43
  123. data/lib/beaker/options/command_line_parser.rb +12 -23
  124. data/lib/beaker/options/hosts_file_parser.rb +34 -25
  125. data/lib/beaker/options/options_file_parser.rb +3 -6
  126. data/lib/beaker/options/options_hash.rb +3 -10
  127. data/lib/beaker/options/parser.rb +89 -105
  128. data/lib/beaker/options/presets.rb +114 -123
  129. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  130. data/lib/beaker/options/validator.rb +26 -31
  131. data/lib/beaker/perf.rb +29 -34
  132. data/lib/beaker/platform.rb +38 -46
  133. data/lib/beaker/result.rb +7 -6
  134. data/lib/beaker/shared/error_handler.rb +8 -10
  135. data/lib/beaker/shared/fog_credentials.rb +5 -9
  136. data/lib/beaker/shared/host_manager.rb +40 -46
  137. data/lib/beaker/shared/options_resolver.rb +3 -7
  138. data/lib/beaker/shared/repetition.rb +6 -8
  139. data/lib/beaker/shared/semvar.rb +39 -43
  140. data/lib/beaker/shared/timed.rb +2 -5
  141. data/lib/beaker/shared.rb +1 -1
  142. data/lib/beaker/ssh_connection.rb +46 -55
  143. data/lib/beaker/subcommand.rb +23 -30
  144. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  145. data/lib/beaker/tasks/quick_start.rb +5 -10
  146. data/lib/beaker/tasks/rake_task.rb +26 -28
  147. data/lib/beaker/tasks/test.rb +4 -4
  148. data/lib/beaker/test_case.rb +15 -27
  149. data/lib/beaker/test_suite.rb +35 -39
  150. data/lib/beaker/test_suite_result.rb +52 -57
  151. data/lib/beaker/version.rb +1 -1
  152. data/lib/beaker.rb +5 -6
  153. data/spec/beaker/cli_spec.rb +135 -153
  154. data/spec/beaker/command_spec.rb +64 -58
  155. data/spec/beaker/dsl/assertions_spec.rb +38 -47
  156. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +114 -135
  157. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  158. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +30 -36
  159. data/spec/beaker/dsl/outcomes_spec.rb +15 -14
  160. data/spec/beaker/dsl/roles_spec.rb +170 -132
  161. data/spec/beaker/dsl/structure_spec.rb +181 -163
  162. data/spec/beaker/dsl/test_tagging_spec.rb +94 -95
  163. data/spec/beaker/dsl/wrappers_spec.rb +39 -40
  164. data/spec/beaker/host/aix_spec.rb +14 -14
  165. data/spec/beaker/host/cisco_spec.rb +92 -102
  166. data/spec/beaker/host/eos_spec.rb +15 -36
  167. data/spec/beaker/host/freebsd/exec_spec.rb +5 -8
  168. data/spec/beaker/host/freebsd/pkg_spec.rb +29 -29
  169. data/spec/beaker/host/mac/exec_spec.rb +4 -5
  170. data/spec/beaker/host/mac/group_spec.rb +47 -56
  171. data/spec/beaker/host/mac/user_spec.rb +53 -62
  172. data/spec/beaker/host/pswindows/exec_spec.rb +36 -35
  173. data/spec/beaker/host/pswindows/file_spec.rb +21 -18
  174. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  175. data/spec/beaker/host/pswindows_spec.rb +14 -14
  176. data/spec/beaker/host/unix/exec_spec.rb +87 -92
  177. data/spec/beaker/host/unix/file_spec.rb +76 -82
  178. data/spec/beaker/host/unix/pkg_spec.rb +165 -407
  179. data/spec/beaker/host/unix_spec.rb +11 -207
  180. data/spec/beaker/host/windows/exec_spec.rb +32 -34
  181. data/spec/beaker/host/windows/file_spec.rb +22 -23
  182. data/spec/beaker/host/windows/group_spec.rb +17 -19
  183. data/spec/beaker/host/windows/pkg_spec.rb +10 -13
  184. data/spec/beaker/host/windows/user_spec.rb +17 -23
  185. data/spec/beaker/host/windows_spec.rb +39 -39
  186. data/spec/beaker/host_prebuilt_steps_spec.rb +193 -341
  187. data/spec/beaker/host_spec.rb +241 -312
  188. data/spec/beaker/hypervisor/hypervisor_spec.rb +38 -63
  189. data/spec/beaker/localhost_connection_spec.rb +14 -13
  190. data/spec/beaker/logger_junit_spec.rb +22 -34
  191. data/spec/beaker/logger_spec.rb +174 -155
  192. data/spec/beaker/network_manager_spec.rb +27 -27
  193. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  194. data/spec/beaker/options/data/hosts_preserved.yml +395 -0
  195. data/spec/beaker/options/hosts_file_parser_spec.rb +36 -31
  196. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  197. data/spec/beaker/options/options_hash_spec.rb +7 -9
  198. data/spec/beaker/options/parser_spec.rb +187 -187
  199. data/spec/beaker/options/presets_spec.rb +8 -10
  200. data/spec/beaker/options/subcommand_options_parser_spec.rb +15 -15
  201. data/spec/beaker/options/validator_spec.rb +27 -28
  202. data/spec/beaker/perf_spec.rb +32 -34
  203. data/spec/beaker/platform_spec.rb +27 -37
  204. data/spec/beaker/shared/error_handler_spec.rb +8 -17
  205. data/spec/beaker/shared/fog_credentials_spec.rb +30 -30
  206. data/spec/beaker/shared/host_manager_spec.rb +55 -89
  207. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  208. data/spec/beaker/shared/repetition_spec.rb +24 -31
  209. data/spec/beaker/shared/semvar_spec.rb +21 -26
  210. data/spec/beaker/ssh_connection_spec.rb +85 -90
  211. data/spec/beaker/subcommand/subcommand_util_spec.rb +40 -37
  212. data/spec/beaker/subcommand_spec.rb +89 -89
  213. data/spec/beaker/test_case_spec.rb +33 -62
  214. data/spec/beaker/test_suite_spec.rb +153 -160
  215. data/spec/helpers.rb +48 -53
  216. data/spec/matchers.rb +9 -8
  217. data/spec/mocks.rb +6 -11
  218. data/spec/spec_helper.rb +0 -4
  219. metadata +60 -85
  220. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  221. data/acceptance/tests/base/external_resources_test.rb +0 -31
  222. data/spec/beaker/host/mac_spec.rb +0 -113
  223. data/spec/mock_fission.rb +0 -60
  224. data/spec/mock_vsphere.rb +0 -314
  225. data/spec/mock_vsphere_helper.rb +0 -183
@@ -1,10 +1,9 @@
1
- [ 'host', 'command_factory' ].each do |lib|
1
+ %w[host command_factory].each do |lib|
2
2
  require "beaker/#{lib}"
3
3
  end
4
4
 
5
5
  module Cisco
6
6
  class Host < Unix::Host
7
-
8
7
  # as the cisco hosts tend to have custom
9
8
  # ssh configuration, the presets
10
9
  # do not apply where verification of the
@@ -12,10 +11,10 @@ module Cisco
12
11
  def platform_defaults
13
12
  h = Beaker::Options::OptionsHash.new
14
13
  h.merge({
15
- 'ssh' => {
16
- :verify_host_key => false,
17
- },
18
- })
14
+ 'ssh' => {
15
+ :verify_host_key => false,
16
+ },
17
+ })
19
18
  end
20
19
 
21
20
  # Tells you whether a host platform supports beaker's
@@ -34,9 +33,7 @@ module Cisco
34
33
  #
35
34
  # @return nil
36
35
  def scp_post_operations(scp_file_actual, scp_file_target)
37
- if self[:platform] =~ /cisco_nexus/
38
- execute( "mv #{scp_file_actual} #{scp_file_target}" )
39
- end
36
+ execute("mv #{scp_file_actual} #{scp_file_target}") if self[:platform].include?('cisco_nexus')
40
37
  nil
41
38
  end
42
39
 
@@ -47,10 +44,10 @@ module Cisco
47
44
  # @return [String] path, changed if needed due to host
48
45
  # constraints
49
46
  def scp_path(path)
50
- if self[:platform] =~ /cisco_nexus/
51
- @home_dir ||= execute( 'pwd' )
52
- answer = "#{@home_dir}/#{File.basename( path )}"
53
- answer << '/' if path =~ /\/$/
47
+ if self[:platform].include?('cisco_nexus')
48
+ @home_dir ||= execute('pwd')
49
+ answer = "#{@home_dir}/#{File.basename(path)}"
50
+ answer << '/' if /\/$/.match?(path)
54
51
  return answer
55
52
  end
56
53
  path
@@ -81,20 +78,17 @@ module Cisco
81
78
  # @param [Hash] opts optional parameters
82
79
  #
83
80
  # @return [String] Command string as needed for this host
84
- def prepend_commands(command = '', user_pc = '', opts = {})
81
+ def prepend_commands(command = '', user_pc = '', _opts = {})
85
82
  return user_pc unless command.index('vsh').nil?
86
- if self[:platform] =~ /cisco_nexus/
83
+
84
+ if self[:platform].include?('cisco_nexus')
87
85
  return user_pc unless command.index('ntpdate').nil?
88
86
  end
89
87
 
90
88
  prepend_cmds = 'source /etc/profile;'
91
89
  prepend_cmds << " sudo -E sh -c \"" if self[:user] != 'root'
92
- if self[:vrf]
93
- prepend_cmds << "ip netns exec #{self[:vrf]} "
94
- end
95
- if user_pc && !user_pc.empty?
96
- prepend_cmds << "#{user_pc} "
97
- end
90
+ prepend_cmds << "ip netns exec #{self[:vrf]} " if self[:vrf]
91
+ prepend_cmds << "#{user_pc} " if user_pc && !user_pc.empty?
98
92
  prepend_cmds.strip
99
93
  end
100
94
 
@@ -105,10 +99,10 @@ module Cisco
105
99
  # @param [Hash] opts optional parameters
106
100
  #
107
101
  # @return [String] Command string as needed for this host
108
- def append_commands(command = '', user_ac = '', opts = {})
109
- command.gsub('"') {'\\"'}
102
+ def append_commands(command = '', _user_ac = '', _opts = {})
103
+ command.gsub('"') { '\\"' }
110
104
  # vsh commands, ntpdate or when user is root commands do not require an appended `"`
111
- return '"' unless command =~ /ntpdate|\/isan\/bin\/vsh/ || self[:user] == 'root'
105
+ return '"' unless /ntpdate|\/isan\/bin\/vsh/.match?(command) || self[:user] == 'root'
112
106
  end
113
107
 
114
108
  # Construct the environment string for this command
@@ -125,16 +119,17 @@ module Cisco
125
119
  def environment_string env
126
120
  prestring = ''
127
121
  return prestring if env.empty?
128
- env_array = self.environment_variable_string_pair_array( env )
122
+
123
+ env_array = self.environment_variable_string_pair_array(env)
129
124
  environment_string = env_array.join(' ')
130
125
 
131
- if self[:platform] =~ /cisco_nexus/
132
- prestring << " export"
133
- else
134
- prestring << " env"
135
- end
126
+ prestring << if self[:platform].include?('cisco_nexus')
127
+ " export"
128
+ else
129
+ " env"
130
+ end
136
131
  environment_string = "#{prestring} #{environment_string}"
137
- environment_string << ';' if prestring =~ /export/
132
+ environment_string << ';' if prestring.include?('export')
138
133
  environment_string
139
134
  end
140
135
 
@@ -145,27 +140,20 @@ module Cisco
145
140
  # this will be raised with the appropriate message
146
141
  def validate_setup
147
142
  msg = nil
148
- if self[:platform] =~ /cisco_nexus/
149
- if !self[:vrf]
150
- msg = 'Cisco Nexus hosts must be provided with a :vrf value.'
151
- end
152
- if !self[:user]
153
- msg = 'Cisco hosts must be provided with a :user value'
154
- end
143
+ if self[:platform].include?('cisco_nexus')
144
+ msg = 'Cisco Nexus hosts must be provided with a :vrf value.' if !self[:vrf]
145
+ msg = 'Cisco hosts must be provided with a :user value' if !self[:user]
155
146
  end
156
- if self[:platform] =~ /cisco_ios_xr/
157
- if !self[:user]
158
- msg = 'Cisco hosts must be provided with a :user value'
159
- end
147
+ if self[:platform].include?('cisco_ios_xr')
148
+ msg = 'Cisco hosts must be provided with a :user value' if !self[:user]
160
149
  end
161
150
 
162
- if msg
163
- msg << <<-EOF
151
+ return unless msg
152
+
153
+ msg << <<-EOF
164
154
  Check https://github.com/puppetlabs/beaker/blob/master/docs/hosts/cisco.md for more info.'
165
- EOF
166
- raise ArgumentError, msg
167
- end
155
+ EOF
156
+ raise ArgumentError, msg
168
157
  end
169
-
170
158
  end
171
159
  end
@@ -1,34 +1,9 @@
1
- [ 'host', 'command_factory' ].each do |lib|
1
+ %w[host command_factory].each do |lib|
2
2
  require "beaker/#{lib}"
3
3
  end
4
4
 
5
5
  module Eos
6
6
  class Host < Unix::Host
7
-
8
- # Gets the path & file name for the puppet agent dev package on EOS
9
- #
10
- # @param [String] puppet_collection Name of the puppet collection to use
11
- # @param [String] puppet_agent_version Version of puppet agent to get
12
- # @param [Hash{Symbol=>String}] opts Options hash to provide extra values
13
- #
14
- # @note EOS doesn't use any additional options at this time, but does require
15
- # both puppet_collection & puppet_agent_version, & will fail without them
16
- #
17
- # @raise [ArgumentError] If one of the two required parameters (puppet_collection,
18
- # puppet_agent_version) is either not passed or set to nil
19
- #
20
- # @return [String, String] Path to the directory and filename of the package, respectively
21
- def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} )
22
- error_message = "Must provide %s argument to get puppet agent dev package information"
23
- raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
24
- raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version
25
-
26
- variant, version, arch, _ = self['platform'].to_array
27
- release_path = "#{variant}/#{version}/#{puppet_collection}/#{arch}"
28
- release_file = "puppet-agent-#{puppet_agent_version}-1.#{variant}#{version}.#{arch}.swix"
29
- return release_path, release_file
30
- end
31
-
32
7
  # Copies a remote file to the host location specified
33
8
  #
34
9
  # @param [String] remote_url URL to the remote file
@@ -38,7 +13,7 @@ module Eos
38
13
  # about location, so that parameter is ignored
39
14
  #
40
15
  # @return [Result] The result of copying that file to the host
41
- def get_remote_file( remote_url, host_directory = '' )
16
+ def get_remote_file(remote_url, _host_directory = '')
42
17
  commands = ['enable', "copy #{remote_url} extension:"]
43
18
  command = commands.join("\n")
44
19
  execute("Cli -c '#{command}'")
@@ -49,11 +24,10 @@ module Eos
49
24
  # @param [String] filename Name of the file to install, including file extension
50
25
  #
51
26
  # @return [Result] The result of running the install command on the host
52
- def install_from_file( filename )
27
+ def install_from_file(filename)
53
28
  commands = ['enable', "extension #{filename}"]
54
29
  command = commands.join("\n")
55
30
  execute("Cli -c '#{command}'")
56
31
  end
57
-
58
32
  end
59
- end
33
+ end
@@ -3,7 +3,7 @@ module FreeBSD::Exec
3
3
 
4
4
  def echo_to_file(str, filename)
5
5
  # FreeBSD gets weird about special characters, we have to go a little OTT here
6
- escaped_str = str.gsub(/\t/,'\\t').gsub(/\n/,'\\n')
6
+ escaped_str = str.gsub(/\t/, '\\t').gsub(/\n/, '\\n')
7
7
 
8
8
  exec(Beaker::Command.new("printf \"#{escaped_str}\" > #{filename}"))
9
9
  end
@@ -8,11 +8,11 @@ module FreeBSD::Pkg
8
8
 
9
9
  def check_pkgng_sh
10
10
  'TMPDIR=/dev/null ASSUME_ALWAYS_YES=1 PACKAGESITE=file:///nonexist ' \
11
- 'pkg info -x "pkg(-devel)?\\$" > /dev/null 2>&1'
11
+ 'pkg info -x "pkg(-devel)?\\$" > /dev/null 2>&1'
12
12
  end
13
13
 
14
14
  def pkgng_active?(opts = {})
15
- opts = {:accept_all_exit_codes => true}.merge(opts)
15
+ opts = { :accept_all_exit_codes => true }.merge(opts)
16
16
  execute("/bin/sh -c '#{check_pkgng_sh}'", opts) { |r| r }.exit_code == 0
17
17
  end
18
18
 
@@ -35,7 +35,7 @@ module FreeBSD::Pkg
35
35
  end
36
36
 
37
37
  def check_for_package(package, opts = {})
38
- opts = {:accept_all_exit_codes => true}.merge(opts)
38
+ opts = { :accept_all_exit_codes => true }.merge(opts)
39
39
  cmd = if pkgng_active?
40
40
  "pkg info #{package}"
41
41
  else
@@ -1,15 +1,14 @@
1
- [ 'host', 'command_factory' ].each do |lib|
1
+ %w[host command_factory].each do |lib|
2
2
  require "beaker/#{lib}"
3
3
  end
4
4
 
5
5
  module FreeBSD
6
6
  class Host < Unix::Host
7
-
8
- [
9
- 'exec',
10
- 'pkg',
7
+ %w[
8
+ exec
9
+ pkg
11
10
  ].each do |lib|
12
- require "beaker/host/freebsd/#{lib}"
11
+ require "beaker/host/freebsd/#{lib}"
13
12
  end
14
13
 
15
14
  include FreeBSD::Exec
@@ -18,12 +17,10 @@ module FreeBSD
18
17
  def platform_defaults
19
18
  h = Beaker::Options::OptionsHash.new
20
19
  h.merge({
21
- 'user' => 'root',
22
- 'group' => 'root',
23
- 'pathseparator' => ':',
24
- })
20
+ 'user' => 'root',
21
+ 'group' => 'root',
22
+ 'pathseparator' => ':',
23
+ })
25
24
  end
26
-
27
25
  end
28
-
29
26
  end
@@ -1,7 +1,7 @@
1
1
  module Mac::Exec
2
2
  include Beaker::CommandFactory
3
3
 
4
- def touch(file, abs=true)
4
+ def touch(file, abs = true)
5
5
  (abs ? '/usr/bin/touch' : 'touch') + " #{file}"
6
6
  end
7
7
 
@@ -21,17 +21,17 @@ module Mac::Exec
21
21
  # (from {#ssh_service_restart})
22
22
  def ssh_permit_user_environment
23
23
  ssh_config_file = '/etc/sshd_config'
24
- ssh_config_file = '/private/etc/ssh/sshd_config' if self['platform'] =~ /^osx-/
24
+ ssh_config_file = '/private/etc/ssh/sshd_config' if /^osx-/.match?(self['platform'])
25
25
 
26
26
  exec(Beaker::Command.new("echo '\nPermitUserEnvironment yes' >> #{ssh_config_file}"))
27
- ssh_service_restart()
27
+ ssh_service_restart
28
28
  end
29
29
 
30
- # Checks if selinux is enabled
30
+ #  Checks if selinux is enabled
31
31
  # selinux is not availble on OS X
32
32
  #
33
33
  # @return [Boolean] false
34
- def selinux_enabled?()
34
+ def selinux_enabled?
35
35
  false
36
36
  end
37
37
 
@@ -6,11 +6,11 @@ module Mac::Group
6
6
  # @param [Proc] block Additional actions or insertions
7
7
  #
8
8
  # @return [Array<String>] The list of group names on the system
9
- def group_list(&block)
9
+ def group_list
10
10
  execute('dscacheutil -q group') do |result|
11
11
  groups = []
12
12
  result.stdout.each_line do |line|
13
- groups << line.split(': ')[1].strip if line =~ /^name:/
13
+ groups << line.split(': ')[1].strip if /^name:/.match?(line)
14
14
  end
15
15
 
16
16
  yield result if block_given?
@@ -28,14 +28,14 @@ module Mac::Group
28
28
  # @return [String] Group information in /etc/group format
29
29
  # @raise [FailTest] Raises an Assertion failure if it can't find the name
30
30
  # queried for in the returned block
31
- def group_get(name, &block)
31
+ def group_get(name)
32
32
  execute("dscacheutil -q group -a name #{name}") do |result|
33
- fail_test "failed to get group #{name}" unless result.stdout =~ /^name: #{name}/
34
- gi = Hash.new # group info
35
- result.stdout.each_line { |line|
33
+ fail_test "failed to get group #{name}" unless /^name: #{name}/.match?(result.stdout)
34
+ gi = {} # group info
35
+ result.stdout.each_line do |line|
36
36
  pieces = line.split(': ')
37
37
  gi[pieces[0].to_sym] = pieces[1].strip if pieces[1] != nil
38
- }
38
+ end
39
39
  answer = "#{gi[:name]}:#{gi[:password]}:#{gi[:gid]}"
40
40
 
41
41
  yield answer if block_given?
@@ -51,12 +51,12 @@ module Mac::Group
51
51
  def group_gid(name)
52
52
  gid = -1
53
53
  execute("dscacheutil -q group -a name #{name}") do |result|
54
- result.stdout.each_line { |line|
55
- if line =~ /^gid:/
54
+ result.stdout.each_line do |line|
55
+ if /^gid:/.match?(line)
56
56
  gid = (line[5, line.length - 5]).chomp
57
57
  break
58
58
  end
59
- }
59
+ end
60
60
  gid
61
61
  end
62
62
  end
@@ -65,16 +65,16 @@ module Mac::Group
65
65
  #
66
66
  # @param [String] name Name of the group
67
67
  # @param [Proc] block Additional actions or insertions
68
- def group_present(name, &block)
68
+ def group_present(name)
69
69
  group_exists = false
70
70
  execute("dscacheutil -q group -a name #{name}") do |result|
71
- group_exists = result.stdout =~ /^name: #{name}/
71
+ group_exists = result.stdout.start_with?("name: #{name}")
72
72
  end
73
73
 
74
74
  return if group_exists
75
75
 
76
76
  gid = gid_next
77
- create_cmd = "dscl . create /Groups/#{name}"
77
+ create_cmd = "dscl . create /Groups/#{name}"
78
78
  create_cmd << " && dscl . create /Groups/#{name} PrimaryGroupID #{gid}"
79
79
  execute(create_cmd)
80
80
  end
@@ -5,7 +5,7 @@ module Mac::Pkg
5
5
  raise "Package #{name} cannot be queried on #{self}"
6
6
  end
7
7
 
8
- def install_package(name, cmdline_args = '', version = nil)
8
+ def install_package(name, _cmdline_args = '', _version = nil)
9
9
  generic_install_dmg("#{name}.dmg", name, "#{name}.pkg")
10
10
  end
11
11
 
@@ -28,7 +28,7 @@ module Mac::Pkg
28
28
  execute("installer -pkg /Volumes/#{pkg_base}/#{pkg_name} -target /")
29
29
  end
30
30
 
31
- def uninstall_package(name, cmdline_args = '')
31
+ def uninstall_package(name, _cmdline_args = '')
32
32
  raise "Package #{name} cannot be uninstalled on #{self}"
33
33
  end
34
34
 
@@ -37,117 +37,14 @@ module Mac::Pkg
37
37
  # @param [String] name The name of the package to update
38
38
  # @param [String] cmdline_args Additional command line arguments for
39
39
  # the package manager
40
- def upgrade_package(name, cmdline_args = '')
41
- raise "Package #{name} cannot be upgraded on #{self}"
40
+ def upgrade_package(name, _cmdline_args = '')
41
+ raise "Package #{name} cannot be upgraded on #{self}"
42
42
  end
43
43
 
44
- # Deploy configuration generated by the packaging tooling to this host.
45
- #
46
- # This method calls one of #deploy_apt_repo, #deploy_yum_repo, or
47
- # #deploy_zyp_repo depending on the platform of this Host.
48
- #
49
- # @note See {Beaker::DSL::Helpers::HostHelpers#deploy_package_repo} for info on
50
- # params
51
- def deploy_package_repo(path, name, version)
52
- raise "Package repo cannot be deployed on #{self}; the platform is not supported"
53
- end
54
-
55
- #Examine the host system to determine the architecture
56
- #@return [Boolean] true if x86_64, false otherwise
44
+ # Examine the host system to determine the architecture
45
+ # @return [Boolean] true if x86_64, false otherwise
57
46
  def determine_if_x86_64
58
47
  result = exec(Beaker::Command.new("uname -a | grep x86_64"), :expect_all_exit_codes => true)
59
48
  result.exit_code == 0
60
49
  end
61
-
62
- # Gets the path & file name for the puppet agent dev package on OSX
63
- #
64
- # @param [String] puppet_collection Name of the puppet collection to use
65
- # @param [String] puppet_agent_version Version of puppet agent to get
66
- # @param [Hash{Symbol=>String}] opts Options hash to provide extra values
67
- #
68
- # @note OSX does require :download_url to be set on the opts argument
69
- # in order to check for builds on the builds server
70
- #
71
- # @raise [ArgumentError] If one of the two required parameters (puppet_collection,
72
- # puppet_agent_version) is either not passed or set to nil
73
- #
74
- # @return [String, String] Path to the directory and filename of the package, respectively
75
- def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} )
76
- error_message = "Must provide %s argument to get puppet agent dev package information"
77
- raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
78
- raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version
79
- raise ArgumentError, error_message % "opts[:download_url]" unless opts[:download_url]
80
-
81
- variant, version, arch, codename = self['platform'].to_array
82
-
83
- mac_pkg_name = "puppet-agent-#{puppet_agent_version}"
84
- version = version[0,2] + '.' + version[2,2] unless version.include?(".")
85
- # newest hotness
86
- path_chunk = "apple/#{version}/#{puppet_collection}/#{arch}"
87
- release_path_end = path_chunk
88
- # moved to doing this when 'el capitan' came out & the objection was
89
- # raised that the code name wasn't a fact, & as such can be hard to script
90
- # example: puppet-agent-0.1.0-1.osx10.9.dmg
91
- release_file = "#{mac_pkg_name}-1.osx#{version}.dmg"
92
- if not link_exists?("#{opts[:download_url]}/#{release_path_end}/#{release_file}") # new hotness
93
- # little older change involved the code name as only difference from above
94
- # example: puppet-agent-0.1.0-1.mavericks.dmg
95
- release_file = "#{mac_pkg_name}-1.#{codename}.dmg"
96
- end
97
- if not link_exists?("#{opts[:download_url]}/#{release_path_end}/#{release_file}") # oops, try the old stuff
98
- release_path_end = "apple/#{puppet_collection}"
99
- # example: puppet-agent-0.1.0-osx-10.9-x86_64.dmg
100
- release_file = "#{mac_pkg_name}-#{variant}-#{version}-x86_64.dmg"
101
- end
102
- return release_path_end, release_file
103
- end
104
-
105
- # Gets host-specific information for PE promoted puppet-agent packages
106
- #
107
- # @param [String] puppet_collection Name of the puppet collection to use
108
- # @param [Hash{Symbol=>String}] opts Options hash to provide extra values
109
- #
110
- # @return [String, String, String] Host-specific information for packages
111
- # 1. release_path_end Suffix for the release_path. Used on Windows. Check
112
- # {Windows::Pkg#pe_puppet_agent_promoted_package_info} to see usage.
113
- # 2. release_file Path to the file on release build servers
114
- # 3. download_file Filename for the package itself
115
- def pe_puppet_agent_promoted_package_info( puppet_collection = nil, opts = {} )
116
- error_message = "Must provide %s argument to get puppet agent dev package information"
117
- raise ArgumentError, error_message % "puppet_collection" unless puppet_collection
118
-
119
- variant, version, arch, codename = self['platform'].to_array
120
- release_file = "/repos/apple/#{version}/#{puppet_collection}/#{arch}/puppet-agent-*"
121
-
122
- # macOS puppet-agent tarballs haven't always included arch
123
- agent_version = opts[:puppet_agent_version]
124
- agent_version_f = agent_version&.to_f
125
-
126
- download_file = if agent_version_f.nil? || (agent_version_f < 6.28 || (agent_version_f >= 7.0 && agent_version_f < 7.18))
127
- "puppet-agent-#{variant}-#{version}.tar.gz"
128
- else
129
- "puppet-agent-#{variant}-#{version}-#{arch}.tar.gz"
130
- end
131
-
132
- return '', release_file, download_file
133
- end
134
-
135
- # Installs a given PE promoted package on a host
136
- #
137
- # @param [String] onhost_copy_base Base copy directory on the host
138
- # @param [String] onhost_copied_download Downloaded file path on the host
139
- # @param [String] onhost_copied_file Copied file path once un-compressed
140
- # @param [String] download_file File name of the downloaded file
141
- # @param [Hash{Symbol=>String}] opts additional options
142
- #
143
- # @return nil
144
- def pe_puppet_agent_promoted_package_install(
145
- onhost_copy_base, onhost_copied_download, onhost_copied_file, download_file, opts
146
- )
147
- execute("tar -zxvf #{onhost_copied_download} -C #{onhost_copy_base}")
148
- # move to better location
149
- execute("mv #{onhost_copied_file}.dmg .")
150
- self.install_package("puppet-agent-*")
151
- end
152
-
153
50
  end
@@ -6,11 +6,11 @@ module Mac::User
6
6
  # @param [Proc] block Additional actions or insertions
7
7
  #
8
8
  # @return [Array<String>] The list of user names on the system
9
- def user_list(&block)
9
+ def user_list
10
10
  execute('dscacheutil -q user') do |result|
11
11
  users = []
12
12
  result.stdout.each_line do |line|
13
- users << line.split(': ')[1].strip if line =~ /^name:/
13
+ users << line.split(': ')[1].strip if /^name:/.match?(line)
14
14
  end
15
15
 
16
16
  yield result if block_given?
@@ -31,9 +31,9 @@ module Mac::User
31
31
  # @return [Result] User information in /etc/passwd format
32
32
  # @raise [FailTest] Raises an Assertion failure if it can't find the name
33
33
  # queried for in the returned block
34
- def user_get(name, &block)
34
+ def user_get(name)
35
35
  execute("id -P #{name}") do |result|
36
- fail_test "failed to get user #{name}" unless result.stdout =~ /^#{name}:/
36
+ fail_test "failed to get user #{name}" unless /^#{name}:/.match?(result.stdout)
37
37
 
38
38
  yield result if block_given?
39
39
  result
@@ -44,17 +44,17 @@ module Mac::User
44
44
  #
45
45
  # @param [String] name Name of the user
46
46
  # @param [Proc] block Additional actions or insertions
47
- def user_present(name, &block)
47
+ def user_present(name)
48
48
  user_exists = false
49
49
  execute("dscacheutil -q user -a name #{name}") do |result|
50
- user_exists = result.stdout =~ /^name: #{name}/
50
+ user_exists = result.stdout.start_with?("name: #{name}")
51
51
  end
52
52
 
53
53
  return if user_exists
54
54
 
55
55
  uid = uid_next
56
56
  gid = gid_next
57
- create_cmd = "dscl . create /Users/#{name}"
57
+ create_cmd = "dscl . create /Users/#{name}"
58
58
  create_cmd << " && dscl . create /Users/#{name} NFSHomeDirectory /Users/#{name}"
59
59
  create_cmd << " && dscl . create /Users/#{name} UserShell /bin/bash"
60
60
  create_cmd << " && dscl . create /Users/#{name} UniqueID #{uid}"
@@ -1,11 +1,10 @@
1
- [ 'host', 'command_factory', 'command', 'options' ].each do |lib|
1
+ %w[host command_factory command options].each do |lib|
2
2
  require "beaker/#{lib}"
3
3
  end
4
4
 
5
5
  module Mac
6
- class Host < Unix::Host
7
-
8
- [ 'exec', 'user', 'group', 'pkg' ].each do |lib|
6
+ class Host < Unix::Host
7
+ %w[exec user group pkg].each do |lib|
9
8
  require "beaker/host/mac/#{lib}"
10
9
  end
11
10
 
@@ -17,18 +16,18 @@ module Mac
17
16
  def platform_defaults
18
17
  h = Beaker::Options::OptionsHash.new
19
18
  h.merge({
20
- 'user' => 'root',
21
- 'group' => 'root',
22
- 'pathseparator' => ':',
23
- })
19
+ 'user' => 'root',
20
+ 'group' => 'root',
21
+ 'pathseparator' => ':',
22
+ })
24
23
  end
25
24
 
26
25
  attr_reader :external_copy_base
26
+
27
27
  def initialize name, host_hash, options
28
28
  super
29
29
 
30
30
  @external_copy_base = '/var/root'
31
31
  end
32
-
33
32
  end
34
33
  end