Skip to content

Commit a9b8b80

Browse files
authored
Support Satellite 6.3 (#39)
* Sat63 fixes (#38) * New methods for Sat 6.3 yum export * Fix to puppet exporter to handle backend_id * Fix for 6.3 file exports * Fix DoV export for 6.3 * Count DRPMs as well as RPMs * Update README * Version bump to 1.2.3
1 parent 781a5d0 commit a9b8b80

File tree

4 files changed

+123
-36
lines changed

4 files changed

+123
-36
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66
## [Unreleased]
77

88

9+
## [1.2.3] - 2018-03-12
10+
### Changed
11+
- Export package count now counts DRPM packages exported by Sat 6.3
12+
13+
### Fixed
14+
- sat_export did not handle new backend_identifier value generated by Sat 6.3
15+
16+
917
## [1.2.2] - 2018-02-25
1018
### Added
1119
- Option to tag a published content view with a custom comment
@@ -77,7 +85,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7785
## 0.6 - 2017-02-27
7886
- Last of a series of pre-release betas
7987

80-
[Unreleased]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.2...HEAD
88+
[Unreleased]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.3...HEAD
89+
[1.2.3]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.2...1.2.3
8190
[1.2.2]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.1...1.2.2
8291
[1.2.1]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.0...1.2.1
8392
[1.2.0]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.1.1...1.2.0

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ Importing content in a disconnected environment can be a challenge.
44
These scripts make use of the Inter-Satellite Sync capability in Satellite 6.2 to
55
allow for full and incremental export/import of content between environments.
66

7-
These scripts have been written and tested using Satellite 6.2 on RHEL7
7+
These scripts have been written and tested using Satellite 6.x on RHEL7. (RHEL6 not supported)
8+
Export/Import testing has been performed on the following version combinations:
9+
* 6.2 -> 6.2
10+
* 6.2 -> 6.3
11+
* 6.3 -> 6.2
12+
* 6.3 -> 6.3
813

914
## Definitions
1015
Throughout these scripts the following references are used:
@@ -14,8 +19,8 @@ Throughout these scripts the following references are used:
1419

1520

1621
# Requirements
17-
* Satellite >= 6.2.x
18-
* Python >= 2.7
22+
* Satellite >= 6.2.9
23+
* Python = 2.7
1924
* PyYAML
2025

2126
The Export and Import scripts are intended to be run on the Satellite servers directly.

rel-eng/sat6_scripts.spec

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Name: sat6_scripts
2-
Version: 1.2.1
3-
Release: 2%{?dist}
2+
Version: 1.2.3
3+
Release: 1%{?dist}
44
Summary: Scripts to automate Satellite 6 tasks
55

66
License: GPL
77
URL: https://github.com/ggatward/sat6_scripts
8-
Source0: sat6_scripts-1.2.1.tar.gz
8+
Source0: sat6_scripts-1.2.3.tar.gz
99

1010
Requires: python >= 2.7, PyYAML
1111

@@ -130,6 +130,12 @@ mandb -q
130130

131131

132132
%changelog
133+
* Mon Mar 12 2018 Geoff Gatward <ggatward@redhat.com> 1.2.3
134+
- Refer https://github.com/ggatward/sat6_scripts/blob/1.2.3/CHANGELOG.md
135+
136+
* Sun Feb 25 2018 Geoff Gatward <ggatward@redhat.com> 1.2.2
137+
- Refer https://github.com/ggatward/sat6_scripts/blob/1.2.2/CHANGELOG.md
138+
133139
* Mon Dec 11 2017 Geoff Gatward <ggatward@redhat.com> 1.2.1
134140
- Refer https://github.com/ggatward/sat6_scripts/blob/1.2.1/CHANGELOG.md
135141

sat_export.py

Lines changed: 96 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def get_cv(org_id):
4848
msg = " Version ID: " + str(ver['id'])
4949
helpers.log_msg(msg, 'DEBUG')
5050

51-
# There will only ever be one DOV
52-
return cv_result['id']
51+
# Return the ID (should be '1') and the label (forms part of the export path name)
52+
return cv_result['id'], cv_result['label']
5353

5454
# Promote a content view version
5555
def export_cv(dov_ver, last_export, export_type):
@@ -160,7 +160,7 @@ def export_repo(repo_id, last_export, export_type):
160160
return str(task_id)
161161

162162

163-
def export_iso(repo_id, repo_label, repo_relative, last_export, export_type):
163+
def export_iso(repo_id, repo_path, repo_label, repo_relative, last_export, export_type, satver):
164164
"""
165165
Export iso repository
166166
Takes the repository id and a start time (find newer than value)
@@ -192,25 +192,45 @@ def export_iso(repo_id, repo_label, repo_relative, last_export, export_type):
192192
sys.stdout.flush()
193193

194194
if export_type == 'full':
195-
os.system('find -L /var/lib/pulp/published/http/isos/*' + repo_label \
195+
os.system('find -L /var/lib/pulp/published/http/isos/*' + repo_path \
196196
+ ' -type f -exec cp --parents -Lrp {} ' + ISOEXPORTDIR + " \;")
197197
else:
198-
os.system('find -L /var/lib/pulp/published/http/isos/*' + repo_label \
198+
os.system('find -L /var/lib/pulp/published/http/isos/*' + repo_path \
199199
+ ' -type f -newerct $(date +%Y-%m-%d -d "' + last_export + '") -exec cp --parents -Lrp {} ' \
200200
+ ISOEXPORTDIR + ' \;')
201201
# We need to copy the manifest anyway, otherwise we'll cause import issues if we have an empty repo
202-
os.system('find -L /var/lib/pulp/published/http/isos/*' + repo_label \
202+
os.system('find -L /var/lib/pulp/published/http/isos/*' + repo_path \
203203
+ ' -name PULP_MANIFEST -exec cp --parents -Lrp {} ' + ISOEXPORTDIR + ' \;')
204204

205205

206206
# At this point the iso/ export dir will contain individual repos - we need to 'normalise' them
207-
for dirpath, subdirs, files in os.walk(ISOEXPORTDIR):
208-
for tdir in subdirs:
209-
if repo_label in tdir:
210-
# This is where the exported ISOs for our repo are located
211-
INDIR = os.path.join(dirpath, tdir)
212-
# And this is where we want them to be moved to so we can export them in Satellite format
213-
# We need to knock off '<org_name>/Library/' from beginning of repo_relative and replace with export/
207+
if satver == '6.2':
208+
for dirpath, subdirs, files in os.walk(ISOEXPORTDIR):
209+
for tdir in subdirs:
210+
if repo_label in tdir:
211+
# This is where the exported ISOs for our repo are located
212+
INDIR = os.path.join(dirpath, tdir)
213+
# And this is where we want them to be moved to so we can export them in Satellite format
214+
# We need to knock off '<org_name>/Library/' from beginning of repo_relative and replace with export/
215+
exportpath = "/".join(repo_relative.strip("/").split('/')[2:])
216+
OUTDIR = helpers.EXPORTDIR + '/export/' + exportpath
217+
218+
# Move the files into the final export tree
219+
if not os.path.exists(OUTDIR):
220+
shutil.move(INDIR, OUTDIR)
221+
222+
os.chdir(OUTDIR)
223+
numfiles = len([f for f in os.walk(".").next()[2] if f[ -8: ] != "MANIFEST"])
224+
225+
msg = "File Export OK (" + str(numfiles) + " new files)"
226+
helpers.log_msg(msg, 'INFO')
227+
print helpers.GREEN + msg + helpers.ENDC
228+
229+
else:
230+
# Satellite 6.3 changed the published file structure
231+
for dirpath, subdirs, files in os.walk(ISOEXPORTDIR):
232+
if repo_relative in dirpath:
233+
INDIR = dirpath
214234
exportpath = "/".join(repo_relative.strip("/").split('/')[2:])
215235
OUTDIR = helpers.EXPORTDIR + '/export/' + exportpath
216236

@@ -289,7 +309,7 @@ def export_puppet(repo_id, repo_label, repo_relative, last_export, export_type,
289309
# Subtract the manifest from the number of files:
290310
numfiles = numfiles - 1
291311

292-
msg = "Puppet Export OK (" + str(numfiles) + " new files)"
312+
msg = "Puppet Export OK (" + str(numfiles) + " new modules)"
293313
helpers.log_msg(msg, 'INFO')
294314
print helpers.GREEN + msg + helpers.ENDC
295315

@@ -571,7 +591,7 @@ def create_tar(export_dir, name, export_history):
571591
os.system('sha256sum ' + short_tarfile + '_* > ' + short_tarfile + '.sha256')
572592

573593

574-
def prep_export_tree(org_name):
594+
def prep_export_tree(org_name, basepaths):
575595
"""
576596
Function to combine individual export directories into single export tree
577597
Export top level contains /content and /custom directories with 'listing'
@@ -583,11 +603,16 @@ def prep_export_tree(org_name):
583603
devnull = open(os.devnull, 'wb')
584604
if not os.path.exists(helpers.EXPORTDIR + "/export"):
585605
os.makedirs(helpers.EXPORTDIR + "/export")
586-
# Haven't found a nice python way to do this - yet...
587-
subprocess.call("cp -rp " + helpers.EXPORTDIR + "/" + org_name + "*/" + org_name + \
588-
"/Library/* " + helpers.EXPORTDIR + "/export", shell=True, stdout=devnull, stderr=devnull)
589-
# Remove original directores
590-
os.system("rm -rf " + helpers.EXPORTDIR + "/" + org_name + "*/")
606+
607+
# Copy the content from each exported repo into a common /export structure
608+
for basepath in basepaths:
609+
msg = "Processing " + basepath
610+
helpers.log_msg(msg, 'DEBUG')
611+
subprocess.call("cp -rp " + basepath + "*/" + org_name + \
612+
"/Library/* " + helpers.EXPORTDIR + "/export", shell=True, stdout=devnull, stderr=devnull)
613+
614+
# Remove original directores
615+
os.system("rm -rf " + basepath + "*/")
591616

592617
# We need to re-generate the 'listing' files as we will have overwritten some during the merge
593618
msg = "Rebuilding listing files..."
@@ -725,6 +750,7 @@ def main(args):
725750
org_id = helpers.get_org_id(org_name)
726751
exported_repos = []
727752
export_history = []
753+
basepaths = []
728754
package_count = {}
729755
# If a specific environment is requested, find and read that config file
730756
repocfg = os.path.join(dir, confdir + '/exports.yml')
@@ -864,7 +890,13 @@ def main(args):
864890
check_running_tasks(label, ename)
865891

866892
# Get the version of the CV (Default Org View) to export
867-
dov_ver = get_cv(org_id)
893+
dov_ver, dov_label = get_cv(org_id)
894+
895+
# Set the basepath of the export (needed due to Satellite 6.3 changes in other exports)
896+
# 6.3 provides a 'latest_version' in the API that gives us '1.0' however this is not available
897+
# in 6.2 so we must build the string manually for compatibility
898+
basepath = helpers.EXPORTDIR + "/" + org_name + "-" + dov_label + "-v" + str(dov_ver) + ".0"
899+
basepaths.append(basepath)
868900

869901
# Now we have a CV ID and a starting date, and no conflicting tasks, we can export
870902
export_id = export_cv(dov_ver, last_export, export_type)
@@ -951,7 +983,17 @@ def main(args):
951983
# First resolve the product label - this forms part of the export path
952984
product = get_product(org_id, repo_result['product']['cp_id'])
953985
# Now we can build the export path itself
954-
basepath = helpers.EXPORTDIR + "/" + org_name + "-" + product + "-" + repo_result['label']
986+
987+
# Satellite 6.3 uses a new backend_identifier key in the API result
988+
if 'backend_identifier' in repo_result:
989+
basepath = helpers.EXPORTDIR + "/" + repo_result['backend_identifier']
990+
else:
991+
basepath = helpers.EXPORTDIR + "/" + org_name + "-" + product + "-" + repo_result['label']
992+
993+
# Add to the basepath list so we can use specific paths later
994+
# (Introduced due to path name changes in Sat6.3)
995+
basepaths.append(basepath)
996+
955997
if export_type == 'incr':
956998
basepath = basepath + "-incremental"
957999
exportpath = basepath + "/" + repo_result['relative_path']
@@ -968,10 +1010,21 @@ def main(args):
9681010
helpers.mailout(subject, output)
9691011
sys.exit(1)
9701012

971-
os.chdir(exportpath)
972-
numrpms = len([f for f in os.walk(".").next()[2] if f[ -4: ] == ".rpm"])
973-
974-
msg = "Repository Export OK (" + str(numrpms) + " new packages)"
1013+
# Count the number of .rpm files in the exported repo (recursively)
1014+
numrpms = 0
1015+
numdrpms = 0
1016+
for dirpath, dirs, files in os.walk(exportpath):
1017+
for filename in files:
1018+
fname = os.path.join(dirpath,filename)
1019+
if fname.endswith('.rpm'):
1020+
numrpms = numrpms + 1
1021+
if fname.endswith('.drpm'):
1022+
numdrpms = numdrpms + 1
1023+
1024+
if numdrpms == 0:
1025+
msg = "Repository Export OK (" + str(numrpms) + " new rpms)"
1026+
else:
1027+
msg = "Repository Export OK (" + str(numrpms) + " new rpms + " + str(numdrpms) + " drpms)"
9751028
helpers.log_msg(msg, 'INFO')
9761029
print helpers.GREEN + msg + helpers.ENDC
9771030

@@ -1026,8 +1079,16 @@ def main(args):
10261079
ok_to_export = check_running_tasks(repo_result['label'], ename)
10271080

10281081
if ok_to_export:
1082+
# Satellite 6.3 uses a different path for published file content
1083+
if 'backend_identifier' in repo_result:
1084+
repo_path = repo_result['relative_path']
1085+
satver = '6.3'
1086+
else:
1087+
repo_path = repo_result['label']
1088+
satver = '6.2'
1089+
10291090
# Trigger export on the repo
1030-
numfiles = export_iso(repo_result['id'], repo_result['label'], repo_result['relative_path'], last_export, export_type)
1091+
numfiles = export_iso(repo_result['id'], repo_path, repo_result['label'], repo_result['relative_path'], last_export, export_type, satver)
10311092

10321093
# Reset the export type to the user specified, in case we overrode it.
10331094
export_type = orig_export_type
@@ -1074,9 +1135,15 @@ def main(args):
10741135
# Check if there are any currently running tasks that will conflict
10751136
ok_to_export = check_running_tasks(repo_result['label'], ename)
10761137

1138+
# Satellite 6.3 uses a new backend_identifier key in the API result
1139+
if 'backend_identifier' in repo_result:
1140+
backend_id = repo_result['backend_identifier']
1141+
else:
1142+
backend_id = repo_result['label']
1143+
10771144
if ok_to_export:
10781145
# Trigger export on the repo
1079-
numfiles = export_puppet(repo_result['id'], repo_result['label'], repo_result['relative_path'], last_export, export_type, pforge)
1146+
numfiles = export_puppet(repo_result['id'], backend_id, repo_result['relative_path'], last_export, export_type, pforge)
10801147

10811148
# Reset the export type to the user specified, in case we overrode it.
10821149
export_type = orig_export_type
@@ -1099,7 +1166,7 @@ def main(args):
10991166

11001167

11011168
# Combine resulting directory structures into a single repo format (top level = /content)
1102-
prep_export_tree(org_name)
1169+
prep_export_tree(org_name, basepaths)
11031170

11041171
# Now we need to process the on-disk export data.
11051172
# Define the location of our exported data.

0 commit comments

Comments
 (0)