hammer_cli_katello 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/hammer_cli_katello/content_export.rb +39 -0
- data/lib/hammer_cli_katello/content_export_helper.rb +64 -6
- data/lib/hammer_cli_katello/version.rb +1 -1
- data/test/data/4.5/foreman_api.json +1 -1
- data/test/functional/content_export/complete/version_test.rb +48 -3
- data/test/functional/content_export/generate_listing_test.rb +62 -0
- data/test/test_helper.rb +1 -1
- metadata +25 -26
- data/test/data/4.6/foreman_api.json +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3d5ff0a9eec365ed64127733829a53befcdef1dc9a6bdeff5d98f986c988170c
|
4
|
+
data.tar.gz: 150fa12bf6481c901ba50f1b1548a1999d05204bd2049a454eb6e8962a2b5692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03f7a6238d527555bd4e228eb8779823f3040a3bfcae3302a614e1f4c574a27365f785992f9f92f1117932d3c25b4f68de8181fff7f2e2179379328363f87d64
|
7
|
+
data.tar.gz: 17fea0c7d58536e7ae2785acb79b04e381d6346ec710c3672315df214388f31e2f43a1005a8e67cc6335253f73910dd0dee15361825d82bf7d65b45b4434804a
|
@@ -44,6 +44,45 @@ module HammerCLIKatello
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
class GenerateListingCommand < HammerCLIKatello::Command
|
48
|
+
desc _("Generates listing file on each directory of a syncable export. This command "\
|
49
|
+
+ "only needs to be used if the export was performed asynchronously or "\
|
50
|
+
+ "if the listing files were lost. "\
|
51
|
+
+ "Assumes the syncable export directory is accessible on disk")
|
52
|
+
|
53
|
+
command_name 'generate-listing'
|
54
|
+
|
55
|
+
include ContentExportHelper
|
56
|
+
|
57
|
+
option "--task-id", "TASK_ID",
|
58
|
+
_("Generate listing files for a syncable export task"),
|
59
|
+
:attribute_name => :option_task_id,
|
60
|
+
:required => false
|
61
|
+
|
62
|
+
option "--id", "ID",
|
63
|
+
_("Generate listing files based on specified export history"),
|
64
|
+
:attribute_name => :option_export_id,
|
65
|
+
:required => false
|
66
|
+
|
67
|
+
def execute
|
68
|
+
export_history = if option_task_id
|
69
|
+
export_task = reload_task(option_task_id)
|
70
|
+
fetch_export_history_from_task(export_task)
|
71
|
+
else
|
72
|
+
fetch_export_history(option_export_id)
|
73
|
+
end
|
74
|
+
|
75
|
+
unless export_history
|
76
|
+
raise _("No export history was found. Verify the value given for "\
|
77
|
+
+ "--task-id or --id")
|
78
|
+
end
|
79
|
+
|
80
|
+
make_listing_files(export_history)
|
81
|
+
|
82
|
+
HammerCLI::EX_OK
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
47
86
|
class ListCommand < HammerCLIKatello::ListCommand
|
48
87
|
desc "View content view export histories"
|
49
88
|
output do
|
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'hammer_cli_katello/repository'
|
2
|
-
|
2
|
+
require 'find'
|
3
3
|
# rubocop:disable ModuleLength
|
4
4
|
module HammerCLIKatello
|
5
5
|
module ContentExportHelper
|
6
6
|
include ApipieHelper
|
7
|
-
|
8
7
|
def execute
|
9
8
|
warn_unexportable_repositories
|
10
9
|
response = super
|
11
10
|
if option_async?
|
12
|
-
|
13
|
-
+ "with the command:")
|
14
|
-
output.print_message(" hammer content-export generate-metadata --task-id #{@task['id']}")
|
11
|
+
emit_async_info
|
15
12
|
HammerCLI::EX_OK
|
16
13
|
elsif response != HammerCLI::EX_OK
|
17
14
|
response
|
18
15
|
else
|
19
16
|
export_history = fetch_export_history_from_task(reload_task(@task))
|
20
|
-
if
|
17
|
+
if syncable?
|
18
|
+
make_listing_files(export_history)
|
19
|
+
HammerCLI::EX_OK
|
20
|
+
elsif export_history
|
21
21
|
generate_metadata_json(export_history)
|
22
22
|
HammerCLI::EX_OK
|
23
23
|
else
|
@@ -27,6 +27,22 @@ module HammerCLIKatello
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def emit_async_info
|
31
|
+
if syncable?
|
32
|
+
output.print_message _("Once the task completes the listing files may be generated "\
|
33
|
+
+ "with the command:")
|
34
|
+
output.print_message(" hammer content-export generate-listing --task-id #{@task['id']}")
|
35
|
+
else
|
36
|
+
output.print_message _("Once the task completes the export metadata must be generated "\
|
37
|
+
+ "with the command:")
|
38
|
+
output.print_message(" hammer content-export generate-metadata --task-id #{@task['id']}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def syncable?
|
43
|
+
options.key?("option_format") && option_format == 'syncable'
|
44
|
+
end
|
45
|
+
|
30
46
|
def send_request
|
31
47
|
@task = super
|
32
48
|
end
|
@@ -54,6 +70,48 @@ module HammerCLIKatello
|
|
54
70
|
fetch_export_history(export_history_id)
|
55
71
|
end
|
56
72
|
|
73
|
+
def check_export_history_syncable!(export_history)
|
74
|
+
unless export_history["metadata"]["format"] == "syncable"
|
75
|
+
raise _("Cannot generate listing files for this export since "\
|
76
|
+
+ "it is not syncable. It was not generated with --format=syncable.")
|
77
|
+
end
|
78
|
+
|
79
|
+
raise _("Export History does not have the path specified."\
|
80
|
+
+ " The task may have errored out.") unless export_history["path"]
|
81
|
+
end
|
82
|
+
|
83
|
+
def make_listing_files(export_history)
|
84
|
+
check_export_history_syncable!(export_history)
|
85
|
+
output.print_message _("Generated #{export_history['path']}")
|
86
|
+
|
87
|
+
return unless Dir.exist?("#{export_history['path']}/content")
|
88
|
+
|
89
|
+
begin
|
90
|
+
# export history path may look like
|
91
|
+
# "/var/lib/pulp/exports/export-12803/apple/3.0//2022-06-30T17-23-06-00-00"
|
92
|
+
# Generate listing files for all sub directories of
|
93
|
+
# /var/lib/pulp/exports/export-12803/apple/3.0/$date/$org/Library/
|
94
|
+
ignorables = Dir.glob("#{export_history['path']}/content/**/repodata").map do |path|
|
95
|
+
File.dirname(path)
|
96
|
+
end
|
97
|
+
|
98
|
+
paths = Find.find("#{export_history['path']}/content").select do |path|
|
99
|
+
File.directory?(path) &&
|
100
|
+
ignorables.none? { |ignorable| path.start_with?(ignorable) }
|
101
|
+
end
|
102
|
+
|
103
|
+
paths.each do |dir|
|
104
|
+
directories = Dir.chdir(dir) { Dir['*'] }
|
105
|
+
File.write("#{dir}/listing", directories.join("\n"))
|
106
|
+
end
|
107
|
+
rescue SystemCallError
|
108
|
+
output.print_message _("Unable to access/write listing files"\
|
109
|
+
+ " to '#{export_history['path']}'." \
|
110
|
+
+ " To generate listing files run the command below as a root user ")
|
111
|
+
output.print_message(" hammer content-export generate-listing --id #{export_history['id']}")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
57
115
|
def generate_metadata_json(export_history)
|
58
116
|
metadata_json = export_history["metadata"].to_json
|
59
117
|
begin
|