hammer_cli_foreman 2.3.2 → 3.0.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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +33 -3
  3. data/lib/hammer_cli_foreman.rb +3 -21
  4. data/lib/hammer_cli_foreman/associating_commands.rb +0 -24
  5. data/lib/hammer_cli_foreman/bookmark.rb +1 -1
  6. data/lib/hammer_cli_foreman/combination.rb +3 -13
  7. data/lib/hammer_cli_foreman/command_extensions.rb +1 -2
  8. data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
  9. data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
  10. data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
  11. data/lib/hammer_cli_foreman/commands.rb +16 -9
  12. data/lib/hammer_cli_foreman/compute_resource.rb +22 -0
  13. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
  14. data/lib/hammer_cli_foreman/config_report.rb +2 -0
  15. data/lib/hammer_cli_foreman/filter.rb +2 -2
  16. data/lib/hammer_cli_foreman/host.rb +1 -47
  17. data/lib/hammer_cli_foreman/hostgroup.rb +2 -53
  18. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +7 -28
  19. data/lib/hammer_cli_foreman/id_resolver.rb +0 -61
  20. data/lib/hammer_cli_foreman/location.rb +0 -6
  21. data/lib/hammer_cli_foreman/operating_system.rb +2 -1
  22. data/lib/hammer_cli_foreman/option_builders.rb +6 -5
  23. data/lib/hammer_cli_foreman/option_sources.rb +0 -1
  24. data/lib/hammer_cli_foreman/option_sources/id_params.rb +27 -10
  25. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +25 -6
  26. data/lib/hammer_cli_foreman/organization.rb +0 -6
  27. data/lib/hammer_cli_foreman/ping.rb +6 -1
  28. data/lib/hammer_cli_foreman/references.rb +0 -16
  29. data/lib/hammer_cli_foreman/registration.rb +18 -0
  30. data/lib/hammer_cli_foreman/smart_proxy.rb +0 -52
  31. data/lib/hammer_cli_foreman/version.rb +1 -1
  32. data/lib/minitest/coverage_reporter.rb +1 -1
  33. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  41. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  42. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  43. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/test/data/2.4/foreman_api.json +1 -0
  47. data/test/data/2.5/foreman_api.json +1 -0
  48. data/test/functional/architecture_test.rb +81 -0
  49. data/test/functional/bookmark_test.rb +24 -1
  50. data/test/functional/compute_profile_test.rb +56 -0
  51. data/test/functional/compute_resource_test.rb +37 -0
  52. data/test/functional/filter_test.rb +115 -47
  53. data/test/functional/host_test.rb +94 -13
  54. data/test/functional/hostgroup/create_test.rb +0 -117
  55. data/test/functional/hostgroup/update_test.rb +0 -79
  56. data/test/functional/http_proxy_test.rb +12 -0
  57. data/test/functional/location_test.rb +13 -3
  58. data/test/functional/mail_notification_test.rb +22 -0
  59. data/test/functional/media_test.rb +11 -0
  60. data/test/functional/model_test.rb +52 -0
  61. data/test/functional/operating_system_test.rb +53 -0
  62. data/test/functional/ping_test.rb +33 -0
  63. data/test/functional/realm_test.rb +11 -0
  64. data/test/functional/registration_test.rb +8 -0
  65. data/test/functional/report_template_test.rb +11 -0
  66. data/test/functional/settings_test.rb +21 -0
  67. data/test/functional/status_test.rb +79 -13
  68. data/test/functional/template_test.rb +16 -37
  69. data/test/functional/user_test.rb +11 -0
  70. data/test/functional/usergroup_test.rb +53 -0
  71. data/test/test_helper.rb +1 -1
  72. data/test/unit/apipie_resource_mock.rb +22 -39
  73. data/test/unit/architecture_test.rb +10 -1
  74. data/test/unit/bookmark_test.rb +95 -0
  75. data/test/unit/compute_profile_test.rb +87 -0
  76. data/test/unit/config_report_test.rb +1 -0
  77. data/test/unit/helpers/command.rb +0 -8
  78. data/test/unit/host_test.rb +14 -61
  79. data/test/unit/hostgroup_test.rb +7 -26
  80. data/test/unit/id_resolver_test.rb +0 -28
  81. data/test/unit/mail_notification_test.rb +53 -0
  82. data/test/unit/model_test.rb +47 -37
  83. data/test/unit/operating_system_test.rb +10 -3
  84. data/test/unit/option_sources/id_params_test.rb +9 -0
  85. data/test/unit/option_sources/ids_params_test.rb +9 -0
  86. data/test/unit/settings_test.rb +4 -0
  87. data/test/unit/smart_proxy_test.rb +0 -12
  88. data/test/unit/usergroup_test.rb +10 -0
  89. metadata +76 -73
  90. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +0 -29
  91. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +0 -29
  92. data/lib/hammer_cli_foreman/config_group.rb +0 -45
  93. data/lib/hammer_cli_foreman/option_sources/puppet_environment_params.rb +0 -59
  94. data/lib/hammer_cli_foreman/puppet_class.rb +0 -61
  95. data/lib/hammer_cli_foreman/puppet_environment.rb +0 -65
  96. data/lib/hammer_cli_foreman/smart_class_parameter.rb +0 -189
  97. data/test/functional/proxy_test.rb +0 -86
  98. data/test/functional/smart_class_parameter_test.rb +0 -97
  99. data/test/unit/config_group_test.rb +0 -72
  100. data/test/unit/puppet_class_test.rb +0 -72
  101. data/test/unit/puppet_environment_test.rb +0 -114
  102. data/test/unit/smart_class_parameter_test.rb +0 -113
@@ -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
- :id => '1'
8
- }).returns(@filter.merge('override?' => override))
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(filter create)
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(filter update)
106
+ @cmd = %w[filter update]
40
107
  @filter = {
41
- "search" => nil,
42
- "resource_type" => "User",
43
- "unlimited?" => false,
44
- "created_at" => "2017-07-18 14:34:09 UTC",
45
- "updated_at" => "2017-07-18 14:34:09 UTC",
46
- "override?" => true,
47
- "id" => 404,
48
- "role" => {
49
- "name" => "Some Role",
50
- "id" => 28,
51
- "description" => "Description\nof the new\nrole",
52
- "origin" => nil
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
- "permissions" => [{
55
- "name" => "view_users",
56
- "id" => 164,
57
- "resource_type" => "User"
122
+ 'permissions' => [{
123
+ 'name' => 'view_users',
124
+ 'id' => 164,
125
+ 'resource_type' => 'User'
58
126
  }],
59
- "locations" => [{
60
- "id" => 28,
61
- "name" => "location74",
62
- "title" => "location74",
63
- "description" => nil
127
+ 'locations' => [{
128
+ 'id' => 28,
129
+ 'name' => 'location74',
130
+ 'title' => 'location74',
131
+ 'description' => nil
64
132
  }],
65
- "organizations" => [{
66
- "id" => 27,
67
- "name" => "organization74",
68
- "title" => "organization74",
69
- "description" => nil
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(:override => false)
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
- }).returns(@filter)
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
- }).returns(@filter)
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(:override => true)
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' => ['1', '2'],
108
- 'location_ids' => ['3', '4']
175
+ 'organization_ids' => %w[1 2],
176
+ 'location_ids' => %w[3 4]
109
177
  }
110
- }).returns(@filter)
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' => ['1', '2'],
121
- 'location_ids' => ['3', '4']
188
+ 'organization_ids' => %w[1 2],
189
+ 'location_ids' => %w[3 4]
122
190
  }
123
- }).returns(@filter)
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(:override => false)
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
@@ -308,7 +356,6 @@ describe 'host update' do
308
356
  'organization_id' => '5',
309
357
  'location_id' => '5',
310
358
  'compute_attributes' => {},
311
- 'puppetclass_ids' => [],
312
359
  'owner_id' => '1',
313
360
  'owner_name' => 'adminGroup',
314
361
  'owner_type' => 'Usergroup'
@@ -356,7 +403,7 @@ describe 'host update' do
356
403
  it 'updates nothing without host related parameters' do
357
404
  api_expects(:hosts, :update, 'Update host with no host params').returns({})
358
405
 
359
- expected_result = success_result("Host updated.\n")
406
+ expected_result = success_result("Nothing to update.\n")
360
407
 
361
408
  result = run_cmd(cmd + minimal_params)
362
409
  assert_cmd(expected_result, result)
@@ -410,7 +457,25 @@ describe 'host update' do
410
457
  )
411
458
  api_expects(:hosts, :update, 'Update host with new owner').with_params(
412
459
  'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
413
- 'owner_id' => '1' }
460
+ 'owner_id' => '1' }
461
+ ) do |par|
462
+ par['id'] == '1' && par['host']['owner_id'] == '1'
463
+ end.returns(updated_host)
464
+
465
+ expected_result = success_result("Host updated.\n")
466
+
467
+ result = run_cmd(cmd + minimal_params + params)
468
+
469
+ assert_cmd(expected_result, result)
470
+ end
471
+
472
+ it 'should update the host owner with id' do
473
+ params = ['--owner-id=1']
474
+
475
+ api_expects(:hosts, :update, 'Update host with new owner').with_params(
476
+ 'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
477
+ 'owner_id' => '1'
478
+ }
414
479
  ) do |par|
415
480
  par['id'] == '1' && par['host']['owner_id'] == '1'
416
481
  end.returns(updated_host)
@@ -426,7 +491,7 @@ end
426
491
  describe 'host config reports' do
427
492
  let(:report15) do
428
493
  {
429
- "id" => 15,
494
+ "id" => 15,
430
495
  "host_id" => 1,
431
496
  "host_name" => "host.example.com",
432
497
  "reported_at" => "2017-11-13 03:04:53 UTC",
@@ -503,16 +568,32 @@ describe 'disassociate host from vm' do
503
568
  end
504
569
  end
505
570
 
506
- describe 'run puppetrun for host' do
507
- let(:cmd) { ['host', 'puppetrun'] }
508
- let(:params) { ['--id=1'] }
509
571
 
510
- it "does nothing for puppetrun" do
511
- expected_result = CommandExpectation.new
512
- expected_result.expected_err = "The puppetrun feature has been removed, however you can use the Remote Execution Plugin to run Puppet commands\n"
513
- expected_result.expected_exit_code = HammerCLI::EX_SOFTWARE
514
572
 
515
- result = run_cmd(cmd)
516
- assert_cmd(expected_result, result)
573
+ describe 'list' do
574
+ before do
575
+ @cmd = %w[host list]
576
+ end
577
+
578
+ it 'should run list command with defaults' do
579
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
580
+ defaults = HammerCLI::Defaults.new(
581
+ {
582
+ organization_id: {
583
+ provider: 'foreman'
584
+ },
585
+ location_id: {
586
+ provider: 'foreman'
587
+ }
588
+ }
589
+ )
590
+ defaults.stubs(:write_to_file).returns(true)
591
+ defaults.stubs(:providers).returns(providers)
592
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
593
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
594
+ api_expects(:hosts, :index, 'List hosts').returns(index_response([{ 'id' => '42' }]))
595
+
596
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
597
+ _(result.exit_code).must_equal HammerCLI::EX_OK
517
598
  end
518
599
  end
@@ -68,25 +68,6 @@ module HammerCLIForeman
68
68
  run_cmd(%w(hostgroup create --name hg1 --domain d1))
69
69
  end
70
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
71
  it 'allows location ids' do
91
72
  api_expects(:hostgroups, :create) do |p|
92
73
  p['hostgroup']['location_ids'] == ['1','4'] &&
@@ -203,104 +184,6 @@ module HammerCLIForeman
203
184
  run_cmd(%w(hostgroup create --name hg1 --partition-table pt1))
204
185
  end
205
186
 
206
- it 'allows puppet ca proxy id' do
207
- api_expects(:hostgroups, :create).with_params({
208
- :hostgroup => {
209
- :name => 'hg1',
210
- :puppet_ca_proxy_id => 1
211
- }
212
- })
213
- run_cmd(%w(hostgroup create --name hg1 --puppet-ca-proxy-id 1))
214
- end
215
-
216
- it 'allows puppet ca proxy name' do
217
- api_expects(:smart_proxies, :index) do |p|
218
- p[:search] = "name = \"sp1\""
219
- end.returns(index_response([{'id' => 1}]))
220
- api_expects(:hostgroups, :create) do |p|
221
- p['hostgroup']['puppet_ca_proxy_id'] == 1 &&
222
- p['hostgroup']['name'] == 'hg1'
223
- end
224
- run_cmd(%w(hostgroup create --name hg1 --puppet-ca-proxy sp1))
225
- end
226
-
227
- it 'allows puppet class ids' do
228
- api_expects(:hostgroups, :create) do |p|
229
- p['hostgroup']['puppetclass_ids'] == ['1','2'] &&
230
- p['hostgroup']['name'] == 'hg1'
231
- end
232
- run_cmd(%w(hostgroup create --name hg1 --puppet-class-ids 1,2))
233
- end
234
-
235
- it 'allows puppet class names' do
236
- api_expects(:puppetclasses, :index) do |p|
237
- p[:search] = "name = \"pc1\" or name = \"pc2\""
238
- end.returns(index_response('puppetclasses' => [
239
- {'id' => 1, 'name' => 'pc1'},
240
- {'id' => 2, 'name' => 'pc2'}
241
- ]))
242
- api_expects(:hostgroups, :create) do |p|
243
- p['hostgroup']['puppetclass_ids'] == [1,2] &&
244
- p['hostgroup']['name'] == 'hg1'
245
- end
246
- run_cmd(%w(hostgroup create --name hg1 --puppet-classes pc1,pc2))
247
- end
248
-
249
- it 'allows puppet class names that exceeds entries_per_page' do
250
- search_objects = []
251
- response_objects = []
252
- ids = []
253
- names = []
254
- 1100.times.with_object('pc').each do |id, name|
255
- next_name = "\"#{name}#{id}\""
256
- search_objects << "name = #{next_name}"
257
- response_objects << { 'id' => id, 'name' => next_name }
258
- ids << id
259
- names << next_name
260
- end
261
-
262
- api_expects(:puppetclasses, :index) do |p|
263
- p[:search] == search_objects.join(' or ') &&
264
- p[:page].to_i == 1 &&
265
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
266
- end.returns(
267
- index_response('puppetclasses' => response_objects[0...1000]))
268
-
269
- api_expects(:puppetclasses, :index) do |p|
270
- p[:search] == search_objects.join(' or ') &&
271
- p[:page].to_i == 2 &&
272
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
273
- end.returns(index_response('puppetclasses' => response_objects[1000...1100]))
274
-
275
- api_expects(:hostgroups, :create) do |p|
276
- p['hostgroup']['name'] == 'hg1' &&
277
- p['hostgroup']['puppetclass_ids'] == ids
278
- end
279
-
280
- run_cmd(%w[hostgroup create --name hg1 --puppet-classes] << names.join(',').tr('"', ''))
281
- end
282
-
283
- it 'allows puppet proxy id' do
284
- api_expects(:hostgroups, :create).with_params({
285
- :hostgroup => {
286
- :name => 'hg1',
287
- :puppet_proxy_id => 1
288
- }
289
- })
290
- run_cmd(%w(hostgroup create --name hg1 --puppet-proxy-id 1))
291
- end
292
-
293
- it 'allows puppet proxy name' do
294
- api_expects(:smart_proxies, :index) do |p|
295
- p[:search] = "name = \"sp1\""
296
- end.returns(index_response([{'id' => 1}]))
297
- api_expects(:hostgroups, :create) do |p|
298
- p['hostgroup']['puppet_proxy_id'] == 1 &&
299
- p['hostgroup']['name'] == 'hg1'
300
- end
301
- run_cmd(%w(hostgroup create --name hg1 --puppet-proxy sp1))
302
- end
303
-
304
187
  it 'allows realm id' do
305
188
  api_expects(:hostgroups, :create) do |p|
306
189
  p['hostgroup']['realm_id'] == 1 &&