Cleanup and improve testing

Small improvements to testing, some cleanup
in formatting and changing the default value
for the password parameter by making it required
and removing the undef default value (instead
of using fail).

Change-Id: Ibd56e93ad7f398b04ec7fb9281af5d42d0e1548f
This commit is contained in:
Tobias Urdin 2020-02-16 21:32:14 +01:00
parent 1c072a304e
commit 6616e79e19
2 changed files with 74 additions and 61 deletions

View File

@ -7,150 +7,146 @@
# === Parameters
#
# [*password*]
# (required) Password for this account as defined in keystone
# (Required) Password for this account as defined in keystone
#
# [*auth_url*]
# (optional) URL to authenticate against
# (Optional) URL to authenticate against
# Defaults to 'http://127.0.0.1:5000/v3/'
#
# [*service_token*]
# (optional) Keystone service token
# (Optional) Keystone service token
# NOTE: This setting will trigger a warning from keystone.
# Authentication credentials will be ignored by keystone client
# in favor of token authentication.
# Defaults to undef.
#
# [*service_endpoint*]
# (optional) Keystone service endpoint
# (Optional) Keystone service endpoint
# Defaults to 'http://127.0.0.1:5000/v3/'
#
# [*username*]
# (optional) Username for this account as defined in keystone
# (Optional) Username for this account as defined in keystone
# Defaults to 'admin'.
#
# [*tenant_name*]
# (optional) Tenant for this account as defined in keystone
# (Optional) Tenant for this account as defined in keystone
# Defaults to undef.
#
# [*project_name*]
# (optional) Project for this account as defined in keystone
# (Optional) Project for this account as defined in keystone
# Use instead of tenant_name for when using identity v3.
# Defaults to 'openstack'.
#
# [*region_name*]
# (optional) Openstack region to use
# (Optional) Openstack region to use
# Defaults to 'RegionOne'.
#
# [*use_no_cache*]
# (optional) Do not use the auth token cache.
# (Optional) Do not use the auth token cache.
# Defaults to true.
#
# [*os_interface*]
# (optional) The common endpoint to use with OSC
# (Optional) The common endpoint to use with OSC
# Defaults to 'public'.
#
# [*os_endpoint_type*]
# (optional) The common endpoint to use with service-specific clients
# (Optional) The common endpoint to use with service-specific clients
# Defaults to 'publicURL'.
#
# [*cinder_endpoint_type*]
# (optional) The Cinder endpoint to use
# (Optional) The Cinder endpoint to use
# Defaults to 'publicURL'.
#
# [*glance_endpoint_type*]
# (optional) The Glance endpoint to use
# (Optional) The Glance endpoint to use
# Defaults to 'publicURL'.
#
# [*keystone_endpoint_type*]
# (optional) The Keystone endpoint to use
# (Optional) The Keystone endpoint to use
# Defaults to 'publicURL'.
#
# [*nova_endpoint_type*]
# (optional) The Nova endpoint to use
# (Optional) The Nova endpoint to use
# Defaults to 'publicURL'.
#
# [*neutron_endpoint_type*]
# (optional) The Neutron endpoint to use
# (Optional) The Neutron endpoint to use
# Defaults to 'publicURL'.
#
# [*auth_strategy*]
# (optional) The method to use for authentication
# (Optional) The method to use for authentication
# Defaults to 'keystone'.
#
# [*path*]
# (optional) File path
# (Optional) File path
# Defaults to '/root/openrc'.
#
# [*project_domain*]
# (optional) Project domain in v3 api.
# (Optional) Project domain in v3 api.
# Defaults to 'default'.
#
# [*user_domain*]
# (optional) User domain in v3 api.
# (Optional) User domain in v3 api.
# Defaults to 'default'.
#
# [*auth_type*]
# (optional) Authentication type to load.
# (Optional) Authentication type to load.
# Default to undef.
#
# [*compute_api_version*]
# (optional) Compute API version to use.
# (Optional) Compute API version to use.
# Defaults to undef.
#
# [*network_api_version*]
# (optional) Network API version to use.
# (Optional) Network API version to use.
# Defaults to undef.
#
# [*image_api_version*]
# (optional) Image API version to use.
# (Optional) Image API version to use.
# Defaults to undef.
#
# [*volume_api_version*]
# (optional) Volume API version to use.
# (Optional) Volume API version to use.
# Defaults to undef.
#
# [*identity_api_version*]
# (optional) Identity API version to use.
# (Optional) Identity API version to use.
# Defaults to '3'.
#
# [*object_api_version*]
# (optional) Object API version to use.
# (Optional) Object API version to use.
# Defaults to undef.
#
class openstack_extras::auth_file(
$password = undef,
$auth_url = 'http://127.0.0.1:5000/v3/',
$service_token = undef,
$service_endpoint = 'http://127.0.0.1:5000/v3/',
$username = 'admin',
$tenant_name = undef,
$project_name = 'openstack',
$region_name = 'RegionOne',
$use_no_cache = true,
$project_domain = 'default',
$user_domain = '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,
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',
$tenant_name = undef,
$project_name = 'openstack',
$region_name = 'RegionOne',
$use_no_cache = true,
$project_domain = 'default',
$user_domain = '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,
) {
if ! $password {
fail('You must specify a password for openstack_extras::auth_file')
}
file { $path:
owner => 'root',
group => 'root',

View File

@ -9,6 +9,14 @@ describe 'openstack_extras::auth_file' do
}
end
it { is_expected.to contain_file('/root/openrc').with(
:owner => 'root',
:group => 'root',
:mode => '0700',
:show_diff => false,
:tag => ['openrc'],
)}
it {
verify_contents(catalogue, '/root/openrc', [
'export OS_NO_CACHE=\'true\'',
@ -52,6 +60,7 @@ describe 'openstack_extras::auth_file' do
:nova_endpoint_type => 'internalURL',
:neutron_endpoint_type => 'internalURL',
:auth_strategy => 'no_auth',
:path => '/path/to/file',
:user_domain => 'anotherdomain',
:project_domain => 'anotherdomain',
:compute_api_version => '2.1',
@ -63,8 +72,16 @@ describe 'openstack_extras::auth_file' do
}
end
it { is_expected.to contain_file('/path/to/file').with(
:owner => 'root',
:group => 'root',
:mode => '0700',
:show_diff => false,
:tag => ['openrc'],
)}
it {
verify_contents(catalogue, '/root/openrc', [
verify_contents(catalogue, '/path/to/file', [
'export OS_SERVICE_TOKEN=\'servicetoken\'',
'export OS_SERVICE_ENDPOINT=\'http://127.0.0.2:5000/v3/\'',
'export OS_NO_CACHE=\'false\'',