Skip to content

Commit

Permalink
Cleanup prior to RPM packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
ggatward committed Dec 19, 2016
1 parent e41959d commit 0391d4b
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/check_sync
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
import sys

sys.path.insert(0, '/usr/local/bin/sat6_scripts')
sys.path.insert(0, '/usr/share/sat6_scripts')
try:
import check_sync
check_sync.main(sys.argv[1:])
Expand Down
2 changes: 1 addition & 1 deletion bin/clean_content_views
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
import sys

sys.path.insert(0, '/usr/local/bin/sat6_scripts')
sys.path.insert(0, '/usr/share/sat6_scripts')
try:
import clean_content_views
clean_content_views.main(sys.argv[1:])
Expand Down
6 changes: 3 additions & 3 deletions bin/promote_content_view → bin/promote_content_views
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/python
import sys

sys.path.insert(0, '/usr/local/bin/sat6_scripts')
sys.path.insert(0, '/usr/share/sat6_scripts')
try:
import promote_content_view
promote_content_view.main(sys.argv[1:])
import promote_content_views
promote_content_views.main(sys.argv[1:])
except KeyboardInterrupt, e:
print >> sys.stderr, "\n\nExiting on user cancel."
sys.exit(1)
Expand Down
6 changes: 3 additions & 3 deletions bin/publish_content_view → bin/publish_content_views
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/python
import sys

sys.path.insert(0, '/usr/local/bin/sat6_scripts')
sys.path.insert(0, '/usr/share/sat6_scripts')
try:
import publish_content_view
publish_content_view.main(sys.argv[1:])
import publish_content_views
publish_content_views.main(sys.argv[1:])
except KeyboardInterrupt, e:
print >> sys.stderr, "\n\nExiting on user cancel."
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion bin/sat_export
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
import sys

sys.path.insert(0, '/usr/local/bin/sat6_scripts')
sys.path.insert(0, '/usr/share/sat6_scripts')
try:
import sat_export
sat_export.main(sys.argv[1:])
Expand Down
2 changes: 1 addition & 1 deletion bin/sat_import
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
import sys

sys.path.insert(0, '/usr/local/bin/sat6_scripts')
sys.path.insert(0, '/usr/share/sat6_scripts')
try:
import sat_import
sat_import.main(sys.argv[1:])
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 21 additions & 2 deletions sat_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ def export_puppet(repo_id, repo_label, repo_relative, last_export, export_type,
return numfiles


def count_packages(repo_id):
"""
Return the number of packages/erratum in a respository
"""
result = helpers.get_json(
helpers.KATELLO_API + "repositories/" + str(repo_id)
)

numpkg = result['content_counts']['rpm']
numerrata = result['content_counts']['erratum']

return str(numpkg) + ':' + str(numerrata)


def check_running_tasks(label, name):
"""
Expand Down Expand Up @@ -639,6 +652,7 @@ def main(args):
# Get the org_id (Validates our connection to the API)
org_id = helpers.get_org_id(org_name)
exported_repos = []
package_count = {}
# If a specific environment is requested, find and read that config file
repocfg = os.path.join(dir, confdir + '/exports.yml')
if args.env:
Expand Down Expand Up @@ -822,6 +836,10 @@ def main(args):
ok_to_export = check_running_tasks(repo_result['label'], ename)

if ok_to_export:
# Count the number of packages
numpkg = count_packages(repo_result['id'])
package_count[repo_result['label']] = numpkg

# Trigger export on the repo
export_id = export_repo(repo_result['id'], last_export, export_type)

Expand Down Expand Up @@ -973,9 +991,10 @@ def main(args):
# Define the location of our exported data.
export_dir = helpers.EXPORTDIR + "/export"

# Write out the list of exported repos. This will be transferred to the disconnected system
# and used to perform the repo sync tasks during the import.
# Write out the list of exported repos and the package counts. These will be transferred to the
# disconnected system and used to perform the repo sync tasks during the import.
pickle.dump(exported_repos, open(export_dir + '/exported_repos.pkl', 'wb'))
pickle.dump(package_count, open(export_dir + '/package_count.pkl', 'wb'))

# Run GPG Checks on the exported RPMs
if not args.nogpg:
Expand Down
51 changes: 51 additions & 0 deletions sat_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,53 @@ def sync_content(org_id, imported_repos):
return delete_override


def count_packages(repo_id):
"""
Return the number of packages/erratum in a respository
"""
result = helpers.get_json(
helpers.KATELLO_API + "repositories/" + str(repo_id)
)

numpkg = result['content_counts']['rpm']
numerrata = result['content_counts']['erratum']

return numpkg, numerrata


def check_counts(package_count)
"""
Verify the number of pkgs/errutum in each repo match the sync host.
Input is a dictionary loaded from a pickle that was created on the sync
host in format {Repo_Label, pkgs:erratum}
"""

# Get a listing of repositories in this Satellite
enabled_repos = helpers.get_p_json(
helpers.KATELLO_API + "/repositories/", \
json.dumps(
{
"organization_id": org_id,
"per_page": '1000',
}
))

# First loop through the repos in the import dict and find the local ID
for repo, counts in package_count.iteritems():
print repo, counts
# Split the count data into packages and erratum
sync_pkgs = counts.split(':')[0]
sync_erratum = counts.split(':')[1]

for repo_result in enabled_repos['results']:
if repo in repo_result['label']:
print repo_result['label'], repo_result['id']
local_pkgs, local_erratum = count_packages(repo_result['id'])

print "Packages: " + str(sync_pkgs), str(local_pkgs)
print "Erratum: " + str(sync_erratum), str(local_erratum)


def main(args):
"""
Main Routine
Expand Down Expand Up @@ -249,10 +296,14 @@ def main(args):
# We need to figure out which repos to sync. This comes to us via a pickle containing
# a list of repositories that were exported
imported_repos = pickle.load(open('exported_repos.pkl', 'rb'))
package_count = pickle.load(open('package_count.pkl', 'rb'))

# Run a repo sync on each imported repo
(delete_override) = sync_content(org_id, imported_repos)

# Verify the repository package/erratum counts match the sync host
check_counts(package_count)

print helpers.GREEN + "Import complete.\n" + helpers.ENDC
print 'Please publish content views to make new content available.'

Expand Down

0 comments on commit 0391d4b

Please sign in to comment.