Bug 1148439 - checksum verification in spacewalk-data-fsck does not work
Summary: checksum verification in spacewalk-data-fsck does not work
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Satellite 5
Classification: Red Hat
Component: Server
Version: 570
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Michael Mráka
QA Contact: Ales Dujicek
URL:
Whiteboard:
Depends On:
Blocks: sat570-lowbug
TreeView+ depends on / blocked
 
Reported: 2014-10-01 13:26 UTC by Pavel Studeník
Modified: 2015-01-13 09:54 UTC (History)
6 users (show)

Fixed In Version: spacewalk-backend-2.3.3-12
Doc Type: Bug Fix
Doc Text:
Clone Of: 1148163
Environment:
Last Closed: 2015-01-13 09:54:20 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Pavel Studeník 2014-10-01 13:26:59 UTC
+++ This bug was initially created as a clone of Bug #1148163 +++

Description of problem:

spacewalk-data-fsck checksum verification is broken

[root@spacew1 ~]# /usr/bin/spacewalk-data-fsck --db-only
File checksum mismatch: /var/satellite/redhat/1/360/libjpeg/6b-46.el6/i686/36099439b7dbc9323588f1999bff9b1738bb8b4df56149eb7ebb5b5226107665/libjpeg-6b-46.el6.i686.rpm (sha256: 36099439b7dbc9323588f1999bff9b1738bb8b4df56149eb7ebb5b5226107665 vs. None)
...

I'm getting "... vs. None)" for all files.

Version-Release number of selected component (if applicable):
spacewalk-backend-tools-2.2.43-1.el6.noarch

How reproducible:


Steps to Reproduce:
1. /usr/bin/spacewalk-data-fsck --db-only
same for --fs-only
2. 
3.

Actual results:
see above

Expected results:
checksum verification should work

Additional info:

The problem is that check_disk_checksum() is using "checksum"
as a variable name, that overrides the import checksum:

...
    from spacewalk.common import checksum
...

def check_disk_checksum(abs_path, checksum_type, checksum):
    try:
        fp = file(abs_path ,'rb')
        h = checksum.getHashlibInstance(checksum_type, False)
        h.update(fp.read())
        file_checksum = h.hexdigest()
        fp.close()
    except:
        file_checksum = None
    ret = 0
    if file_checksum != checksum:
        log(0, "File checksum mismatch: %s (%s: %s vs. %s)" %
                 (abs_path, checksum_type, checksum, file_checksum))
        ret = 1
    return ret

When adding raise to see the exception, it is:
...
  File "/usr/bin/spacewalk-data-fsck_debug", line 217, in check_disk_checksum
    h = checksum.getHashlibInstance(checksum_type, False)
AttributeError: 'str' object has no attribute 'getHashlibInstance'

possible patch:

--- spacewalk-data-fsck.orig	2014-07-11 13:57:05.000000000 +0200
+++ spacewalk-data-fsck	2014-09-30 21:49:00.487999668 +0200
@@ -211,7 +211,7 @@
     log(0, "File %s%s successfully restored, new file path: %s" % (prefix, row['path'], new_path))
     return 0
 
-def check_disk_checksum(abs_path, checksum_type, checksum):
+def check_disk_checksum(abs_path, checksum_type, db_checksum):
     try:
         fp = file(abs_path ,'rb')
         h = checksum.getHashlibInstance(checksum_type, False)
@@ -221,9 +221,9 @@
     except:
         file_checksum = None
     ret = 0
-    if file_checksum != checksum:
+    if file_checksum != db_checksum:
         log(0, "File checksum mismatch: %s (%s: %s vs. %s)" %
-                 (abs_path, checksum_type, checksum, file_checksum))
+                 (abs_path, checksum_type, db_checksum, file_checksum))
         ret = 1
     return ret

Probably the following commit broke it:
https://github.com/spacewalkproject/spacewalk/commit/5dabeddf4306f61f555b6a329324dbc3b0afc8cc

--- Additional comment from Pavel Studeník on 2014-10-01 09:23:39 EDT ---

Need to change /usr/bin/spacewalk-data-fsck for debug

@@ -218,7 +218,7 @@
         h.update(fp.read())
         file_checksum = h.hexdigest()
         fp.close()
-    except:
+    except IndexError:
         file_checksum = None
     ret = 0
     if file_checksum != checksum:


I get following traceback:

>> spacewalk-data-fsck 
Traceback (most recent call last):
  File "/usr/bin/spacewalk-data-fsck", line 312, in <module>
    exit_value += check_db_vs_disk(options)
  File "/usr/bin/spacewalk-data-fsck", line 109, in check_db_vs_disk
    row['checksum_type'], row['checksum'])
  File "/usr/bin/spacewalk-data-fsck", line 217, in check_disk_checksum
    h = checksum.getHashlibInstance(checksum_type, False)
AttributeError: 'str' object has no attribute 'getHashlibInstance'

package: spacewalk-backend-tools-2.3.3-10.el6sat.noarch

Comment 2 Michael Mráka 2014-10-08 12:31:21 UTC
Backported to SATELLITE-5.7 as
commit 23278394fed63f48315a23bc15c5407c075c035e
    1148439 - fixed variable name

Comment 5 Clifford Perry 2015-01-13 09:54:20 UTC
With the release of Red Hat Satellite 5.7 on January 12th 2015 this bug is
being moved to a Closed Current Release state. 

The Satellite 5.7 GA Errata:
 - https://rhn.redhat.com/errata/RHSA-2015-0033.html 

Satellite 5.7 Release Notes:
 -
https://access.redhat.com/documentation/en-US/Red_Hat_Satellite/5.7/html-single/Release_Notes/index.html

Satellite Customer Portal Blog announcement for release:
 - https://access.redhat.com/blogs/1169563/posts/1315743 

Cliff


Note You need to log in before you can comment on or make changes to this bug.