Use user model for grant_domain, revoke_domain

Unlike the rest of the library, openstack_user's grant_domain and
revoke_domain actions bypass the fog models and call directly into the
requests. It works, but it is inconsistent and confusing.

This patch uses user.grant_role instead of directly calling
connection.grant_domain_user_role. Likewise for revoke_domain.
This commit is contained in:
Roger Luethi 2017-11-10 15:43:58 +01:00
parent ae02bdc632
commit 049eb35d46
2 changed files with 10 additions and 12 deletions

View File

@ -85,16 +85,14 @@ module OpenstackclientCookbook
user = connection.users.find { |u| u.name == user_name }
domain = connection.domains.find { |p| p.name == domain_name }
role = connection.roles.find { |r| r.name == role_name }
connection.grant_domain_user_role(
domain.id, user.id, role.id) if role && domain && user
user.grant_role role.id if role && domain && user
end
action :revoke_domain do
user = connection.users.find { |u| u.name == user_name }
domain = connection.domains.find { |p| p.name == domain_name }
role = connection.roles.find { |r| r.name == role_name }
connection.revoke_domain_user_role(
domain.id, user.id, role.id) if role && domain && user
user.revoke_role role.id if role && domain && user
end
end
end

View File

@ -35,7 +35,9 @@ describe 'openstackclient_test::user' do
let(:found_user) do
double :find,
id: 4,
destroy: true
destroy: true,
grant_role: true,
revoke_role: true
end
let(:users_populated) do
@ -155,9 +157,7 @@ describe 'openstackclient_test::user' do
users: users_populated,
domains: domains_populated,
roles: roles_populated,
projects: projects_populated,
grant_domain_user_role: true,
revoke_domain_user_role: true
projects: projects_populated
end
before do
@ -244,14 +244,14 @@ describe 'openstackclient_test::user' do
end
it do
expect(connection_dub).to receive(:grant_domain_user_role)
.with(5, 4, 3)
expect(found_user).to receive(:grant_role)
.with(3)
chef_run
end
it do
expect(connection_dub).to receive(:revoke_domain_user_role)
.with(5, 4, 3)
expect(found_user).to receive(:revoke_role)
.with(3)
chef_run
end
end