[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-12-14 21:37:15

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

Log message:
	more fixes for delete cluster

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.182&r2=1.183
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/homebase_adapters.py.diff?cvsroot=cluster&r1=1.40&r2=1.41

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/12/14 18:22:53	1.182
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/12/14 21:37:15	1.183
@@ -1850,8 +1850,16 @@
 			luci_log.debug('GRA1: no cluster nodes for %s found.' % clustername)
 			raise Exception, 'no cluster nodes were found at %s' % path
 	except Exception, e:
-		luci_log.debug('GRA2: cluster folder %s for %s is missing: %s.' \
-			% (path, clustername, str(e)))
+		try:
+			luci_log.debug('GRA2: cluster folder %s for %s is missing: %s.' \
+				% (path, clustername, str(e)))
+
+			if len(clusterfolder.objectItems()) < 1:
+				clusters = self.restrictedTraverse(str(CLUSTER_FOLDER_PATH))
+				clusters.manage_delObjects([clustername])
+		except Exception, e:
+			luci_log.debug_verbose('GRA3: %s' % str(e))
+
 		return None
 
 	cluname = lower(clustername)
@@ -2040,7 +2048,7 @@
 		luci_log.debug_verbose('GCS0: error: %s' % str(e))
 		doc = None
 
-	if doc is None:
+	if doc is None and not cluname:
 		try:
 			model = request.SESSION.get('model')
 			cinfo = getClusterStatusModel(model)
@@ -2832,7 +2840,7 @@
 			continue
 
 		if delete is True:
-			if nodeDelete(self, rc, model, clustername, nodename, nodename_resolved) is None:
+			if nodeDelete(self, rc, model, clustername, nodename, nodename_resolved, delete_cluster=True) is None:
 				luci_log.debug_verbose('CStop1: nodeDelete failed')
 				errors += 1
 		else:
@@ -2852,7 +2860,8 @@
 	return snum_err + jnum_err
 
 def clusterDelete(self, model):
-	if clusterStop(self, model, delete=True) < 1:
+	num_errors = clusterStop(self, model, delete=True)
+	if num_errors < 1:
 		try:
 			clustername = model.getClusterName()
 		except Exception, e:
@@ -2862,8 +2871,20 @@
 		try:
 			delCluster(self, clustername)
 		except Exception, e:
-			luci_log.debug_verbose('clusterDelete0: %s: %s' \
+			luci_log.debug_verbose('clusterDelete1: %s: %s' \
+				% (clustername, str(e)))
+
+		try:
+			clusterfolder = self.restrictedTraverse(str(CLUSTER_FOLDER_PATH + clustername))
+			if len(clusterfolder.objectItems()) < 1:
+				clusters = self.restrictedTraverse(str(CLUSTER_FOLDER_PATH))
+				clusters.manage_delObjects([clustername])
+		except Exception, e:
+			luci_log.debug_verbose('clusterDelete2: %s %s' \
 				% (clustername, str(e)))
+	else:
+		luci_log.debug_verbose('clusterDelete2: %s: %d errors' \
+			% (clustername, num_errors))
 
 def forceNodeReboot(self, rc, clustername, nodename_resolved):
 	batch_number, result = nodeReboot(rc)
@@ -2943,21 +2964,14 @@
 		luci_log.debug_verbose('FNF4: failed to set flags: %s' % str(e))
 	return True
 
-def nodeDelete(self, rc, model, clustername, nodename, nodename_resolved):
+def nodeDelete(self, rc, model, clustername, nodename, nodename_resolved, delete_cluster=False):
 	# We need to get a node name other than the node
 	# to be deleted, then delete the node from the cluster.conf
 	# and propogate it. We will need two ricci agents for this task,
-	# unless we are deleting the last remaining cluster node.
+	# unless we are deleting the cluster itself.
 
-	if len(model.getNodes()) == 1:
-		# If this is the last cluster node, we don't need a second
-		# node to propagate a new cluster.conf file. We need only to
-		# stop the final node and delete its cluster.conf file.
-		last_node = True
-	else:
+	if not delete_cluster:
 		# Make sure we can find a second node before we hose anything.
-
-		last_node = False
 		found_one = False
 
 		path = str(CLUSTER_FOLDER_PATH + clustername)
@@ -3024,32 +3038,40 @@
 		luci_log.debug_verbose('ND5: batch_number and/or result is None')
 		return None
 
-	# It is not worth flagging this node in DB, as we are going
-	# to delete it anyway. Now, we need to delete node from model
-	# and send out new cluster.conf
-	delete_target = None
-	nodelist = model.getNodes()
-	find_node = lower(nodename)
-	for n in nodelist:
+	# Unless we're deleting the whole cluster, it is not worth
+	# flagging this node in DB, as we are going to delete it
+	# anyway. Now, we need to delete node from model and send out
+	# new cluster.conf
+
+	if delete_cluster:
 		try:
-			if lower(n.getName()) == find_node:
-				delete_target = n
-				break
-		except:
-			continue
+			set_node_flag(self, clustername, rc.hostname(), str(batch_number), NODE_DELETE, "Deleting cluster \"%s\": Deleting node \'%s\'" \
+				% (clustername, nodename_resolved))
+		except Exception, e:
+			luci_log.debug_verbose('ND5a: failed to set flags: %s' % str(e))
+	else:
+		delete_target = None
+		nodelist = model.getNodes()
+		find_node = lower(nodename)
+		for n in nodelist:
+			try:
+				if lower(n.getName()) == find_node:
+					delete_target = n
+					break
+			except:
+				continue
 
-	if delete_target is None:
-		luci_log.debug_verbose('ND6: no delete target for %s in cluster %s' \
-			% (nodename, clustername))
-		return None
+		if delete_target is None:
+			luci_log.debug_verbose('ND6: no delete target for %s in cluster %s' \
+				% (nodename, clustername))
+			return None
 
-	try:
-		model.deleteNode(delete_target)
-	except Exception, e:
-		luci_log.debug_verbose('ND6a: deleteNode %s failed: %s' \
-			% (delete_target.getName(), str(e)))
+		try:
+			model.deleteNode(delete_target)
+		except Exception, e:
+			luci_log.debug_verbose('ND6a: deleteNode %s failed: %s' \
+				% (delete_target.getName(), str(e)))
 
-	if not last_node:
 		try:
 			str_buf = model.exportModelAsString()
 			if not str_buf:
@@ -3066,22 +3088,20 @@
 
 	# Now we need to delete the node from the DB
 	path = str(CLUSTER_FOLDER_PATH + clustername)
-	del_path = str(path + '/' + nodename_resolved)
-
 	try:
-		delnode = self.restrictedTraverse(del_path)
 		clusterfolder = self.restrictedTraverse(path)
-		clusterfolder.manage_delObjects(delnode[0])
+		clusterfolder.manage_delObjects([nodename_resolved])
 	except Exception, e:
-		luci_log.debug_verbose('ND9: error deleting %s: %s' \
-			% (del_path, str(e)))
+		luci_log.debug_verbose('ND9: error deleting %s at %s: %s' \
+			% (nodename_resolved, path, str(e)))
 
-	if not last_node:
-		try:
-			set_node_flag(self, clustername, rc2.hostname(), str(batch_number), NODE_DELETE, "Deleting node \'%s\'" % nodename_resolved)
-		except Exception, e:
-			luci_log.debug_verbose('ND10: failed to set flags: %s' % str(e))
+	if delete_cluster:
+		return True
 
+	try:
+		set_node_flag(self, clustername, rc2.hostname(), str(batch_number), NODE_DELETE, "Deleting node \'%s\'" % nodename_resolved)
+	except Exception, e:
+		luci_log.debug_verbose('ND10: failed to set flags: %s' % str(e))
 	return True
 
 def nodeTaskProcess(self, model, request):
@@ -5293,6 +5313,7 @@
 	batch_id = str(batchid)
 	objname = str(agent + '____flag')
 
+	objpath = ''
 	try:
 		clusterfolder = self.restrictedTraverse(path)
 		clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
--- conga/luci/site/luci/Extensions/homebase_adapters.py	2006/11/02 21:12:07	1.40
+++ conga/luci/site/luci/Extensions/homebase_adapters.py	2006/12/14 21:37:15	1.41
@@ -925,15 +925,15 @@
 		try:
 			return self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName + '/objectItems')('Folder')
 		except Exception, e:
-			luci_log.debug_verbose('GCS0: %s: %s' % (clusterName, str(e)))
+			luci_log.debug_verbose('GCSy0: %s: %s' % (clusterName, str(e)))
 			return None
 
 	try:
 		i = getSecurityManager().getUser()
 		if not i:
-			raise Exception, 'GCSMGU failed'
+			raise Exception, 'security manager says no user'
 	except Exception, e:
-		luci_log.debug_verbose('GCS1: %s: %s' % (clusterName, str(e)))
+		luci_log.debug_verbose('GCSy1: %s: %s' % (clusterName, str(e)))
 		return None
 
 	try:
@@ -941,7 +941,7 @@
 		if not csystems or len(csystems) < 1:
 			return None
 	except Exception, e:
-		luci_log.debug_verbose('GCS2: %s: %s' % (clusterName, str(e)))
+		luci_log.debug_verbose('GCSy2: %s: %s' % (clusterName, str(e)))
 		return None
 
 	allowedCSystems = list()
@@ -950,7 +950,7 @@
 			if i.has_role('View', c[1]):
 				allowedCSystems.append(c)
 		except Exception, e:
-			luci_log.debug_verbose('GCS3: %s: %s: %s' \
+			luci_log.debug_verbose('GCSy3: %s: %s: %s' \
 				% (clusterName, c[0], str(e)))
 
 	return allowedCSystems
@@ -1356,17 +1356,25 @@
 		cluster = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName)
 		if not cluster:
 			raise Exception, 'cluster DB entry is missing'
-		csystems = getClusterSystems(self, clusterName)
-	except Exception, e:
-		luci_log.debug_verbose('delCluSysterms: error for %s: %s' \
-			% (clusterName, str(e)))
-		return 'Unable to find any systems for cluster %s' % clusterName
+
+		try:
+			csystems = getClusterSystems(self, clusterName)
+			if not csystems or len(csystems) < 1:
+				return None
+		except Exception, e:
+			luci_log.debug_verbose('delCluSystems0: %s' % str(e))
+			return None
+	except Exception, er:
+		luci_log.debug_verbose('delCluSystems1: error for %s: %s' \
+			% (clusterName, str(er)))
+		return str(er)
 
 	errors = ''
 	for i in csystems:
 		err = delClusterSystem(self, cluster, i[0])
 		if err:
 			errors += 'Unable to delete the cluster system %s: %s\n' % (i[0], err)
+			luci_log.debug_verbose('delCluSystems2: %s' % err)
 	return errors
 
 def getDefaultUser(self, request):


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