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)'