diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6fc52a0..6581c57 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. @@ -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. diff --git a/tasks/abs.rb b/tasks/abs.rb index 3562f84..f3b3679 100755 --- a/tasks/abs.rb +++ b/tasks/abs.rb @@ -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 @@ -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 diff --git a/tasks/docker.rb b/tasks/docker.rb index 3343cad..f5c3bd8 100755 --- a/tasks/docker.rb +++ b/tasks/docker.rb @@ -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") @@ -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 @@ -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 diff --git a/tasks/docker_exp.rb b/tasks/docker_exp.rb index 31ce40d..96876c4 100755 --- a/tasks/docker_exp.rb +++ b/tasks/docker_exp.rb @@ -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 @@ -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 diff --git a/tasks/provision_service.rb b/tasks/provision_service.rb index b0df15b..0adb5b0 100755 --- a/tasks/provision_service.rb +++ b/tasks/provision_service.rb @@ -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', @@ -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 { diff --git a/tasks/update_node_pp.rb b/tasks/update_node_pp.rb index 266e8b9..0834726 100755 --- a/tasks/update_node_pp.rb +++ b/tasks/update_node_pp.rb @@ -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 diff --git a/tasks/update_site_pp.rb b/tasks/update_site_pp.rb index e4a833f..cbcdf78 100755 --- a/tasks/update_site_pp.rb +++ b/tasks/update_site_pp.rb @@ -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 diff --git a/tasks/vagrant.rb b/tasks/vagrant.rb index 685773f..fbcf18f 100755 --- a/tasks/vagrant.rb +++ b/tasks/vagrant.rb @@ -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) @@ -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 @@ -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