From 1272343cdd963062c33f0a9cb19733269f0a6446 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 10:42:28 +1100 Subject: [PATCH 01/57] (rubocop) Fix Style/StringLiterals --- lib/vmfloaty.rb | 20 ++-- lib/vmfloaty/auth.rb | 10 +- lib/vmfloaty/errors.rb | 8 +- lib/vmfloaty/http.rb | 6 +- lib/vmfloaty/pooler.rb | 20 ++-- lib/vmfloaty/service.rb | 12 +-- lib/vmfloaty/ssh.rb | 10 +- lib/vmfloaty/utils.rb | 2 +- spec/vmfloaty/auth_spec.rb | 60 ++++++------ spec/vmfloaty/nonstandard_pooler_spec.rb | 8 +- spec/vmfloaty/pooler_spec.rb | 114 +++++++++++------------ spec/vmfloaty/utils_spec.rb | 92 +++++++++--------- 12 files changed, 181 insertions(+), 181 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 9bbe782..390d2ab 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -43,7 +43,7 @@ class Vmfloaty force = options.force if args.empty? - STDERR.puts "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs." + STDERR.puts 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.' exit 1 end @@ -53,12 +53,12 @@ class Vmfloaty large_pool_requests = os_types.select{|_,v| v > max_pool_request} if ! large_pool_requests.empty? and ! force STDERR.puts "Requesting vms over #{max_pool_request} requires a --force flag." - STDERR.puts "Try again with `floaty get --force`" + STDERR.puts 'Try again with `floaty get --force`' exit 1 end if os_types.empty? - STDERR.puts "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs." + STDERR.puts 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.' exit 1 end @@ -144,10 +144,10 @@ class Vmfloaty modify_all = options.all if hostname.nil? and !modify_all - STDERR.puts "ERROR: Provide a hostname or specify --all." + STDERR.puts 'ERROR: Provide a hostname or specify --all.' exit 1 end - running_vms = modify_all ? service.list_active(verbose) : hostname.split(",") + running_vms = modify_all ? service.list_active(verbose) : hostname.split(',') tags = options.tags ? JSON.parse(options.tags) : nil modify_hash = { @@ -171,11 +171,11 @@ class Vmfloaty end if ok if modify_all - puts "Successfully modified all VMs." + puts 'Successfully modified all VMs.' else puts "Successfully modified VM #{hostname}." end - puts "Use `floaty list --active` to see the results." + puts 'Use `floaty list --active` to see the results.' end end end @@ -205,7 +205,7 @@ class Vmfloaty if delete_all running_vms = service.list_active(verbose) if running_vms.empty? - STDERR.puts "You have no running VMs." + STDERR.puts 'You have no running VMs.' else Utils.pretty_print_hosts(verbose, service, running_vms) # Confirm deletion @@ -236,7 +236,7 @@ class Vmfloaty end end else - STDERR.puts "You did not provide any hosts to delete" + STDERR.puts 'You did not provide any hosts to delete' exit 1 end @@ -417,7 +417,7 @@ class Vmfloaty use_token = !options.notoken if args.empty? - STDERR.puts "No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs." + STDERR.puts 'No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs.' exit 1 end diff --git a/lib/vmfloaty/auth.rb b/lib/vmfloaty/auth.rb index b68e22d..7d33327 100644 --- a/lib/vmfloaty/auth.rb +++ b/lib/vmfloaty/auth.rb @@ -7,11 +7,11 @@ class Auth def self.get_token(verbose, url, user, password) conn = Http.get_conn_with_auth(verbose, url, user, password) - resp = conn.post "token" + resp = conn.post 'token' res_body = JSON.parse(resp.body) - if res_body["ok"] - return res_body["token"] + if res_body['ok'] + return res_body['token'] else raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}" end @@ -26,7 +26,7 @@ class Auth response = conn.delete "token/#{token}" res_body = JSON.parse(response.body) - if res_body["ok"] + if res_body['ok'] return res_body else raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}" @@ -43,7 +43,7 @@ class Auth response = conn.get "token/#{token}" res_body = JSON.parse(response.body) - if res_body["ok"] + if res_body['ok'] return res_body else raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}" diff --git a/lib/vmfloaty/errors.rb b/lib/vmfloaty/errors.rb index 221fa14..ee8e2cb 100644 --- a/lib/vmfloaty/errors.rb +++ b/lib/vmfloaty/errors.rb @@ -1,23 +1,23 @@ class AuthError < StandardError - def initialize(msg="Could not authenticate to pooler") + def initialize(msg='Could not authenticate to pooler') super end end class TokenError < StandardError - def initialize(msg="Could not do operation with token provided") + def initialize(msg='Could not do operation with token provided') super end end class MissingParamError < StandardError - def initialize(msg="Argument provided to function is missing") + def initialize(msg='Argument provided to function is missing') super end end class ModifyError < StandardError - def initialize(msg="Could not modify VM") + def initialize(msg='Could not modify VM') super end end diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index 656b732..f21b993 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -18,7 +18,7 @@ class Http def self.get_conn(verbose, url) if url.nil? - raise "Did not provide a url to connect to" + raise 'Did not provide a url to connect to' end unless is_url(url) @@ -36,11 +36,11 @@ class Http def self.get_conn_with_auth(verbose, url, user, password) if url.nil? - raise "Did not provide a url to connect to" + raise 'Did not provide a url to connect to' end if user.nil? - raise "You did not provide a user to authenticate with" + raise 'You did not provide a user to authenticate with' end unless is_url(url) diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index e81b4cd..8bdef2c 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -37,24 +37,24 @@ class Pooler conn.headers['X-AUTH-TOKEN'] = token end - os_string = "" + os_string = '' os_type.each do |os,num| num.times do |i| - os_string << os+"+" + os_string << os+'+' end end - os_string = os_string.chomp("+") + os_string = os_string.chomp('+') if os_string.size == 0 - raise MissingParamError, "No operating systems provided to obtain." + raise MissingParamError, 'No operating systems provided to obtain.' end response = conn.post "vm/#{os_string}" res_body = JSON.parse(response.body) - if res_body["ok"] + if res_body['ok'] res_body elsif response.status == 401 raise AuthError, "HTTP #{response.status}: The token provided could not authenticate to the pooler.\n#{res_body}" @@ -65,7 +65,7 @@ class Pooler def self.modify(verbose, url, hostname, token, modify_hash) if token.nil? - raise TokenError, "Token provided was nil. Request cannot be made to modify vm" + raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' end modify_hash.keys.each do |key| @@ -93,7 +93,7 @@ class Pooler def self.disk(verbose, url, hostname, token, disk) if token.nil? - raise TokenError, "Token provided was nil. Request cannot be made to modify vm" + raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' end conn = Http.get_conn(verbose, url) @@ -107,7 +107,7 @@ class Pooler def self.delete(verbose, url, hosts, token) if token.nil? - raise TokenError, "Token provided was nil. Request cannot be made to delete vm" + raise TokenError, 'Token provided was nil. Request cannot be made to delete vm' end conn = Http.get_conn(verbose, url) @@ -154,7 +154,7 @@ class Pooler def self.snapshot(verbose, url, hostname, token) if token.nil? - raise TokenError, "Token provided was nil. Request cannot be made to snapshot vm" + raise TokenError, 'Token provided was nil. Request cannot be made to snapshot vm' end conn = Http.get_conn(verbose, url) @@ -167,7 +167,7 @@ class Pooler def self.revert(verbose, url, hostname, token, snapshot_sha) if token.nil? - raise TokenError, "Token provided was nil. Request cannot be made to revert vm" + raise TokenError, 'Token provided was nil. Request cannot be made to revert vm' end conn = Http.get_conn(verbose, url) diff --git a/lib/vmfloaty/service.rb b/lib/vmfloaty/service.rb index b2a2333..14a8df3 100644 --- a/lib/vmfloaty/service.rb +++ b/lib/vmfloaty/service.rb @@ -31,7 +31,7 @@ class Service def user unless @config['user'] - puts "Enter your pooler service username:" + puts 'Enter your pooler service username:' @config['user'] = STDIN.gets.chomp end @config['user'] @@ -39,7 +39,7 @@ class Service def token unless @config['token'] - puts "No token found. Retrieving a token..." + puts 'No token found. Retrieving a token...' @config['token'] = get_new_token(nil) end @config['token'] @@ -47,13 +47,13 @@ class Service def get_new_token(verbose) username = user - pass = Commander::UI::password "Enter your pooler service password:", '*' + pass = Commander::UI::password 'Enter your pooler service password:', '*' Auth.get_token(verbose, url, username, pass) end def delete_token(verbose, token_value = @config['token']) username = user - pass = Commander::UI::password "Enter your pooler service password:", '*' + pass = Commander::UI::password 'Enter your pooler service password:', '*' Auth.delete_token(verbose, url, username, pass, token_value) end @@ -91,9 +91,9 @@ class Service def pretty_print_running(verbose, hostnames = []) if hostnames.empty? - puts "You have no running VMs." + puts 'You have no running VMs.' else - puts "Running VMs:" + puts 'Running VMs:' @service_object.pretty_print_hosts(verbose, hostnames, url) end end diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index 4ee4b8c..4087d3a 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -14,19 +14,19 @@ class Ssh end def self.ssh(verbose, host_os, token, url) - ssh_path = which("ssh") + ssh_path = which('ssh') if !ssh_path - raise "Could not determine path to ssh" + raise 'Could not determine path to ssh' end os_types = {} os_types[host_os] = 1 response = Pooler.retrieve(verbose, os_types, token, url) - if response["ok"] == true + if response['ok'] == true if host_os =~ /win/ - user = "Administrator" + user = 'Administrator' else - user = "root" + user = 'root' end hostname = "#{response[host_os]["hostname"]}.#{response["domain"]}" diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index b8e1a17..fca7a32 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -65,7 +65,7 @@ class Utils # ...] os_types = {} os_args.each do |arg| - os_arr = arg.split("=") + os_arr = arg.split('=') if os_arr.size == 1 # assume they didn't specify an = sign if split returns 1 size os_types[os_arr[0]] = 1 diff --git a/spec/vmfloaty/auth_spec.rb b/spec/vmfloaty/auth_spec.rb index bcd246e..8a527ed 100644 --- a/spec/vmfloaty/auth_spec.rb +++ b/spec/vmfloaty/auth_spec.rb @@ -3,67 +3,67 @@ require_relative '../../lib/vmfloaty/auth' describe Pooler do before :each do - @vmpooler_url = "https://vmpooler.example.com" + @vmpooler_url = 'https://vmpooler.example.com' end - describe "#get_token" do + describe '#get_token' do before :each do - @get_token_response = "{\"ok\": true,\"token\":\"utpg2i2xswor6h8ttjhu3d47z53yy47y\"}" - @token = "utpg2i2xswor6h8ttjhu3d47z53yy47y" + @get_token_response = '{"ok": true,"token":"utpg2i2xswor6h8ttjhu3d47z53yy47y"}' + @token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y' end - it "returns a token from vmpooler" do - stub_request(:post, "https://first.last:password@vmpooler.example.com/token"). + it 'returns a token from vmpooler' do + stub_request(:post, 'https://first.last:password@vmpooler.example.com/token'). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2'}). to_return(:status => 200, :body => @get_token_response, :headers => {}) - token = Auth.get_token(false, @vmpooler_url, "first.last", "password") + token = Auth.get_token(false, @vmpooler_url, 'first.last', 'password') expect(token).to eq @token end - it "raises a token error if something goes wrong" do - stub_request(:post, "https://first.last:password@vmpooler.example.com/token"). + it 'raises a token error if something goes wrong' do + stub_request(:post, 'https://first.last:password@vmpooler.example.com/token'). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2'}). - to_return(:status => 500, :body => "{\"ok\":false}", :headers => {}) + to_return(:status => 500, :body => '{"ok":false}', :headers => {}) - expect{ Auth.get_token(false, @vmpooler_url, "first.last", "password") }.to raise_error(TokenError) + expect{ Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError) end end - describe "#delete_token" do + describe '#delete_token' do before :each do - @delete_token_response = "{\"ok\":true}" - @token = "utpg2i2xswor6h8ttjhu3d47z53yy47y" + @delete_token_response = '{"ok":true}' + @token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y' end - it "deletes the specified token" do - stub_request(:delete, "https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). + it 'deletes the specified token' do + stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y'). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). to_return(:status => 200, :body => @delete_token_response, :headers => {}) - expect(Auth.delete_token(false, @vmpooler_url, "first.last", "password", @token)).to eq JSON.parse(@delete_token_response) + expect(Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response) end - it "raises a token error if something goes wrong" do - stub_request(:delete, "https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). + it 'raises a token error if something goes wrong' do + stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y'). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). - to_return(:status => 500, :body => "{\"ok\":false}", :headers => {}) + to_return(:status => 500, :body => '{"ok":false}', :headers => {}) - expect{ Auth.delete_token(false, @vmpooler_url, "first.last", "password", @token) }.to raise_error(TokenError) + expect{ Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError) end - it "raises a token error if no token provided" do - expect{ Auth.delete_token(false, @vmpooler_url, "first.last", "password", nil) }.to raise_error(TokenError) + it 'raises a token error if no token provided' do + expect{ Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', nil) }.to raise_error(TokenError) end end - describe "#token_status" do + describe '#token_status' do before :each do - @token_status_response = "{\"ok\":true,\"utpg2i2xswor6h8ttjhu3d47z53yy47y\":{\"created\":\"2015-04-28 19:17:47 -0700\"}}" - @token = "utpg2i2xswor6h8ttjhu3d47z53yy47y" + @token_status_response = '{"ok":true,"utpg2i2xswor6h8ttjhu3d47z53yy47y":{"created":"2015-04-28 19:17:47 -0700"}}' + @token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y' end - it "checks the status of a token" do + it 'checks the status of a token' do stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). to_return(:status => 200, :body => @token_status_response, :headers => {}) @@ -71,15 +71,15 @@ describe Pooler do expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response) end - it "raises a token error if something goes wrong" do + it 'raises a token error if something goes wrong' do stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). - to_return(:status => 500, :body => "{\"ok\":false}", :headers => {}) + to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect{ Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError) end - it "raises a token error if no token provided" do + it 'raises a token error if no token provided' do expect{ Auth.token_status(false, @vmpooler_url, nil) }.to raise_error(TokenError) end end diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 02ab9d9..7b03827 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -172,10 +172,10 @@ BODY end it 'raises an error if the user tries to modify an unsupported attribute' do - stub_request(:put, "https://nspooler.example.com/host/myfakehost"). - with(body: {"{}"=>true}, + stub_request(:put, 'https://nspooler.example.com/host/myfakehost'). + with(body: {'{}'=>true}, headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'token-value'}). - to_return(status: 200, body: "", headers: {}) + to_return(status: 200, body: '', headers: {}) details = { lifetime: 12 } expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) } .to raise_error(ModifyError) @@ -188,7 +188,7 @@ BODY headers: @post_request_headers) .to_return(status: 200, body: '{"ok": true}', headers: {}) - modify_hash = { reason: "testing" } + modify_hash = { reason: 'testing' } modify_req = NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', modify_hash) expect(modify_req['ok']).to be true end diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index 557149a..397e99a 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -3,15 +3,15 @@ require_relative '../../lib/vmfloaty/pooler' describe Pooler do before :each do - @vmpooler_url = "https://vmpooler.example.com" + @vmpooler_url = 'https://vmpooler.example.com' end - describe "#list" do + describe '#list' do before :each do - @list_response_body = "[\"debian-7-i386\",\"debian-7-x86_64\",\"centos-7-x86_64\"]" + @list_response_body = '["debian-7-i386","debian-7-x86_64","centos-7-x86_64"]' end - it "returns a hash with operating systems from the pooler" do + it 'returns a hash with operating systems from the pooler' do stub_request(:get, "#{@vmpooler_url}/vm"). to_return(:status => 200, :body => @list_response_body, :headers => {}) @@ -19,42 +19,42 @@ describe Pooler do expect(list).to be_an_instance_of Array end - it "filters operating systems based on the filter param" do + it 'filters operating systems based on the filter param' do stub_request(:get, "#{@vmpooler_url}/vm"). to_return(:status => 200, :body => @list_response_body, :headers => {}) - list = Pooler.list(false, @vmpooler_url, "deb") + list = Pooler.list(false, @vmpooler_url, 'deb') expect(list).to be_an_instance_of Array expect(list.size).to equal 2 end - it "returns nothing if the filter does not match" do + it 'returns nothing if the filter does not match' do stub_request(:get, "#{@vmpooler_url}/vm"). to_return(:status => 200, :body => @list_response_body, :headers => {}) - list = Pooler.list(false, @vmpooler_url, "windows") + list = Pooler.list(false, @vmpooler_url, 'windows') expect(list).to be_an_instance_of Array expect(list.size).to equal 0 end end - describe "#retrieve" do + describe '#retrieve' do before :each do - @retrieve_response_body_single = "{\"ok\":true,\"debian-7-i386\":{\"hostname\":\"fq6qlpjlsskycq6\"}}" - @retrieve_response_body_double = "{\"ok\":true,\"debian-7-i386\":{\"hostname\":[\"sc0o4xqtodlul5w\",\"4m4dkhqiufnjmxy\"]},\"centos-7-x86_64\":{\"hostname\":\"zb91y9qbrbf6d3q\"}}" + @retrieve_response_body_single = '{"ok":true,"debian-7-i386":{"hostname":"fq6qlpjlsskycq6"}}' + @retrieve_response_body_double = '{"ok":true,"debian-7-i386":{"hostname":["sc0o4xqtodlul5w","4m4dkhqiufnjmxy"]},"centos-7-x86_64":{"hostname":"zb91y9qbrbf6d3q"}}' end - it "raises an AuthError if the token is invalid" do + it 'raises an AuthError if the token is invalid' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). - to_return(:status => 401, :body => "{\"ok\":false}", :headers => {}) + to_return(:status => 401, :body => '{"ok":false}', :headers => {}) vm_hash = {} vm_hash['debian-7-i386'] = 1 expect{ Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url) }.to raise_error(AuthError) end - it "retrieves a single vm with a token" do + it 'retrieves a single vm with a token' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {}) @@ -63,11 +63,11 @@ describe Pooler do vm_hash['debian-7-i386'] = 1 vm_req = Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url) expect(vm_req).to be_an_instance_of Hash - expect(vm_req["ok"]).to equal true - expect(vm_req["debian-7-i386"]["hostname"]).to eq "fq6qlpjlsskycq6" + expect(vm_req['ok']).to equal true + expect(vm_req['debian-7-i386']['hostname']).to eq 'fq6qlpjlsskycq6' end - it "retrieves a multiple vms with a token" do + it 'retrieves a multiple vms with a token' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {}) @@ -77,24 +77,24 @@ describe Pooler do vm_hash['centos-7-x86_64'] = 1 vm_req = Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url) expect(vm_req).to be_an_instance_of Hash - expect(vm_req["ok"]).to equal true - expect(vm_req["debian-7-i386"]["hostname"]).to be_an_instance_of Array - expect(vm_req["debian-7-i386"]["hostname"]).to eq ["sc0o4xqtodlul5w", "4m4dkhqiufnjmxy"] - expect(vm_req["centos-7-x86_64"]["hostname"]).to eq "zb91y9qbrbf6d3q" + expect(vm_req['ok']).to equal true + expect(vm_req['debian-7-i386']['hostname']).to be_an_instance_of Array + expect(vm_req['debian-7-i386']['hostname']).to eq ['sc0o4xqtodlul5w', '4m4dkhqiufnjmxy'] + expect(vm_req['centos-7-x86_64']['hostname']).to eq 'zb91y9qbrbf6d3q' end end - describe "#modify" do + describe '#modify' do before :each do - @modify_response_body_success = "{\"ok\":true}" - @modify_response_body_fail = "{\"ok\":false}" + @modify_response_body_success = '{"ok":true}' + @modify_response_body_fail = '{"ok":false}' end - it "raises a TokenError if token provided is nil" do + it 'raises a TokenError if token provided is nil' do expect{ Pooler.modify(false, @vmpooler_url, 'myfakehost', nil, {}) }.to raise_error(TokenError) end - it "modifies the TTL of a vm" do + it 'modifies the TTL of a vm' do modify_hash = { :lifetime => 12 } stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). with(:body => {'{"lifetime":12}'=>true}, @@ -102,17 +102,17 @@ describe Pooler do to_return(:status => 200, :body => @modify_response_body_success, :headers => {}) modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash) - expect(modify_req["ok"]).to be true + expect(modify_req['ok']).to be true end end - describe "#delete" do + describe '#delete' do before :each do - @delete_response_body_success = "{\"ok\":true}" - @delete_response = {"fq6qlpjlsskycq6"=>{"ok"=>true}} + @delete_response_body_success = '{"ok":true}' + @delete_response = {'fq6qlpjlsskycq6'=>{'ok'=>true}} end - it "deletes a specified vm" do + it 'deletes a specified vm' do stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). to_return(:status => 200, :body => @delete_response_body_success, :headers => {}) @@ -120,18 +120,18 @@ describe Pooler do expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile')).to eq @delete_response end - it "raises a token error if no token provided" do + it 'raises a token error if no token provided' do expect{ Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil) }.to raise_error(TokenError) end end - describe "#status" do + describe '#status' do before :each do #smaller version - @status_response_body = "{\"capacity\":{\"current\":716,\"total\":717,\"percent\": 99.9},\"status\":{\"ok\":true,\"message\":\"Battle station fully armed and operational.\"}}" + @status_response_body = '{"capacity":{"current":716,"total":717,"percent": 99.9},"status":{"ok":true,"message":"Battle station fully armed and operational."}}' end - it "prints the status" do + it 'prints the status' do stub_request(:get, "#{@vmpooler_url}/status"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). to_return(:status => 200, :body => @status_response_body, :headers => {}) @@ -141,21 +141,21 @@ describe Pooler do end end - describe "#summary" do + describe '#summary' do before :each do - @status_response_body = "" + @status_response_body = '' - it "prints the summary" do + it 'prints the summary' do end end end - describe "#query" do + describe '#query' do before :each do - @query_response_body = "{\"ok\": true,\"fq6qlpjlsskycq6\":{\"template\":\"debian-7-x86_64\",\"lifetime\": 2,\"running\": 0.08,\"state\":\"running\",\"snapshots\":[\"n4eb4kdtp7rwv4x158366vd9jhac8btq\" ],\"domain\": \"delivery.puppetlabs.net\"}}" + @query_response_body = '{"ok": true,"fq6qlpjlsskycq6":{"template":"debian-7-x86_64","lifetime": 2,"running": 0.08,"state":"running","snapshots":["n4eb4kdtp7rwv4x158366vd9jhac8btq" ],"domain": "delivery.puppetlabs.net"}}' end - it "makes a query about a vm" do + it 'makes a query about a vm' do stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). to_return(:status => 200, :body => @query_response_body, :headers => {}) @@ -165,59 +165,59 @@ describe Pooler do end end - describe "#snapshot" do + describe '#snapshot' do before :each do - @snapshot_response_body = "{\"ok\":true}" + @snapshot_response_body = '{"ok":true}' end - it "makes a snapshot for a single vm" do + it 'makes a snapshot for a single vm' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). to_return(:status => 200, :body => @snapshot_response_body, :headers => {}) snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile') - expect(snapshot_req["ok"]).to be true + expect(snapshot_req['ok']).to be true end end - describe "#revert" do + describe '#revert' do before :each do - @revert_response_body = "{\"ok\":true}" + @revert_response_body = '{"ok":true}' end - it "makes a request to revert a vm from a snapshot" do + it 'makes a request to revert a vm from a snapshot' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). to_return(:status => 200, :body => @revert_response_body, :headers => {}) revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve') - expect(revert_req["ok"]).to be true + expect(revert_req['ok']).to be true end it "doesn't make a request to revert a vm if snapshot is not provided" do - expect{ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, "Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6") + expect{ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6') end - it "raises a TokenError if no token was provided" do + it 'raises a TokenError if no token was provided' do expect{ Pooler.revert(false, @vmpooler_url, 'myfakehost', nil, 'shaaaaaaa') }.to raise_error(TokenError) end end - describe "#disk" do + describe '#disk' do before :each do - @disk_response_body_success = "{\"ok\":true}" - @disk_response_body_fail = "{\"ok\":false}" + @disk_response_body_success = '{"ok":true}' + @disk_response_body_fail = '{"ok":false}' end - it "makes a request to extend disk space of a vm" do + it 'makes a request to extend disk space of a vm' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12) - expect(disk_req["ok"]).to be true + expect(disk_req['ok']).to be true end - it "raises a TokenError if no token was provided" do + it 'raises a TokenError if no token was provided' do expect{ Pooler.disk(false, @vmpooler_url, 'myfakehost', nil, 12) }.to raise_error(TokenError) end end diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 5a78a61..1885bfa 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -5,7 +5,7 @@ require_relative '../../lib/vmfloaty/utils' describe Utils do - describe "#standardize_hostnames" do + describe '#standardize_hostnames' do before :each do @vmpooler_response_body ='{ "ok": true, @@ -28,24 +28,24 @@ describe Utils do }' end - it "formats a result from vmpooler into a hash of os to hostnames" do + it 'formats a result from vmpooler into a hash of os to hostnames' do result = Utils.standardize_hostnames(JSON.parse(@vmpooler_response_body)) - expect(result).to eq('centos-7-x86_64' => ["dlgietfmgeegry2.delivery.mycompany.net"], - 'ubuntu-1610-x86_64' => ["gdoy8q3nckuob0i.delivery.mycompany.net", "ctnktsd0u11p9tm.delivery.mycompany.net"]) + expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'], + 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net']) end - it "formats a result from the nonstandard pooler into a hash of os to hostnames" do + it 'formats a result from the nonstandard pooler into a hash of os to hostnames' do result = Utils.standardize_hostnames(JSON.parse(@nonstandard_response_body)) expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'], 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net']) end end - describe "#format_host_output" do + describe '#format_host_output' do before :each do @vmpooler_results = { - 'centos-7-x86_64' => ["dlgietfmgeegry2.delivery.mycompany.net"], - 'ubuntu-1610-x86_64' => ["gdoy8q3nckuob0i.delivery.mycompany.net", "ctnktsd0u11p9tm.delivery.mycompany.net"] + 'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'], + 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'] } @nonstandard_results = { 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'], @@ -62,43 +62,43 @@ describe Utils do - power8-ubuntu16.04-6.delivery.mycompany.net (ubuntu-16.04-power8) OUT end - it "formats a hostname hash from vmpooler into a list that includes the os" do + it 'formats a hostname hash from vmpooler into a list that includes the os' do expect(Utils.format_host_output(@vmpooler_results)).to eq(@vmpooler_output) end - it "formats a hostname hash from the nonstandard pooler into a list that includes the os" do + it 'formats a hostname hash from the nonstandard pooler into a list that includes the os' do expect(Utils.format_host_output(@nonstandard_results)).to eq(@nonstandard_output) end end - describe "#get_service_object" do - it "assumes vmpooler by default" do + describe '#get_service_object' do + it 'assumes vmpooler by default' do expect(Utils.get_service_object).to be Pooler end - it "uses nspooler when told explicitly" do - expect(Utils.get_service_object "nspooler").to be NonstandardPooler + it 'uses nspooler when told explicitly' do + expect(Utils.get_service_object 'nspooler').to be NonstandardPooler end end - describe "#get_service_config" do + describe '#get_service_config' do before :each do @default_config = { - "url" => "http://default.url", - "user" => "first.last.default", - "token" => "default-token", + 'url' => 'http://default.url', + 'user' => 'first.last.default', + 'token' => 'default-token', } @services_config = { - "services" => { - "vm" => { - "url" => "http://vmpooler.url", - "user" => "first.last.vmpooler", - "token" => "vmpooler-token" + 'services' => { + 'vm' => { + 'url' => 'http://vmpooler.url', + 'user' => 'first.last.vmpooler', + 'token' => 'vmpooler-token' }, - "ns" => { - "url" => "http://nspooler.url", - "user" => "first.last.nspooler", - "token" => "nspooler-token" + 'ns' => { + 'url' => 'http://nspooler.url', + 'user' => 'first.last.nspooler', + 'token' => 'nspooler-token' } } } @@ -110,44 +110,44 @@ describe Utils do expect(Utils.get_service_config(config, options)).to include @services_config['services']['vm'] end - it "allows selection by configured service key" do + it 'allows selection by configured service key' do config = @default_config.merge @services_config - options = MockOptions.new({:service => "ns"}) + options = MockOptions.new({:service => 'ns'}) expect(Utils.get_service_config(config, options)).to include @services_config['services']['ns'] end - it "uses top-level service config values as defaults when configured service values are missing" do + it 'uses top-level service config values as defaults when configured service values are missing' do config = @default_config.merge @services_config - config["services"]['vm'].delete 'url' - options = MockOptions.new({:service => "vm"}) + config['services']['vm'].delete 'url' + options = MockOptions.new({:service => 'vm'}) expect(Utils.get_service_config(config, options)['url']).to eq 'http://default.url' end it "raises an error if passed a service name that hasn't been configured" do config = @default_config.merge @services_config - options = MockOptions.new({:service => "none"}) + options = MockOptions.new({:service => 'none'}) expect { Utils.get_service_config(config, options) }.to raise_error ArgumentError end - it "prioritizes values passed as command line options over configuration options" do + it 'prioritizes values passed as command line options over configuration options' do config = @default_config - options = MockOptions.new({:url => "http://alternate.url", :token => "alternate-token"}) - expected = config.merge({"url" => "http://alternate.url", "token" => "alternate-token"}) + options = MockOptions.new({:url => 'http://alternate.url', :token => 'alternate-token'}) + expected = config.merge({'url' => 'http://alternate.url', 'token' => 'alternate-token'}) expect(Utils.get_service_config(config, options)).to include expected end end - describe "#generate_os_hash" do + describe '#generate_os_hash' do before :each do - @host_hash = {"centos"=>1, "debian"=>5, "windows"=>1} + @host_hash = {'centos'=>1, 'debian'=>5, 'windows'=>1} end - it "takes an array of os arguments and returns a formatted hash" do - host_arg = ["centos", "debian=5", "windows=1"] + it 'takes an array of os arguments and returns a formatted hash' do + host_arg = ['centos', 'debian=5', 'windows=1'] expect(Utils.generate_os_hash(host_arg)).to eq @host_hash end - it "returns an empty hash if there are no arguments provided" do + it 'returns an empty hash if there are no arguments provided' do host_arg = [] expect(Utils.generate_os_hash(host_arg)).to be_empty end @@ -166,7 +166,7 @@ describe Utils do 'ip' => '127.0.0.1', 'domain' => 'delivery.mycompany.net' }} - output = "- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)" + output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)' expect(Utils).to receive(:puts).with(output) @@ -192,7 +192,7 @@ describe Utils do 'ip' => '127.0.0.1', 'domain' => 'delivery.mycompany.net' }} - output = "- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)" + output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)' expect(Utils).to receive(:puts).with(output) @@ -205,7 +205,7 @@ describe Utils do end it 'prints a nonstandard pooler output with host, template, and time remaining' do - hostname = "sol11-9.delivery.mycompany.net" + hostname = 'sol11-9.delivery.mycompany.net' response_body = { hostname => { 'fqdn' => hostname, 'os_triple' => 'solaris-11-sparc', @@ -213,7 +213,7 @@ describe Utils do 'reserved_for_reason' => '', 'hours_left_on_reservation' => 35.89 }} - output = "- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)" + output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)' expect(Utils).to receive(:puts).with(output) @@ -234,7 +234,7 @@ describe Utils do 'reserved_for_reason' => 'testing', 'hours_left_on_reservation' => 35.89 }} - output = "- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)" + output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)' expect(Utils).to receive(:puts).with(output) From 1cf00a5a4c75de00b98128a706cd34014f94a776 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 10:44:25 +1100 Subject: [PATCH 02/57] (rubocop) Fix Style/ZeroLengthPredicate --- lib/vmfloaty/pooler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 8bdef2c..539e85b 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -46,7 +46,7 @@ class Pooler os_string = os_string.chomp('+') - if os_string.size == 0 + if os_string.empty? raise MissingParamError, 'No operating systems provided to obtain.' end From 02e49e5c4f48d7c5ab1a61feab5e866e595cfafc Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 10:46:35 +1100 Subject: [PATCH 03/57] (rubocop) Fix Style/ColonMethodCall --- lib/vmfloaty/service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vmfloaty/service.rb b/lib/vmfloaty/service.rb index 14a8df3..aa0dae0 100644 --- a/lib/vmfloaty/service.rb +++ b/lib/vmfloaty/service.rb @@ -47,13 +47,13 @@ class Service def get_new_token(verbose) username = user - pass = Commander::UI::password 'Enter your pooler service password:', '*' + pass = Commander::UI.password 'Enter your pooler service password:', '*' Auth.get_token(verbose, url, username, pass) end def delete_token(verbose, token_value = @config['token']) username = user - pass = Commander::UI::password 'Enter your pooler service password:', '*' + pass = Commander::UI.password 'Enter your pooler service password:', '*' Auth.delete_token(verbose, url, username, pass, token_value) end From e0cbf89b8f5b7ac467a114a0d26b59348c4ae67d Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 10:48:00 +1100 Subject: [PATCH 04/57] (rubocop) Fix Style/FrozenStringLiteralComment --- Gemfile | 2 ++ Rakefile | 2 ++ bin/floaty | 1 + lib/vmfloaty.rb | 1 + lib/vmfloaty/auth.rb | 2 ++ lib/vmfloaty/conf.rb | 2 ++ lib/vmfloaty/errors.rb | 2 ++ lib/vmfloaty/http.rb | 2 ++ lib/vmfloaty/nonstandard_pooler.rb | 12 +++--------- lib/vmfloaty/pooler.rb | 12 +++--------- lib/vmfloaty/service.rb | 2 ++ lib/vmfloaty/ssh.rb | 2 ++ lib/vmfloaty/utils.rb | 2 ++ lib/vmfloaty/version.rb | 2 ++ spec/spec_helper.rb | 2 ++ spec/vmfloaty/auth_spec.rb | 2 ++ spec/vmfloaty/nonstandard_pooler_spec.rb | 2 ++ spec/vmfloaty/pooler_spec.rb | 2 ++ spec/vmfloaty/service_spec.rb | 2 ++ spec/vmfloaty/utils_spec.rb | 2 ++ vmfloaty.gemspec | 2 ++ 21 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 926c627..26acfc9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile index efbd5a9..3d5a4dd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubygems' require 'bundler/setup' require 'rspec/core/rake_task' diff --git a/bin/floaty b/bin/floaty index 6fe5b10..1a1b0be 100755 --- a/bin/floaty +++ b/bin/floaty @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 390d2ab..4a29e49 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'rubygems' require 'commander' diff --git a/lib/vmfloaty/auth.rb b/lib/vmfloaty/auth.rb index 7d33327..bbe7425 100644 --- a/lib/vmfloaty/auth.rb +++ b/lib/vmfloaty/auth.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' require 'json' require 'vmfloaty/http' diff --git a/lib/vmfloaty/conf.rb b/lib/vmfloaty/conf.rb index 2f04e61..a232f8d 100644 --- a/lib/vmfloaty/conf.rb +++ b/lib/vmfloaty/conf.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'yaml' class Conf diff --git a/lib/vmfloaty/errors.rb b/lib/vmfloaty/errors.rb index ee8e2cb..098a94c 100644 --- a/lib/vmfloaty/errors.rb +++ b/lib/vmfloaty/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AuthError < StandardError def initialize(msg='Could not authenticate to pooler') super diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index f21b993..71f955d 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' require 'uri' diff --git a/lib/vmfloaty/nonstandard_pooler.rb b/lib/vmfloaty/nonstandard_pooler.rb index 7384db8..512e90d 100644 --- a/lib/vmfloaty/nonstandard_pooler.rb +++ b/lib/vmfloaty/nonstandard_pooler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'vmfloaty/errors' require 'vmfloaty/http' require 'faraday' @@ -24,15 +26,7 @@ class NonstandardPooler conn = Http.get_conn(verbose, url) conn.headers['X-AUTH-TOKEN'] = token if token - os_string = '' - os_type.each do |os, num| - num.times do |_i| - os_string << os + '+' - end - end - - os_string = os_string.chomp('+') - + os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+') if os_string.empty? raise MissingParamError, 'No operating systems provided to obtain.' end diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 539e85b..a84035b 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' require 'vmfloaty/http' require 'json' @@ -37,15 +39,7 @@ class Pooler conn.headers['X-AUTH-TOKEN'] = token end - os_string = '' - os_type.each do |os,num| - num.times do |i| - os_string << os+'+' - end - end - - os_string = os_string.chomp('+') - + os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+') if os_string.empty? raise MissingParamError, 'No operating systems provided to obtain.' end diff --git a/lib/vmfloaty/service.rb b/lib/vmfloaty/service.rb index aa0dae0..e1ce49e 100644 --- a/lib/vmfloaty/service.rb +++ b/lib/vmfloaty/service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'commander/user_interaction' require 'commander/command' require 'vmfloaty/utils' diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index 4087d3a..6afc03e 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Ssh def self.which(cmd) diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index fca7a32..763bb8f 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'vmfloaty/pooler' require 'vmfloaty/nonstandard_pooler' diff --git a/lib/vmfloaty/version.rb b/lib/vmfloaty/version.rb index 4000441..1521a18 100644 --- a/lib/vmfloaty/version.rb +++ b/lib/vmfloaty/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Vmfloaty VERSION = '0.8.2'.freeze end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 982b1ed..558a0ad 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'vmfloaty' require 'webmock/rspec' diff --git a/spec/vmfloaty/auth_spec.rb b/spec/vmfloaty/auth_spec.rb index 8a527ed..0869a33 100644 --- a/spec/vmfloaty/auth_spec.rb +++ b/spec/vmfloaty/auth_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require_relative '../../lib/vmfloaty/auth' diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 7b03827..332e491 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'vmfloaty/utils' require 'vmfloaty/errors' diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index 397e99a..43524d4 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require_relative '../../lib/vmfloaty/pooler' diff --git a/spec/vmfloaty/service_spec.rb b/spec/vmfloaty/service_spec.rb index 78ba671..3f709ce 100644 --- a/spec/vmfloaty/service_spec.rb +++ b/spec/vmfloaty/service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../lib/vmfloaty/service' describe Service do diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 1885bfa..2ec858b 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'json' require 'commander/command' diff --git a/vmfloaty.gemspec b/vmfloaty.gemspec index 4317b4a..fcbaaab 100644 --- a/vmfloaty.gemspec +++ b/vmfloaty.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.push File.expand_path('../lib', __FILE__) require 'vmfloaty/version' From 0d95977db3dfba9cde5cae0e5799b81125363bc9 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 10:55:50 +1100 Subject: [PATCH 05/57] (rubocop) Disable Style/Documentation for now --- .rubocop.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..223211f --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +--- +AllCops: + TargetRubyVersion: 2.4 + +Style/Documentation: + Enabled: False From 42014ae39fa304bbb8f47b468c5639a6e9f89b84 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 10:56:46 +1100 Subject: [PATCH 06/57] (rubocop) Fix Style/RedundantReturn --- lib/vmfloaty/http.rb | 6 +++--- lib/vmfloaty/ssh.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index 71f955d..9d169b0 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -15,7 +15,7 @@ class Http return true end - return false + false end def self.get_conn(verbose, url) @@ -33,7 +33,7 @@ class Http faraday.adapter Faraday.default_adapter end - return conn + conn end def self.get_conn_with_auth(verbose, url, user, password) @@ -56,7 +56,7 @@ class Http faraday.adapter Faraday.default_adapter end - return conn + conn end end diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index 6afc03e..c5c63c6 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -12,7 +12,7 @@ class Ssh return exe if File.executable?(exe) && !File.directory?(exe) } end - return nil + nil end def self.ssh(verbose, host_os, token, url) @@ -40,6 +40,6 @@ class Ssh else raise "Could not get vm from vmpooler:\n #{response}" end - return + nil end end From fcf7154a8b1ac4b761c9edfc8ffe0067ed6e160b Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:03:11 +1100 Subject: [PATCH 07/57] (rubocop) Style/HashSyntax to use hash_rockets for consistency --- .rubocop.yml | 2 + Gemfile | 2 +- Rakefile | 2 +- lib/vmfloaty.rb | 8 ++-- spec/vmfloaty/nonstandard_pooler_spec.rb | 54 ++++++++++++------------ 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 223211f..e336fa0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,3 +4,5 @@ AllCops: Style/Documentation: Enabled: False +Style/HashSyntax: + EnforcedStyle: hash_rockets diff --git a/Gemfile b/Gemfile index 26acfc9..adb75fe 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gemspec -gem 'rake', require: false +gem 'rake', :require => false group :test do gem 'rspec', '~> 3.5.0' diff --git a/Rakefile b/Rakefile index 3d5a4dd..bcfae46 100644 --- a/Rakefile +++ b/Rakefile @@ -28,4 +28,4 @@ RuboCop::RakeTask.new(:rubocop) do |task| end # Default task is to run the unit tests -task default: :spec +task :default => :spec diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 4a29e49..11bc196 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -152,10 +152,10 @@ class Vmfloaty tags = options.tags ? JSON.parse(options.tags) : nil modify_hash = { - lifetime: options.lifetime, - disk: options.disk, - tags: tags, - reason: options.reason + :lifetime => options.lifetime, + :disk => options.disk, + :tags => tags, + :reason => options.reason } modify_hash.delete_if { |_, value| value.nil? } diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 332e491..1491204 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -49,7 +49,7 @@ describe NonstandardPooler do it 'returns an array with operating systems from the pooler' do stub_request(:get, "#{@nspooler_url}/status") - .to_return(status: 200, body: @status_response_body, headers: {}) + .to_return(:status => 200, :body => @status_response_body, :headers => {}) list = NonstandardPooler.list(false, @nspooler_url, nil) expect(list).to be_an_instance_of Array @@ -57,7 +57,7 @@ describe NonstandardPooler do it 'filters operating systems based on the filter param' do stub_request(:get, "#{@nspooler_url}/status") - .to_return(status: 200, body: @status_response_body, headers: {}) + .to_return(:status => 200, :body => @status_response_body, :headers => {}) list = NonstandardPooler.list(false, @nspooler_url, 'aix') expect(list).to be_an_instance_of Array @@ -66,7 +66,7 @@ describe NonstandardPooler do it 'returns nothing if the filter does not match' do stub_request(:get, "#{@nspooler_url}/status") - .to_return(status: 199, body: @status_response_body, headers: {}) + .to_return(:status => 199, :body => @status_response_body, :headers => {}) list = NonstandardPooler.list(false, @nspooler_url, 'windows') expect(list).to be_an_instance_of Array @@ -134,8 +134,8 @@ BODY it 'raises an AuthError if the token is invalid' do stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc") - .with(headers: @post_request_headers) - .to_return(status: 401, body: '{"ok":false,"reason": "token: token-value does not exist"}', headers: {}) + .with(:headers => @post_request_headers) + .to_return(:status => 401, :body => '{"ok":false,"reason": "token: token-value does not exist"}', :headers => {}) vm_hash = { 'solaris-11-sparc' => 1 } expect { NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url) }.to raise_error(AuthError) @@ -143,8 +143,8 @@ BODY it 'retrieves a single vm with a token' do stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc") - .with(headers: @post_request_headers) - .to_return(status: 200, body: @retrieve_response_body_single, headers: {}) + .with(:headers => @post_request_headers) + .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {}) vm_hash = { 'solaris-11-sparc' => 1 } vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url) @@ -155,8 +155,8 @@ BODY it 'retrieves a multiple vms with a token' do stub_request(:post,"#{@nspooler_url}/host/aix-7.1-power+solaris-10-sparc+solaris-10-sparc") - .with(headers: @post_request_headers) - .to_return(status: 200, body: @retrieve_response_body_many, headers: {}) + .with(:headers => @post_request_headers) + .to_return(:status => 200, :body => @retrieve_response_body_many, :headers => {}) vm_hash = { 'aix-7.1-power' => 1, 'solaris-10-sparc' => 2 } vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url) @@ -175,10 +175,10 @@ BODY it 'raises an error if the user tries to modify an unsupported attribute' do stub_request(:put, 'https://nspooler.example.com/host/myfakehost'). - with(body: {'{}'=>true}, - headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'token-value'}). - to_return(status: 200, body: '', headers: {}) - details = { lifetime: 12 } + with(:body => {'{}'=>true}, + :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'token-value'}). + to_return(:status => 200, :body => '', :headers => {}) + details = { :lifetime => 12 } expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) } .to raise_error(ModifyError) end @@ -186,11 +186,11 @@ BODY it 'modifies the reason of a vm' do modify_request_body = { '{"reserved_for_reason":"testing"}' => true } stub_request(:put, "#{@nspooler_url}/host/myfakehost") - .with(body: modify_request_body, - headers: @post_request_headers) - .to_return(status: 200, body: '{"ok": true}', headers: {}) + .with(:body => modify_request_body, + :headers => @post_request_headers) + .to_return(:status => 200, :body => '{"ok": true}', :headers => {}) - modify_hash = { reason: 'testing' } + modify_hash = { :reason => 'testing' } modify_req = NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', modify_hash) expect(modify_req['ok']).to be true end @@ -221,8 +221,8 @@ BODY it 'prints the status' do stub_request(:get, "#{@nspooler_url}/status") - .with(headers: @get_request_headers) - .to_return(status: 200, body: @status_response_body, headers: {}) + .with(:headers => @get_request_headers) + .to_return(:status => 200, :body => @status_response_body, :headers => {}) status = NonstandardPooler.status(false, @nspooler_url) expect(status).to be_an_instance_of Hash @@ -245,8 +245,8 @@ BODY it 'prints the summary' do stub_request(:get, "#{@nspooler_url}/summary") - .with(headers: @get_request_headers) - .to_return(status: 200, body: @status_response_body, headers: {}) + .with(:headers => @get_request_headers) + .to_return(:status => 200, :body => @status_response_body, :headers => {}) summary = NonstandardPooler.summary(false, @nspooler_url) expect(summary).to be_an_instance_of Hash @@ -271,8 +271,8 @@ BODY it 'makes a query about a vm' do stub_request(:get, "#{@nspooler_url}/host/sol10-11") - .with(headers: @get_request_headers_notoken) - .to_return(status: 200, body: @query_response_body, headers: {}) + .with(:headers => @get_request_headers_notoken) + .to_return(:status => 200, :body => @query_response_body, :headers => {}) query_req = NonstandardPooler.query(false, @nspooler_url, 'sol10-11') expect(query_req).to be_an_instance_of Hash @@ -287,8 +287,8 @@ BODY it 'deletes a single existing vm' do stub_request(:delete, "#{@nspooler_url}/host/sol11-7") - .with(headers: @post_request_headers) - .to_return(status: 200, body: @delete_response_success, headers: {}) + .with(:headers => @post_request_headers) + .to_return(:status => 200, :body => @delete_response_success, :headers => {}) request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value') expect(request['sol11-7']['ok']).to be true @@ -296,8 +296,8 @@ BODY it 'does not delete a nonexistant vm' do stub_request(:delete, "#{@nspooler_url}/host/fakehost") - .with(headers: @post_request_headers) - .to_return(status: 401, body: @delete_response_failure, headers: {}) + .with(:headers => @post_request_headers) + .to_return(:status => 401, :body => @delete_response_failure, :headers => {}) request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value') expect(request['fakehost']['ok']).to be false From 874a6e7cf66b5c13eff410de6d261c306d5d105e Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:05:08 +1100 Subject: [PATCH 08/57] (rubocop) Fix Style/ClassCheck --- lib/vmfloaty/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index 9d169b0..33e4f19 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -11,7 +11,7 @@ class Http uri = URI.parse(url) - if uri.kind_of?(URI::HTTP) or uri.kind_of?(URI::HTTPS) + if uri.is_a?(URI::HTTP) or uri.is_a?(URI::HTTPS) return true end From 79f764560d7e18e2a5d1f1008b5117dfe540b5be Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:06:05 +1100 Subject: [PATCH 09/57] (rubocop) Fix Style/AndOr --- lib/vmfloaty.rb | 4 ++-- lib/vmfloaty/http.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 11bc196..2d587e2 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -52,7 +52,7 @@ class Vmfloaty max_pool_request = 5 large_pool_requests = os_types.select{|_,v| v > max_pool_request} - if ! large_pool_requests.empty? and ! force + if ! large_pool_requests.empty? && ! force STDERR.puts "Requesting vms over #{max_pool_request} requires a --force flag." STDERR.puts 'Try again with `floaty get --force`' exit 1 @@ -144,7 +144,7 @@ class Vmfloaty hostname = args[0] modify_all = options.all - if hostname.nil? and !modify_all + if hostname.nil? && !modify_all STDERR.puts 'ERROR: Provide a hostname or specify --all.' exit 1 end diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index 33e4f19..bb7636e 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -11,7 +11,7 @@ class Http uri = URI.parse(url) - if uri.is_a?(URI::HTTP) or uri.is_a?(URI::HTTPS) + if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) return true end From d95c6946b8940dad24c6294b958be506a40ea6ab Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:08:05 +1100 Subject: [PATCH 10/57] (rubocop) Fix Style/BracesAroundHashParameters --- spec/vmfloaty/service_spec.rb | 4 ++-- spec/vmfloaty/utils_spec.rb | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/vmfloaty/service_spec.rb b/spec/vmfloaty/service_spec.rb index 3f709ce..17085af 100644 --- a/spec/vmfloaty/service_spec.rb +++ b/spec/vmfloaty/service_spec.rb @@ -45,14 +45,14 @@ describe Service do describe '#delete_token' do it 'deletes a token' do - service = Service.new(MockOptions.new,{'user' => 'first.last', 'url' => 'http://default.url'}) + service = Service.new(MockOptions.new,'user' => 'first.last', 'url' => 'http://default.url') allow(Commander::UI).to(receive(:password) .with('Enter your pooler service password:', '*') .and_return('hunter2')) allow(Auth).to(receive(:delete_token) .with(nil, 'http://default.url', 'first.last', 'hunter2', 'token-value') .and_return('ok' => true)) - expect(service.delete_token(nil, 'token-value')).to eql({'ok' => true}) + expect(service.delete_token(nil, 'token-value')).to eql('ok' => true) end end diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 2ec858b..12c86ee 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -114,27 +114,27 @@ describe Utils do it 'allows selection by configured service key' do config = @default_config.merge @services_config - options = MockOptions.new({:service => 'ns'}) + options = MockOptions.new(:service => 'ns') expect(Utils.get_service_config(config, options)).to include @services_config['services']['ns'] end it 'uses top-level service config values as defaults when configured service values are missing' do config = @default_config.merge @services_config config['services']['vm'].delete 'url' - options = MockOptions.new({:service => 'vm'}) + options = MockOptions.new(:service => 'vm') expect(Utils.get_service_config(config, options)['url']).to eq 'http://default.url' end it "raises an error if passed a service name that hasn't been configured" do config = @default_config.merge @services_config - options = MockOptions.new({:service => 'none'}) + options = MockOptions.new(:service => 'none') expect { Utils.get_service_config(config, options) }.to raise_error ArgumentError end it 'prioritizes values passed as command line options over configuration options' do config = @default_config - options = MockOptions.new({:url => 'http://alternate.url', :token => 'alternate-token'}) - expected = config.merge({'url' => 'http://alternate.url', 'token' => 'alternate-token'}) + options = MockOptions.new(:url => 'http://alternate.url', :token => 'alternate-token') + expected = config.merge('url' => 'http://alternate.url', 'token' => 'alternate-token') expect(Utils.get_service_config(config, options)).to include expected end end @@ -172,7 +172,7 @@ describe Utils do expect(Utils).to receive(:puts).with(output) - service = Service.new(MockOptions.new, {'url' => url}) + service = Service.new(MockOptions.new, 'url' => url) allow(service).to receive(:query) .with(nil, hostname) .and_return(response_body) @@ -198,7 +198,7 @@ describe Utils do expect(Utils).to receive(:puts).with(output) - service = Service.new(MockOptions.new, {'url' => url}) + service = Service.new(MockOptions.new, 'url' => url) allow(service).to receive(:query) .with(nil, hostname) .and_return(response_body) @@ -219,7 +219,7 @@ describe Utils do expect(Utils).to receive(:puts).with(output) - service = Service.new(MockOptions.new, {'url' => url, 'type' => 'ns'}) + service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns') allow(service).to receive(:query) .with(nil, hostname) .and_return(response_body) @@ -240,7 +240,7 @@ describe Utils do expect(Utils).to receive(:puts).with(output) - service = Service.new(MockOptions.new, {'url' => url, 'type' => 'ns'}) + service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns') allow(service).to receive(:query) .with(nil, hostname) .and_return(response_body) From c7c8e48e2f41d3f02ffb99bf019164cee41cb617 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:10:52 +1100 Subject: [PATCH 11/57] (rubocop) Fix Style/ExpandPathArguments --- Rakefile | 2 +- bin/floaty | 2 +- vmfloaty.gemspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index bcfae46..bde93cf 100644 --- a/Rakefile +++ b/Rakefile @@ -11,7 +11,7 @@ $stdout.sync = true $stderr.sync = true # Change to the directory of this file. -Dir.chdir(File.expand_path('../', __FILE__)) +Dir.chdir(File.expand_path(__dir__)) # This installs the tasks that help with gem creation and # publishing. diff --git a/bin/floaty b/bin/floaty index 1a1b0be..5ab2e1f 100755 --- a/bin/floaty +++ b/bin/floaty @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) +$LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) require 'vmfloaty' diff --git a/vmfloaty.gemspec b/vmfloaty.gemspec index fcbaaab..455fce0 100644 --- a/vmfloaty.gemspec +++ b/vmfloaty.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -$LOAD_PATH.push File.expand_path('../lib', __FILE__) +$LOAD_PATH.push File.expand_path('lib', __dir__) require 'vmfloaty/version' Gem::Specification.new do |s| From 7bafee35a7e4edd2be7d22dbcf80f22ab217a20c Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:14:23 +1100 Subject: [PATCH 12/57] (rubocop) Fix Style/IfUnlessModifier --- lib/vmfloaty.rb | 8 ++------ lib/vmfloaty/auth.rb | 8 ++------ lib/vmfloaty/http.rb | 24 ++++++------------------ lib/vmfloaty/nonstandard_pooler.rb | 4 +--- lib/vmfloaty/pooler.rb | 8 ++------ lib/vmfloaty/ssh.rb | 4 +--- lib/vmfloaty/utils.rb | 4 +--- 7 files changed, 15 insertions(+), 45 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 2d587e2..17947d9 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -212,9 +212,7 @@ class Vmfloaty # Confirm deletion puts confirmed = true - unless force - confirmed = agree('Delete all these VMs? [y/N]') - end + confirmed = agree('Delete all these VMs? [y/N]') unless force if confirmed response = service.delete(verbose, running_vms) response.each do |hostname, result| @@ -381,9 +379,7 @@ class Vmfloaty puts result when 'status' token_value = options.token - if token_value.nil? - token_value = args[1] - end + token_value = args[1] if token_value.nil? status = service.token_status(verbose, token_value) puts status when nil diff --git a/lib/vmfloaty/auth.rb b/lib/vmfloaty/auth.rb index bbe7425..091b7c2 100644 --- a/lib/vmfloaty/auth.rb +++ b/lib/vmfloaty/auth.rb @@ -20,9 +20,7 @@ class Auth end def self.delete_token(verbose, url, user, password, token) - if token.nil? - raise TokenError, 'You did not provide a token' - end + raise TokenError, 'You did not provide a token' if token.nil? conn = Http.get_conn_with_auth(verbose, url, user, password) @@ -36,9 +34,7 @@ class Auth end def self.token_status(verbose, url, token) - if token.nil? - raise TokenError, 'You did not provide a token' - end + raise TokenError, 'You did not provide a token' if token.nil? conn = Http.get_conn(verbose, url) diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index bb7636e..860df2b 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -11,21 +11,15 @@ class Http uri = URI.parse(url) - if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) - return true - end + return true if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) false end def self.get_conn(verbose, url) - if url.nil? - raise 'Did not provide a url to connect to' - end + raise 'Did not provide a url to connect to' if url.nil? - unless is_url(url) - url = "https://#{url}" - end + url = "https://#{url}" unless is_url(url) conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| faraday.request :url_encoded @@ -37,17 +31,11 @@ class Http end def self.get_conn_with_auth(verbose, url, user, password) - if url.nil? - raise 'Did not provide a url to connect to' - end + raise 'Did not provide a url to connect to' if url.nil? - if user.nil? - raise 'You did not provide a user to authenticate with' - end + raise 'You did not provide a user to authenticate with' if user.nil? - unless is_url(url) - url = "https://#{url}" - end + url = "https://#{url}" unless is_url(url) conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| faraday.request :url_encoded diff --git a/lib/vmfloaty/nonstandard_pooler.rb b/lib/vmfloaty/nonstandard_pooler.rb index 512e90d..aacb6bb 100644 --- a/lib/vmfloaty/nonstandard_pooler.rb +++ b/lib/vmfloaty/nonstandard_pooler.rb @@ -94,9 +94,7 @@ class NonstandardPooler response_body = {} - unless hosts.is_a? Array - hosts = hosts.split(',') - end + hosts = hosts.split(',') unless hosts.is_a? Array hosts.each do |host| response = conn.delete "host/#{host}" res_body = JSON.parse(response.body) diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index a84035b..2c0b934 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -35,9 +35,7 @@ class Pooler # Developers can use `Utils.generate_os_hash` to # generate the os_type param. conn = Http.get_conn(verbose, url) - if token - conn.headers['X-AUTH-TOKEN'] = token - end + conn.headers['X-AUTH-TOKEN'] = token if token os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+') if os_string.empty? @@ -106,9 +104,7 @@ class Pooler conn = Http.get_conn(verbose, url) - if token - conn.headers['X-AUTH-TOKEN'] = token - end + conn.headers['X-AUTH-TOKEN'] = token if token response_body = {} diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index c5c63c6..848d054 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -17,9 +17,7 @@ class Ssh def self.ssh(verbose, host_os, token, url) ssh_path = which('ssh') - if !ssh_path - raise 'Could not determine path to ssh' - end + raise 'Could not determine path to ssh' if !ssh_path os_types = {} os_types[host_os] = 1 diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 763bb8f..b42bfaa 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -41,9 +41,7 @@ class Utils response_body.each do |os, value| hostnames = Array(value['hostname']) - if domain - hostnames.map! {|host| "#{host}.#{domain}"} - end + hostnames.map! {|host| "#{host}.#{domain}"} if domain result[os] = hostnames end From 12c179504669ad8c73ece18758aaf68c1c416a1e Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:16:25 +1100 Subject: [PATCH 13/57] (rubocop) Fix Style/RescueStandardError --- lib/vmfloaty/conf.rb | 2 +- lib/vmfloaty/utils.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vmfloaty/conf.rb b/lib/vmfloaty/conf.rb index a232f8d..b1bfef1 100644 --- a/lib/vmfloaty/conf.rb +++ b/lib/vmfloaty/conf.rb @@ -8,7 +8,7 @@ class Conf conf = {} begin conf = YAML.load_file("#{Dir.home}/.vmfloaty.yml") - rescue + rescue StandardError STDERR.puts "WARNING: There was no config file at #{Dir.home}/.vmfloaty.yml" end conf diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index b42bfaa..9d0cc61 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -103,7 +103,7 @@ class Utils else raise "Invalid service type #{service.type}" end - rescue => e + rescue StandardError => e STDERR.puts("Something went wrong while trying to gather information on #{hostname}:") STDERR.puts(e) end @@ -128,7 +128,7 @@ class Utils missing = max - ready - pending char = 'o' puts "#{name.ljust(width)} #{(char*ready).green}#{(char*pending).yellow}#{(char*missing).red}" - rescue => e + rescue StandardError => e puts "#{name.ljust(width)} #{e.red}" end end @@ -147,7 +147,7 @@ class Utils missing = max - ready - pending char = 'o' puts "#{name.ljust(width)} #{(char*ready).green}#{(char*pending).yellow}#{(char*missing).red}" - rescue => e + rescue StandardError => e puts "#{name.ljust(width)} #{e.red}" end end From 5ad213075b2a3b4187271a764c5f22334c1bb306 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:17:55 +1100 Subject: [PATCH 14/57] (rubocop) Fix Style/StringLiteralsInInterpolation --- lib/vmfloaty/ssh.rb | 2 +- lib/vmfloaty/utils.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index 848d054..b982527 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -29,7 +29,7 @@ class Ssh user = 'root' end - hostname = "#{response[host_os]["hostname"]}.#{response["domain"]}" + hostname = "#{response[host_os]['hostname']}.#{response['domain']}" cmd = "#{ssh_path} #{user}@#{hostname}" # TODO: Should this respect more ssh settings? Can it be configured diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 9d0cc61..1759396 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -91,7 +91,7 @@ class Utils end duration = "#{host_data['running']}/#{host_data['lifetime']} hours" metadata = [host_data['template'], duration, *tag_pairs] - puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(", ")})" + puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})" when 'NonstandardPooler' line = "- #{host_data['fqdn']} (#{host_data['os_triple']}" line += ", #{host_data['hours_left_on_reservation']}h remaining" From d25732b9504342ae4515312589ec45dc57dbe5be Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:19:13 +1100 Subject: [PATCH 15/57] (rubocop) Fix Style/NegatedIf --- lib/vmfloaty/ssh.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index b982527..3642e49 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -17,7 +17,7 @@ class Ssh def self.ssh(verbose, host_os, token, url) ssh_path = which('ssh') - raise 'Could not determine path to ssh' if !ssh_path + raise 'Could not determine path to ssh' unless ssh_path os_types = {} os_types[host_os] = 1 From 397bbd4dcede934e65399fb38120a6c932d7b31d Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:20:02 +1100 Subject: [PATCH 16/57] (rubocop) Fix Style/RedundantFreeze --- lib/vmfloaty/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty/version.rb b/lib/vmfloaty/version.rb index 1521a18..5bc74da 100644 --- a/lib/vmfloaty/version.rb +++ b/lib/vmfloaty/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class Vmfloaty - VERSION = '0.8.2'.freeze + VERSION = '0.8.2' end From cdb9b0ca3d2172afe18422e9ea0a5a2be7a03ebb Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:21:53 +1100 Subject: [PATCH 17/57] (rubocop) Fix Style/NestedParenthesizedCalls --- spec/vmfloaty/utils_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 12c86ee..7450960 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -79,7 +79,7 @@ describe Utils do end it 'uses nspooler when told explicitly' do - expect(Utils.get_service_object 'nspooler').to be NonstandardPooler + expect(Utils.get_service_object('nspooler')).to be NonstandardPooler end end From 095ac9e75e28fd231a81e2508aac7638ebc84c47 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:24:18 +1100 Subject: [PATCH 18/57] (rubocop) Fix Style/WordArray --- lib/vmfloaty/utils.rb | 2 +- spec/vmfloaty/pooler_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 1759396..12b5047 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -165,7 +165,7 @@ class Utils end def self.get_service_object(type = '') - nspooler_strings = ['ns', 'nspooler', 'nonstandard', 'nonstandard_pooler'] + nspooler_strings = %w[ns nspooler nonstandard nonstandard_pooler] if nspooler_strings.include? type.downcase NonstandardPooler else diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index 43524d4..1f6e8fb 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -81,7 +81,7 @@ describe Pooler do expect(vm_req).to be_an_instance_of Hash expect(vm_req['ok']).to equal true expect(vm_req['debian-7-i386']['hostname']).to be_an_instance_of Array - expect(vm_req['debian-7-i386']['hostname']).to eq ['sc0o4xqtodlul5w', '4m4dkhqiufnjmxy'] + expect(vm_req['debian-7-i386']['hostname']).to eq %w[sc0o4xqtodlul5w 4m4dkhqiufnjmxy] expect(vm_req['centos-7-x86_64']['hostname']).to eq 'zb91y9qbrbf6d3q' end end From 1aea79a9a1781982decf41006110fb0a94a62b10 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:25:02 +1100 Subject: [PATCH 19/57] (rubocop) Fix Style/SymbolArray --- lib/vmfloaty/nonstandard_pooler.rb | 2 +- lib/vmfloaty/pooler.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vmfloaty/nonstandard_pooler.rb b/lib/vmfloaty/nonstandard_pooler.rb index aacb6bb..0e1e449 100644 --- a/lib/vmfloaty/nonstandard_pooler.rb +++ b/lib/vmfloaty/nonstandard_pooler.rb @@ -50,7 +50,7 @@ class NonstandardPooler end modify_hash.each do |key, value| - unless [:reason, :reserved_for_reason].include? key + unless %i[reason reserved_for_reason].include? key raise ModifyError, "Configured service type does not support modification of #{key}" end end diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 2c0b934..023f971 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -61,7 +61,7 @@ class Pooler end modify_hash.keys.each do |key| - unless [:tags, :lifetime, :disk].include? key + unless %i[tags lifetime disk].include? key raise ModifyError, "Configured service type does not support modification of #{key}." end end From 58f64b284362922dc3952904ae92d4724d80dbf3 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:27:53 +1100 Subject: [PATCH 20/57] (rubocop) Fix Style/TrailingCommaInHashLiteral --- .rubocop.yml | 2 ++ lib/vmfloaty.rb | 2 +- lib/vmfloaty/utils.rb | 2 +- spec/vmfloaty/nonstandard_pooler_spec.rb | 4 ++-- spec/vmfloaty/service_spec.rb | 4 ++-- spec/vmfloaty/utils_spec.rb | 22 +++++++++++----------- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e336fa0..4136241 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,3 +6,5 @@ Style/Documentation: Enabled: False Style/HashSyntax: EnforcedStyle: hash_rockets +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: comma diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 17947d9..410e1dd 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -155,7 +155,7 @@ class Vmfloaty :lifetime => options.lifetime, :disk => options.disk, :tags => tags, - :reason => options.reason + :reason => options.reason, } modify_hash.delete_if { |_, value| value.nil? } diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 12b5047..6747524 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -179,7 +179,7 @@ class Utils 'url' => config['url'], 'user' => config['user'], 'token' => config['token'], - 'type' => config['type'] || 'vmpooler' + 'type' => config['type'] || 'vmpooler', } if config['services'] diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 1491204..3185da1 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -12,13 +12,13 @@ describe NonstandardPooler do 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2', - 'X-Auth-Token' => 'token-value' + 'X-Auth-Token' => 'token-value', } @get_request_headers = { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2', - 'X-Auth-Token' => 'token-value' + 'X-Auth-Token' => 'token-value', } @get_request_headers_notoken = @get_request_headers.tap do |headers| headers.delete('X-Auth-Token') diff --git a/spec/vmfloaty/service_spec.rb b/spec/vmfloaty/service_spec.rb index 17085af..bdffb45 100644 --- a/spec/vmfloaty/service_spec.rb +++ b/spec/vmfloaty/service_spec.rb @@ -60,7 +60,7 @@ describe Service do it 'reports the status of a token' do config = { 'user' => 'first.last', - 'url' => 'http://default.url' + 'url' => 'http://default.url', } options = MockOptions.new('token' => 'token-value') service = Service.new(options, config) @@ -69,7 +69,7 @@ describe Service do 'user' => config['user'], 'created' => '2017-09-22 02:04:18 +0000', 'last_accessed' => '2017-09-22 02:04:28 +0000', - 'reserved_hosts' => [] + 'reserved_hosts' => [], } allow(Auth).to(receive(:token_status) .with(nil, config['url'], 'token-value') diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 7450960..9836b85 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -47,11 +47,11 @@ describe Utils do before :each do @vmpooler_results = { 'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'], - 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'] + 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'], } @nonstandard_results = { 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'], - 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'] + 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'], } @vmpooler_output = <<-OUT.chomp - dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64) @@ -95,14 +95,14 @@ describe Utils do 'vm' => { 'url' => 'http://vmpooler.url', 'user' => 'first.last.vmpooler', - 'token' => 'vmpooler-token' + 'token' => 'vmpooler-token', }, 'ns' => { 'url' => 'http://nspooler.url', 'user' => 'first.last.nspooler', - 'token' => 'nspooler-token' - } - } + 'token' => 'nspooler-token', + }, + }, } end @@ -166,7 +166,7 @@ describe Utils do 'running' => 9.66, 'state' => 'running', 'ip' => '127.0.0.1', - 'domain' => 'delivery.mycompany.net' + 'domain' => 'delivery.mycompany.net', }} output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)' @@ -189,10 +189,10 @@ describe Utils do 'state' => 'running', 'tags' => { 'user' => 'bob', - 'role' => 'agent' + 'role' => 'agent', }, 'ip' => '127.0.0.1', - 'domain' => 'delivery.mycompany.net' + 'domain' => 'delivery.mycompany.net', }} output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)' @@ -213,7 +213,7 @@ describe Utils do 'os_triple' => 'solaris-11-sparc', 'reserved_by_user' => 'first.last', 'reserved_for_reason' => '', - 'hours_left_on_reservation' => 35.89 + 'hours_left_on_reservation' => 35.89, }} output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)' @@ -234,7 +234,7 @@ describe Utils do 'os_triple' => 'solaris-11-sparc', 'reserved_by_user' => 'first.last', 'reserved_for_reason' => 'testing', - 'hours_left_on_reservation' => 35.89 + 'hours_left_on_reservation' => 35.89, }} output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)' From 0e5dd9b7db405b58eeb5e4256fbeb42988338845 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:29:31 +1100 Subject: [PATCH 21/57] (rubocop) Fix Style/TrailingCommaInArrayLiteral --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 4136241..7be7272 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,3 +8,5 @@ Style/HashSyntax: EnforcedStyle: hash_rockets Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: comma +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma From 692577a486870e167569fb1cbc2e963463c0ddf9 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:30:58 +1100 Subject: [PATCH 22/57] (rubocop) Fix Style/TrailingCommaInArguments --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 7be7272..e0a6614 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,3 +10,5 @@ Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: comma Style/TrailingCommaInArrayLiteral: EnforcedStyleForMultiline: comma +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: comma From 613121f34dd170b4997810d55f93741ef554fc52 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:33:02 +1100 Subject: [PATCH 23/57] (rubocop) Fix Style/BlockDelimiters --- lib/vmfloaty/ssh.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index 3642e49..4e25965 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -7,10 +7,10 @@ class Ssh exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| - exts.each { |ext| + exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) - } + end end nil end From dec621e9b8a6792fd3709f35bc689c65599d5315 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:37:16 +1100 Subject: [PATCH 24/57] (rubocop) Fix Style/ConditionalAssignment --- lib/vmfloaty/pooler.rb | 10 +++++----- lib/vmfloaty/ssh.rb | 6 +----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 023f971..8695fb4 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -12,11 +12,11 @@ class Pooler response = conn.get 'vm' response_body = JSON.parse(response.body) - if os_filter - hosts = response_body.select { |i| i[/#{os_filter}/] } - else - hosts = response_body - end + hosts = if os_filter + response_body.select { |i| i[/#{os_filter}/] } + else + response_body + end hosts end diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index 4e25965..bf9cb76 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -23,11 +23,7 @@ class Ssh response = Pooler.retrieve(verbose, os_types, token, url) if response['ok'] == true - if host_os =~ /win/ - user = 'Administrator' - else - user = 'root' - end + user = host_os =~ /win/ ? 'Administrator' : 'root' hostname = "#{response[host_os]['hostname']}.#{response['domain']}" cmd = "#{ssh_path} #{user}@#{hostname}" From 6c4fe8384c3ece08b55a334ef8733ac486fd02d2 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:41:25 +1100 Subject: [PATCH 25/57] (rubocop) Fix Style/IfInsideElse --- lib/vmfloaty/utils.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 6747524..a145003 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -190,12 +190,12 @@ class Utils service_config.merge! values else # If the user provided a service name at the command line, use that service if posible, or fail - if config['services'][options.service] - # If the service is configured but some values are missing, use the top-level defaults to fill them in - service_config.merge! config['services'][options.service] - else + unless config['services'][options.service] raise ArgumentError, "Could not find a configured service named '#{options.service}' in ~/.vmfloaty.yml" end + + # If the service is configured but some values are missing, use the top-level defaults to fill them in + service_config.merge! config['services'][options.service] end end From b7b08c9c9e28147cff7de4365a2e0b320fd3fec9 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:45:06 +1100 Subject: [PATCH 26/57] (rubocop) Fix Style/MissingRespondToMissing --- lib/vmfloaty/service.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/vmfloaty/service.rb b/lib/vmfloaty/service.rb index e1ce49e..899f651 100644 --- a/lib/vmfloaty/service.rb +++ b/lib/vmfloaty/service.rb @@ -23,6 +23,10 @@ class Service end end + def respond_to_missing?(m, *) + @service_object.respond_to?(m) || super + end + def url @config['url'] end From 6a771a8d7698bc40a479c93ea8afd0f534a5f846 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:22:02 +1100 Subject: [PATCH 27/57] (rubocop) Fix Style/GuardClause --- lib/vmfloaty/auth.rb | 21 ++++++--------------- lib/vmfloaty/ssh.rb | 17 +++++++---------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/lib/vmfloaty/auth.rb b/lib/vmfloaty/auth.rb index 091b7c2..a1fdd60 100644 --- a/lib/vmfloaty/auth.rb +++ b/lib/vmfloaty/auth.rb @@ -12,11 +12,8 @@ class Auth resp = conn.post 'token' res_body = JSON.parse(resp.body) - if res_body['ok'] - return res_body['token'] - else - raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}" - end + return res_body['token'] if res_body['ok'] + raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}" end def self.delete_token(verbose, url, user, password, token) @@ -26,11 +23,8 @@ class Auth response = conn.delete "token/#{token}" res_body = JSON.parse(response.body) - if res_body['ok'] - return res_body - else - raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}" - end + return res_body if res_body['ok'] + raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}" end def self.token_status(verbose, url, token) @@ -41,10 +35,7 @@ class Auth response = conn.get "token/#{token}" res_body = JSON.parse(response.body) - if res_body['ok'] - return res_body - else - raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}" - end + return res_body if res_body['ok'] + raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}" end end diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index bf9cb76..e20d84d 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -22,18 +22,15 @@ class Ssh os_types[host_os] = 1 response = Pooler.retrieve(verbose, os_types, token, url) - if response['ok'] == true - user = host_os =~ /win/ ? 'Administrator' : 'root' + raise "Could not get vm from vmpooler:\n #{response}" unless response['ok'] + user = host_os =~ /win/ ? 'Administrator' : 'root' - hostname = "#{response[host_os]['hostname']}.#{response['domain']}" - cmd = "#{ssh_path} #{user}@#{hostname}" + hostname = "#{response[host_os]['hostname']}.#{response['domain']}" + cmd = "#{ssh_path} #{user}@#{hostname}" - # TODO: Should this respect more ssh settings? Can it be configured - # by users ssh config and does this respect those settings? - Kernel.exec(cmd) - else - raise "Could not get vm from vmpooler:\n #{response}" - end + # TODO: Should this respect more ssh settings? Can it be configured + # by users ssh config and does this respect those settings? + Kernel.exec(cmd) nil end end From b16e3fc79284889b9ad573a38b94dc41f807cef9 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:26:38 +1100 Subject: [PATCH 28/57] (rubocop) Fix Layout/SpaceAroundOperators --- lib/vmfloaty/utils.rb | 4 ++-- spec/vmfloaty/auth_spec.rb | 12 ++++++------ spec/vmfloaty/nonstandard_pooler_spec.rb | 4 ++-- spec/vmfloaty/pooler_spec.rb | 24 ++++++++++++------------ spec/vmfloaty/utils_spec.rb | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index a145003..ef20802 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -127,7 +127,7 @@ class Utils pending = pool['pending'] missing = max - ready - pending char = 'o' - puts "#{name.ljust(width)} #{(char*ready).green}#{(char*pending).yellow}#{(char*missing).red}" + puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}" rescue StandardError => e puts "#{name.ljust(width)} #{e.red}" end @@ -146,7 +146,7 @@ class Utils pending = pool['pending'] || 0 # not available for nspooler missing = max - ready - pending char = 'o' - puts "#{name.ljust(width)} #{(char*ready).green}#{(char*pending).yellow}#{(char*missing).red}" + puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}" rescue StandardError => e puts "#{name.ljust(width)} #{e.red}" end diff --git a/spec/vmfloaty/auth_spec.rb b/spec/vmfloaty/auth_spec.rb index 0869a33..dc7f66d 100644 --- a/spec/vmfloaty/auth_spec.rb +++ b/spec/vmfloaty/auth_spec.rb @@ -16,7 +16,7 @@ describe Pooler do it 'returns a token from vmpooler' do stub_request(:post, 'https://first.last:password@vmpooler.example.com/token'). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2'}). to_return(:status => 200, :body => @get_token_response, :headers => {}) token = Auth.get_token(false, @vmpooler_url, 'first.last', 'password') @@ -25,7 +25,7 @@ describe Pooler do it 'raises a token error if something goes wrong' do stub_request(:post, 'https://first.last:password@vmpooler.example.com/token'). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2'}). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect{ Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError) @@ -40,7 +40,7 @@ describe Pooler do it 'deletes the specified token' do stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y'). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). to_return(:status => 200, :body => @delete_token_response, :headers => {}) expect(Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response) @@ -48,7 +48,7 @@ describe Pooler do it 'raises a token error if something goes wrong' do stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y'). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect{ Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError) @@ -67,7 +67,7 @@ describe Pooler do it 'checks the status of a token' do stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). to_return(:status => 200, :body => @token_status_response, :headers => {}) expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response) @@ -75,7 +75,7 @@ describe Pooler do it 'raises a token error if something goes wrong' do stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect{ Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError) diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 3185da1..70507e3 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -175,8 +175,8 @@ BODY it 'raises an error if the user tries to modify an unsupported attribute' do stub_request(:put, 'https://nspooler.example.com/host/myfakehost'). - with(:body => {'{}'=>true}, - :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'token-value'}). + with(:body => {'{}' => true}, + :headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'token-value'}). to_return(:status => 200, :body => '', :headers => {}) details = { :lifetime => 12 } expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) } diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index 1f6e8fb..c5bdf0d 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -48,7 +48,7 @@ describe Pooler do it 'raises an AuthError if the token is invalid' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 401, :body => '{"ok":false}', :headers => {}) vm_hash = {} @@ -58,7 +58,7 @@ describe Pooler do it 'retrieves a single vm with a token' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {}) vm_hash = {} @@ -71,7 +71,7 @@ describe Pooler do it 'retrieves a multiple vms with a token' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {}) vm_hash = {} @@ -99,8 +99,8 @@ describe Pooler do it 'modifies the TTL of a vm' do modify_hash = { :lifetime => 12 } stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:body => {'{"lifetime":12}'=>true}, - :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). + with(:body => {'{"lifetime":12}' => true}, + :headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 200, :body => @modify_response_body_success, :headers => {}) modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash) @@ -111,12 +111,12 @@ describe Pooler do describe '#delete' do before :each do @delete_response_body_success = '{"ok":true}' - @delete_response = {'fq6qlpjlsskycq6'=>{'ok'=>true}} + @delete_response = {'fq6qlpjlsskycq6' => {'ok' => true}} end it 'deletes a specified vm' do stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 200, :body => @delete_response_body_success, :headers => {}) expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile')).to eq @delete_response @@ -135,7 +135,7 @@ describe Pooler do it 'prints the status' do stub_request(:get, "#{@vmpooler_url}/status"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). to_return(:status => 200, :body => @status_response_body, :headers => {}) status = Pooler.status(false, @vmpooler_url) @@ -159,7 +159,7 @@ describe Pooler do it 'makes a query about a vm' do stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). to_return(:status => 200, :body => @query_response_body, :headers => {}) query_req = Pooler.query(false, @vmpooler_url, 'fq6qlpjlsskycq6') @@ -174,7 +174,7 @@ describe Pooler do it 'makes a snapshot for a single vm' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 200, :body => @snapshot_response_body, :headers => {}) snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile') @@ -189,7 +189,7 @@ describe Pooler do it 'makes a request to revert a vm from a snapshot' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 200, :body => @revert_response_body, :headers => {}) revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve') @@ -213,7 +213,7 @@ describe Pooler do it 'makes a request to extend disk space of a vm' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length'=>'0', 'User-Agent'=>'Faraday v0.9.2', 'X-Auth-Token'=>'mytokenfile'}). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) + with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12) expect(disk_req['ok']).to be true diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 9836b85..b9aca22 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -9,7 +9,7 @@ describe Utils do describe '#standardize_hostnames' do before :each do - @vmpooler_response_body ='{ + @vmpooler_response_body = '{ "ok": true, "domain": "delivery.mycompany.net", "ubuntu-1610-x86_64": { @@ -141,7 +141,7 @@ describe Utils do describe '#generate_os_hash' do before :each do - @host_hash = {'centos'=>1, 'debian'=>5, 'windows'=>1} + @host_hash = {'centos' => 1, 'debian' => 5, 'windows' => 1} end it 'takes an array of os arguments and returns a formatted hash' do From 7cd0256a97e1b4c0ec2f356d4fd4bf021e19ed3e Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:28:17 +1100 Subject: [PATCH 29/57] (rubocop) Fix Layout/SpaceInsideBlockBraces --- lib/vmfloaty.rb | 2 +- lib/vmfloaty/utils.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 410e1dd..428a73f 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -51,7 +51,7 @@ class Vmfloaty os_types = Utils.generate_os_hash(args) max_pool_request = 5 - large_pool_requests = os_types.select{|_,v| v > max_pool_request} + large_pool_requests = os_types.select{ |_,v| v > max_pool_request } if ! large_pool_requests.empty? && ! force STDERR.puts "Requesting vms over #{max_pool_request} requires a --force flag." STDERR.puts 'Try again with `floaty get --force`' diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index ef20802..7bfdd52 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -41,7 +41,7 @@ class Utils response_body.each do |os, value| hostnames = Array(value['hostname']) - hostnames.map! {|host| "#{host}.#{domain}"} if domain + hostnames.map! { |host| "#{host}.#{domain}" } if domain result[os] = hostnames end @@ -87,7 +87,7 @@ class Utils when 'Pooler' tag_pairs = [] unless host_data['tags'].nil? - tag_pairs = host_data['tags'].map {|key, value| "#{key}: #{value}"} + tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } end duration = "#{host_data['running']}/#{host_data['lifetime']} hours" metadata = [host_data['template'], duration, *tag_pairs] @@ -117,7 +117,7 @@ class Utils when 'Pooler' message = status_response['status']['message'] pools = status_response['pools'] - pools.select! {|_, pool| pool['ready'] < pool['max']} unless verbose + pools.select! { |_, pool| pool['ready'] < pool['max'] } unless verbose width = pools.keys.map(&:length).max pools.each do |name, pool| @@ -136,7 +136,7 @@ class Utils when 'NonstandardPooler' pools = status_response pools.delete 'ok' - pools.select! {|_, pool| pool['available_hosts'] < pool['total_hosts']} unless verbose + pools.select! { |_, pool| pool['available_hosts'] < pool['total_hosts'] } unless verbose width = pools.keys.map(&:length).max pools.each do |name, pool| From eb0d31260fe26815a74568962ba24ea2f4ccd7fb Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:30:26 +1100 Subject: [PATCH 30/57] (rubocop) Fix Layout/SpaceAroundEqualsInParameterDefault --- lib/vmfloaty/errors.rb | 8 ++++---- lib/vmfloaty/pooler.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vmfloaty/errors.rb b/lib/vmfloaty/errors.rb index 098a94c..28891cc 100644 --- a/lib/vmfloaty/errors.rb +++ b/lib/vmfloaty/errors.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true class AuthError < StandardError - def initialize(msg='Could not authenticate to pooler') + def initialize(msg = 'Could not authenticate to pooler') super end end class TokenError < StandardError - def initialize(msg='Could not do operation with token provided') + def initialize(msg = 'Could not do operation with token provided') super end end class MissingParamError < StandardError - def initialize(msg='Argument provided to function is missing') + def initialize(msg = 'Argument provided to function is missing') super end end class ModifyError < StandardError - def initialize(msg='Could not modify VM') + def initialize(msg = 'Could not modify VM') super end end diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 8695fb4..8eceb8c 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -6,7 +6,7 @@ require 'json' require 'vmfloaty/errors' class Pooler - def self.list(verbose, url, os_filter=nil) + def self.list(verbose, url, os_filter = nil) conn = Http.get_conn(verbose, url) response = conn.get 'vm' From b8971c040a5800b476bcae9ffd8a94894fcee65b Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:32:05 +1100 Subject: [PATCH 31/57] (rubocop) Fix Layout/SpaceInsideLiteralHashBraces --- lib/vmfloaty/http.rb | 4 ++-- spec/vmfloaty/auth_spec.rb | 12 ++++++------ spec/vmfloaty/nonstandard_pooler_spec.rb | 4 ++-- spec/vmfloaty/pooler_spec.rb | 24 ++++++++++++------------ spec/vmfloaty/service_spec.rb | 2 +- spec/vmfloaty/utils_spec.rb | 10 +++++----- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index 860df2b..b120538 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -21,7 +21,7 @@ class Http url = "https://#{url}" unless is_url(url) - conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| + conn = Faraday.new(:url => url, :ssl => { :verify => false }) do |faraday| faraday.request :url_encoded faraday.response :logger if verbose faraday.adapter Faraday.default_adapter @@ -37,7 +37,7 @@ class Http url = "https://#{url}" unless is_url(url) - conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| + conn = Faraday.new(:url => url, :ssl => { :verify => false }) do |faraday| faraday.request :url_encoded faraday.request :basic_auth, user, password faraday.response :logger if verbose diff --git a/spec/vmfloaty/auth_spec.rb b/spec/vmfloaty/auth_spec.rb index dc7f66d..817ed28 100644 --- a/spec/vmfloaty/auth_spec.rb +++ b/spec/vmfloaty/auth_spec.rb @@ -16,7 +16,7 @@ describe Pooler do it 'returns a token from vmpooler' do stub_request(:post, 'https://first.last:password@vmpooler.example.com/token'). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 200, :body => @get_token_response, :headers => {}) token = Auth.get_token(false, @vmpooler_url, 'first.last', 'password') @@ -25,7 +25,7 @@ describe Pooler do it 'raises a token error if something goes wrong' do stub_request(:post, 'https://first.last:password@vmpooler.example.com/token'). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect{ Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError) @@ -40,7 +40,7 @@ describe Pooler do it 'deletes the specified token' do stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y'). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 200, :body => @delete_token_response, :headers => {}) expect(Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response) @@ -48,7 +48,7 @@ describe Pooler do it 'raises a token error if something goes wrong' do stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y'). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect{ Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError) @@ -67,7 +67,7 @@ describe Pooler do it 'checks the status of a token' do stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 200, :body => @token_status_response, :headers => {}) expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response) @@ -75,7 +75,7 @@ describe Pooler do it 'raises a token error if something goes wrong' do stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect{ Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError) diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 70507e3..cc0f6c0 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -175,8 +175,8 @@ BODY it 'raises an error if the user tries to modify an unsupported attribute' do stub_request(:put, 'https://nspooler.example.com/host/myfakehost'). - with(:body => {'{}' => true}, - :headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'token-value'}). + with(:body => { '{}' => true }, + :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'token-value' }). to_return(:status => 200, :body => '', :headers => {}) details = { :lifetime => 12 } expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) } diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index c5bdf0d..c973930 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -48,7 +48,7 @@ describe Pooler do it 'raises an AuthError if the token is invalid' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 401, :body => '{"ok":false}', :headers => {}) vm_hash = {} @@ -58,7 +58,7 @@ describe Pooler do it 'retrieves a single vm with a token' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {}) vm_hash = {} @@ -71,7 +71,7 @@ describe Pooler do it 'retrieves a multiple vms with a token' do stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {}) vm_hash = {} @@ -99,8 +99,8 @@ describe Pooler do it 'modifies the TTL of a vm' do modify_hash = { :lifetime => 12 } stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:body => {'{"lifetime":12}' => true}, - :headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). + with(:body => { '{"lifetime":12}' => true }, + :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @modify_response_body_success, :headers => {}) modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash) @@ -111,12 +111,12 @@ describe Pooler do describe '#delete' do before :each do @delete_response_body_success = '{"ok":true}' - @delete_response = {'fq6qlpjlsskycq6' => {'ok' => true}} + @delete_response = { 'fq6qlpjlsskycq6' => { 'ok' => true } } end it 'deletes a specified vm' do stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @delete_response_body_success, :headers => {}) expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile')).to eq @delete_response @@ -135,7 +135,7 @@ describe Pooler do it 'prints the status' do stub_request(:get, "#{@vmpooler_url}/status"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 200, :body => @status_response_body, :headers => {}) status = Pooler.status(false, @vmpooler_url) @@ -159,7 +159,7 @@ describe Pooler do it 'makes a query about a vm' do stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 200, :body => @query_response_body, :headers => {}) query_req = Pooler.query(false, @vmpooler_url, 'fq6qlpjlsskycq6') @@ -174,7 +174,7 @@ describe Pooler do it 'makes a snapshot for a single vm' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @snapshot_response_body, :headers => {}) snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile') @@ -189,7 +189,7 @@ describe Pooler do it 'makes a request to revert a vm from a snapshot' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @revert_response_body, :headers => {}) revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve') @@ -213,7 +213,7 @@ describe Pooler do it 'makes a request to extend disk space of a vm' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12"). - with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile'}). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) + with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12) expect(disk_req['ok']).to be true diff --git a/spec/vmfloaty/service_spec.rb b/spec/vmfloaty/service_spec.rb index bdffb45..7e9812a 100644 --- a/spec/vmfloaty/service_spec.rb +++ b/spec/vmfloaty/service_spec.rb @@ -7,7 +7,7 @@ describe Service do describe '#initialize' do it 'store configuration options' do options = MockOptions.new({}) - config = {'url' => 'http://example.url'} + config = { 'url' => 'http://example.url' } service = Service.new(options, config) expect(service.config).to include config end diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index b9aca22..2caed14 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -141,7 +141,7 @@ describe Utils do describe '#generate_os_hash' do before :each do - @host_hash = {'centos' => 1, 'debian' => 5, 'windows' => 1} + @host_hash = { 'centos' => 1, 'debian' => 5, 'windows' => 1 } end it 'takes an array of os arguments and returns a formatted hash' do @@ -167,7 +167,7 @@ describe Utils do 'state' => 'running', 'ip' => '127.0.0.1', 'domain' => 'delivery.mycompany.net', - }} + } } output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)' expect(Utils).to receive(:puts).with(output) @@ -193,7 +193,7 @@ describe Utils do }, 'ip' => '127.0.0.1', 'domain' => 'delivery.mycompany.net', - }} + } } output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)' expect(Utils).to receive(:puts).with(output) @@ -214,7 +214,7 @@ describe Utils do 'reserved_by_user' => 'first.last', 'reserved_for_reason' => '', 'hours_left_on_reservation' => 35.89, - }} + } } output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)' expect(Utils).to receive(:puts).with(output) @@ -235,7 +235,7 @@ describe Utils do 'reserved_by_user' => 'first.last', 'reserved_for_reason' => 'testing', 'hours_left_on_reservation' => 35.89, - }} + } } output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)' expect(Utils).to receive(:puts).with(output) From fd753ba188480898aa9edc10b5e1082f646a4440 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:34:24 +1100 Subject: [PATCH 32/57] (rubocop) Fix Layout/SpaceBeforeBlockBraces --- lib/vmfloaty.rb | 2 +- spec/vmfloaty/auth_spec.rb | 10 +++++----- spec/vmfloaty/pooler_spec.rb | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 428a73f..a68fc26 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -51,7 +51,7 @@ class Vmfloaty os_types = Utils.generate_os_hash(args) max_pool_request = 5 - large_pool_requests = os_types.select{ |_,v| v > max_pool_request } + large_pool_requests = os_types.select { |_,v| v > max_pool_request } if ! large_pool_requests.empty? && ! force STDERR.puts "Requesting vms over #{max_pool_request} requires a --force flag." STDERR.puts 'Try again with `floaty get --force`' diff --git a/spec/vmfloaty/auth_spec.rb b/spec/vmfloaty/auth_spec.rb index 817ed28..1aacaae 100644 --- a/spec/vmfloaty/auth_spec.rb +++ b/spec/vmfloaty/auth_spec.rb @@ -28,7 +28,7 @@ describe Pooler do with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) - expect{ Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError) + expect { Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError) end end @@ -51,11 +51,11 @@ describe Pooler do with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) - expect{ Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError) + expect { Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError) end it 'raises a token error if no token provided' do - expect{ Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', nil) }.to raise_error(TokenError) + expect { Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', nil) }.to raise_error(TokenError) end end @@ -78,11 +78,11 @@ describe Pooler do with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). to_return(:status => 500, :body => '{"ok":false}', :headers => {}) - expect{ Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError) + expect { Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError) end it 'raises a token error if no token provided' do - expect{ Auth.token_status(false, @vmpooler_url, nil) }.to raise_error(TokenError) + expect { Auth.token_status(false, @vmpooler_url, nil) }.to raise_error(TokenError) end end end diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index c973930..304dd36 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -53,7 +53,7 @@ describe Pooler do vm_hash = {} vm_hash['debian-7-i386'] = 1 - expect{ Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url) }.to raise_error(AuthError) + expect { Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url) }.to raise_error(AuthError) end it 'retrieves a single vm with a token' do @@ -93,7 +93,7 @@ describe Pooler do end it 'raises a TokenError if token provided is nil' do - expect{ Pooler.modify(false, @vmpooler_url, 'myfakehost', nil, {}) }.to raise_error(TokenError) + expect { Pooler.modify(false, @vmpooler_url, 'myfakehost', nil, {}) }.to raise_error(TokenError) end it 'modifies the TTL of a vm' do @@ -123,7 +123,7 @@ describe Pooler do end it 'raises a token error if no token provided' do - expect{ Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil) }.to raise_error(TokenError) + expect { Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil) }.to raise_error(TokenError) end end @@ -197,11 +197,11 @@ describe Pooler do end it "doesn't make a request to revert a vm if snapshot is not provided" do - expect{ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6') + expect { Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6') end it 'raises a TokenError if no token was provided' do - expect{ Pooler.revert(false, @vmpooler_url, 'myfakehost', nil, 'shaaaaaaa') }.to raise_error(TokenError) + expect { Pooler.revert(false, @vmpooler_url, 'myfakehost', nil, 'shaaaaaaa') }.to raise_error(TokenError) end end @@ -220,7 +220,7 @@ describe Pooler do end it 'raises a TokenError if no token was provided' do - expect{ Pooler.disk(false, @vmpooler_url, 'myfakehost', nil, 12) }.to raise_error(TokenError) + expect { Pooler.disk(false, @vmpooler_url, 'myfakehost', nil, 12) }.to raise_error(TokenError) end end end From 6f4039713698884e81d1174a3a7042db6d62d923 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:36:47 +1100 Subject: [PATCH 33/57] (rubocop) Fix Layout/DotPosition --- spec/vmfloaty/auth_spec.rb | 36 ++++++------ spec/vmfloaty/nonstandard_pooler_spec.rb | 8 +-- spec/vmfloaty/pooler_spec.rb | 72 ++++++++++++------------ 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/spec/vmfloaty/auth_spec.rb b/spec/vmfloaty/auth_spec.rb index 1aacaae..5133e37 100644 --- a/spec/vmfloaty/auth_spec.rb +++ b/spec/vmfloaty/auth_spec.rb @@ -15,18 +15,18 @@ describe Pooler do end it 'returns a token from vmpooler' do - stub_request(:post, 'https://first.last:password@vmpooler.example.com/token'). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(:status => 200, :body => @get_token_response, :headers => {}) + stub_request(:post, 'https://first.last:password@vmpooler.example.com/token') + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 200, :body => @get_token_response, :headers => {}) token = Auth.get_token(false, @vmpooler_url, 'first.last', 'password') expect(token).to eq @token end it 'raises a token error if something goes wrong' do - stub_request(:post, 'https://first.last:password@vmpooler.example.com/token'). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(:status => 500, :body => '{"ok":false}', :headers => {}) + stub_request(:post, 'https://first.last:password@vmpooler.example.com/token') + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect { Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError) end @@ -39,17 +39,17 @@ describe Pooler do end it 'deletes the specified token' do - stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y'). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(:status => 200, :body => @delete_token_response, :headers => {}) + stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y') + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 200, :body => @delete_token_response, :headers => {}) expect(Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response) end it 'raises a token error if something goes wrong' do - stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y'). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(:status => 500, :body => '{"ok":false}', :headers => {}) + stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y') + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect { Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError) end @@ -66,17 +66,17 @@ describe Pooler do end it 'checks the status of a token' do - stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(:status => 200, :body => @token_status_response, :headers => {}) + stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 200, :body => @token_status_response, :headers => {}) expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response) end it 'raises a token error if something goes wrong' do - stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(:status => 500, :body => '{"ok":false}', :headers => {}) + stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect { Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError) end diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index cc0f6c0..4b60db9 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -174,10 +174,10 @@ BODY end it 'raises an error if the user tries to modify an unsupported attribute' do - stub_request(:put, 'https://nspooler.example.com/host/myfakehost'). - with(:body => { '{}' => true }, - :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'token-value' }). - to_return(:status => 200, :body => '', :headers => {}) + stub_request(:put, 'https://nspooler.example.com/host/myfakehost') + .with(:body => { '{}' => true }, + :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'token-value' }) + .to_return(:status => 200, :body => '', :headers => {}) details = { :lifetime => 12 } expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) } .to raise_error(ModifyError) diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index 304dd36..eb52710 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -14,16 +14,16 @@ describe Pooler do end it 'returns a hash with operating systems from the pooler' do - stub_request(:get, "#{@vmpooler_url}/vm"). - to_return(:status => 200, :body => @list_response_body, :headers => {}) + stub_request(:get, "#{@vmpooler_url}/vm") + .to_return(:status => 200, :body => @list_response_body, :headers => {}) list = Pooler.list(false, @vmpooler_url, nil) expect(list).to be_an_instance_of Array end it 'filters operating systems based on the filter param' do - stub_request(:get, "#{@vmpooler_url}/vm"). - to_return(:status => 200, :body => @list_response_body, :headers => {}) + stub_request(:get, "#{@vmpooler_url}/vm") + .to_return(:status => 200, :body => @list_response_body, :headers => {}) list = Pooler.list(false, @vmpooler_url, 'deb') expect(list).to be_an_instance_of Array @@ -31,8 +31,8 @@ describe Pooler do end it 'returns nothing if the filter does not match' do - stub_request(:get, "#{@vmpooler_url}/vm"). - to_return(:status => 200, :body => @list_response_body, :headers => {}) + stub_request(:get, "#{@vmpooler_url}/vm") + .to_return(:status => 200, :body => @list_response_body, :headers => {}) list = Pooler.list(false, @vmpooler_url, 'windows') expect(list).to be_an_instance_of Array @@ -47,9 +47,9 @@ describe Pooler do end it 'raises an AuthError if the token is invalid' do - stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). - to_return(:status => 401, :body => '{"ok":false}', :headers => {}) + stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) + .to_return(:status => 401, :body => '{"ok":false}', :headers => {}) vm_hash = {} vm_hash['debian-7-i386'] = 1 @@ -57,9 +57,9 @@ describe Pooler do end it 'retrieves a single vm with a token' do - stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). - to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {}) + stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) + .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {}) vm_hash = {} vm_hash['debian-7-i386'] = 1 @@ -70,9 +70,9 @@ describe Pooler do end it 'retrieves a multiple vms with a token' do - stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). - to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {}) + stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) + .to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {}) vm_hash = {} vm_hash['debian-7-i386'] = 2 @@ -98,10 +98,10 @@ describe Pooler do it 'modifies the TTL of a vm' do modify_hash = { :lifetime => 12 } - stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:body => { '{"lifetime":12}' => true }, - :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). - to_return(:status => 200, :body => @modify_response_body_success, :headers => {}) + stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6") + .with(:body => { '{"lifetime":12}' => true }, + :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) + .to_return(:status => 200, :body => @modify_response_body_success, :headers => {}) modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash) expect(modify_req['ok']).to be true @@ -115,9 +115,9 @@ describe Pooler do end it 'deletes a specified vm' do - stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). - to_return(:status => 200, :body => @delete_response_body_success, :headers => {}) + stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) + .to_return(:status => 200, :body => @delete_response_body_success, :headers => {}) expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile')).to eq @delete_response end @@ -134,9 +134,9 @@ describe Pooler do end it 'prints the status' do - stub_request(:get, "#{@vmpooler_url}/status"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(:status => 200, :body => @status_response_body, :headers => {}) + stub_request(:get, "#{@vmpooler_url}/status") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 200, :body => @status_response_body, :headers => {}) status = Pooler.status(false, @vmpooler_url) expect(status).to be_an_instance_of Hash @@ -158,9 +158,9 @@ describe Pooler do end it 'makes a query about a vm' do - stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(:status => 200, :body => @query_response_body, :headers => {}) + stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 200, :body => @query_response_body, :headers => {}) query_req = Pooler.query(false, @vmpooler_url, 'fq6qlpjlsskycq6') expect(query_req).to be_an_instance_of Hash @@ -173,9 +173,9 @@ describe Pooler do end it 'makes a snapshot for a single vm' do - stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). - to_return(:status => 200, :body => @snapshot_response_body, :headers => {}) + stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) + .to_return(:status => 200, :body => @snapshot_response_body, :headers => {}) snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile') expect(snapshot_req['ok']).to be true @@ -188,9 +188,9 @@ describe Pooler do end it 'makes a request to revert a vm from a snapshot' do - stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). - to_return(:status => 200, :body => @revert_response_body, :headers => {}) + stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) + .to_return(:status => 200, :body => @revert_response_body, :headers => {}) revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve') expect(revert_req['ok']).to be true @@ -212,8 +212,8 @@ describe Pooler do end it 'makes a request to extend disk space of a vm' do - stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12"). - with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) + stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12") + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12) expect(disk_req['ok']).to be true From b2ac1ddf2ff53f62f8773885fb0dac672f195e54 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:39:47 +1100 Subject: [PATCH 34/57] (rubocop) Fix Layout/MultilineMethodCallIndentation --- spec/vmfloaty/auth_spec.rb | 8 ++++---- spec/vmfloaty/nonstandard_pooler_spec.rb | 6 +++--- spec/vmfloaty/utils_spec.rb | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/vmfloaty/auth_spec.rb b/spec/vmfloaty/auth_spec.rb index 5133e37..f110359 100644 --- a/spec/vmfloaty/auth_spec.rb +++ b/spec/vmfloaty/auth_spec.rb @@ -16,8 +16,8 @@ describe Pooler do it 'returns a token from vmpooler' do stub_request(:post, 'https://first.last:password@vmpooler.example.com/token') - .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }) - .to_return(:status => 200, :body => @get_token_response, :headers => {}) + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 200, :body => @get_token_response, :headers => {}) token = Auth.get_token(false, @vmpooler_url, 'first.last', 'password') expect(token).to eq @token @@ -25,8 +25,8 @@ describe Pooler do it 'raises a token error if something goes wrong' do stub_request(:post, 'https://first.last:password@vmpooler.example.com/token') - .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }) - .to_return(:status => 500, :body => '{"ok":false}', :headers => {}) + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(:status => 500, :body => '{"ok":false}', :headers => {}) expect { Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError) end diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 4b60db9..82eba9c 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -175,12 +175,12 @@ BODY it 'raises an error if the user tries to modify an unsupported attribute' do stub_request(:put, 'https://nspooler.example.com/host/myfakehost') - .with(:body => { '{}' => true }, + .with(:body => { '{}' => true }, :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'token-value' }) - .to_return(:status => 200, :body => '', :headers => {}) + .to_return(:status => 200, :body => '', :headers => {}) details = { :lifetime => 12 } expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) } - .to raise_error(ModifyError) + .to raise_error(ModifyError) end it 'modifies the reason of a vm' do diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 2caed14..4f3e4ac 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -174,8 +174,8 @@ describe Utils do service = Service.new(MockOptions.new, 'url' => url) allow(service).to receive(:query) - .with(nil, hostname) - .and_return(response_body) + .with(nil, hostname) + .and_return(response_body) Utils.pretty_print_hosts(nil, service, hostname) end @@ -200,8 +200,8 @@ describe Utils do service = Service.new(MockOptions.new, 'url' => url) allow(service).to receive(:query) - .with(nil, hostname) - .and_return(response_body) + .with(nil, hostname) + .and_return(response_body) Utils.pretty_print_hosts(nil, service, hostname) end @@ -221,8 +221,8 @@ describe Utils do service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns') allow(service).to receive(:query) - .with(nil, hostname) - .and_return(response_body) + .with(nil, hostname) + .and_return(response_body) Utils.pretty_print_hosts(nil, service, hostname) end @@ -242,8 +242,8 @@ describe Utils do service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns') allow(service).to receive(:query) - .with(nil, hostname) - .and_return(response_body) + .with(nil, hostname) + .and_return(response_body) Utils.pretty_print_hosts(nil, service, hostname) end From edaa3e5645ec0ec5cfa54b6d05f8a9ff34ad5504 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:41:22 +1100 Subject: [PATCH 35/57] (rubocop) Fix Layout/EmptyLinesAroundBlockBody --- spec/vmfloaty/nonstandard_pooler_spec.rb | 1 - spec/vmfloaty/service_spec.rb | 2 -- spec/vmfloaty/utils_spec.rb | 1 - 3 files changed, 4 deletions(-) diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 82eba9c..c01d79e 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -23,7 +23,6 @@ describe NonstandardPooler do @get_request_headers_notoken = @get_request_headers.tap do |headers| headers.delete('X-Auth-Token') end - end describe '#list' do diff --git a/spec/vmfloaty/service_spec.rb b/spec/vmfloaty/service_spec.rb index 7e9812a..55e4fb3 100644 --- a/spec/vmfloaty/service_spec.rb +++ b/spec/vmfloaty/service_spec.rb @@ -3,7 +3,6 @@ require_relative '../../lib/vmfloaty/service' describe Service do - describe '#initialize' do it 'store configuration options' do options = MockOptions.new({}) @@ -77,5 +76,4 @@ describe Service do expect(service.token_status(nil, 'token-value')).to eql(status) end end - end diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 4f3e4ac..6933aeb 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -6,7 +6,6 @@ require 'commander/command' require_relative '../../lib/vmfloaty/utils' describe Utils do - describe '#standardize_hostnames' do before :each do @vmpooler_response_body = '{ From bb9e821d5ed359b8a9ce6586af11a885f5492c39 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:43:27 +1100 Subject: [PATCH 36/57] (rubocop) Fix Layout/EmptyLinesAroundClassBody --- lib/vmfloaty/conf.rb | 1 - lib/vmfloaty/http.rb | 1 - lib/vmfloaty/service.rb | 2 -- lib/vmfloaty/ssh.rb | 1 - 4 files changed, 5 deletions(-) diff --git a/lib/vmfloaty/conf.rb b/lib/vmfloaty/conf.rb index b1bfef1..5e572fa 100644 --- a/lib/vmfloaty/conf.rb +++ b/lib/vmfloaty/conf.rb @@ -3,7 +3,6 @@ require 'yaml' class Conf - def self.read_config conf = {} begin diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index b120538..f2ef77c 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -46,5 +46,4 @@ class Http conn end - end diff --git a/lib/vmfloaty/service.rb b/lib/vmfloaty/service.rb index 899f651..e5ad4be 100644 --- a/lib/vmfloaty/service.rb +++ b/lib/vmfloaty/service.rb @@ -6,7 +6,6 @@ require 'vmfloaty/utils' require 'vmfloaty/ssh' class Service - attr_reader :config def initialize(options, config_hash = {}) @@ -135,5 +134,4 @@ class Service def disk(verbose, hostname, disk) @service_object.disk(verbose, url, hostname, token, disk) end - end \ No newline at end of file diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index e20d84d..0b3f9bb 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class Ssh - def self.which(cmd) # Gets path of executable for given command From e6d1fbf954c3015abdfd15222ec2c0b84f9f8d46 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:44:11 +1100 Subject: [PATCH 37/57] (rubocop) Fix Layout/TrailingBlankLines --- lib/vmfloaty/service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty/service.rb b/lib/vmfloaty/service.rb index e5ad4be..123f400 100644 --- a/lib/vmfloaty/service.rb +++ b/lib/vmfloaty/service.rb @@ -134,4 +134,4 @@ class Service def disk(verbose, hostname, disk) @service_object.disk(verbose, url, hostname, token, disk) end -end \ No newline at end of file +end From e8f420a08ce1adc59b7d158986e1706041789bf3 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:46:15 +1100 Subject: [PATCH 38/57] (rubocop) Fix Layout/EmptyLineAfterGuardClause --- lib/vmfloaty/auth.rb | 3 +++ lib/vmfloaty/ssh.rb | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lib/vmfloaty/auth.rb b/lib/vmfloaty/auth.rb index a1fdd60..dcf06c0 100644 --- a/lib/vmfloaty/auth.rb +++ b/lib/vmfloaty/auth.rb @@ -13,6 +13,7 @@ class Auth res_body = JSON.parse(resp.body) return res_body['token'] if res_body['ok'] + raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}" end @@ -24,6 +25,7 @@ class Auth response = conn.delete "token/#{token}" res_body = JSON.parse(response.body) return res_body if res_body['ok'] + raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}" end @@ -36,6 +38,7 @@ class Auth res_body = JSON.parse(response.body) return res_body if res_body['ok'] + raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}" end end diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index 0b3f9bb..5de4313 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -17,11 +17,13 @@ class Ssh def self.ssh(verbose, host_os, token, url) ssh_path = which('ssh') raise 'Could not determine path to ssh' unless ssh_path + os_types = {} os_types[host_os] = 1 response = Pooler.retrieve(verbose, os_types, token, url) raise "Could not get vm from vmpooler:\n #{response}" unless response['ok'] + user = host_os =~ /win/ ? 'Administrator' : 'root' hostname = "#{response[host_os]['hostname']}.#{response['domain']}" From cecea8bc052b28fe28a068bd7054ae6ae997867b Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:47:16 +1100 Subject: [PATCH 39/57] (rubocop) Fix Layout/SpaceAfterNot --- lib/vmfloaty.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index a68fc26..6471d18 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -52,7 +52,7 @@ class Vmfloaty max_pool_request = 5 large_pool_requests = os_types.select { |_,v| v > max_pool_request } - if ! large_pool_requests.empty? && ! force + if !large_pool_requests.empty? && !force STDERR.puts "Requesting vms over #{max_pool_request} requires a --force flag." STDERR.puts 'Try again with `floaty get --force`' exit 1 From 9afae18ee2c42d3fb2e6c01bbae56fcf86d8d6f0 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:48:04 +1100 Subject: [PATCH 40/57] (rubocop) Fix Layout/SpaceAfterComma --- lib/vmfloaty.rb | 2 +- spec/vmfloaty/nonstandard_pooler_spec.rb | 2 +- spec/vmfloaty/service_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 6471d18..a9e3925 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -51,7 +51,7 @@ class Vmfloaty os_types = Utils.generate_os_hash(args) max_pool_request = 5 - large_pool_requests = os_types.select { |_,v| v > max_pool_request } + large_pool_requests = os_types.select { |_, v| v > max_pool_request } if !large_pool_requests.empty? && !force STDERR.puts "Requesting vms over #{max_pool_request} requires a --force flag." STDERR.puts 'Try again with `floaty get --force`' diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index c01d79e..dcddbcf 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -153,7 +153,7 @@ BODY end it 'retrieves a multiple vms with a token' do - stub_request(:post,"#{@nspooler_url}/host/aix-7.1-power+solaris-10-sparc+solaris-10-sparc") + stub_request(:post, "#{@nspooler_url}/host/aix-7.1-power+solaris-10-sparc+solaris-10-sparc") .with(:headers => @post_request_headers) .to_return(:status => 200, :body => @retrieve_response_body_many, :headers => {}) diff --git a/spec/vmfloaty/service_spec.rb b/spec/vmfloaty/service_spec.rb index 55e4fb3..2ee0bc9 100644 --- a/spec/vmfloaty/service_spec.rb +++ b/spec/vmfloaty/service_spec.rb @@ -44,7 +44,7 @@ describe Service do describe '#delete_token' do it 'deletes a token' do - service = Service.new(MockOptions.new,'user' => 'first.last', 'url' => 'http://default.url') + service = Service.new(MockOptions.new, 'user' => 'first.last', 'url' => 'http://default.url') allow(Commander::UI).to(receive(:password) .with('Enter your pooler service password:', '*') .and_return('hunter2')) From f2ab052fa4b96683a01f508386b418ce9feeffce Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:49:03 +1100 Subject: [PATCH 41/57] (rubocop) Fix Layout/ExtraSpacing --- spec/vmfloaty/pooler_spec.rb | 2 +- spec/vmfloaty/utils_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index eb52710..115e5cc 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -213,7 +213,7 @@ describe Pooler do it 'makes a request to extend disk space of a vm' do stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12") - .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) + .with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @disk_response_body_success, :headers => {}) disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12) expect(disk_req['ok']).to be true diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index 6933aeb..dafdbdb 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -155,7 +155,7 @@ describe Utils do end describe '#pretty_print_hosts' do - let(:url) { 'http://pooler.example.com' } + let(:url) { 'http://pooler.example.com' } it 'prints a vmpooler output with host fqdn, template and duration info' do hostname = 'mcpy42eqjxli9g2' From f2167f8be7930b7cfb6715c2f53adcaf230cd3a8 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 12:59:34 +1100 Subject: [PATCH 42/57] (rubocop) Fix Layout/CaseIndentation --- lib/vmfloaty.rb | 34 +++++++------- lib/vmfloaty/utils.rb | 106 +++++++++++++++++++++--------------------- 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index a9e3925..8b64e3c 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -371,23 +371,23 @@ class Vmfloaty begin case action - when 'get' - token = service.get_new_token(verbose) - puts token - when 'delete' - result = service.delete_token(verbose, options.token) - puts result - when 'status' - token_value = options.token - token_value = args[1] if token_value.nil? - status = service.token_status(verbose, token_value) - puts status - when nil - STDERR.puts 'No action provided' - exit 1 - else - STDERR.puts "Unknown action: #{action}" - exit 1 + when 'get' + token = service.get_new_token(verbose) + puts token + when 'delete' + result = service.delete_token(verbose, options.token) + puts result + when 'status' + token_value = options.token + token_value = args[1] if token_value.nil? + status = service.token_status(verbose, token_value) + puts status + when nil + STDERR.puts 'No action provided' + exit 1 + else + STDERR.puts "Unknown action: #{action}" + exit 1 end rescue TokenError => e STDERR.puts e diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 7bfdd52..d2e591e 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -84,24 +84,24 @@ class Utils host_data = response[hostname] case service.type - when 'Pooler' - tag_pairs = [] - unless host_data['tags'].nil? - tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } - end - duration = "#{host_data['running']}/#{host_data['lifetime']} hours" - metadata = [host_data['template'], duration, *tag_pairs] - puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})" - when 'NonstandardPooler' - line = "- #{host_data['fqdn']} (#{host_data['os_triple']}" - line += ", #{host_data['hours_left_on_reservation']}h remaining" - unless host_data['reserved_for_reason'].empty? - line += ", reason: #{host_data['reserved_for_reason']}" - end - line += ')' - puts line - else - raise "Invalid service type #{service.type}" + when 'Pooler' + tag_pairs = [] + unless host_data['tags'].nil? + tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } + end + duration = "#{host_data['running']}/#{host_data['lifetime']} hours" + metadata = [host_data['template'], duration, *tag_pairs] + puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})" + when 'NonstandardPooler' + line = "- #{host_data['fqdn']} (#{host_data['os_triple']}" + line += ", #{host_data['hours_left_on_reservation']}h remaining" + unless host_data['reserved_for_reason'].empty? + line += ", reason: #{host_data['reserved_for_reason']}" + end + line += ')' + puts line + else + raise "Invalid service type #{service.type}" end rescue StandardError => e STDERR.puts("Something went wrong while trying to gather information on #{hostname}:") @@ -114,45 +114,45 @@ class Utils status_response = service.status(verbose) case service.type - when 'Pooler' - message = status_response['status']['message'] - pools = status_response['pools'] - pools.select! { |_, pool| pool['ready'] < pool['max'] } unless verbose + when 'Pooler' + message = status_response['status']['message'] + pools = status_response['pools'] + pools.select! { |_, pool| pool['ready'] < pool['max'] } unless verbose - width = pools.keys.map(&:length).max - pools.each do |name, pool| - begin - max = pool['max'] - ready = pool['ready'] - pending = pool['pending'] - missing = max - ready - pending - char = 'o' - puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}" - rescue StandardError => e - puts "#{name.ljust(width)} #{e.red}" - end + width = pools.keys.map(&:length).max + pools.each do |name, pool| + begin + max = pool['max'] + ready = pool['ready'] + pending = pool['pending'] + missing = max - ready - pending + char = 'o' + puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}" + rescue StandardError => e + puts "#{name.ljust(width)} #{e.red}" end - puts message.colorize(status_response['status']['ok'] ? :default : :red) - when 'NonstandardPooler' - pools = status_response - pools.delete 'ok' - pools.select! { |_, pool| pool['available_hosts'] < pool['total_hosts'] } unless verbose + end + puts message.colorize(status_response['status']['ok'] ? :default : :red) + when 'NonstandardPooler' + pools = status_response + pools.delete 'ok' + pools.select! { |_, pool| pool['available_hosts'] < pool['total_hosts'] } unless verbose - width = pools.keys.map(&:length).max - pools.each do |name, pool| - begin - max = pool['total_hosts'] - ready = pool['available_hosts'] - pending = pool['pending'] || 0 # not available for nspooler - missing = max - ready - pending - char = 'o' - puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}" - rescue StandardError => e - puts "#{name.ljust(width)} #{e.red}" - end + width = pools.keys.map(&:length).max + pools.each do |name, pool| + begin + max = pool['total_hosts'] + ready = pool['available_hosts'] + pending = pool['pending'] || 0 # not available for nspooler + missing = max - ready - pending + char = 'o' + puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}" + rescue StandardError => e + puts "#{name.ljust(width)} #{e.red}" end - else - raise "Invalid service type #{service.type}" + end + else + raise "Invalid service type #{service.type}" end end From 851009b1f62b19c138942bd9f514b7290cae985b Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:08:00 +1100 Subject: [PATCH 43/57] (rubocop) Fix Layout/AlignHash & Layout/IndentHash --- .rubocop.yml | 4 ++ lib/vmfloaty.rb | 8 +-- lib/vmfloaty/utils.rb | 8 +-- spec/vmfloaty/nonstandard_pooler_spec.rb | 18 ++--- spec/vmfloaty/pooler_spec.rb | 4 +- spec/vmfloaty/service_spec.rb | 14 ++-- spec/vmfloaty/utils_spec.rb | 88 ++++++++++++------------ 7 files changed, 74 insertions(+), 70 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e0a6614..0430a26 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,3 +12,7 @@ Style/TrailingCommaInArrayLiteral: EnforcedStyleForMultiline: comma Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma +Layout/AlignHash: + EnforcedHashRocketStyle: table +Layout/IndentHash: + EnforcedStyle: consistent diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 8b64e3c..713a81e 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -152,10 +152,10 @@ class Vmfloaty tags = options.tags ? JSON.parse(options.tags) : nil modify_hash = { - :lifetime => options.lifetime, - :disk => options.disk, - :tags => tags, - :reason => options.reason, + :lifetime => options.lifetime, + :disk => options.disk, + :tags => tags, + :reason => options.reason, } modify_hash.delete_if { |_, value| value.nil? } diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index d2e591e..8652ba5 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -176,10 +176,10 @@ class Utils def self.get_service_config(config, options) # The top-level url, user, and token values in the config file are treated as defaults service_config = { - 'url' => config['url'], - 'user' => config['user'], - 'token' => config['token'], - 'type' => config['type'] || 'vmpooler', + 'url' => config['url'], + 'user' => config['user'], + 'token' => config['token'], + 'type' => config['type'] || 'vmpooler', } if config['services'] diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index dcddbcf..2e8b740 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -9,16 +9,16 @@ describe NonstandardPooler do before :each do @nspooler_url = 'https://nspooler.example.com' @post_request_headers = { - 'Accept' => '*/*', + 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent' => 'Faraday v0.9.2', - 'X-Auth-Token' => 'token-value', + 'User-Agent' => 'Faraday v0.9.2', + 'X-Auth-Token' => 'token-value', } @get_request_headers = { - 'Accept' => '*/*', + 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent' => 'Faraday v0.9.2', - 'X-Auth-Token' => 'token-value', + 'User-Agent' => 'Faraday v0.9.2', + 'X-Auth-Token' => 'token-value', } @get_request_headers_notoken = @get_request_headers.tap do |headers| headers.delete('X-Auth-Token') @@ -174,8 +174,8 @@ BODY it 'raises an error if the user tries to modify an unsupported attribute' do stub_request(:put, 'https://nspooler.example.com/host/myfakehost') - .with(:body => { '{}' => true }, - :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'token-value' }) + .with(:body => { '{}' => true }, + :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'token-value' }) .to_return(:status => 200, :body => '', :headers => {}) details = { :lifetime => 12 } expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) } @@ -185,7 +185,7 @@ BODY it 'modifies the reason of a vm' do modify_request_body = { '{"reserved_for_reason":"testing"}' => true } stub_request(:put, "#{@nspooler_url}/host/myfakehost") - .with(:body => modify_request_body, + .with(:body => modify_request_body, :headers => @post_request_headers) .to_return(:status => 200, :body => '{"ok": true}', :headers => {}) diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index 115e5cc..1f26e70 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -99,8 +99,8 @@ describe Pooler do it 'modifies the TTL of a vm' do modify_hash = { :lifetime => 12 } stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6") - .with(:body => { '{"lifetime":12}' => true }, - :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) + .with(:body => { '{"lifetime":12}' => true }, + :headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Faraday v0.9.2', 'X-Auth-Token' => 'mytokenfile' }) .to_return(:status => 200, :body => @modify_response_body_success, :headers => {}) modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash) diff --git a/spec/vmfloaty/service_spec.rb b/spec/vmfloaty/service_spec.rb index 2ee0bc9..e622c15 100644 --- a/spec/vmfloaty/service_spec.rb +++ b/spec/vmfloaty/service_spec.rb @@ -58,17 +58,17 @@ describe Service do describe '#token_status' do it 'reports the status of a token' do config = { - 'user' => 'first.last', - 'url' => 'http://default.url', + 'user' => 'first.last', + 'url' => 'http://default.url', } options = MockOptions.new('token' => 'token-value') service = Service.new(options, config) status = { - 'ok' => true, - 'user' => config['user'], - 'created' => '2017-09-22 02:04:18 +0000', - 'last_accessed' => '2017-09-22 02:04:28 +0000', - 'reserved_hosts' => [], + 'ok' => true, + 'user' => config['user'], + 'created' => '2017-09-22 02:04:18 +0000', + 'last_accessed' => '2017-09-22 02:04:28 +0000', + 'reserved_hosts' => [], } allow(Auth).to(receive(:token_status) .with(nil, config['url'], 'token-value') diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index dafdbdb..ae0eb8c 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -31,13 +31,13 @@ describe Utils do it 'formats a result from vmpooler into a hash of os to hostnames' do result = Utils.standardize_hostnames(JSON.parse(@vmpooler_response_body)) - expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'], + expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'], 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net']) end it 'formats a result from the nonstandard pooler into a hash of os to hostnames' do result = Utils.standardize_hostnames(JSON.parse(@nonstandard_response_body)) - expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'], + expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'], 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net']) end end @@ -45,11 +45,11 @@ describe Utils do describe '#format_host_output' do before :each do @vmpooler_results = { - 'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'], + 'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'], 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'], } @nonstandard_results = { - 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'], + 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'], 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'], } @vmpooler_output = <<-OUT.chomp @@ -85,23 +85,23 @@ describe Utils do describe '#get_service_config' do before :each do @default_config = { - 'url' => 'http://default.url', - 'user' => 'first.last.default', - 'token' => 'default-token', + 'url' => 'http://default.url', + 'user' => 'first.last.default', + 'token' => 'default-token', } @services_config = { - 'services' => { - 'vm' => { - 'url' => 'http://vmpooler.url', - 'user' => 'first.last.vmpooler', - 'token' => 'vmpooler-token', - }, - 'ns' => { - 'url' => 'http://nspooler.url', - 'user' => 'first.last.nspooler', - 'token' => 'nspooler-token', - }, + 'services' => { + 'vm' => { + 'url' => 'http://vmpooler.url', + 'user' => 'first.last.vmpooler', + 'token' => 'vmpooler-token', }, + 'ns' => { + 'url' => 'http://nspooler.url', + 'user' => 'first.last.nspooler', + 'token' => 'nspooler-token', + }, + }, } end @@ -160,12 +160,12 @@ describe Utils do it 'prints a vmpooler output with host fqdn, template and duration info' do hostname = 'mcpy42eqjxli9g2' response_body = { hostname => { - 'template' => 'ubuntu-1604-x86_64', - 'lifetime' => 12, - 'running' => 9.66, - 'state' => 'running', - 'ip' => '127.0.0.1', - 'domain' => 'delivery.mycompany.net', + 'template' => 'ubuntu-1604-x86_64', + 'lifetime' => 12, + 'running' => 9.66, + 'state' => 'running', + 'ip' => '127.0.0.1', + 'domain' => 'delivery.mycompany.net', } } output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)' @@ -182,16 +182,16 @@ describe Utils do it 'prints a vmpooler output with host fqdn, template, duration info, and tags when supplied' do hostname = 'aiydvzpg23r415q' response_body = { hostname => { - 'template' => 'redhat-7-x86_64', - 'lifetime' => 48, - 'running' => 7.67, - 'state' => 'running', - 'tags' => { - 'user' => 'bob', - 'role' => 'agent', - }, - 'ip' => '127.0.0.1', - 'domain' => 'delivery.mycompany.net', + 'template' => 'redhat-7-x86_64', + 'lifetime' => 48, + 'running' => 7.67, + 'state' => 'running', + 'tags' => { + 'user' => 'bob', + 'role' => 'agent', + }, + 'ip' => '127.0.0.1', + 'domain' => 'delivery.mycompany.net', } } output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)' @@ -208,11 +208,11 @@ describe Utils do it 'prints a nonstandard pooler output with host, template, and time remaining' do hostname = 'sol11-9.delivery.mycompany.net' response_body = { hostname => { - 'fqdn' => hostname, - 'os_triple' => 'solaris-11-sparc', - 'reserved_by_user' => 'first.last', - 'reserved_for_reason' => '', - 'hours_left_on_reservation' => 35.89, + 'fqdn' => hostname, + 'os_triple' => 'solaris-11-sparc', + 'reserved_by_user' => 'first.last', + 'reserved_for_reason' => '', + 'hours_left_on_reservation' => 35.89, } } output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)' @@ -229,11 +229,11 @@ describe Utils do it 'prints a nonstandard pooler output with host, template, time remaining, and reason' do hostname = 'sol11-9.delivery.mycompany.net' response_body = { hostname => { - 'fqdn' => hostname, - 'os_triple' => 'solaris-11-sparc', - 'reserved_by_user' => 'first.last', - 'reserved_for_reason' => 'testing', - 'hours_left_on_reservation' => 35.89, + 'fqdn' => hostname, + 'os_triple' => 'solaris-11-sparc', + 'reserved_by_user' => 'first.last', + 'reserved_for_reason' => 'testing', + 'hours_left_on_reservation' => 35.89, } } output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)' From 7d9545f202ee27492ac1ff9cfc2d7553a8bcc52a Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:11:07 +1100 Subject: [PATCH 44/57] (rubocop) Fix Layout/IndentHeredoc --- spec/vmfloaty/nonstandard_pooler_spec.rb | 190 +++++++++++------------ spec/vmfloaty/utils_spec.rb | 16 +- 2 files changed, 103 insertions(+), 103 deletions(-) diff --git a/spec/vmfloaty/nonstandard_pooler_spec.rb b/spec/vmfloaty/nonstandard_pooler_spec.rb index 2e8b740..f6a179e 100644 --- a/spec/vmfloaty/nonstandard_pooler_spec.rb +++ b/spec/vmfloaty/nonstandard_pooler_spec.rb @@ -27,22 +27,22 @@ describe NonstandardPooler do describe '#list' do before :each do - @status_response_body = <<-BODY -{ - "ok": true, - "solaris-10-sparc": { - "total_hosts": 11, - "available_hosts": 11 - }, - "ubuntu-16.04-power8": { - "total_hosts": 10, - "available_hosts": 10 - }, - "aix-7.2-power": { - "total_hosts": 5, - "available_hosts": 4 - } -} + @status_response_body = <<~BODY + { + "ok": true, + "solaris-10-sparc": { + "total_hosts": 11, + "available_hosts": 11 + }, + "ubuntu-16.04-power8": { + "total_hosts": 10, + "available_hosts": 10 + }, + "aix-7.2-power": { + "total_hosts": 5, + "available_hosts": 4 + } + } BODY end @@ -75,24 +75,24 @@ describe NonstandardPooler do describe '#list_active' do before :each do - @token_status_body_active = <<-BODY -{ - "ok": true, - "user": "first.last", - "created": "2017-09-18 01:25:41 +0000", - "last_accessed": "2017-09-21 19:46:25 +0000", - "reserved_hosts": ["sol10-9", "sol10-11"] -} -BODY - @token_status_body_empty = <<-BODY -{ - "ok": true, - "user": "first.last", - "created": "2017-09-18 01:25:41 +0000", - "last_accessed": "2017-09-21 19:46:25 +0000", - "reserved_hosts": [] -} -BODY + @token_status_body_active = <<~BODY + { + "ok": true, + "user": "first.last", + "created": "2017-09-18 01:25:41 +0000", + "last_accessed": "2017-09-21 19:46:25 +0000", + "reserved_hosts": ["sol10-9", "sol10-11"] + } + BODY + @token_status_body_empty = <<~BODY + { + "ok": true, + "user": "first.last", + "created": "2017-09-18 01:25:41 +0000", + "last_accessed": "2017-09-21 19:46:25 +0000", + "reserved_hosts": [] + } + BODY end it 'prints an output of fqdn, template, and duration' do @@ -107,28 +107,28 @@ BODY describe '#retrieve' do before :each do - @retrieve_response_body_single = <<-BODY -{ - "ok": true, - "solaris-11-sparc": { - "hostname": "sol11-4.delivery.puppetlabs.net" - } -} -BODY - @retrieve_response_body_many = <<-BODY -{ - "ok": true, - "solaris-10-sparc": { - "hostname": [ - "sol10-9.delivery.puppetlabs.net", - "sol10-10.delivery.puppetlabs.net" - ] - }, - "aix-7.1-power": { - "hostname": "pe-aix-71-ci-acceptance.delivery.puppetlabs.net" - } -} -BODY + @retrieve_response_body_single = <<~BODY + { + "ok": true, + "solaris-11-sparc": { + "hostname": "sol11-4.delivery.puppetlabs.net" + } + } + BODY + @retrieve_response_body_many = <<~BODY + { + "ok": true, + "solaris-10-sparc": { + "hostname": [ + "sol10-9.delivery.puppetlabs.net", + "sol10-10.delivery.puppetlabs.net" + ] + }, + "aix-7.1-power": { + "hostname": "pe-aix-71-ci-acceptance.delivery.puppetlabs.net" + } + } + BODY end it 'raises an AuthError if the token is invalid' do @@ -199,23 +199,23 @@ BODY before :each do @status_response_body = '{"capacity":{"current":716,"total":717,"percent": 99.9},"status":{"ok":true,"message":"Battle station fully armed and operational."}}' # TODO: make this report stuff like 'broken' - @status_response_body = <<-BODY -{ - "ok": true, - "solaris-10-sparc": { - "total_hosts": 11, - "available_hosts": 10 - }, - "ubuntu-16.04-power8": { - "total_hosts": 10, - "available_hosts": 10 - }, - "aix-7.2-power": { - "total_hosts": 5, - "available_hosts": 4 - } -} -BODY + @status_response_body = <<~BODY + { + "ok": true, + "solaris-10-sparc": { + "total_hosts": 11, + "available_hosts": 10 + }, + "ubuntu-16.04-power8": { + "total_hosts": 10, + "available_hosts": 10 + }, + "aix-7.2-power": { + "total_hosts": 5, + "available_hosts": 4 + } + } + BODY end it 'prints the status' do @@ -230,16 +230,16 @@ BODY describe '#summary' do before :each do - @status_response_body = <<-BODY -{ - "ok": true, - "total": 57, - "available": 39, - "in_use": 16, - "resetting": 2, - "broken": 0 -} -BODY + @status_response_body = <<~BODY + { + "ok": true, + "total": 57, + "available": 39, + "in_use": 16, + "resetting": 2, + "broken": 0 + } + BODY end it 'prints the summary' do @@ -254,18 +254,18 @@ BODY describe '#query' do before :each do - @query_response_body = <<-BODY -{ - "ok": true, - "sol10-11": { - "fqdn": "sol10-11.delivery.puppetlabs.net", - "os_triple": "solaris-10-sparc", - "reserved_by_user": "first.last", - "reserved_for_reason": "testing", - "hours_left_on_reservation": 29.12 - } -} -BODY + @query_response_body = <<~BODY + { + "ok": true, + "sol10-11": { + "fqdn": "sol10-11.delivery.puppetlabs.net", + "os_triple": "solaris-10-sparc", + "reserved_by_user": "first.last", + "reserved_for_reason": "testing", + "hours_left_on_reservation": 29.12 + } + } + BODY end it 'makes a query about a vm' do diff --git a/spec/vmfloaty/utils_spec.rb b/spec/vmfloaty/utils_spec.rb index ae0eb8c..7fd795b 100644 --- a/spec/vmfloaty/utils_spec.rb +++ b/spec/vmfloaty/utils_spec.rb @@ -52,15 +52,15 @@ describe Utils do 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'], 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'], } - @vmpooler_output = <<-OUT.chomp -- dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64) -- gdoy8q3nckuob0i.delivery.mycompany.net (ubuntu-1610-x86_64) -- ctnktsd0u11p9tm.delivery.mycompany.net (ubuntu-1610-x86_64) + @vmpooler_output = <<~OUT.chomp + - dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64) + - gdoy8q3nckuob0i.delivery.mycompany.net (ubuntu-1610-x86_64) + - ctnktsd0u11p9tm.delivery.mycompany.net (ubuntu-1610-x86_64) OUT - @nonstandard_output = <<-OUT.chomp -- sol10-10.delivery.mycompany.net (solaris-10-sparc) -- sol10-11.delivery.mycompany.net (solaris-10-sparc) -- power8-ubuntu16.04-6.delivery.mycompany.net (ubuntu-16.04-power8) + @nonstandard_output = <<~OUT.chomp + - sol10-10.delivery.mycompany.net (solaris-10-sparc) + - sol10-11.delivery.mycompany.net (solaris-10-sparc) + - power8-ubuntu16.04-6.delivery.mycompany.net (ubuntu-16.04-power8) OUT end it 'formats a hostname hash from vmpooler into a list that includes the os' do From c78ad33104bf5a19a54b37e06f3670e9e82f9bce Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:12:33 +1100 Subject: [PATCH 45/57] (rubocop) Fix Layout/LeadingCommentSpace --- spec/vmfloaty/pooler_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/vmfloaty/pooler_spec.rb b/spec/vmfloaty/pooler_spec.rb index 1f26e70..5c61978 100644 --- a/spec/vmfloaty/pooler_spec.rb +++ b/spec/vmfloaty/pooler_spec.rb @@ -129,7 +129,7 @@ describe Pooler do describe '#status' do before :each do - #smaller version + # smaller version @status_response_body = '{"capacity":{"current":716,"total":717,"percent": 99.9},"status":{"ok":true,"message":"Battle station fully armed and operational."}}' end From c97af3f7db45c322e0f3bcb426ef32f515630fd8 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:15:53 +1100 Subject: [PATCH 46/57] (rubocop) Fix Performance/RegexpMatch --- lib/vmfloaty/ssh.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index 5de4313..9adee9c 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -24,7 +24,7 @@ class Ssh response = Pooler.retrieve(verbose, os_types, token, url) raise "Could not get vm from vmpooler:\n #{response}" unless response['ok'] - user = host_os =~ /win/ ? 'Administrator' : 'root' + user = /win/.match?(host_os) ? 'Administrator' : 'root' hostname = "#{response[host_os]['hostname']}.#{response['domain']}" cmd = "#{ssh_path} #{user}@#{hostname}" From 2a05f0d976b835b50dc9d26ece6548978560fdd6 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:18:24 +1100 Subject: [PATCH 47/57] (rubocop) Fix Lint/ScriptPermission --- lib/vmfloaty.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 713a81e..a2defb8 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -1,4 +1,3 @@ -#!/usr/bin/env ruby # frozen_string_literal: true require 'rubygems' From f0863e7fb06b9d7e9ed937f621e8a9dc0871fe2e Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:19:54 +1100 Subject: [PATCH 48/57] (rubocop) Fix Lint/UnusedMethodArgument --- lib/vmfloaty/nonstandard_pooler.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vmfloaty/nonstandard_pooler.rb b/lib/vmfloaty/nonstandard_pooler.rb index 0e1e449..855fa84 100644 --- a/lib/vmfloaty/nonstandard_pooler.rb +++ b/lib/vmfloaty/nonstandard_pooler.rb @@ -71,15 +71,15 @@ class NonstandardPooler response.body.empty? ? {} : JSON.parse(response.body) end - def self.disk(verbose, url, hostname, token, disk) + def self.disk(_verbose, _url, _hostname, _token, _disk) raise ModifyError, 'Configured service type does not support modification of disk space' end - def self.snapshot(verbose, url, hostname, token) + def self.snapshot(_verbose, _url, _hostname, _token) raise ModifyError, 'Configured service type does not support snapshots' end - def self.revert(verbose, url, hostname, token, snapshot_sha) + def self.revert(_verbose, _url, _hostname, _token, _snapshot_sha) raise ModifyError, 'Configured service type does not support snapshots' end From 63eb49c747910490adbb4ad2b85089a8c446c122 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:20:57 +1100 Subject: [PATCH 49/57] (rubocop) Fix Lint/UnusedBlockArgument --- lib/vmfloaty/nonstandard_pooler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty/nonstandard_pooler.rb b/lib/vmfloaty/nonstandard_pooler.rb index 855fa84..f504686 100644 --- a/lib/vmfloaty/nonstandard_pooler.rb +++ b/lib/vmfloaty/nonstandard_pooler.rb @@ -49,7 +49,7 @@ class NonstandardPooler raise TokenError, 'Token provided was nil; Request cannot be made to modify VM' end - modify_hash.each do |key, value| + modify_hash.each do |key, _value| unless %i[reason reserved_for_reason].include? key raise ModifyError, "Configured service type does not support modification of #{key}" end From 66993b43fddb7e58e89b0ead60a0d1979eb40f47 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:22:01 +1100 Subject: [PATCH 50/57] (rubocop) Fix Gemspec/OrderedDependencies --- vmfloaty.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmfloaty.gemspec b/vmfloaty.gemspec index 455fce0..6947bf3 100644 --- a/vmfloaty.gemspec +++ b/vmfloaty.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.test_files = Dir['spec/**/*'] s.require_path = 'lib' + s.add_dependency 'colorize', '~> 0.8.1' s.add_dependency 'commander', '~> 4.4.3' s.add_dependency 'faraday', '~> 0.9.0' - s.add_dependency 'colorize', '~> 0.8.1' end From e1379a8b9c2723f9c4e1e2a23d2983daf6bd5a6a Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:25:33 +1100 Subject: [PATCH 51/57] (rubocop) Fix Naming/PredicateName --- lib/vmfloaty/http.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index f2ef77c..b1984b8 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -4,7 +4,7 @@ require 'faraday' require 'uri' class Http - def self.is_url(url) + def self.url?(url) # This method exists because it seems like Farady # has no handling around if a user gives us a URI # with no protocol on the beginning of the URL @@ -19,7 +19,7 @@ class Http def self.get_conn(verbose, url) raise 'Did not provide a url to connect to' if url.nil? - url = "https://#{url}" unless is_url(url) + url = "https://#{url}" unless url?(url) conn = Faraday.new(:url => url, :ssl => { :verify => false }) do |faraday| faraday.request :url_encoded @@ -35,7 +35,7 @@ class Http raise 'You did not provide a user to authenticate with' if user.nil? - url = "https://#{url}" unless is_url(url) + url = "https://#{url}" unless url?(url) conn = Faraday.new(:url => url, :ssl => { :verify => false }) do |faraday| faraday.request :url_encoded From e50d4b32593a5951bc6746f2b75fa71308cc09c2 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:27:25 +1100 Subject: [PATCH 52/57] (rubocop) Fix Naming/HeredocDelimiterNaming --- lib/vmfloaty.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index a2defb8..c2170a3 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -431,13 +431,13 @@ class Vmfloaty command :completion do |c| c.syntax = 'floaty completion [options]' c.summary = 'Outputs path to completion script' - c.description = Utils.strip_heredoc(<<-EOF) + c.description = Utils.strip_heredoc(<<-DESCRIPTION) Outputs path to a completion script for the specified shell (or 'bash' if not specified). This makes it easy to add the completion script to your profile: source $(floaty completion --shell bash) This subcommand will exit non-zero with an error message if no completion script is available for the requested shell. - EOF + DESCRIPTION c.example 'Gets path to bash tab completion script', 'floaty completion --shell bash' c.option '--shell STRING', String, 'Shell to request completion script for' c.action do |_, options| From af6dc740e4b3cfb55e8a7d1118376f4c151c6e6e Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 13:28:43 +1100 Subject: [PATCH 53/57] (rubocop) Fix Naming/UncommunicativeMethodParamName --- lib/vmfloaty/service.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vmfloaty/service.rb b/lib/vmfloaty/service.rb index 123f400..648e71b 100644 --- a/lib/vmfloaty/service.rb +++ b/lib/vmfloaty/service.rb @@ -14,16 +14,16 @@ class Service @service_object = Utils.get_service_object @config['type'] end - def method_missing(m, *args, &block) - if @service_object.respond_to? m - @service_object.send(m, *args, &block) + def method_missing(method_name, *args, &block) + if @service_object.respond_to?(method_name) + @service_object.send(method_name, *args, &block) else super end end - def respond_to_missing?(m, *) - @service_object.respond_to?(m) || super + def respond_to_missing?(method_name, *) + @service_object.respond_to?(method_name) || super end def url From 426e9ce96bbcedf036121f898156d0be9e8123c3 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 15:37:50 +1100 Subject: [PATCH 54/57] (rubocop) Fix Style/ConditionalAssignment --- lib/vmfloaty/utils.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 8652ba5..3f2d433 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -66,12 +66,7 @@ class Utils os_types = {} os_args.each do |arg| os_arr = arg.split('=') - if os_arr.size == 1 - # assume they didn't specify an = sign if split returns 1 size - os_types[os_arr[0]] = 1 - else - os_types[os_arr[0]] = os_arr[1].to_i - end + os_types[os_arr[0]] = os_arr.size == 1 ? 1 : os_arr[1].to_i end os_types end From 6e1f626d7b16ccc387e8fe6ba2af4eb88ae45985 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 15:40:17 +1100 Subject: [PATCH 55/57] (rubocop) Fix Style/IfUnlessModifier --- lib/vmfloaty.rb | 8 ++----- lib/vmfloaty/nonstandard_pooler.rb | 16 ++++--------- lib/vmfloaty/pooler.rb | 36 ++++++++---------------------- lib/vmfloaty/utils.rb | 16 ++++--------- 4 files changed, 19 insertions(+), 57 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index c2170a3..dfe390a 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -300,9 +300,7 @@ class Vmfloaty hostname = args[0] snapshot_sha = args[1] || options.snapshot - if args[1] && options.snapshot - STDERR.puts "Two snapshot arguments were given....using snapshot #{snapshot_sha}" - end + STDERR.puts "Two snapshot arguments were given....using snapshot #{snapshot_sha}" if args[1] && options.snapshot begin revert_req = service.revert(verbose, hostname, snapshot_sha) @@ -419,9 +417,7 @@ class Vmfloaty host_os = args.first - if args.length > 1 - STDERR.puts "Can't ssh to multiple hosts; Using #{host_os} only..." - end + STDERR.puts "Can't ssh to multiple hosts; Using #{host_os} only..." if args.length > 1 service.ssh(verbose, host_os, use_token) exit 0 diff --git a/lib/vmfloaty/nonstandard_pooler.rb b/lib/vmfloaty/nonstandard_pooler.rb index f504686..f5451b7 100644 --- a/lib/vmfloaty/nonstandard_pooler.rb +++ b/lib/vmfloaty/nonstandard_pooler.rb @@ -27,9 +27,7 @@ class NonstandardPooler conn.headers['X-AUTH-TOKEN'] = token if token os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+') - if os_string.empty? - raise MissingParamError, 'No operating systems provided to obtain.' - end + raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty? response = conn.post "host/#{os_string}" @@ -45,14 +43,10 @@ class NonstandardPooler end def self.modify(verbose, url, hostname, token, modify_hash) - if token.nil? - raise TokenError, 'Token provided was nil; Request cannot be made to modify VM' - end + raise TokenError, 'Token provided was nil; Request cannot be made to modify VM' if token.nil? modify_hash.each do |key, _value| - unless %i[reason reserved_for_reason].include? key - raise ModifyError, "Configured service type does not support modification of #{key}" - end + raise ModifyError, "Configured service type does not support modification of #{key}" unless %i[reason reserved_for_reason].include? key end if modify_hash[:reason] @@ -84,9 +78,7 @@ class NonstandardPooler end def self.delete(verbose, url, hosts, token) - if token.nil? - raise TokenError, 'Token provided was nil; Request cannot be made to delete VM' - end + raise TokenError, 'Token provided was nil; Request cannot be made to delete VM' if token.nil? conn = Http.get_conn(verbose, url) diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 8eceb8c..f8d8633 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -24,9 +24,7 @@ class Pooler def self.list_active(verbose, url, token) status = Auth.token_status(verbose, url, token) vms = [] - if status[token] && status[token]['vms'] - vms = status[token]['vms']['running'] - end + vms = status[token]['vms']['running'] if status[token] && status[token]['vms'] vms end @@ -38,9 +36,7 @@ class Pooler conn.headers['X-AUTH-TOKEN'] = token if token os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+') - if os_string.empty? - raise MissingParamError, 'No operating systems provided to obtain.' - end + raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty? response = conn.post "vm/#{os_string}" @@ -56,14 +52,10 @@ class Pooler end def self.modify(verbose, url, hostname, token, modify_hash) - if token.nil? - raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' - end + raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' if token.nil? modify_hash.keys.each do |key| - unless %i[tags lifetime disk].include? key - raise ModifyError, "Configured service type does not support modification of #{key}." - end + raise ModifyError, "Configured service type does not support modification of #{key}." unless %i[tags lifetime disk].include? key end conn = Http.get_conn(verbose, url) @@ -84,9 +76,7 @@ class Pooler end def self.disk(verbose, url, hostname, token, disk) - if token.nil? - raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' - end + raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' if token.nil? conn = Http.get_conn(verbose, url) conn.headers['X-AUTH-TOKEN'] = token @@ -98,9 +88,7 @@ class Pooler end def self.delete(verbose, url, hosts, token) - if token.nil? - raise TokenError, 'Token provided was nil. Request cannot be made to delete vm' - end + raise TokenError, 'Token provided was nil. Request cannot be made to delete vm' if token.nil? conn = Http.get_conn(verbose, url) @@ -143,9 +131,7 @@ class Pooler end def self.snapshot(verbose, url, hostname, token) - if token.nil? - raise TokenError, 'Token provided was nil. Request cannot be made to snapshot vm' - end + raise TokenError, 'Token provided was nil. Request cannot be made to snapshot vm' if token.nil? conn = Http.get_conn(verbose, url) conn.headers['X-AUTH-TOKEN'] = token @@ -156,16 +142,12 @@ class Pooler end def self.revert(verbose, url, hostname, token, snapshot_sha) - if token.nil? - raise TokenError, 'Token provided was nil. Request cannot be made to revert vm' - end + raise TokenError, 'Token provided was nil. Request cannot be made to revert vm' if token.nil? conn = Http.get_conn(verbose, url) conn.headers['X-AUTH-TOKEN'] = token - if snapshot_sha.nil? - raise "Snapshot SHA provided was nil, could not revert #{hostname}" - end + raise "Snapshot SHA provided was nil, could not revert #{hostname}" if snapshot_sha.nil? response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}" res_body = JSON.parse(response.body) diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 3f2d433..b9f5a9c 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -30,9 +30,7 @@ class Utils # } # } - unless response_body.delete('ok') - raise ArgumentError, "Bad GET response passed to format_hosts: #{response_body.to_json}" - end + raise ArgumentError, "Bad GET response passed to format_hosts: #{response_body.to_json}" unless response_body.delete('ok') # vmpooler reports the domain separately from the hostname domain = response_body.delete('domain') @@ -81,18 +79,14 @@ class Utils case service.type when 'Pooler' tag_pairs = [] - unless host_data['tags'].nil? - tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } - end + tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil? duration = "#{host_data['running']}/#{host_data['lifetime']} hours" metadata = [host_data['template'], duration, *tag_pairs] puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})" when 'NonstandardPooler' line = "- #{host_data['fqdn']} (#{host_data['os_triple']}" line += ", #{host_data['hours_left_on_reservation']}h remaining" - unless host_data['reserved_for_reason'].empty? - line += ", reason: #{host_data['reserved_for_reason']}" - end + line += ", reason: #{host_data['reserved_for_reason']}" unless host_data['reserved_for_reason'].empty? line += ')' puts line else @@ -185,9 +179,7 @@ class Utils service_config.merge! values else # If the user provided a service name at the command line, use that service if posible, or fail - unless config['services'][options.service] - raise ArgumentError, "Could not find a configured service named '#{options.service}' in ~/.vmfloaty.yml" - end + raise ArgumentError, "Could not find a configured service named '#{options.service}' in ~/.vmfloaty.yml" unless config['services'][options.service] # If the service is configured but some values are missing, use the top-level defaults to fill them in service_config.merge! config['services'][options.service] From 893f9363e01856f6273da74305a9d01cb6585710 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 15:50:07 +1100 Subject: [PATCH 56/57] (rubocop) Defer Metrics cop changes for now --- .rubocop.yml | 4 +++- .rubocop_todo.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 0430a26..1895d8e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,5 @@ ---- +inherit_from: .rubocop_todo.yml + AllCops: TargetRubyVersion: 2.4 @@ -12,6 +13,7 @@ Style/TrailingCommaInArrayLiteral: EnforcedStyleForMultiline: comma Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma + Layout/AlignHash: EnforcedHashRocketStyle: table Layout/IndentHash: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..cb32ba8 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,46 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2019-02-03 15:31:20 +1100 using RuboCop version 0.63.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 8 +Metrics/AbcSize: + Max: 319 + +# Offense count: 25 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 278 + +# Offense count: 1 +# Configuration parameters: CountBlocks. +Metrics/BlockNesting: + Max: 4 + +# Offense count: 4 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 394 + +# Offense count: 4 +Metrics/CyclomaticComplexity: + Max: 55 + +# Offense count: 13 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 391 + +# Offense count: 3 +Metrics/PerceivedComplexity: + Max: 63 + +# Offense count: 193 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 285 From 4440164f8ac05dfc0cf856de9166d82f50c96425 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 15:59:29 +1100 Subject: [PATCH 57/57] Run rubocop during CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6788143..14574bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,4 @@ sudo: false language: ruby rvm: - 2.4 -script: rspec spec +script: bundle exec rake rubocop spec