Skip to content

Commit

Permalink
more safe corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasAud committed Jan 17, 2024
1 parent 18566db commit 265ce67
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 43 deletions.
18 changes: 0 additions & 18 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ Style/CollectionCompact:
Exclude:
- 'tasks/vagrant.rb'

# Offense count: 14
# This cop supports safe autocorrection (--autocorrect).
Style/FileWrite:
Exclude:
- 'tasks/abs.rb'
- 'tasks/docker.rb'
- 'tasks/docker_exp.rb'
- 'tasks/provision_service.rb'
- 'tasks/update_node_pp.rb'
- 'tasks/update_site_pp.rb'
- 'tasks/vagrant.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods.
Expand All @@ -117,12 +105,6 @@ Style/MixinUsage:
- 'tasks/docker_exp.rb'
- 'tasks/vagrant.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/NegatedIfElseCondition:
Exclude:
- 'tasks/docker.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Methods.
Expand Down
4 changes: 2 additions & 2 deletions tasks/abs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def provision(platform, inventory_location, vars)
add_node_to_group(inventory_hash, node, group_name)
end

File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
File.write(inventory_full_path, inventory_hash.to_yaml)
{ status: 'ok', nodes: data.length }
end

Expand Down Expand Up @@ -147,7 +147,7 @@ def tear_down(node_name, inventory_location)
targets_to_remove.each do |target|
remove_node(inventory_hash, target)
end
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
File.write(inventory_full_path, inventory_hash.to_yaml)
{ status: 'ok', removed: targets_to_remove }
end

Expand Down
10 changes: 5 additions & 5 deletions tasks/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def fix_ssh(distro, version, container)
# https://bugzilla.redhat.com/show_bug.cgi?id=1728777
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}

if !%r{^(7|8|9|2)}.match?(version)
run_local_command("docker exec #{container} service sshd restart")
else
if %r{^(7|8|9|2)}.match?(version)
run_local_command("docker exec #{container} /usr/sbin/sshd")
else
run_local_command("docker exec #{container} service sshd restart")
end
when %r{sles}
run_local_command("docker exec #{container} /usr/sbin/sshd")
Expand Down Expand Up @@ -207,7 +207,7 @@ def provision(image, inventory_location, vars)
install_ssh_components(distro, version, full_container_name)
fix_ssh(distro, version, full_container_name)
add_node_to_group(inventory_hash, node, group_name)
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
File.write(inventory_full_path, inventory_hash.to_yaml)
{ status: 'ok', node_name: "#{hostname}:#{front_facing_port}", node: node }
end

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

Expand Down
4 changes: 2 additions & 2 deletions tasks/docker_exp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def provision(docker_platform, inventory_location, vars)

group_name = 'docker_nodes'
add_node_to_group(inventory_hash, node, group_name)
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
File.write(inventory_full_path, inventory_hash.to_yaml)
{ status: 'ok', node_name: container_id, node: node }
end

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

Expand Down
12 changes: 3 additions & 9 deletions tasks/provision_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ def invoke_cloud_request(params, uri, job_url, verb, retry_attempts)
raise StandardError "Unknown verb: '#{verb}'"
end

if job_url
File.open('request.json', 'wb') do |f|
f.write(request.body)
end
end
File.binwrite('request.json', request.body) if job_url

req_options = {
use_ssl: uri.scheme == 'https',
Expand Down Expand Up @@ -134,12 +130,10 @@ def provision(platform, inventory_location, vars, retry_attempts)
g['targets'] = g['targets'] + bg['targets'] if g['name'] == bg['name']
end
end
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
File.write(inventory_full_path, inventory_hash.to_yaml)
else
FileUtils.mkdir_p(File.join(Dir.pwd, '/spec/fixtures'))
File.open(inventory_full_path, 'wb') do |f|
f.write(YAML.dump(response_hash))
end
File.binwrite(inventory_full_path, YAML.dump(response_hash))
end

{
Expand Down
2 changes: 1 addition & 1 deletion tasks/update_node_pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def update_file(manifest, target_node)
else
final_manifest = "node '#{target_node}' \n{\n #{manifest} \n}"
end
File.open(site_path, 'w+') { |f| f.write(final_manifest) }
File.write(site_path, final_manifest)
"#{site_path} updated"
end

Expand Down
2 changes: 1 addition & 1 deletion tasks/update_site_pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def update_file(manifest)
raise Puppet::Error, "stderr: ' %{stderr}')" % { stderr: stderr } if status != 0

site_path = File.join(path, 'site.pp')
File.open(site_path, 'w+') { |f| f.write(manifest) }
File.write(site_path, manifest)
'site.pp updated'
end

Expand Down
8 changes: 3 additions & 5 deletions tasks/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def generate_vagrantfile(file_path, platform, enable_synced_folder, provider, cp
#{provider_config_block}
end
VF
File.open(file_path, 'w') do |f|
f.write(vf)
end
File.write(file_path, vf)
end

def get_vagrant_dir(platform, vagrant_dirs, int = 0)
Expand Down Expand Up @@ -187,7 +185,7 @@ def provision(platform, inventory_location, enable_synced_folder, provider, cpus
group_name = 'winrm_nodes'
end
add_node_to_group(inventory_hash, node, group_name)
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
File.write(inventory_full_path, inventory_hash.to_yaml)
{ status: 'ok', node_name: node_name, node: node }
end

Expand All @@ -203,7 +201,7 @@ def tear_down(node_name, inventory_location)
FileUtils.rm_r(vagrant_env)
end
warn "Removed #{node_name}"
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }
File.write(inventory_full_path, inventory_hash.to_yaml)
{ status: 'ok' }
end

Expand Down

0 comments on commit 265ce67

Please sign in to comment.