Skip to content

Commit 9930f92

Browse files
committed
correcting more safe offenses
1 parent 18566db commit 9930f92

File tree

8 files changed

+18
-50
lines changed

8 files changed

+18
-50
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,6 @@ Style/CollectionCompact:
8989
Exclude:
9090
- 'tasks/vagrant.rb'
9191

92-
# Offense count: 14
93-
# This cop supports safe autocorrection (--autocorrect).
94-
Style/FileWrite:
95-
Exclude:
96-
- 'tasks/abs.rb'
97-
- 'tasks/docker.rb'
98-
- 'tasks/docker_exp.rb'
99-
- 'tasks/provision_service.rb'
100-
- 'tasks/update_node_pp.rb'
101-
- 'tasks/update_site_pp.rb'
102-
- 'tasks/vagrant.rb'
103-
10492
# Offense count: 1
10593
# This cop supports unsafe autocorrection (--autocorrect-all).
10694
# Configuration parameters: AllowedMethods.
@@ -117,21 +105,9 @@ Style/MixinUsage:
117105
- 'tasks/docker_exp.rb'
118106
- 'tasks/vagrant.rb'
119107

120-
# Offense count: 1
121-
# This cop supports safe autocorrection (--autocorrect).
122-
Style/NegatedIfElseCondition:
123-
Exclude:
124-
- 'tasks/docker.rb'
125-
126108
# Offense count: 1
127109
# This cop supports unsafe autocorrection (--autocorrect-all).
128110
# Configuration parameters: Methods.
129111
Style/RedundantArgument:
130112
Exclude:
131113
- 'tasks/update_node_pp.rb'
132-
133-
# Offense count: 2
134-
# This cop supports safe autocorrection (--autocorrect).
135-
Style/RedundantStringEscape:
136-
Exclude:
137-
- 'tasks/vagrant.rb'

tasks/abs.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def provision(platform, inventory_location, vars)
113113
add_node_to_group(inventory_hash, node, group_name)
114114
end
115115

116-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
116+
File.write(inventory_full_path, inventory_hash.to_yaml)
117117
{ status: 'ok', nodes: data.length }
118118
end
119119

@@ -147,7 +147,7 @@ def tear_down(node_name, inventory_location)
147147
targets_to_remove.each do |target|
148148
remove_node(inventory_hash, target)
149149
end
150-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
150+
File.write(inventory_full_path, inventory_hash.to_yaml)
151151
{ status: 'ok', removed: targets_to_remove }
152152
end
153153

tasks/docker.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def fix_ssh(distro, version, container)
7474
# https://bugzilla.redhat.com/show_bug.cgi?id=1728777
7575
run_local_command("docker exec #{container} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd") if distro =~ %r{redhat|centos} && version =~ %r{^7}
7676

77-
if !%r{^(7|8|9|2)}.match?(version)
78-
run_local_command("docker exec #{container} service sshd restart")
79-
else
77+
if %r{^(7|8|9|2)}.match?(version)
8078
run_local_command("docker exec #{container} /usr/sbin/sshd")
79+
else
80+
run_local_command("docker exec #{container} service sshd restart")
8181
end
8282
when %r{sles}
8383
run_local_command("docker exec #{container} /usr/sbin/sshd")
@@ -207,7 +207,7 @@ def provision(image, inventory_location, vars)
207207
install_ssh_components(distro, version, full_container_name)
208208
fix_ssh(distro, version, full_container_name)
209209
add_node_to_group(inventory_hash, node, group_name)
210-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
210+
File.write(inventory_full_path, inventory_hash.to_yaml)
211211
{ status: 'ok', node_name: "#{hostname}:#{front_facing_port}", node: node }
212212
end
213213

@@ -222,7 +222,7 @@ def tear_down(node_name, inventory_location)
222222
run_local_command(remove_docker)
223223
remove_node(inventory_hash, node_name)
224224
puts "Removed #{node_name}"
225-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
225+
File.write(inventory_full_path, inventory_hash.to_yaml)
226226
{ status: 'ok' }
227227
end
228228

tasks/docker_exp.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def provision(docker_platform, inventory_location, vars)
3838

3939
group_name = 'docker_nodes'
4040
add_node_to_group(inventory_hash, node, group_name)
41-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
41+
File.write(inventory_full_path, inventory_hash.to_yaml)
4242
{ status: 'ok', node_name: container_id, node: node }
4343
end
4444

@@ -53,7 +53,7 @@ def tear_down(node_name, inventory_location)
5353
run_local_command(remove_docker)
5454
remove_node(inventory_hash, node_name)
5555
puts "Removed #{node_name}"
56-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
56+
File.write(inventory_full_path, inventory_hash.to_yaml)
5757
{ status: 'ok' }
5858
end
5959

tasks/provision_service.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ def invoke_cloud_request(params, uri, job_url, verb, retry_attempts)
5555
raise StandardError "Unknown verb: '#{verb}'"
5656
end
5757

58-
if job_url
59-
File.open('request.json', 'wb') do |f|
60-
f.write(request.body)
61-
end
62-
end
58+
File.binwrite('request.json', request.body) if job_url
6359

6460
req_options = {
6561
use_ssl: uri.scheme == 'https',
@@ -134,12 +130,10 @@ def provision(platform, inventory_location, vars, retry_attempts)
134130
g['targets'] = g['targets'] + bg['targets'] if g['name'] == bg['name']
135131
end
136132
end
137-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
133+
File.write(inventory_full_path, inventory_hash.to_yaml)
138134
else
139135
FileUtils.mkdir_p(File.join(Dir.pwd, '/spec/fixtures'))
140-
File.open(inventory_full_path, 'wb') do |f|
141-
f.write(YAML.dump(response_hash))
142-
end
136+
File.binwrite(inventory_full_path, YAML.dump(response_hash))
143137
end
144138

145139
{

tasks/update_node_pp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def update_file(manifest, target_node)
2121
else
2222
final_manifest = "node '#{target_node}' \n{\n #{manifest} \n}"
2323
end
24-
File.open(site_path, 'w+') { |f| f.write(final_manifest) }
24+
File.write(site_path, final_manifest)
2525
"#{site_path} updated"
2626
end
2727

tasks/update_site_pp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def update_file(manifest)
1111
raise Puppet::Error, "stderr: ' %{stderr}')" % { stderr: stderr } if status != 0
1212

1313
site_path = File.join(path, 'site.pp')
14-
File.open(site_path, 'w+') { |f| f.write(manifest) }
14+
File.write(site_path, manifest)
1515
'site.pp updated'
1616
end
1717

tasks/vagrant.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def generate_vagrantfile(file_path, platform, enable_synced_folder, provider, cp
5454
''
5555
end
5656
vf = <<~VF
57-
Vagrant.configure(\"2\") do |config|
57+
Vagrant.configure("2") do |config|
5858
config.vm.box = '#{platform}'
5959
config.vm.boot_timeout = 600
6060
config.ssh.insert_key = false
@@ -64,9 +64,7 @@ def generate_vagrantfile(file_path, platform, enable_synced_folder, provider, cp
6464
#{provider_config_block}
6565
end
6666
VF
67-
File.open(file_path, 'w') do |f|
68-
f.write(vf)
69-
end
67+
File.write(file_path, vf)
7068
end
7169

7270
def get_vagrant_dir(platform, vagrant_dirs, int = 0)
@@ -187,7 +185,7 @@ def provision(platform, inventory_location, enable_synced_folder, provider, cpus
187185
group_name = 'winrm_nodes'
188186
end
189187
add_node_to_group(inventory_hash, node, group_name)
190-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
188+
File.write(inventory_full_path, inventory_hash.to_yaml)
191189
{ status: 'ok', node_name: node_name, node: node }
192190
end
193191

@@ -203,7 +201,7 @@ def tear_down(node_name, inventory_location)
203201
FileUtils.rm_r(vagrant_env)
204202
end
205203
warn "Removed #{node_name}"
206-
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
204+
File.write(inventory_full_path, inventory_hash.to_yaml)
207205
{ status: 'ok' }
208206
end
209207

0 commit comments

Comments
 (0)