From 5736ebba4cb2c7782ce1a1cd9112f754080bf8a6 Mon Sep 17 00:00:00 2001 From: Vasyl Saienko Date: Sat, 25 Mar 2017 00:58:01 +0200 Subject: [PATCH] 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 --- examples/ironic_config_to_swift_uuid.pp | 3 ++ .../provider/ironic_config/ini_setting.rb | 15 ++++++ manifests/glance.pp | 53 +++++++++++++------ ...account_project_uuid-c4c5af7095f51c78.yaml | 7 +++ spec/classes/ironic_glance_spec.rb | 11 ++++ 5 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 examples/ironic_config_to_swift_uuid.pp create mode 100644 releasenotes/notes/ironic_config_get_swift_account_project_uuid-c4c5af7095f51c78.yaml diff --git a/examples/ironic_config_to_swift_uuid.pp b/examples/ironic_config_to_swift_uuid.pp new file mode 100644 index 00000000..94bd80d3 --- /dev/null +++ b/examples/ironic_config_to_swift_uuid.pp @@ -0,0 +1,3 @@ +ironic_config { + 'glance/swift_account': value => 'swift_user_project', transform_to => 'project_uuid'; +} diff --git a/lib/puppet/provider/ironic_config/ini_setting.rb b/lib/puppet/provider/ironic_config/ini_setting.rb index 91f5af76..cdfcca78 100644 --- a/lib/puppet/provider/ironic_config/ini_setting.rb +++ b/lib/puppet/provider/ironic_config/ini_setting.rb @@ -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 diff --git a/manifests/glance.pp b/manifests/glance.pp index 566372a1..09a65ce5 100644 --- a/manifests/glance.pp +++ b/manifests/glance.pp @@ -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; + } + } } diff --git a/releasenotes/notes/ironic_config_get_swift_account_project_uuid-c4c5af7095f51c78.yaml b/releasenotes/notes/ironic_config_get_swift_account_project_uuid-c4c5af7095f51c78.yaml new file mode 100644 index 00000000..2a6ddd36 --- /dev/null +++ b/releasenotes/notes/ironic_config_get_swift_account_project_uuid-c4c5af7095f51c78.yaml @@ -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. diff --git a/spec/classes/ironic_glance_spec.rb b/spec/classes/ironic_glance_spec.rb index f86e8056..fb59ce9e 100644 --- a/spec/classes/ironic_glance_spec.rb +++ b/spec/classes/ironic_glance_spec.rb @@ -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({