Bug 1148163 - 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: Spacewalk
Classification: Community
Component: Server
Version: 2.2
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Michael Mráka
QA Contact: Red Hat Satellite QA List
URL:
Whiteboard:
Depends On:
Blocks: space23
TreeView+ depends on / blocked
 
Reported: 2014-09-30 19:56 UTC by Stephan Dühr
Modified: 2015-04-14 19:03 UTC (History)
3 users (show)

Fixed In Version: spacewalk-backend-2.3.18-1
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1148439 (view as bug list)
Environment:
Last Closed: 2015-04-14 19:03:35 UTC
Embargoed:


Attachments (Terms of Use)

Description Stephan Dühr 2014-09-30 19:56:58 UTC
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

Comment 1 Pavel Studeník 2014-10-01 13:23:39 UTC
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 11:10:56 UTC
Fixed in spacewalk master by
commit 34025800df02297be963b9dade036cda20b498d2
    1148163 - fixed variable name

Comment 3 Grant Gainey 2015-03-23 16:59:18 UTC
Moving bugs to ON_QA as we move to release Spacewalk 2.3

Comment 4 Grant Gainey 2015-04-14 19:03:35 UTC
Spacewalk 2.3 has been released. See

https://fedorahosted.org/spacewalk/wiki/ReleaseNotes23


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