From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 16 Jun 2006 19:35:33 -0000 Subject: [Cluster-devel] conga/luci/utils luci_admin Message-ID: <20060616193533.15989.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Changes by: rmccabe at sourceware.org 2006-06-16 19:35:33 Modified files: luci/utils : luci_admin Log message: Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.10&r2=1.11 --- conga/luci/utils/luci_admin 2006/06/16 18:17:24 1.10 +++ conga/luci/utils/luci_admin 2006/06/16 19:35:33 1.11 @@ -33,6 +33,8 @@ import Products.CMFCore.MemberDataTool import transaction +LUCI_INIT_DEBUG = 0 + LUCI_USER='luci' LUCI_GROUP='luci' @@ -50,6 +52,14 @@ 'Products.CMFCore.MemberDataTool.MemberData' ] +null = file('/dev/null', 'rwb+', 0) + +if LUCI_INIT_DEBUG: + verbose = sys.stderr +else: + verbose = null +orig_stderr = sys.stderr + def luci_restore(argv): if len(argv) > 0: dbfn = argv[0] @@ -67,40 +77,56 @@ db.pack() conn = db.open() except: - stderr.write('Unable to open the luci database \"' + dbfn + '\"\n') - sys.exit(1) + stderr.write('Unable to open the Luci database \"' + dbfn + '\"\n') + return -1 try: node = xml.dom.minidom.parse(backupfn) except: - stderr.write('Unable to open the luci backup file \"'+ backupfn +'\"\n') - sys.exit(1) + stderr.write('Unable to open the Luci backup file \"'+ backupfn +'\"\n') + return -1 node = node.getElementsByTagName('luci') if not node or len(node) < 1: sys.stderr.write('Backup file is missing the \'luci\' tag\n') - sys.exit(1) + return -1 node = node[0].getElementsByTagName('backupData') if not node or len(node) < 1: sys.stderr.write('Backup file is missing the \'backupData\' tag\n') - sys.exit(1) + return -1 node = node[0] - tempuser = AccessControl.User.UnrestrictedUser('admin', '', - ('manage','Manager', 'Owner', 'View', 'Authenticated'), []) + try: + sys.stderr = null + tempuser = AccessControl.User.UnrestrictedUser('admin', '', + ('manage','Manager', 'Owner', 'View', 'Authenticated'), []) - newSecurityManager(None, tempuser) + newSecurityManager(None, tempuser) - app = conn.root()['Application'] - AppInitializer(app).initialize() + app = conn.root()['Application'] + AppInitializer(app).initialize() + sys.stderr = orig_stderr + except: + sys.stderr = orig_stderr + sys.stderr.write('An error occurred while initializing the Luci installation for restoration from backup\n') + return -1 - portal_mem = app.unrestrictedTraverse('/luci/portal_membership') - portal_reg = app.unrestrictedTraverse('/luci/portal_registration') + try: + portal_mem = app.unrestrictedTraverse('/luci/portal_membership') + portal_reg = app.unrestrictedTraverse('/luci/portal_registration') + if not portal_mem or not portal_reg: + raise + except: + sys.stderr.write('Your Luci installation appears to be corrupt. Please reinstall, then try to restore again.') + return -1 userList = node.getElementsByTagName('userList') - if userList and len(userList) > 0: - userList = userList[0].getElementsByTagName('user') + if not userList or len(userList) < 1: + sys.stderr.write('Your backup file contains no users. At the very least, the admin user must exist. Please check that your backup file is not corrupt.\n') + return -1 + + userList = userList[0].getElementsByTagName('user') for u in userList: id = u.getAttribute('id') if not id: @@ -134,10 +160,21 @@ member = portal_mem.getMemberById(id) if not member: transaction.abort() - sys.stderr.write('Error adding user \"' + id + '\"\n') + sys.stderr.write('An error occurred while restoring the user \"' + id + '\"\n') + return -1 + + verbose.write('Added user \"' + id + '\"\n') #transaction.commit() - x = app.unrestrictedTraverse('/luci/systems/storage') + try: + x = app.unrestrictedTraverse('/luci/systems/storage') + if not x: + raise + except: + sys.stderr.write('Cannot find the Luci storage systems directory. Your Luci installation may be corrupt.') + transaction.abort() + return -1 + systemList = node.getElementsByTagName('systemList') if not systemList or len(systemList) < 1: sys.write.stderr('No storage systems to add') @@ -158,9 +195,9 @@ if not new_system: raise except: - sys.stderr.write('Unable to add system \"' + id + '\"\n') + sys.stderr.write('An error occurred while restoring storage system \"' + id + '\"\n') transaction.abort() - sys.exit(1) + return -1 userPerms = s.getElementsByTagName('permList') if not userPerms or len(userPerms) < 1: @@ -173,9 +210,18 @@ if not newuser: continue new_system.manage_setLocalRoles(newuser, ['View']) + + verbose.write('Added storage system \"' + id + '\"\n') #transaction.commit() - x = app.unrestrictedTraverse('/luci/systems/cluster') + try: + x = app.unrestrictedTraverse('/luci/systems/cluster') + if not x: + raise + except: + sys.stderr.write('Cannot find the Luci cluster directory. Your Luci installation may be corrupt.') + transaction.abort() + return -1 clusterList = node.getElementsByTagName('cluster') for c in clusterList: id = c.getAttribute('id') @@ -191,9 +237,9 @@ if not new_cluster: raise except: - sys.stderr.write('Error adding cluster \"' + id + '\"\n') + sys.stderr.write('An error occurred while restoring the cluster \"' + id + '\"\n') transaction.abort() - sys.exit(1) + return -1 userPerms = c.getElementsByTagName('permList') if not userPerms or len(userPerms) < 1: @@ -209,13 +255,13 @@ clusterSystems = c.getElementsByTagName('systemsList') if not clusterSystems or len(clusterSystems) < 1: - sys.stderr.write('No cluster storage systems to add\n') + verbose.write('Cluster \"' + id + '\" has no storage systems\n') continue clusterSystems = clusterSystems[0].getElementsByTagName('ref') for i in clusterSystems: newsys = i.getAttribute('name') if not newsys: - sys.stderr.write('Cluster system element missing name tag\n') + sys.stderr.write('Storage system missing name for cluster \"' + id + '\"\n') continue newsys = str(newsys) stitle = i.getAttribute('title') @@ -223,15 +269,26 @@ stitle = str(stitle) else: stitle = None + try: x.manage_addFolder(newsys, stitle) - + newcs = app.unrestrictedTraverse('/luci/systems/cluster/' + id + '/' + newsys) + if not newcs: + raise + except: + sys.stderr.write('An error occurred while restoring the storage system \"' + newsys + '\" for cluster \"' + id + '\"') + transaction.abort() + return -1 + verbose.write('Added storage system \"' + newsys + '\" for cluster \"' + id) + verbose.write('Added cluster\"' + id + '\"') #transaction.commit() + #transaction.commit() transaction.abort() conn.close() db.pack() db.close() fs.close() + return 0 # This function's ability to work is dependent # upon the structure of @dict @@ -290,39 +347,36 @@ sys.stderr.write('Unable to open \"' + backupfn + '\" to write backup.\n') sys.exit(1) - # To suppress some meaningless zope errors upon unpickling certain - # kinds of objects. - temp = sys.stderr - null = file('/dev/null') + # To suppress some useless zope error messages. + sys.stderr = null next_oid = None while True: oid, tid, data, next_oid = fs.record_iternext(next_oid) - sys.stderr = null try: obj = conn.get(oid) obj_class = str(type(obj)).split('\'')[1] except: - continue - sys.stderr = temp + if next_oid is None: break + else: continue if not obj_class in examine_classes: - continue + if next_oid is None: break + else: continue - # for some reason, when stderr is dumped to /dev/null - # something goes wrong here, which is why it's set and restored - # inside the loop. try: conn.setstate(obj) except: - continue + if next_oid is None: break + else: continue dict = obj.__dict__ if obj_class == 'OFS.Folder.Folder': if not 'title' in dict or dict['title'][0:9] != '__luci__:': - continue + if next_oid is None: break + else: continue title = dict['title'].split(':') cur = None @@ -350,7 +404,8 @@ cur = systems[dict['id']] else: # we don't care - continue + if next_oid is None: break + else: continue if cur: roles = dict['__ac_local_roles__'] @@ -373,7 +428,8 @@ cur_user['passwd'] = dict['__'] elif obj_class == 'Products.CMFCore.MemberDataTool.MemberData': if not 'id' in dict and not 'name' in dict: - continue + if next_oid is None: break + else: continue try: cur_user = users[dict['id']] @@ -388,7 +444,8 @@ cur_user[i] = dict[i] if next_oid is None: break - sys.stderr = temp + + sys.stderr = orig_stderr null.close() conn.close() db.close() @@ -411,7 +468,7 @@ luciData = doc.createElement('luci') doc.appendChild(luciData) dataNode = dataToXML(doc, backup, 'backupData') - + try: certfile = file(SSL_PRIVKEY_PATH, 'rb') output = certfile.read()