From 0fed3e115548ccd01c1c53feb5110ddc92188ef5 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 14 Sep 2025 02:21:34 +0900 Subject: [PATCH] Add parameter types to openstack_extras::auth_file Change-Id: I33b25eb5ab4b74bd82cf2089809a1f4ef1dfa28e Signed-off-by: Takashi Kajinami --- .puppet-lint.rc | 1 - manifests/auth_file.pp | 52 +++++++++---------- .../openstack_extras_auth_file_spec.rb | 2 +- spec/spec_helper.rb | 6 ++- spec/type_aliases/apiversion_spec.rb | 46 ++++++++++++++++ spec/type_aliases/endpointtype_spec.rb | 39 ++++++++++++++ types/apiversion.pp | 5 ++ types/endpointtype.pp | 8 +++ 8 files changed, 130 insertions(+), 29 deletions(-) create mode 100644 spec/type_aliases/apiversion_spec.rb create mode 100644 spec/type_aliases/endpointtype_spec.rb create mode 100644 types/apiversion.pp create mode 100644 types/endpointtype.pp diff --git a/.puppet-lint.rc b/.puppet-lint.rc index d69fc48..fa32f36 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1,2 +1 @@ ---no-parameter_types-check --no-strict_indent-check diff --git a/manifests/auth_file.pp b/manifests/auth_file.pp index 7350cad..e090605 100644 --- a/manifests/auth_file.pp +++ b/manifests/auth_file.pp @@ -114,32 +114,32 @@ # Defaults to undef. # class openstack_extras::auth_file ( - $password, - $auth_url = 'http://127.0.0.1:5000/v3/', - $service_token = undef, - $service_endpoint = 'http://127.0.0.1:5000/v3/', - $username = 'admin', - $project_name = 'openstack', - $region_name = 'RegionOne', - $use_no_cache = true, - $project_domain_name = 'Default', - $user_domain_name = 'Default', - $auth_type = undef, - $os_interface = 'public', - $os_endpoint_type = 'publicURL', - $cinder_endpoint_type = 'publicURL', - $glance_endpoint_type = 'publicURL', - $keystone_endpoint_type = 'publicURL', - $nova_endpoint_type = 'publicURL', - $neutron_endpoint_type = 'publicURL', - $auth_strategy = 'keystone', - $path = '/root/openrc', - $compute_api_version = undef, - $network_api_version = undef, - $image_api_version = undef, - $volume_api_version = undef, - $identity_api_version = '3', - $object_api_version = undef, + String[1] $password, + Stdlib::HTTPUrl $auth_url = 'http://127.0.0.1:5000/v3/', + Optional[String[1]] $service_token = undef, + Stdlib::HTTPUrl $service_endpoint = 'http://127.0.0.1:5000/v3/', + String[1] $username = 'admin', + String[1] $project_name = 'openstack', + String[1] $region_name = 'RegionOne', + Boolean $use_no_cache = true, + String[1] $project_domain_name = 'Default', + String[1] $user_domain_name = 'Default', + Optional[String[1]] $auth_type = undef, + Openstack_extras::EndpointType $os_interface = 'public', + Openstack_extras::EndpointType $os_endpoint_type = 'publicURL', + Openstack_extras::EndpointType $cinder_endpoint_type = 'publicURL', + Openstack_extras::EndpointType $glance_endpoint_type = 'publicURL', + Openstack_extras::EndpointType $keystone_endpoint_type = 'publicURL', + Openstack_extras::EndpointType $nova_endpoint_type = 'publicURL', + Openstack_extras::EndpointType $neutron_endpoint_type = 'publicURL', + String[1] $auth_strategy = 'keystone', + Stdlib::Absolutepath $path = '/root/openrc', + Optional[Openstack_extras::ApiVersion] $compute_api_version = undef, + Optional[Openstack_extras::ApiVersion] $network_api_version = undef, + Optional[Openstack_extras::ApiVersion] $image_api_version = undef, + Optional[Openstack_extras::ApiVersion] $volume_api_version = undef, + Openstack_extras::ApiVersion $identity_api_version = 3, + Optional[Openstack_extras::ApiVersion] $object_api_version = undef, ) { file { $path: ensure => file, diff --git a/spec/classes/openstack_extras_auth_file_spec.rb b/spec/classes/openstack_extras_auth_file_spec.rb index db92833..16a4432 100644 --- a/spec/classes/openstack_extras_auth_file_spec.rb +++ b/spec/classes/openstack_extras_auth_file_spec.rb @@ -51,7 +51,7 @@ describe 'openstack_extras::auth_file' do :username => 'myuser', :project_name => 'myproject', :region_name => 'myregion', - :use_no_cache => 'false', + :use_no_cache => false, :os_interface => 'internal', :os_endpoint_type => 'internalURL', :cinder_endpoint_type => 'internalURL', diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b68b8dd..0eaf1be 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,8 @@ -require 'puppetlabs_spec_helper/module_spec_helper' +if ENV.fetch('IMPLEMENTATION', 'puppet') == 'puppet' + require 'puppetlabs_spec_helper/module_spec_helper' +else + require 'voxpupuli/test/spec_helper' +end require 'shared_examples' require 'puppet-openstack_spec_helper/facts' diff --git a/spec/type_aliases/apiversion_spec.rb b/spec/type_aliases/apiversion_spec.rb new file mode 100644 index 0000000..fb3d293 --- /dev/null +++ b/spec/type_aliases/apiversion_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'Openstack_extras::ApiVersion' do + describe 'valid types' do + context 'with valid types' do + [ + 1, + 2, + 1.0, + 2.1, + '1', + '2', + '1.0', + '2.1', + ].each do |value| + describe value.inspect do + it { is_expected.to allow_value(value) } + end + end + end + end + + describe 'invalid types' do + context 'with garbage inputs' do + [ + nil, + 0, + -1, + 0.9, + -0.1, + false, + '', + '-1', + '-1.0', + '0.9', + '1.1.2', + '1.1a', + '', + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end +end diff --git a/spec/type_aliases/endpointtype_spec.rb b/spec/type_aliases/endpointtype_spec.rb new file mode 100644 index 0000000..0d366f0 --- /dev/null +++ b/spec/type_aliases/endpointtype_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe 'Openstack_extras::EndpointType' do + describe 'valid types' do + context 'with valid types' do + [ + 'public', + 'internal', + 'admin', + 'publicURL', + 'internalURL', + 'adminURL', + ].each do |value| + describe value.inspect do + it { is_expected.to allow_value(value) } + end + end + end + end + + describe 'invalid types' do + context 'with garbage inputs' do + [ + nil, + 0, + false, + '', + 'unknown', + ['public'], + {'public' => 'public'}, + '', + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end +end diff --git a/types/apiversion.pp b/types/apiversion.pp new file mode 100644 index 0000000..e54352d --- /dev/null +++ b/types/apiversion.pp @@ -0,0 +1,5 @@ +type Openstack_extras::ApiVersion = Variant[ + Integer[1], + Float[1], + Pattern[/^[1-9]\d*(\.\d+)?$/], +] diff --git a/types/endpointtype.pp b/types/endpointtype.pp new file mode 100644 index 0000000..80bbd1f --- /dev/null +++ b/types/endpointtype.pp @@ -0,0 +1,8 @@ +type Openstack_extras::EndpointType = Enum[ + 'public', + 'internal', + 'admin', + 'publicURL', + 'internalURL', + 'adminURL', +]