From d1eb834a2087c6010f1ea4d7f834a219c0603012 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 31 Aug 2021 10:00:15 +0900 Subject: [PATCH] CredentialsV3: Ensure all attributes are cleared by unset Currently the unset method only clears attributes defined in the base Crednetial class and ones specific to CredentialV3 are left set. This change ensures the method clears all attributes. Closes-Bug: #1942145 Change-Id: I4bddbf9bb3c6251aa8b68a8bc2ef8799f3c8065e --- lib/puppet/provider/openstack/credentials.rb | 8 ++++---- spec/unit/provider/openstack/credentials_spec.rb | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/openstack/credentials.rb b/lib/puppet/provider/openstack/credentials.rb index afade9c2..1fa852a1 100644 --- a/lib/puppet/provider/openstack/credentials.rb +++ b/lib/puppet/provider/openstack/credentials.rb @@ -45,10 +45,10 @@ class Puppet::Provider::Openstack::Credentials end def unset - KEYS.each do |key| - if key != :identity_api_version && - self.instance_variable_defined?("@#{key}") - set(key, '') + self.instance_variables.each do |var| + if var.to_s != '@identity_api_version' && + self.instance_variable_defined?(var.to_s) + set(var.to_s.sub(/^@/,''), '') end end end diff --git a/spec/unit/provider/openstack/credentials_spec.rb b/spec/unit/provider/openstack/credentials_spec.rb index 1562454f..3baa4eb4 100644 --- a/spec/unit/provider/openstack/credentials_spec.rb +++ b/spec/unit/provider/openstack/credentials_spec.rb @@ -86,6 +86,7 @@ describe Puppet::Provider::Openstack::Credentials do creds.auth_url = 'auth_url' creds.password = 'password' creds.project_name = 'project_name' + creds.domain_name = 'domain_name' creds.username = 'username' creds.token = 'token' creds.endpoint = 'endpoint' @@ -94,6 +95,7 @@ describe Puppet::Provider::Openstack::Credentials do expect(creds.auth_url).to eq('') expect(creds.password).to eq('') expect(creds.project_name).to eq('') + expect(creds.domain_name).to eq('') expect(creds.username).to eq('') expect(creds.token).to eq('') expect(creds.endpoint).to eq('')