hammer_cli_foreman 2.4.0 → 3.1.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 (117) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +40 -0
  3. data/lib/hammer_cli_foreman/architecture.rb +5 -5
  4. data/lib/hammer_cli_foreman/associating_commands.rb +0 -24
  5. data/lib/hammer_cli_foreman/bookmark.rb +5 -5
  6. data/lib/hammer_cli_foreman/combination.rb +3 -13
  7. data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
  8. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -10
  9. data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
  10. data/lib/hammer_cli_foreman/command_extensions/user.rb +9 -5
  11. data/lib/hammer_cli_foreman/command_extensions.rb +1 -2
  12. data/lib/hammer_cli_foreman/commands.rb +17 -11
  13. data/lib/hammer_cli_foreman/compute_attribute.rb +1 -1
  14. data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
  15. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
  16. data/lib/hammer_cli_foreman/compute_resource.rb +23 -0
  17. data/lib/hammer_cli_foreman/config_report.rb +2 -0
  18. data/lib/hammer_cli_foreman/filter.rb +2 -2
  19. data/lib/hammer_cli_foreman/host.rb +1 -47
  20. data/lib/hammer_cli_foreman/hostgroup.rb +14 -58
  21. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +10 -31
  22. data/lib/hammer_cli_foreman/id_resolver.rb +7 -68
  23. data/lib/hammer_cli_foreman/location.rb +0 -6
  24. data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
  25. data/lib/hammer_cli_foreman/model.rb +5 -5
  26. data/lib/hammer_cli_foreman/operating_system.rb +10 -10
  27. data/lib/hammer_cli_foreman/option_builders.rb +84 -52
  28. data/lib/hammer_cli_foreman/option_sources/id_params.rb +41 -11
  29. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +39 -7
  30. data/lib/hammer_cli_foreman/option_sources.rb +0 -1
  31. data/lib/hammer_cli_foreman/organization.rb +0 -6
  32. data/lib/hammer_cli_foreman/ping.rb +6 -1
  33. data/lib/hammer_cli_foreman/references.rb +0 -16
  34. data/lib/hammer_cli_foreman/registration.rb +18 -0
  35. data/lib/hammer_cli_foreman/settings.rb +3 -3
  36. data/lib/hammer_cli_foreman/smart_proxy.rb +7 -57
  37. data/lib/hammer_cli_foreman/template.rb +3 -15
  38. data/lib/hammer_cli_foreman/user.rb +4 -4
  39. data/lib/hammer_cli_foreman/usergroup.rb +5 -5
  40. data/lib/hammer_cli_foreman/version.rb +1 -1
  41. data/lib/hammer_cli_foreman.rb +3 -21
  42. data/lib/minitest/coverage_reporter.rb +1 -1
  43. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  47. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  49. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  50. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  51. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  52. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  53. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  54. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  55. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  56. data/test/data/2.4/foreman_api.json +1 -0
  57. data/test/data/2.5/foreman_api.json +1 -0
  58. data/test/data/3.1/foreman_api.json +1 -0
  59. data/test/functional/architecture_test.rb +37 -5
  60. data/test/functional/bookmark_test.rb +5 -2
  61. data/test/functional/compute_attribute_test.rb +20 -20
  62. data/test/functional/compute_profile_test.rb +14 -1
  63. data/test/functional/compute_resource_test.rb +37 -0
  64. data/test/functional/filter_test.rb +2 -1
  65. data/test/functional/host_test.rb +65 -11
  66. data/test/functional/hostgroup/create_test.rb +11 -117
  67. data/test/functional/hostgroup/update_test.rb +11 -79
  68. data/test/functional/http_proxy_test.rb +12 -0
  69. data/test/functional/location_test.rb +13 -3
  70. data/test/functional/mail_notification_test.rb +3 -1
  71. data/test/functional/media_test.rb +11 -0
  72. data/test/functional/model_test.rb +3 -1
  73. data/test/functional/operating_system_test.rb +3 -1
  74. data/test/functional/personal_access_token_test.rb +4 -4
  75. data/test/functional/ping_test.rb +33 -0
  76. data/test/functional/realm_test.rb +11 -0
  77. data/test/functional/registration_test.rb +8 -0
  78. data/test/functional/report_template_test.rb +11 -0
  79. data/test/functional/settings_test.rb +4 -4
  80. data/test/functional/template_test.rb +87 -48
  81. data/test/functional/user_mail_notification_test.rb +3 -3
  82. data/test/functional/user_test.rb +11 -0
  83. data/test/functional/usergroup_test.rb +3 -1
  84. data/test/test_helper.rb +1 -1
  85. data/test/unit/apipie_resource_mock.rb +1 -39
  86. data/test/unit/architecture_test.rb +10 -10
  87. data/test/unit/bookmark_test.rb +10 -14
  88. data/test/unit/commands_test.rb +1 -2
  89. data/test/unit/compute_profile_test.rb +10 -10
  90. data/test/unit/config_report_test.rb +1 -0
  91. data/test/unit/helpers/command.rb +0 -8
  92. data/test/unit/host_test.rb +14 -61
  93. data/test/unit/hostgroup_test.rb +7 -26
  94. data/test/unit/id_resolver_test.rb +0 -28
  95. data/test/unit/mail_notification_test.rb +4 -4
  96. data/test/unit/model_test.rb +47 -47
  97. data/test/unit/operating_system_test.rb +10 -16
  98. data/test/unit/option_builders_test.rb +88 -83
  99. data/test/unit/settings_test.rb +4 -4
  100. data/test/unit/smart_proxy_test.rb +0 -12
  101. data/test/unit/usergroup_test.rb +10 -10
  102. metadata +115 -128
  103. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +0 -29
  104. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +0 -29
  105. data/lib/hammer_cli_foreman/config_group.rb +0 -45
  106. data/lib/hammer_cli_foreman/option_sources/puppet_environment_params.rb +0 -59
  107. data/lib/hammer_cli_foreman/puppet_class.rb +0 -61
  108. data/lib/hammer_cli_foreman/puppet_environment.rb +0 -65
  109. data/lib/hammer_cli_foreman/smart_class_parameter.rb +0 -189
  110. data/test/functional/config_group_test.rb +0 -50
  111. data/test/functional/proxy_test.rb +0 -86
  112. data/test/functional/smart_class_parameter_test.rb +0 -97
  113. data/test/reports/TEST-Minitest-Result.xml +0 -4344
  114. data/test/unit/config_group_test.rb +0 -82
  115. data/test/unit/puppet_class_test.rb +0 -72
  116. data/test/unit/puppet_environment_test.rb +0 -114
  117. data/test/unit/smart_class_parameter_test.rb +0 -113
@@ -68,25 +68,6 @@ module HammerCLIForeman
68
68
  run_cmd(%w(hostgroup update --id 1 --domain d1))
69
69
  end
70
70
 
71
- it 'allows environment id' do
72
- api_expects(:hostgroups, :update) do |p|
73
- p['hostgroup']['environment_id'] == 1 &&
74
- p['id'] == '1'
75
- end
76
- run_cmd(%w(hostgroup update --id 1 --environment-id 1))
77
- end
78
-
79
- it 'allows environment name' do
80
- api_expects(:environments, :index) do |p|
81
- p[:search] = "name = \"env1\""
82
- end.returns(index_response([{'id' => 1}]))
83
- api_expects(:hostgroups, :update) do |p|
84
- p['hostgroup']['environment_id'] == 1 &&
85
- p['id'] == '1'
86
- end
87
- run_cmd(%w(hostgroup update --id 1 --environment env1))
88
- end
89
-
90
71
  it 'allows location ids' do
91
72
  api_expects(:hostgroups, :update) do |p|
92
73
  p['hostgroup']['location_ids'] == ['1','4'] &&
@@ -182,6 +163,17 @@ module HammerCLIForeman
182
163
  run_cmd(%w(hostgroup update --id 1 --parent parent_hg))
183
164
  end
184
165
 
166
+ it 'allows parent hostgroup title' do
167
+ api_expects(:hostgroups, :index) do |p|
168
+ p[:search] = 'title = "parent_hg"'
169
+ end.returns(index_response([{ 'id' => 1 }]))
170
+ api_expects(:hostgroups, :update) do |p|
171
+ p['hostgroup']['parent_id'] == 1 &&
172
+ p['id'] == '1'
173
+ end
174
+ run_cmd(%w[hostgroup update --id 1 --parent parent_hg])
175
+ end
176
+
185
177
  it 'allows partition table id' do
186
178
  api_expects(:hostgroups, :update) do |p|
187
179
  p['hostgroup']['ptable_id'] == 1 &&
@@ -201,66 +193,6 @@ module HammerCLIForeman
201
193
  run_cmd(%w(hostgroup update --id 1 --partition-table pt1))
202
194
  end
203
195
 
204
- it 'allows puppet ca proxy id' do
205
- api_expects(:hostgroups, :update).with_params({
206
- :id => '1',
207
- :hostgroup => { :puppet_ca_proxy_id => 1 }
208
- })
209
- run_cmd(%w(hostgroup update --id 1 --puppet-ca-proxy-id 1))
210
- end
211
-
212
- it 'allows puppet ca proxy name' do
213
- api_expects(:smart_proxies, :index) do |p|
214
- p[:search] = "name = \"sp1\""
215
- end.returns(index_response([{'id' => 1}]))
216
- api_expects(:hostgroups, :update) do |p|
217
- p['hostgroup']['puppet_ca_proxy_id'] == 1 &&
218
- p['id'] == '1'
219
- end
220
- run_cmd(%w(hostgroup update --id 1 --puppet-ca-proxy sp1))
221
- end
222
-
223
- it 'allows puppet class ids' do
224
- api_expects(:hostgroups, :update) do |p|
225
- p['hostgroup']['puppetclass_ids'] == ['1','2'] &&
226
- p['id'] == '1'
227
- end
228
- run_cmd(%w(hostgroup update --id 1 --puppet-class-ids 1,2))
229
- end
230
-
231
- it 'allows puppet class names' do
232
- api_expects(:puppetclasses, :index) do |p|
233
- p[:search] = "name = \"pc1\" or name = \"pc2\""
234
- end.returns(index_response('puppetclasses' => [
235
- {'id' => 1, 'name' => 'pc1'},
236
- {'id' => 2, 'name' => 'pc2'}
237
- ]))
238
- api_expects(:hostgroups, :update) do |p|
239
- p['hostgroup']['puppetclass_ids'] == [1,2] &&
240
- p['id'] == '1'
241
- end
242
- run_cmd(%w(hostgroup update --id 1 --puppet-classes pc1,pc2))
243
- end
244
-
245
- it 'allows puppet proxy id' do
246
- api_expects(:hostgroups, :update).with_params({
247
- :id => '1',
248
- :hostgroup => { :puppet_proxy_id => 1 }
249
- })
250
- run_cmd(%w(hostgroup update --id 1 --puppet-proxy-id 1))
251
- end
252
-
253
- it 'allows puppet proxy name' do
254
- api_expects(:smart_proxies, :index) do |p|
255
- p[:search] = "name = \"sp1\""
256
- end.returns(index_response([{'id' => 1}]))
257
- api_expects(:hostgroups, :update) do |p|
258
- p['hostgroup']['puppet_proxy_id'] == 1 &&
259
- p['id'] == '1'
260
- end
261
- run_cmd(%w(hostgroup update --id 1 --puppet-proxy sp1))
262
- end
263
-
264
196
  it 'allows realm id' do
265
197
  api_expects(:hostgroups, :update) do |p|
266
198
  p['hostgroup']['realm_id'] == 1 &&
@@ -61,9 +61,21 @@ describe 'httpproxy' do
61
61
  end
62
62
 
63
63
  it 'deletes an http proxy' do
64
+ api_expects(:http_proxies, :destroy, 'Delete proxy').returns(http_proxy)
65
+
64
66
  expected_result = success_result("Http proxy deleted.\n")
65
67
 
66
68
  result = run_cmd(%w(http-proxy delete --id 1))
67
69
  assert_cmd(expected_result, result)
68
70
  end
71
+
72
+ it 'updates nothing without related parameters' do
73
+ api_expects(:http_proxies, :update, 'Update proxy with no params').returns({})
74
+
75
+ expected_result = success_result("Nothing to update.\n")
76
+
77
+ result = run_cmd(%w(http-proxy update --id 1))
78
+ assert_cmd(expected_result, result)
79
+ end
80
+
69
81
  end
@@ -208,7 +208,6 @@ describe 'info' do
208
208
  provisioning_templates: [],
209
209
  domains: [],
210
210
  realms: [],
211
- environments: [],
212
211
  hostgroups: [],
213
212
  organizations: [],
214
213
  parameters: []
@@ -242,8 +241,6 @@ describe 'info' do
242
241
  '',
243
242
  'Realms:',
244
243
  '',
245
- 'Environments:',
246
- '',
247
244
  'Hostgroups:',
248
245
  '',
249
246
  'Parameters:',
@@ -272,4 +269,17 @@ describe 'update' do
272
269
  result = run_cmd(@cmd + params)
273
270
  assert_cmd(success_result("Location updated.\n"), result)
274
271
  end
272
+
273
+ it 'updates nothing without related parameters' do
274
+ params = %w[--id=1]
275
+
276
+ api_expects(:locations, :index)
277
+ api_expects(:locations, :update, 'Update location with no params').returns({})
278
+
279
+ expected_result = success_result("Nothing to update.\n")
280
+
281
+ result = run_cmd(@cmd + params)
282
+ assert_cmd(expected_result, result)
283
+ end
284
+
275
285
  end
@@ -26,7 +26,7 @@ describe 'mail_notification' do
26
26
  end
27
27
 
28
28
  it 'should run list command with defaults' do
29
- providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
29
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.5')) }
30
30
  defaults = HammerCLI::Defaults.new(
31
31
  {
32
32
  organization_id: {
@@ -39,6 +39,8 @@ describe 'mail_notification' do
39
39
  )
40
40
  defaults.stubs(:write_to_file).returns(true)
41
41
  defaults.stubs(:providers).returns(providers)
42
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
43
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
42
44
  api_expects(:mail_notifications, :index, 'List mail notifications').returns(@mail_notifications)
43
45
 
44
46
  result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
@@ -126,5 +126,16 @@ describe 'medium' do
126
126
  result = run_cmd(@cmd + params)
127
127
  assert_cmd(success_result("Installation medium updated.\n"), result)
128
128
  end
129
+
130
+ it 'updates nothing without medium related parameters' do
131
+ params = %w[--id=1]
132
+
133
+ api_expects(:media, :update, 'Update medium with no params').returns({})
134
+
135
+ expected_result = success_result("Nothing to update.\n")
136
+
137
+ result = run_cmd(@cmd + params)
138
+ assert_cmd(expected_result, result)
139
+ end
129
140
  end
130
141
  end
@@ -26,7 +26,7 @@ describe 'model' do
26
26
  end
27
27
 
28
28
  it 'should run list command with defaults' do
29
- providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
29
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.5')) }
30
30
  defaults = HammerCLI::Defaults.new(
31
31
  {
32
32
  organization_id: {
@@ -39,6 +39,8 @@ describe 'model' do
39
39
  )
40
40
  defaults.stubs(:write_to_file).returns(true)
41
41
  defaults.stubs(:providers).returns(providers)
42
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
43
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
42
44
  api_expects(:models, :index, 'List models').returns(@models)
43
45
 
44
46
  result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
@@ -27,7 +27,7 @@ describe 'operating_system' do
27
27
  end
28
28
 
29
29
  it 'should run list command with defaults' do
30
- providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
30
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.5')) }
31
31
  defaults = HammerCLI::Defaults.new(
32
32
  {
33
33
  organization_id: {
@@ -40,6 +40,8 @@ describe 'operating_system' do
40
40
  )
41
41
  defaults.stubs(:write_to_file).returns(true)
42
42
  defaults.stubs(:providers).returns(providers)
43
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
44
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
43
45
  api_expects(:operatingsystems, :index, 'List operating systems').returns(@operating_system)
44
46
 
45
47
  result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
@@ -37,7 +37,7 @@ describe 'personal_access_token' do
37
37
 
38
38
  it 'lists all access tokens for a given user' do
39
39
  api_expects(:personal_access_tokens, :index, 'List').with_params(
40
- 'user_id' => 1, 'page' => 1, 'per_page' => 1000
40
+ 'user_id' => '1', 'page' => 1, 'per_page' => 1000
41
41
  ).returns(index_response([access_token, active_access_token]))
42
42
 
43
43
  output = IndexMatcher.new([
@@ -67,7 +67,7 @@ describe 'personal_access_token' do
67
67
 
68
68
  it 'creates an access token to a given user' do
69
69
  api_expects(:personal_access_tokens, :create).with_params(
70
- 'user_id' => 1, 'personal_access_token' => {
70
+ 'user_id' => '1', 'personal_access_token' => {
71
71
  'expires_at' => '01/01/2048', 'name' => 'test'
72
72
  }
73
73
  ).returns(access_token)
@@ -85,7 +85,7 @@ describe 'personal_access_token' do
85
85
 
86
86
  it 'shows the personal access token' do
87
87
  api_expects(:personal_access_tokens, :show, 'Show PAT').with_params(
88
- 'id' => '1', 'user_id' => 1
88
+ 'id' => '1', 'user_id' => '1'
89
89
  ).returns(access_token)
90
90
 
91
91
  output = OutputMatcher.new([
@@ -109,7 +109,7 @@ describe 'personal_access_token' do
109
109
  let(:params) { ['--id=1', '--user-id=1'] }
110
110
  it 'deletes an access token to a given user' do
111
111
  api_expects(:personal_access_tokens, :destroy, 'Revoke PAT').with_params(
112
- 'id' => '1', 'user_id' => 1
112
+ 'id' => '1', 'user_id' => '1'
113
113
  ).returns(access_token)
114
114
 
115
115
  expected_result = success_result(
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.join(File.dirname(__FILE__), 'test_helper')
2
4
 
3
5
  describe 'ping' do
@@ -30,5 +32,36 @@ describe 'ping' do
30
32
  result = run_cmd(cmd)
31
33
  assert_cmd(expected_result, result)
32
34
  end
35
+
36
+ it 'returns 1 if one of the services failed and shows unrecognized services' do
37
+ ping_results['results']['new_plugin'] = {
38
+ 'services' => {
39
+ 'first' => {
40
+ 'status' => 'FAIL'
41
+ },
42
+ 'second' => {
43
+ 'status' => 'ok'
44
+ }
45
+ },
46
+ 'status' => 'FAIL'
47
+ }
48
+ api_expects(:ping, :ping, 'Ping').returns(ping_results)
49
+
50
+ expected_result = CommandExpectation.new
51
+ expected_result.expected_out = OutputMatcher.new(
52
+ [
53
+ 'database:',
54
+ ' Status: ok',
55
+ ' Server Response: Duration: 0ms'
56
+ ]
57
+ )
58
+ expected_result.expected_err =
59
+ ['1 more service(s) failed, but not shown:',
60
+ 'first',
61
+ ''].join("\n")
62
+ expected_result.expected_exit_code = 1
63
+ result = run_cmd(cmd)
64
+ assert_cmd(expected_result, result)
65
+ end
33
66
  end
34
67
  end
@@ -99,5 +99,16 @@ describe 'realm' do
99
99
  result = run_cmd(@cmd + params)
100
100
  assert_cmd(success_result("Realm [%{name}] updated.\n"), result)
101
101
  end
102
+
103
+ it 'updates nothing without realm related parameters' do
104
+ params = %w[--id=1]
105
+
106
+ api_expects(:realms, :update, 'Update realm with no params').returns({})
107
+
108
+ expected_result = success_result("Nothing to update.\n")
109
+
110
+ result = run_cmd(@cmd + params)
111
+ assert_cmd(expected_result, result)
112
+ end
102
113
  end
103
114
  end
@@ -0,0 +1,8 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe 'registration_commands' do
4
+ it 'create' do
5
+ api_expects(:registration_commands, :create)
6
+ run_cmd(%w(host-registration generate-command))
7
+ end
8
+ end
@@ -195,6 +195,17 @@ describe 'report-template' do
195
195
  result = run_cmd(cmd + params)
196
196
  assert_cmd(success_result("Report template updated.\n"), result)
197
197
  end
198
+
199
+ it 'updates nothing without template related parameters' do
200
+ params = %w[--id=1]
201
+
202
+ api_expects(:report_templates, :update, 'Update template with no params').returns({})
203
+
204
+ expected_result = success_result("Nothing to update.\n")
205
+
206
+ result = run_cmd(cmd + params)
207
+ assert_cmd(expected_result, result)
208
+ end
198
209
  end
199
210
 
200
211
  describe 'dump' do
@@ -32,7 +32,7 @@ describe 'Settings' do
32
32
  end
33
33
 
34
34
  it 'should run list command with defaults' do
35
- providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
35
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.5')) }
36
36
  defaults = HammerCLI::Defaults.new(
37
37
  {
38
38
  organization_id: {
@@ -45,9 +45,9 @@ describe 'Settings' do
45
45
  )
46
46
  defaults.stubs(:write_to_file).returns(true)
47
47
  defaults.stubs(:providers).returns(providers)
48
- api_expects(:settings, :index, 'List').with_params(
49
- 'page' => 1, 'per_page' => 1000
50
- ).returns(index_response([setting]))
48
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
49
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
50
+ api_expects(:settings, :index, 'List settings').returns(setting)
51
51
 
52
52
  result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
53
53
  _(result.exit_code).must_equal HammerCLI::EX_OK
@@ -85,7 +85,6 @@ describe 'template' do
85
85
  it "doesn't send snippet flag when --type is undefined" do
86
86
  params = ['--id=1', '--locked=true']
87
87
 
88
- api_expects(:template_kinds, :index, 'Get list of template kinds').returns(index_response([]))
89
88
  api_expects(:provisioning_templates, :update, 'Update the template') do |par|
90
89
  par['id'] == '1' &&
91
90
  par['provisioning_template']['locked'] == true
@@ -95,6 +94,59 @@ describe 'template' do
95
94
 
96
95
  assert_cmd(success_result("Provisioning template updated.\n"), result)
97
96
  end
97
+
98
+ it 'updates nothing without template related parameters' do
99
+ params = %w[--id=1 --organization-id=1 --location-id=1]
100
+
101
+ api_expects(:provisioning_templates, :update, 'Update template with no params').returns({})
102
+
103
+ expected_result = success_result("Nothing to update.\n")
104
+
105
+ result = run_cmd(@cmd + params)
106
+ assert_cmd(expected_result, result)
107
+ end
108
+
109
+ it 'should update a template' do
110
+ params = ['--id=1', '--type=snippet']
111
+
112
+ expected_result = CommandExpectation.new
113
+ expected_result.expected_out =
114
+ ['Provisioning template updated.',
115
+ ''].join("\n")
116
+ expected_result.expected_exit_code = HammerCLI::EX_OK
117
+
118
+ api_expects(:provisioning_templates, :update, 'Update template with params') do |p|
119
+ p['id'] == '1' && p['provisioning_template']['snippet'] == true
120
+ end
121
+
122
+ result = run_cmd(@cmd + params)
123
+ assert_cmd(expected_result, result)
124
+ end
125
+
126
+ it 'should update a template by name' do
127
+ params = ['--name=tpl', '--type=provision']
128
+
129
+ expected_result = CommandExpectation.new
130
+ expected_result.expected_out =
131
+ ['Provisioning template updated.',
132
+ ''].join("\n")
133
+ expected_result.expected_exit_code = HammerCLI::EX_OK
134
+
135
+ api_expects_search(:provisioning_templates, name: 'tpl').returns(
136
+ index_response([{ 'id' => '1' }])
137
+ )
138
+ api_expects_search(:template_kinds, name: 'provision').returns(
139
+ index_response([{ 'id' => '1' }])
140
+ )
141
+ api_expects(:provisioning_templates, :update, 'Update template with params') do |p|
142
+ p['id'] == '1' &&
143
+ p['provisioning_template']['snippet'] == false &&
144
+ p['provisioning_template']['template_kind_id'] == '1'
145
+ end
146
+
147
+ result = run_cmd(@cmd + params)
148
+ assert_cmd(expected_result, result)
149
+ end
98
150
  end
99
151
 
100
152
  describe 'create' do
@@ -108,65 +160,53 @@ describe 'template' do
108
160
  expected_result = CommandExpectation.new
109
161
  expected_result.expected_err =
110
162
  ['Could not create the provisioning template:',
111
- " Error: unknown template kind",
112
- ' ',
113
- " See: 'hammer template create --help'.",
163
+ ' Error: template_kind not found.',
114
164
  ''].join("\n")
115
- expected_result.expected_exit_code = HammerCLI::EX_USAGE
165
+ expected_result.expected_exit_code = HammerCLI::EX_SOFTWARE
116
166
 
117
- HammerCLIForeman::Template::CreateCommand.any_instance.stubs(:kinds).returns(["PXELinux"])
118
-
119
- api_expects_no_call
167
+ api_expects_search(:template_kinds, name: 'unknown').returns(
168
+ index_response([])
169
+ )
120
170
 
121
171
  result = run_cmd(@cmd + params)
122
172
  assert_cmd(expected_result, result)
123
173
  end
124
- end
125
174
 
126
- describe 'combinations' do
127
- before do
128
- @cmd = %w(template combination)
129
- end
175
+ it 'should create a template' do
176
+ params = ['--name=tpl', '--file=Gemfile', '--type=provision']
130
177
 
131
- it 'should create new combination with warning' do
132
- params = ['create','--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
133
- expected_result = success_result("Template combination created.\n")
134
- expected_result.expected_err = "Warning: Option --environment-id is deprecated. Use --puppet-environment[-id] instead\n"
135
- api_expects(:template_combinations, :create, 'Create template combination') do |params|
136
- params['provisioning_template_id'] == 10 &&
137
- params['hostgroup_id'] == 1 &&
138
- params['environment_id'] == 1 &&
139
- params['template_combination'] == {'environment_id' => 1, 'hostgroup_id' => 1}
178
+ expected_result = CommandExpectation.new
179
+ expected_result.expected_out =
180
+ ['Provisioning template created.',
181
+ ''].join("\n")
182
+ expected_result.expected_exit_code = HammerCLI::EX_OK
183
+
184
+ api_expects_search(:template_kinds, name: 'provision').returns(
185
+ index_response([{ 'id' => '1' }])
186
+ )
187
+ api_expects(:provisioning_templates, :create, 'Create template with params') do |p|
188
+ p['provisioning_template']['name'] == 'tpl' &&
189
+ p['provisioning_template']['snippet'] == false &&
190
+ p['provisioning_template']['template_kind_id'] = '1'
140
191
  end
141
192
 
142
193
  result = run_cmd(@cmd + params)
143
194
  assert_cmd(expected_result, result)
144
195
  end
196
+ end
197
+
198
+ describe 'combinations' do
199
+ before do
200
+ @cmd = %w(template combination)
201
+ end
145
202
 
146
203
  it 'should create new combination' do
147
- params = ['create','--provisioning-template-id=10', '--hostgroup-id=1', '--puppet-environment-id=1']
204
+ params = ['create','--provisioning-template-id=10', '--hostgroup-id=1']
148
205
  expected_result = success_result("Template combination created.\n")
149
206
  api_expects(:template_combinations, :create, 'Create template combination') do |params|
150
- params['provisioning_template_id'] == 10 &&
151
- params['hostgroup_id'] == 1 &&
152
- params['environment_id'] == 1 &&
153
- params['template_combination'] == {'environment_id' => 1, 'hostgroup_id' => 1}
154
- end
155
-
156
- result = run_cmd(@cmd + params)
157
- assert_cmd(expected_result, result)
158
- end
159
-
160
- it 'should update combination with warning' do
161
- params = ['update', '--id=3', '--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
162
- expected_result = success_result("Template combination updated.\n")
163
- expected_result.expected_err = "Warning: Option --environment-id is deprecated. Use --puppet-environment[-id] instead\n"
164
- api_expects(:template_combinations, :update, 'Update template combination') do |params|
165
- params['id'] == '3' &&
166
- params['provisioning_template_id'] == 10 &&
167
- params['hostgroup_id'] == 1 &&
168
- params['environment_id'] == 1 &&
169
- params['template_combination'] == { 'environment_id' => 1, 'hostgroup_id' => 1 }
207
+ params['provisioning_template_id'] == '10' &&
208
+ params['hostgroup_id'] == '1' &&
209
+ params['template_combination'] == { 'hostgroup_id' => '1' }
170
210
  end
171
211
 
172
212
  result = run_cmd(@cmd + params)
@@ -174,14 +214,13 @@ describe 'template' do
174
214
  end
175
215
 
176
216
  it 'should update combination' do
177
- params = ['update', '--id=3', '--provisioning-template-id=10', '--hostgroup-id=1', '--puppet-environment-id=1']
217
+ params = ['update', '--id=3', '--provisioning-template-id=10', '--hostgroup-id=1']
178
218
  expected_result = success_result("Template combination updated.\n")
179
219
  api_expects(:template_combinations, :update, 'Update template combination') do |params|
180
220
  params['id'] == '3' &&
181
- params['provisioning_template_id'] == 10 &&
182
- params['hostgroup_id'] == 1 &&
183
- params['environment_id'] == 1 &&
184
- params['template_combination'] == { 'environment_id' => 1, 'hostgroup_id' => 1 }
221
+ params['provisioning_template_id'] == '10' &&
222
+ params['hostgroup_id'] == '1' &&
223
+ params['template_combination'] == { 'hostgroup_id' => '1' }
185
224
  end
186
225
 
187
226
  result = run_cmd(@cmd + params)
@@ -55,9 +55,9 @@ describe 'user_mail_notification' do
55
55
  params = ['--user-id=2']
56
56
 
57
57
  expected_result = common_error_result(
58
- @cmd,
59
- "Could not find mail_notification, please set one of options --mail-notification, --mail-notification-id.",
60
- "Could not add user mail notification"
58
+ @cmd,
59
+ 'Could not find mail_notification, please set one of options --mail-notification-id, --mail-notification.',
60
+ 'Could not add user mail notification'
61
61
  )
62
62
 
63
63
  result = run_cmd(@cmd + params)
@@ -82,6 +82,17 @@ describe "user" do
82
82
  assert_cmd(expected_result, result)
83
83
  end
84
84
 
85
+ it 'updates nothing without user related parameters' do
86
+ params = %w[--id=1]
87
+
88
+ api_expects(:users, :update, 'Update user with no params').returns({})
89
+
90
+ expected_result = success_result("Nothing to update.\n")
91
+
92
+ result = run_cmd(cmd + params)
93
+ assert_cmd(expected_result, result)
94
+ end
95
+
85
96
  describe "update password" do
86
97
  def replace_foreman_connection(connection)
87
98
  HammerCLI.context[:api_connection].drop('foreman')
@@ -27,7 +27,7 @@ describe 'user-group' do
27
27
  end
28
28
 
29
29
  it 'should run list command with defaults' do
30
- providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
30
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.5')) }
31
31
  defaults = HammerCLI::Defaults.new(
32
32
  {
33
33
  organization_id: {
@@ -40,6 +40,8 @@ describe 'user-group' do
40
40
  )
41
41
  defaults.stubs(:write_to_file).returns(true)
42
42
  defaults.stubs(:providers).returns(providers)
43
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
44
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
43
45
  api_expects(:usergroups, :index, 'List user groups').returns(@user_groups)
44
46
 
45
47
  result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
data/test/test_helper.rb CHANGED
@@ -17,7 +17,7 @@ require "mocha/minitest"
17
17
  require 'hammer_cli'
18
18
  require 'hammer_cli_foreman/testing/api_expectations'
19
19
 
20
- FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '2.1'
20
+ FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '3.1'
21
21
  unless Dir.entries('test/data').include? FOREMAN_VERSION
22
22
  raise StandardError.new "Version is not correct"
23
23
  end