Allow address_for default family to be overridden

When IPv6 is wanted as the default interface address family, allow
single override to make that change.

Change-Id: I0ec7cc1eaab3dec09f26c745c1a5b7133e17cd0a
Implements: blueprint ipv6-support
This commit is contained in:
Mark Vanderwiel
2014-04-07 13:50:35 -05:00
parent a69421e1c4
commit adbc887b5e
5 changed files with 23 additions and 5 deletions

View File

@@ -2,6 +2,9 @@
This file is used to list changes made in each version of cookbook-openstack-common.
## 9.0.2
* Allow address_for family default to be overridden
## 9.0.1
### Bug
* Fix the depends cookbook version issue in metadata.rb

View File

@@ -122,6 +122,7 @@ default['openstack']['yum']['repo-key'] = 'https://raw.github.com/redhat-opensta
# ******************** OpenStack Identity Endpoints ***************************
default['openstack']['endpoints']['host'] = '127.0.0.1'
default['openstack']['endpoints']['family'] = 'inet'
# The OpenStack Identity Bind API endpoint is used to determine what IP/host
# to bind the Identity services to.

View File

@@ -24,8 +24,8 @@ module ::Openstack # rubocop:disable Documentation
#
# @param [String] interface The interface to query.
# @param [String] family The protocol family to use.
# @return [String] The IPv4 address.
def address_for(interface, family = 'inet')
# @return [String] The address.
def address_for(interface, family = node['openstack']['endpoints']['family'])
interface_node = node['network']['interfaces'][interface]['addresses']
interface_node.select do |address, data|
return address if data['family'] == family

View File

@@ -4,7 +4,7 @@ maintainer_email 'cookbooks@lists.tfoundry.com'
license 'Apache 2.0'
description 'Common OpenStack attributes, libraries and recipes.'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '9.0.1'
version '9.0.2'
recipe 'openstack-common', 'Installs/Configures common recipes'
recipe 'openstack-common::set_endpoints_by_interface', 'Set endpoints by interface'

View File

@@ -33,14 +33,28 @@ describe 'openstack-common::default' do
include_context 'library-stubs'
describe '#address_for' do
describe '#address_for ipv4' do
it 'returns ipv4 address' do
expect(
subject.address_for('lo')
).to eq('127.0.0.1')
end
it 'returns ipv4 address' do
it 'returns ipv6 address' do
expect(
subject.address_for('lo', 'inet6')
).to eq('::1')
end
end
describe '#address_for ipv6' do
it 'returns ipv6 address' do
node.set['openstack']['endpoints']['family'] = 'inet6'
expect(
subject.address_for('lo')
).to eq('::1')
end
it 'returns ipv6 address' do
expect(
subject.address_for('lo', 'inet6')
).to eq('::1')