Merge "limit: Support new options to query endpoint"

This commit is contained in:
Zuul 2024-10-11 16:44:56 +00:00 committed by Gerrit Code Review
commit 6b04e13ad4
3 changed files with 174 additions and 86 deletions

View File

@ -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,11 +72,15 @@
# Defaults to $facts['os_service_default'].
#
define oslo::limit(
$endpoint_id,
$username,
$password,
$auth_url,
$project_name = $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'],
@ -68,6 +91,13 @@ define oslo::limit(
$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,7 +109,11 @@ define oslo::limit(
}
$limit_options = {
'oslo_limit/endpoint_id' => { value => $endpoint_id },
'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 },

View File

@ -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``

View File

@ -8,27 +8,32 @@ 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',
}
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/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')
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('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('oslo_limit/endpoint_service_name').with_value('<SERVICE DEFAULT>')
end
it 'configures the default params' do
is_expected.to contain_keystone_config('oslo_limit/project_name').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('oslo_limit/endpoint_region_name').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('oslo_limit/endpoint_interface').with_value('<SERVICE DEFAULT>')
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('<SERVICE DEFAULT>')
@ -41,9 +46,12 @@ describe 'oslo::limit' do
end
context 'with parameters overridden' do
let :params do
required_params.merge!({
:project_name => 'services',
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',
@ -55,7 +63,10 @@ describe 'oslo::limit' do
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/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('<SERVICE DEFAULT>')
@ -68,8 +79,8 @@ describe 'oslo::limit' do
end
context 'with system_scope' do
let :params do
required_params.merge!({
before :each do
params.merge!({
:project_name => 'services',
:system_scope => 'all',
})
@ -83,6 +94,39 @@ describe 'oslo::limit' do
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/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('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('oslo_limit/endpoint_service_type').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('oslo_limit/endpoint_service_name').with_value('nova')
end
end
context 'with endpoint_service_type' do
let :params do
required_params.merge({
:endpoint_service_type => 'compute',
})
end
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('<SERVICE DEFAULT>')
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('<SERVICE DEFAULT>')
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|