hammer_cli_katello 0.23.0 → 0.24.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +14 -2
  3. data/lib/hammer_cli_katello/content_export.rb +72 -0
  4. data/lib/hammer_cli_katello/content_export_complete.rb +25 -0
  5. data/lib/hammer_cli_katello/content_export_helper.rb +181 -0
  6. data/lib/hammer_cli_katello/content_export_incremental.rb +25 -0
  7. data/lib/hammer_cli_katello/content_import.rb +63 -0
  8. data/lib/hammer_cli_katello/content_view.rb +3 -1
  9. data/lib/hammer_cli_katello/host_traces.rb +17 -0
  10. data/lib/hammer_cli_katello/ping.rb +10 -3
  11. data/lib/hammer_cli_katello/repository.rb +59 -1
  12. data/lib/hammer_cli_katello/version.rb +1 -1
  13. data/test/data/3.18/foreman_api.json +1 -0
  14. data/test/functional/content_export/complete/library_test.rb +155 -0
  15. data/test/functional/content_export/complete/version_test.rb +217 -0
  16. data/test/functional/content_export/content_export_helpers.rb +26 -0
  17. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  18. data/test/functional/content_export/incremental/library_test.rb +172 -0
  19. data/test/functional/content_export/incremental/version_test.rb +268 -0
  20. data/test/functional/content_export/list_test.rb +34 -0
  21. data/test/functional/content_import/library_test.rb +85 -0
  22. data/test/functional/content_import/metadata.json +1 -0
  23. data/test/functional/content_import/version_test.rb +85 -0
  24. data/test/functional/content_view/content_view_helpers.rb +3 -1
  25. data/test/functional/host/extensions/update_test.rb +0 -1
  26. data/test/functional/host/traces/resolve_test.rb +31 -0
  27. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +1 -1
  28. data/test/functional/ping_test.rb +2 -1
  29. data/test/functional/repository/update_test.rb +41 -1
  30. data/test/functional/search_helpers.rb +11 -0
  31. data/test/test_helper.rb +1 -1
  32. metadata +32 -3
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_export'
3
+
4
+ describe 'content-export list' do
5
+ let(:empty_response) do
6
+ {
7
+ "total" => 0,
8
+ "subtotal" => 0,
9
+ "page" => "1",
10
+ "per_page" => "1000",
11
+ "error" => nil,
12
+ "search" => nil,
13
+ "sort" => {
14
+ "by" => nil,
15
+ "order" => nil
16
+ },
17
+ "results" => []
18
+ }
19
+ end
20
+
21
+ it 'allows minimal options' do
22
+ ex = api_expects(:content_exports, :index)
23
+
24
+ ex.returns(empty_response)
25
+ # rubocop:disable LineLength
26
+ expected_result = success_result('---|--------------------|------|----------------------|-------------------------|------------|-----------
27
+ ID | DESTINATION SERVER | PATH | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
28
+ ---|--------------------|------|----------------------|-------------------------|------------|-----------
29
+ ')
30
+ # rubocop:enable LineLength
31
+ result = run_cmd(%w(content-export list))
32
+ assert_cmd(expected_result, result)
33
+ end
34
+ end
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import library' do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-import library)
9
+ end
10
+
11
+ let(:task_id) { '5' }
12
+
13
+ let(:response) do
14
+ {
15
+ 'id' => task_id,
16
+ 'state' => 'planned'
17
+ }
18
+ end
19
+
20
+ let(:path) do
21
+ File.dirname(__FILE__)
22
+ end
23
+
24
+ let(:metadata) do
25
+ JSON.parse(File.read("#{path}/metadata.json"))
26
+ end
27
+
28
+ let(:organization_id) { 3 }
29
+
30
+ it "performs import with required options and async" do
31
+ params = [
32
+ "--organization-id=#{organization_id}",
33
+ "--path=#{path}",
34
+ '--async'
35
+ ]
36
+ api_expects(:content_imports, :library)
37
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
38
+ .returns(response)
39
+
40
+ result = run_cmd(@cmd + params)
41
+
42
+ assert_equal("Archive is being imported in task #{task_id}.\n", result.out)
43
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
44
+ end
45
+
46
+ it "performs import with required options" do
47
+ params = [
48
+ "--organization-id=#{organization_id}",
49
+ "--path=#{path}"
50
+ ]
51
+
52
+ api_expects(:content_imports, :library)
53
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
54
+ .returns(response)
55
+
56
+ expect_foreman_task(task_id)
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
60
+ end
61
+
62
+ it 'fails on missing required params' do
63
+ params = [
64
+ '--id=2'
65
+ ]
66
+
67
+ result = run_cmd(@cmd + params)
68
+ expected_error = "Could not import the archive."
69
+
70
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
71
+ assert_equal(result.err[/#{expected_error}/], expected_error)
72
+ end
73
+
74
+ it 'fails on missing metadata.json' do
75
+ bad_path = "/nosuchdir"
76
+ params = [
77
+ "--organization-id=#{organization_id}",
78
+ "--path=#{bad_path}"
79
+ ]
80
+ result = run_cmd(@cmd + params)
81
+ expected_error = "Unable to find '#{bad_path}/metadata.json'."
82
+
83
+ assert_match(/#{expected_error}/, result.err)
84
+ end
85
+ end
@@ -0,0 +1 @@
1
+ {"organization":"export-9697","repository_mapping":{"katello-15062":{"repository":"katello","product":"prod","redhat":false},"misc-28137":{"repository":"misc","product":"prod","redhat":false},"candlepin-37918":{"repository":"candlepin","product":"prod","redhat":false}},"content_view":"view","content_view_version":{"major":1,"minor":0},"incremental":false,"toc":"export-24d91ced-3d11-4fa2-b5ea-19a41f7b97a5-20201118_1523-toc.json"}
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import version' do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-import version)
9
+ end
10
+
11
+ let(:task_id) { '5' }
12
+
13
+ let(:response) do
14
+ {
15
+ 'id' => task_id,
16
+ 'state' => 'planned'
17
+ }
18
+ end
19
+
20
+ let(:path) do
21
+ File.dirname(__FILE__)
22
+ end
23
+
24
+ let(:metadata) do
25
+ JSON.parse(File.read("#{path}/metadata.json"))
26
+ end
27
+
28
+ let(:content_view_id) { 3 }
29
+
30
+ it "performs import with required options and async" do
31
+ params = [
32
+ "--content-view-id=#{content_view_id}",
33
+ "--path=#{path}",
34
+ '--async'
35
+ ]
36
+ api_expects(:content_imports, :version)
37
+ .with_params('content_view_id' => content_view_id, 'path' => path, 'metadata' => metadata)
38
+ .returns(response)
39
+
40
+ result = run_cmd(@cmd + params)
41
+
42
+ assert_equal("Archive is being imported in task #{task_id}.\n", result.out)
43
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
44
+ end
45
+
46
+ it "performs import with required options" do
47
+ params = [
48
+ "--content-view-id=#{content_view_id}",
49
+ "--path=#{path}"
50
+ ]
51
+
52
+ api_expects(:content_imports, :version)
53
+ .with_params('content_view_id' => content_view_id, 'path' => path, 'metadata' => metadata)
54
+ .returns(response)
55
+
56
+ expect_foreman_task(task_id)
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
60
+ end
61
+
62
+ it 'fails on missing required params' do
63
+ params = [
64
+ '--id=2'
65
+ ]
66
+
67
+ result = run_cmd(@cmd + params)
68
+ expected_error = "Could not import the archive."
69
+
70
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
71
+ assert_equal(result.err[/#{expected_error}/], expected_error)
72
+ end
73
+
74
+ it 'fails on missing metadata.json' do
75
+ bad_path = "/nosuchdir"
76
+ params = [
77
+ "--content-view-id=#{content_view_id}",
78
+ "--path=#{bad_path}"
79
+ ]
80
+ result = run_cmd(@cmd + params)
81
+ expected_error = "Unable to find '#{bad_path}/metadata.json'."
82
+
83
+ assert_match(/#{expected_error}/, result.err)
84
+ end
85
+ end
@@ -13,6 +13,8 @@ module ContentViewHelpers
13
13
  end
14
14
 
15
15
  def expect_content_view_version_search(params, returns)
16
- expect_generic_search(:content_view_versions, params: params, returns: returns)
16
+ expect_lenient_search(:content_view_versions,
17
+ params: params,
18
+ returns: returns)
17
19
  end
18
20
  end
@@ -29,7 +29,6 @@ module HammerCLIForeman
29
29
  with_params('id' => host_id.to_s,
30
30
  'organization_id' => organization_id,
31
31
  'host' => {
32
- 'compute_attributes' => {},
33
32
  'content_facet_attributes' => {
34
33
  'content_view_id' => cv_id,
35
34
  'lifecycle_environment_id' => env_id,
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+
3
+ describe 'host trace resolve' do
4
+ include ForemanTaskHelpers
5
+
6
+ before do
7
+ @cmd = %w(host traces resolve)
8
+ end
9
+
10
+ let(:host_id) { '2' }
11
+ let(:task_id) { '5' }
12
+ let(:response) do
13
+ {
14
+ 'id' => task_id,
15
+ 'state' => 'stopped'
16
+ }
17
+ end
18
+
19
+ it "resolves traces on a host" do
20
+ trace_ids = [3]
21
+ params = ["--host-id=#{host_id}", "--trace-ids=#{trace_ids}"]
22
+
23
+ ex = api_expects(:host_tracer, :resolve)
24
+
25
+ ex.returns(response)
26
+
27
+ expect_foreman_task(task_id)
28
+
29
+ run_cmd(@cmd + params)
30
+ end
31
+ end
@@ -4,7 +4,7 @@ module LifecycleEnvironmentHelpers
4
4
  include SearchHelpers
5
5
 
6
6
  def expect_lifecycle_environment_search(org_id, name, id)
7
- expect_generic_search(:lifecycle_environments,
7
+ expect_lenient_search(:lifecycle_environments,
8
8
  params: {'name' => name, 'organization_id' => org_id},
9
9
  returns: {'id' => id})
10
10
  end
@@ -12,7 +12,8 @@ describe 'ping' do
12
12
  'candlepin_auth' => {'status' => 'ok', 'duration_ms' => '34'},
13
13
  'katello_events' => {'status' => 'ok', 'message' => '0 messages', 'duration_ms' => '34'},
14
14
  'pulp' => {'status' => 'ok', 'duration_ms' => '34'},
15
- 'pulp_auth' => {'status' => 'ok', 'duration_ms' => '34'}
15
+ 'pulp_auth' => {'status' => 'ok', 'duration_ms' => '34'},
16
+ 'pulp3' => {'status' => 'ok', 'duration_ms' => '34'}
16
17
  }
17
18
  )
18
19
 
@@ -2,7 +2,7 @@ require_relative '../test_helper'
2
2
  require_relative '../organization/organization_helpers'
3
3
  require 'hammer_cli_katello/repository'
4
4
 
5
- module HammerCLIKatello
5
+ module HammerCLIKatello # rubocop:disable Metrics/ModuleLength
6
6
  describe Repository::UpdateCommand do
7
7
  include OrganizationHelpers
8
8
 
@@ -14,6 +14,46 @@ module HammerCLIKatello
14
14
  run_cmd(%w(repository update --id 1 --new-name rep1))
15
15
  end
16
16
 
17
+ describe 'tags docker images' do
18
+ let(:repo_id) { 3 }
19
+ let(:tag_name) { "latest" }
20
+ let(:digest) { "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }
21
+ let(:upload_id) { "1234" }
22
+ let(:_href) { "/pulp/api/v2/content/uploads/#{upload_id}" }
23
+ let(:upload_response) do
24
+ {
25
+ "upload_id" => upload_id,
26
+ "_href" => _href
27
+ }
28
+ end
29
+ it "adds a tag to an image" do
30
+ ex = api_expects(:content_uploads, :create)
31
+ .with_params('repository_id' => repo_id, :size => 0)
32
+
33
+ ex.returns(upload_response)
34
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
35
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true,
36
+ :uploads => [{
37
+ :id => '1234',
38
+ :name => tag_name,
39
+ :digest => digest
40
+ }],
41
+ :content_type => "docker_tag"
42
+ )
43
+
44
+ ex2.returns("")
45
+
46
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
47
+ .with_params('id' => upload_id, 'repository_id' => repo_id)
48
+
49
+ ex3.returns("")
50
+ # rubocop:disable LineLength
51
+ result = run_cmd(%W(repository update --id #{repo_id} --docker-tag #{tag_name} --docker-digest #{digest}))
52
+ # rubocop:enable LineLength
53
+ assert_equal(result.exit_code, 0)
54
+ end
55
+ end
56
+
17
57
  describe 'resolves repository ID' do
18
58
  it 'by requiring product' do
19
59
  api_expects_no_call
@@ -3,4 +3,15 @@ module SearchHelpers
3
3
  ex = api_expects(resource, :index, "Find the #{resource}").with_params(args[:params])
4
4
  ex.returns(index_response([args[:returns]]))
5
5
  end
6
+
7
+ def expect_lenient_search(resource, params:, returns:)
8
+ ex = api_expects(resource, :index, "Find the #{resource}") do |p|
9
+ params.each do |key, expected|
10
+ actual = p[key] || p[key.to_sym] || p[key.to_s]
11
+ assert_equal expected.to_s, actual.to_s, "key: '#{key}', resource: #{resource}"
12
+ end
13
+ end
14
+ returns = [returns] unless returns.is_a? Array
15
+ ex.returns(index_response(returns))
16
+ end
6
17
  end
@@ -17,7 +17,7 @@ require 'minitest/spec'
17
17
  require 'mocha/minitest'
18
18
  require 'hammer_cli'
19
19
 
20
- KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '3.17')
20
+ KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '3.18')
21
21
 
22
22
  if HammerCLI.context[:api_connection]
23
23
  HammerCLI.context[:api_connection].create('foreman') do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_katello
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.24.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Price
@@ -35,7 +35,7 @@ authors:
35
35
  autorequire:
36
36
  bindir: bin
37
37
  cert_chain: []
38
- date: 2020-09-02 00:00:00.000000000 Z
38
+ date: 2021-01-05 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: hammer_cli_foreman
@@ -240,6 +240,11 @@ files:
240
240
  - lib/hammer_cli_katello/commands.rb
241
241
  - lib/hammer_cli_katello/composite_content_view_name_resolvable.rb
242
242
  - lib/hammer_cli_katello/content_credential.rb
243
+ - lib/hammer_cli_katello/content_export.rb
244
+ - lib/hammer_cli_katello/content_export_complete.rb
245
+ - lib/hammer_cli_katello/content_export_helper.rb
246
+ - lib/hammer_cli_katello/content_export_incremental.rb
247
+ - lib/hammer_cli_katello/content_import.rb
243
248
  - lib/hammer_cli_katello/content_override.rb
244
249
  - lib/hammer_cli_katello/content_view.rb
245
250
  - lib/hammer_cli_katello/content_view_component.rb
@@ -329,6 +334,7 @@ files:
329
334
  - test/data/3.15/foreman_api.json
330
335
  - test/data/3.16/foreman_api.json
331
336
  - test/data/3.17/foreman_api.json
337
+ - test/data/3.18/foreman_api.json
332
338
  - test/data/3.2/foreman_api.json
333
339
  - test/data/3.4/foreman_api.json
334
340
  - test/data/3.5/foreman_api.json
@@ -363,6 +369,16 @@ files:
363
369
  - test/functional/capsule/list_test.rb
364
370
  - test/functional/content_credentials/info_test.rb
365
371
  - test/functional/content_credentials/list_test.rb
372
+ - test/functional/content_export/complete/library_test.rb
373
+ - test/functional/content_export/complete/version_test.rb
374
+ - test/functional/content_export/content_export_helpers.rb
375
+ - test/functional/content_export/generate_metadata_test.rb
376
+ - test/functional/content_export/incremental/library_test.rb
377
+ - test/functional/content_export/incremental/version_test.rb
378
+ - test/functional/content_export/list_test.rb
379
+ - test/functional/content_import/library_test.rb
380
+ - test/functional/content_import/metadata.json
381
+ - test/functional/content_import/version_test.rb
366
382
  - test/functional/content_view/add_content_view_version_test.rb
367
383
  - test/functional/content_view/add_repository_test.rb
368
384
  - test/functional/content_view/component/add_test.rb
@@ -426,6 +442,7 @@ files:
426
442
  - test/functional/host/subscription/remove_test.rb
427
443
  - test/functional/host/subscription/unregister_test.rb
428
444
  - test/functional/host/traces/list_test.rb
445
+ - test/functional/host/traces/resolve_test.rb
429
446
  - test/functional/host_collection/add_host_test.rb
430
447
  - test/functional/host_collection/content_api_expectations.rb
431
448
  - test/functional/host_collection/content_install_test.rb
@@ -518,7 +535,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
518
535
  - !ruby/object:Gem::Version
519
536
  version: '0'
520
537
  requirements: []
521
- rubygems_version: 3.0.8
538
+ rubygems_version: 3.1.4
522
539
  signing_key:
523
540
  specification_version: 4
524
541
  summary: Katello commands for Hammer
@@ -533,6 +550,7 @@ test_files:
533
550
  - test/data/3.15/foreman_api.json
534
551
  - test/data/3.16/foreman_api.json
535
552
  - test/data/3.17/foreman_api.json
553
+ - test/data/3.18/foreman_api.json
536
554
  - test/data/3.2/foreman_api.json
537
555
  - test/data/3.4/foreman_api.json
538
556
  - test/data/3.5/foreman_api.json
@@ -567,6 +585,16 @@ test_files:
567
585
  - test/functional/capsule/list_test.rb
568
586
  - test/functional/content_credentials/info_test.rb
569
587
  - test/functional/content_credentials/list_test.rb
588
+ - test/functional/content_export/complete/library_test.rb
589
+ - test/functional/content_export/complete/version_test.rb
590
+ - test/functional/content_export/content_export_helpers.rb
591
+ - test/functional/content_export/generate_metadata_test.rb
592
+ - test/functional/content_export/incremental/library_test.rb
593
+ - test/functional/content_export/incremental/version_test.rb
594
+ - test/functional/content_export/list_test.rb
595
+ - test/functional/content_import/library_test.rb
596
+ - test/functional/content_import/metadata.json
597
+ - test/functional/content_import/version_test.rb
570
598
  - test/functional/content_view/add_content_view_version_test.rb
571
599
  - test/functional/content_view/add_repository_test.rb
572
600
  - test/functional/content_view/component/add_test.rb
@@ -630,6 +658,7 @@ test_files:
630
658
  - test/functional/host/subscription/remove_test.rb
631
659
  - test/functional/host/subscription/unregister_test.rb
632
660
  - test/functional/host/traces/list_test.rb
661
+ - test/functional/host/traces/resolve_test.rb
633
662
  - test/functional/host_collection/add_host_test.rb
634
663
  - test/functional/host_collection/content_api_expectations.rb
635
664
  - test/functional/host_collection/content_install_test.rb