Specify the default tenant during user create

If the project tenant is given when creating the user account,
honor it by assigning that as the _default_ project tenant.

This is especially helpful when creating initial service accounts and
assigning them to the `service` project).
This commit is contained in:
Howard Abrams 2017-04-11 14:38:58 -07:00
parent 57e59b64e4
commit 03fbe7b7a3
2 changed files with 4 additions and 0 deletions

View File

@ -31,12 +31,14 @@ module OpenstackclientCookbook
action :create do action :create do
user = connection.users.find { |u| u.name == user_name } user = connection.users.find { |u| u.name == user_name }
project = connection.projects.find { |p| p.name == project_name }
if user if user
log "User with name: \"#{user_name}\" already exists" log "User with name: \"#{user_name}\" already exists"
else else
connection.users.create( connection.users.create(
name: user_name, name: user_name,
email: email, email: email,
default_project_id: project ? project.id : nil,
password: password password: password
) )
end end

View File

@ -65,6 +65,7 @@ describe 'openstackclient_test::user' do
let(:found_project) do let(:found_project) do
double :find, double :find,
id: 42,
grant_role_to_user: true, grant_role_to_user: true,
revoke_role_from_user: true revoke_role_from_user: true
end end
@ -133,6 +134,7 @@ describe 'openstackclient_test::user' do
.with( .with(
name: 'myuser', name: 'myuser',
email: 'myemail', email: 'myemail',
default_project_id: 42,
password: 'mypassword' password: 'mypassword'
) )
chef_run chef_run