Skip to content

Commit

Permalink
Fix clean functionality, pre-release updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Gatward committed Nov 25, 2018
1 parent dededcb commit 2814396
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Fixed

## [1.2.4] - 2018-11-25
### Fixed
- clean_content_views raised an exception if a CV version was included in a composite view
- Default org view was assumed to be version 1.0. Correct version is now extracted (Issue #43)
- Org name and label do not always match. Issue with mixed case and spaces in org name (Issue #42)
Expand All @@ -13,7 +16,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Tasks in 'planning' state were not being considered when checking for locks
- foreman_tasks API returns action as 'Promote' instead of 'Promotion' in Sat 6.3


### Added
- Option to define the tar split size (Issue #44)

Expand Down Expand Up @@ -97,7 +99,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 0.6 - 2017-02-27
- Last of a series of pre-release betas

[Unreleased]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.3...HEAD
[Unreleased]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.4...HEAD
[1.2.4]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.3...1.2.4
[1.2.3]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.2...1.2.3
[1.2.2]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.1...1.2.2
[1.2.1]: https://github.com/RedHatSatellite/sat6_scripts/compare/1.2.0...1.2.1
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Overview

Importing content in a disconnected environment can be a challenge.
These scripts make use of the Inter-Satellite Sync capability in Satellite 6.2 to
These scripts make use of the Inter-Satellite Sync capability in Satellite 6 to
allow for full and incremental export/import of content between environments.

These scripts have been written and tested using Satellite 6.x on RHEL7. (RHEL6 not supported)
Export/Import testing has been performed on the following version combinations:
* 6.2 -> 6.2
* 6.2 -> 6.3
* 6.3 -> 6.2
* 6.3 -> 6.3
* 6.3 -> 6.2
* 6.3 -> 6.4
* 6.4 -> 6.4
* 6.4 -> 6.3


## Definitions
Throughout these scripts the following references are used:
Expand Down
Empty file modified bin/auto_content
100644 → 100755
Empty file.
23 changes: 13 additions & 10 deletions clean_content_views.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ def get_cv(org_id, cleanup_list, keep):

return ver_list, ver_descr, ver_keep

# def get_content_view_version(cvid):
# cvv = helpers.get_json(
# helpers.KATELLO_API + "content_view_versions/" + str(cvid))
#
# return cvv

def get_content_view_info(cvid):
"""
Expand Down Expand Up @@ -121,19 +116,22 @@ def cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep, cleanall, ignorefir
sys.exit(1)

for cvid in ver_list.keys():
# Check if there is a publish/promote already running on this content view
locked = helpers.check_running_publish(ver_list[cvid], ver_descr[cvid])

msg = "Cleaning content view '" + str(ver_descr[cvid]) + "'"
helpers.log_msg(msg, 'INFO')
print helpers.HEADER + msg + helpers.ENDC

# Check if there is a publish/promote already running on this content view
locked = helpers.check_running_publish(ver_list[cvid], ver_descr[cvid])
if locked:
continue

# For the given content view we need to find the orphaned versions
cvinfo = get_content_view_info(cvid)

# Find the oldest published version
version_list = []
orphan_versions = []
orphan_dict = {}
all_versions = []
ccv_versions = []
for version in cvinfo['versions']:
Expand All @@ -150,8 +148,10 @@ def cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep, cleanall, ignorefir
if not version['environment_ids']:
# These are the versions that don't belong to an environment (i.e. orphans)
# We also cross-check for versions that may be in a CCV here.
# We add the version name and id into a dictionary so we can delete by id.
if not version_in_use:
orphan_versions.append(float(version['version']))
orphan_dict[version['version']] = version['id']
continue
else:
msg = "Found version " + str(version['version'])
Expand Down Expand Up @@ -210,6 +210,9 @@ def cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep, cleanall, ignorefir
str(ver_descr[cvid]) + "'"
helpers.log_msg(msg, 'DEBUG')

# Lookup the version_id from our orphan_dict
delete_id = orphan_dict.get(str(version))

msg = "Removing version " + str(version)
helpers.log_msg(msg, 'INFO')
print helpers.HEADER + msg + helpers.ENDC
Expand All @@ -219,7 +222,7 @@ def cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep, cleanall, ignorefir
elif version in orphan_versions:
msg = "Skipping delete of version " + str(version) + " (due to keep value)"
else:
msg = "Skipping delete of version " + str(version)
msg = "Skipping delete of version " + str(version) + " (in use)"
helpers.log_msg(msg, 'INFO')
print msg
continue
Expand All @@ -236,7 +239,7 @@ def cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep, cleanall, ignorefir
json.dumps(
{
"id": cvid,
"content_view_version_ids": version['id']
"content_view_version_ids": delete_id
}
))['id']

Expand Down
43 changes: 31 additions & 12 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,48 +416,67 @@ def check_running_publish(cvid, desc):
for task_result in tasks['results']:
if task_result['state'] == 'planning' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Publish':
if task_result['input']['content_view']['id'] == cvid:
msg = "Unable to start '" + desc + "': content view is locked by another task"
log_msg(msg, 'WARNING')
locked = True
return locked
msg = "Unable to start '" + desc + "': A publish task is in planning state, cannot determine if it is for this CV"
log_msg(msg, 'WARNING')
locked = True
return locked
if task_result['state'] == 'running' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Publish':
if task_result['input']['content_view']['id'] == cvid:
msg = "Unable to start '" + desc + "': content view is locked by another task"
msg = "Unable to start '" + desc + "': content view is locked by a running Publish task"
log_msg(msg, 'WARNING')
locked = True
return locked
if task_result['state'] == 'paused' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Publish':
if task_result['input']['content_view']['id'] == cvid:
msg = "Unable to start '" + desc + "': content view is locked by a paused task"
msg = "Unable to start '" + desc + "': content view is locked by a paused Publish task"
log_msg(msg, 'WARNING')
locked = True
return locked
if task_result['state'] == 'planning' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Promotion' or task_result['humanized']['action'] == 'Promote':
msg = "Unable to start '" + desc + "': A promotion task is in planning state, cannot determine if it is for this CV"
log_msg(msg, 'WARNING')
locked = True
return locked
if task_result['state'] == 'running' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Promotion' or task_result['humanized']['action'] == 'Promote':
if task_result['input']['content_view']['id'] == cvid:
msg = "Unable to start '" + desc + "': content view is locked by another task"
msg = "Unable to start '" + desc + "': content view is locked by a running Promotion task"
log_msg(msg, 'WARNING')
locked = True
return locked
if task_result['state'] == 'running' and task_result['label'] != 'Actions::BulkAction':
if task_result['state'] == 'paused' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Promotion' or task_result['humanized']['action'] == 'Promote':
if task_result['input']['content_view']['id'] == cvid:
msg = "Unable to start '" + desc + "': content view is locked by another task"
msg = "Unable to start '" + desc + "': content view is locked by a paused Promotion task"
log_msg(msg, 'WARNING')
locked = True
return locked
if task_result['state'] == 'planning' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Remove Versions and Associations':
msg = "Unable to start '" + desc + "': A remove task is in planning state, cannot determine if it is for this CV"
log_msg(msg, 'WARNING')
locked = True
return locked
if task_result['state'] == 'running' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Remove Versions and Associations':
if task_result['input']['content_view']['id'] == cvid:
msg = "Unable to start '" + desc + "': content view is locked by a running CV deletion task"
log_msg(msg, 'WARNING')
locked = True
return locked
if task_result['state'] == 'paused' and task_result['label'] != 'Actions::BulkAction':
if task_result['humanized']['action'] == 'Promotion' or task_result['humanized']['action'] == 'Promote':
if task_result['humanized']['action'] == 'Remove Versions and Associations':
if task_result['input']['content_view']['id'] == cvid:
msg = "Unable to start '" + desc + "': content view is locked by a paused task"
msg = "Unable to start '" + desc + "': content view is locked by a paused CV deletion task"
log_msg(msg, 'WARNING')
locked = True
return locked



def query_yes_no(question, default="yes"):
"""
Ask a yes/no question via raw_input() and return their answer.
Expand Down
17 changes: 10 additions & 7 deletions rel-eng/sat6_scripts.spec
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Name: sat6_scripts
Version: 1.2.3
Version: 1.2.4
Release: 1%{?dist}
Summary: Scripts to automate Satellite 6 tasks

License: GPL
URL: https://github.com/ggatward/sat6_scripts
Source0: sat6_scripts-1.2.3.tar.gz
URL: https://github.com/RedHatSatellite/sat6_scripts
Source0: sat6_scripts-1.2.4.tar.gz

Requires: python >= 2.7, PyYAML

Expand Down Expand Up @@ -130,17 +130,20 @@ mandb -q


%changelog
* Sun Nov 25 2018 Geoff Gatward <[email protected]> 1.2.4
- Refer https://github.com/RedHatSatellite/sat6_scripts/blob/1.2.4/CHANGELOG.md

* Mon Mar 12 2018 Geoff Gatward <[email protected]> 1.2.3
- Refer https://github.com/ggatward/sat6_scripts/blob/1.2.3/CHANGELOG.md
- Refer https://github.com/RedHatSatellite/sat6_scripts/blob/1.2.3/CHANGELOG.md

* Sun Feb 25 2018 Geoff Gatward <[email protected]> 1.2.2
- Refer https://github.com/ggatward/sat6_scripts/blob/1.2.2/CHANGELOG.md
- Refer https://github.com/RedHatSatellite/sat6_scripts/blob/1.2.2/CHANGELOG.md

* Mon Dec 11 2017 Geoff Gatward <[email protected]> 1.2.1
- Refer https://github.com/ggatward/sat6_scripts/blob/1.2.1/CHANGELOG.md
- Refer https://github.com/RedHatSatellite/sat6_scripts/blob/1.2.1/CHANGELOG.md

* Sun Dec 10 2017 Geoff Gatward <[email protected]> 1.2.0
- Refer https://github.com/ggatward/sat6_scripts/blob/1.2.0/CHANGELOG.md
- Refer https://github.com/RedHatSatellite/sat6_scripts/blob/1.2.0/CHANGELOG.md

* Wed Oct 25 2017 Geoff Gatward <[email protected]> 1.1.1
- Refer https://github.com/ggatward/sat6_scripts/blob/1.1.1/CHANGELOG.md
Expand Down

0 comments on commit 2814396

Please sign in to comment.