- Timestamp:
- Jul 16, 2008 5:59:59 PM (16 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- dc8c3e6
- Parents:
- bb3769a
- Location:
- fedd
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_client.py
rbb3769a r0c0b13c 147 147 print >>out, "%s: %s" % (a['attribute'], a['value']) 148 148 149 def exit_with_fault(dict, out=sys.stderr): 150 """ Print an error message and exit. 151 152 The dictionary contains the RequestAccessFaultBody elements.""" 153 codestr = "" 154 155 if dict.has_key('errstr'): 156 codestr = "Error: %s" % dict['errstr'] 157 158 if dict.has_key('code'): 159 if len(codestr) > 0 : 160 codestr += " (%d)" % dict['code'] 161 else: 162 codestr = "Error Code: %d" % dict['code'] 163 164 print>>out, codestr 165 print>>out, "Description: %s" % dict['desc'] 166 sys.exit(dict.get('code', 20)) 167 149 168 def add_ssh_key(option, opt_str, value, parser, access_keys): 150 169 try: … … 274 293 if opts.debug > 1: print >>sys.stderr, msg 275 294 276 print FaultType.typecode;277 278 295 if opts.transport == "soap": 279 296 loc = feddServiceLocator(); … … 299 316 sys.exit("Malformed response (XMLPRC?): %s" % e) 300 317 except ZSI.FaultException, e: 301 print dir(e.fault.detail[0]) 302 print e.fault.detail[0].RequestAccessFaultBody.get_element_code() 303 d = unpack_soap(e.fault.detail[0].get_element_RequestAccessFaultBody()) 304 f = unpack_soap(e.fault.detail[0]) 305 print "unpack ", d 306 print "unpack ", f 307 sys.exit("Fault: %s %s" % (str(e.fault.code), str(e.fault.string))) 308 318 resp = e.fault.detail[0] 309 319 310 320 if (resp != None): 311 resp_body = resp.get_element_RequestAccessResponseBody() 312 if ( resp_body != None): 313 try: 314 resp_dict = unpack_soap(resp_body) 315 if opts.debug > 1: print >>sys.stderr, resp_dict 316 print_response_as_testbed(resp_dict, opts.label) 317 except RuntimeError, e: 318 sys.exit("Bad response. %s" % e.messgae) 319 else: sys.exit("No body in resonpse!?") 321 if 'get_element_RequestAccessResponseBody' in dir(resp): 322 resp_body = resp.get_element_RequestAccessResponseBody() 323 if ( resp_body != None): 324 try: 325 resp_dict = unpack_soap(resp_body) 326 if opts.debug > 1: print >>sys.stderr, resp_dict 327 print_response_as_testbed(resp_dict, opts.label) 328 except RuntimeError, e: 329 sys.exit("Bad response. %s" % e.message) 330 elif 'get_element_RequestAccessFaultBody' in dir(resp): 331 resp_body = resp.get_element_RequestAccessFaultBody() 332 if resp_body != None: 333 exit_with_fault(unpack_soap(resp_body)) 334 else: sys.exit("No body in response!?") 320 335 else: sys.exit("No response?!?") 321 336 elif opts.transport == "xmlrpc": … … 331 346 resp, method = loads(resp) 332 347 except Error, e: 333 sys.exit("Fault: %s" % e) 348 resp = { 'RequestAccessFaultBody': \ 349 { 'errstr' : e.faultCode, 'desc' : e.faultString } } 334 350 335 351 336 352 if (resp != None): 337 try: 338 print resp 339 resp_dict = resp[0]['RequestAccessResponseBody'] 340 if opts.debug > 1: print >>sys.stderr, resp_dict 341 print_response_as_testbed(resp_dict, opts.label) 342 except RuntimeError, e: 343 sys.exit("Bad response. %s" % e.messgae) 353 if resp.has_key('RequestAccessReponseBody'): 354 try: 355 resp_dict = resp[0]['RequestAccessResponseBody'] 356 if opts.debug > 1: print >>sys.stderr, resp_dict 357 print_response_as_testbed(resp_dict, opts.label) 358 except RuntimeError, e: 359 sys.exit("Bad response. %s" % e.messgae) 360 elif resp.has_key('RequestAccessFaultBody'): 361 exit_with_fault(resp['RequestAccessFaultBody']) 362 else: sys.exit("No body in response!?") 363 344 364 else: sys.exit("No response?!?") -
fedd/fedd_proj.py
rbb3769a r0c0b13c 20 20 from fedd_services import * 21 21 from fedd_util import * 22 import parse_detail 22 23 23 24 if False: … … 66 67 return "access_proj('%s', [])" % self.name 67 68 68 # These are used to make the error reporting independent of the transport. 69 # The XMLRPC and SOAP dispatchers will convert them to transport-specific 70 # errors 71 class server_error(RuntimeError): pass 72 class client_error(RuntimeError): pass 73 # Error parsing config 69 # This is used to make the service error reporting independent of the 70 # transport. The XMLRPC and SOAP dispatchers will convert it into 71 # transport-specific errors 72 class service_error(RuntimeError): 73 access = 1 74 proxy= 2 75 req = 3 76 server_config = 4 77 internal = 5 78 code_str = { 79 access : "Access Denied", 80 proxy : "Proxy Error", 81 req : "Badly Formed Request", 82 server_config: "Server Configuration Error", 83 internal : "Internal Error" 84 } 85 str_code = dict([ (v, k) for k, v in code_str.iteritems() ]) 86 client_errors = ( req ) 87 server_errors = ( access, proxy, server_config, internal) 88 89 def __init__(self, code=None, desc=None, from_string=None): 90 self.code = code 91 self.desc = desc 92 if code == None: 93 self.set_code_from_string(from_string) 94 RuntimeError.__init__(self, desc) 95 96 def code_string(self, code=None): 97 code = code or self.code 98 return fedd_proj.service_error.code_str.get(code) 99 100 def set_code_from_string(self, errstr): 101 self.code = fedd_proj.service_error.str_code.get(errstr, 102 fedd_proj. service_error.internal) 103 return self.code 104 105 def is_client_error(self): 106 return self.code in fedd_proj.service_error.client_errors 107 108 def is_server_error(self): 109 return self.code in fedd_proj.service_error.server_errors 110 111 # Used to report errors parsing the configuration files, not in providing 112 # service 74 113 class parse_error(RuntimeError): pass 75 114 … … 229 268 rc = subprocess.call(cmd) 230 269 except OSerror, e: 231 raise fedd_proj.server_error( 270 raise fedd_proj.service_error(\ 271 fedd_proj.service_error.internal, 232 272 "Dynamic project subprocess creation error "+ \ 233 273 "[%s] (%s)" % (cmd[1], e.strerror)) … … 236 276 237 277 if rc != 0: 238 raise fedd_proj.server_error( 278 raise fedd_proj.service_error(\ 279 fedd_proj.service_error.internal, 239 280 "Dynamic project subprocess error " +\ 240 281 "[%s] (%d)" % (cmd[1], rc)) … … 266 307 ctx = fedd_ssl_context(self.cert_file, tc, password=self.cert_pwd) 267 308 except SSL.SSLError: 268 raise fedd_proj.server_error("Server certificates misconfigured") 309 raise fedd_proj.service_error(fedd_proj.service_error.server_config, 310 "Server certificates misconfigured") 269 311 270 312 # Of all the dumbass things. The XMLRPC library in use here won't … … 286 328 { "RequestAccessRequestBody": r}) 287 329 resp, method = xmlrpclib.loads(resp) 330 except xmlrpclib.Fault, f: 331 se = fedd_proj.service_error(None, f.faultString, f.faultCode) 332 raise se 288 333 except xmlrpclib.Error, e: 289 raise fedd_proj.server_error("Remote XMLRPC Fault: %s" % e) 334 raise fedd_proj.service_error(fedd_proj.service_error.proxy, 335 "Remote XMLRPC Fault: %s" % e) 290 336 291 337 if resp[0].has_key('RequestAccessResponseBody'): 292 338 return resp[0]['RequestAccessResponseBody'] 293 339 else: 294 raise fedd_proj.server_error("Bad proxy response") 340 raise fedd_proj.service_error(fedd_proj.service_error.proxy, 341 "Bad proxy response") 295 342 296 343 def proxy_request(self, dt, req): … … 308 355 ctx = fedd_ssl_context(self.cert_file, tc, password=self.cert_pwd) 309 356 except SSL.SSLError: 310 raise fedd_proj.server_error("Server certificates misconfigured") 357 raise fedd_proj.service_error(fedd_proj.service_error.server_config, 358 "Server certificates misconfigured") 311 359 312 360 loc = feddServiceLocator(); … … 322 370 resp = port.RequestAccess(msg) 323 371 except ZSI.ParseException, e: 324 raise fedd_proj.server_error("Bad format message (XMLRPC??): %s" % 372 raise fedd_proj.service_error(fedd_proj.service_error.proxy, 373 "Bad format message (XMLRPC??): %s" % 325 374 str(e)) 326 except ZSI.FaultException, e:327 raise e.fault328 329 375 r = unpack_soap(resp) 330 376 … … 332 378 return r['RequestAccessResponseBody'] 333 379 else: 334 raise fedd_proj.server_error("Bad proxy response") 380 raise fedd_proj.service_error(fedd_proj.service_error.proxy, 381 "Bad proxy response") 335 382 336 383 def permute_wildcards(self, a, p): … … 401 448 fedids = [ u for u in user if isinstance(u, type(fid))] 402 449 if len(fedids) > 1: 403 raise fedd_proj. client_error(450 raise fedd_proj.service_error(service_error.req, 404 451 "User asserting multiple fedids") 405 452 elif len(fedids) == 1 and fedids[0] != fid: 406 raise fedd_proj. client_error(453 raise fedd_proj.service_error(service_error.req, 407 454 "User asserting different fedid") 408 455 project = None … … 410 457 elif principal_type == "project": 411 458 if isinstance(project, type(fid)) and fid != project: 412 raise fedd_proj. client_error(459 raise fedd_proj.service_error(service_error.req, 413 460 "Project asserting different fedid") 414 461 tb = None … … 419 466 print "Found: ", found 420 467 421 if found == None: raise fedd_proj.server_error("Access denied") 468 if found == None: 469 raise fedd_proj.service_error(fedd_proj.service_error.access, 470 "Access denied") 422 471 423 472 # resolve <dynamic> and <same> in found … … 429 478 found[0].name = project 430 479 else : 431 raise fedd_proj.server_error( 480 raise fedd_proj.service_error(\ 481 fedd_proj.service_error.server_config, 432 482 "Project matched <same> when no project given") 433 483 elif found[0].name == "<dynamic>": … … 438 488 if user_match == "<any>": 439 489 if user != None: found = (found[0], user[0]) 440 else: raise fedd_proj.server_error( 490 else: raise fedd_proj.service_error(\ 491 fedd_proj.service_error.server_config, 441 492 "Matched <same> on anonymous request") 442 493 else: … … 487 538 req = req['RequestAccessRequestBody'] 488 539 else: 489 raise fedd_proj. client_error("No request!?")540 raise fedd_proj.service_error(service_error.req, "No request!?") 490 541 491 542 if req.has_key('destinationTestbed'): … … 505 556 t not in found[0].node_types] 506 557 if len(inaccessible) > 0: 507 raise fedd_proj.serv er_error(558 raise fedd_proj.service_error(fedd_proj.service_error.access, 508 559 "Access denied (nodetypes %s)" % \ 509 560 str(', ').join(inaccessible)) … … 516 567 else: pass # SSH key additions 517 568 else: 518 raise fedd_proj.client_error("SSH access parameters required") 569 raise fedd_proj.service_error(service_error.req, 570 "SSH access parameters required") 519 571 520 572 resp = self.build_response(req['allocID'], found, ssh) … … 525 577 # Proxy the request using SOAP 526 578 return self.proxy_request(dt, req) 527 except RuntimeError, f: 528 p_fault = f 529 530 531 # This runs if SOAP failed 532 try: 579 except fedd_proj.service_error, e: 580 if e.code == fedd_proj.service_error.proxy: p_fault = None 581 else: raise 582 except ZSI.FaultException, f: 583 p_fault = f.fault.detail[0] 584 585 586 # If we could not get a valid SOAP response to the request above, 587 # try the same address using XMLRPC and let any faults flow back 588 # out. 589 if p_fault == None: 533 590 return self.proxy_xmlrpc_request(dt, req) 534 print "here" 535 except RuntimeError: 536 # Both failed, return the SOAP error. If somehow that 537 # exception is gone, return the XMLRPC one 538 if p_fault != None: raise p_fault 539 else: raise 591 else: 592 # Build the fault 593 body = p_fault.get_element_RequestAccessFaultBody() 594 if body != None: 595 raise service_error(body.get_element_code(), 596 body.get_element_desc()); 597 else: 598 raise fedd_proj.service_error(\ 599 fedd_proj.service_error.proxy, 600 "Undefined fault from proxy??"); 540 601 541 602 def soap_RequestAccess(self, ps, fid): … … 556 617 return xmlrpclib.dumps(({ "RequestAccessResponseBody": msg },)) 557 618 else: 558 raise server_error("No response generated?!"); 619 raise service_error(fedd_proj.service_error.internal, 620 "No response generated?!"); 559 621 560 622 def read_trust(self, trust): … … 729 791 try: 730 792 return getattr(self, fedd_proj.soap_methods[method])(req, fid) 731 except fedd_proj.server_error, e: 732 de = ns0.faultType_Def((ns0.faultType_Def.schema,"RequestAccessFaultBody")).pyclass() 733 de._code=100 734 de._desc="temp" 735 f = Fault(Fault.Server, "Server Test", detail=de) 736 raise f 737 except fedd_proj.client_error, e: 738 raise Fault(Fault.Client, str(e)) 793 except fedd_proj.service_error, e: 794 de = ns0.faultType_Def( 795 (ns0.faultType_Def.schema, 796 "RequestAccessFaultBody")).pyclass() 797 de._code=e.code 798 de._errstr=e.code_string() 799 de._desc=e.desc 800 if e.is_server_error(): 801 raise Fault(Fault.Server, e.code_string(), detail=de) 802 else: 803 raise Fault(Fault.Client, e.code_string(), detail=de) 739 804 else: 740 805 raise Fault(Fault.Client, "Unknown method: %s" % method) … … 744 809 try: 745 810 return getattr(self, fedd_proj.xmlrpc_methods[method])(req, fid) 746 except fedd_proj.server_error, e: 747 raise xmlrpclib.Fault("server", str(e)) 748 except fedd_proj.client_error, e: 749 raise xmlrpclib.Fault("client", str(e)) 811 except fedd_proj.service_error, e: 812 raise xmlrpclib.Fault(e.code_string(), e.desc) 750 813 else: 751 814 raise xmlrpclib.Fault(100, "Unknown method: %s" % method) -
fedd/fedd_types.xsd
rbb3769a r0c0b13c 185 185 <xsd:complexType name="faultType"> 186 186 <xsd:sequence> 187 <xsd:element name="code" type="xsd:int"/> 187 <xsd:element name="code" type="xsd:int"> 188 <xsd:restriction> 189 <xsd:enumeration value="1"/> <!-- access denied --> 190 <xsd:enumeration value="2"/> <!-- proxy error --> 191 <xsd:enumeration value="3"/> <!-- badly formed request --> 192 <xsd:enumeration value="4"/> <!-- internal error --> 193 </xsd:restriction> 194 </xsd:element> 195 <xsd:element name="errstr" minOccurs="0" maxOccurs="1" type="xsd:string"> 196 </xsd:element> 188 197 <xsd:element name="desc" type="xsd:string"/> 189 198 </xsd:sequence>
Note: See TracChangeset
for help on using the changeset viewer.