beaker-hostgenerator 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,9 +29,7 @@ module BeakerHostGenerator
29
29
 
30
30
  tokens.each do |token|
31
31
  if is_ostype_token?(token, bhg_version)
32
- if nodeid[ostype] == 1 and ostype != nil
33
- raise "Error: no nodes generated for #{ostype}"
34
- end
32
+ raise "Error: no nodes generated for #{ostype}" if nodeid[ostype] == 1 and !ostype.nil?
35
33
 
36
34
  ostype = token
37
35
  next
@@ -52,7 +50,7 @@ module BeakerHostGenerator
52
50
  # Delegate to the hypervisor
53
51
  hypervisor = BeakerHostGenerator::Hypervisor.create(node_info, options)
54
52
  host_config = hypervisor.generate_node(node_info, host_config, bhg_version)
55
- config['CONFIG'].deeper_merge!(hypervisor.global_config())
53
+ config['CONFIG'].deeper_merge!(hypervisor.global_config)
56
54
 
57
55
  # Merge in any arbitrary key-value host settings. Treat the 'hostname'
58
56
  # setting specially, and don't merge it in as an arbitrary setting.
@@ -61,7 +59,7 @@ module BeakerHostGenerator
61
59
  arbitrary_settings.has_key?('hostname')
62
60
  host_config.merge!(arbitrary_settings)
63
61
 
64
- if PE_USE_WIN32 && ostype =~ /windows/ && node_info['bits'] == "64"
62
+ if PE_USE_WIN32 && ostype =~ /windows/ && node_info['bits'] == '64'
65
63
  host_config['ruby_arch'] = 'x86'
66
64
  host_config['install_32'] = true
67
65
  end
@@ -77,9 +75,7 @@ module BeakerHostGenerator
77
75
  decoded = prepare(options[:global_config])
78
76
  # Support for strings without '{}' was introduced, so just double
79
77
  # check here to ensure that we pass in values surrounded by '{}'.
80
- if !decoded.start_with?('{')
81
- decoded = "{#{decoded}}"
82
- end
78
+ decoded = "{#{decoded}}" unless decoded.start_with?('{')
83
79
  global_config = settings_string_to_map(decoded)
84
80
  config['CONFIG'].deeper_merge!(global_config)
85
81
  end
@@ -87,7 +83,7 @@ module BeakerHostGenerator
87
83
  # Munge non-string scalar values into proper data types
88
84
  unstringify_values!(config)
89
85
 
90
- return config
86
+ config
91
87
  end
92
88
 
93
89
  def get_host_roles(node_info)
@@ -101,22 +97,22 @@ module BeakerHostGenerator
101
97
  roles << role
102
98
  end
103
99
 
104
- return roles
100
+ roles
105
101
  end
106
102
 
107
103
  private
108
104
 
109
105
  def generate_host_roles!(host_config, node_info, options)
110
- if not options[:disable_default_role]
111
- host_config['roles'] = ['agent']
112
- else
113
- host_config['roles'] = []
114
- end
106
+ host_config['roles'] = if options[:disable_default_role]
107
+ []
108
+ else
109
+ ['agent']
110
+ end
115
111
 
116
112
  host_config['roles'].concat get_host_roles(node_info)
117
113
  host_config['roles'].uniq!
118
114
 
119
- if not options[:disable_role_config]
115
+ unless options[:disable_role_config]
120
116
  host_config['roles'].each do |role|
121
117
  host_config.deeper_merge! get_role_config(role)
122
118
  end
@@ -145,12 +141,16 @@ module BeakerHostGenerator
145
141
  # converted to true/false.
146
142
  # The only valid boolean-strings are "true" and "false".
147
143
  def unstringify_value(value)
148
- result = Integer(value) rescue value
144
+ result = begin
145
+ Integer(value)
146
+ rescue StandardError
147
+ value
148
+ end
149
149
  if value == 'true'
150
150
  result = true
151
151
  elsif value == 'false'
152
152
  result = false
153
- elsif value.kind_of?(Array)
153
+ elsif value.is_a?(Array)
154
154
  value.each_with_index do |v, i|
155
155
  result[i] = unstringify_value(v)
156
156
  end
@@ -24,7 +24,7 @@ module BeakerHostGenerator
24
24
 
25
25
  case node_info['ostype']
26
26
  when /^(almalinux|centos|redhat|rocky)/
27
- base_config['template'] ||= base_config['platform'].gsub(/^el/, $1)
27
+ base_config['template'] ||= base_config['platform'].gsub(/^el/, ::Regexp.last_match(1))
28
28
  when /^fedora/
29
29
  base_config['template'] ||= base_config['platform']
30
30
  when /^ubuntu/
@@ -23,9 +23,7 @@ module BeakerHostGenerator
23
23
  base_config['image'].sub!(/(\w+)/, 'almalinux')
24
24
  end
25
25
 
26
- if node_info['bits'] == '64'
27
- base_config['image'] = "amd64/#{base_config['image']}"
28
- end
26
+ base_config['image'] = "amd64/#{base_config['image']}" if node_info['bits'] == '64'
29
27
 
30
28
  case node_info['ostype']
31
29
  when /^ubuntu/
@@ -37,7 +35,7 @@ module BeakerHostGenerator
37
35
  ]
38
36
  end
39
37
 
40
- return base_generate_node(node_info, base_config, bhg_version, :docker)
38
+ base_generate_node(node_info, base_config, bhg_version, :docker)
41
39
  end
42
40
  end
43
41
  end
@@ -11,14 +11,14 @@ module BeakerHostGenerator
11
11
  # ostype is ubuntu2204, debian10, rocky9
12
12
  os, version = node_info['ostype'].split(/(\D+)/).reject!(&:empty?)
13
13
  base_config['image'] = case os
14
- when 'ubuntu'
15
- "#{os}-#{version[0, 2]}.#{version[2, 2]}"
16
- when 'centos'
17
- version.to_i == 7 ? "#{os}-#{version}" : "#{os}-stream-#{version}"
18
- else
19
- "#{os}-#{version}"
20
- end
21
- return base_generate_node(node_info, base_config, bhg_version, :hcloud)
14
+ when 'ubuntu'
15
+ "#{os}-#{version[0, 2]}.#{version[2, 2]}"
16
+ when 'centos'
17
+ version.to_i == 7 ? "#{os}-#{version}" : "#{os}-stream-#{version}"
18
+ else
19
+ "#{os}-#{version}"
20
+ end
21
+ base_generate_node(node_info, base_config, bhg_version, :hcloud)
22
22
  end
23
23
  end
24
24
  end
@@ -7,7 +7,7 @@ module BeakerHostGenerator::Hypervisor
7
7
  include BeakerHostGenerator::Data
8
8
 
9
9
  def generate_node(node_info, base_config, bhg_version)
10
- return base_generate_node(node_info, base_config, bhg_version, :general)
10
+ base_generate_node(node_info, base_config, bhg_version, :general)
11
11
  end
12
12
  end
13
13
  end
@@ -8,18 +8,18 @@ module BeakerHostGenerator
8
8
  include BeakerHostGenerator::Data
9
9
 
10
10
  def generate_node(node_info, base_config, bhg_version)
11
- if node_info['ostype'] =~ /^centos/
12
- base_config['box'] = node_info['ostype'].sub(/(\d)/, '/\1')
13
- elsif node_info['ostype'] =~ /^fedora/
14
- base_config['box'] = node_info['ostype'].sub(/(\d)/, '/\1') + '-cloud-base'
15
- else
16
- base_config['box'] = "generic/#{node_info['ostype']}"
17
- end
11
+ base_config['box'] = if node_info['ostype'] =~ /^centos/
12
+ node_info['ostype'].sub(/(\d)/, '/\1')
13
+ elsif node_info['ostype'] =~ /^fedora/
14
+ node_info['ostype'].sub(/(\d)/, '/\1') + '-cloud-base'
15
+ else
16
+ "generic/#{node_info['ostype']}"
17
+ end
18
18
 
19
19
  # We don't use this by default
20
20
  base_config['synced_folder'] = 'disabled'
21
21
 
22
- return base_generate_node(node_info, base_config, bhg_version, :vagrant)
22
+ base_generate_node(node_info, base_config, bhg_version, :vagrant)
23
23
  end
24
24
  end
25
25
  end
@@ -19,7 +19,7 @@ module BeakerHostGenerator
19
19
 
20
20
  case node_info['ostype']
21
21
  when /^(almalinux|centos|redhat|rocky)/
22
- base_config['template'] ||= base_config['platform'].gsub(/^el/, $1)
22
+ base_config['template'] ||= base_config['platform'].gsub(/^el/, ::Regexp.last_match(1))
23
23
  when /^fedora/
24
24
  base_config['template'] ||= base_config['platform']
25
25
  when /^ubuntu/
@@ -28,14 +28,12 @@ module BeakerHostGenerator
28
28
  'x86_64'
29
29
  when '32'
30
30
  'i386'
31
- else
32
- nil
33
31
  end
34
32
 
35
33
  base_config['template'] ||= "#{node_info['ostype'].sub('ubuntu', 'ubuntu-')}-#{arch}" if arch
36
34
  end
37
35
 
38
- return base_config
36
+ base_config
39
37
  end
40
38
  end
41
39
  end
@@ -37,7 +37,7 @@ module BeakerHostGenerator
37
37
  #
38
38
  # @returns [Hash{String=>Hypervisor::Interface}] A map of hypervisor names
39
39
  # and their implementations.
40
- def self.builtin_hypervisors()
40
+ def self.builtin_hypervisors
41
41
  {
42
42
  'vmpooler' => BeakerHostGenerator::Hypervisor::Vmpooler,
43
43
  'vagrant' => BeakerHostGenerator::Hypervisor::Vagrant,
@@ -60,7 +60,7 @@ module BeakerHostGenerator
60
60
  # This will only be called if the hypervisor is used for a node, in which
61
61
  # case the returned map will be merged in with global configuration from
62
62
  # other hypervisors.
63
- def global_config()
63
+ def global_config
64
64
  {}
65
65
  end
66
66
 
@@ -84,7 +84,7 @@ module BeakerHostGenerator
84
84
  #
85
85
  # @param [Integer] bhg_version The version of OS info to use when building
86
86
  # up the node definition.
87
- def generate_node(node_info, base_config, bhg_version)
87
+ def generate_node(_node_info, _base_config, _bhg_version)
88
88
  raise "Method 'generate_node' not implemented!"
89
89
  end
90
90
 
@@ -98,7 +98,7 @@ module BeakerHostGenerator
98
98
 
99
99
  base_config['hypervisor'] = @name
100
100
 
101
- return base_config
101
+ base_config
102
102
  end
103
103
  end
104
104
  end
@@ -62,7 +62,7 @@ module BeakerHostGenerator
62
62
  # * agent
63
63
  # * database
64
64
  #
65
- NODE_REGEX = /\A(?<bits>[A-Z0-9]+|\d+)((?<arbitrary_roles>([[:lower:]_]*|\,)*)\.)?(?<roles>[uacldfm]*)(?<host_settings>\{[[:print:]]*\})?\Z/
65
+ NODE_REGEX = /\A(?<bits>[A-Z0-9]+|\d+)((?<arbitrary_roles>([[:lower:]_]*|,)*)\.)?(?<roles>[uacldfm]*)(?<host_settings>\{[[:print:]]*\})?\Z/
66
66
 
67
67
  module_function
68
68
 
@@ -137,13 +137,7 @@ module BeakerHostGenerator
137
137
  # @param [Integer] bhg_version The version of OS info to use when testing
138
138
  # for whether the token represent an OS platform.
139
139
  def is_ostype_token?(token, bhg_version)
140
- BeakerHostGenerator::Data.get_platforms(bhg_version).each do |platform|
141
- ostype = platform.split('-')[0]
142
- if ostype == token
143
- return true
144
- end
145
- end
146
- return false
140
+ BeakerHostGenerator::Data.get_platforms(bhg_version).any? { |platform| platform.split('-')[0] == token }
147
141
  end
148
142
 
149
143
  # Converts a string token that represents a node (and not an OS type) into
@@ -168,28 +162,20 @@ module BeakerHostGenerator
168
162
  node_info = NODE_REGEX.match(token)
169
163
 
170
164
  if node_info
171
- node_info = Hash[node_info.names.zip(node_info.captures)]
165
+ node_info = node_info.names.zip(node_info.captures).to_h
172
166
  else
173
167
  raise BeakerHostGenerator::Exceptions::InvalidNodeSpecError.new,
174
168
  "Invalid node_info token: #{token}"
175
169
  end
170
+ node_info['arbitrary_roles'] = if node_info['arbitrary_roles']
171
+ node_info['arbitrary_roles'].split(',') || ''
172
+ else
173
+ # Default to empty list to avoid having to check for nil elsewhere
174
+ []
175
+ end
176
+ node_info['host_settings'] = node_info['host_settings'] ? settings_string_to_map(node_info['host_settings']) : {}
176
177
 
177
- if node_info['arbitrary_roles']
178
- node_info['arbitrary_roles'] =
179
- node_info['arbitrary_roles'].split(',') || ''
180
- else
181
- # Default to empty list to avoid having to check for nil elsewhere
182
- node_info['arbitrary_roles'] = []
183
- end
184
-
185
- if node_info['host_settings']
186
- node_info['host_settings'] =
187
- settings_string_to_map(node_info['host_settings'])
188
- else
189
- node_info['host_settings'] = {}
190
- end
191
-
192
- return node_info
178
+ node_info
193
179
  end
194
180
 
195
181
  # Transforms the arbitrary host settings map from a string representation
@@ -228,7 +214,7 @@ module BeakerHostGenerator
228
214
 
229
215
  break if blob.nil?
230
216
 
231
- if stringscan.pos() == 1
217
+ if stringscan.pos == 1
232
218
  object = {}
233
219
  object_depth.push(object)
234
220
  next
@@ -251,7 +237,7 @@ module BeakerHostGenerator
251
237
  next
252
238
  end
253
239
 
254
- if blob == ']' or blob == '}'
240
+ if [']', '}'].include?(blob)
255
241
  object_depth.pop
256
242
  current_depth = current_depth.pred
257
243
  next
@@ -263,11 +249,11 @@ module BeakerHostGenerator
263
249
  if blob[-2] == '='
264
250
  raise Beaker::HostGenerator::Exceptions::InvalidNodeSpecError unless blob.end_with?('{', '[')
265
251
 
266
- if blob[-1] == '{'
267
- current_object[blob[0..-3]] = {}
268
- else
269
- current_object[blob[0..-3]] = []
270
- end
252
+ current_object[blob[0..-3]] = if blob[-1] == '{'
253
+ {}
254
+ else
255
+ []
256
+ end
271
257
  object_depth.push(current_object[blob[0..-3]])
272
258
  current_depth = current_depth.next
273
259
  next
@@ -288,9 +274,7 @@ module BeakerHostGenerator
288
274
  next
289
275
  end
290
276
 
291
- if blob == ','
292
- next
293
- end
277
+ next if blob == ','
294
278
 
295
279
  if blob[-1] == ','
296
280
  if current_type == Hash
@@ -308,18 +292,18 @@ module BeakerHostGenerator
308
292
  end
309
293
  end
310
294
 
311
- if blob[-1] == ']'
312
- current_object.push(blob[0..-2])
313
- object_depth.pop
314
- current_depth = current_depth.pred
315
- next
316
- end
295
+ next unless blob[-1] == ']'
296
+
297
+ current_object.push(blob[0..-2])
298
+ object_depth.pop
299
+ current_depth = current_depth.pred
300
+ next
317
301
  end
318
302
 
319
303
  object
320
304
  rescue Exception
321
305
  raise BeakerHostGenerator::Exceptions::InvalidNodeSpecError,
322
- "Malformed host settings: #{host_settings}"
306
+ "Malformed host settings: #{host_settings}"
323
307
  end
324
308
  end
325
309
  end
@@ -11,10 +11,9 @@ module BeakerHostGenerator
11
11
  }
12
12
 
13
13
  CM_CONFIG = { 'main' => {
14
- 'dns_alt_names' => 'puppet',
15
- 'environmentpath' => '/etc/puppetlabs/puppet/environments',
16
- },
17
- }
14
+ 'dns_alt_names' => 'puppet',
15
+ 'environmentpath' => '/etc/puppetlabs/puppet/environments',
16
+ } }
18
17
 
19
18
  ROLE_CONFIG = {
20
19
  'compile_master' => CM_CONFIG,
@@ -7,7 +7,7 @@ module BeakerHostGenerator
7
7
  module Utils
8
8
  module_function
9
9
 
10
- def pe_dir(version, family = nil)
10
+ def pe_dir(version, _family = nil)
11
11
  BeakerHostGenerator::Data.pe_dir(version)
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ module BeakerHostGenerator
15
15
  vmpooler_hypervisor = BeakerHostGenerator::Hypervisor::Vmpooler.new
16
16
  config = {}
17
17
  config.deeper_merge! BeakerHostGenerator::Data.BASE_CONFIG
18
- config['CONFIG'].deeper_merge! vmpooler_hypervisor.global_config()
18
+ config['CONFIG'].deeper_merge! vmpooler_hypervisor.global_config
19
19
 
20
20
  hosts.each do |host|
21
21
  config['HOSTS'][host.node_name] = {
@@ -25,12 +25,10 @@ module BeakerHostGenerator
25
25
  }
26
26
  end
27
27
 
28
- File.open(path, 'w') do |file|
29
- file.write(config.to_yaml)
30
- end
28
+ File.write(path, config.to_yaml)
31
29
  end
32
30
 
33
- def get_platforms(hypervisor_type = 'vmpooler', bhg_version = 0)
31
+ def get_platforms(_hypervisor_type = 'vmpooler', bhg_version = 0)
34
32
  BeakerHostGenerator::Data.get_platforms(bhg_version)
35
33
  end
36
34
 
@@ -1,5 +1,5 @@
1
1
  module BeakerHostGenerator
2
2
  module Version
3
- STRING = '2.1.0'
3
+ STRING = '2.2.0'
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # Load libraries.
2
2
 
3
3
  module BeakerHostGenerator
4
- require 'beaker-hostgenerator/cli'
5
- require 'beaker-hostgenerator/data'
6
- require 'beaker-hostgenerator/generator'
4
+ require 'beaker-hostgenerator/cli'
5
+ require 'beaker-hostgenerator/data'
6
+ require 'beaker-hostgenerator/generator'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-hostgenerator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Branan Purvine-Riley
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-05-02 00:00:00.000000000 Z
14
+ date: 2023-05-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fakefs
@@ -37,16 +37,16 @@ dependencies:
37
37
  name: minitest
38
38
  requirement: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ">="
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '0'
42
+ version: '5.18'
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '0'
49
+ version: '5.18'
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: pry
52
52
  requirement: !ruby/object:Gem::Requirement
@@ -93,44 +93,16 @@ dependencies:
93
93
  name: rspec-its
94
94
  requirement: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- type: :development
100
- prerelease: false
101
- version_requirements: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- - !ruby/object:Gem::Dependency
107
- name: thin
108
- requirement: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
- type: :development
114
- prerelease: false
115
- version_requirements: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- - !ruby/object:Gem::Dependency
121
- name: yard
122
- requirement: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - ">="
96
+ - - "~>"
125
97
  - !ruby/object:Gem::Version
126
- version: '0'
98
+ version: '1.3'
127
99
  type: :development
128
100
  prerelease: false
129
101
  version_requirements: !ruby/object:Gem::Requirement
130
102
  requirements:
131
- - - ">="
103
+ - - "~>"
132
104
  - !ruby/object:Gem::Version
133
- version: '0'
105
+ version: '1.3'
134
106
  - !ruby/object:Gem::Dependency
135
107
  name: deep_merge
136
108
  requirement: !ruby/object:Gem::Requirement
@@ -193,7 +165,7 @@ files:
193
165
  - lib/beaker-hostgenerator/version.rb
194
166
  homepage: https://github.com/puppetlabs/beaker-hostgenerator
195
167
  licenses:
196
- - Apache2
168
+ - Apache-2.0
197
169
  metadata: {}
198
170
  post_install_message:
199
171
  rdoc_options: []