hammer_cli_foreman 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +18 -0
  3. data/lib/hammer_cli_foreman.rb +0 -4
  4. data/lib/hammer_cli_foreman/associating_commands.rb +2 -2
  5. data/lib/hammer_cli_foreman/auth.rb +4 -4
  6. data/lib/hammer_cli_foreman/command_extensions/ping.rb +10 -1
  7. data/lib/hammer_cli_foreman/commands.rb +3 -1
  8. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +1 -0
  9. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +16 -9
  10. data/lib/hammer_cli_foreman/location.rb +2 -0
  11. data/lib/hammer_cli_foreman/organization.rb +2 -0
  12. data/lib/hammer_cli_foreman/ping.rb +20 -11
  13. data/lib/hammer_cli_foreman/references.rb +16 -0
  14. data/lib/hammer_cli_foreman/settings.rb +14 -0
  15. data/lib/hammer_cli_foreman/version.rb +1 -1
  16. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  17. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  18. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  19. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  20. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  21. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  22. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  23. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  24. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  25. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  26. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  27. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  28. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  29. data/test/functional/audit_test.rb +86 -63
  30. data/test/functional/compute_profile_test.rb +4 -2
  31. data/test/functional/host_test.rb +26 -15
  32. data/test/functional/location_test.rb +134 -0
  33. data/test/functional/media_test.rb +130 -0
  34. data/test/functional/organization_test.rb +52 -0
  35. data/test/functional/realm_test.rb +1 -2
  36. data/test/functional/role_test.rb +9 -12
  37. data/test/functional/settings_test.rb +57 -1
  38. data/test/functional/user_test.rb +39 -0
  39. data/test/unit/media_test.rb +1 -1
  40. data/test/unit/partition_table_test.rb +2 -2
  41. data/test/unit/role_test.rb +2 -2
  42. metadata +6 -7
  43. data/lib/hammer_cli_foreman/trend.rb +0 -47
  44. data/test/functional/trend_test.rb +0 -83
@@ -33,8 +33,10 @@ describe "parameters" do
33
33
  }
34
34
  end
35
35
  it 'update compute profile name' do
36
- params = ['--id=1' ,'--new-name=profile2']
37
- api_expects(:compute_profiles, :update, 'Update the compute profile').with_params({"name" =>"profile2"}).returns(@compute_profile)
36
+ params = ['--id=1', '--new-name=profile2']
37
+ api_expects(:compute_profiles, :update, 'Update the compute profile').with_params(
38
+ { 'compute_profile' => { 'name' => 'profile2' } }
39
+ ).returns(@compute_profile)
38
40
  result = run_cmd(@cmd + params)
39
41
  assert_cmd(success_result("Compute profile updated.\n"), result)
40
42
  end
@@ -315,6 +315,26 @@ describe 'host update' do
315
315
  }
316
316
  end
317
317
 
318
+ it 'updates with passed options only' do
319
+ params = ['--new-name=new-name']
320
+ expected_result = success_result("Host updated.\n")
321
+
322
+ api_expects(:hosts, :update, 'Update host name only').with_params(
323
+ 'id' => '1', 'organization_id' => 1, 'location_id' => 1,
324
+ 'host' => { 'name' => 'new-name' }
325
+ ).returns(
326
+ {
327
+ 'id' => '1',
328
+ 'name' => 'new-name',
329
+ 'organization_id' => '1',
330
+ 'location_id' => '1'
331
+ }
332
+ )
333
+
334
+ result = run_cmd(cmd + minimal_params + params)
335
+ assert_cmd(expected_result, result)
336
+ end
337
+
318
338
  it 'ensures helper methods are invoked' do
319
339
  params = ['--image-id=1']
320
340
  expected_result = success_result("Host updated.\n")
@@ -350,12 +370,9 @@ describe 'host update' do
350
370
  )
351
371
  api_expects(:hosts, :update, 'Update host with new org').with_params(
352
372
  'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
353
- 'organization_id' => '5', 'compute_attributes' => {}
354
- }
373
+ 'organization_id' => '5' }
355
374
  ) do |par|
356
- par['id'] == '1' &&
357
- par['host']['organization_id'] == '5' &&
358
- par['host']['compute_attributes'] == {}
375
+ par['id'] == '1' && par['host']['organization_id'] == '5'
359
376
  end.returns(updated_host)
360
377
 
361
378
  expected_result = success_result("Host updated.\n")
@@ -373,12 +390,9 @@ describe 'host update' do
373
390
  )
374
391
  api_expects(:hosts, :update, 'Update host with new loc').with_params(
375
392
  'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
376
- 'location_id' => '5', 'compute_attributes' => {}
377
- }
393
+ 'location_id' => '5' }
378
394
  ) do |par|
379
- par['id'] == '1' &&
380
- par['host']['location_id'] == '5' &&
381
- par['host']['compute_attributes'] == {}
395
+ par['id'] == '1' && par['host']['location_id'] == '5'
382
396
  end.returns(updated_host)
383
397
 
384
398
  expected_result = success_result("Host updated.\n")
@@ -396,12 +410,9 @@ describe 'host update' do
396
410
  )
397
411
  api_expects(:hosts, :update, 'Update host with new owner').with_params(
398
412
  'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
399
- 'owner_id' => '1', 'compute_attributes' => {}
400
- }
413
+ 'owner_id' => '1' }
401
414
  ) do |par|
402
- par['id'] == '1' &&
403
- par['host']['owner_id'] == '1' &&
404
- par['host']['compute_attributes'] == {}
415
+ par['id'] == '1' && par['host']['owner_id'] == '1'
405
416
  end.returns(updated_host)
406
417
 
407
418
  expected_result = success_result("Host updated.\n")
@@ -139,3 +139,137 @@ describe "parameters" do
139
139
  end
140
140
  end
141
141
  end
142
+
143
+ describe 'create' do
144
+ before do
145
+ @cmd = %w(location create)
146
+ end
147
+
148
+ it 'should print error missing argument name' do
149
+ expected_result = "Could not create the location:\n Missing arguments for '--name'.\n"
150
+
151
+ api_expects(:locations, :index)
152
+
153
+ result = run_cmd(@cmd)
154
+ assert_match(expected_result, result.err)
155
+ end
156
+
157
+ it 'should create a location' do
158
+ params = ['--name=test-location']
159
+
160
+ api_expects(:locations, :index)
161
+ api_expects(:locations, :create, 'Create a locations') do |params|
162
+ (params['location']['name'] == 'test-location')
163
+ end
164
+
165
+ result = run_cmd(@cmd + params)
166
+ assert_cmd(success_result("Location created.\n"), result)
167
+ end
168
+ end
169
+
170
+ describe 'delete' do
171
+ before do
172
+ @cmd = %w(location delete)
173
+ end
174
+
175
+ it 'should print error missing argument id' do
176
+ expected_result = "Could not delete the location:\n Missing arguments for '--id'.\n"
177
+
178
+ api_expects(:locations, :index)
179
+
180
+ result = run_cmd(@cmd)
181
+ assert_match(expected_result, result.err)
182
+ end
183
+
184
+ it 'should delete a location' do
185
+ params = ['--id=1']
186
+
187
+ api_expects(:locations, :index)
188
+ api_expects(:locations, :destroy, 'Delete a location').with_params(id: '1')
189
+
190
+ result = run_cmd(@cmd + params)
191
+ assert_cmd(success_result("Location deleted.\n"), result)
192
+ end
193
+ end
194
+
195
+ describe 'info' do
196
+ before do
197
+ @cmd = ['location', 'info']
198
+ @location = {
199
+ id: 1,
200
+ title: 'Default Location',
201
+ name: 'Default Location',
202
+ users: [],
203
+ smart_proxies: [],
204
+ subnets: [],
205
+ compute_resources: [],
206
+ media: [],
207
+ ptables: [],
208
+ provisioning_templates: [],
209
+ domains: [],
210
+ realms: [],
211
+ environments: [],
212
+ hostgroups: [],
213
+ organizations: [],
214
+ parameters: []
215
+ }
216
+ end
217
+
218
+ it 'should return the info of a location' do
219
+ params = ['--id', 1]
220
+ api_expects(:locations, :index)
221
+ api_expects(:locations, :show, 'Info location').returns(@location)
222
+
223
+ output = OutputMatcher.new([
224
+ 'Id: 1',
225
+ 'Title: Default Location',
226
+ 'Name: Default Location',
227
+ 'Users:',
228
+ '',
229
+ 'Smart proxies:',
230
+ '',
231
+ 'Subnets:',
232
+ '',
233
+ 'Compute resources:',
234
+ '',
235
+ 'Installation media:',
236
+ '',
237
+ 'Templates:',
238
+ '',
239
+ 'Partition Tables:',
240
+ '',
241
+ 'Domains:',
242
+ '',
243
+ 'Realms:',
244
+ '',
245
+ 'Environments:',
246
+ '',
247
+ 'Hostgroups:',
248
+ '',
249
+ 'Parameters:',
250
+ ])
251
+
252
+ expected_result = success_result(output)
253
+ result = run_cmd(@cmd + params)
254
+ assert_cmd(expected_result, result)
255
+ end
256
+ end
257
+
258
+ describe 'update' do
259
+ before do
260
+ @cmd = ['location', 'update']
261
+ end
262
+
263
+ it 'should update a location' do
264
+ params = ['--id=1', '--new-name=Default Location test']
265
+
266
+ api_expects(:locations, :index)
267
+ api_expects(:locations, :update, 'Update a location') do |params|
268
+ (params['location']['id'] == '1')
269
+ (params['location']['name'] == 'Default Location test')
270
+ end
271
+
272
+ result = run_cmd(@cmd + params)
273
+ assert_cmd(success_result("Location updated.\n"), result)
274
+ end
275
+ end
@@ -0,0 +1,130 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe 'medium' do
4
+ describe 'list' do
5
+ before do
6
+ @cmd = %w[medium list]
7
+ @media = [{
8
+ id: 1,
9
+ name: 'CentOS mirror',
10
+ path: 'http://mirror.centos.org/centos/$major/os/$arch',
11
+ os_family: 'Redhat',
12
+ operating_systems: [],
13
+ locations: [],
14
+ organizations: []
15
+ }]
16
+ end
17
+
18
+ it 'should return a list of media' do
19
+ api_expects(:media, :index, 'List media').returns(@media)
20
+
21
+ output = IndexMatcher.new([
22
+ ['ID', 'NAME', 'PATH'],
23
+ ['1', 'CentOS mirror', 'http://mirror.centos.org/centos/$major/os/$arch']
24
+ ])
25
+ expected_result = success_result(output)
26
+
27
+ result = run_cmd(@cmd)
28
+ assert_cmd(expected_result, result)
29
+ end
30
+ end
31
+
32
+ describe 'info' do
33
+ before do
34
+ @cmd = ['medium', 'info']
35
+ @medium = {
36
+ id: 1,
37
+ name: 'CentOS mirror',
38
+ path: 'http://mirror.centos.org/centos/$major/os/$arch',
39
+ os_family: 'Redhat',
40
+ operating_systems: [],
41
+ locations: [],
42
+ organizations: []
43
+ }
44
+ end
45
+
46
+ it 'should return the info of a medium' do
47
+ params = ['--id', 1]
48
+ api_expects(:media, :show, 'Info medium').returns(@medium)
49
+
50
+ output = OutputMatcher.new([
51
+ 'Id: 1',
52
+ 'Name: CentOS mirror',
53
+ 'Path: http://mirror.centos.org/centos/$major/os/$arch',
54
+ 'OS Family: Redhat'
55
+ ])
56
+
57
+ expected_result = success_result(output)
58
+ result = run_cmd(@cmd + params)
59
+ assert_cmd(expected_result, result)
60
+ end
61
+ end
62
+
63
+ describe 'create' do
64
+ before do
65
+ @cmd = %w(medium create)
66
+ end
67
+
68
+ it 'should print error missing argument name and path' do
69
+ expected_result = "Could not create the installation medium:\n Missing arguments for '--name', '--path'.\n"
70
+
71
+
72
+ result = run_cmd(@cmd)
73
+ assert_match(expected_result, result.err)
74
+ end
75
+
76
+ it 'should create a media' do
77
+ params = ['--name=CentOS mirror', '--path=http://mirror.centos.org/centos/$major/os/$arch']
78
+
79
+ api_expects(:media, :create) do |params|
80
+ (params['medium']['name'] == 'CentOS mirror')
81
+ (params['medium']['path'] == 'http://mirror.centos.org/centos/$major/os/$arch')
82
+ end
83
+
84
+ result = run_cmd(@cmd + params)
85
+ assert_cmd(success_result("Installation medium created.\n"), result)
86
+ end
87
+ end
88
+
89
+ describe 'delete' do
90
+ before do
91
+ @cmd = %w(medium delete)
92
+ end
93
+
94
+ it 'should print error missing argument id' do
95
+ expected_result = "Could not delete the installation media:\n Missing arguments for '--id'.\n"
96
+
97
+ api_expects_no_call
98
+
99
+ result = run_cmd(@cmd)
100
+ assert_match(expected_result, result.err)
101
+ end
102
+
103
+ it 'should delete a media' do
104
+ params = ['--id=1']
105
+
106
+ api_expects(:media, :destroy, 'Delete a media').with_params(id: '1')
107
+
108
+ result = run_cmd(@cmd + params)
109
+ assert_cmd(success_result("Installation medium deleted.\n"), result)
110
+ end
111
+ end
112
+
113
+ describe 'update' do
114
+ before do
115
+ @cmd = ['medium', 'update']
116
+ end
117
+
118
+ it 'should update a media' do
119
+ params = ['--id=1', '--new-name=CentOS mirror test']
120
+
121
+ api_expects(:media, :update, 'Update a media') do |params|
122
+ (params['medium']['id'] == '1')
123
+ (params['medium']['name'] == 'CentOS mirror test')
124
+ end
125
+
126
+ result = run_cmd(@cmd + params)
127
+ assert_cmd(success_result("Installation medium updated.\n"), result)
128
+ end
129
+ end
130
+ end
@@ -210,3 +210,55 @@ describe 'associating commands' do
210
210
  end
211
211
  end
212
212
  end
213
+
214
+ describe 'create' do
215
+ before do
216
+ @cmd = %w(organization create)
217
+ end
218
+
219
+ it 'should print error missing argument name' do
220
+ expected_result = "Could not create the organization:\n Missing arguments for '--name'.\n"
221
+
222
+ api_expects(:organizations, :index)
223
+
224
+ result = run_cmd(@cmd)
225
+ assert_match(expected_result, result.err)
226
+ end
227
+
228
+ it 'should create an organization' do
229
+ params = ['--name=test-organization']
230
+
231
+ api_expects(:organizations, :index)
232
+ api_expects(:organizations, :create, 'Create an organization') do |params|
233
+ (params['organization']['name'] == 'test-organization')
234
+ end
235
+
236
+ result = run_cmd(@cmd + params)
237
+ assert_cmd(success_result("Organization created.\n"), result)
238
+ end
239
+ end
240
+
241
+ describe 'delete' do
242
+ before do
243
+ @cmd = %w(organization delete)
244
+ end
245
+
246
+ it 'should print error missing argument id' do
247
+ expected_result = "Could not delete the organization:\n Missing arguments for '--id'.\n"
248
+
249
+ api_expects(:organizations, :index)
250
+
251
+ result = run_cmd(@cmd)
252
+ assert_match(expected_result, result.err)
253
+ end
254
+
255
+ it 'should delete an organization' do
256
+ params = ['--id=1']
257
+
258
+ api_expects(:organizations, :index)
259
+ api_expects(:organizations, :destroy, 'Delete an organization').with_params(id: '1')
260
+
261
+ result = run_cmd(@cmd + params)
262
+ assert_cmd(success_result("Organization deleted.\n"), result)
263
+ end
264
+ end
@@ -93,7 +93,7 @@ describe 'realm' do
93
93
 
94
94
  api_expects(:realms, :update, 'Update a realm') do |params|
95
95
  (params['id'] == '1' &&
96
- params['name'] == 'test-realm-update')
96
+ params['realm']['name'] == 'test-realm-update')
97
97
  end
98
98
 
99
99
  result = run_cmd(@cmd + params)
@@ -101,4 +101,3 @@ describe 'realm' do
101
101
  end
102
102
  end
103
103
  end
104
-
@@ -40,9 +40,9 @@ describe 'role' do
40
40
  it 'should clone a role by id' do
41
41
  params = ['--id=1', '--new-name=zzz']
42
42
 
43
- api_expects(:roles, :clone, 'Clone role').with_params({
44
- 'id' => '1', 'role' => {'name' => 'zzz'}, 'name' => 'zzz'
45
- })
43
+ api_expects(:roles, :clone, 'Clone role').with_params(
44
+ { 'id' => '1', 'role' => { 'name' => 'zzz' } }
45
+ )
46
46
 
47
47
  result = run_cmd(@cmd + params)
48
48
  assert_cmd(success_result("User role cloned.\n"), result)
@@ -51,16 +51,13 @@ describe 'role' do
51
51
  it 'should clone a role by name' do
52
52
  params = ['--name=old', '--new-name=zzz']
53
53
 
54
- api_expects_search(:roles, { :name => 'old' }, 'Attempt find role').returns(
55
- index_response(
56
- [{
57
- 'name' => 'old',
58
- 'id' => 1
59
- }]))
54
+ api_expects_search(:roles, { name: 'old' }, 'Attempt find role').returns(
55
+ index_response([{ 'name' => 'old', 'id' => 1 }])
56
+ )
60
57
 
61
- api_expects(:roles, :clone, 'Clone role').with_params({
62
- 'id' => 1, 'role' => {'name' => 'zzz'}, 'name' => 'zzz'
63
- })
58
+ api_expects(:roles, :clone, 'Clone role').with_params(
59
+ { 'id' => 1, 'role' => { 'name' => 'zzz' } }
60
+ )
64
61
 
65
62
  result = run_cmd(@cmd + params)
66
63
  assert_cmd(success_result("User role cloned.\n"), result)