diff --git a/manifests/limit.pp b/manifests/limit.pp index 9aa033d..825a1ae 100644 --- a/manifests/limit.pp +++ b/manifests/limit.pp @@ -4,20 +4,39 @@ # # === Parameters: # -# [*endpoint_id*] -# (Required) The service's endpoint id which is registered in Keystone. -# # [*username*] # (Required) The name of the service user # # [*password*] # (Required) Password to create for the service user # +# [*endpoint_id*] +# (Optional) The service's endpoint id which is registered in Keystone. +# Defaults to undef +# +# [*endpoint_service_name*] +# (Optional) Service name for endpoint discovery +# Defaults to undef +# +# [*endpoint_service_type*] +# (Optional) Service type for endpoint discovery +# Defaults to undef +# +# [*endpoint_region_name*] +# (Optional) Region to which the endpoint belongs. +# Defaults to $facts['os_service_default'] +# +# [*endpoint_interface*] +# (Optional) The interface for endpoint discovery. +# Defaults to $facts['os_service_default'] +# # [*auth_url*] -# (Required) The URL to use for authentication. +# (Optional) The URL to use for authentication. +# Defaults to 'http://localhost:5000'. # # [*project_name*] -# (Required) Service project name +# (Optional) Service project name +# Defaults to 'services'. # # [*user_domain_name*] # (Optional) Name of domain for $username @@ -53,21 +72,32 @@ # Defaults to $facts['os_service_default']. # define oslo::limit( - $endpoint_id, - $username, - $password, - $auth_url, - $project_name = $facts['os_service_default'], - $user_domain_name = 'Default', - $project_domain_name = 'Default', - $system_scope = $facts['os_service_default'], - $auth_type = 'password', - $service_type = $facts['os_service_default'], - $valid_interfaces = $facts['os_service_default'], - $region_name = $facts['os_service_default'], - $endpoint_override = $facts['os_service_default'], + String[1] $username, + String[1] $password, + Optional[String[1]] $endpoint_id = undef, + Optional[String[1]] $endpoint_service_name = undef, + Optional[String[1]] $endpoint_service_type = undef, + $endpoint_region_name = $facts['os_service_default'], + $endpoint_interface = $facts['os_service_default'], + $auth_url = 'http://localhost:5000', + $project_name = 'services', + $user_domain_name = 'Default', + $project_domain_name = 'Default', + $system_scope = $facts['os_service_default'], + $auth_type = 'password', + $service_type = $facts['os_service_default'], + $valid_interfaces = $facts['os_service_default'], + $region_name = $facts['os_service_default'], + $endpoint_override = $facts['os_service_default'], ) { + if delete_undef_values([$endpoint_id, $endpoint_service_name, $endpoint_service_type]) == [] { + fail('Either endpoint_id, endpoint_service_name or endpoint_service_type is required') + } + if $endpoint_id and ($endpoint_service_name or $endpoint_service_type) { + fail('endpoint_id and endpoint_service_name/type are mutually exclusive') + } + if is_service_default($system_scope) { $project_name_real = $project_name $project_domain_name_real = $project_domain_name @@ -79,19 +109,23 @@ define oslo::limit( } $limit_options = { - 'oslo_limit/endpoint_id' => { value => $endpoint_id }, - 'oslo_limit/username' => { value => $username }, - 'oslo_limit/password' => { value => $password, secret => true }, - 'oslo_limit/auth_url' => { value => $auth_url }, - 'oslo_limit/project_name' => { value => $project_name_real }, - 'oslo_limit/user_domain_name' => { value => $user_domain_name }, - 'oslo_limit/project_domain_name' => { value => $project_domain_name_real }, - 'oslo_limit/system_scope' => { value => $system_scope }, - 'oslo_limit/auth_type' => { value => $auth_type }, - 'oslo_limit/service_type' => { value => $service_type }, - 'oslo_limit/valid_interfaces' => { value => join(any2array($valid_interfaces), ',') }, - 'oslo_limit/region_name' => { value => $region_name }, - 'oslo_limit/endpoint_override' => { value => $endpoint_override }, + 'oslo_limit/endpoint_id' => { value => pick($endpoint_id, $facts['os_service_default']) }, + 'oslo_limit/endpoint_service_name' => { value => pick($endpoint_service_name, $facts['os_service_default']) }, + 'oslo_limit/endpoint_service_type' => { value => pick($endpoint_service_type, $facts['os_service_default']) }, + 'oslo_limit/endpoint_region_name' => { value => $endpoint_region_name }, + 'oslo_limit/endpoint_interface' => { value => $endpoint_interface }, + 'oslo_limit/username' => { value => $username }, + 'oslo_limit/password' => { value => $password, secret => true }, + 'oslo_limit/auth_url' => { value => $auth_url }, + 'oslo_limit/project_name' => { value => $project_name_real }, + 'oslo_limit/user_domain_name' => { value => $user_domain_name }, + 'oslo_limit/project_domain_name' => { value => $project_domain_name_real }, + 'oslo_limit/system_scope' => { value => $system_scope }, + 'oslo_limit/auth_type' => { value => $auth_type }, + 'oslo_limit/service_type' => { value => $service_type }, + 'oslo_limit/valid_interfaces' => { value => join(any2array($valid_interfaces), ',') }, + 'oslo_limit/region_name' => { value => $region_name }, + 'oslo_limit/endpoint_override' => { value => $endpoint_override }, } create_resources($name, $limit_options) } diff --git a/releasenotes/notes/oslo-limit-query-endpoint-options-c85c4542bc678217.yaml b/releasenotes/notes/oslo-limit-query-endpoint-options-c85c4542bc678217.yaml new file mode 100644 index 0000000..b319c08 --- /dev/null +++ b/releasenotes/notes/oslo-limit-query-endpoint-options-c85c4542bc678217.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + The following parameters have been added to the ``oslo::limit`` defined + resource type. + + - ``endpoint_service_name`` + - ``endpoint_service_type`` + - ``endpoint_region_name`` + - ``endpoint_interface`` diff --git a/spec/defines/oslo_limit_spec.rb b/spec/defines/oslo_limit_spec.rb index 606b62f..984c5cf 100644 --- a/spec/defines/oslo_limit_spec.rb +++ b/spec/defines/oslo_limit_spec.rb @@ -8,77 +8,121 @@ describe 'oslo::limit' do let :required_params do { - :endpoint_id => '770f924a-e483-4b43-a6f3-73acc91f4757', - :username => 'keystone', - :password => 'keystone_password', - :auth_url => 'http://127.0.0.1:5000/v3', + :username => 'keystone', + :password => 'keystone_password', } end - context 'with default parameters' do + context 'with endpoint_id' do let :params do - required_params + required_params.merge!({ + :endpoint_id => '770f924a-e483-4b43-a6f3-73acc91f4757' + }) + end + + context 'with default parameters' do + it 'configures the required params' do + is_expected.to contain_keystone_config('oslo_limit/username').with_value('keystone') + is_expected.to contain_keystone_config('oslo_limit/password').with_value('keystone_password').with_secret(true) + is_expected.to contain_keystone_config('oslo_limit/endpoint_id').with_value('770f924a-e483-4b43-a6f3-73acc91f4757') + is_expected.to contain_keystone_config('oslo_limit/endpoint_service_type').with_value('') + is_expected.to contain_keystone_config('oslo_limit/endpoint_service_name').with_value('') + end + + it 'configures the default params' do + is_expected.to contain_keystone_config('oslo_limit/endpoint_region_name').with_value('') + is_expected.to contain_keystone_config('oslo_limit/endpoint_interface').with_value('') + is_expected.to contain_keystone_config('oslo_limit/auth_url').with_value('http://localhost:5000') + is_expected.to contain_keystone_config('oslo_limit/project_name').with_value('services') + is_expected.to contain_keystone_config('oslo_limit/user_domain_name').with_value('Default') + is_expected.to contain_keystone_config('oslo_limit/project_domain_name').with_value('Default') + is_expected.to contain_keystone_config('oslo_limit/system_scope').with_value('') + is_expected.to contain_keystone_config('oslo_limit/auth_type').with_value('password') + is_expected.to contain_keystone_config('oslo_limit/service_type').with_value('') + is_expected.to contain_keystone_config('oslo_limit/valid_interfaces').with_value('') + is_expected.to contain_keystone_config('oslo_limit/region_name').with_value('') + is_expected.to contain_keystone_config('oslo_limit/endpoint_override').with_value('') + end + end + + context 'with parameters overridden' do + before :each do + params.merge!({ + :endpoint_region_name => 'regionOne', + :endpoint_interface => 'public', + :auth_url => 'http://localhost:5000/v3', + :project_name => 'alt_services', + :user_domain_name => 'UserDomain', + :project_domain_name => 'ProjectDomain', + :auth_type => 'v3password', + :service_type => 'identity', + :valid_interfaces => ['admin', 'internal'], + :region_name => 'regionOne', + :endpoint_override => 'http://localhost:5000', + }) + end + + it 'configures the overridden values' do + is_expected.to contain_keystone_config('oslo_limit/endpoint_region_name').with_value('regionOne') + is_expected.to contain_keystone_config('oslo_limit/endpoint_interface').with_value('public') + is_expected.to contain_keystone_config('oslo_limit/auth_url').with_value('http://localhost:5000/v3') + is_expected.to contain_keystone_config('oslo_limit/project_name').with_value('alt_services') + is_expected.to contain_keystone_config('oslo_limit/user_domain_name').with_value('UserDomain') + is_expected.to contain_keystone_config('oslo_limit/project_domain_name').with_value('ProjectDomain') + is_expected.to contain_keystone_config('oslo_limit/system_scope').with_value('') + is_expected.to contain_keystone_config('oslo_limit/auth_type').with_value('v3password') + is_expected.to contain_keystone_config('oslo_limit/service_type').with_value('identity') + is_expected.to contain_keystone_config('oslo_limit/valid_interfaces').with_value('admin,internal') + is_expected.to contain_keystone_config('oslo_limit/region_name').with_value('regionOne') + is_expected.to contain_keystone_config('oslo_limit/endpoint_override').with_value('http://localhost:5000') + end + end + + context 'with system_scope' do + before :each do + params.merge!({ + :project_name => 'services', + :system_scope => 'all', + }) + end + + it 'configures system_scope but ignore project parameters' do + is_expected.to contain_keystone_config('oslo_limit/project_name').with_value('') + is_expected.to contain_keystone_config('oslo_limit/project_domain_name').with_value('') + is_expected.to contain_keystone_config('oslo_limit/system_scope').with_value('all') + end + end + end + + context 'with endpoint_service_name' do + let :params do + required_params.merge({ + :endpoint_service_name => 'nova', + }) end it 'configures the required params' do - is_expected.to contain_keystone_config('oslo_limit/endpoint_id').with_value('770f924a-e483-4b43-a6f3-73acc91f4757') is_expected.to contain_keystone_config('oslo_limit/username').with_value('keystone') is_expected.to contain_keystone_config('oslo_limit/password').with_value('keystone_password').with_secret(true) - is_expected.to contain_keystone_config('oslo_limit/auth_url').with_value('http://127.0.0.1:5000/v3') - end - - it 'configures the default params' do - is_expected.to contain_keystone_config('oslo_limit/project_name').with_value('') - is_expected.to contain_keystone_config('oslo_limit/user_domain_name').with_value('Default') - is_expected.to contain_keystone_config('oslo_limit/project_domain_name').with_value('Default') - is_expected.to contain_keystone_config('oslo_limit/system_scope').with_value('') - is_expected.to contain_keystone_config('oslo_limit/auth_type').with_value('password') - is_expected.to contain_keystone_config('oslo_limit/service_type').with_value('') - is_expected.to contain_keystone_config('oslo_limit/valid_interfaces').with_value('') - is_expected.to contain_keystone_config('oslo_limit/region_name').with_value('') - is_expected.to contain_keystone_config('oslo_limit/endpoint_override').with_value('') + is_expected.to contain_keystone_config('oslo_limit/endpoint_id').with_value('') + is_expected.to contain_keystone_config('oslo_limit/endpoint_service_type').with_value('') + is_expected.to contain_keystone_config('oslo_limit/endpoint_service_name').with_value('nova') end end - context 'with parameters overridden' do + context 'with endpoint_service_type' do let :params do - required_params.merge!({ - :project_name => 'services', - :user_domain_name => 'UserDomain', - :project_domain_name => 'ProjectDomain', - :auth_type => 'v3password', - :service_type => 'identity', - :valid_interfaces => ['admin', 'internal'], - :region_name => 'regionOne', - :endpoint_override => 'http://localhost:5000', + required_params.merge({ + :endpoint_service_type => 'compute', }) end - it 'configures the overridden values' do - is_expected.to contain_keystone_config('oslo_limit/project_name').with_value('services') - is_expected.to contain_keystone_config('oslo_limit/user_domain_name').with_value('UserDomain') - is_expected.to contain_keystone_config('oslo_limit/project_domain_name').with_value('ProjectDomain') - is_expected.to contain_keystone_config('oslo_limit/system_scope').with_value('') - is_expected.to contain_keystone_config('oslo_limit/auth_type').with_value('v3password') - is_expected.to contain_keystone_config('oslo_limit/service_type').with_value('identity') - is_expected.to contain_keystone_config('oslo_limit/valid_interfaces').with_value('admin,internal') - is_expected.to contain_keystone_config('oslo_limit/region_name').with_value('regionOne') - is_expected.to contain_keystone_config('oslo_limit/endpoint_override').with_value('http://localhost:5000') - end - end - - context 'with system_scope' do - let :params do - required_params.merge!({ - :project_name => 'services', - :system_scope => 'all', - }) - end - - it 'configures system_scope but ignore project parameters' do - is_expected.to contain_keystone_config('oslo_limit/project_name').with_value('') - is_expected.to contain_keystone_config('oslo_limit/project_domain_name').with_value('') - is_expected.to contain_keystone_config('oslo_limit/system_scope').with_value('all') + it 'configures the required params' do + is_expected.to contain_keystone_config('oslo_limit/username').with_value('keystone') + is_expected.to contain_keystone_config('oslo_limit/password').with_value('keystone_password').with_secret(true) + is_expected.to contain_keystone_config('oslo_limit/endpoint_id').with_value('') + is_expected.to contain_keystone_config('oslo_limit/endpoint_service_type').with_value('compute') + is_expected.to contain_keystone_config('oslo_limit/endpoint_service_name').with_value('') end end end