46 lines
1.4 KiB
Ruby
Raw Normal View History

# Load libraries from openstacklib here to simulate how they live together in a real puppet run (for provider unit tests)
$LOAD_PATH.push(File.join(File.dirname(__FILE__), 'fixtures', 'modules', 'openstacklib', 'lib'))
require 'puppetlabs_spec_helper/module_spec_helper'
require 'shared_examples'
require 'webmock/rspec'
require 'puppet-openstack_spec_helper/defaults'
require 'rspec-puppet-facts'
include RspecPuppetFacts
# LP1492636 - Cohabitation of compile matcher and webmock
WebMock.disable_net_connect!(:allow => "169.254.169.254")
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_configures, 'configures'
c.alias_it_should_behave_like_to :it_raises, 'raises'
# TODO(aschultz): remove this after all tests converted to use OSDefaults
# instead of referencing @default_facts
c.before :each do
@default_facts = OSDefaults.get_facts
end
end
RSpec::Matchers.define :be_absent do
match do |actual|
actual == :absent
end
end
at_exit { RSpec::Puppet::Coverage.report! }
def setup_provider_tests
Puppet::Provider::Keystone.class_exec do
def self.reset
@admin_endpoint = nil
@tenant_hash = nil
@admin_token = nil
@keystone_file = nil
Puppet::Provider::Keystone.class_variable_set('@@default_domain_id', nil)
@domain_hash = nil
end
end
end
Add composite namevar for tenant, user, user_role. There are two sides on this patch, the user facing one, and the developer's one. It gives more flexibility for the interface used by the user for the Keystone_tenant, Keystone_user and Keystone_user_roles resources. For instance to specify a user and give the admin role, currently you have to: keystone_user { 'new_admin::admin_domain': ensure => present, enabled => true, tenant => 'openstackv3::admin_domain', email => 'test@example.tld', password => 'a_big_secret', } keystone_user_role { 'new_admin::admin_domain@openstackv3::admin_domain': ensure => present, roles => ['admin'], } Now you can specify it like this: keystone_user { 'new_admin': ensure => present, enabled => true, domain => 'admin_domain', tenant => 'openstackv3::admin_domain', email => 'test@example.tld', password => 'a_big_secret', } keystone_user_role { 'new_admin@openstackv3': ensure => present, user_domain => 'admin_domain', project_domain => 'admin_domain', roles => ['admin'], } For the developer this simplify the code. Puppet is using composite namevar to make all the resources unique. So guessing what pattern is used in the title is no longer required. For instance this : keystone_tenant { 'project_one': ensure => present } keystone_tenant { 'meaningless': name => 'project_one', domain => 'Default', ensure => present } is detected as the same tenant by puppet. The same is true for dependencies. This is working correctly: keystone_tenant { 'meaningless': name => 'project_one', domain => 'domain_one', ensure => present } file {'/tmp/needed': ensure => present, require => Keystone_tenant['project_one::domain_one'] } In autorequire term in type definition, you just have to pass the fully qualified name (with the domain suffix for user and tenant) of the resource and puppet will do the matching, whatever the original title is. See the examples in user and tenant in keystone_user_role type. Change-Id: I4deb27dc6f71fb7a7ec6a9c72bd0e1412c2e9a30
2015-09-23 20:17:31 +02:00
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }