Do not manage network, subnet, router resources if prefetch fails

If prefetch of neutron_network, neutron_subnet, or neutron_router
resources fails (because of Neutron API timeouts or failures, for
example) then the provider will believe the resources don't exist
and will attempt to create them.  This can cause duplicate
resources in Neutron.

This patch records when the prefetch fails, and if so, shunts
any of the resource management methods to fail().

Change-Id: I612847bfd23ac735583ab228d8a9396f52f0ef14
Closes-bug: 1532284
This commit is contained in:
Mike Dorman 2016-01-08 11:03:31 -07:00
parent 023292b59c
commit 1d354007be
3 changed files with 90 additions and 3 deletions

View File

@ -19,8 +19,17 @@ Puppet::Type.type(:neutron_network).provide(
'net' 'net'
end end
def self.do_not_manage
@do_not_manage
end
def self.do_not_manage=(value)
@do_not_manage = value
end
def self.instances def self.instances
list_neutron_resources(neutron_type).collect do |id| self.do_not_manage = true
list = list_neutron_resources(neutron_type).collect do |id|
attrs = get_neutron_resource_attrs(neutron_type, id) attrs = get_neutron_resource_attrs(neutron_type, id)
new( new(
:ensure => :present, :ensure => :present,
@ -35,6 +44,8 @@ Puppet::Type.type(:neutron_network).provide(
:tenant_id => attrs['tenant_id'] :tenant_id => attrs['tenant_id']
) )
end end
self.do_not_manage = false
list
end end
def self.prefetch(resources) def self.prefetch(resources)
@ -51,6 +62,10 @@ Puppet::Type.type(:neutron_network).provide(
end end
def create def create
if self.class.do_not_manage
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
end
network_opts = Array.new network_opts = Array.new
if @resource[:shared] =~ /true/i if @resource[:shared] =~ /true/i
@ -107,19 +122,31 @@ Puppet::Type.type(:neutron_network).provide(
end end
def destroy def destroy
if self.class.do_not_manage
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
end
auth_neutron('net-delete', name) auth_neutron('net-delete', name)
@property_hash[:ensure] = :absent @property_hash[:ensure] = :absent
end end
def admin_state_up=(value) def admin_state_up=(value)
if self.class.do_not_manage
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
end
auth_neutron('net-update', "--admin_state_up=#{value}", name) auth_neutron('net-update', "--admin_state_up=#{value}", name)
end end
def shared=(value) def shared=(value)
if self.class.do_not_manage
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
end
auth_neutron('net-update', "--shared=#{value}", name) auth_neutron('net-update', "--shared=#{value}", name)
end end
def router_external=(value) def router_external=(value)
if self.class.do_not_manage
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
end
if value == 'False' if value == 'False'
auth_neutron('net-update', "--router:external=#{value}", name) auth_neutron('net-update', "--router:external=#{value}", name)
else else

View File

@ -15,8 +15,17 @@ Puppet::Type.type(:neutron_router).provide(
mk_resource_methods mk_resource_methods
def self.do_not_manage
@do_not_manage
end
def self.do_not_manage=(value)
@do_not_manage = value
end
def self.instances def self.instances
list_neutron_resources('router').collect do |id| self.do_not_manage = true
list = list_neutron_resources('router').collect do |id|
attrs = get_neutron_resource_attrs('router', id) attrs = get_neutron_resource_attrs('router', id)
new( new(
:ensure => :present, :ensure => :present,
@ -30,6 +39,8 @@ Puppet::Type.type(:neutron_router).provide(
:tenant_id => attrs['tenant_id'] :tenant_id => attrs['tenant_id']
) )
end end
self.do_not_manage = false
list
end end
def self.prefetch(resources) def self.prefetch(resources)
@ -46,6 +57,10 @@ Puppet::Type.type(:neutron_router).provide(
end end
def create def create
if self.class.do_not_manage
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
end
opts = Array.new opts = Array.new
if @resource[:admin_state_up] == 'False' if @resource[:admin_state_up] == 'False'
@ -105,6 +120,9 @@ EOT
end end
def destroy def destroy
if self.class.do_not_manage
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
end
auth_neutron('router-delete', name) auth_neutron('router-delete', name)
@property_hash[:ensure] = :absent @property_hash[:ensure] = :absent
end end
@ -121,6 +139,9 @@ EOT
end end
def gateway_network_name=(value) def gateway_network_name=(value)
if self.class.do_not_manage
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
end
if value == '' if value == ''
auth_neutron('router-gateway-clear', name) auth_neutron('router-gateway-clear', name)
else else
@ -142,6 +163,9 @@ EOT
end end
def admin_state_up=(value) def admin_state_up=(value)
if self.class.do_not_manage
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
end
set_admin_state_up(value) set_admin_state_up(value)
end end
@ -150,6 +174,9 @@ EOT
end end
def distributed=(value) def distributed=(value)
if self.class.do_not_manage
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
end
results = auth_neutron("router-show", '--format=shell', resource[:name]) results = auth_neutron("router-show", '--format=shell', resource[:name])
attrs = self.class.parse_creation_output(results) attrs = self.class.parse_creation_output(results)
set_admin_state_up(false) set_admin_state_up(false)
@ -160,6 +187,9 @@ EOT
end end
def ha=(value) def ha=(value)
if self.class.do_not_manage
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
end
results = auth_neutron("router-show", '--format=shell', resource[:name]) results = auth_neutron("router-show", '--format=shell', resource[:name])
attrs = self.class.parse_creation_output(results) attrs = self.class.parse_creation_output(results)
set_admin_state_up(false) set_admin_state_up(false)

View File

@ -20,8 +20,17 @@ Puppet::Type.type(:neutron_subnet).provide(
'subnet' 'subnet'
end end
def self.do_not_manage
@do_not_manage
end
def self.do_not_manage=(value)
@do_not_manage = value
end
def self.instances def self.instances
list_neutron_resources(neutron_type).collect do |id| self.do_not_manage = true
list = list_neutron_resources(neutron_type).collect do |id|
attrs = get_neutron_resource_attrs(neutron_type, id) attrs = get_neutron_resource_attrs(neutron_type, id)
new( new(
:ensure => :present, :ensure => :present,
@ -38,6 +47,8 @@ Puppet::Type.type(:neutron_subnet).provide(
:tenant_id => attrs['tenant_id'] :tenant_id => attrs['tenant_id']
) )
end end
self.do_not_manage = false
list
end end
def self.prefetch(resources) def self.prefetch(resources)
@ -88,6 +99,10 @@ Puppet::Type.type(:neutron_subnet).provide(
end end
def create def create
if self.class.do_not_manage
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
end
opts = ["--name=#{@resource[:name]}"] opts = ["--name=#{@resource[:name]}"]
if @resource[:ip_version] if @resource[:ip_version]
@ -165,11 +180,17 @@ Puppet::Type.type(:neutron_subnet).provide(
end end
def destroy def destroy
if self.class.do_not_manage
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
end
auth_neutron('subnet-delete', name) auth_neutron('subnet-delete', name)
@property_hash[:ensure] = :absent @property_hash[:ensure] = :absent
end end
def gateway_ip=(value) def gateway_ip=(value)
if self.class.do_not_manage
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
end
if value == '' if value == ''
auth_neutron('subnet-update', '--no-gateway', name) auth_neutron('subnet-update', '--no-gateway', name)
else else
@ -178,6 +199,9 @@ Puppet::Type.type(:neutron_subnet).provide(
end end
def enable_dhcp=(value) def enable_dhcp=(value)
if self.class.do_not_manage
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
end
if value == 'False' if value == 'False'
auth_neutron('subnet-update', "--disable-dhcp", name) auth_neutron('subnet-update', "--disable-dhcp", name)
else else
@ -186,6 +210,9 @@ Puppet::Type.type(:neutron_subnet).provide(
end end
def dns_nameservers=(values) def dns_nameservers=(values)
if self.class.do_not_manage
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
end
unless values.empty? unless values.empty?
opts = ["#{name}", "--dns-nameservers", "list=true"] opts = ["#{name}", "--dns-nameservers", "list=true"]
for value in values for value in values
@ -196,6 +223,9 @@ Puppet::Type.type(:neutron_subnet).provide(
end end
def host_routes=(values) def host_routes=(values)
if self.class.do_not_manage
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
end
unless values.empty? unless values.empty?
opts = ["#{name}", "--host-routes", "type=dict", "list=true"] opts = ["#{name}", "--host-routes", "type=dict", "list=true"]
for value in values for value in values