hammer_cli_foreman 0.7.0 → 0.8.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.

Potentially problematic release.


This version of hammer_cli_foreman might be problematic. Click here for more details.

Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +11 -0
  3. data/lib/hammer_cli_foreman.rb +4 -0
  4. data/lib/hammer_cli_foreman/associating_commands.rb +21 -0
  5. data/lib/hammer_cli_foreman/host.rb +0 -5
  6. data/lib/hammer_cli_foreman/id_resolver.rb +6 -2
  7. data/lib/hammer_cli_foreman/location.rb +1 -0
  8. data/lib/hammer_cli_foreman/organization.rb +2 -0
  9. data/lib/hammer_cli_foreman/realm.rb +53 -0
  10. data/lib/hammer_cli_foreman/smart_class_parameter.rb +3 -0
  11. data/lib/hammer_cli_foreman/smart_variable.rb +4 -1
  12. data/lib/hammer_cli_foreman/usergroup.rb +1 -3
  13. data/lib/hammer_cli_foreman/version.rb +1 -1
  14. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  15. data/locale/ca/hammer-cli-foreman.edit.po +376 -290
  16. data/locale/ca/hammer-cli-foreman.po +393 -192
  17. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  18. data/locale/de/hammer-cli-foreman.edit.po +277 -179
  19. data/locale/de/hammer-cli-foreman.po +420 -219
  20. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  21. data/locale/en/hammer-cli-foreman.edit.po +216 -144
  22. data/locale/en/hammer-cli-foreman.po +55 -1
  23. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  24. data/locale/en_GB/hammer-cli-foreman.edit.po +339 -224
  25. data/locale/en_GB/hammer-cli-foreman.po +391 -190
  26. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  27. data/locale/es/hammer-cli-foreman.edit.po +251 -158
  28. data/locale/es/hammer-cli-foreman.po +444 -242
  29. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  30. data/locale/fr/hammer-cli-foreman.edit.po +252 -159
  31. data/locale/fr/hammer-cli-foreman.po +392 -191
  32. data/locale/hammer-cli-foreman.pot +253 -175
  33. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/it/hammer-cli-foreman.edit.po +281 -188
  35. data/locale/it/hammer-cli-foreman.po +391 -190
  36. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/ja/hammer-cli-foreman.edit.po +282 -189
  38. data/locale/ja/hammer-cli-foreman.po +457 -256
  39. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/ko/hammer-cli-foreman.edit.po +280 -187
  41. data/locale/ko/hammer-cli-foreman.po +458 -257
  42. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  43. data/locale/pt_BR/hammer-cli-foreman.edit.po +255 -162
  44. data/locale/pt_BR/hammer-cli-foreman.po +455 -254
  45. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/locale/ru/hammer-cli-foreman.edit.po +443 -337
  47. data/locale/ru/hammer-cli-foreman.po +412 -211
  48. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  49. data/locale/zh_CN/hammer-cli-foreman.edit.po +278 -185
  50. data/locale/zh_CN/hammer-cli-foreman.po +465 -264
  51. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  52. data/locale/zh_TW/hammer-cli-foreman.edit.po +279 -186
  53. data/locale/zh_TW/hammer-cli-foreman.po +459 -258
  54. data/test/data/README.md +2 -2
  55. data/test/functional/hostgroup/create_test.rb +303 -0
  56. data/test/functional/hostgroup/update_test.rb +303 -0
  57. data/test/functional/smart_variable_test.rb +150 -0
  58. data/test/unit/host_test.rb +0 -4
  59. data/test/unit/location_test.rb +1 -0
  60. data/test/unit/organization_test.rb +1 -0
  61. data/test/unit/realm_test.rb +87 -0
  62. data/test/unit/smart_class_parameter_test.rb +7 -0
  63. data/test/unit/smart_variable_test.rb +1 -1
  64. data/test/unit/usergroup_test.rb +2 -0
  65. metadata +13 -4
data/test/data/README.md CHANGED
@@ -17,9 +17,9 @@
17
17
  ```bash
18
18
  $ FOREMAN_APIPIE_LANGS=en rake apipie:cache
19
19
  ```
20
- 1. in **hammer-cli-foreman** in `test/unit/data/` Create directory with name matching the Foreman version in `test/unit/data/` (e.g. `test/unit/data/1.10`)
20
+ 1. in **hammer-cli-foreman** in `test/data/` Create directory with name matching the Foreman version in `test/data/` (e.g. `test/data/1.10`)
21
21
  1. copy the API cache from the Foreman instance into the newly created directory and name it as `foreman_api.json`
22
- 1. update the following line in `test/unit/test_helper.rb` to match the new default Foreman version
22
+ 1. update the following line in `test/test_helper.rb` to match the new default Foreman version
23
23
 
24
24
  ```ruby
25
25
  FOREMAN_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '1.10')
@@ -0,0 +1,303 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_foreman/hostgroup'
3
+
4
+ module HammerCLIForeman
5
+ describe Hostgroup do
6
+ describe CreateCommand do
7
+ it 'allows minimal options' do
8
+ api_expects(:hostgroups, :create) do |par|
9
+ par['hostgroup']['name'] == 'hg1'
10
+ end
11
+ run_cmd(%w(hostgroup create --name hg1))
12
+ end
13
+
14
+ it 'allows architecture id' do
15
+ api_expects(:hostgroups, :create) do |p|
16
+ p['hostgroup']['architecture_id'] == 1 &&
17
+ p['hostgroup']['name'] == 'hg1'
18
+ end
19
+ run_cmd(%w(hostgroup create --name hg1 --architecture-id 1))
20
+ end
21
+
22
+ it 'allows architecture name' do
23
+ api_expects(:architectures, :index) do |p|
24
+ p[:search] = "name = \"arch1\""
25
+ end.returns(index_response([{'id' => 1}]))
26
+ api_expects(:hostgroups, :create) do |p|
27
+ p['hostgroup']['architecture_id'] == 1 &&
28
+ p['hostgroup']['name'] == 'hg1'
29
+ end
30
+ run_cmd(%w(hostgroup create --name hg1 --architecture arch1))
31
+ end
32
+
33
+ it 'allows compute profile id' do
34
+ api_expects(:hostgroups, :create) do |p|
35
+ p['hostgroup']['compute_profile_id'] == 1 &&
36
+ p['hostgroup']['name'] == 'hg1'
37
+ end
38
+ run_cmd(%w(hostgroup create --name hg1 --compute-profile-id 1))
39
+ end
40
+
41
+ it 'allows compute profile name' do
42
+ api_expects(:compute_profiles, :index) do |p|
43
+ p[:search] = "name = \"cp1\""
44
+ end.returns(index_response([{'id' => 1}]))
45
+ api_expects(:hostgroups, :create) do |p|
46
+ p['hostgroup']['compute_profile_id'] == 1 &&
47
+ p['hostgroup']['name'] == 'hg1'
48
+ end
49
+ run_cmd(%w(hostgroup create --name hg1 --compute-profile cp1))
50
+ end
51
+
52
+ it 'allows domain id' do
53
+ api_expects(:hostgroups, :create) do |p|
54
+ p['hostgroup']['domain_id'] == 1 &&
55
+ p['hostgroup']['name'] == 'hg1'
56
+ end
57
+ run_cmd(%w(hostgroup create --name hg1 --domain-id 1))
58
+ end
59
+
60
+ it 'allows domain name' do
61
+ api_expects(:domains, :index) do |p|
62
+ p[:search] = "name = \"d1\""
63
+ end.returns(index_response([{'id' => 1}]))
64
+ api_expects(:hostgroups, :create) do |p|
65
+ p['hostgroup']['domain_id'] == 1 &&
66
+ p['hostgroup']['name'] == 'hg1'
67
+ end
68
+ run_cmd(%w(hostgroup create --name hg1 --domain d1))
69
+ end
70
+
71
+ it 'allows environment id' do
72
+ api_expects(:hostgroups, :create) do |p|
73
+ p['hostgroup']['environment_id'] == 1 &&
74
+ p['hostgroup']['name'] == 'hg1'
75
+ end
76
+ run_cmd(%w(hostgroup create --name hg1 --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, :create) do |p|
84
+ p['hostgroup']['environment_id'] == 1 &&
85
+ p['hostgroup']['name'] == 'hg1'
86
+ end
87
+ run_cmd(%w(hostgroup create --name hg1 --environment env1))
88
+ end
89
+
90
+ it 'allows location ids' do
91
+ api_expects(:hostgroups, :create) do |p|
92
+ p['hostgroup']['location_ids'] == ['1','4'] &&
93
+ p['hostgroup']['name'] == 'hg1'
94
+ end
95
+ run_cmd(%w(hostgroup create --name hg1 --location-ids 1,4))
96
+ end
97
+
98
+ it 'allows location names' do
99
+ api_expects(:locations, :index) do |p|
100
+ p[:search] == "name = \"loc1\" or name = \"loc2\""
101
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
102
+ api_expects(:hostgroups, :create) do |p|
103
+ p['hostgroup']['location_ids'] == [1, 2] &&
104
+ p['hostgroup']['name'] == 'hg1'
105
+ end
106
+ run_cmd(%w(hostgroup create --name hg1 --locations loc1,loc2))
107
+ end
108
+
109
+ it 'allows medium id' do
110
+ api_expects(:hostgroups, :create) do |p|
111
+ p['hostgroup']['medium_id'] == 1 &&
112
+ p['hostgroup']['name'] == 'hg1'
113
+ end
114
+ run_cmd(%w(hostgroup create --name hg1 --medium-id 1))
115
+ end
116
+
117
+ it 'allows medium name' do
118
+ api_expects(:media, :index) do |p|
119
+ p[:search] = "name = \"med1\""
120
+ end.returns(index_response([{'id' => 1}]))
121
+ api_expects(:hostgroups, :create) do |p|
122
+ p['hostgroup']['medium_id'] == 1 &&
123
+ p['hostgroup']['name'] == 'hg1'
124
+ end
125
+ run_cmd(%w(hostgroup create --name hg1 --medium med1))
126
+ end
127
+
128
+ it 'allows operating system id' do
129
+ api_expects(:hostgroups, :create) do |p|
130
+ p['hostgroup']['operatingsystem_id'] == 1 &&
131
+ p['hostgroup']['name'] == 'hg1'
132
+ end
133
+ run_cmd(%w(hostgroup create --name hg1 --operatingsystem-id 1))
134
+ end
135
+
136
+ it 'allows operating system name' do
137
+ api_expects(:operatingsystems, :index) do |p|
138
+ p[:search] = "name = \"os1\""
139
+ end.returns(index_response([{'id' => 1}]))
140
+ api_expects(:hostgroups, :create) do |p|
141
+ p['hostgroup']['operatingsystem_id'] == 1 &&
142
+ p['hostgroup']['name'] == 'hg1'
143
+ end
144
+ run_cmd(%w(hostgroup create --name hg1 --operatingsystem os1))
145
+ end
146
+
147
+ it 'allows organization ids' do
148
+ api_expects(:hostgroups, :create) do |p|
149
+ p['hostgroup']['organization_ids'] == ['1','4'] &&
150
+ p['hostgroup']['name'] == 'hg1'
151
+ end
152
+ run_cmd(%w(hostgroup create --name hg1 --organization-ids 1,4))
153
+ end
154
+
155
+ it 'allows organization names' do
156
+ api_expects(:organizations, :index) do |p|
157
+ p[:search] == "name = \"org1\" or name = \"org2\""
158
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
159
+ api_expects(:hostgroups, :create) do |p|
160
+ p['hostgroup']['organization_ids'] == [1, 2] &&
161
+ p['hostgroup']['name'] == 'hg1'
162
+ end
163
+ run_cmd(%w(hostgroup create --name hg1 --organizations org1,org2))
164
+ end
165
+
166
+ it 'allows parent hostgroup id' do
167
+ api_expects(:hostgroups, :create) do |p|
168
+ p['hostgroup']['parent_id'] == 1 &&
169
+ p['hostgroup']['name'] == 'hg1'
170
+ end
171
+ run_cmd(%w(hostgroup create --name hg1 --parent-id 1))
172
+ end
173
+
174
+ it 'allows parent hostgroup name' do
175
+ api_expects(:hostgroups, :index) do |p|
176
+ p[:search] = "name = \"parent_hg\""
177
+ end.returns(index_response([{'id' => 1}]))
178
+ api_expects(:hostgroups, :create) do |p|
179
+ p['hostgroup']['parent_id'] == 1 &&
180
+ p['hostgroup']['name'] == 'hg1'
181
+ end
182
+ run_cmd(%w(hostgroup create --name hg1 --parent parent_hg))
183
+ end
184
+
185
+ it 'allows partition table id' do
186
+ api_expects(:hostgroups, :create) do |p|
187
+ p['hostgroup']['ptable_id'] == 1 &&
188
+ p['hostgroup']['name'] == 'hg1'
189
+ end
190
+ run_cmd(%w(hostgroup create --name hg1 --partition-table-id 1))
191
+ end
192
+
193
+ it 'allows partition table name' do
194
+ api_expects(:ptables, :index) do |p|
195
+ p[:search] = "name = \"pt1\""
196
+ end.returns(index_response([{'id' => 1}]))
197
+ api_expects(:hostgroups, :create) do |p|
198
+ p['hostgroup']['ptable_id'] == 1 &&
199
+ p['hostgroup']['name'] == 'hg1'
200
+ end
201
+ run_cmd(%w(hostgroup create --name hg1 --partition-table pt1))
202
+ end
203
+
204
+ it 'allows puppet ca proxy id' do
205
+ api_expects(:hostgroups, :create) do |p|
206
+ p['hostgroup']['puppet_ca_proxy_id'] == 1 &&
207
+ p['hostgroup']['name'] == 'hg1'
208
+ end
209
+ run_cmd(%w(hostgroup create --name hg1 --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, :create) do |p|
217
+ p['hostgroup']['puppet_ca_proxy_id'] == 1 &&
218
+ p['hostgroup']['name'] == 'hg1'
219
+ end
220
+ run_cmd(%w(hostgroup create --name hg1 --puppet-ca-proxy sp1))
221
+ end
222
+
223
+ it 'allows puppet class ids' do
224
+ api_expects(:hostgroups, :create) do |p|
225
+ p['hostgroup']['puppetclass_ids'] == ['1','2'] &&
226
+ p['hostgroup']['name'] == 'hg1'
227
+ end
228
+ run_cmd(%w(hostgroup create --name hg1 --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, :create) do |p|
239
+ p['hostgroup']['puppetclass_ids'] == [1,2] &&
240
+ p['hostgroup']['name'] == 'hg1'
241
+ end
242
+ run_cmd(%w(hostgroup create --name hg1 --puppet-classes pc1,pc2))
243
+ end
244
+
245
+ it 'allows puppet proxy id' do
246
+ api_expects(:hostgroups, :create) do |p|
247
+ p['hostgroup']['puppet_proxy_id'] == 1 &&
248
+ p['hostgroup']['name'] == 'hg1'
249
+ end
250
+ run_cmd(%w(hostgroup create --name hg1 --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, :create) do |p|
258
+ p['hostgroup']['puppet_proxy_id'] == 1 &&
259
+ p['hostgroup']['name'] == 'hg1'
260
+ end
261
+ run_cmd(%w(hostgroup create --name hg1 --puppet-proxy sp1))
262
+ end
263
+
264
+ it 'allows realm id' do
265
+ api_expects(:hostgroups, :create) do |p|
266
+ p['hostgroup']['realm_id'] == 1 &&
267
+ p['hostgroup']['name'] == 'hg1'
268
+ end
269
+ run_cmd(%w(hostgroup create --name hg1 --realm-id 1))
270
+ end
271
+
272
+ it 'allows realm name' do
273
+ api_expects(:realms, :index) do |p|
274
+ p[:search] = "name = \"realm1\""
275
+ end.returns(index_response([{'id' => 1}]))
276
+ api_expects(:hostgroups, :create) do |p|
277
+ p['hostgroup']['realm_id'] == 1 &&
278
+ p['hostgroup']['name'] == 'hg1'
279
+ end
280
+ run_cmd(%w(hostgroup create --name hg1 --realm realm1))
281
+ end
282
+
283
+ it 'allows subnet id' do
284
+ api_expects(:hostgroups, :create) do |p|
285
+ p['hostgroup']['subnet_id'] == 1 &&
286
+ p['hostgroup']['name'] == 'hg1'
287
+ end
288
+ run_cmd(%w(hostgroup create --name hg1 --subnet-id 1))
289
+ end
290
+
291
+ it 'allows subnet name' do
292
+ api_expects(:subnets, :index) do |p|
293
+ p[:search] = "name = \"subnet1\""
294
+ end.returns(index_response([{'id' => 1}]))
295
+ api_expects(:hostgroups, :create) do |p|
296
+ p['hostgroup']['subnet_id'] == 1 &&
297
+ p['hostgroup']['name'] == 'hg1'
298
+ end
299
+ run_cmd(%w(hostgroup create --name hg1 --subnet subnet1))
300
+ end
301
+ end
302
+ end
303
+ end
@@ -0,0 +1,303 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_foreman/hostgroup'
3
+
4
+ module HammerCLIForeman
5
+ describe Hostgroup do
6
+ describe UpdateCommand do
7
+ it 'allows minimal options' do
8
+ api_expects(:hostgroups, :update) do |par|
9
+ par['id'] == '1'
10
+ end
11
+ run_cmd(%w(hostgroup update --id 1))
12
+ end
13
+
14
+ it 'allows architecture id' do
15
+ api_expects(:hostgroups, :update) do |p|
16
+ p['hostgroup']['architecture_id'] == 1 &&
17
+ p['id'] == '1'
18
+ end
19
+ run_cmd(%w(hostgroup update --id 1 --architecture-id 1))
20
+ end
21
+
22
+ it 'allows architecture name' do
23
+ api_expects(:architectures, :index) do |p|
24
+ p[:search] = "name = \"arch1\""
25
+ end.returns(index_response([{'id' => 1}]))
26
+ api_expects(:hostgroups, :update) do |p|
27
+ p['hostgroup']['architecture_id'] == 1 &&
28
+ p['id'] == '1'
29
+ end
30
+ run_cmd(%w(hostgroup update --id 1 --architecture arch1))
31
+ end
32
+
33
+ it 'allows compute profile id' do
34
+ api_expects(:hostgroups, :update) do |p|
35
+ p['hostgroup']['compute_profile_id'] == 1 &&
36
+ p['id'] == '1'
37
+ end
38
+ run_cmd(%w(hostgroup update --id 1 --compute-profile-id 1))
39
+ end
40
+
41
+ it 'allows compute profile name' do
42
+ api_expects(:compute_profiles, :index) do |p|
43
+ p[:search] = "name = \"cp1\""
44
+ end.returns(index_response([{'id' => 1}]))
45
+ api_expects(:hostgroups, :update) do |p|
46
+ p['hostgroup']['compute_profile_id'] == 1 &&
47
+ p['id'] == '1'
48
+ end
49
+ run_cmd(%w(hostgroup update --id 1 --compute-profile cp1))
50
+ end
51
+
52
+ it 'allows domain id' do
53
+ api_expects(:hostgroups, :update) do |p|
54
+ p['hostgroup']['domain_id'] == 1 &&
55
+ p['id'] == '1'
56
+ end
57
+ run_cmd(%w(hostgroup update --id 1 --domain-id 1))
58
+ end
59
+
60
+ it 'allows domain name' do
61
+ api_expects(:domains, :index) do |p|
62
+ p[:search] = "name = \"d1\""
63
+ end.returns(index_response([{'id' => 1}]))
64
+ api_expects(:hostgroups, :update) do |p|
65
+ p['hostgroup']['domain_id'] == 1 &&
66
+ p['id'] == '1'
67
+ end
68
+ run_cmd(%w(hostgroup update --id 1 --domain d1))
69
+ end
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
+ it 'allows location ids' do
91
+ api_expects(:hostgroups, :update) do |p|
92
+ p['hostgroup']['location_ids'] == ['1','4'] &&
93
+ p['id'] == '1'
94
+ end
95
+ run_cmd(%w(hostgroup update --id 1 --location-ids 1,4))
96
+ end
97
+
98
+ it 'allows location names' do
99
+ api_expects(:locations, :index) do |p|
100
+ p[:search] == "name = \"loc1\" or name = \"loc2\""
101
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
102
+ api_expects(:hostgroups, :update) do |p|
103
+ p['hostgroup']['location_ids'] == [1, 2] &&
104
+ p['id'] == '1'
105
+ end
106
+ run_cmd(%w(hostgroup update --id 1 --locations loc1,loc2))
107
+ end
108
+
109
+ it 'allows medium id' do
110
+ api_expects(:hostgroups, :update) do |p|
111
+ p['hostgroup']['medium_id'] == 1 &&
112
+ p['id'] == '1'
113
+ end
114
+ run_cmd(%w(hostgroup update --id 1 --medium-id 1))
115
+ end
116
+
117
+ it 'allows medium name' do
118
+ api_expects(:media, :index) do |p|
119
+ p[:search] = "name = \"med1\""
120
+ end.returns(index_response([{'id' => 1}]))
121
+ api_expects(:hostgroups, :update) do |p|
122
+ p['hostgroup']['medium_id'] == 1 &&
123
+ p['id'] == '1'
124
+ end
125
+ run_cmd(%w(hostgroup update --id 1 --medium med1))
126
+ end
127
+
128
+ it 'allows operating system id' do
129
+ api_expects(:hostgroups, :update) do |p|
130
+ p['hostgroup']['operatingsystem_id'] == 1 &&
131
+ p['id'] == '1'
132
+ end
133
+ run_cmd(%w(hostgroup update --id 1 --operatingsystem-id 1))
134
+ end
135
+
136
+ it 'allows operating system name' do
137
+ api_expects(:operatingsystems, :index) do |p|
138
+ p[:search] = "name = \"os1\""
139
+ end.returns(index_response([{'id' => 1}]))
140
+ api_expects(:hostgroups, :update) do |p|
141
+ p['hostgroup']['operatingsystem_id'] == 1 &&
142
+ p['id'] == '1'
143
+ end
144
+ run_cmd(%w(hostgroup update --id 1 --operatingsystem os1))
145
+ end
146
+
147
+ it 'allows organization ids' do
148
+ api_expects(:hostgroups, :update) do |p|
149
+ p['hostgroup']['organization_ids'] == ['1','4'] &&
150
+ p['id'] == '1'
151
+ end
152
+ run_cmd(%w(hostgroup update --id 1 --organization-ids 1,4))
153
+ end
154
+
155
+ it 'allows organization names' do
156
+ api_expects(:organizations, :index) do |p|
157
+ p[:search] == "name = \"org1\" or name = \"org2\""
158
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
159
+ api_expects(:hostgroups, :update) do |p|
160
+ p['hostgroup']['organization_ids'] == [1, 2] &&
161
+ p['id'] == '1'
162
+ end
163
+ run_cmd(%w(hostgroup update --id 1 --organizations org1,org2))
164
+ end
165
+
166
+ it 'allows parent hostgroup id' do
167
+ api_expects(:hostgroups, :update) do |p|
168
+ p['hostgroup']['parent_id'] == 1 &&
169
+ p['id'] == '1'
170
+ end
171
+ run_cmd(%w(hostgroup update --id 1 --parent-id 1))
172
+ end
173
+
174
+ it 'allows parent hostgroup name' do
175
+ api_expects(:hostgroups, :index) do |p|
176
+ p[:search] = "name = \"parent_hg\""
177
+ end.returns(index_response([{'id' => 1}]))
178
+ api_expects(:hostgroups, :update) do |p|
179
+ p['hostgroup']['parent_id'] == 1 &&
180
+ p['id'] == '1'
181
+ end
182
+ run_cmd(%w(hostgroup update --id 1 --parent parent_hg))
183
+ end
184
+
185
+ it 'allows partition table id' do
186
+ api_expects(:hostgroups, :update) do |p|
187
+ p['hostgroup']['ptable_id'] == 1 &&
188
+ p['id'] == '1'
189
+ end
190
+ run_cmd(%w(hostgroup update --id 1 --partition-table-id 1))
191
+ end
192
+
193
+ it 'allows partition table name' do
194
+ api_expects(:ptables, :index) do |p|
195
+ p[:search] = "name = \"pt1\""
196
+ end.returns(index_response([{'id' => 1}]))
197
+ api_expects(:hostgroups, :update) do |p|
198
+ p['hostgroup']['ptable_id'] == 1 &&
199
+ p['id'] == '1'
200
+ end
201
+ run_cmd(%w(hostgroup update --id 1 --partition-table pt1))
202
+ end
203
+
204
+ it 'allows puppet ca proxy id' do
205
+ api_expects(:hostgroups, :update) do |p|
206
+ p['hostgroup']['puppet_ca_proxy_id'] == 1 &&
207
+ p['id'] == '1'
208
+ end
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) do |p|
247
+ p['hostgroup']['puppet_proxy_id'] == 1 &&
248
+ p['id'] == '1'
249
+ end
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
+ it 'allows realm id' do
265
+ api_expects(:hostgroups, :update) do |p|
266
+ p['hostgroup']['realm_id'] == 1 &&
267
+ p['id'] == '1'
268
+ end
269
+ run_cmd(%w(hostgroup update --id 1 --realm-id 1))
270
+ end
271
+
272
+ it 'allows realm name' do
273
+ api_expects(:realms, :index) do |p|
274
+ p[:search] = "name = \"realm1\""
275
+ end.returns(index_response([{'id' => 1}]))
276
+ api_expects(:hostgroups, :update) do |p|
277
+ p['hostgroup']['realm_id'] == 1 &&
278
+ p['id'] == '1'
279
+ end
280
+ run_cmd(%w(hostgroup update --id 1 --realm realm1))
281
+ end
282
+
283
+ it 'allows subnet id' do
284
+ api_expects(:hostgroups, :update) do |p|
285
+ p['hostgroup']['subnet_id'] == 1 &&
286
+ p['id'] == '1'
287
+ end
288
+ run_cmd(%w(hostgroup update --id 1 --subnet-id 1))
289
+ end
290
+
291
+ it 'allows subnet name' do
292
+ api_expects(:subnets, :index) do |p|
293
+ p[:search] = "name = \"subnet1\""
294
+ end.returns(index_response([{'id' => 1}]))
295
+ api_expects(:hostgroups, :update) do |p|
296
+ p['hostgroup']['subnet_id'] == 1 &&
297
+ p['id'] == '1'
298
+ end
299
+ run_cmd(%w(hostgroup update --id 1 --subnet subnet1))
300
+ end
301
+ end
302
+ end
303
+ end