From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 26 Oct 2006 22:59:14 -0000 Subject: [Cluster-devel] conga/luci/site/luci/Extensions ModelBuilder.p ... Message-ID: <20061026225914.26566.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-10-26 22:59:13 Modified files: luci/site/luci/Extensions: ModelBuilder.py cluster_adapters.py ricci_bridge.py Log message: - fix for broken exportModelAsString() - fix for broken resource add/edit handler - lots more debugging and verbose exception handling Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ModelBuilder.py.diff?cvsroot=cluster&r1=1.9&r2=1.10 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.129&r2=1.130 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_bridge.py.diff?cvsroot=cluster&r1=1.35&r2=1.36 --- conga/luci/site/luci/Extensions/ModelBuilder.py 2006/10/24 15:05:28 1.9 +++ conga/luci/site/luci/Extensions/ModelBuilder.py 2006/10/26 22:59:13 1.10 @@ -416,9 +416,9 @@ return True - def exportModelAsString(self, strbuf): + def exportModelAsString(self): if self.perform_final_check() == False: # failed - return False + return None #check for dual power fences self.dual_power_fence_check() @@ -438,7 +438,7 @@ #can be used self.purgePCDuplicates() - return True + return strbuf def has_filepath(self): if self.filename == None: --- conga/luci/site/luci/Extensions/cluster_adapters.py 2006/10/25 01:11:08 1.129 +++ conga/luci/site/luci/Extensions/cluster_adapters.py 2006/10/26 22:59:13 1.130 @@ -258,7 +258,6 @@ flag.manage_addProperty(FLAG_DESC,"Creating node " + key + " for cluster " + clusterName, "string") flag.manage_addProperty(LAST_STATUS, 0, "int") - def validateAddClusterNode(self, request): errors = list() messages = list() @@ -441,7 +440,7 @@ return (False, {'errors': ['An invalid resource type was specified: ' + res_type]}) try: - resObj = resourceAddHandler[res_type](self, dummy_form) + resObj = resourceAddHandler[res_type](request, dummy_form) except: luci_log('res type %d is invalid' % res_type) resObj = None @@ -453,11 +452,32 @@ return (True, {'messages': ['This service has been updated.']}) def validateResourceAdd(self, request): - return (True, {}) - -def validateResourceEdit(self, request): - return (True, {}) + try: + res_type = request.form['type'].strip() + if not res_type: + raise KeyError, 'type is blank' + except Exception, e: + luci_log.debug_verbose('resourceAdd: type is blank') + return (False, {'errors': ['No resource type was given.']}) + + errors = list() + try: + res = resourceAddHandler[res_type](request) + if res is None or res[0] is None or res[1] is None: + if res and res[2]: + errors.extend(res[2]) + raise Exception, 'An error occurred while adding this resource' + modelb = res[1] + newres = res[0] + addResource(self, request, modelb, newres) + except Exception, e: + if len(errors) < 1: + errors.append('An error occurred while adding this resource') + luci_log.debug_verbose('resource error: %s' % str(e)) + return (False, {'errors': errors}) + return (True, {'messages': ['Resource added successfully']}) + ## Cluster properties form validation routines def validateMCastConfig(self, form): @@ -705,7 +725,7 @@ 21: validateServiceAdd, 24: validateServiceAdd, 31: validateResourceAdd, - 33: validateResourceEdit, + 33: validateResourceAdd, 51: validateFenceAdd, 50: validateFenceEdit, } @@ -1331,19 +1351,21 @@ def getRicciAgent(self, clustername): #Check cluster permission here! return none if false - path = CLUSTER_FOLDER_PATH + clustername + path = str(CLUSTER_FOLDER_PATH + clustername) try: clusterfolder = self.restrictedTraverse(path) if not clusterfolder: - luci_log.debug('cluster folder %s for %s is missing.' \ + luci_log.debug('GRA: cluster folder %s for %s is missing.' \ % (path, clustername)) - raise + raise Exception, 'no cluster folder at %s' % path nodes = clusterfolder.objectItems('Folder') if len(nodes) < 1: - luci_log.debug('no cluster nodes for %s found.' % clustername) - return None - except: + luci_log.debug('GRA: no cluster nodes for %s found.' % clustername) + raise Exception, 'no cluster nodes were found@%s' % path + except Exception, e: + luci_log.debug('GRA: cluster folder %s for %s is missing: %s.' \ + % (path, clustername, str(e))) return None cluname = lower(clustername) @@ -1360,24 +1382,31 @@ try: rc = RicciCommunicator(hostname) except RicciError, e: - luci_log.debug('ricci error: %s' % str(e)) + luci_log.debug('GRA: ricci error: %s' % str(e)) continue try: clu_info = rc.cluster_info() - if cluname != lower(clu_info[0]) and cluname != lower(clu_info[1]): - luci_log.debug('%s reports it\'s in cluster %s:%s; we expect %s' \ + except Exception, e: + luci_log.debug('GRA: cluster_info error: %s' % str(e)) + + if cluname != lower(clu_info[0]) and cluname != lower(clu_info[1]): + try: + luci_log.debug('GRA: %s reports it\'s in cluster %s:%s; we expect %s' \ % (hostname, clu_info[0], clu_info[1], cluname)) - # node reports it's in a different cluster - raise - except: + setNodeFlag(self, node, CLUSTER_NODE_NOT_MEMBER) + except: + pass continue if rc.authed(): return rc - setNodeFlag(node[1], CLUSTER_NODE_NEED_AUTH) + try: + setNodeFlag(node[1], CLUSTER_NODE_NEED_AUTH) + except: + pass - luci_log.debug('no ricci agent could be found for cluster %s' % cluname) + luci_log.debug('GRA: no ricci agent could be found for cluster %s' % cluname) return None def getRicciAgentForCluster(self, req): @@ -1394,23 +1423,14 @@ return getRicciAgent(self, clustername) def getClusterStatus(self, rc): - clustatus_batch ='' - - try: - clustatuscmd_xml = minidom.parseString(clustatus_batch).firstChild - except: - return {} - - try: - ricci_xml = rc.process_batch(clustatuscmd_xml, async=False) - except RicciError, e: - luci_log.debug('ricci error: %s', str(e)) - except: + doc = getClusterStatusBatch(rc) + if not doc: + try: + luci_log.debug_verbose('getClusterStatusBatch returned None for %s/%s' % rc.cluster_info()) + except: + pass return {} - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return {} results = list() vals = {} @@ -2284,8 +2304,14 @@ return None model.deleteNode(delete_target) - str_buf = "" - model.exportModelAsString(str_buf) + + try: + str_buf = model.exportModelAsString() + if not str_buf: + raise Exception, 'model string is blank' + except Exception, e: + luci_log.debug_verbose('NTP exportModelAsString: %s' % str(e)) + return None # propagate the new cluster.conf via the second node batch_number, result = setClusterConf(rc2, str(str_buf)) @@ -2669,12 +2695,28 @@ xvm.addAttribute("name", req.form['xenvmname']) xvm.addAttribute("path", req.form['xenvmpath']) - stringbuf = "" - model.exportModelAsString(stringbuf) - setClusterConf(stringbuf) + try: + stringbuf = model.exportModelAsString() + if not stringbuf: + raise Exception, 'model is blank' + except Exception, e: + luci_log.debug_verbose('exportModelAsString error: %s' % str(e)) + return None - - + try: + clustername = model.getClusterName() + if not clustername: + raise Exception, 'cluster name from modelb.getClusterName() is blank' + except Exception, e: + luci_log.debug_verbose('error: getClusterName: %s' % str(e)) + return None + + rc = getRicciAgent(self, clustername) + if not rc: + luci_log.debug_verbose('Unable to find a ricci agent for the %s cluster' % clustername) + return None + + setClusterConf(rc, stringbuf) def getXenVMInfo(self, model, request): try: @@ -2916,7 +2958,12 @@ map['isVirtualized'] = rc.dom0() except: # default to rhel5 if something crazy happened. - luci_log.debug('An error occurred while attempting to get OS/Virt info for %s -- defaulting to rhel5/False' % rc.hostname()) + try: + luci_log.debug('An error occurred while attempting to get OS/Virt info for %s -- defaulting to rhel5/False' % rc.hostname()) + except: + # this can throw an exception if the original exception + # is caused by rc being None or stale. + pass map['os'] = 'rhel5' map['isVirtualized'] = False return map @@ -2948,15 +2995,30 @@ return resList def getResourceInfo(modelb, request): + if not modelb: + luci_log.debug_verbose('no modelb obj in getResourceInfo') + return {} + + name = None try: name = request['resourcename'] except KeyError, e: try: name = request.form['resourcename'] except: - luci_log.debug_verbose('getResourceInfo missing res name') - return {} + pass except: + pass + + if name is None: + try: + type = request.form['type'] + if type == 'ip': + name = request.form['value'].strip() + except: + pass + + if name is None: luci_log.debug_verbose('getResourceInfo missing res name') return {} @@ -2997,7 +3059,7 @@ try: modelb = request.SESSION.get('model') except: - luci_log.debug_verbose('delResource unable to extract model from SESSION') + luci_log.debug_verbose('delRes unable to extract model from SESSION') return errstr try: @@ -3006,10 +3068,10 @@ try: name = request.form['resourcename'] except: - luci_log.debug_verbose('delResource missing resname %s' % str(e)) + luci_log.debug_verbose('delRes missing resname %s' % str(e)) return errstr + ': ' + str(e) except: - luci_log.debug_verbose('delResource missing resname') + luci_log.debug_verbose('delRes missing resname') return errstr + ': ' + str(e) try: @@ -3018,7 +3080,7 @@ try: clustername = request.form['clustername'] except: - luci_log.debug_verbose('delResource missing cluster name') + luci_log.debug_verbose('delRes missing cluster name') return errstr + ': could not determine the cluster name.' try: @@ -3039,20 +3101,20 @@ break if not found: - luci_log.debug_verbose('delresource cant find res %s' % name) + luci_log.debug_verbose('delRes cant find res %s' % name) return errstr + ': the specified resource was not found.' try: conf = modelb.exportModelAsString() if not conf: - raise - except: - luci_log.debug_verbose('exportModelAsString failed') + raise Exception, 'model string is blank' + except Exception, e: + luci_log.debug_verbose('delRes: exportModelAsString failed: %s' % str(e)) return errstr - batch_number, result = setClusterConf(str(conf)) + batch_number, result = setClusterConf(rc, str(conf)) if batch_number is None or result is None: - luci_log.debug_verbose('missing batch and/or result from setClusterConf') + luci_log.debug_verbose('delRes: missing batch and/or result from setClusterConf') return errstr modelstr = "" @@ -3070,10 +3132,10 @@ flag.manage_addProperty(TASKTYPE, RESOURCE_REMOVE, "string") flag.manage_addProperty(FLAG_DESC, "Removing Resource \'" + request['resourcename'] + "\'", "string") except Exception, e: - luci_log.debug('An error occurred while setting flag %s: %s' \ + luci_log.debug('delRes: An error occurred while setting flag %s: %s' \ % (objname, str(e))) except: - luci_log.debug('An error occurred while setting flag %s' % objname) + luci_log.debug('delRes: An error occurred while setting flag %s' % objname) response = request.RESPONSE response.redirect(request['HTTP_REFERER'] + "&busyfirst=true") @@ -3082,99 +3144,142 @@ if form is None: form = request.form + if not form: + luci_log.debug_verbose('addIp error: form is missing') + return None + modelb = request.SESSION.get('model') - if not modelb or not form: + if not modelb: + luci_log.debug_verbose('addIp error: modelb is missing') return None if form.has_key('edit'): try: oldname = form['oldname'].strip() if not oldname: - raise KeyError('oldname is blank.') + raise KeyError, 'oldname is blank.' res = getResourceForEdit(modelb, oldname) - except KeyError, e: + except Exception, e: + luci_log.debug_verbose('addIp error: %s' % str(e)) return None else: - res = apply(Ip) + try: + res = apply(Ip) + if not res: + raise Exception, 'apply(Ip) is None' + except Exception, e: + luci_log.debug_verbose('addIp error: %s' % str(e)) + return None if not res: + luci_log.debug_verbose('addIp error: res is none') return None + errors = list() try: addr = form['ip_address'].strip() if not addr: - raise KeyError('ip_address is blank') + raise KeyError, 'ip_address is blank' # XXX: validate IP addr res.attr_hash['address'] = addr except KeyError, e: - return None + err = str(e) + errors.append(err) + luci_log.debug_verbose('addIp error: %s' % err) if 'monitorLink' in form: res.attr_hash['monitor_link'] = '1' else: res.attr_hash['monitor_link'] = '0' - modelb.getResourcesPtr().addChild(res) - return res + if len(errors) > 1: + return [None, None, errors] + return [res, modelb, None] def addFs(request, form=None): if form is None: form = request.form - modelb = request.SESSION.get('model') - if not modelb or not form: + if not form: + luci_log.debug_verbose('addFs error: form is missing') + return None + + modelb = request.SESSION.get('model') + if not modelb: + luci_log.debug_verbose('addFs error: modelb is missing') return None if form.has_key('edit'): try: oldname = form['oldname'].strip() if not oldname: - raise KeyError('oldname is blank.') + raise KeyError, 'oldname is blank.' res = getResourceForEdit(modelb, oldname) - except KeyError, e: + except Exception, e: + luci_log.debug_verbose('addFs error: %s' % str(e)) return None else: - res = apply(Fs) + try: + res = apply(Fs) + if not res: + raise Exception, 'apply(Fs) is None' + except Exception, e: + luci_log.debug_verbose('addFs error: %s' % str(e)) + return None if not res: + luci_log.debug_verbose('addFs error: fs obj was not created') return None # XXX: sanity check these fields + errors = list() try: name = form['resourceName'].strip() res.attr_hash['name'] = name - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addFs error: %s' % err) try: mountpoint = form['mountpoint'].strip() res.attr_hash['mountpoint'] = mountpoint - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addFs error: %s' % err) try: device = form['device'].strip() res.attr_hash['device'] = device - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addFs error: %s' % err) try: options = form['options'].strip() res.attr_hash['options'] = options - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addFs error: %s' % err) try: fstype = form['fstype'].strip() res.attr_hash['fstype'] = fstype - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addFs error: %s' % err) try: fsid = form['fsid'].strip() res.attr_hash['fsid'] = fsid - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addFs error: %s' % err) if form.has_key('forceunmount'): res.attr_hash['force_unmount'] = '1' @@ -3191,27 +3296,33 @@ else: res.attr_hash['force_fsck'] = '0' - modelb.getResourcesPtr().addChild(res) - return res + if len(errors) > 1: + return [None, None, errors] + return [res, modelb, None] def addGfs(request, form=None): if form is None: form = request.form + if not form: + luci_log.debug_verbose('addGfs error: form is missing') + return None + modelb = request.SESSION.get('model') if not modelb: + luci_log.debug_verbose('addGfs error: modelb is missing') return None if form.has_key('edit'): try: oldname = form['oldname'].strip() if not oldname: - raise KeyError('oldname is blank.') + raise KeyError, 'oldname is blank.' res = getResourceForEdit(modelb, oldname) if not res: luci_log.debug('resource %s was not found for editing' % oldname) return None - except KeyError, e: + except Exception, e: luci_log.debug('resource %s was not found for editing: %s' \ % (oldname, str(e))) return None @@ -3219,286 +3330,387 @@ try: res = apply(Clusterfs) if not res: - raise + raise Exception, 'apply(Clusterfs) is None' + except Exception, e: + luci_log.debug('addGfs error: %s' % str(e)) + return None except: - luci_log.debug('Error creating node Clusterfs resource') + luci_log.debug('addGfs error') return None # XXX: sanity check these fields + errors = list() try: name = form['resourceName'].strip() if not name: - raise + raise KeyError, 'resourceName is blank' res.attr_hash['name'] = name - except: - luci_log.debug_verbose('name is missing in clusterfs res') - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addGfs error: %s' % err) try: mountpoint = form['mountpoint'].strip() res.attr_hash['mountpoint'] = mountpoint - except: - luci_log.debug_verbose('mountpoint is missing in clusterfs res') - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addGfs error: %s' % err) try: device = form['device'].strip() res.attr_hash['device'] = device - except: - luci_log.debug_verbose('device is missing in clusterfs res') - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addGfs error: %s' % err) try: options = form['options'].strip() res.attr_hash['options'] = options - except: - luci_log.debug_verbose('options is missing in clusterfs res') - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addGfs error: %s' % err) try: fsid = form['fsid'].strip() res.attr_hash['fsid'] = fsid - except: - luci_log.debug_verbose('fsid is missing in clusterfs res') - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addGfs error: %s' % err) if form.has_key('forceunmount'): res.attr_hash['force_unmount'] = '1' else: res.attr_hash['force_unmount'] = '0' - modelb.getResourcesPtr().addChild(res) - return res + if len(errors) > 1: + return [None, None, errors] + return [res, modelb, None] def addNfsm(request, form=None): if form is None: form = request.form - modelb = request.SESSION.get('model') - if not form or not modelb: + if not form: + luci_log.debug_verbose('addNfsm error: form is missing') + return None + + modelb = request.SESSION.get('model') + if not modelb: + luci_log.debug_verbose('addNfsm error: modelb is missing') return None if form.has_key('edit'): try: oldname = form['oldname'].strip() if not oldname: - raise KeyError('oldname is blank.') + raise KeyError, 'oldname is blank.' res = getResourceForEdit(modelb, oldname) - except KeyError, e: + except Exception, e: + luci_log.debug_verbose('addNfsm error: %s' % str(e)) return None else: - res = apply(Netfs) + try: + res = apply(Netfs) + except Exception, e: + luci_log.debug_verbose('addNfsm error: %s' % str(e)) + return None if not res: return None # XXX: sanity check these fields + errors = list() try: name = form['resourceName'].strip() if not name: - raise + raise KeyError, 'resourceName is blank' res.attr_hash['name'] = name - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsm error: %s' % err) try: mountpoint = form['mountpoint'].strip() res.attr_hash['mountpoint'] = mountpoint - except: - return None - + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsm error: %s' % err) + try: host = form['host'].strip() res.attr_hash['host'] = host - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsm error: %s' % err) try: options = form['options'].strip() res.attr_hash['options'] = options - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsm error: %s' % err) try: exportpath = form['exportpath'].strip() res.attr_hash['exportpath'] = exportpath - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsm error: %s' % err) try: nfstype = form['nfstype'].strip().lower() if nfstype != 'nfs' and nfstype != 'nfs4': - raise + raise KeyError, 'invalid nfs type: %s' % nfstype res.attr_hash['nfstype'] = nfstype - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsm error: %s' % err) if form.has_key('forceunmount'): res.attr_hash['force_unmount'] = '1' else: res.attr_hash['force_unmount'] = '0' - modelb.getResourcesPtr().addChild(res) - return res + if len(errors) > 1: + return [None, None, errors] + return [res, modelb, None] def addNfsc(request, form=None): if form is None: form = request.form - modelb = request.SESSION.get('model') - if not form or not modelb: + if not form: + luci_log.debug_verbose('addNfsc error: form is missing') + return None + + modelb = request.SESSION.get('model') + if not modelb: + luci_log.debug_verbose('addNfsc error: modelb is missing') return None if form.has_key('edit'): try: oldname = form['oldname'].strip() if not oldname: - raise KeyError('oldname is blank.') + raise KeyError, 'oldname is blank.' res = getResourceForEdit(modelb, oldname) - except KeyError, e: + except Exception, e: + luci_log.debug_verbose('addNfsc error: %s' % str(e)) return None else: - res = apply(NFSClient) + try: + res = apply(NFSClient) + except: + luci_log.debug_verbose('addNfsc error: %s' % str(e)) + return None if not res: + luci_log.debug_verbose('addNfsc error: res is none') return None + errors = list() try: name = form['resourceName'].strip() if not name: - raise + raise KeyError, 'resourceName is blank' res.attr_hash['name'] = name - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsc error: %s' % err) try: target = form['target'].strip() res.attr_hash['target'] = target - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsc error: %s' % err) try: options = form['options'].strip() res.attr_hash['options'] = options - except: - return None - - modelb.getResourcesPtr().addChild(res) - return res + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsc error: %s' % err) + + if len(errors) > 1: + return [None, None, errors] + return [res, modelb, None] def addNfsx(request, form=None): if form is None: form = request.form - modelb = request.SESSION.get('model') - if not modelb or not form: + if not form: + luci_log.debug_verbose('addNfsx error: modelb is missing') + return None + + modelb = request.SESSION.get('model') + if not modelb: + luci_log.debug_verbose('addNfsx error: modelb is missing') return None if form.has_key('edit'): try: oldname = form['oldname'].strip() if not oldname: - raise KeyError('oldname is blank.') + raise KeyError, 'oldname is blank.' res = getResourceForEdit(modelb, oldname) - except KeyError, e: + except Exception, e: + luci_log.debug_verbose('addNfsx error: %s', str(e)) return None else: - res = apply(NFSExport) + try: + res = apply(NFSExport) + except: + luci_log.debug_verbose('addNfsx error: %s', str(e)) + return None if not res: + luci_log.debug_verbose('addNfsx error: res is None') return None + errors = list() try: name = form['resourceName'].strip() if not name: - raise + raise KeyError, 'resourceName is blank' res.attr_hash['name'] = name - except: - return None - - modelb.getResourcesPtr().addChild(res) - return res + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addNfsx error: %s', err) + + if len(errors) > 1: + return [None, None, errors] + return [res, modelb, None] def addScr(request, form=None): if form is None: form = request.form - modelb = request.SESSION.get('model') - form = request.form - if not modelb or not form: + if not form: + luci_log.debug_verbose('addScr error: form is missing') + return None + + modelb = request.SESSION.get('model') + if not modelb: + luci_log.debug_verbose('addScr error: modelb is missing') return None if form.has_key('edit'): try: oldname = form['oldname'].strip() if not oldname: - raise KeyError('oldname is blank.') + raise KeyError, 'oldname is blank.' res = getResourceForEdit(modelb, oldname) - except KeyError, e: + except Exception, e: + luci_log.debug_verbose('addScr error: %s' % str(e)) return None else: - res = apply(Script) + try: + res = apply(Script) + except Exception, e: + luci_log.debug_verbose('addScr error: %s' % str(e)) + return None if not res: + luci_log.debug_verbose('addScr error: res is None') return None + errors = list() try: name = form['resourceName'].strip() if not name: - raise + raise KeyError, 'resourceName is blank' res.attr_hash['name'] = name - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addScr error: %s' % err) try: file = form['file'].strip() if not file: - raise + raise KeyError, 'file path is blank' res.attr_hash['file'] = file - except: - return None - - modelb.getResourcesPtr().addChild(res) - return res + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addScr error: %s' % err) + + if len(errors) > 1: + return [None, None, errors] + return [res, modelb, None] def addSmb(request, form=None): if form is None: form = request.form - modelb = request.SESSION.get('model') - if not modelb or not form: + if not form: + luci_log.debug_verbose('addSmb error: form is missing') + return None + + modelb = request.SESSION.get('model') + if not modelb: + luci_log.debug_verbose('addSmb error: modelb is missing') return None if form.has_key('edit'): try: oldname = form['oldname'].strip() if not oldname: - raise KeyError('oldname is blank.') + raise KeyError, 'oldname is blank.' res = getResourceForEdit(modelb, oldname) - except KeyError, e: + except Exception, e: + luci_log.debug_verbose('addSmb error: %s' % str(e)) return None else: - res = apply(Samba) + try: + res = apply(Samba) + except Exception, e: + luci_log.debug_verbose('addSmb error: %s' % str(e)) + return None if not res: + luci_log.debug_verbose('addSmb error: res is None') return None + errors = list() try: name = form['resourceName'].strip() if not name: - raise + raise KeyError, 'resourceName is blank' res.attr_hash['name'] = name - except: - return None + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addSmb error: %s' % err) try: workgroup = form['workgroup'].strip() res.attr_hash['workgroup'] = workgroup - except: - return None - - modelb.getResourcesPtr().addChild(res) - return res + except Exception, e: + err = str(e) + errors.append(err) + luci_log.debug_verbose('addSmb error: %s' % err) + + if len(errors) > 1: + return [None, None, errors] + return [res, modelb, None] resourceAddHandler = { 'ip': addIp, @@ -3581,48 +3793,37 @@ return messages -def addResource(self, rc, request): - if not request.form: - return (False, {'errors': ['No form was submitted.']}) - - try: - type = request.form['type'].strip() - if not type or not type in resourceAddHandler: - raise - except: - return (False, {'errors': ['Form type is missing.']}) +def addResource(self, request, modelb, res): + clustername = modelb.getClusterName() + if not clustername: + raise Exception, 'cluster name from modelb.getClusterName() is blank' + + rc = getRicciAgent(self, clustername) + if not rc: + raise Exception, 'Unable to find a ricci agent for the %s cluster' % clustername - try: - resname = request.form['resourceName'] - except KeyError, e: - # For IP, the IP address itself is the name. - if request.form['type'] != 'ip': - return (False, {'errors': ['No resource name was given.']}) + modelb.getResourcesPtr().addChild(res) try: - clustername = request['clustername'] - except KeyError, e: - try: - clustername = request.form['clustername'] - except: - return 'unable to determine the current cluster\'s name' - - res = resourceAddHandler[type](request) - modelb = request.SESSION.get('model') - modelstr = "" - conf = modelb.exportModelAsString() + conf = modelb.exportModelAsString() + if not conf: + raise Exception, 'model string for %s is blank' % clustername + except Exception, e: + luci_log.debug_verbose('addResource: exportModelAsString err: %s' % str(e)) + return 'An error occurred while adding this resource' try: ragent = rc.hostname() if not ragent: - luci_log.debug('missing hostname') - raise - batch_number, result = setClusterConf(str(conf)) + luci_log.debug_verbose('missing hostname') + raise Exception, 'unknown ricci agent hostname' + luci_log.debug_verbose('SENDING NEW CLUSTER CONF: %s' % conf) + batch_number, result = setClusterConf(rc, str(conf)) if batch_number is None or result is None: - luci_log.debug('missing batch_number or result') - raise - except: - return "Some error occured in setClusterConf\n" + luci_log.debug_verbose('missing batch_number or result') + raise Exception, 'batch_number or results is None from setClusterConf' + except Exception, e: + return 'An error occurred while propagating the new cluster.conf: %s' % str(e) path = str(CLUSTER_FOLDER_PATH + clustername) clusterfolder = self.restrictedTraverse(path) @@ -3638,7 +3839,7 @@ flag.manage_addProperty(TASKTYPE, RESOURCE_ADD, "string") if type != 'ip': - flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + request.form['resourceName'] + "\'", "string") + 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") except Exception, e: @@ -3667,7 +3868,7 @@ request.SESSION.set('model', model) except: luci_log.debug_verbose('Appending model to request failed') - return False + return 'An error occurred while storing the cluster model.' def resolve_nodename(self, clustername, nodename): path = str(CLUSTER_FOLDER_PATH + clustername) --- conga/luci/site/luci/Extensions/ricci_bridge.py 2006/10/25 16:01:17 1.35 +++ conga/luci/site/luci/Extensions/ricci_bridge.py 2006/10/26 22:59:13 1.36 @@ -2,6 +2,12 @@ from time import time, ctime from xml.dom import minidom from ricci_communicator import RicciCommunicator +from LuciSyslog import LuciSyslog + +try: + luci_log = LuciSyslog() +except: + pass def checkBatch(rc, batch_id): try: @@ -201,19 +207,28 @@ return minidom.parseString(batch).firstChild def batchAttemptResult(self, doc): - docc = None - rc_node = None + try: + batch = doc.getElementsByTagName('batch') + if not batch or len(batch) < 1: + raise Exception, 'no batch tag was found' + except Exception, e: + luci_log.debug_verbose('batchAttemptResult: %s' % str(e)) - for node in doc.firstChild.childNodes: - if node.nodeType == xml.dom.Node.ELEMENT_NODE: - if node.nodeName == 'batch': - #get batch number and status code - batch_number = node.getAttribute('batch_id') - result = node.getAttribute('status') - return (batch_number, result) - else: - #print "RETURNING NONE!!!" - return (None, None) + for i in batch: + try: + batch_number = i.getAttribute('batch_id') + result = i.getAttribute('status') + return (batch_number, result) + except Exception, e: + luci_log.debug_verbose('batchAttemptResult: %s' % str(e)) + + try: + luci_log.debug_verbose('no batch with batchid and status found in \"%s\"' % doc.toxml()) + except: + pass + + return (None, None) + def getPayload(bt_node): if not bt_node: @@ -260,6 +275,17 @@ doc.appendChild(cl_node) return doc +def getClusterStatusBatch(rc): + batch_str ='' + ricci_xml = rc.batch_run(batch_str, async=False) + + doc = getPayload(ricci_xml) + if not doc or not doc.firstChild: + luci_log.debug_verbose('doc is None from getPayload: %s' % ricci_xml.toxml()) + return None + + return doc + def setClusterConf(rc, clusterconf, propagate=True): if propagate == True: propg = 'true' @@ -274,10 +300,7 @@ batch_str = '' + conf + '' ricci_xml = rc.batch_run(batch_str) - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return (None, None) - return batchAttemptResult(doc) + return batchAttemptResult(ricci_xml) def getNodeLogs(rc): errstr = 'log not accessible' @@ -334,10 +357,7 @@ batch_str = '' ricci_xml = rc.batch_run(batch_str) - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return (None, None) - return batchAttemptResult(doc) + return batchAttemptResult(ricci_xml) def nodeLeaveCluster(rc, cluster_shutdown=False, purge=False): cshutdown = 'false' @@ -351,19 +371,13 @@ batch_str = '' ricci_xml = rc.batch_run(batch_str) - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return (None, None) - return batchAttemptResult(doc) + return batchAttemptResult(ricci_xml) def nodeFence(rc, nodename): batch_str = '' ricci_xml = rc.batch_run(batch_str) - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return (None, None) - return batchAttemptResult(doc) + return batchAttemptResult(ricci_xml) def nodeJoinCluster(rc, cluster_startup=False): cstartup = 'false' @@ -373,10 +387,7 @@ batch_str = '' ricci_xml = rc.batch_run(batch_str) - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return (None, None) - return batchAttemptResult(doc) + return batchAttemptResult(ricci_xml) def startService(rc, servicename, preferrednode=None): if preferrednode != None: @@ -385,28 +396,19 @@ batch_str = '' ricci_xml = rc.batch_run(batch_str) - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return (None, None) - return batchAttemptResult(doc) + return batchAttemptResult(ricci_xml) def restartService(rc, servicename): batch_str = '' ricci_xml = rc.batch_run(batch_str) - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return (None, None) - return batchAttemptResult(doc) + return batchAttemptResult(ricci_xml) def stopService(rc, servicename): batch_str = '' ricci_xml = rc.batch_run(batch_str) - doc = getPayload(ricci_xml) - if not doc or not doc.firstChild: - return (None, None) - return batchAttemptResult(doc) + return batchAttemptResult(ricci_xml) def getDaemonStates(rc, dlist): batch_str = ''