puppet-tripleo/spec/functions/ip_to_erl_format_spec.rb
Michele Baldessari 2f038b30e8 Make sure we bind the rabbit inter-cluster to a specific interface
Currently the inter-cluster communication port listens to all ip
addresses:
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 25631/beam.smp

In order to limit it to listen only to the network assigned to rabbitmq
we need to add the following:
{kernel, [
    ...
    {inet_dist_use_interface, {172,17,0,16}},
    ...
  ]}

In order to do the conversion from an ip address to the Erlang
representation we add a function that takes a string and returns a
converted output. The (~400 randomly generated) IPv6/4 addresses at [1]
have been parsed both via erl's built-in inet:parse_address() function
and our ruby implementation. All converted ip addresses resulted in the
same output [2], [3]. The only difference is that Erlang's parse_address()
considers network ip addresses (e.g. 10.0.0.0) invalid whereas the ruby
function does not. This should not be a problem as the use case here is
to bind a service to a specific ip address on an interface and if
anything we likely prefer the less strict behaviour, given that at least
in theory it is perfectly valid for an interface to have a network
address assigned to it.

[1] http://acksyn.org/files/tripleo/ip-addresses.txt
[2] http://acksyn.org/files/tripleo/ip-addresses-ruby.txt
[3] http://acksyn.org/files/tripleo/ip-addresses-erl.txt
Change-Id: I211c75b9bab25c545bcc7f90f34edebc92bba788
Partial-Bug: #1645898
2017-01-20 08:41:22 +01:00

12 lines
630 B
Ruby

require 'spec_helper'
require 'puppet'
describe 'ip_to_erl_format' do
it { should run.with_params('192.168.2.1').and_return('{192,168,2,1}') }
it { should run.with_params('0.0.0.0').and_return('{0,0,0,0}') }
it { should run.with_params('5a40:79cf:8251:5dc5:1624:3c03:3c04:9ba8').and_return('{23104,31183,33361,24005,5668,15363,15364,39848}') }
it { should run.with_params('fe80::204:acff:fe17:bf38').and_return('{65152,0,0,0,516,44287,65047,48952}') }
it { should run.with_params('::1:2').and_return('{0,0,0,0,0,0,1,2}') }
it { should run.with_params('192.256.0.0').and_raise_error(IPAddr::InvalidAddressError) }
end