def test_detect_permission(self):
     """ test python API detect mal formed permissions """
     d = serviceaccess.parse(self.filename, self.section, "DB")
     try:
         serviceaccess.check(d, "db")
     except serviceaccess.ServiceaccessException:
         pass
示例#2
0
    def __init__(self, desfile=None, section=None):
        """
        Create an interface object for a DES database.

        The DES services file and/or section contained therein may be specified
        via the desfile and section arguments.  When omitted default values
        will be used as defined in DESDM-3.  A tag of "db" will be used in all
        cases.

        """

        self.configdict = serviceaccess.parse(desfile,section,'DB')
        self.type       = self.configdict['type']

        serviceaccess.check (self.configdict, 'DB')

        if self.type == 'oracle':
            import oracon
            conClass = oracon.OracleConnection
        elif self.type == 'postgres':
            import pgcon
            conClass = pgcon.PostgresConnection
        else:
            raise errors.UnknownDBTypeError (self.type)

        MAXTRIES = 5
        TRY_DELAY = 10 # seconds
        trycnt = 0
        done = False
        lasterr = ""
        while not done and trycnt < MAXTRIES: 
            trycnt += 1
            try:
                self.con = conClass (self.configdict)
                done = True
            except Exception as e:
                lasterr = str(e).strip()
                timestamp = time.strftime("%x %X", time.localtime())
                print "%s: Error when trying to connect to database: %s" % (timestamp,lasterr)
                if trycnt < MAXTRIES:
                    print "\tRetrying...\n"
                    time.sleep(TRY_DELAY)

        if not done:
            print "Exechost:", socket.gethostname()
            print "Connection information:", str(self)
            #for key in ("user", "type", "port", "server"):
            #    print "\t%s = %s" % (key, self.configdict[key])
            print ""
            raise Exception("Aborting attempt to connect to database.  Last error message: %s" % lasterr)
        elif trycnt > 1: # only print success message if we've printed failure message
            print "Successfully connected to database after retrying."
 def test_python_maximal_assert(self):
     """ Test that checkign a proper file throws no errors """
     serviceaccess.check(self.maximal, "db")
 def test_python_maximal_assert(self):
     """ Test that checkign a proper file throws no errors """
     with self.assertRaises(serviceaccess.ServiceaccessException):
         serviceaccess.check(
             serviceaccess.parse(self.filename, 'db-maximal', "db"), 'db')
 def test_python_minimal_assert(self):
     """ test that check function passed a clean file"""
     serviceaccess.check(self.minimal, "db")