Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ end

RSpec::Core::RakeTask.new(:spec)

task default: [:rubocop, :loc, :spec]
task default: %i[rubocop loc spec]
19 changes: 11 additions & 8 deletions lib/kitchen/driver/openstack.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Encoding: UTF-8

#
# Author:: Jonathan Hartman (<j@p4nt5.com>)
# Author:: JJ Asghar (<jj@chef.io>)
Expand Down Expand Up @@ -59,6 +60,7 @@ class Openstack < Kitchen::Driver::Base
default_config :connect_timeout, 60
default_config :read_timeout, 60
default_config :write_timeout, 60
default_config :metadata, nil

# Set the proper server name in the config
def config_server_name
Expand Down Expand Up @@ -142,7 +144,7 @@ def openstack_server
end

def required_server_settings
[:openstack_username, :openstack_api_key, :openstack_auth_url]
%i[openstack_username openstack_api_key openstack_auth_url]
end

def optional_server_settings
Expand All @@ -152,7 +154,7 @@ def optional_server_settings
end

def connection_options
[:read_timeout, :write_timeout, :connect_timeout]
%i[read_timeout write_timeout connect_timeout]
end

def network
Expand Down Expand Up @@ -190,11 +192,12 @@ def create_server
server_def[:block_device_mapping] = get_bdm(config)
end

[
:security_groups,
:key_name,
:user_data,
:config_drive
%i[
security_groups
key_name
user_data
config_drive
metadata
].each do |c|
server_def[c] = optional_config(c) if config[c]
end
Expand Down Expand Up @@ -401,7 +404,7 @@ def add_ohai_hint(state)
end

def hints_path
Ohai::Config[:hints_path][0]
Ohai.config[:hints_path][0]
end

def disable_ssl_validation
Expand Down
5 changes: 3 additions & 2 deletions lib/kitchen/driver/openstack/volume.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Encoding: UTF-8

#
# Author:: Jonathan Hartman (<j@p4nt5.com>)
#
Expand Down Expand Up @@ -40,8 +41,8 @@ def volume(openstack_server)
def create_volume(config, os)
opt = {}
bdm = config[:block_device_mapping]
vanilla_options = [:snapshot_id, :imageRef, :volume_type,
:source_volid, :availability_zone]
vanilla_options = %i[snapshot_id imageRef volume_type
source_volid availability_zone]
vanilla_options.select { |o| bdm[o] }.each do |key|
opt[key] = bdm[key]
end
Expand Down
1 change: 1 addition & 0 deletions lib/kitchen/driver/openstack_version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Encoding: UTF-8

#
# Author:: Jonathan Hartman (<j@p4nt5.com>)
#
Expand Down
108 changes: 72 additions & 36 deletions spec/kitchen/driver/openstack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
describe Kitchen::Driver::Openstack do
let(:logged_output) { StringIO.new }
let(:logger) { Logger.new(logged_output) }
let(:config) { Hash.new }
let(:state) { Hash.new }
let(:config) { {} }
let(:state) { {} }
let(:instance_name) { 'potatoes' }
let(:transport) { Kitchen::Transport::Dummy.new }
let(:platform) { Kitchen::Platform.new(name: 'fake_platform') }
Expand Down Expand Up @@ -69,16 +69,17 @@
expect(driver[:connect_timeout]).to eq(60)
end

nils = [
:server_name,
:openstack_tenant,
:openstack_region,
:openstack_service_name,
:floating_ip_pool,
:floating_ip,
:availability_zone,
:security_groups,
:network_ref
nils = %i[
server_name
openstack_tenant
openstack_region
openstack_service_name
floating_ip_pool
floating_ip
availability_zone
security_groups
network_ref
metadata
]
nils.each do |i|
it "defaults to no #{i}" do
Expand Down Expand Up @@ -117,6 +118,10 @@
volume_size: '5',
device_name: 'vda',
delete_on_termination: true
},
metadata: {
name: 'test',
ohai: 'chef'
}
}
end
Expand All @@ -136,7 +141,7 @@

describe '#create' do
let(:server) do
double(id: 'test123', wait_for: true, public_ip_addresses: %w(1.2.3.4))
double(id: 'test123', wait_for: true, public_ip_addresses: %w[1.2.3.4])
end
let(:driver) do
d = super()
Expand Down Expand Up @@ -173,7 +178,7 @@
}
end
let(:server) do
double(id: 'test123', wait_for: true, public_ip_addresses: %w(1.2.3.4))
double(id: 'test123', wait_for: true, public_ip_addresses: %w[1.2.3.4])
end

let(:driver) do
Expand Down Expand Up @@ -232,7 +237,7 @@
end

context 'no server ID present' do
let(:state) { Hash.new }
let(:state) { {} }

it 'does nothing' do
allow(driver).to receive(:compute)
Expand Down Expand Up @@ -330,17 +335,17 @@

describe '#required_server_settings' do
it 'returns the required settings for an OpenStack server' do
expected = [
:openstack_username, :openstack_api_key, :openstack_auth_url
expected = %i[
openstack_username openstack_api_key openstack_auth_url
]
expect(driver.send(:required_server_settings)).to eq(expected)
end
end

describe '#optional_server_settings' do
it 'returns the optional settings for an OpenStack server' do
excluded = [
:openstack_username, :openstack_api_key, :openstack_auth_url
excluded = %i[
openstack_username openstack_api_key openstack_auth_url
]
expect(driver.send(:optional_server_settings)).not_to include(*excluded)
end
Expand Down Expand Up @@ -745,7 +750,7 @@
server_name: 'hello',
image_ref: '111',
flavor_ref: '1',
network_ref: %w(1 2)
network_ref: %w[1 2]
}
end

Expand Down Expand Up @@ -814,6 +819,37 @@
driver.send(:create_server)
end
end

context 'metadata specified' do
let(:config) do
{
server_name: 'hello',
image_ref: '111',
flavor_ref: '1',
metadata: {
name: 'hello',
ohai: 'chef'
}
}
end
let(:data) do
{
name: 'hello',
ohai: 'chef'
}
end

it 'passes metadata contents' do
expect(servers).to receive(:create).with(
name: 'hello',
image_ref: '111',
flavor_ref: '1',
availability_zone: nil,
metadata: data
)
driver.send(:create_server)
end
end
end

describe '#default_name' do
Expand Down Expand Up @@ -1010,36 +1046,36 @@
end

context 'both public and private IPs' do
let(:public_ip_addresses) { %w(1::1 1.2.3.4) }
let(:private_ip_addresses) { %w(5.5.5.5) }
let(:parsed_ips) { [%w(1.2.3.4), %w(5.5.5.5)] }
let(:public_ip_addresses) { %w[1::1 1.2.3.4] }
let(:private_ip_addresses) { %w[5.5.5.5] }
let(:parsed_ips) { [%w[1.2.3.4], %w[5.5.5.5]] }

it 'returns a public IPv4 address' do
expect(driver.send(:get_ip, server)).to eq('1.2.3.4')
end
end

context 'only public IPs' do
let(:public_ip_addresses) { %w(4.3.2.1 2::1) }
let(:parsed_ips) { [%w(4.3.2.1), []] }
let(:public_ip_addresses) { %w[4.3.2.1 2::1] }
let(:parsed_ips) { [%w[4.3.2.1], []] }

it 'returns a public IPv4 address' do
expect(driver.send(:get_ip, server)).to eq('4.3.2.1')
end
end

context 'only private IPs' do
let(:private_ip_addresses) { %w(3::1 5.5.5.5) }
let(:parsed_ips) { [[], %w(5.5.5.5)] }
let(:private_ip_addresses) { %w[3::1 5.5.5.5] }
let(:parsed_ips) { [[], %w[5.5.5.5]] }

it 'returns a private IPv4 address' do
expect(driver.send(:get_ip, server)).to eq('5.5.5.5')
end
end

context 'no predictable network name' do
let(:ip_addresses) { %w(3::1 5.5.5.5) }
let(:parsed_ips) { [[], %w(5.5.5.5)] }
let(:ip_addresses) { %w[3::1 5.5.5.5] }
let(:parsed_ips) { [[], %w[5.5.5.5]] }

it 'returns the first IP that matches the IP version' do
expect(driver.send(:get_ip, server)).to eq('5.5.5.5')
Expand Down Expand Up @@ -1090,7 +1126,7 @@
'private' => [{ 'addr' => '8.8.8.8' }, { 'addr' => '9.9.9.9' }]
}
end
let(:parsed_ips) { [%w(6.6.6.6 7.7.7.7), %w(8.8.8.8 9.9.9.9)] }
let(:parsed_ips) { [%w[6.6.6.6 7.7.7.7], %w[8.8.8.8 9.9.9.9]] }

it 'selects the first public IP' do
expect(driver.send(:get_ip, server)).to eq('6.6.6.6')
Expand Down Expand Up @@ -1149,7 +1185,7 @@
let(:addresses) do
{ 'public' => [{ 'addr' => '6.6.6.6' }, { 'addr' => '7.7.7.7' }] }
end
let(:parsed_ips) { [%w(6.6.6.6 7.7.7.7), []] }
let(:parsed_ips) { [%w[6.6.6.6 7.7.7.7], []] }

it 'selects the first public IP' do
expect(driver.send(:get_ip, server)).to eq('6.6.6.6')
Expand All @@ -1160,7 +1196,7 @@
let(:addresses) do
{ 'private' => [{ 'addr' => '8.8.8.8' }, { 'addr' => '9.9.9.9' }] }
end
let(:parsed_ips) { [[], %w(8.8.8.8 9.9.9.9)] }
let(:parsed_ips) { [[], %w[8.8.8.8 9.9.9.9]] }

it 'selects the first private IP' do
expect(driver.send(:get_ip, server)).to eq('8.8.8.8')
Expand Down Expand Up @@ -1188,10 +1224,10 @@
end

describe '#parse_ips' do
let(:pub_v4) { %w(1.1.1.1 2.2.2.2) }
let(:pub_v6) { %w(1::1 2::2) }
let(:priv_v4) { %w(3.3.3.3 4.4.4.4) }
let(:priv_v6) { %w(3::3 4::4) }
let(:pub_v4) { %w[1.1.1.1 2.2.2.2] }
let(:pub_v6) { %w[1::1 2::2] }
let(:priv_v4) { %w[3.3.3.3 4.4.4.4] }
let(:priv_v6) { %w[3::3 4::4] }
let(:pub) { pub_v4 + pub_v6 }
let(:priv) { priv_v4 + priv_v6 }

Expand Down