Changeset 8cb269a for fedd/federation


Ignore:
Timestamp:
Oct 13, 2011 2:48:24 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
compt_changes, info-ops, master
Children:
0dc62df
Parents:
c167378
Message:

Send the ns pasring error back to the caller (and back to the user)
closes #40

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/ns2topdl.py

    rc167378 r8cb269a  
    66import logging
    77import topdl
     8
     9import os.path
    810
    911from util import *
     
    105107            raise service_error(service_error.internal, "Cannot create tmp dir")
    106108
    107         tclfile = tmpdir + "/experiment.tcl"
     109        tclfile = os.path.join(tmpdir, "experiment.tcl")
     110        # save error output in case the parse fails.
     111        errfile = os.path.join(tmpdir, "errfile")
    108112        pid = "dummy"
    109113        gid = "dummy"
     
    124128                    f.write(file_content)
    125129                    f.close()
     130                    ef = open(errfile, 'w')
    126131                except EnvironmentError:
    127132                    raise service_error(service_error.internal,
     
    138143        tclcmd.extend([pid, gid, eid, tclfile])
    139144        self.log.debug("Calling splitter %s" % " ".join(tclcmd))
    140         tclparser = subprocess.Popen(tclcmd, stdout=subprocess.PIPE)
     145        tclparser = subprocess.Popen(tclcmd, stdout=subprocess.PIPE, stderr=ef)
    141146
    142         top = topdl.topology_from_xml(file=tclparser.stdout, top="experiment")
     147        try:
     148            top = topdl.topology_from_xml(file=tclparser.stdout,
     149                    top="experiment")
     150        except:
     151            top = None
     152
     153        if top is None:
     154            # There was an ns parsing error, gather up the error from the
     155            # errfile and raise a service_error containing the error text
     156            try:
     157                ef = open(errfile, 'r')
     158                parse_err = ef.read()
     159                ef.close()
     160            except EnvironmentError:
     161                raise service_error(service_error.internal,
     162                        "Cannot read error string")
     163
     164            raise service_error(service_error.req,
     165                    "Cannot parse ns file: %s" % parse_err)
    143166
    144167        # Walk up tmpdir, deleting as we go
Note: See TracChangeset for help on using the changeset viewer.