hammer_cli_katello 0.3.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +0 -1
  3. data/lib/hammer_cli_katello/activation_key.rb +12 -29
  4. data/lib/hammer_cli_katello/composite_content_view_name_resolvable.rb +6 -8
  5. data/lib/hammer_cli_katello/content_override.rb +48 -0
  6. data/lib/hammer_cli_katello/content_view.rb +98 -5
  7. data/lib/hammer_cli_katello/content_view_name_resolvable.rb +4 -6
  8. data/lib/hammer_cli_katello/content_view_purge.rb +92 -0
  9. data/lib/hammer_cli_katello/content_view_version.rb +13 -0
  10. data/lib/hammer_cli_katello/erratum.rb +9 -0
  11. data/lib/hammer_cli_katello/filter_rule.rb +3 -4
  12. data/lib/hammer_cli_katello/host_collection.rb +8 -2
  13. data/lib/hammer_cli_katello/host_errata.rb +1 -1
  14. data/lib/hammer_cli_katello/host_subscription.rb +25 -0
  15. data/lib/hammer_cli_katello/hostgroup_extensions.rb +7 -6
  16. data/lib/hammer_cli_katello/id_resolver.rb +13 -4
  17. data/lib/hammer_cli_katello/katello_environment_name_resolvable.rb +4 -6
  18. data/lib/hammer_cli_katello/lifecycle_environment_name_resolvable.rb +4 -6
  19. data/lib/hammer_cli_katello/organization.rb +1 -0
  20. data/lib/hammer_cli_katello/package.rb +16 -3
  21. data/lib/hammer_cli_katello/package_group.rb +16 -2
  22. data/lib/hammer_cli_katello/product_content.rb +36 -0
  23. data/lib/hammer_cli_katello/repository.rb +48 -7
  24. data/lib/hammer_cli_katello/version.rb +1 -1
  25. data/test/data/3.4/foreman_api.json +1 -0
  26. data/test/functional/{activaton_key → activation_key}/add_host_collection_test.rb +0 -0
  27. data/test/functional/activation_key/content_override_test.rb +91 -0
  28. data/test/functional/{activaton_key → activation_key}/create_test.rb +0 -0
  29. data/test/functional/{activaton_key → activation_key}/list_test.rb +0 -0
  30. data/test/functional/{activaton_key → activation_key}/product_content_test.rb +0 -0
  31. data/test/functional/{activaton_key → activation_key}/remove_host_collection_test.rb +0 -0
  32. data/test/functional/{activaton_key → activation_key}/subscriptions_test.rb +0 -0
  33. data/test/functional/{activaton_key → activation_key}/update_test.rb +0 -0
  34. data/test/functional/content_view/add_content_view_version_test.rb +57 -3
  35. data/test/functional/content_view/add_repository_test.rb +1 -0
  36. data/test/functional/content_view/copy_test.rb +53 -0
  37. data/test/functional/content_view/delete_test.rb +62 -0
  38. data/test/functional/content_view/publish_test.rb +1 -0
  39. data/test/functional/content_view/puppet_module/add_test.rb +1 -0
  40. data/test/functional/content_view/purge_test.rb +72 -0
  41. data/test/functional/content_view/remove_content_view_version_test.rb +57 -3
  42. data/test/functional/content_view/remove_test.rb +78 -0
  43. data/test/functional/content_view/update_test.rb +53 -0
  44. data/test/functional/content_view/version/republish_repositories_test.rb +35 -0
  45. data/test/functional/erratum/list_test.rb +108 -0
  46. data/test/functional/host/subscription/content_override_test.rb +95 -0
  47. data/test/functional/host/subscription/product_content_test.rb +27 -0
  48. data/test/functional/host_collection/content_api_expectations.rb +35 -0
  49. data/test/functional/host_collection/content_install_test.rb +42 -17
  50. data/test/functional/host_collection/content_remove_test.rb +22 -12
  51. data/test/functional/host_collection/content_update_test.rb +22 -12
  52. data/test/functional/hostgroup/create_test.rb +6 -0
  53. data/test/functional/hostgroup/data/hostgroup.json +2 -2
  54. data/test/functional/hostgroup/info_test.rb +2 -1
  55. data/test/functional/hostgroup/update_test.rb +12 -0
  56. data/test/functional/package/list_test.rb +89 -18
  57. data/test/functional/package_group/list_test.rb +33 -0
  58. data/test/functional/repository/export_test.rb +121 -0
  59. data/test/functional/repository/remove_content_test.rb +98 -8
  60. data/test/functional/repository/update_test.rb +108 -0
  61. data/test/functional/repository/upload_test.rb +73 -3
  62. data/test/test_helper.rb +1 -1
  63. data/test/unit/id_resolver_test.rb +26 -0
  64. metadata +54 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2935135ce7a735329312a4941a262cf9dfd4d0ce
4
- data.tar.gz: 22c93056f82485f36df800e2d7654be414d8de02
3
+ metadata.gz: b724181082827487def5bd163bd3ede79f92d898
4
+ data.tar.gz: c479307f8e19564413bb8e0b29da2582e98b4625
5
5
  SHA512:
6
- metadata.gz: ea5a8007be9c13b7b891fe6618982ce6012ed69b8645cd88c17efdce82a7cb66f313247c9057133620327e0af3549fa810094aeafe5aa942922e85609ea2ebb9
7
- data.tar.gz: cba3aa8b3fe0bf3cfaf65b39791601d513c4f3115fb7cc8965c4ccc79ce009fcbc259772f030df5e5a35ed93fdf398ad78545965e07a0f830320da308bc1c110
6
+ metadata.gz: 6ff728a57e711d064752fc75f721fc283634f4cb0cc50df4b80813e9d01b11099c6654ab3b9c440610511023c49892c6fb1dbfff04e9dbf41bb318ece1978efa
7
+ data.tar.gz: 99dc2f0ba6c14a6e1cf1388d6b4c9f7712b2db6089f3295e24bc196efa7d60657e276a62ace84d15b5f2630d6a3205d30a94dacf83d2d2e75d5cce45336086b8
@@ -23,7 +23,6 @@ module HammerCLIKatello
23
23
  require "hammer_cli_katello/version"
24
24
  require "hammer_cli_katello/exception_handler"
25
25
  require 'hammer_cli_katello/i18n'
26
- require "hammer_cli_katello/version"
27
26
  require 'hammer_cli_katello/id_resolver'
28
27
  require 'hammer_cli_katello/capsule'
29
28
  require 'hammer_cli_katello/id_name_options_validator'
@@ -1,3 +1,6 @@
1
+ require 'hammer_cli_katello/content_override'
2
+ require 'hammer_cli_katello/product_content'
3
+
1
4
  module HammerCLIKatello
2
5
  class ActivationKeyCommand < HammerCLIKatello::Command
3
6
  resource :activation_keys
@@ -191,38 +194,18 @@ module HammerCLIKatello
191
194
  failure_message _("Could not remove subscription from activation key")
192
195
  end
193
196
 
194
- class ProductContentCommand < HammerCLIKatello::ListCommand
195
- action :product_content
196
-
197
- desc _("List associated products")
198
- command_name "product-content"
199
-
200
- output do
201
- from :content do
202
- field :id, _("ID")
203
- field :name, _("Name")
204
- field :type, _("Type")
205
- field :contentUrl, _("URL")
206
- field :gpgUrl, _("GPG Key")
207
- field :label, _("Label")
208
- end
209
- field :enabled, _("Enabled?"), Fields::Boolean
210
- field :override, _("Override")
211
- end
212
-
213
- build_options
197
+ class ProductContentCommand < HammerCLIKatello::ProductContentBase::ProductContentCommand
198
+ resource :activation_keys, :product_content
199
+ setup
214
200
  end
215
201
 
216
- class ContentOverrideCommand < HammerCLIKatello::SingleResourceCommand
217
- action :content_override
202
+ class ContentOverrideCommand < ::HammerCLIKatello::ContentOverrideBase::ContentOverrideCommand
203
+ resource :activation_keys, :content_override
204
+ setup
218
205
 
219
- desc _("Override product content defaults")
220
- command_name "content-override"
221
-
222
- build_options
223
-
224
- success_message _("Updated content override")
225
- failure_message _("Could not update content override")
206
+ build_options do |o|
207
+ o.without(:content_overrides)
208
+ end
226
209
  end
227
210
 
228
211
  class HostCollectionsCommand < HammerCLIKatello::ListCommand
@@ -10,15 +10,13 @@ module HammerCLIKatello
10
10
  }
11
11
  end
12
12
 
13
- def all_options
14
- result = super.clone
15
- if result['option_composite_content_view_name'] &&
16
- result['option_composite_content_view_id'].nil?
17
- options = composite_content_view_resolve_options(result)
18
- result['option_composite_content_view_id'] = resolver.content_view_id(options)
19
- @all_options = result
13
+ def options
14
+ if super['option_composite_content_view_name'] &&
15
+ super['option_composite_content_view_id'].nil?
16
+ options = composite_content_view_resolve_options(super)
17
+ super['option_composite_content_view_id'] = resolver.content_view_id(options)
20
18
  end
21
- result
19
+ super
22
20
  end
23
21
 
24
22
  def self.included(base)
@@ -0,0 +1,48 @@
1
+ module HammerCLIKatello
2
+ module ContentOverrideBase
3
+ class ContentOverrideCommand < HammerCLIKatello::SingleResourceCommand
4
+ def self.setup
5
+ desc _("Override product content defaults")
6
+ command_name "content-override"
7
+
8
+ success_message _("Updated content override")
9
+ failure_message _("Could not update content override")
10
+
11
+ option "--content-label", "CONTENT_LABEL", _("Label of the content"),
12
+ :attribute_name => :option_content_label, :required => true
13
+
14
+ option "--name", "NAME", _("Name/Key to override. " \
15
+ "To enable or disable a repo select 'enabled'." \
16
+ "Default value: enabled"),
17
+ :attribute_name => :option_name, :default => "enabled"
18
+
19
+ option "--value", "VALUE", _("Override value. " \
20
+ "Note for repo enablement you can use a boolean value"),
21
+ :attribute_name => :option_value, :required => false
22
+
23
+ option ["--remove"], :flag, _("Remove a content override")
24
+
25
+ validate_options do
26
+ any(:option_remove, :option_value).required
27
+
28
+ if option(:option_remove).exist?
29
+ option(:option_value).rejected
30
+ elsif option(:option_value).exist?
31
+ option(:option_remove).rejected
32
+ end
33
+ end
34
+ end
35
+
36
+ def request_params
37
+ super.tap do |opts|
38
+ opts.delete('content_override')
39
+ override = { 'content_label' => option_content_label }
40
+ override['value'] = option_value if option_value
41
+ override['remove'] = true if option_remove?
42
+ override['name'] = option_name
43
+ opts['content_overrides'] = [override]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,4 +1,5 @@
1
1
  require 'hammer_cli_katello/content_view_puppet_module'
2
+ require 'hammer_cli_katello/content_view_purge'
2
3
  require 'hammer_cli_katello/filter'
3
4
  require 'hammer_cli_katello/content_view_version'
4
5
  require 'hammer_cli_katello/content_view_component'
@@ -125,12 +126,32 @@ module HammerCLIKatello
125
126
  end
126
127
 
127
128
  class CopyCommand < HammerCLIKatello::CreateCommand
129
+ include OrganizationOptions
130
+
128
131
  action :copy
129
132
 
130
133
  desc _("Copy a content view")
131
134
  command_name "copy"
132
135
 
133
- option "--name", "NAME", _("New content view name"), :attribute_name => :option_name
136
+ option "--name", "NAME", _("Content view name to search by"), :attribute_name => :option_name
137
+ option "--new-name", "NEW_NAME", _("New content view name"),
138
+ :attribute_name => :option_new_name
139
+
140
+ validate_options do
141
+ organization_options = [:option_organization_id, :option_organization_name, \
142
+ :option_organization_label]
143
+
144
+ if option(:option_name).exist?
145
+ any(*organization_options).required
146
+ end
147
+ end
148
+
149
+ def request_params
150
+ super.tap do |opts|
151
+ opts['name'] = option_new_name
152
+ end
153
+ end
154
+
134
155
  build_options
135
156
 
136
157
  success_message _("Content view copied")
@@ -138,14 +159,26 @@ module HammerCLIKatello
138
159
  end
139
160
 
140
161
  class UpdateCommand < HammerCLIKatello::UpdateCommand
162
+ include OrganizationOptions
163
+
141
164
  success_message _("Content view updated")
142
165
  failure_message _("Could not update the content view")
143
166
 
167
+ validate_options do
168
+ organization_options = [:option_organization_id, :option_organization_name, \
169
+ :option_organization_label]
170
+
171
+ if option(:option_name).exist?
172
+ any(*organization_options).required
173
+ end
174
+ end
175
+
144
176
  build_options
145
177
  end
146
178
 
147
179
  class DeleteCommand < HammerCLIKatello::DeleteCommand
148
180
  include HammerCLIForemanTasks::Async
181
+ include OrganizationOptions
149
182
 
150
183
  action :destroy
151
184
  command_name "delete"
@@ -153,6 +186,15 @@ module HammerCLIKatello
153
186
  success_message _("Content view is being deleted with task %{id}")
154
187
  failure_message _("Could not delete the content view")
155
188
 
189
+ validate_options do
190
+ organization_options = [:option_organization_id, :option_organization_name, \
191
+ :option_organization_label]
192
+
193
+ if option(:option_name).exist?
194
+ any(*organization_options).required
195
+ end
196
+ end
197
+
156
198
  build_options
157
199
  end
158
200
 
@@ -197,10 +239,17 @@ module HammerCLIKatello
197
239
  option ["--environment-ids"], "ENVIRONMENT_IDS",
198
240
  _("Comma separated list of environment ids to remove")
199
241
 
242
+ def all_options
243
+ opts = super
244
+ opts['option_content_view_id'] = option_id
245
+ opts['option_lifecycle_environment_names'] = opts['option_environment_names']
246
+ opts
247
+ end
248
+
200
249
  def request_params
201
250
  super.tap do |opts|
202
251
  %w(content_view_version_ids environment_ids).each do |key|
203
- opts[key] = opts[key].split(",") if opts[key]
252
+ opts[key] = opts[key].split(",") if opts[key] && opts[key].respond_to?(:split)
204
253
  end
205
254
  end
206
255
  end
@@ -208,34 +257,74 @@ module HammerCLIKatello
208
257
  success_message _("Content view objects are being removed task %{id}")
209
258
  failure_message _("Could not remove objects from content view")
210
259
 
211
- build_options :without => %w(content_view_version_ids environment_ids)
260
+ build_options
212
261
  end
213
262
 
214
263
  class AddContentViewVersionCommand < HammerCLIKatello::AddAssociatedCommand
264
+ include OrganizationOptions
265
+
215
266
  command_name 'add-version'
216
267
  desc _('Add a content view version to a composite view')
217
268
 
269
+ validate_options do
270
+ if option(:option_content_view_version_version).exist?
271
+ any(:option_content_view_id, :option_content_view_name).required
272
+ end
273
+ end
274
+
218
275
  def association_name(plural = false)
219
276
  plural ? "components" : "component"
220
277
  end
221
278
 
279
+ validate_options do
280
+ organization_options = [:option_organization_id, :option_organization_name, \
281
+ :option_organization_label]
282
+
283
+ if option(:option_name).exist?
284
+ any(*organization_options).required
285
+ end
286
+ end
287
+
222
288
  associated_resource :content_view_versions
223
- build_options
289
+
290
+ build_options do |o|
291
+ o.expand.including(:content_views)
292
+ end
224
293
 
225
294
  success_message _("The component version has been added")
226
295
  failure_message _("Could not add version")
227
296
  end
228
297
 
229
298
  class RemoveContentViewVersionCommand < HammerCLIKatello::RemoveAssociatedCommand
299
+ include OrganizationOptions
300
+
230
301
  command_name 'remove-version'
231
302
  desc _('Remove a content view version from a composite view')
232
303
 
304
+ validate_options do
305
+ if option(:option_content_view_version_version).exist?
306
+ any(:option_content_view_id, :option_content_view_name).required
307
+ end
308
+ end
309
+
233
310
  def association_name(plural = false)
234
311
  plural ? "components" : "component"
235
312
  end
236
313
 
314
+ validate_options do
315
+ organization_options = [:option_organization_id, :option_organization_name, \
316
+ :option_organization_label]
317
+
318
+ if option(:option_name).exist?
319
+ any(*organization_options).required
320
+ end
321
+ end
322
+
237
323
  associated_resource :content_view_versions
238
- build_options
324
+
325
+ build_options do |o|
326
+ o.expand.including(:content_views)
327
+ end
239
328
 
240
329
  success_message _("The component version has been removed")
241
330
  failure_message _("Could not remove version")
@@ -260,5 +349,9 @@ module HammerCLIKatello
260
349
  subcommand HammerCLIKatello::ContentViewComponent.command_name,
261
350
  HammerCLIKatello::ContentViewComponent.desc,
262
351
  HammerCLIKatello::ContentViewComponent
352
+
353
+ subcommand HammerCLIKatello::ContentViewPurgeCommand.command_name,
354
+ HammerCLIKatello::ContentViewPurgeCommand.desc,
355
+ HammerCLIKatello::ContentViewPurgeCommand
263
356
  end
264
357
  end
@@ -9,13 +9,11 @@ module HammerCLIKatello
9
9
  end
10
10
 
11
11
  def all_options
12
- result = super.clone
13
- if result['option_content_view_name'] && result['option_content_view_id'].nil?
14
- result['option_content_view_id'] = resolver.content_view_id(
15
- content_view_resolve_options(result))
16
- @all_options = result
12
+ if super['option_content_view_name'] && super['option_content_view_id'].nil?
13
+ super['option_content_view_id'] = resolver.content_view_id(
14
+ content_view_resolve_options(super))
17
15
  end
18
- result
16
+ super
19
17
  end
20
18
  end
21
19
  end
@@ -0,0 +1,92 @@
1
+ module HammerCLIKatello
2
+ class ContentViewPurgeCommand < HammerCLIKatello::Command
3
+ include HammerCLIForemanTasks::Async
4
+ include OrganizationOptions
5
+
6
+ command_name "purge"
7
+ desc "Delete old versions of a content view"
8
+
9
+ option "--id", "ID", _("Content View numeric identifier")
10
+ option "--name", "NAME", _("Content View name")
11
+ option "--count", "COUNT", _("count of unused versions to keep"),
12
+ default: 3, format: HammerCLI::Options::Normalizers::Number.new
13
+
14
+ validate_options do
15
+ organization_options = [:option_organization_id, :option_organization_name, \
16
+ :option_organization_label]
17
+
18
+ any(:option_name, :option_id).required
19
+
20
+ if option(:option_name).exist?
21
+ any(*organization_options).required
22
+ end
23
+ end
24
+
25
+ build_options
26
+
27
+ def resource_content_views
28
+ HammerCLIForeman.foreman_resource(:content_views)
29
+ end
30
+
31
+ def resource_content_view_versions
32
+ HammerCLIForeman.foreman_resource(:content_view_versions)
33
+ end
34
+
35
+ def all_options
36
+ if super['option_id'].nil? && super['option_name']
37
+ super['option_id'] = resolver.content_view_id(super)
38
+ end
39
+ super
40
+ end
41
+
42
+ def execute
43
+ if option_count < 0
44
+ output.print_error _("Invalid value for --count option: value must be 0 or greater.")
45
+ return HammerCLI::EX_USAGE
46
+ end
47
+
48
+ # Check if there is something to do
49
+ if option_count >= old_unused_versions.size
50
+ output.print_error _("No versions to delete.")
51
+ HammerCLI::EX_NOT_FOUND
52
+ else
53
+ versions_to_purge = old_unused_versions.slice(0, old_unused_versions.size - option_count)
54
+
55
+ versions_to_purge.each do |v|
56
+ purge_version(v)
57
+ end
58
+ HammerCLI::EX_OK
59
+ end
60
+ end
61
+
62
+ private def purge_version(v)
63
+ if option_async?
64
+ task = resource_content_view_versions.call(:destroy, 'id' => v["id"])
65
+ print_message _("Version '%{version}' of content view '%{view}' scheduled "\
66
+ "for deletion in task '%{task_id}'.") %
67
+ {version: v["version"], view: content_view["name"], task_id: task['id']}
68
+ else
69
+ task_progress(resource_content_view_versions.call(:destroy, 'id' => v["id"]))
70
+ print_message _("Version '%{version}' of content view '%{view}' deleted.") %
71
+ {version: v["version"], view: content_view["name"]}
72
+ end
73
+ end
74
+
75
+ private def content_view
76
+ @content_view ||= resource_content_views.call(:show, 'id' => options['option_id'])
77
+ end
78
+
79
+ private def old_unused_versions
80
+ return @old_unused_versions if @old_unused_versions
81
+
82
+ all_versions = content_view['versions'].sort_by do |version|
83
+ [version[:major], version[:minor]]
84
+ end
85
+
86
+ # Keep only versions which are not used
87
+ @old_unused_versions = all_versions.select do |v|
88
+ v["environment_ids"].empty?
89
+ end
90
+ end
91
+ end
92
+ end
@@ -62,6 +62,19 @@ module HammerCLIKatello
62
62
  end
63
63
  end
64
64
 
65
+ class RepublishRepositoriesCommand < HammerCLIKatello::SingleResourceCommand
66
+ include HammerCLIForemanTasks::Async
67
+
68
+ action :republish_repositories
69
+ command_name "republish-repositories"
70
+
71
+ success_message _("Content View Version is being republished with task %{id}")
72
+ failure_message _("Could not republish the Content View")
73
+ build_options do |o|
74
+ o.expand(:all).including(:content_views, :organizations)
75
+ end
76
+ end
77
+
65
78
  class PromoteCommand < HammerCLIKatello::SingleResourceCommand
66
79
  include HammerCLIForemanTasks::Async
67
80