Browse Source

Deprecate floating ip pool management for nova-network

Change-Id: If6bd13bed00ab954eb2b920dd5f1a59fcbeee736
changes/25/748325/3
Takashi Kajinami 11 months ago
parent
commit
924e9d3f02
  1. 75
      lib/puppet/provider/nova_floating/nova_manage.rb
  2. 2
      lib/puppet/type/nova_floating.rb
  3. 10
      manifests/manage/floating.pp
  4. 8
      releasenotes/notes/deprecate-nova_floating-8d507b9214b2440d.yaml
  5. 99
      spec/unit/provider/nova_floating/nova_manage_spec.rb

75
lib/puppet/provider/nova_floating/nova_manage.rb

@ -1,85 +1,18 @@
Puppet::Type.type(:nova_floating).provide(:nova_manage) do
desc "Manage nova floating"
desc "Manage nova floating (DEPRECATED!)"
optional_commands :nova_manage => 'nova-manage'
def exists?
if resource[:network] =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}$/
# Calculate num quads to grab for prefix$$
mask=resource[:network].sub(/.*\/([0-9][0-9]?)/, '\1').to_i
num_quads = 4 - mask / 8
prefix=resource[:network].sub(/(\.[0-9]{1,3}){#{num_quads}}(\/[0-9]{1,2})?$/, '') + "."
return nova_manage("floating", "list").match(/#{prefix}/)
elsif resource[:network].to_s =~ /^.{0,2}\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}.{0,2}/
if resource[:ensure] == :absent
operate_range.any?
else
operate_range.empty?
end
end
warning('nova_floating type is deprecated and has no effect')
end
def create
if resource[:network] =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}$/
nova_manage("floating", "create", '--pool', resource[:pool], resource[:network])
elsif resource[:network].to_s =~ /^.{0,2}\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}.{0,2}/
mixed_range.each do |ip|
nova_manage("floating", "create", ip)
end
end
warning('nova_floating type is deprecated and has no effect')
end
def destroy
if resource[:network] =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}$/
nova_manage("floating", "delete", resource[:network])
elsif resource[:network].to_s =~ /^.{0,2}\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}.{0,2}/
mixed_range.each do |ip|
nova_manage("floating", "delete", ip )
end
end
end
# Create range in cidr, including first and last ip
# Nova will create this range, excluding network and broadcast IPs
def mixed_range
require 'netaddr'
range = []
NetAddr.merge(operate_range).each do |cidr|
tmp_range = NetAddr::CIDR.create(cidr).enumerate
range << tmp_range.first.to_s
range << tmp_range.last.to_s
end
range.uniq!
range += NetAddr.merge(operate_range).delete_if{ |part| part =~ /\/3[12]/}
end
# Calculate existed IPs and provided ip ranges
def operate_range
exist_range = []
output = nova_manage("floating", "list")
range_list = output.scan(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
range_list.each do |element|
exist_range << element
end
if @resource[:ensure] == :absent
ip_range & exist_range
else
ip_range - exist_range
end
end
def ip_range
require 'netaddr'
ip_range = []
Array(@resource[:network]).each do |rng|
ip = rng.split('-')
generated_range = NetAddr.range(NetAddr::CIDR.create(ip.first), NetAddr::CIDR.create(ip.last))
ip_range += generated_range.unshift(ip.first).push(ip.last)
end
return ip_range
warning('nova_floating type is deprecated and has no effect')
end
end

2
lib/puppet/type/nova_floating.rb

@ -1,6 +1,6 @@
Puppet::Type.newtype(:nova_floating) do
@doc = "Manage creation/deletion of nova floating ip ranges. "
@doc = "Manage creation/deletion of nova floating ip ranges. (DEPRECATED!)"
ensurable

10
manifests/manage/floating.pp

@ -5,13 +5,11 @@
# [*network*]
# (mandatory) The network name to work on
#
define nova::manage::floating ( $network ) {
define nova::manage::floating (
$network
) {
include nova::deps
nova_floating { $name:
ensure => present,
network => $network,
provider => 'nova_manage',
}
warning('The nova::manage::floating class is deprecated and has no effect')
}

8
releasenotes/notes/deprecate-nova_floating-8d507b9214b2440d.yaml

@ -0,0 +1,8 @@
---
deprecations:
- |
The following items has been deprecated and has no effect now, because
nova-network has been removed from nova.
- The ``nova::manage::floatingip`` class
- The ``nova_floating`` type and its provider

99
spec/unit/provider/nova_floating/nova_manage_spec.rb

@ -1,99 +0,0 @@
require 'puppet'
require 'puppet/provider/nova_floating/nova_manage'
require 'tempfile'
provider_class = Puppet::Type.type(:nova_floating).provider(:nova_manage)
describe provider_class do
let :range_attrs do
{
:ensure => 'present',
:pool => 'nova',
:network => '10.1.0.1-10.1.0.2',
}
end
let :network_attrs do
{
:ensure => 'present',
:pool => 'nova',
:network => '11.1.0.0/30'
}
end
let :resource_range do
Puppet::Type::Nova_floating.new(range_attrs)
end
let :resource_network do
Puppet::Type::Nova_floating.new(network_attrs)
end
let :provider_range do
provider_class.new(resource_range)
end
let :provider_network do
provider_class.new(resource_network)
end
shared_examples 'nova_floating' do
describe '#exists?' do
it 'should check if ips of a network are not existing' do
provider_network.expects(:nova_manage).with('floating', 'list').returns('No floating IP addresses have been defined.')
expect(provider_network.exists?).to be_falsey
end
it 'should check if ips of a network are existing' do
provider_network.expects(:nova_manage).with('floating', 'list').returns('None 11.1.0.1 None nova br-ex\nNone 11.1.0.2 None nova br-ex')
expect(provider_network.exists?).to be_truthy
end
it 'should check if ips are not existing' do
provider_range.expects(:nova_manage).with('floating', 'list').returns('No floating IP addresses have been defined.')
expect(provider_range.exists?).to be_falsey
end
it 'should check if ips are existing' do
provider_range.expects(:nova_manage).with('floating', 'list').returns('None 10.1.0.1 None nova br-ex\nNone 10.1.0.2 None nova br-ex')
expect(provider_range.exists?).to be_truthy
end
end
describe '#create' do
it 'should check if ips of network were created' do
provider_network.expects(:nova_manage).with('floating', 'create', '--pool', 'nova', '11.1.0.0/30').returns('None 11.1.0.1 None nova br-ex\nNone 11.1.0.2 None nova br-ex')
expect(provider_network.create).to be_truthy
end
it 'should check if ips of range were created' do
provider_range.stubs(:nova_manage).with('floating', 'create', '10.1.0.1')
provider_range.stubs(:nova_manage).with('floating', 'create', '10.1.0.2')
provider_range.stubs(:nova_manage).with('floating', 'list').returns('None 10.1.0.1 None nova br-ex\nNone 10.1.0.2 None nova br-ex')
expect(provider_range.create).to be_truthy
end
end
describe '#destroy' do
it 'should check if ips of network were deleted' do
provider_network.expects(:nova_manage).with('floating', 'delete', '11.1.0.0/30').returns('No floating IP addresses have been defined.')
expect(provider_network.destroy).to be_truthy
end
it 'should check if ips of range were deleted' do
provider_range.stubs(:nova_manage).with('floating', 'delete', '10.1.0.1')
provider_range.expects(:nova_manage).with('floating', 'list').returns('None 10.1.0.2 None nova br-ex')
provider_range.stubs(:nova_manage).with('floating', 'delete', '10.1.0.2')
provider_range.expects(:nova_manage).with('floating', 'list').returns('No floating IP addresses have been defined.')
expect(provider_range.destroy).to be_truthy
end
end
end
it_behaves_like('nova_floating')
end
Loading…
Cancel
Save