backend/satellite_tools/spacewalk-data-fsck
| 53 +++++++++-
java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/test/CryptoKeysHandlerTest.java
| 14 +-
2 files changed, 58 insertions(+), 9 deletions(-)
New commits:
commit 86bbb78dd505f53efd9435c29f6e581ca36d0625
Author: Tomas Kasparek <tkasparek(a)redhat.com>
Date: Thu Sep 6 16:13:55 2012 +0200
Adding file path restoration functionality to spacewalk-data-fsck
If there is file path irregularity in file path and file info stored in the
database spacewalk-data-fsck reports NEVRAO mismatch. With new feature -F or
--fix-file-path spacewalk-data-fsck restores file path so it responds to informations
stored in the databse.
NEVRAO mismatches are mainly caused by upgrades from earlier versions of spacewalk,
where epochs were ommited in filepaths.
diff --git a/backend/satellite_tools/spacewalk-data-fsck
b/backend/satellite_tools/spacewalk-data-fsck
index f16e48c..caab86d 100755
--- a/backend/satellite_tools/spacewalk-data-fsck
+++ b/backend/satellite_tools/spacewalk-data-fsck
@@ -28,6 +28,7 @@ report_msg = {
'file' : "%5d files scanned",
'exists' : "ERROR: %5d files missing on disk",
'dbexists' : "ERROR: %5d files missing in database",
+ 'restore' : "ERROR: %5d file paths could not be restored",
'size' : "ERROR: %5d file size mismatch(es)",
'checksum' : "ERROR: %5d file checksum mismatch(es)",
'nevrao' : "ERROR: %5d file NEVRAO mismatch(es)",
@@ -95,6 +96,8 @@ def check_db_vs_disk(options):
if check_disk_exists(abs_path) == 1:
report['exists'] += 1
+ elif options.restore:
+ report['restore'] += check_disk_nevrao(abs_path, row.copy(),
True)
else:
if options.size:
report['size'] += check_disk_size(abs_path,
row['package_size'])
@@ -105,7 +108,7 @@ def check_db_vs_disk(options):
row['checksum_type'],
row['checksum'])
h.close()
error_found=0
- for i in ['file', 'exists', 'size', 'nevrao',
'checksum']:
+ for i in ['file', 'exists', 'restore', 'size',
'nevrao', 'checksum']:
if report[i] > 0:
log(1, report_msg[i] % report[i])
if i != 'file':
@@ -127,7 +130,7 @@ def check_disk_size(abs_path, size):
ret = 1
return ret
-def check_disk_nevrao(abs_path, row):
+def check_disk_nevrao(abs_path, row, restore=None):
file = {};
(_redhat_,
file['org_id'],
@@ -156,9 +159,53 @@ def check_disk_nevrao(abs_path, row):
if file[key] != row[key]:
log(0, "File path mismatch: %s (%s: %s vs. %s)" % (abs_path, key,
row[key],
file[key]))
+ if restore:
+ log(2, "Begining file path restoration: %s" % abs_path)
+ return restore_file_path(file, row)
ret = 1
return ret
+
+def restore_file_path(file, row):
+ prefix = CFG.MOUNT_POINT + '/'
+ new_path = 'redhat/' + row['org_id'] + '/' +
row['checksum_prefix'] + '/' + row['name'] + '/' +
row['evr'] + '/' + row['arch'] + '/' +
row['checksum'] + '/' + row['basename']
+ query = "update rhnPackage set path=\'" + new_path + "\' where
id=" + str(row['id'])
+ new_path = prefix + new_path
+ cleanup = True
+ try: #1st, make dirs needed
+ os.makedirs(new_path.rsplit('/', 1)[0])
+ except OSError, e:
+ if e.errno!=17: #something broke up
+ log(0, "File path restoration failed: %s" % row['path'])
+ return 1
+ else:
+ cleanup = False #dir already exists, do not cleanup
+ try: #2nd, create hardlink; os.link and os.makedirs in 1 dir would be problem due to
checking of errno 17...
+ os.link(prefix + row['path'], new_path)
+ except OSError:
+ log(0, "File path restoration failed, rolling back: %s" %
row['path'])
+ if cleanup==True:
+ try:
+ os.removedirs(new_path.rsplit('/', 1)[0])
+ except OSError, e:
+ if e.errno!=39:
+ log(0, "Could not rollback file path restoration: %s" %
row['path'])
+ return 1
+ return
+ h = rhnSQL.prepare(query)
+ h.execute()
+ rhnSQL.commit()
+ try:
+ os.remove(prefix + row['path'])
+ os.removedirs(prefix + row['path'].rsplit('/', 1)[0])
+ except OSError, e:
+ if e.errno==2:
+ log(2, "File %s%s was removed by someone else but transaction has been
successfully completed" % (prefix, row['path']))
+ elif e.errno!=39:
+ log(4, "Unexpected error, computer is going to self destruct")
+ 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):
try:
fp = file(abs_path ,'rb')
@@ -242,6 +289,8 @@ if __name__ == '__main__':
help="Check only if packages from filesystem are in the
database"),
Option("-r", "--remove",
action="store_true",
help="Automaticaly remove packages from filesystem not present in
database"),
+ Option("-F", "--fix-file-path",
action="store_true", dest="restore", default=False,
+ help="Restores file paths, try this when you have NEVRAO mismatches. Do
not run this command with another commands"),
]
parser = OptionParser(option_list=options_table)
(options, args) = parser.parse_args()
commit 56e90002ce480b9de2b84bdca8713a32a2b000a0
Author: Tomas Kasparek <tkasparek(a)redhat.com>
Date: Wed Sep 5 13:40:58 2012 +0200
CryptoKeysHandlerTest are undertaken with OrgAdmin privileges.
Change made in bugzilla 733420 prevented CryptoKeysHandlerTest run correctly as Org or
Config admin is required for API calls in CryptoKeysHandler.
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/test/CryptoKeysHandlerTest.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/test/CryptoKeysHandlerTest.java
index b90ecc3..652006c 100644
---
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/test/CryptoKeysHandlerTest.java
+++
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/keys/test/CryptoKeysHandlerTest.java
@@ -38,7 +38,7 @@ public class CryptoKeysHandlerTest extends BaseHandlerTestCase {
public void testListAllKeys() throws Exception {
// Setup
- User otherOrg = UserTestUtils.findNewUser();
+ User otherOrg = UserTestUtils.findNewUser("testUser",
"testOrg", true);
CryptoKey key = CryptoTest.createTestKey(otherOrg.getOrg());
KickstartFactory.saveCryptoKey(key);
flushAndEvict(key);
@@ -65,11 +65,11 @@ public class CryptoKeysHandlerTest extends BaseHandlerTestCase {
// Test
CryptoKeysHandler handler = new CryptoKeysHandler();
- handler.create(regularKey, description, "GPG", content);
+ handler.create(adminKey, description, "GPG", content);
// Verify
CryptoKey cryptoKey =
- KickstartFactory.lookupCryptoKey(description, regular.getOrg());
+ KickstartFactory.lookupCryptoKey(description, admin.getOrg());
assertNotNull(cryptoKey);
assertEquals(cryptoKey.getDescription(), description);
@@ -79,14 +79,14 @@ public class CryptoKeysHandlerTest extends BaseHandlerTestCase {
public void testDelete() throws Exception {
// Setup
- CryptoKey key = CryptoTest.createTestKey(regular.getOrg());
+ CryptoKey key = CryptoTest.createTestKey(admin.getOrg());
KickstartFactory.saveCryptoKey(key);
assertNotNull(KickstartFactory.lookupCryptoKeyById(key.getId(), key.getOrg()));
flushAndEvict(key);
// Test
CryptoKeysHandler handler = new CryptoKeysHandler();
- handler.delete(regularKey, key.getDescription());
+ handler.delete(adminKey, key.getDescription());
// Verify
CryptoKey deletedKey =
@@ -96,14 +96,14 @@ public class CryptoKeysHandlerTest extends BaseHandlerTestCase {
public void testGetDetails() throws Exception {
// Setup
- CryptoKey key = CryptoTest.createTestKey(regular.getOrg());
+ CryptoKey key = CryptoTest.createTestKey(admin.getOrg());
KickstartFactory.saveCryptoKey(key);
assertNotNull(KickstartFactory.lookupCryptoKeyById(key.getId(), key.getOrg()));
flushAndEvict(key);
// Test
CryptoKeysHandler handler = new CryptoKeysHandler();
- CryptoKey cryptoKey = handler.getDetails(regularKey, key.getDescription());
+ CryptoKey cryptoKey = handler.getDetails(adminKey, key.getDescription());
// Verify
assertNotNull(cryptoKey);