Skip to content

Commit

Permalink
Fixes #30814 - change --owner_type's default to user (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
adiabramovitch authored Apr 8, 2021
1 parent ff069bd commit e3495d7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/hammer_cli_foreman/hosts/common_update_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ def request_params

private

def owner_id(name, type = 'User')

def owner_id(name, type)
return unless name
return resolver.user_id('option_login' => name) if type == 'User'
return resolver.usergroup_id('option_name' => name) if type == 'Usergroup'

resolver.usergroup_id('option_name' => name)
resolver.user_id('option_login' => name)
end

def proxy_id(name)
resolver.smart_proxy_id('option_name' => name) if name
end
Expand Down
33 changes: 33 additions & 0 deletions test/functional/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,39 @@

assert_cmd(expected_result, result)
end

it 'should create a host and set owner-type' do
params = ['--owner=admin']

api_expects_search(:users, {login: 'admin'}).returns(index_response([{ 'id' => 1 }]))

api_expects(:hosts, :create, 'Create a host with an owner').with_params(
'location_id' => 1, 'organization_id' => 1, 'host' => {
'owner_id' => 1, 'name' => 'test'
}
).returns(results: { 'owner' => 'admin', 'name' => 'test' })

expected_result = success_result("Host created.\n")

result = run_cmd(cmd + minimal_params_without_hostgroup + params)

assert_cmd(expected_result, result)
end

it 'should create a host with default owner-type User' do

api_expects(:hosts, :create, 'Create a host with an owner').with_params(
'location_id' => 1, 'organization_id' => 1, 'host' => {
'name' => 'test'
}
).returns(results: { 'owner_type' => 'User', 'name' => 'test' })

expected_result = success_result("Host created.\n")

result = run_cmd(cmd + minimal_params_without_hostgroup)

assert_cmd(expected_result, result)
end
end

describe 'host update' do
Expand Down

0 comments on commit e3495d7

Please sign in to comment.