Implement better nova_admin_tenant_id_setter exists? method
Actually do some checking in the exists? method here to see if the neutron.conf nova_admin_tenant_id setting is correct already. That way Puppet can properly recognize when the resource is already in the right state. Change-Id: I9692f4689683298cba4af1cacd700975f7e50b17 Closes-bug: 1392862
This commit is contained in:
parent
663b4b16d2
commit
4914498877
@ -12,6 +12,7 @@ require 'rubygems'
|
||||
require 'net/http'
|
||||
require 'net/https'
|
||||
require 'json'
|
||||
require 'puppet/util/inifile'
|
||||
|
||||
class KeystoneError < Puppet::Error
|
||||
end
|
||||
@ -126,6 +127,8 @@ def keystone_v2_tenants(auth_url,
|
||||
end
|
||||
|
||||
Puppet::Type.type(:nova_admin_tenant_id_setter).provide(:ruby) do
|
||||
@tenant_id = nil
|
||||
|
||||
def authenticate
|
||||
keystone_v2_authenticate(
|
||||
@resource[:auth_url],
|
||||
@ -144,13 +147,19 @@ Puppet::Type.type(:nova_admin_tenant_id_setter).provide(:ruby) do
|
||||
end
|
||||
|
||||
def exists?
|
||||
false
|
||||
ini_file = Puppet::Util::IniConfig::File.new
|
||||
ini_file.read("/etc/neutron/neutron.conf")
|
||||
ini_file['DEFAULT'] && ini_file['DEFAULT']['nova_admin_tenant_id'] && ini_file['DEFAULT']['nova_admin_tenant_id'] == tenant_id
|
||||
end
|
||||
|
||||
def create
|
||||
config
|
||||
end
|
||||
|
||||
def tenant_id
|
||||
@tenant_id ||= get_tenant_id
|
||||
end
|
||||
|
||||
# This looks for the tenant specified by the 'tenant_name' parameter to
|
||||
# the resource and returns the corresponding UUID if there is a single
|
||||
# match.
|
||||
@ -174,7 +183,7 @@ Puppet::Type.type(:nova_admin_tenant_id_setter).provide(:ruby) do
|
||||
|
||||
def config
|
||||
Puppet::Type.type(:neutron_config).new(
|
||||
{:name => 'DEFAULT/nova_admin_tenant_id', :value => "#{get_tenant_id}"}
|
||||
{:name => 'DEFAULT/nova_admin_tenant_id', :value => "#{tenant_id}"}
|
||||
).create
|
||||
end
|
||||
|
||||
|
@ -77,6 +77,19 @@ describe 'Puppet::Type.type(:nova_admin_tenant_id_setter)' do
|
||||
expect(provider.exists?).to be_false
|
||||
expect(provider.create).to be_nil
|
||||
end
|
||||
|
||||
context 'when tenant id already set' do
|
||||
it 'should create a resource, with exists? true' do
|
||||
mock = { 'DEFAULT' => { 'nova_admin_tenant_id' => 'UUID_SERVICES' } }
|
||||
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
|
||||
mock.expects(:read).with('/etc/neutron/neutron.conf')
|
||||
|
||||
resource = Puppet::Type::Nova_admin_tenant_id_setter.new(params)
|
||||
provider = provider_class.new(resource)
|
||||
expect(provider.exists?).to be_true
|
||||
expect(provider.create).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# What happens if we ask for a tenant that does not exist?
|
||||
|
Loading…
Reference in New Issue
Block a user