RedHatSatellite / sat6_scripts

Scripts to automate various Satellite 6 content related tasks, including disconnected export/import, publish, promote, cleanup and more...
GNU General Public License v3.0
53 stars 33 forks source link

clean_content_views.py fails in Satellite 6.5 #58

Open icc-marti opened 5 years ago

icc-marti commented 5 years ago

Script clean_content_views.py fails in Red Hat Satellite 6.5 with the following error code:

Cleaning content view 'All Repositories'
Traceback (most recent call last):
  File "./clean_content_views.py", line 348, in <module>
    main(sys.argv[1:])
  File "./clean_content_views.py", line 341, in main
    cleanup(ver_list, ver_descr, dry_run, runuser, ver_keep, cleanall, ignorefirstpromoted)
  File "./clean_content_views.py", line 144, in cleanup
    version_in_use, version_in_ccv = check_version_views(version['id'])
  File "./clean_content_views.py", line 93, in check_version_views
    if viewlist['katello_content_views']:
KeyError: 'katello_content_views'

Seems issue is in line 94. Tested quering API at https://localhost/katello/api/v2/content_view_versions/id and the list doesn't contain an attribute _katello_contentviews.

ggatward commented 5 years ago

Thanks for the report - reproduced here as well. Looks like there is no straight-up replacement of the katello_content_views field in the JSON output - working this one in branch ISSUE-58 against both 6.5 and 6.4 installations.

adam-kosseck commented 5 years ago

Any news on a fix for this? As a workaround I've setup a cron job to run hammer in a loop to clear out old content views - however it'd be really nice to have a proper fix.

assen-totin commented 5 years ago

Would also like to see a fix - it's been 2 months now, we have to manually clean up old versions after each promotion. If you cannot fix the code here, at least, provide a patch to apply locally.

After all, these scripts are more or less "official" RedHat supplementary scripts for what Satellite should have long had as built-in functions -so it is a pity to see them not working after a change in Satellite.

ggatward commented 5 years ago

Unfortunately other commitments have left me unable to work on this (or any) issue in this project for a while. These scripts are NOT official RedHat product.

There is an ISSUE-58 branch of this project that contains a semi-fix for Satellite 6.5, in that it uses the new API syntax, however there is no code currently to allow backwards compatibility with 6.3/4, and there also seems to be no way in 6.5 to pull the required info to handle CCV versions nicely, so if you are using CCV's it won't work anyway.

Please feel free to try that branch and see if it helps - I am hoping to get some time to focus on this project again soon.

assen-totin commented 5 years ago

After looking at the current structure of the viewlist, it seems that this simple patch does the job for me:

--- clean_content_views.py  2019-07-24 21:54:34.230530353 +0200
+++ 1.py    2019-08-11 12:41:48.770446697 +0200
@@ -91,7 +91,7 @@
     # If the list is not empty we need to return this fact. A CV that belongs
     # to NO versions will be a candidate for cleanup.
     viewlist['composite_content_view_ids']
-    if viewlist['katello_content_views']:
+    if viewlist['environments']:
         version_in_use = True
         msg = "Version " + str(viewlist['version']) + " is associated with published CV"
         helpers.log_msg(msg, 'DEBUG')

The "environments" key will be empty whenever the examined version is not part of any environment (i.e. may be deleted if other requirements, like number of instances to keep, are met) - and will not be empty whenever the version is used in an environment, hence should not be touched.

adam-kosseck commented 5 years ago

@assen-totin I have tested your patch (manually) against code from the master branch and can confirm that it works perfectly. Well done!

nin0-0 commented 4 years ago

You can replace katello_content_views with content_view too