hammer_cli_foreman 2.3.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/release_notes.md +27 -0
- data/lib/hammer_cli_foreman.rb +3 -0
- data/lib/hammer_cli_foreman/architecture.rb +5 -5
- data/lib/hammer_cli_foreman/bookmark.rb +6 -6
- data/lib/hammer_cli_foreman/command_extensions.rb +1 -0
- data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
- data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
- data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
- data/lib/hammer_cli_foreman/commands.rb +14 -0
- data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
- data/lib/hammer_cli_foreman/compute_resource.rb +22 -0
- data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
- data/lib/hammer_cli_foreman/config_group.rb +5 -5
- data/lib/hammer_cli_foreman/config_report.rb +2 -0
- data/lib/hammer_cli_foreman/filter.rb +2 -2
- data/lib/hammer_cli_foreman/host.rb +1 -11
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +6 -5
- data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
- data/lib/hammer_cli_foreman/model.rb +5 -5
- data/lib/hammer_cli_foreman/operating_system.rb +10 -9
- data/lib/hammer_cli_foreman/option_builders.rb +27 -7
- data/lib/hammer_cli_foreman/ping.rb +6 -1
- data/lib/hammer_cli_foreman/registration.rb +18 -0
- data/lib/hammer_cli_foreman/settings.rb +3 -3
- data/lib/hammer_cli_foreman/usergroup.rb +5 -5
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/test/data/2.4/foreman_api.json +1 -0
- data/test/data/2.5/foreman_api.json +1 -0
- data/test/functional/architecture_test.rb +79 -0
- data/test/functional/bookmark_test.rb +22 -1
- data/test/functional/compute_profile_test.rb +54 -0
- data/test/functional/compute_resource_test.rb +37 -0
- data/test/functional/config_group_test.rb +50 -0
- data/test/functional/filter_test.rb +115 -47
- data/test/functional/host_test.rb +99 -3
- data/test/functional/http_proxy_test.rb +12 -0
- data/test/functional/location_test.rb +13 -0
- data/test/functional/mail_notification_test.rb +20 -0
- data/test/functional/media_test.rb +11 -0
- data/test/functional/model_test.rb +50 -0
- data/test/functional/operating_system_test.rb +51 -0
- data/test/functional/ping_test.rb +33 -0
- data/test/functional/realm_test.rb +11 -0
- data/test/functional/registration_test.rb +8 -0
- data/test/functional/report_template_test.rb +11 -0
- data/test/functional/settings_test.rb +21 -0
- data/test/functional/status_test.rb +79 -13
- data/test/functional/template_test.rb +12 -0
- data/test/functional/user_test.rb +11 -0
- data/test/functional/usergroup_test.rb +51 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/apipie_resource_mock.rb +21 -0
- data/test/unit/architecture_test.rb +10 -1
- data/test/unit/bookmark_test.rb +99 -0
- data/test/unit/compute_profile_test.rb +87 -0
- data/test/unit/config_group_test.rb +10 -0
- data/test/unit/config_report_test.rb +1 -0
- data/test/unit/host_test.rb +0 -23
- data/test/unit/mail_notification_test.rb +53 -0
- data/test/unit/model_test.rb +10 -0
- data/test/unit/operating_system_test.rb +14 -1
- data/test/unit/settings_test.rb +4 -0
- data/test/unit/usergroup_test.rb +10 -0
- metadata +129 -107
- data/test/reports/TEST-Minitest-Result.xml +0 -4344
@@ -27,6 +27,26 @@ describe 'bookmark' do
|
|
27
27
|
result = run_cmd(@cmd)
|
28
28
|
assert_cmd(expected_result, result)
|
29
29
|
end
|
30
|
+
|
31
|
+
it 'should run list command with defaults' do
|
32
|
+
providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
|
33
|
+
defaults = HammerCLI::Defaults.new(
|
34
|
+
{
|
35
|
+
organization_id: {
|
36
|
+
provider: 'foreman'
|
37
|
+
},
|
38
|
+
location_id: {
|
39
|
+
provider: 'foreman'
|
40
|
+
}
|
41
|
+
}
|
42
|
+
)
|
43
|
+
defaults.stubs(:write_to_file).returns(true)
|
44
|
+
defaults.stubs(:providers).returns(providers)
|
45
|
+
api_expects(:bookmarks, :index, 'List bookmarks').returns(@bookmarks)
|
46
|
+
|
47
|
+
result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
|
48
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
49
|
+
end
|
30
50
|
end
|
31
51
|
|
32
52
|
describe 'info' do
|
@@ -138,7 +158,8 @@ describe 'bookmark' do
|
|
138
158
|
api_expects(:bookmarks, :update) do |par|
|
139
159
|
par['id'] == '1'
|
140
160
|
end
|
141
|
-
run_cmd(%w[bookmark update --id 1])
|
161
|
+
result = run_cmd(%w[bookmark update --id 1])
|
162
|
+
assert_cmd(success_result("Nothing to update.\n"), result)
|
142
163
|
end
|
143
164
|
|
144
165
|
it 'update bookmark' do
|
@@ -40,6 +40,17 @@ describe "parameters" do
|
|
40
40
|
result = run_cmd(@cmd + params)
|
41
41
|
assert_cmd(success_result("Compute profile updated.\n"), result)
|
42
42
|
end
|
43
|
+
|
44
|
+
it 'updates nothing without profile related parameters' do
|
45
|
+
params = %w[--id=1]
|
46
|
+
api_expects(:compute_profiles, :update, 'Update profile with no params').returns({})
|
47
|
+
|
48
|
+
expected_result = success_result("Nothing to update.\n")
|
49
|
+
|
50
|
+
result = run_cmd(@cmd + params)
|
51
|
+
assert_cmd(expected_result, result)
|
52
|
+
end
|
53
|
+
|
43
54
|
end
|
44
55
|
|
45
56
|
describe "delete compute profile" do
|
@@ -98,4 +109,47 @@ describe "parameters" do
|
|
98
109
|
end
|
99
110
|
end
|
100
111
|
|
112
|
+
describe 'list' do
|
113
|
+
before do
|
114
|
+
@cmd = %w[compute-profile list]
|
115
|
+
@compute_profiles = [{
|
116
|
+
id: 1,
|
117
|
+
name: '1-Small',
|
118
|
+
}]
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should return a list of compute profiles' do
|
122
|
+
api_expects(:compute_profiles, :index, 'List compute profiles').returns(@compute_profiles)
|
123
|
+
|
124
|
+
output = IndexMatcher.new([
|
125
|
+
%w[ID NAME],
|
126
|
+
%w[1 1-Small]
|
127
|
+
])
|
128
|
+
expected_result = success_result(output)
|
129
|
+
|
130
|
+
result = run_cmd(@cmd)
|
131
|
+
assert_cmd(expected_result, result)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should run list command with defaults' do
|
135
|
+
providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
|
136
|
+
defaults = HammerCLI::Defaults.new(
|
137
|
+
{
|
138
|
+
organization_id: {
|
139
|
+
provider: 'foreman'
|
140
|
+
},
|
141
|
+
location_id: {
|
142
|
+
provider: 'foreman'
|
143
|
+
}
|
144
|
+
}
|
145
|
+
)
|
146
|
+
defaults.stubs(:write_to_file).returns(true)
|
147
|
+
defaults.stubs(:providers).returns(providers)
|
148
|
+
api_expects(:compute_profiles, :index, 'List compute profiles').returns(@compute_profiles)
|
149
|
+
|
150
|
+
result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
|
151
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
101
155
|
end
|
@@ -51,6 +51,18 @@ describe 'compute-resource' do
|
|
51
51
|
assert_cmd(expected_result, result)
|
52
52
|
end
|
53
53
|
|
54
|
+
describe 'associate VMs to hosts' do
|
55
|
+
it 'successful associate vms to hosts' do
|
56
|
+
expected_result = success_result("Virtual machines have been associated.\n")
|
57
|
+
api_expects(:compute_resources, :associate, 'Associate VMs') do |p|
|
58
|
+
p['id'] == '1'
|
59
|
+
end
|
60
|
+
result = run_cmd(%w(compute-resource associate-vms --id 1))
|
61
|
+
assert_cmd(expected_result, result)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
54
66
|
it 'should print error for blank --provider option' do
|
55
67
|
params = %w(--provider= --name=new'')
|
56
68
|
expected_result = CommandExpectation.new
|
@@ -198,6 +210,31 @@ end
|
|
198
210
|
end
|
199
211
|
end
|
200
212
|
|
213
|
+
describe 'vnic profiles' do
|
214
|
+
let(:cmd) { base_cmd << 'vnic-profiles' }
|
215
|
+
let(:vnic_profile_1) { { id: 1, name: 'network1', network: 2 } }
|
216
|
+
let(:vnic_profile_2) { { id: 2, name: 'network2', network: 2 } }
|
217
|
+
let(:vnic_profiles) { [vnic_profile_1, vnic_profile_2] }
|
218
|
+
|
219
|
+
it 'lists available vnic profiles for a compute resource' do
|
220
|
+
api_expects(:compute_resources, :available_vnic_profiles, 'vnic-profiles').with_params(
|
221
|
+
'id' => '1'
|
222
|
+
).returns(index_response(vnic_profiles))
|
223
|
+
|
224
|
+
output = IndexMatcher.new(
|
225
|
+
[
|
226
|
+
['VNIC PROFILE ID', 'NAME', 'NETWORK ID'],
|
227
|
+
['1', 'network1','2'],
|
228
|
+
['2', 'network2','2']
|
229
|
+
]
|
230
|
+
)
|
231
|
+
expected_result = success_result(output)
|
232
|
+
|
233
|
+
result = run_cmd(cmd + base_params)
|
234
|
+
assert_cmd(expected_result, result)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
201
238
|
describe 'images' do
|
202
239
|
let(:cmd) { base_cmd << 'images' }
|
203
240
|
let(:image1) { { uuid: 1, name: 'image1' } }
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
4
|
+
|
5
|
+
describe 'config_group' do
|
6
|
+
describe 'list' do
|
7
|
+
before do
|
8
|
+
@cmd = %w[config-group list]
|
9
|
+
@config_groups = [{
|
10
|
+
id: 1,
|
11
|
+
name: 'config-group-test',
|
12
|
+
}]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return a list of config groups' do
|
16
|
+
api_expects(:config_groups, :index, 'List config groups').returns(@config_groups)
|
17
|
+
|
18
|
+
output = IndexMatcher.new([
|
19
|
+
%w[ID NAME],
|
20
|
+
%w[1 config-group-test]
|
21
|
+
])
|
22
|
+
expected_result = success_result(output)
|
23
|
+
|
24
|
+
result = run_cmd(@cmd)
|
25
|
+
assert_cmd(expected_result, result)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should run list command with defaults' do
|
29
|
+
providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
|
30
|
+
defaults = HammerCLI::Defaults.new(
|
31
|
+
{
|
32
|
+
organization_id: {
|
33
|
+
provider: 'foreman'
|
34
|
+
},
|
35
|
+
location_id: {
|
36
|
+
provider: 'foreman'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
)
|
40
|
+
defaults.stubs(:write_to_file).returns(true)
|
41
|
+
defaults.stubs(:providers).returns(providers)
|
42
|
+
api_expects(:config_groups, :index, 'List config groups').returns(@config_groups)
|
43
|
+
|
44
|
+
result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
|
45
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
@@ -1,18 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
4
|
|
3
5
|
describe 'filter' do
|
4
6
|
def api_expects_filter_info(options)
|
5
7
|
override = !!options[:override]
|
6
|
-
api_expects(:filters, :show, 'Get filter info').with_params(
|
7
|
-
:
|
8
|
-
|
8
|
+
api_expects(:filters, :show, 'Get filter info').with_params(
|
9
|
+
id: '1'
|
10
|
+
).returns(@filter.merge('override?' => override))
|
9
11
|
end
|
10
12
|
|
11
13
|
def taxonomy_usage_error(action, cmd)
|
12
14
|
usage_error_result(
|
13
15
|
cmd,
|
14
16
|
'Organizations and locations can be set only for overriding filters.',
|
15
|
-
"Could not #{action} the permission filter"
|
17
|
+
"Could not #{action} the permission filter"
|
18
|
+
)
|
16
19
|
end
|
17
20
|
|
18
21
|
def assert_update_success(result)
|
@@ -21,7 +24,7 @@ describe 'filter' do
|
|
21
24
|
|
22
25
|
describe 'create' do
|
23
26
|
before do
|
24
|
-
@cmd = %w
|
27
|
+
@cmd = %w[filter create]
|
25
28
|
end
|
26
29
|
|
27
30
|
it 'prints error when taxonomies are used for a not-overriding filter' do
|
@@ -32,41 +35,106 @@ describe 'filter' do
|
|
32
35
|
result = run_cmd(@cmd + params)
|
33
36
|
assert_cmd(taxonomy_usage_error('create', @cmd), result)
|
34
37
|
end
|
38
|
+
|
39
|
+
it 'should create a filter' do
|
40
|
+
params = ['--role-id=1', '--permission-ids=[1]']
|
41
|
+
|
42
|
+
api_expects(:filters, :create) do |params|
|
43
|
+
(params['filter']['role_id'] == 1)
|
44
|
+
(params['filter']['permission_ids'] == [1])
|
45
|
+
end
|
46
|
+
|
47
|
+
result = run_cmd(@cmd + params)
|
48
|
+
assert_cmd(success_result("Permission filter for [%<resource_type_label>s] created.\n"), result)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'list' do
|
53
|
+
before do
|
54
|
+
@cmd = %w[filter list]
|
55
|
+
@filters = [{
|
56
|
+
id: 1,
|
57
|
+
resource_type: 'Architecture',
|
58
|
+
search: 'none',
|
59
|
+
unlimited?: true,
|
60
|
+
override?: false,
|
61
|
+
role: { name: 'Manager', id: 2, description: 'Role granting all available permissions.', origin: 'foreman' },
|
62
|
+
permissions: 'view_architectures'
|
63
|
+
}]
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should return a list of filters' do
|
67
|
+
api_expects(:filters, :index, 'List filters').returns(@filters)
|
68
|
+
|
69
|
+
output = IndexMatcher.new([
|
70
|
+
['ID', 'RESOURCE TYPE', 'SEARCH', 'UNLIMITED?', 'OVERRIDE?', 'ROLE', 'PERMISSIONS'],
|
71
|
+
['1', 'Architecture', 'none', 'yes', 'no', 'Manager', 'view_architectures']
|
72
|
+
])
|
73
|
+
expected_result = success_result(output)
|
74
|
+
|
75
|
+
result = run_cmd(@cmd)
|
76
|
+
assert_cmd(expected_result, result)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'delete' do
|
81
|
+
before do
|
82
|
+
@cmd = %w(filter delete)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should print error missing argument id' do
|
86
|
+
expected_result = "Could not delete the permission filter:\n Missing arguments for '--id'.\n"
|
87
|
+
|
88
|
+
api_expects_no_call
|
89
|
+
|
90
|
+
result = run_cmd(@cmd)
|
91
|
+
assert_match(expected_result, result.err)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should delete a filter' do
|
95
|
+
params = ['--id=1']
|
96
|
+
|
97
|
+
api_expects(:filters, :destroy, 'Delete a filter').with_params(id: '1')
|
98
|
+
|
99
|
+
result = run_cmd(@cmd + params)
|
100
|
+
assert_cmd(success_result("Permission filter deleted.\n"), result)
|
101
|
+
end
|
35
102
|
end
|
36
103
|
|
37
104
|
describe 'update' do
|
38
105
|
before do
|
39
|
-
@cmd = %w
|
106
|
+
@cmd = %w[filter update]
|
40
107
|
@filter = {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
108
|
+
'search' => nil,
|
109
|
+
'resource_type_label' => 'User',
|
110
|
+
'resource_type' => 'User',
|
111
|
+
'unlimited?' => false,
|
112
|
+
'created_at' => '2017-07-18 14:34:09 UTC',
|
113
|
+
'updated_at' => '2017-07-18 14:34:09 UTC',
|
114
|
+
'override?' => true,
|
115
|
+
'id' => 404,
|
116
|
+
'role' => {
|
117
|
+
'name' => 'Some Role',
|
118
|
+
'id' => 28,
|
119
|
+
'description' => "Description\nof the new\nrole",
|
120
|
+
'origin' => nil
|
53
121
|
},
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
122
|
+
'permissions' => [{
|
123
|
+
'name' => 'view_users',
|
124
|
+
'id' => 164,
|
125
|
+
'resource_type' => 'User'
|
58
126
|
}],
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
127
|
+
'locations' => [{
|
128
|
+
'id' => 28,
|
129
|
+
'name' => 'location74',
|
130
|
+
'title' => 'location74',
|
131
|
+
'description' => nil
|
64
132
|
}],
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
133
|
+
'organizations' => [{
|
134
|
+
'id' => 27,
|
135
|
+
'name' => 'organization74',
|
136
|
+
'title' => 'organization74',
|
137
|
+
'description' => nil
|
70
138
|
}]
|
71
139
|
}
|
72
140
|
end
|
@@ -74,13 +142,13 @@ describe 'filter' do
|
|
74
142
|
it 'resets taxonomies when a filter is not-overriding' do
|
75
143
|
params = ['--id=1']
|
76
144
|
|
77
|
-
api_expects_filter_info(:
|
78
|
-
api_expects(:filters, :update, 'Update the filter').with_params(
|
145
|
+
api_expects_filter_info(override: false)
|
146
|
+
api_expects(:filters, :update, 'Update the filter').with_params(
|
79
147
|
'filter' => {
|
80
148
|
'organization_ids' => [],
|
81
149
|
'location_ids' => []
|
82
150
|
}
|
83
|
-
|
151
|
+
).returns(@filter)
|
84
152
|
|
85
153
|
assert_update_success(run_cmd(@cmd + params))
|
86
154
|
end
|
@@ -88,12 +156,12 @@ describe 'filter' do
|
|
88
156
|
it 'resets taxonomies when switching a filter to not-overriding' do
|
89
157
|
params = ['--id=1', '--override=false']
|
90
158
|
|
91
|
-
api_expects(:filters, :update, 'Update the filter').with_params(
|
159
|
+
api_expects(:filters, :update, 'Update the filter').with_params(
|
92
160
|
'filter' => {
|
93
161
|
'organization_ids' => [],
|
94
162
|
'location_ids' => []
|
95
163
|
}
|
96
|
-
|
164
|
+
).returns(@filter)
|
97
165
|
|
98
166
|
assert_update_success(run_cmd(@cmd + params))
|
99
167
|
end
|
@@ -101,13 +169,13 @@ describe 'filter' do
|
|
101
169
|
it 'can add taxonomies when a filter is overriding' do
|
102
170
|
params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4']
|
103
171
|
|
104
|
-
api_expects_filter_info(:
|
105
|
-
api_expects(:filters, :update, 'Update the filter').with_params(
|
172
|
+
api_expects_filter_info(override: true)
|
173
|
+
api_expects(:filters, :update, 'Update the filter').with_params(
|
106
174
|
'filter' => {
|
107
|
-
'organization_ids' => [
|
108
|
-
'location_ids' => [
|
175
|
+
'organization_ids' => %w[1 2],
|
176
|
+
'location_ids' => %w[3 4]
|
109
177
|
}
|
110
|
-
|
178
|
+
).returns(@filter)
|
111
179
|
|
112
180
|
assert_update_success(run_cmd(@cmd + params))
|
113
181
|
end
|
@@ -115,12 +183,12 @@ describe 'filter' do
|
|
115
183
|
it 'can add taxonomies when switching a filter to overriding' do
|
116
184
|
params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4', '--override=true']
|
117
185
|
|
118
|
-
api_expects(:filters, :update, 'Update the filter').with_params(
|
186
|
+
api_expects(:filters, :update, 'Update the filter').with_params(
|
119
187
|
'filter' => {
|
120
|
-
'organization_ids' => [
|
121
|
-
'location_ids' => [
|
188
|
+
'organization_ids' => %w[1 2],
|
189
|
+
'location_ids' => %w[3 4]
|
122
190
|
}
|
123
|
-
|
191
|
+
).returns(@filter)
|
124
192
|
|
125
193
|
assert_update_success(run_cmd(@cmd + params))
|
126
194
|
end
|
@@ -128,7 +196,7 @@ describe 'filter' do
|
|
128
196
|
it 'prints error when taxonomies are used on not-overriding' do
|
129
197
|
params = ['--id=1', '--organization-ids=1,2', '--location-ids=3,4']
|
130
198
|
|
131
|
-
api_expects_filter_info(:
|
199
|
+
api_expects_filter_info(override: false)
|
132
200
|
|
133
201
|
result = run_cmd(@cmd + params)
|
134
202
|
assert_cmd(taxonomy_usage_error('update', @cmd), result)
|
@@ -297,6 +297,54 @@ describe "host create" do
|
|
297
297
|
assert_cmd(expected_result, result)
|
298
298
|
end
|
299
299
|
|
300
|
+
it 'should create a host with an owner' do
|
301
|
+
params = ['--owner-id=1']
|
302
|
+
|
303
|
+
api_expects(:hosts, :create, 'Create a host with an owner').with_params(
|
304
|
+
'location_id' => 1, 'organization_id' => 1, 'host' => {
|
305
|
+
'owner_id' => '1', 'name' => 'test'
|
306
|
+
}
|
307
|
+
).returns(results: { 'owner_id' => '1', 'name' => 'test' })
|
308
|
+
|
309
|
+
expected_result = success_result("Host created.\n")
|
310
|
+
|
311
|
+
result = run_cmd(cmd + minimal_params_without_hostgroup + params)
|
312
|
+
|
313
|
+
assert_cmd(expected_result, result)
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should create a host and set owner-type' do
|
317
|
+
params = ['--owner=admin']
|
318
|
+
|
319
|
+
api_expects_search(:users, {login: 'admin'}).returns(index_response([{ 'id' => 1 }]))
|
320
|
+
|
321
|
+
api_expects(:hosts, :create, 'Create a host with an owner').with_params(
|
322
|
+
'location_id' => 1, 'organization_id' => 1, 'host' => {
|
323
|
+
'owner_id' => 1, 'name' => 'test'
|
324
|
+
}
|
325
|
+
).returns(results: { 'owner' => 'admin', 'name' => 'test' })
|
326
|
+
|
327
|
+
expected_result = success_result("Host created.\n")
|
328
|
+
|
329
|
+
result = run_cmd(cmd + minimal_params_without_hostgroup + params)
|
330
|
+
|
331
|
+
assert_cmd(expected_result, result)
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'should create a host with default owner-type User' do
|
335
|
+
|
336
|
+
api_expects(:hosts, :create, 'Create a host with an owner').with_params(
|
337
|
+
'location_id' => 1, 'organization_id' => 1, 'host' => {
|
338
|
+
'name' => 'test'
|
339
|
+
}
|
340
|
+
).returns(results: { 'owner_type' => 'User', 'name' => 'test' })
|
341
|
+
|
342
|
+
expected_result = success_result("Host created.\n")
|
343
|
+
|
344
|
+
result = run_cmd(cmd + minimal_params_without_hostgroup)
|
345
|
+
|
346
|
+
assert_cmd(expected_result, result)
|
347
|
+
end
|
300
348
|
end
|
301
349
|
|
302
350
|
describe 'host update' do
|
@@ -356,7 +404,7 @@ describe 'host update' do
|
|
356
404
|
it 'updates nothing without host related parameters' do
|
357
405
|
api_expects(:hosts, :update, 'Update host with no host params').returns({})
|
358
406
|
|
359
|
-
expected_result = success_result("
|
407
|
+
expected_result = success_result("Nothing to update.\n")
|
360
408
|
|
361
409
|
result = run_cmd(cmd + minimal_params)
|
362
410
|
assert_cmd(expected_result, result)
|
@@ -410,7 +458,25 @@ describe 'host update' do
|
|
410
458
|
)
|
411
459
|
api_expects(:hosts, :update, 'Update host with new owner').with_params(
|
412
460
|
'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
|
413
|
-
|
461
|
+
'owner_id' => '1' }
|
462
|
+
) do |par|
|
463
|
+
par['id'] == '1' && par['host']['owner_id'] == '1'
|
464
|
+
end.returns(updated_host)
|
465
|
+
|
466
|
+
expected_result = success_result("Host updated.\n")
|
467
|
+
|
468
|
+
result = run_cmd(cmd + minimal_params + params)
|
469
|
+
|
470
|
+
assert_cmd(expected_result, result)
|
471
|
+
end
|
472
|
+
|
473
|
+
it 'should update the host owner with id' do
|
474
|
+
params = ['--owner-id=1']
|
475
|
+
|
476
|
+
api_expects(:hosts, :update, 'Update host with new owner').with_params(
|
477
|
+
'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
|
478
|
+
'owner_id' => '1'
|
479
|
+
}
|
414
480
|
) do |par|
|
415
481
|
par['id'] == '1' && par['host']['owner_id'] == '1'
|
416
482
|
end.returns(updated_host)
|
@@ -426,7 +492,7 @@ end
|
|
426
492
|
describe 'host config reports' do
|
427
493
|
let(:report15) do
|
428
494
|
{
|
429
|
-
|
495
|
+
"id" => 15,
|
430
496
|
"host_id" => 1,
|
431
497
|
"host_name" => "host.example.com",
|
432
498
|
"reported_at" => "2017-11-13 03:04:53 UTC",
|
@@ -502,3 +568,33 @@ describe 'disassociate host from vm' do
|
|
502
568
|
assert_cmd(expected_result, result)
|
503
569
|
end
|
504
570
|
end
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
describe 'list' do
|
575
|
+
before do
|
576
|
+
@cmd = %w[host list]
|
577
|
+
end
|
578
|
+
|
579
|
+
it 'should run list command with defaults' do
|
580
|
+
providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
|
581
|
+
defaults = HammerCLI::Defaults.new(
|
582
|
+
{
|
583
|
+
organization_id: {
|
584
|
+
provider: 'foreman'
|
585
|
+
},
|
586
|
+
location_id: {
|
587
|
+
provider: 'foreman'
|
588
|
+
}
|
589
|
+
}
|
590
|
+
)
|
591
|
+
defaults.stubs(:write_to_file).returns(true)
|
592
|
+
defaults.stubs(:providers).returns(providers)
|
593
|
+
api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
|
594
|
+
api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
|
595
|
+
api_expects(:hosts, :index, 'List hosts').returns(index_response([{ 'id' => '42' }]))
|
596
|
+
|
597
|
+
result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
|
598
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
599
|
+
end
|
600
|
+
end
|