[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/site/luci/Extensions cluster_adapte ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-11-02 03:17:07

Modified files:
	luci/site/luci/Extensions: cluster_adapters.py 
	                           homebase_adapters.py 

Log message:
	homebase_adapters cleanup, logging, and exception robustness
	fix a bug that causes IP resource creation to fail in cluster_adapters

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.135&r2=1.136
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/homebase_adapters.py.diff?cvsroot=cluster&r1=1.38&r2=1.39

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/31 17:18:12	1.135
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/11/02 03:17:07	1.136
@@ -3090,7 +3090,11 @@
       rc = RicciCommunicator(ricci[0])
       finished = checkBatch(rc, item[1].getProperty(BATCH_ID))
       if finished == True:
-        node_report['desc'] = item[1].getProperty(FLAG_DESC) + REDIRECT_MSG
+        flag_desc = item[1].getProperty(FLAG_DESC)
+        if flag_desc is None:
+          node_report['desc'] = REDIRECT_MSG
+        else:
+          node_report['desc'] = flag_desc + REDIRECT_MSG
         nodereports.append(node_report)
         try:
             clusterfolder.manage_delObjects(item[0])
@@ -4009,7 +4013,7 @@
 		flag.manage_addProperty(BATCH_ID, batch_id, "string")
 		flag.manage_addProperty(TASKTYPE, RESOURCE_ADD, "string")
 
-		if type != 'ip':
+		if res.attr_hash['type'] != 'ip':
 			flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + res.attr_hash['name'] + "\'", "string")
 		else:
 			flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + res.attr_hash['address'] + "\'", "string")
--- conga/luci/site/luci/Extensions/homebase_adapters.py	2006/11/01 20:34:02	1.38
+++ conga/luci/site/luci/Extensions/homebase_adapters.py	2006/11/02 03:17:07	1.39
@@ -1,23 +1,20 @@
-import string
 import re
-import sys
 import os
 from AccessControl import getSecurityManager
-from ZPublisher import HTTPRequest
-import xml.dom
 import cgi
 
-from ricci_defines import *
+from conga_constants import PLONE_ROOT, CLUSTER_NODE_NEED_AUTH, \
+							HOMEBASE_ADD_CLUSTER, HOMEBASE_ADD_CLUSTER_INITIAL, \
+							HOMEBASE_ADD_SYSTEM, HOMEBASE_ADD_USER, \
+							HOMEBASE_DEL_SYSTEM, HOMEBASE_DEL_USER, HOMEBASE_PERMS
 from ricci_bridge import getClusterConf
-from ricci_communicator import RicciCommunicator
-from ricci_communicator import CERTS_DIR_PATH
+from ricci_communicator import RicciCommunicator, CERTS_DIR_PATH
 from clusterOS import resolveOSType
-from conga_constants import *
-from LuciSyslog import LuciSyslog, LuciSyslogError
+from LuciSyslog import LuciSyslog
 
 try:
 	luci_log = LuciSyslog()
-except LuciSyslogError, e:
+except:
 	pass
 
 def siteIsSetup(self):
@@ -27,8 +24,8 @@
 	except: pass
 	return False
 
-def strFilter(regex, replaceChar, str):
-	return re.sub(regex, replaceChar, str)
+def strFilter(regex, replaceChar, arg):
+	return re.sub(regex, replaceChar, arg)
 
 def validateDelSystem(self, request):
 	errors = list()
@@ -74,6 +71,8 @@
 
 	try:
 		user = self.portal_membership.getMemberById(userId)
+		if not user:
+			raise Exception, 'user %s does not exist' % userId
 	except:
 		return (False, {'errors': [ 'No such user: \"' + userId + '\"' ] })
 
@@ -531,7 +530,7 @@
 						i[1].manage_setLocalRoles(userId, roles)
 						messages.append('Added permission for ' + userId + ' for cluster ' + i[0])
 				except:
-						errors.append('Failed to add permission for ' + userId + ' for cluster ' + i[0])
+					errors.append('Failed to add permission for ' + userId + ' for cluster ' + i[0])
 			else:
 				try:
 					if user.has_role('View', i[1]):
@@ -545,7 +544,7 @@
 
 						messages.append('Removed permission for ' + userId + ' for cluster ' + i[0])
 				except:
-						errors.append('Failed to remove permission for ' + userId + ' for cluster ' + i[0])
+					errors.append('Failed to remove permission for ' + userId + ' for cluster ' + i[0])
 
 	storage = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/objectItems')('Folder')
 	if not '__SYSTEM' in request.form:
@@ -572,7 +571,7 @@
 						i[1].manage_setLocalRoles(userId, roles)
 						messages.append('Added permission for ' + userId + ' for system ' + i[0])
 				except:
-						errors.append('Failed to add permission for ' + userId + ' for system ' + i[0])
+					errors.append('Failed to add permission for ' + userId + ' for system ' + i[0])
 			else:
 				try:
 					if user.has_role('View', i[1]):
@@ -586,7 +585,7 @@
 
 						messages.append('Removed permission for ' + userId + ' for system ' + i[0])
 				except:
-						errors.append('Failed to remove permission for ' + userId + ' for system ' + i[0])
+					errors.append('Failed to remove permission for ' + userId + ' for system ' + i[0])
 
 	if len(errors) > 0:
 		returnCode = False
@@ -665,23 +664,25 @@
 ]
 
 def userAuthenticated(self):
-	if (isAdmin(self) or getSecurityManager().getUser().has_role('Authenticated', self.restrictedTraverse(PLONE_ROOT))):
-		return True
-
+	try:
+		if (isAdmin(self) or getSecurityManager().getUser().has_role('Authenticated', self.restrictedTraverse(PLONE_ROOT))):
+			return True
+	except Exception, e:
+		luci_log.debug_verbose('UA0: %s' % str(e)) 
 	return False
 
 def isAdmin(self):
 	try:
 		return getSecurityManager().getUser().has_role('Owner', self.restrictedTraverse(PLONE_ROOT))
-	except:
-		pass
+	except Exception, e:
+		luci_log.debug_verbose('IA0: %s' % str(e)) 
 	return False
 
 def userIsAdmin(self, userId):
 	try:
 		return self.portal_membership.getMemberById(userId).has_role('Owner', self.restrictedTraverse(PLONE_ROOT))
-	except:
-		pass
+	except Exception, e:
+		luci_log.debug_verbose('UIA0: %s: %s' % (userId, str(e)))
 	return False
 
 def homebaseControlPost(self, request):
@@ -698,15 +699,19 @@
 	if 'pagetype' in request.form:
 		pagetype = int(request.form['pagetype'])
 	else:
-		try: request.SESSION.set('checkRet', {})
-		except: pass
+		try:
+			request.SESSION.set('checkRet', {})
+		except:
+			pass
 		return homebasePortal(self, request, '.', '0')
 
 	try:
 		validatorFn = formValidators[pagetype - 1]
 	except:
-		try: request.SESSION.set('checkRet', {})
-		except: pass
+		try:
+			request.SESSION.set('checkRet', {})
+		except:
+			pass
 		return homebasePortal(self, request, '.', '0')
 
 	if validatorFn == validateAddClusterInitial or validatorFn == validateAddCluster:
@@ -913,71 +918,111 @@
 
 def getClusterSystems(self, clusterName):
 	if isAdmin(self):
-		return self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName + '/objectItems')('Folder')
+		try:
+			return self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName + '/objectItems')('Folder')
+		except Exception, e:
+			luci_log.debug_verbose('GCS0: %s: %s' % (clusterName, str(e)))
+			return None
 
 	try:
 		i = getSecurityManager().getUser()
 		if not i:
-			raise
-	except:
+			raise Exception, 'GCSMGU failed'
+	except Exception, e:
+		luci_log.debug_verbose('GCS1: %s: %s' % (clusterName, str(e)))
 		return None
 
-	csystems = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName + '/objectItems')('Folder')
-	if not csystems:
+	try:
+		csystems = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName + '/objectItems')('Folder')
+		if not csystems or len(csystems) < 1:
+			return None
+	except Exception, e:
+		luci_log.debug_verbose('GCS2: %s: %s' % (clusterName, str(e)))
 		return None
 
 	allowedCSystems = list()
 	for c in csystems:
-		if i.has_role('View', c[1]):
-			allowedCSystems.append(c)
-	return (c)
+		try:
+			if i.has_role('View', c[1]):
+				allowedCSystems.append(c)
+		except Exception, e:
+			luci_log.debug_verbose('GCS3: %s: %s: %s' \
+				% (clusterName, c[0], str(e)))
+
+	return allowedCSystems
 
 def getClusters(self):
 	if isAdmin(self):
-		return self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/objectItems')('Folder')
+		try:
+			return self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/objectItems')('Folder')
+		except Exception, e:
+			luci_log.debug_verbose('GC0: %s' % str(e))
+			return None
 	try:
 		i = getSecurityManager().getUser()
 		if not i:
-			raise
-	except:
+			raise Exception, 'GSMGU failed'
+	except Exception, e:
+		luci_log.debug_verbose('GC1: %s' % str(e))
 		return None
 
-	clusters = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/objectItems')('Folder')
-	if not clusters:
+	try:
+		clusters = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/objectItems')('Folder')
+		if not clusters or len(clusters) < 1:
+			return None
+	except Exception, e:
+		luci_log.debug_verbose('GC2: %s' % str(e))
 		return None
 
 	allowedClusters = list()
 	for c in clusters:
-		if i.has_role('View', c[1]):
-			allowedClusters.append(c)
+		try:
+			if i.has_role('View', c[1]):
+				allowedClusters.append(c)
+		except Exception, e:
+			luci_log.debug_verbose('GC3: %s: %s' % (c[0], str(e)))
 
 	return allowedClusters
 
 def getStorage(self):
 	if isAdmin(self):
-		return self.restrictedTraverse(PLONE_ROOT + '/systems/storage/objectItems')('Folder')
+		try:
+			return self.restrictedTraverse(PLONE_ROOT + '/systems/storage/objectItems')('Folder')
+		except Exception, e:
+			luci_log.debug_verbose('GS0: %s' % str(e))
+			return None
+
 	try:
 		i = getSecurityManager().getUser()
 		if not i:
-			return None
-	except:
+			raise Exception, 'GSMGU failed'
+	except Exception, e:
+		luci_log.debug_verbose('GS1: %s' % str(e))
 		return None
 
-	storage = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/objectItems')('Folder')
-	if not storage:
+	try:
+		storage = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/objectItems')('Folder')
+		if not storage or len(storage) < 1:
+			return None
+	except Exception, e:
+		luci_log.debug_verbose('GS2: %s' % str(e))
 		return None
 
 	allowedStorage = list()
 	for s in storage:
-		if i.has_role('View', s[1]):
-			allowedStorage.append(s)
+		try:
+			if i.has_role('View', s[1]):
+				allowedStorage.append(s)
+		except Exception, e:
+			luci_log.debug_verbose('GS3: %s' % str(e))
 
 	return allowedStorage
 
 def createSystem(self, host, passwd):
 	try:
 		exists = self.restrictedTraverse(PLONE_ROOT +'/systems/storage/' + host)
-		return 'Storage system \"' + host + '\" is already managed.'
+		luci_log.debug_verbose('CS0: %s already exists' % host)
+		return 'Storage system %s is already managed' % host
 	except:
 		pass
 
@@ -986,49 +1031,52 @@
 		if rc is None:
 			raise Exception, 'unknown error'
 	except Exception, e:
+		luci_log.debug_verbose('CS1: %s: %s' % (host, str(e)))
 		return 'Unable to establish a connection to the ricci agent on %s: %s' \
 			% (host, str(e))
 
 	try:
 		if not rc.authed():
 			rc.auth(passwd)
-	except:
-		return 'Unable to communicate with the ricci agent on \"' + host + '\" for authentication'
+	except Exception, e:
+		luci_log.debug_verbose('CS2: %s: %s' % (host, str(e)))
+		return 'Unable to communicate with the ricci agent on %s for authentication' % host
 
 	try:
 		i = rc.authed()
-	except:
-		return 'Unable to authenticate to the ricci agent on \"' + host + '\"'
+	except Exception, e:
+		luci_log.debug_verbose('CS3 %s: %s' % (host, str(e)))
+		return 'Unable to authenticate to the ricci agent on %s' % host
 
 	if i != True:
-		return 'Authentication for storage system \"' + host + '\" failed'
-
-#	rhost = rc.system_name()
-#	if rhost and rhost != host and rhost[:9] != 'localhost' and rhost[:5] != '127.0':
-#		host = str(rhost)
+		return 'Authentication for storage system %s failed' % host
 
 	try:
-		exists = self.restrictedTraverse(PLONE_ROOT +'/systems/storage/' + host)
-		return 'Storage system \"' + host + '\" is already managed.'
+		exists = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
+		luci_log.debug_verbose('CS4 %s already exists' % host)
+		return 'Storage system %s is already managed' % host
 	except:
 		pass
 
 	try:
 		ssystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/')
 	except Exception, e:
-		return 'Unable to create storage system %s: %s' % (host, str(e))
+		luci_log.debug_verbose('CS5 %s: %s' % (host, str(e)))
+		return 'Unable to create storage system %s: %s' % host
 
 	try:
 		ssystem.manage_addFolder(host, '__luci__:system')
 		newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
 	except Exception, e:
-		return 'Unable to create storage system %s: %s' % (host, str(e))
+		luci_log.debug_verbose('CS6 %s: %s' % (host, str(e)))
+		return 'Unable to create DB entry for storage system %s' % host
 
 	try:
 		newSystem.manage_acquiredPermissions([])
-		newSystem.manage_role('View', ['Access contents information','View'])
+		newSystem.manage_role('View', ['Access contents information', 'View'])
 	except Exception, e:
-		return 'Unable to set permissions on storage system %s: %s' % (host, str(e))
+		luci_log.debug_verbose('CS7 %s: %s' % (host, str(e)))
+		return 'Unable to set permissions on storage system %s' % host
 
 	return None
 
@@ -1036,26 +1084,27 @@
 	try:
 		sessionData = request.SESSION.get('checkRet')
 		nodeUnauth(sessionData['requestResults']['nodeList'])
-	except:
-		pass
+	except Exception, e:
+		luci_log.debug_verbose('AMC0: %s' % str(e))
 
 def manageCluster(self, clusterName, nodeList):
 	clusterName = str(clusterName)
-	luci_log.debug_verbose('manageCluster for %s' % clusterName)
 
 	try:
 		clusters = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/')
 		if not clusters:
 			raise Exception, 'cannot find the cluster entry in the DB'
-	except:
+	except Exception, e:
 		nodeUnauth(nodeList)
-		return 'Unable to create cluster \"' + clusterName + '\": the cluster directory is missing.'
+		luci_log.debug_verbose('MC0: %s: %s' % (clusterName, str(e)))
+		return 'Unable to create cluster %s: the cluster directory is missing.' % clusterName
 
 	try:
 		newCluster = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName)
 		if newCluster:
 			nodeUnauth(nodeList)
-			return 'A cluster named \"' + clusterName + '\" is already managed by Luci'
+			luci_log.debug_verbose('MC1: cluster %s: already exists' % clusterName)
+			return 'A cluster named %s is already managed by Luci' % clusterName
 	except:
 		pass
 
@@ -1063,20 +1112,22 @@
 		clusters.manage_addFolder(clusterName, '__luci__:cluster')
 		newCluster = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName)
 		if not newCluster:
-			raise Exception, 'unable to find cluster folder for %s' % clusterName
+			raise Exception, 'unable to create the cluster DB entry for %s' % clusterName
 	except Exception, e:
 		nodeUnauth(nodeList)
+		luci_log.debug_verbose('MC2: %s: %s' % (clusterName, str(e)))
 		return 'Unable to create cluster %s: %s' % (clusterName, str(e))
 
 	try:
 		newCluster.manage_acquiredPermissions([])
-		newCluster.manage_role('View', ['Access Contents Information','View'])
+		newCluster.manage_role('View', ['Access Contents Information', 'View'])
 	except Exception, e:
+		luci_log.debug_verbose('MC3: %s: %s' % (clusterName, str(e)))
 		nodeUnauth(nodeList)
 		try:
 			clusters.manage_delObjects([clusterName])
-		except:
-			pass
+		except Exception, e:
+			luci_log.debug_verbose('MC4: %s: %s' % (clusterName, str(e)))
 		return 'Unable to set permissions on new cluster: %s: %s' % (clusterName, str(e))
 
 	try:
@@ -1084,14 +1135,14 @@
 		if not cluster_os:
 			raise KeyError, 'Cluster OS is blank'
 	except KeyError, e:
-		luci_log.debug_verbose('Warning adding cluster %s: %s' \
-			% (clusterName, str(e)))
+		luci_log.debug_verbose('MC5: %s: %s' % (clusterName, str(e)))
 		cluster_os = 'rhel5'
 
 	try:
 		newCluster.manage_addProperty('cluster_os', cluster_os, 'string')
-	except:
-		pass # we were unable to set the OS property string on this cluster
+	except Exception, e:
+		luci_log.debug_verbose('MC5: %s: %s: %s' \
+			% (clusterName, cluster_os, str(e)))
 
 	for i in nodeList:
 		#if 'ricci_host' in i:
@@ -1103,15 +1154,19 @@
 			newCluster.manage_addFolder(host, '__luci__:csystem:' + clusterName)
 			newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName + '/' + host)
 			if not newSystem:
-				raise Exception, 'unable to create cluster system DB entry'
+				raise Exception, 'unable to create cluster system DB entry for node %s' % host
 			newSystem.manage_acquiredPermissions([])
 			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
 		except Exception, e:
 			nodeUnauth(nodeList)
 			try:
 				clusters.manage_delObjects([clusterName])
-			except:
-				pass
+			except Exception, e:
+				luci_log.debug_verbose('MC6: %s: %s: %s' \
+					% (clusterName, host, str(e)))
+
+			luci_log.debug_verbose('MC7: %s: %s: %s' \
+				% (clusterName, host, str(e)))
 			return 'Unable to create cluster node %s for cluster %s: %s' \
 				% (host, clusterName, str(e))
 
@@ -1120,6 +1175,7 @@
 		if not ssystem:
 			raise Exception, 'The storage DB entry is missing'
 	except Exception, e:
+		luci_log.debug_verbose('MC8: %s: %s: %s' % (clusterName, host, str(e)))
 		return 'Error adding storage node %s: %s' % (host, str(e))
 
 	# Only add storage systems if the cluster and cluster node DB
@@ -1134,22 +1190,25 @@
 			# It's already there, as a storage system, no problem.
 			exists = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
 			continue
-		except: pass
+		except:
+			pass
 
 		try:
 			ssystem.manage_addFolder(host, '__luci__:system')
 			newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
 			newSystem.manage_acquiredPermissions([])
 			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
-		except: pass
+		except Exception, e:
+			luci_log.debug_verbose('MC9: %s: %s: %s' % (clusterName, host, str(e)))
 
 def createClusterSystems(self, clusterName, nodeList):
 	try:
 		clusterObj = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName)
 		if not clusterObj:
 			raise Exception, 'cluster %s DB entry is missing' % clusterName
-	except:
+	except Exception, e:
 		nodeUnauth(nodeList)
+		luci_log.debug_verbose('CCS0: %s: %s' % (clusterName, str(e)))
 		return 'No cluster named \"' + clusterName + '\" is managed by Luci'
 
 	for i in nodeList:
@@ -1168,6 +1227,7 @@
 			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
 		except Exception, e:
 			nodeUnauth(nodeList)
+			luci_log.debug_verbose('CCS1: %s: %s: %s' % (clusterName, host, str(e)))
 			return 'Unable to create cluster node %s for cluster %s: %s' \
 				% (host, clusterName, str(e))
 
@@ -1176,8 +1236,7 @@
 		if not ssystem:
 			raise Exception, 'storage DB entry is missing'
 	except Exception, e:
-		luci_log.debug_verbose('Error: adding storage DB node for %s: %s' \
-			% (host, str(e)))
+		luci_log.debug_verbose('CCS2: %s: %s' % (clusterName, host, str(e)))
 		return
 
 	# Only add storage systems if the and cluster node DB
@@ -1192,14 +1251,16 @@
 			# It's already there, as a storage system, no problem.
 			exists = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
 			continue
-		except: pass
+		except:
+			pass
 
 		try:
 			ssystem.manage_addFolder(host, '__luci__:system')
 			newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
 			newSystem.manage_acquiredPermissions([])
 			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
-		except: pass
+		except Exception, e:
+			luci_log.debug_verbose('CCS3: %s: %s' % (clusterName, host, str(e)))
 
 def delSystem(self, systemName):
 	try:
@@ -1207,6 +1268,7 @@
 		if not ssystem:
 			raise Exception, 'storage DB entry is missing'
 	except Exception, e:
+		luci_log.debug_verbose('delSystem0: %s: %s' % (systemName, str(e)))
 		return 'Unable to find storage system %s: %s' % (systemName, str(e))
 
 	try:
@@ -1216,27 +1278,33 @@
 	except Exception, e:
 		try:
 			ssystem.manage_delObjects([systemName])
-		except:
-			return 'Unable to delete the storage system \"' + systemName + '\"'
-		luci_log.debug_verbose('ricci error for %s: %s' % (systemName, str(e)))
+		except Exception, e:
+			luci_log.debug_verbose('delSystem1: %s: %s' % (systemName, str(e)))
+			return 'Unable to delete the storage system %s' % systemName
+		luci_log.debug_verbose('delSystem2: %s: %s' % (systemName, str(e)))
 		return
 
 	# Only unauthenticate if the system isn't a member of
 	# a managed cluster.
 	cluster_info = rc.cluster_info()
 	if not cluster_info[0]:
-		try: rc.unauth()
-		except: pass
+		try:
+			rc.unauth()
+		except:
+			pass
 	else:
 		try:
 			newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + cluster_info[0] + '/' + systemName)
 		except:
-			try: rc.unauth()
-			except: pass
+			try:
+				rc.unauth()
+			except:
+				pass
 
 	try:
 		ssystem.manage_delObjects([systemName])
 	except Exception, e:
+		luci_log.debug_verbose('delSystem3: %s: %s' % (systemName, str(e)))
 		return 'Unable to delete storage system %s: %s' \
 			% (systemName, str(e))
 
@@ -1244,9 +1312,10 @@
 	try:
 		clusters = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/')
 		if not clusters:
-			raise
-	except:
-		return 'Unable to find cluster \"' + clusterName + '\"'
+			raise Exception, 'clusters DB entry is missing'
+	except Exception, e:
+		luci_log.debug_verbose('delCluster0: %s' % str(e))
+		return 'Unable to find cluster %s' % clusterName
 
 	err = delClusterSystems(self, clusterName)
 	if err:
@@ -1254,26 +1323,28 @@
 
 	try:
 		clusters.manage_delObjects([clusterName])
-	except:
-		return 'Unable to delete cluster \"' + clusterName + '\"'
+	except Exception, e:
+		luci_log.debug_verbose('delCluster1: %s' % str(e))
+		return 'Unable to delete cluster %s' % clusterName
 
 def delClusterSystem(self, cluster, systemName):
 	try:
 		if not self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + systemName):
 			raise
 	except:
+		# It's not a storage system, so unauthenticate.
 		try:
 			rc = RicciCommunicator(systemName)
 			rc.unauth()
 		except Exception, e:
-			luci_log.debug_verbose('ricci error for %s: %s' \
+			luci_log.debug_verbose('delClusterSystem0: ricci error for %s: %s' \
 				% (systemName, str(e)))
 
 	try:
 		cluster.manage_delObjects([systemName])
 	except Exception, e:
 		err_str = 'Error deleting cluster object %s: %s' % (systemName, str(e))
-		luci_log.debug_verbose(err_str)
+		luci_log.debug_verbose('delClusterSystem1: %s' % err_str)
 		return err_str
 
 def delClusterSystems(self, clusterName):
@@ -1285,7 +1356,7 @@
 	except Exception, e:
 		luci_log.debug_verbose('delCluSysterms: error for %s: %s' \
 			% (clusterName, str(e)))
-		return 'Unable to find any systems for cluster \"' + clusterName + '\"'
+		return 'Unable to find any systems for cluster %s' % clusterName
 
 	errors = ''
 	for i in csystems:
@@ -1297,34 +1368,65 @@
 def getDefaultUser(self, request):
 	try:
 		user = request.form['userList']
-	except:
+	except KeyError, e:
 		try:
 			user = request['user']
 		except:
 			try:
-				user = self.portal_membership.listMembers()[0].getUserName()
-			except:
+				members = list()
+				members.extend(self.portal_membership.listMembers())
+				members.sort()
+				user = members[0].getUserName()
+			except Exception, e:
+				luci_log.debug_verbose('getDefaultUser0: %s' % str(e))
 				user = None
 
+	if not user:
+		luci_log.debug_verbose('getDefaultUser1: user is none')
 	return user
 
 def getUserPerms(self):
 	perms = {}
-	for i in self.portal_membership.listMembers():
+
+	try:
+		members = list()
+		members.extend(self.portal_membership.listMembers())
+		if len(members) < 1:
+			raise Exception, 'no portal members exist'
+		members.sort()
+	except Exception, e:
+		luci_log.debug_verbose('getUserPerms0: %s' % str(e))
+		return {}
+
+	for i in members:
 		userName = i.getUserName()
 
 		perms[userName] = {}
 		perms[userName]['cluster'] = {}
 		perms[userName]['storage'] = {}
 
-		clusters = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/objectItems')('Folder')
-		storage = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/objectItems')('Folder')
+		try:
+			clusters = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/objectItems')('Folder')
+			storage = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/objectItems')('Folder')
+		except Exception, e:
+			luci_log.debug_verbose('getUserPerms1: user %s: %s' % (userName, str(e)))
+			continue
 
 		for c in clusters:
-			perms[userName]['cluster'][c[0]] = i.has_role('View', c[1])
-
+			try:
+				perms[userName]['cluster'][c[0]] = i.has_role('View', c[1])
+			except Exception, e:
+				luci_log.debug_verbose('getUserPerms2: user %s, obj %s: %s' \
+					% (userName, c[0], str(e)))
+				continue
+				
 		for s in storage:
-			perms[userName]['storage'][s[0]] = i.has_role('View', s[1])
+			try:
+				perms[userName]['storage'][s[0]] = i.has_role('View', s[1])
+			except Exception, e:
+				luci_log.debug_verbose('getUserPerms2: user %s, obj %s: %s' \
+					% (userName, s[0], str(e)))
+				continue
 
 	return perms
 
@@ -1397,39 +1499,52 @@
 def getClusterNode(self, nodename, clustername):
 	try:
 		cluster_node = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + str(clustername) + '/' + str(nodename))
+		if not cluster_node:
+			raise Exception, 'cluster node is none'
 		return cluster_node
-	except:
+	except Exception, e:
+		luci_log.debug_verbose('getClusterNode0: %s %s: %s' \
+			% (nodename, clustername, str(e)))
 		return None
 
 def getStorageNode(self, nodename):
 	try:
 		storage_node = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + '/' + str(nodename))
+		if not storage_node:
+			raise Exception, 'storage node is none'
 		return storage_node
-	except:
+	except Exception, e:
+		luci_log.debug_verbose('getStorageNode0: %s: %s' % (nodename, str(e)))
 		return None
 
 def testNodeFlag(node, flag_mask):
 	try:
 		flags = node.getProperty('flags')
+		if flags is None:
+			return False
 		return flags & flag_mask != 0
-	except:
-		pass
+	except Exception, e:
+		luci_log.debug_verbose('testNodeFlag0: %s' % str(e))
 	return False
 
 def setNodeFlag(node, flag_mask):
 	try:
 		flags = node.getProperty('flags')
+		if flags is None:
+			flags = 0
 		node.manage_changeProperties({ 'flags': flags | flag_mask })
 	except:
 		try:
 			node.manage_addProperty('flags', flag_mask, 'int')
-		except:
-			pass
+		except Exception, e:
+			luci_log.debug_verbose('setNodeFlag0: %s' % str(e))
 
 def delNodeFlag(node, flag_mask):
 	try:
 		flags = node.getProperty('flags')
+		if flags is None:
+			return
 		if flags & flag_mask != 0:
 			node.manage_changeProperties({ 'flags': flags & ~flag_mask })
-	except:
-		pass
+	except Exception, e:
+		luci_log.debug_verbose('delNodeFlag0: %s' % str(e))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]