Add ability to translate swift account project name to UUID

This patch adds ability to translate swift account project name to UUID and update
glance/swift_account option in the following format 'AUTH_uuid'.

By either calling ironic_config directly:

  ironic_config {
    'glance/swift_account': value => 'swift_account_project_name', transform_to => 'project_uuid'
  }

or by defining ::ironic::glance class:

  class{'::ironic::glance':
    swift_account_project_name => 'project_name'
  }

Change-Id: I1df2e069b7922f64c0971551bf57d7c06bd318e2
This commit is contained in:
Vasyl Saienko 2017-03-25 00:58:01 +02:00
parent 36dd4c1b6f
commit 5736ebba4c
5 changed files with 74 additions and 15 deletions

View File

@ -0,0 +1,3 @@
ironic_config {
'glance/swift_account': value => 'swift_user_project', transform_to => 'project_uuid';
}

View File

@ -24,4 +24,19 @@ Puppet::Type.type(:ironic_config).provide(
return res[:name]
end
def to_project_uuid(name)
properties = [name, '--column', 'id']
openstack = Puppet::Provider::Ironic::OpenstackRequest.new
res = openstack.openstack_request('project', 'show', properties)
return "AUTH_#{res[:id]}"
end
def from_project_uuid(uuid)
uuid = uuid.sub('AUTH_','')
properties = [uuid, '--column', 'name']
openstack = Puppet::Provider::Ironic::OpenstackRequest.new
res = openstack.openstack_request('project', 'show', properties)
return "AUTH_#{res[:name]}"
end
end

View File

@ -55,9 +55,17 @@
#
# [*swift_account*]
# (optional) The account that Glance uses to communicate with Swift.
# The format is "AUTH_uuid"
# The format is "AUTH_uuid".
# Can not be set together with swift_account_project_name.
# Defaults to $::os_service_default
#
# [*swift_account_project_name*]
# (optional) The project of account that Glance uses to communicate with Swift.
# Will be converted to UUID, and option glance/swift_account will be set in
# the "AUTH_uuid" format.
# Can not be set together with swift_account.
# Defaults to undef, which leaves the configuration intact
#
# [*swift_temp_url_key*]
# (optional) The secret token given to Swift to allow temporary URL
# downloads. Required for several drivers (e.g. agent_ipmitool).
@ -69,19 +77,20 @@
# Defaults to $::os_service_default
#
class ironic::glance (
$auth_type = 'password',
$auth_url = $::os_service_default,
$project_name = 'services',
$username = 'ironic',
$password = $::os_service_default,
$user_domain_name = $::os_service_default,
$project_domain_name = $::os_service_default,
$api_servers = $::os_service_default,
$num_retries = $::os_service_default,
$api_insecure = $::os_service_default,
$swift_account = $::os_service_default,
$swift_temp_url_key = $::os_service_default,
$swift_temp_url_duration = $::os_service_default,
$auth_type = 'password',
$auth_url = $::os_service_default,
$project_name = 'services',
$username = 'ironic',
$password = $::os_service_default,
$user_domain_name = $::os_service_default,
$project_domain_name = $::os_service_default,
$api_servers = $::os_service_default,
$num_retries = $::os_service_default,
$api_insecure = $::os_service_default,
$swift_account = $::os_service_default,
$swift_temp_url_key = $::os_service_default,
$swift_temp_url_duration = $::os_service_default,
$swift_account_project_name = undef,
) {
$api_servers_real = pick($::ironic::glance_api_servers, $api_servers)
@ -98,6 +107,11 @@ class ironic::glance (
$swift_temp_url_key_real = pick($::ironic::conductor::swift_temp_url_key, $swift_temp_url_key)
$swift_temp_url_duration_real = pick($::ironic::conductor::swift_temp_url_duration, $swift_temp_url_duration)
if ($swift_account_project_name and !is_service_default($swift_account_real)) {
fail('swift_account_project_name and swift_account can not be specified in the same time.')
}
ironic_config {
'glance/auth_type': value => $auth_type;
'glance/username': value => $username;
@ -109,8 +123,17 @@ class ironic::glance (
'glance/glance_api_servers': value => $api_servers_converted;
'glance/glance_num_retries': value => $num_retries_real;
'glance/glance_api_insecure': value => $api_insecure_real;
'glance/swift_account': value => $swift_account_real;
'glance/swift_temp_url_key': value => $swift_temp_url_key_real, secret => true;
'glance/swift_temp_url_duration': value => $swift_temp_url_duration_real;
}
if $swift_account_project_name {
ironic_config {
'glance/swift_account': value => $swift_account_project_name, transform_to => 'project_uuid';
}
} else {
ironic_config {
'glance/swift_account': value => $swift_account_real;
}
}
}

View File

@ -0,0 +1,7 @@
---
features:
- Add the ability to convert swift project name to UUID and
set glance/swift_account configuration option. By adding
transform_to => 'project_uuid' parameter to ironic_conifg
option. Or setting ``swift_account_project_name`` parameter
in ::ironic::glance class.

View File

@ -115,6 +115,17 @@ describe 'ironic::glance' do
end
end
context 'when overriding parameters swift_account_project_name' do
before :each do
params.merge!(
:swift_account_project_name => 'abc',
)
end
it 'should set swift_account with new value' do
is_expected.to contain_ironic_config('glance/swift_account').with_value('abc').with_transform_to('project_uuid')
end
end
end
on_supported_os({