add ipv6 options to neutron_subnet type
Allows setting the ipv6_ra_mode and ipv6_address_mode options to be when an ipv6 subnet is created. Change-Id: Ie7e6b489f5646ab469594f0ffea859f72b20fd89
This commit is contained in:
parent
0076a67070
commit
3e3ffdfdd7
@ -29,6 +29,8 @@ Puppet::Type.type(:neutron_subnet).provide(
|
|||||||
:id => attrs['id'],
|
:id => attrs['id'],
|
||||||
:cidr => attrs['cidr'],
|
:cidr => attrs['cidr'],
|
||||||
:ip_version => attrs['ip_version'],
|
:ip_version => attrs['ip_version'],
|
||||||
|
:ipv6_ra_mode => attrs['ipv6_ra_mode'],
|
||||||
|
:ipv6_address_mode => attrs['ipv6_address_mode'],
|
||||||
:gateway_ip => parse_gateway_ip(attrs['gateway_ip']),
|
:gateway_ip => parse_gateway_ip(attrs['gateway_ip']),
|
||||||
:allocation_pools => parse_allocation_pool(attrs['allocation_pools']),
|
:allocation_pools => parse_allocation_pool(attrs['allocation_pools']),
|
||||||
:host_routes => parse_host_routes(attrs['host_routes']),
|
:host_routes => parse_host_routes(attrs['host_routes']),
|
||||||
@ -94,6 +96,14 @@ Puppet::Type.type(:neutron_subnet).provide(
|
|||||||
opts << "--ip-version=#{@resource[:ip_version]}"
|
opts << "--ip-version=#{@resource[:ip_version]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @resource[:ipv6_ra_mode]
|
||||||
|
opts << "--ipv6-ra-mode=#{@resource[:ipv6_ra_mode]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if @resource[:ipv6_address_mode]
|
||||||
|
opts << "--ipv6-address-mode=#{@resource[:ipv6_address_mode]}"
|
||||||
|
end
|
||||||
|
|
||||||
if @resource[:gateway_ip]
|
if @resource[:gateway_ip]
|
||||||
if @resource[:gateway_ip] == ''
|
if @resource[:gateway_ip] == ''
|
||||||
opts << '--no-gateway'
|
opts << '--no-gateway'
|
||||||
@ -151,6 +161,8 @@ Puppet::Type.type(:neutron_subnet).provide(
|
|||||||
:id => attrs['id'],
|
:id => attrs['id'],
|
||||||
:cidr => attrs['cidr'],
|
:cidr => attrs['cidr'],
|
||||||
:ip_version => attrs['ip_version'],
|
:ip_version => attrs['ip_version'],
|
||||||
|
:ipv6_ra_mode => attrs['ipv6_ra_mode'],
|
||||||
|
:ipv6_address_mode => attrs['ipv6_address_mode'],
|
||||||
:gateway_ip => self.class.parse_gateway_ip(attrs['gateway_ip']),
|
:gateway_ip => self.class.parse_gateway_ip(attrs['gateway_ip']),
|
||||||
:allocation_pools => self.class.parse_allocation_pool(attrs['allocation_pools']),
|
:allocation_pools => self.class.parse_allocation_pool(attrs['allocation_pools']),
|
||||||
:host_routes => self.class.parse_host_routes(attrs['host_routes']),
|
:host_routes => self.class.parse_host_routes(attrs['host_routes']),
|
||||||
@ -208,6 +220,8 @@ Puppet::Type.type(:neutron_subnet).provide(
|
|||||||
[
|
[
|
||||||
:cidr,
|
:cidr,
|
||||||
:ip_version,
|
:ip_version,
|
||||||
|
:ipv6_ra_mode,
|
||||||
|
:ipv6_address_mode,
|
||||||
:network_id,
|
:network_id,
|
||||||
:allocation_pools,
|
:allocation_pools,
|
||||||
:tenant_id,
|
:tenant_id,
|
||||||
|
@ -23,6 +23,16 @@ Puppet::Type.newtype(:neutron_subnet) do
|
|||||||
newvalues('4', '6')
|
newvalues('4', '6')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
newproperty(:ipv6_ra_mode) do
|
||||||
|
desc 'The IPv6 RA (Router Advertisement) mode'
|
||||||
|
newvalues('dhcpv6-stateful', 'dhcpv6-stateless', 'slaac')
|
||||||
|
end
|
||||||
|
|
||||||
|
newproperty(:ipv6_address_mode) do
|
||||||
|
desc 'The IPv6 Address mode'
|
||||||
|
newvalues('dhcpv6-stateful', 'dhcpv6-stateless', 'slaac')
|
||||||
|
end
|
||||||
|
|
||||||
newproperty(:allocation_pools, :array_matching => :all) do
|
newproperty(:allocation_pools, :array_matching => :all) do
|
||||||
desc <<-EOT
|
desc <<-EOT
|
||||||
Array of Sub-ranges of cidr available for dynamic allocation to ports.
|
Array of Sub-ranges of cidr available for dynamic allocation to ports.
|
||||||
@ -112,6 +122,12 @@ Please provide a value for only one of tenant_name and tenant_id.
|
|||||||
EOT
|
EOT
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
if (self[:ipv6_ra_mode] || self[:ipv6_address_mode]) && String(self[:ip_version]) != '6'
|
||||||
|
raise(Puppet::Error, <<-EOT
|
||||||
|
ipv6_ra_mode and ipv6_address_mode can only be used with ip_version set to '6'
|
||||||
|
EOT
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -10,6 +10,10 @@ describe provider_class do
|
|||||||
'net1'
|
'net1'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let :subnet_v6_name do
|
||||||
|
'net2'
|
||||||
|
end
|
||||||
|
|
||||||
let :subnet_attrs do
|
let :subnet_attrs do
|
||||||
{
|
{
|
||||||
:name => subnet_name,
|
:name => subnet_name,
|
||||||
@ -26,6 +30,22 @@ describe provider_class do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let :subnet_v6_attrs do
|
||||||
|
{
|
||||||
|
:name => subnet_v6_name,
|
||||||
|
:ensure => 'present',
|
||||||
|
:cidr => '2001:abcd::/64',
|
||||||
|
:ip_version => '6',
|
||||||
|
:gateway_ip => '2001:abcd::1',
|
||||||
|
:enable_dhcp => 'False',
|
||||||
|
:network_name => 'net2',
|
||||||
|
:tenant_id => '60f9544eb94c42a6b7e8e98c2be981b1',
|
||||||
|
:allocation_pools => 'start=2001:abcd::2,end=2001:abcd::ffff:ffff:ffff:fffe',
|
||||||
|
:dns_nameservers => '2001:4860:4860::8888',
|
||||||
|
:host_routes => 'destination=2001:abcd:0:1::/64,nexthop=2001:abcd::1',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
let :resource do
|
let :resource do
|
||||||
Puppet::Type::Neutron_subnet.new(subnet_attrs)
|
Puppet::Type::Neutron_subnet.new(subnet_attrs)
|
||||||
end
|
end
|
||||||
@ -35,7 +55,6 @@ describe provider_class do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'when creating a subnet' do
|
describe 'when creating a subnet' do
|
||||||
|
|
||||||
it 'should call subnet-create with appropriate command line options' do
|
it 'should call subnet-create with appropriate command line options' do
|
||||||
provider.class.stubs(:get_tenant_id).returns(subnet_attrs[:tenant_id])
|
provider.class.stubs(:get_tenant_id).returns(subnet_attrs[:tenant_id])
|
||||||
|
|
||||||
@ -68,6 +87,48 @@ tenant_id="60f9544eb94c42a6b7e8e98c2be981b1"'
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'when creating a ipv6 subnet' do
|
||||||
|
|
||||||
|
let :resource do
|
||||||
|
Puppet::Type::Neutron_subnet.new(subnet_v6_attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
let :provider do
|
||||||
|
provider_class.new(resource)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should call subnet-create with appropriate command line options' do
|
||||||
|
provider.class.stubs(:get_tenant_id).returns(subnet_v6_attrs[:tenant_id])
|
||||||
|
|
||||||
|
output = 'Created a new subnet:
|
||||||
|
allocation_pools="{\"start\": \"2001:abcd::2\", \"end\": \"2001:abcd::ffff:ffff:ffff:fffe\"}"
|
||||||
|
cidr="2001:abcd::/64"
|
||||||
|
dns_nameservers="2001:4860:4860::8888"
|
||||||
|
enable_dhcp="False"
|
||||||
|
gateway_ip="2001:abcd::1"
|
||||||
|
host_routes="{\"nexthop\": \"2001:abcd::1\", \"destination\": \"2001:abcd:0:1::/64\"}"
|
||||||
|
id="dd5e0ef1-2c88-4b0b-ba08-7df65be87963"
|
||||||
|
ip_version="6"
|
||||||
|
name="net1"
|
||||||
|
network_id="98873773-aa34-4b87-af05-70903659246f"
|
||||||
|
tenant_id="60f9544eb94c42a6b7e8e98c2be981b1"'
|
||||||
|
|
||||||
|
provider.expects(:auth_neutron).with('subnet-create', '--format=shell',
|
||||||
|
["--name=#{subnet_v6_attrs[:name]}",
|
||||||
|
"--ip-version=#{subnet_v6_attrs[:ip_version]}",
|
||||||
|
"--gateway-ip=#{subnet_v6_attrs[:gateway_ip]}",
|
||||||
|
"--disable-dhcp",
|
||||||
|
"--allocation-pool=#{subnet_v6_attrs[:allocation_pools]}",
|
||||||
|
"--dns-nameserver=#{subnet_v6_attrs[:dns_nameservers]}",
|
||||||
|
"--host-route=#{subnet_v6_attrs[:host_routes]}",
|
||||||
|
"--tenant_id=#{subnet_v6_attrs[:tenant_id]}",
|
||||||
|
subnet_v6_name],
|
||||||
|
subnet_v6_attrs[:cidr]).returns(output)
|
||||||
|
|
||||||
|
provider.create
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'when updating a subnet' do
|
describe 'when updating a subnet' do
|
||||||
it 'should call subnet-update to change gateway_ip' do
|
it 'should call subnet-update to change gateway_ip' do
|
||||||
provider.expects(:auth_neutron).with('subnet-update',
|
provider.expects(:auth_neutron).with('subnet-update',
|
||||||
|
25
spec/unit/type/neutron_subnet.rb
Normal file
25
spec/unit/type/neutron_subnet.rb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
require 'puppet'
|
||||||
|
require 'puppet/type/neutron_subnet'
|
||||||
|
|
||||||
|
describe 'Puppet::Type.type(:neutron_subnet)' do
|
||||||
|
it 'should not allow ipv6 settings with ip_version = 4' do
|
||||||
|
expect{Puppet::Type.type(:neutron_subnet).new(
|
||||||
|
:name => 'subnet',
|
||||||
|
:network_name => 'net',
|
||||||
|
:cidr => '2001:abcd::/64',
|
||||||
|
:ip_version => '4',
|
||||||
|
:ipv6_ra_mode => 'slaac'
|
||||||
|
)}.to raise_error(Puppet::ResourceError)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow ipv6 settings with ip_version = 6' do
|
||||||
|
expect{Puppet::Type.type(:neutron_subnet).new(
|
||||||
|
:name => 'subnet',
|
||||||
|
:network_name => 'net',
|
||||||
|
:cidr => '2001:abcd::/64',
|
||||||
|
:ip_version => '6',
|
||||||
|
:ipv6_ra_mode => 'slaac'
|
||||||
|
)}.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user