mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(rubocop) Fix Layout/AlignHash & Layout/IndentHash
This commit is contained in:
parent
f2167f8be7
commit
851009b1f6
7 changed files with 74 additions and 70 deletions
|
|
@ -12,3 +12,7 @@ Style/TrailingCommaInArrayLiteral:
|
||||||
EnforcedStyleForMultiline: comma
|
EnforcedStyleForMultiline: comma
|
||||||
Style/TrailingCommaInArguments:
|
Style/TrailingCommaInArguments:
|
||||||
EnforcedStyleForMultiline: comma
|
EnforcedStyleForMultiline: comma
|
||||||
|
Layout/AlignHash:
|
||||||
|
EnforcedHashRocketStyle: table
|
||||||
|
Layout/IndentHash:
|
||||||
|
EnforcedStyle: consistent
|
||||||
|
|
|
||||||
|
|
@ -152,10 +152,10 @@ class Vmfloaty
|
||||||
|
|
||||||
tags = options.tags ? JSON.parse(options.tags) : nil
|
tags = options.tags ? JSON.parse(options.tags) : nil
|
||||||
modify_hash = {
|
modify_hash = {
|
||||||
:lifetime => options.lifetime,
|
:lifetime => options.lifetime,
|
||||||
:disk => options.disk,
|
:disk => options.disk,
|
||||||
:tags => tags,
|
:tags => tags,
|
||||||
:reason => options.reason,
|
:reason => options.reason,
|
||||||
}
|
}
|
||||||
modify_hash.delete_if { |_, value| value.nil? }
|
modify_hash.delete_if { |_, value| value.nil? }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,10 +176,10 @@ class Utils
|
||||||
def self.get_service_config(config, options)
|
def self.get_service_config(config, options)
|
||||||
# The top-level url, user, and token values in the config file are treated as defaults
|
# The top-level url, user, and token values in the config file are treated as defaults
|
||||||
service_config = {
|
service_config = {
|
||||||
'url' => config['url'],
|
'url' => config['url'],
|
||||||
'user' => config['user'],
|
'user' => config['user'],
|
||||||
'token' => config['token'],
|
'token' => config['token'],
|
||||||
'type' => config['type'] || 'vmpooler',
|
'type' => config['type'] || 'vmpooler',
|
||||||
}
|
}
|
||||||
|
|
||||||
if config['services']
|
if config['services']
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,16 @@ describe NonstandardPooler do
|
||||||
before :each do
|
before :each do
|
||||||
@nspooler_url = 'https://nspooler.example.com'
|
@nspooler_url = 'https://nspooler.example.com'
|
||||||
@post_request_headers = {
|
@post_request_headers = {
|
||||||
'Accept' => '*/*',
|
'Accept' => '*/*',
|
||||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||||
'User-Agent' => 'Faraday v0.9.2',
|
'User-Agent' => 'Faraday v0.9.2',
|
||||||
'X-Auth-Token' => 'token-value',
|
'X-Auth-Token' => 'token-value',
|
||||||
}
|
}
|
||||||
@get_request_headers = {
|
@get_request_headers = {
|
||||||
'Accept' => '*/*',
|
'Accept' => '*/*',
|
||||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||||
'User-Agent' => 'Faraday v0.9.2',
|
'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|
|
@get_request_headers_notoken = @get_request_headers.tap do |headers|
|
||||||
headers.delete('X-Auth-Token')
|
headers.delete('X-Auth-Token')
|
||||||
|
|
@ -174,8 +174,8 @@ BODY
|
||||||
|
|
||||||
it 'raises an error if the user tries to modify an unsupported attribute' do
|
it 'raises an error if the user tries to modify an unsupported attribute' do
|
||||||
stub_request(:put, 'https://nspooler.example.com/host/myfakehost')
|
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' })
|
: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 }
|
details = { :lifetime => 12 }
|
||||||
expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) }
|
expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) }
|
||||||
|
|
@ -185,7 +185,7 @@ BODY
|
||||||
it 'modifies the reason of a vm' do
|
it 'modifies the reason of a vm' do
|
||||||
modify_request_body = { '{"reserved_for_reason":"testing"}' => true }
|
modify_request_body = { '{"reserved_for_reason":"testing"}' => true }
|
||||||
stub_request(:put, "#{@nspooler_url}/host/myfakehost")
|
stub_request(:put, "#{@nspooler_url}/host/myfakehost")
|
||||||
.with(:body => modify_request_body,
|
.with(:body => modify_request_body,
|
||||||
:headers => @post_request_headers)
|
:headers => @post_request_headers)
|
||||||
.to_return(:status => 200, :body => '{"ok": true}', :headers => {})
|
.to_return(:status => 200, :body => '{"ok": true}', :headers => {})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ describe Pooler do
|
||||||
it 'modifies the TTL of a vm' do
|
it 'modifies the TTL of a vm' do
|
||||||
modify_hash = { :lifetime => 12 }
|
modify_hash = { :lifetime => 12 }
|
||||||
stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
||||||
.with(:body => { '{"lifetime":12}' => true },
|
.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' })
|
: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 => {})
|
.to_return(:status => 200, :body => @modify_response_body_success, :headers => {})
|
||||||
|
|
||||||
modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash)
|
modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash)
|
||||||
|
|
|
||||||
|
|
@ -58,17 +58,17 @@ describe Service do
|
||||||
describe '#token_status' do
|
describe '#token_status' do
|
||||||
it 'reports the status of a token' do
|
it 'reports the status of a token' do
|
||||||
config = {
|
config = {
|
||||||
'user' => 'first.last',
|
'user' => 'first.last',
|
||||||
'url' => 'http://default.url',
|
'url' => 'http://default.url',
|
||||||
}
|
}
|
||||||
options = MockOptions.new('token' => 'token-value')
|
options = MockOptions.new('token' => 'token-value')
|
||||||
service = Service.new(options, config)
|
service = Service.new(options, config)
|
||||||
status = {
|
status = {
|
||||||
'ok' => true,
|
'ok' => true,
|
||||||
'user' => config['user'],
|
'user' => config['user'],
|
||||||
'created' => '2017-09-22 02:04:18 +0000',
|
'created' => '2017-09-22 02:04:18 +0000',
|
||||||
'last_accessed' => '2017-09-22 02:04:28 +0000',
|
'last_accessed' => '2017-09-22 02:04:28 +0000',
|
||||||
'reserved_hosts' => [],
|
'reserved_hosts' => [],
|
||||||
}
|
}
|
||||||
allow(Auth).to(receive(:token_status)
|
allow(Auth).to(receive(:token_status)
|
||||||
.with(nil, config['url'], 'token-value')
|
.with(nil, config['url'], 'token-value')
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,13 @@ describe Utils do
|
||||||
|
|
||||||
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))
|
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'])
|
'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'])
|
||||||
end
|
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))
|
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'])
|
'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -45,11 +45,11 @@ describe Utils do
|
||||||
describe '#format_host_output' do
|
describe '#format_host_output' do
|
||||||
before :each do
|
before :each do
|
||||||
@vmpooler_results = {
|
@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'],
|
'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'],
|
||||||
}
|
}
|
||||||
@nonstandard_results = {
|
@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'],
|
'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'],
|
||||||
}
|
}
|
||||||
@vmpooler_output = <<-OUT.chomp
|
@vmpooler_output = <<-OUT.chomp
|
||||||
|
|
@ -85,23 +85,23 @@ describe Utils do
|
||||||
describe '#get_service_config' do
|
describe '#get_service_config' do
|
||||||
before :each do
|
before :each do
|
||||||
@default_config = {
|
@default_config = {
|
||||||
'url' => 'http://default.url',
|
'url' => 'http://default.url',
|
||||||
'user' => 'first.last.default',
|
'user' => 'first.last.default',
|
||||||
'token' => 'default-token',
|
'token' => 'default-token',
|
||||||
}
|
}
|
||||||
@services_config = {
|
@services_config = {
|
||||||
'services' => {
|
'services' => {
|
||||||
'vm' => {
|
'vm' => {
|
||||||
'url' => 'http://vmpooler.url',
|
'url' => 'http://vmpooler.url',
|
||||||
'user' => 'first.last.vmpooler',
|
'user' => 'first.last.vmpooler',
|
||||||
'token' => 'vmpooler-token',
|
'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',
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -160,12 +160,12 @@ describe Utils do
|
||||||
it 'prints a vmpooler output with host fqdn, template and duration info' do
|
it 'prints a vmpooler output with host fqdn, template and duration info' do
|
||||||
hostname = 'mcpy42eqjxli9g2'
|
hostname = 'mcpy42eqjxli9g2'
|
||||||
response_body = { hostname => {
|
response_body = { hostname => {
|
||||||
'template' => 'ubuntu-1604-x86_64',
|
'template' => 'ubuntu-1604-x86_64',
|
||||||
'lifetime' => 12,
|
'lifetime' => 12,
|
||||||
'running' => 9.66,
|
'running' => 9.66,
|
||||||
'state' => 'running',
|
'state' => 'running',
|
||||||
'ip' => '127.0.0.1',
|
'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)'
|
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
|
it 'prints a vmpooler output with host fqdn, template, duration info, and tags when supplied' do
|
||||||
hostname = 'aiydvzpg23r415q'
|
hostname = 'aiydvzpg23r415q'
|
||||||
response_body = { hostname => {
|
response_body = { hostname => {
|
||||||
'template' => 'redhat-7-x86_64',
|
'template' => 'redhat-7-x86_64',
|
||||||
'lifetime' => 48,
|
'lifetime' => 48,
|
||||||
'running' => 7.67,
|
'running' => 7.67,
|
||||||
'state' => 'running',
|
'state' => 'running',
|
||||||
'tags' => {
|
'tags' => {
|
||||||
'user' => 'bob',
|
'user' => 'bob',
|
||||||
'role' => 'agent',
|
'role' => 'agent',
|
||||||
},
|
},
|
||||||
'ip' => '127.0.0.1',
|
'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)'
|
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
|
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 => {
|
response_body = { hostname => {
|
||||||
'fqdn' => hostname,
|
'fqdn' => hostname,
|
||||||
'os_triple' => 'solaris-11-sparc',
|
'os_triple' => 'solaris-11-sparc',
|
||||||
'reserved_by_user' => 'first.last',
|
'reserved_by_user' => 'first.last',
|
||||||
'reserved_for_reason' => '',
|
'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)'
|
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
|
it 'prints a nonstandard pooler output with host, template, time remaining, and reason' do
|
||||||
hostname = 'sol11-9.delivery.mycompany.net'
|
hostname = 'sol11-9.delivery.mycompany.net'
|
||||||
response_body = { hostname => {
|
response_body = { hostname => {
|
||||||
'fqdn' => hostname,
|
'fqdn' => hostname,
|
||||||
'os_triple' => 'solaris-11-sparc',
|
'os_triple' => 'solaris-11-sparc',
|
||||||
'reserved_by_user' => 'first.last',
|
'reserved_by_user' => 'first.last',
|
||||||
'reserved_for_reason' => 'testing',
|
'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)'
|
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue